Skip to content

Commit ea076a5

Browse files
Refactor handle kinds into a table and mark the static base address cell handle non-null (#118183)
1 parent 260d02b commit ea076a5

File tree

10 files changed

+143
-212
lines changed

10 files changed

+143
-212
lines changed

src/coreclr/jit/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ set( JIT_HEADERS
304304
compilerbitsettraits.hpp
305305
compmemkind.h
306306
compphases.h
307+
handlekinds.h
307308
dataflow.h
308309
debuginfo.h
309310
decomposelongs.h

src/coreclr/jit/compiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2999,7 +2999,7 @@ class Compiler
29992999

30003000
GenTree* gtNewJmpTableNode();
30013001

3002-
GenTree* gtNewIndOfIconHandleNode(var_types indType, size_t addr, GenTreeFlags iconFlags, bool isInvariant);
3002+
GenTree* gtNewIndOfIconHandleNode(var_types indType, size_t addr, GenTreeFlags iconFlags);
30033003

30043004
GenTreeIntCon* gtNewIconHandleNode(size_t value, GenTreeFlags flags, FieldSeq* fields = nullptr);
30053005

src/coreclr/jit/fgprofile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ GenTree* BlockCountInstrumentor::CreateCounterIncrement(Compiler* comp, uint8_t*
763763

764764
// Read Basic-Block count value
765765
GenTree* valueNode =
766-
comp->gtNewIndOfIconHandleNode(countType, reinterpret_cast<size_t>(counterAddr), GTF_ICON_BBC_PTR, false);
766+
comp->gtNewIndOfIconHandleNode(countType, reinterpret_cast<size_t>(counterAddr), GTF_ICON_BBC_PTR);
767767

768768
// Increment value by 1
769769
GenTree* incValueNode = comp->gtNewOperNode(GT_ADD, countType, valueNode, comp->gtNewIconNode(1, countType));

src/coreclr/jit/flowgraph.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,13 @@ BasicBlock* Compiler::fgCreateGCPoll(GCPollType pollType, BasicBlock* block)
322322
{
323323
// Use a double indirection
324324
GenTree* addr =
325-
gtNewIndOfIconHandleNode(TYP_I_IMPL, (size_t)pAddrOfCaptureThreadGlobal, GTF_ICON_CONST_PTR, true);
325+
gtNewIndOfIconHandleNode(TYP_I_IMPL, (size_t)pAddrOfCaptureThreadGlobal, GTF_ICON_CONST_PTR);
326326
value = gtNewIndir(TYP_INT, addr, GTF_IND_NONFAULTING);
327327
}
328328
else
329329
{
330330
// Use a single indirection
331-
value = gtNewIndOfIconHandleNode(TYP_INT, (size_t)addrTrap, GTF_ICON_GLOBAL_PTR, false);
331+
value = gtNewIndOfIconHandleNode(TYP_INT, (size_t)addrTrap, GTF_ICON_GLOBAL_PTR);
332332
}
333333

334334
// NOTE: in c++ an equivalent load is done via LoadWithoutBarrier() to ensure that the

src/coreclr/jit/gentree.cpp

Lines changed: 73 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -7727,10 +7727,9 @@ GenTreeFlags Compiler::gtTokenToIconFlags(unsigned token)
77277727
// gtNewIndOfIconHandleNode: Creates an indirection GenTree node of a constant handle
77287728
//
77297729
// Arguments:
7730-
// indType - The type returned by the indirection node
7731-
// addr - The constant address to read from
7732-
// iconFlags - The GTF_ICON flag value that specifies the kind of handle that we have
7733-
// isInvariant - The indNode should also be marked as invariant
7730+
// indType - The type returned by the indirection node
7731+
// addr - The constant address to read from
7732+
// iconFlags - The GTF_ICON flag value that specifies the kind of handle that we have
77347733
//
77357734
// Return Value:
77367735
// Returns a GT_IND node representing value at the address provided by 'addr'
@@ -7739,21 +7738,17 @@ GenTreeFlags Compiler::gtTokenToIconFlags(unsigned token)
77397738
// The GT_IND node is marked as non-faulting.
77407739
// If the indirection is not invariant, we also mark the indNode as GTF_GLOB_REF.
77417740
//
7742-
GenTree* Compiler::gtNewIndOfIconHandleNode(var_types indType, size_t addr, GenTreeFlags iconFlags, bool isInvariant)
7741+
GenTree* Compiler::gtNewIndOfIconHandleNode(var_types indType, size_t addr, GenTreeFlags iconFlags)
77437742
{
77447743
GenTree* addrNode = gtNewIconHandleNode(addr, iconFlags);
77457744
GenTreeFlags indirFlags = GTF_IND_NONFAULTING; // This indirection won't cause an exception.
7746-
7747-
if (isInvariant)
7745+
if (GenTree::HandleKindDataIsInvariant(iconFlags))
77487746
{
7749-
// This indirection also is invariant.
77507747
indirFlags |= GTF_IND_INVARIANT;
7751-
7752-
if (iconFlags == GTF_ICON_STR_HDL)
7753-
{
7754-
// String literals are never null
7755-
indirFlags |= GTF_IND_NONNULL;
7756-
}
7748+
}
7749+
if (GenTree::HandleKindDataIsNotNull(iconFlags))
7750+
{
7751+
indirFlags |= GTF_IND_NONNULL;
77577752
}
77587753

77597754
GenTree* indNode = gtNewIndir(indType, addrNode, indirFlags);
@@ -7823,13 +7818,13 @@ GenTree* Compiler::gtNewStringLiteralNode(InfoAccessType iat, void* pValue)
78237818

78247819
case IAT_PVALUE: // The value needs to be accessed via an indirection
78257820
// Create an indirection
7826-
tree = gtNewIndOfIconHandleNode(TYP_REF, (size_t)pValue, GTF_ICON_STR_HDL, true);
7821+
tree = gtNewIndOfIconHandleNode(TYP_REF, (size_t)pValue, GTF_ICON_STR_HDL);
78277822
INDEBUG(tree->gtGetOp1()->AsIntCon()->gtTargetHandle = (size_t)pValue);
78287823
break;
78297824

78307825
case IAT_PPVALUE: // The value needs to be accessed via a double indirection
78317826
// Create the first indirection.
7832-
tree = gtNewIndOfIconHandleNode(TYP_I_IMPL, (size_t)pValue, GTF_ICON_CONST_PTR, true);
7827+
tree = gtNewIndOfIconHandleNode(TYP_I_IMPL, (size_t)pValue, GTF_ICON_CONST_PTR);
78337828
INDEBUG(tree->gtGetOp1()->AsIntCon()->gtTargetHandle = (size_t)pValue);
78347829
// Create the second indirection.
78357830
tree = gtNewIndir(TYP_REF, tree, GTF_IND_NONFAULTING | GTF_IND_INVARIANT | GTF_IND_NONNULL);
@@ -10835,45 +10830,35 @@ void GenTree::SetIndirExceptionFlags(Compiler* comp)
1083510830
}
1083610831
}
1083710832

10833+
static const uint8_t g_handleKindsFlags[] = {
10834+
#define HANDLE_KIND(name, description, flags) flags,
10835+
#include "handlekinds.h"
10836+
};
10837+
1083810838
//------------------------------------------------------------------------------
10839-
// HandleKindDataIsInvariant: Returns true if the data referred to by a handle
10839+
// HandleKindDataIsInvariant: Returns true if the data pointed to by a handle
1084010840
// address is guaranteed to be invariant.
1084110841
//
1084210842
// Arguments:
10843-
// flags - GenTree flags for handle.
10843+
// flags - the handle kind
1084410844
//
10845-
/* static */
1084610845
bool GenTree::HandleKindDataIsInvariant(GenTreeFlags flags)
1084710846
{
10848-
GenTreeFlags handleKind = flags & GTF_ICON_HDL_MASK;
10849-
assert(handleKind != GTF_EMPTY);
10847+
unsigned handleKindIndex = HandleKindToHandleKindIndex(flags);
10848+
return (g_handleKindsFlags[handleKindIndex] & HKF_INVARIANT) != 0;
10849+
}
1085010850

10851-
switch (handleKind)
10852-
{
10853-
case GTF_ICON_SCOPE_HDL:
10854-
case GTF_ICON_CLASS_HDL:
10855-
case GTF_ICON_METHOD_HDL:
10856-
case GTF_ICON_FIELD_HDL:
10857-
case GTF_ICON_STR_HDL:
10858-
case GTF_ICON_CONST_PTR:
10859-
case GTF_ICON_VARG_HDL:
10860-
case GTF_ICON_PINVKI_HDL:
10861-
case GTF_ICON_TOKEN_HDL:
10862-
case GTF_ICON_TLS_HDL:
10863-
case GTF_ICON_CIDMID_HDL:
10864-
case GTF_ICON_FIELD_SEQ:
10865-
case GTF_ICON_STATIC_ADDR_PTR:
10866-
case GTF_ICON_SECREL_OFFSET:
10867-
case GTF_ICON_TLSGD_OFFSET:
10868-
return true;
10869-
case GTF_ICON_FTN_ADDR:
10870-
case GTF_ICON_GLOBAL_PTR:
10871-
case GTF_ICON_STATIC_HDL:
10872-
case GTF_ICON_BBC_PTR:
10873-
case GTF_ICON_STATIC_BOX_PTR:
10874-
default:
10875-
return false;
10876-
}
10851+
//------------------------------------------------------------------------------
10852+
// HandleKindDataIsNotNull: Returns true if the data pointed to by a handle
10853+
// address is guaranteed to be non-null if interpreted as a pointer.
10854+
//
10855+
// Arguments:
10856+
// flags - the handle kind
10857+
//
10858+
bool GenTree::HandleKindDataIsNotNull(GenTreeFlags flags)
10859+
{
10860+
unsigned handleKindIndex = HandleKindToHandleKindIndex(flags);
10861+
return (g_handleKindsFlags[handleKindIndex] & HKF_NONNULL) != 0;
1087710862
}
1087810863

1087910864
#ifdef DEBUG
@@ -10914,48 +10899,10 @@ const char* GenTree::gtGetHandleKindString(GenTreeFlags flags)
1091410899
{
1091510900
case 0:
1091610901
return "";
10917-
case GTF_ICON_SCOPE_HDL:
10918-
return "GTF_ICON_SCOPE_HDL";
10919-
case GTF_ICON_CLASS_HDL:
10920-
return "GTF_ICON_CLASS_HDL";
10921-
case GTF_ICON_METHOD_HDL:
10922-
return "GTF_ICON_METHOD_HDL";
10923-
case GTF_ICON_FIELD_HDL:
10924-
return "GTF_ICON_FIELD_HDL";
10925-
case GTF_ICON_STATIC_HDL:
10926-
return "GTF_ICON_STATIC_HDL";
10927-
case GTF_ICON_STR_HDL:
10928-
return "GTF_ICON_STR_HDL";
10929-
case GTF_ICON_OBJ_HDL:
10930-
return "GTF_ICON_OBJ_HDL";
10931-
case GTF_ICON_CONST_PTR:
10932-
return "GTF_ICON_CONST_PTR";
10933-
case GTF_ICON_GLOBAL_PTR:
10934-
return "GTF_ICON_GLOBAL_PTR";
10935-
case GTF_ICON_VARG_HDL:
10936-
return "GTF_ICON_VARG_HDL";
10937-
case GTF_ICON_PINVKI_HDL:
10938-
return "GTF_ICON_PINVKI_HDL";
10939-
case GTF_ICON_TOKEN_HDL:
10940-
return "GTF_ICON_TOKEN_HDL";
10941-
case GTF_ICON_TLS_HDL:
10942-
return "GTF_ICON_TLS_HDL";
10943-
case GTF_ICON_FTN_ADDR:
10944-
return "GTF_ICON_FTN_ADDR";
10945-
case GTF_ICON_CIDMID_HDL:
10946-
return "GTF_ICON_CIDMID_HDL";
10947-
case GTF_ICON_BBC_PTR:
10948-
return "GTF_ICON_BBC_PTR";
10949-
case GTF_ICON_STATIC_BOX_PTR:
10950-
return "GTF_ICON_STATIC_BOX_PTR";
10951-
case GTF_ICON_FIELD_SEQ:
10952-
return "GTF_ICON_FIELD_SEQ";
10953-
case GTF_ICON_STATIC_ADDR_PTR:
10954-
return "GTF_ICON_STATIC_ADDR_PTR";
10955-
case GTF_ICON_SECREL_OFFSET:
10956-
return "GTF_ICON_SECREL_OFFSET";
10957-
case GTF_ICON_TLSGD_OFFSET:
10958-
return "GTF_ICON_TLSGD_OFFSET";
10902+
#define HANDLE_KIND(name, description, flags) \
10903+
case name: \
10904+
return #name;
10905+
#include "handlekinds.h"
1095910906
default:
1096010907
return "ILLEGAL!";
1096110908
}
@@ -12088,7 +12035,7 @@ void Compiler::gtDispConst(GenTree* tree)
1208812035
}
1208912036
else if (tree->IsIconHandle(GTF_ICON_OBJ_HDL))
1209012037
{
12091-
eePrintObjectDescription(" ", (CORINFO_OBJECT_HANDLE)tree->AsIntCon()->gtIconVal);
12038+
eePrintObjectDescription(" ", CORINFO_OBJECT_HANDLE(tree->AsIntCon()->IconValue()));
1209212039
}
1209312040
else
1209412041
{
@@ -12135,93 +12082,43 @@ void Compiler::gtDispConst(GenTree* tree)
1213512082
}
1213612083
}
1213712084

12138-
if (tree->IsIconHandle())
12085+
switch (tree->GetIconHandleFlag())
1213912086
{
12140-
switch (tree->GetIconHandleFlag())
12141-
{
12142-
case GTF_ICON_SCOPE_HDL:
12143-
printf(" scope");
12144-
break;
12145-
case GTF_ICON_CLASS_HDL:
12146-
if (IsAot())
12147-
{
12148-
printf(" class");
12149-
}
12150-
else
12151-
{
12152-
printf(" class %s", eeGetClassName((CORINFO_CLASS_HANDLE)iconVal));
12153-
}
12154-
break;
12155-
case GTF_ICON_METHOD_HDL:
12156-
if (IsAot())
12157-
{
12158-
printf(" method");
12159-
}
12160-
else
12161-
{
12162-
printf(" method %s", eeGetMethodFullName((CORINFO_METHOD_HANDLE)iconVal));
12163-
}
12164-
break;
12165-
case GTF_ICON_FIELD_HDL:
12166-
if (IsAot())
12167-
{
12168-
printf(" field");
12169-
}
12170-
else
12171-
{
12172-
printf(" field %s", eeGetFieldName((CORINFO_FIELD_HANDLE)iconVal, true));
12173-
}
12174-
break;
12175-
case GTF_ICON_STATIC_HDL:
12176-
printf(" static");
12177-
break;
12178-
case GTF_ICON_OBJ_HDL:
12179-
case GTF_ICON_STR_HDL:
12180-
unreached(); // These cases are handled above
12181-
break;
12182-
case GTF_ICON_CONST_PTR:
12183-
printf(" const ptr");
12184-
break;
12185-
case GTF_ICON_GLOBAL_PTR:
12186-
printf(" global ptr");
12187-
break;
12188-
case GTF_ICON_VARG_HDL:
12189-
printf(" vararg");
12190-
break;
12191-
case GTF_ICON_PINVKI_HDL:
12192-
printf(" pinvoke");
12193-
break;
12194-
case GTF_ICON_TOKEN_HDL:
12195-
printf(" token");
12196-
break;
12197-
case GTF_ICON_TLS_HDL:
12198-
printf(" tls");
12199-
break;
12200-
case GTF_ICON_FTN_ADDR:
12201-
printf(" ftn");
12202-
break;
12203-
case GTF_ICON_CIDMID_HDL:
12204-
printf(" cid/mid");
12205-
break;
12206-
case GTF_ICON_BBC_PTR:
12207-
printf(" bbc");
12208-
break;
12209-
case GTF_ICON_STATIC_BOX_PTR:
12210-
printf(" static box ptr");
12211-
break;
12212-
case GTF_ICON_STATIC_ADDR_PTR:
12213-
printf(" static base addr cell");
12214-
break;
12215-
case GTF_ICON_SECREL_OFFSET:
12216-
printf(" relative offset in section");
12217-
break;
12218-
case GTF_ICON_TLSGD_OFFSET:
12219-
printf(" tls global dynamic offset");
12220-
break;
12221-
default:
12222-
printf(" UNKNOWN");
12223-
break;
12224-
}
12087+
case GTF_EMPTY:
12088+
break;
12089+
#define HANDLE_KIND(name, description, flags) \
12090+
case name: \
12091+
printf(" %s", description); \
12092+
break;
12093+
#include "handlekinds.h"
12094+
default:
12095+
printf(" ILLEGAL");
12096+
break;
12097+
}
12098+
12099+
// Print additional details for some handles.
12100+
switch (tree->GetIconHandleFlag())
12101+
{
12102+
case GTF_ICON_CLASS_HDL:
12103+
if (!IsAot())
12104+
{
12105+
printf(" %s", eeGetClassName((CORINFO_CLASS_HANDLE)iconVal));
12106+
}
12107+
break;
12108+
case GTF_ICON_METHOD_HDL:
12109+
if (!IsAot())
12110+
{
12111+
printf(" %s", eeGetMethodFullName((CORINFO_METHOD_HANDLE)iconVal));
12112+
}
12113+
break;
12114+
case GTF_ICON_FIELD_HDL:
12115+
if (!IsAot())
12116+
{
12117+
printf(" %s", eeGetFieldName((CORINFO_FIELD_HANDLE)iconVal, true));
12118+
}
12119+
break;
12120+
default:
12121+
break;
1222512122
}
1222612123

1222712124
#ifdef FEATURE_SIMD

0 commit comments

Comments
 (0)