Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce HandleKindDataIsInvariant helper #99744

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/coreclr/jit/fgdiagnostic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3390,20 +3390,17 @@ void Compiler::fgDebugCheckFlags(GenTree* tree, BasicBlock* block)
GenTreeFlags handleKind = op1->GetIconHandleFlag();

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

// Currently we expect all indirections with constant addresses to be nonfaulting.
expectedFlags |= GTF_IND_NONFAULTING;
Expand Down
29 changes: 24 additions & 5 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7710,8 +7710,8 @@ GenTreeFlags Compiler::gtTokenToIconFlags(unsigned token)
// Returns a GT_IND node representing value at the address provided by 'addr'
//
// Notes:
// The GT_IND node is marked as non-faulting
// If the indType is GT_REF we also mark the indNode as GTF_GLOB_REF
// The GT_IND node is marked as non-faulting.
// If the indirection is not invariant, we also mark the indNode as GTF_GLOB_REF.
//
GenTree* Compiler::gtNewIndOfIconHandleNode(var_types indType, size_t addr, GenTreeFlags iconFlags, bool isInvariant)
{
Expand All @@ -7720,9 +7720,7 @@ GenTree* Compiler::gtNewIndOfIconHandleNode(var_types indType, size_t addr, GenT

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

// This indirection also is invariant.
indirFlags |= GTF_IND_INVARIANT;
Expand Down Expand Up @@ -10796,6 +10794,27 @@ void GenTree::SetIndirExceptionFlags(Compiler* comp)
}
}

//------------------------------------------------------------------------------
// HandleKindDataIsInvariant: Returns true if the data referred to by a handle
// address is guaranteed to be invariant. Note that GTF_ICON_FTN_ADDR handles may
// or may not point to invariant data.
//
// Arguments:
// flags - GenTree flags for handle.
//
/* static */
bool GenTree::HandleKindDataIsInvariant(GenTreeFlags flags)
{
GenTreeFlags handleKind = flags & GTF_ICON_HDL_MASK;
assert(handleKind != GTF_EMPTY);

// All handle types are assumed invariant except those specifically listed here.

return (handleKind != GTF_ICON_STATIC_HDL) && // Pointer to a mutable class Static variable
(handleKind != GTF_ICON_BBC_PTR) && // Pointer to a mutable basic block count value
(handleKind != GTF_ICON_GLOBAL_PTR); // Pointer to mutable data from the VM state
}

#ifdef DEBUG

/* static */ int GenTree::gtDispFlags(GenTreeFlags flags, GenTreeDebugFlags debugFlags)
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/jit/gentree.h
Original file line number Diff line number Diff line change
Expand Up @@ -2249,6 +2249,7 @@ struct GenTree
}

#if defined(TARGET_XARCH) && defined(FEATURE_HW_INTRINSICS)

bool IsEmbMaskOp()
{
return OperIsHWIntrinsic() && ((gtFlags & GTF_HW_EM_OP) != 0);
Expand All @@ -2263,6 +2264,8 @@ struct GenTree

#endif // TARGET_XARCH && FEATURE_HW_INTRINSICS

static bool HandleKindDataIsInvariant(GenTreeFlags flags);

bool IsCall() const
{
return OperGet() == GT_CALL;
Expand Down
Loading