Skip to content
Closed
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
1 change: 1 addition & 0 deletions src/coreclr/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,7 @@ struct CORINFO_FIELD_INFO
CORINFO_HELPER_DESC accessCalloutHelper;

CORINFO_CONST_LOOKUP fieldLookup; // Used by Ready-to-Run
bool useEnclosingTypeOnly; // Used by NativeAOT
};

//----------------------------------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions src/coreclr/inc/jiteeversionguid.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ typedef const GUID *LPCGUID;
#define GUID_DEFINED
#endif // !GUID_DEFINED

constexpr GUID JITEEVersionIdentifier = { /* e15e62ce-d9c6-418a-a5a7-26ad17fcf4bf */
0xe15e62ce,
0xd9c6,
0x418a,
{0xa5, 0xa7, 0x26, 0xad, 0x17, 0xfc, 0xf4, 0xbf}
constexpr GUID JITEEVersionIdentifier = { /* 315babf8-3790-4267-a046-c13271a0be49 */
0x315babf8,
0x3790,
0x4267,
{0xa0, 0x46, 0xc1, 0x32, 0x71, 0xa0, 0xbe, 0x49}
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
16 changes: 16 additions & 0 deletions src/coreclr/jit/gentree.h
Original file line number Diff line number Diff line change
Expand Up @@ -4078,6 +4078,7 @@ enum GenTreeCallFlags : unsigned int
GTF_CALL_M_EXPANDED_EARLY = 0x00800000, // the Virtual Call target address is expanded and placed in gtControlExpr in Morph rather than in Lower
GTF_CALL_M_HAS_LATE_DEVIRT_INFO = 0x01000000, // this call has late devirtualzation info
GTF_CALL_M_LDVIRTFTN_INTERFACE = 0x02000000, // ldvirtftn on an interface type
GTF_CALL_M_ENCLOSING_TYPE_ONLY = 0x04000000, // helper call needs enclosing type as parameter
};

inline constexpr GenTreeCallFlags operator ~(GenTreeCallFlags a)
Expand Down Expand Up @@ -5450,6 +5451,21 @@ struct GenTreeCall final : public GenTree
return (gtCallMoreFlags & GTF_CALL_M_EXP_RUNTIME_LOOKUP) != 0;
}

void SetArgNeedsEnclosingType()
{
gtCallMoreFlags |= GTF_CALL_M_ENCLOSING_TYPE_ONLY;
}

void ClearArgNeedsEnclosingType()
{
gtCallMoreFlags &= ~GTF_CALL_M_ENCLOSING_TYPE_ONLY;
}

bool IsArgNeedsEnclosingType() const
{
return (gtCallMoreFlags & GTF_CALL_M_ENCLOSING_TYPE_ONLY) != 0;
}

void SetExpandedEarly()
{
gtCallMoreFlags |= GTF_CALL_M_EXPANDED_EARLY;
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3859,6 +3859,10 @@ GenTree* Compiler::impImportStaticFieldAddress(CORINFO_RESOLVED_TOKEN* pResolved
{
// Keep class handle attached to the helper call since it's difficult to restore it.
op1->AsCall()->gtInitClsHnd = pResolvedToken->hClass;
if (pFieldInfo->useEnclosingTypeOnly)
{
op1->AsCall()->SetArgNeedsEnclosingType();
}
}

op1->gtFlags |= callFlags;
Expand Down
28 changes: 28 additions & 0 deletions src/coreclr/jit/valuenum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12301,6 +12301,7 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN
CallArgs* args = &call->gtArgs;
bool generateUniqueVN = false;
bool useEntryPointAddrAsArg0 = false;
bool useEnclosingTypeAsArg0 = false;

switch (vnf)
{
Expand Down Expand Up @@ -12362,6 +12363,26 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN

case VNF_ReadyToRunStaticBaseGC:
case VNF_ReadyToRunStaticBaseNonGC:
{
if (IsTargetAbi(CORINFO_NATIVEAOT_ABI))
{
// TODO: Do this for R2R as well
if (call->IsArgNeedsEnclosingType())
{
useEnclosingTypeAsArg0 = true;
assert((call->gtInitClsHnd != NO_CLASS_HANDLE) && ((ssize_t)call->gtInitClsHnd != 0xcccccccc));
}
else
{
useEntryPointAddrAsArg0 = true;
}
}
else
{
useEntryPointAddrAsArg0 = true;
}
}
break;
case VNF_ReadyToRunStaticBaseThread:
case VNF_ReadyToRunStaticBaseThreadNonGC:
case VNF_ReadyToRunGenericStaticBase:
Expand Down Expand Up @@ -12407,6 +12428,7 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN
// added this arg, so we do not need to use EntryPointAddrAsArg0
// because the indirection cell itself allows us to disambiguate.
useEntryPointAddrAsArg0 = false;
useEnclosingTypeAsArg0 = false;
}

CallArg* curArg = args->Args().begin().GetArg();
Expand All @@ -12433,6 +12455,12 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN
ValueNum callAddrVN = vnStore->VNForHandle(addrValue, GTF_ICON_FTN_ADDR);
vnp0 = ValueNumPair(callAddrVN, callAddrVN);
}
else if (useEnclosingTypeAsArg0)
{
ssize_t addrValue = (ssize_t)call->gtInitClsHnd;
ValueNum callAddrVN = vnStore->VNForHandle(addrValue, GTF_ICON_FTN_ADDR);
vnp0 = ValueNumPair(callAddrVN, callAddrVN);
}
else
#endif // FEATURE_READYTORUN
{
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,9 @@ public unsafe struct CORINFO_FIELD_INFO

// Used by Ready-to-Run
public CORINFO_CONST_LOOKUP fieldLookup;

// Used by NativeAOT
public bool useEnclosingTypeOnly;
};

public unsafe struct CORINFO_THREAD_STATIC_BLOCKS_INFO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2051,7 +2051,7 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET
CORINFO_FIELD_ACCESSOR fieldAccessor;
CORINFO_FIELD_FLAGS fieldFlags = (CORINFO_FIELD_FLAGS)0;
uint fieldOffset = (field.IsStatic && field.HasRva ? 0xBAADF00D : (uint)field.Offset.AsInt);

pResult->useEnclosingTypeOnly = false;
if (field.IsThreadStatic && field.OwningType is MetadataType mt)
{
fieldOffset += _compilation.NodeFactory.ThreadStaticBaseOffset(mt);
Expand Down Expand Up @@ -2175,6 +2175,7 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET

if (helperId != ReadyToRunHelperId.Invalid)
{
pResult->useEnclosingTypeOnly = true;
pResult->fieldLookup = CreateConstLookupToSymbol(
_compilation.NodeFactory.ReadyToRunHelper(helperId, field.OwningType));
}
Expand Down