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

NativeAOT: Optimize static fields of gc types #80969

Merged
merged 7 commits into from
Jan 23, 2023
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
5 changes: 5 additions & 0 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9592,6 +9592,11 @@ void cTreeFlags(Compiler* comp, GenTree* tree)
chars += printf("[GTF_ICON_STATIC_BOX_PTR]");
break;

case GTF_ICON_STATIC_ADDR_PTR:

chars += printf("[GTF_ICON_STATIC_ADDR_PTR]");
break;

default:
assert(!"a forgotten handle flag");
break;
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/jit/emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4189,6 +4189,12 @@ void emitter::emitDispCommentForHandle(size_t handle, size_t cookie, GenTreeFlag
printf("%s %s for %s", commentPrefix, flag == GTF_ICON_STATIC_HDL ? "data" : "box", fieldName);
return;
}

if (flag == GTF_ICON_STATIC_ADDR_PTR)
{
printf("%s static base addr cell", commentPrefix);
return;
}
}

if (handle == 0)
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11434,6 +11434,9 @@ void Compiler::gtDispConst(GenTree* tree)
case GTF_ICON_STATIC_BOX_PTR:
printf(" static box ptr");
break;
case GTF_ICON_STATIC_ADDR_PTR:
printf(" static base addr cell");
break;
default:
printf(" UNKNOWN");
break;
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/gentree.h
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ enum GenTreeFlags : unsigned int
GTF_ICON_BBC_PTR = 0x0F000000, // GT_CNS_INT -- constant is a basic block count pointer
GTF_ICON_STATIC_BOX_PTR = 0x10000000, // GT_CNS_INT -- constant is an address of the box for a STATIC_IN_HEAP field
GTF_ICON_FIELD_SEQ = 0x11000000, // <--------> -- constant is a FieldSeq* (used only as VNHandle)
GTF_ICON_STATIC_ADDR_PTR = 0x13000000, // GT_CNS_INT -- constant is a pointer to a static base address

// GTF_ICON_REUSE_REG_VAL = 0x00800000 // GT_CNS_INT -- GTF_REUSE_REG_VAL, defined above
GTF_ICON_SIMD_COUNT = 0x00200000, // GT_CNS_INT -- constant is Vector<T>.Count
Expand Down
16 changes: 12 additions & 4 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4238,13 +4238,21 @@ GenTree* Compiler::impImportStaticFieldAccess(CORINFO_RESOLVED_TOKEN* pResolvedT
case CORINFO_FIELD_STATIC_RELOCATABLE:
{
#ifdef FEATURE_READYTORUN
assert(pFieldInfo->fieldLookup.accessType == InfoAccessType::IAT_VALUE);
assert(fieldKind == FieldSeq::FieldKind::SimpleStatic);
assert(innerFldSeq != nullptr);

GenTree* baseAddr = gtNewIconHandleNode((size_t)pFieldInfo->fieldLookup.addr, GTF_ICON_STATIC_HDL);
GenTree* offset = gtNewIconNode(pFieldInfo->offset, innerFldSeq);
op1 = gtNewOperNode(GT_ADD, TYP_I_IMPL, baseAddr, offset);
size_t fldAddr = (size_t)pFieldInfo->fieldLookup.addr;
if (pFieldInfo->fieldLookup.accessType == IAT_VALUE)
{
op1 = gtNewIconHandleNode(fldAddr, GTF_ICON_STATIC_HDL);
}
else
{
assert(pFieldInfo->fieldLookup.accessType == IAT_PVALUE);
op1 = gtNewIndOfIconHandleNode(TYP_I_IMPL, fldAddr, GTF_ICON_STATIC_ADDR_PTR, true);
}
GenTree* offset = gtNewIconNode(pFieldInfo->offset, innerFldSeq);
op1 = gtNewOperNode(GT_ADD, TYP_I_IMPL, op1, offset);
#else
unreached();
#endif // FEATURE_READYTORUN
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/valuenum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5360,6 +5360,7 @@ GenTreeFlags ValueNumStore::GetFoldedArithOpResultHandleFlags(ValueNum vn)
case GTF_ICON_CIDMID_HDL:
case GTF_ICON_TLS_HDL:
case GTF_ICON_STATIC_BOX_PTR:
case GTF_ICON_STATIC_ADDR_PTR:
return GTF_ICON_CONST_PTR;
case GTF_ICON_STATIC_HDL:
case GTF_ICON_GLOBAL_PTR:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2141,12 +2141,21 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET
pResult->helper = CorInfoHelpFunc.CORINFO_HELP_READYTORUN_THREADSTATIC_BASE;
helperId = ReadyToRunHelperId.GetThreadStaticBase;
}
else if (!_compilation.HasLazyStaticConstructor(field.OwningType) && !field.HasGCStaticBase)
else if (!_compilation.HasLazyStaticConstructor(field.OwningType))
{
fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_RELOCATABLE;
ISymbolNode baseAddress = _compilation.NodeFactory.TypeNonGCStaticsSymbol((MetadataType)field.OwningType);
pResult->fieldLookup.accessType = InfoAccessType.IAT_VALUE;
pResult->fieldLookup.addr = (void*)ObjectToHandle(baseAddress);
ISymbolNode baseAddr;
if (field.HasGCStaticBase)
{
pResult->fieldLookup.accessType = InfoAccessType.IAT_PVALUE;
baseAddr = _compilation.NodeFactory.TypeGCStaticsSymbol((MetadataType)field.OwningType);
}
else
{
pResult->fieldLookup.accessType = InfoAccessType.IAT_VALUE;
baseAddr = _compilation.NodeFactory.TypeNonGCStaticsSymbol((MetadataType)field.OwningType);
}
pResult->fieldLookup.addr = (void*)ObjectToHandle(baseAddr);
}
else
{
Expand Down