Skip to content

Commit e8118ba

Browse files
Introduce HandleKindDataIsInvariant helper (#99744)
* Introduce `HandleKindDataIsInvariant` helper Small helper to identify if a handle kind is invariant. * Update src/coreclr/jit/gentree.cpp Co-authored-by: Filip Navara <[email protected]> --------- Co-authored-by: Filip Navara <[email protected]>
1 parent 33d737a commit e8118ba

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

src/coreclr/jit/fgdiagnostic.cpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -3411,20 +3411,17 @@ void Compiler::fgDebugCheckFlags(GenTree* tree, BasicBlock* block)
34113411
GenTreeFlags handleKind = op1->GetIconHandleFlag();
34123412

34133413
// Some of these aren't handles to invariant data...
3414-
if ((handleKind == GTF_ICON_STATIC_HDL) || // Pointer to a mutable class Static variable
3415-
(handleKind == GTF_ICON_BBC_PTR) || // Pointer to a mutable basic block count value
3416-
(handleKind == GTF_ICON_FTN_ADDR) || // Pointer to a potentially mutable VM slot
3417-
(handleKind == GTF_ICON_GLOBAL_PTR)) // Pointer to mutable data from the VM state
3414+
if (GenTree::HandleKindDataIsInvariant(handleKind) && (handleKind != GTF_ICON_FTN_ADDR))
3415+
{
3416+
expectedFlags |= GTF_IND_INVARIANT;
3417+
}
3418+
else
34183419
{
34193420
// For statics, we expect the GTF_GLOB_REF to be set. However, we currently
34203421
// fail to set it in a number of situations, and so this check is disabled.
34213422
// TODO: enable checking of GTF_GLOB_REF.
34223423
// expectedFlags |= GTF_GLOB_REF;
34233424
}
3424-
else // All the other handle indirections are considered invariant
3425-
{
3426-
expectedFlags |= GTF_IND_INVARIANT;
3427-
}
34283425

34293426
// Currently we expect all indirections with constant addresses to be nonfaulting.
34303427
expectedFlags |= GTF_IND_NONFAULTING;

src/coreclr/jit/gentree.cpp

+24-5
Original file line numberDiff line numberDiff line change
@@ -7726,8 +7726,8 @@ GenTreeFlags Compiler::gtTokenToIconFlags(unsigned token)
77267726
// Returns a GT_IND node representing value at the address provided by 'addr'
77277727
//
77287728
// Notes:
7729-
// The GT_IND node is marked as non-faulting
7730-
// If the indType is GT_REF we also mark the indNode as GTF_GLOB_REF
7729+
// The GT_IND node is marked as non-faulting.
7730+
// If the indirection is not invariant, we also mark the indNode as GTF_GLOB_REF.
77317731
//
77327732
GenTree* Compiler::gtNewIndOfIconHandleNode(var_types indType, size_t addr, GenTreeFlags iconFlags, bool isInvariant)
77337733
{
@@ -7736,9 +7736,7 @@ GenTree* Compiler::gtNewIndOfIconHandleNode(var_types indType, size_t addr, GenT
77367736

77377737
if (isInvariant)
77387738
{
7739-
assert(iconFlags != GTF_ICON_STATIC_HDL); // Pointer to a mutable class Static variable
7740-
assert(iconFlags != GTF_ICON_BBC_PTR); // Pointer to a mutable basic block count value
7741-
assert(iconFlags != GTF_ICON_GLOBAL_PTR); // Pointer to mutable data from the VM state
7739+
assert(GenTree::HandleKindDataIsInvariant(iconFlags));
77427740

77437741
// This indirection also is invariant.
77447742
indirFlags |= GTF_IND_INVARIANT;
@@ -10814,6 +10812,27 @@ void GenTree::SetIndirExceptionFlags(Compiler* comp)
1081410812
}
1081510813
}
1081610814

10815+
//------------------------------------------------------------------------------
10816+
// HandleKindDataIsInvariant: Returns true if the data referred to by a handle
10817+
// address is guaranteed to be invariant. Note that GTF_ICON_FTN_ADDR handles may
10818+
// or may not point to invariant data.
10819+
//
10820+
// Arguments:
10821+
// flags - GenTree flags for handle.
10822+
//
10823+
/* static */
10824+
bool GenTree::HandleKindDataIsInvariant(GenTreeFlags flags)
10825+
{
10826+
GenTreeFlags handleKind = flags & GTF_ICON_HDL_MASK;
10827+
assert(handleKind != GTF_EMPTY);
10828+
10829+
// All handle types are assumed invariant except those specifically listed here.
10830+
10831+
return (handleKind != GTF_ICON_STATIC_HDL) && // Pointer to a mutable class Static variable
10832+
(handleKind != GTF_ICON_BBC_PTR) && // Pointer to a mutable basic block count value
10833+
(handleKind != GTF_ICON_GLOBAL_PTR); // Pointer to mutable data from the VM state
10834+
}
10835+
1081710836
#ifdef DEBUG
1081810837

1081910838
/* static */ int GenTree::gtDispFlags(GenTreeFlags flags, GenTreeDebugFlags debugFlags)

src/coreclr/jit/gentree.h

+3
Original file line numberDiff line numberDiff line change
@@ -2249,6 +2249,7 @@ struct GenTree
22492249
}
22502250

22512251
#if defined(TARGET_XARCH) && defined(FEATURE_HW_INTRINSICS)
2252+
22522253
bool IsEmbMaskOp()
22532254
{
22542255
return OperIsHWIntrinsic() && ((gtFlags & GTF_HW_EM_OP) != 0);
@@ -2263,6 +2264,8 @@ struct GenTree
22632264

22642265
#endif // TARGET_XARCH && FEATURE_HW_INTRINSICS
22652266

2267+
static bool HandleKindDataIsInvariant(GenTreeFlags flags);
2268+
22662269
bool IsCall() const
22672270
{
22682271
return OperGet() == GT_CALL;

0 commit comments

Comments
 (0)