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

JIT: inline shared generics with runtime lookups inside #99265

Merged
merged 45 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
5095668
Simpler change
EgorBo Mar 5, 2024
4bc4269
Address feedback
EgorBo Mar 6, 2024
4f3353f
clean up
EgorBo Mar 8, 2024
c4b9997
Address feedback
EgorBo Mar 8, 2024
0693f89
Clean up
EgorBo Mar 8, 2024
f300235
fix build
EgorBo Mar 8, 2024
6da6055
clean up
EgorBo Mar 8, 2024
f0da192
Class context?
EgorBo Mar 9, 2024
99f89fc
Disable class context
EgorBo Mar 9, 2024
93b199b
Add containingMd to embedGenericHandle
EgorBo Mar 9, 2024
728272e
clean up
EgorBo Mar 9, 2024
7c4e36d
initial NAOT support
EgorBo Mar 9, 2024
0283ae7
Implement NAOT
EgorBo Mar 9, 2024
cd51417
Clean up
EgorBo Mar 9, 2024
b94506d
Cleanup getRuntimeContextTree
EgorBo Mar 9, 2024
5cda9bf
Merge branch 'main' into shared-generics-2
EgorBo Mar 9, 2024
cfe264e
Enable for R2R as well
EgorBo Mar 9, 2024
b20a859
Merge branch 'main' of github.com:dotnet/runtime into shared-generics-2
EgorBo Mar 9, 2024
366ad39
Address feedback
EgorBo Mar 9, 2024
183925a
clean up
EgorBo Mar 9, 2024
455f69b
Merge branch 'main' into shared-generics-2
EgorBo Mar 9, 2024
9078bdb
fix jit assert
EgorBo Mar 11, 2024
9daffaa
Merge branch 'shared-generics-2' of github.com:EgorBo/runtime-1 into …
EgorBo Mar 11, 2024
550f8ff
repro
EgorBo Mar 11, 2024
410ce12
fix repro
EgorBo Mar 11, 2024
2e540ec
Add CallerHandle to getReadyToRunHelper
EgorBo Mar 11, 2024
66e6dc3
add to getReadyToRunDelegateCtorHelper as well
EgorBo Mar 11, 2024
369f763
formatting
EgorBo Mar 11, 2024
478ef85
Like this (it currently fails)
EgorBo Mar 12, 2024
44186cb
Update src/coreclr/jit/importer.cpp
EgorBo Mar 12, 2024
4fb9a13
fix build
EgorBo Mar 12, 2024
893172c
Fix build
EgorBo Mar 12, 2024
a4a1aa5
Revert "Fix build"
MichalStrehovsky Mar 12, 2024
18c03d0
Revert "fix build"
MichalStrehovsky Mar 12, 2024
32828c4
Revert "Like this (it currently fails)"
MichalStrehovsky Mar 12, 2024
e9d7e87
Revert "fix repro"
MichalStrehovsky Mar 12, 2024
874c339
Revert "repro"
MichalStrehovsky Mar 12, 2024
0f45539
Better fix
MichalStrehovsky Mar 12, 2024
0fb02aa
Address Jakob's feedback
EgorBo Mar 12, 2024
d635133
conservative version
EgorBo Mar 12, 2024
10492e3
make formatter happy
EgorBo Mar 12, 2024
ad38ae1
use GetMethod
EgorBo Mar 13, 2024
af79c6b
Merge branch 'main' of github.com:dotnet/runtime into shared-generics-2
EgorBo Mar 13, 2024
09efb81
Address feedback
EgorBo Mar 13, 2024
467cc06
Address Jan's feedback
EgorBo Mar 13, 2024
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
4 changes: 4 additions & 0 deletions src/coreclr/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2231,6 +2231,7 @@ class ICorStaticInfo
// should be looked up at runtime.
virtual void expandRawHandleIntrinsic(
CORINFO_RESOLVED_TOKEN * pResolvedToken,
CORINFO_METHOD_HANDLE callerHandle,
CORINFO_GENERICHANDLE_RESULT * pResult) = 0;

// Is the given type in System.Private.Corelib and marked with IntrinsicAttribute?
Expand Down Expand Up @@ -2647,13 +2648,15 @@ class ICorStaticInfo
CORINFO_RESOLVED_TOKEN * pResolvedToken,
CORINFO_LOOKUP_KIND * pGenericLookupKind,
CorInfoHelpFunc id,
CORINFO_METHOD_HANDLE callerHandle,
CORINFO_CONST_LOOKUP * pLookup
) = 0;

virtual void getReadyToRunDelegateCtorHelper(
CORINFO_RESOLVED_TOKEN * pTargetMethod,
mdToken targetConstraint,
CORINFO_CLASS_HANDLE delegateType,
CORINFO_METHOD_HANDLE callerHandle,
CORINFO_LOOKUP * pLookup
) = 0;

Expand Down Expand Up @@ -3193,6 +3196,7 @@ class ICorDynamicInfo : public ICorStaticInfo
virtual void embedGenericHandle(
CORINFO_RESOLVED_TOKEN * pResolvedToken,
bool fEmbedParent, // `true` - embeds parent type handle of the field/method handle
CORINFO_METHOD_HANDLE callerHandle,
CORINFO_GENERICHANDLE_RESULT * pResult
) = 0;

Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/inc/icorjitinfoimpl_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ CORINFO_CLASS_HANDLE getDefaultEqualityComparerClass(

void expandRawHandleIntrinsic(
CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_METHOD_HANDLE callerHandle,
CORINFO_GENERICHANDLE_RESULT* pResult) override;

bool isIntrinsicType(
Expand Down Expand Up @@ -297,12 +298,14 @@ bool getReadyToRunHelper(
CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_LOOKUP_KIND* pGenericLookupKind,
CorInfoHelpFunc id,
CORINFO_METHOD_HANDLE callerHandle,
CORINFO_CONST_LOOKUP* pLookup) override;

void getReadyToRunDelegateCtorHelper(
CORINFO_RESOLVED_TOKEN* pTargetMethod,
mdToken targetConstraint,
CORINFO_CLASS_HANDLE delegateType,
CORINFO_METHOD_HANDLE callerHandle,
CORINFO_LOOKUP* pLookup) override;

CorInfoInitClassResult initClass(
Expand Down Expand Up @@ -560,6 +563,7 @@ CORINFO_FIELD_HANDLE embedFieldHandle(
void embedGenericHandle(
CORINFO_RESOLVED_TOKEN* pResolvedToken,
bool fEmbedParent,
CORINFO_METHOD_HANDLE callerHandle,
CORINFO_GENERICHANDLE_RESULT* pResult) override;

void getLocationOfThisType(
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 = { /* e5f629d4-edc8-48f1-a75d-0fa1f0b5af6f */
0xe5f629d4,
0xedc8,
0x48f1,
{0xa7, 0x5d, 0x0f, 0xa1, 0xf0, 0xb5, 0xaf, 0x6f}
constexpr GUID JITEEVersionIdentifier = { /* 35afdf61-5417-4bd7-9302-48efa2507603 */
0x35afdf61,
0x5417,
0x4bd7,
{0x93, 0x02, 0x48, 0xef, 0xa2, 0x50, 0x76, 0x03}
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
12 changes: 8 additions & 4 deletions src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,11 @@ CORINFO_CLASS_HANDLE WrapICorJitInfo::getDefaultEqualityComparerClass(

void WrapICorJitInfo::expandRawHandleIntrinsic(
CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_METHOD_HANDLE callerHandle,
CORINFO_GENERICHANDLE_RESULT* pResult)
{
API_ENTER(expandRawHandleIntrinsic);
wrapHnd->expandRawHandleIntrinsic(pResolvedToken, pResult);
wrapHnd->expandRawHandleIntrinsic(pResolvedToken, callerHandle, pResult);
API_LEAVE(expandRawHandleIntrinsic);
}

Expand Down Expand Up @@ -687,10 +688,11 @@ bool WrapICorJitInfo::getReadyToRunHelper(
CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_LOOKUP_KIND* pGenericLookupKind,
CorInfoHelpFunc id,
CORINFO_METHOD_HANDLE callerHandle,
CORINFO_CONST_LOOKUP* pLookup)
{
API_ENTER(getReadyToRunHelper);
bool temp = wrapHnd->getReadyToRunHelper(pResolvedToken, pGenericLookupKind, id, pLookup);
bool temp = wrapHnd->getReadyToRunHelper(pResolvedToken, pGenericLookupKind, id, callerHandle, pLookup);
API_LEAVE(getReadyToRunHelper);
return temp;
}
Expand All @@ -699,10 +701,11 @@ void WrapICorJitInfo::getReadyToRunDelegateCtorHelper(
CORINFO_RESOLVED_TOKEN* pTargetMethod,
mdToken targetConstraint,
CORINFO_CLASS_HANDLE delegateType,
CORINFO_METHOD_HANDLE callerHandle,
CORINFO_LOOKUP* pLookup)
{
API_ENTER(getReadyToRunDelegateCtorHelper);
wrapHnd->getReadyToRunDelegateCtorHelper(pTargetMethod, targetConstraint, delegateType, pLookup);
wrapHnd->getReadyToRunDelegateCtorHelper(pTargetMethod, targetConstraint, delegateType, callerHandle, pLookup);
API_LEAVE(getReadyToRunDelegateCtorHelper);
}

Expand Down Expand Up @@ -1330,10 +1333,11 @@ CORINFO_FIELD_HANDLE WrapICorJitInfo::embedFieldHandle(
void WrapICorJitInfo::embedGenericHandle(
CORINFO_RESOLVED_TOKEN* pResolvedToken,
bool fEmbedParent,
CORINFO_METHOD_HANDLE callerHandle,
CORINFO_GENERICHANDLE_RESULT* pResult)
{
API_ENTER(embedGenericHandle);
wrapHnd->embedGenericHandle(pResolvedToken, fEmbedParent, pResult);
wrapHnd->embedGenericHandle(pResolvedToken, fEmbedParent, callerHandle, pResult);
API_LEAVE(embedGenericHandle);
}

Expand Down
10 changes: 6 additions & 4 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3440,7 +3440,7 @@ class Compiler
GenTreeAllocObj* gtNewAllocObjNode(
unsigned int helper, bool helperHasSideEffects, CORINFO_CLASS_HANDLE clsHnd, var_types type, GenTree* op1);

GenTreeAllocObj* gtNewAllocObjNode(CORINFO_RESOLVED_TOKEN* pResolvedToken, bool useParent);
GenTreeAllocObj* gtNewAllocObjNode(CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_METHOD_HANDLE callerHandle, bool useParent);

GenTree* gtNewRuntimeLookup(CORINFO_GENERIC_HANDLE hnd, CorInfoGenericHandleType hndTyp, GenTree* lookupTree);

Expand Down Expand Up @@ -4923,7 +4923,7 @@ class Compiler

unsigned impInlineFetchLocal(unsigned lclNum DEBUGARG(const char* reason));

GenTree* impInlineFetchArg(unsigned lclNum, InlArgInfo* inlArgInfo, InlLclVarInfo* lclTypeInfo);
GenTree* impInlineFetchArg(InlArgInfo& argInfo, const InlLclVarInfo& lclInfo);

bool impInlineIsThis(GenTree* tree, InlArgInfo* inlArgInfo);

Expand Down Expand Up @@ -6629,6 +6629,7 @@ class Compiler

void fgInvokeInlineeCompiler(GenTreeCall* call, InlineResult* result, InlineContext** createdContext);
void fgInsertInlineeBlocks(InlineInfo* pInlineInfo);
void fgInsertInlineeArgument(const InlArgInfo& argInfo, BasicBlock* block, Statement** afterStmt, Statement** newStmt, const DebugInfo& callDI);
Statement* fgInlinePrependStatements(InlineInfo* inlineInfo);
void fgInlineAppendStatements(InlineInfo* inlineInfo, BasicBlock* block, Statement* stmt);

Expand Down Expand Up @@ -10217,8 +10218,9 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
unsigned compArgStackSize; // Incoming argument stack size in bytes
#endif // FEATURE_FASTTAILCALL

unsigned compRetBuffArg; // position of hidden return param var (0, 1) (BAD_VAR_NUM means not present);
int compTypeCtxtArg; // position of hidden param for type context for generic code (CORINFO_CALLCONV_PARAMTYPE)
unsigned compRetBuffArg; // position of hidden return param var (0, 1) (BAD_VAR_NUM means not present);
unsigned compTypeCtxtArg; // position of hidden param for type context for generic code
// (CORINFO_CALLCONV_PARAMTYPE)
unsigned compThisArg; // position of implicit this pointer param (not to be confused with lvaArg0Var)
unsigned compILlocalsCount; // Number of vars : args + locals (incl. implicit but not hidden)
unsigned compLocalsCount; // Number of vars : args + locals (incl. implicit and hidden)
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/jit/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2443,7 +2443,7 @@ inline bool Compiler::lvaReportParamTypeArg()
{
if (info.compMethodInfo->options & (CORINFO_GENERICS_CTXT_FROM_METHODDESC | CORINFO_GENERICS_CTXT_FROM_METHODTABLE))
{
assert(info.compTypeCtxtArg != -1);
assert(info.compTypeCtxtArg != BAD_VAR_NUM);

// If the VM requires us to keep the generics context alive and report it (for example, if any catch
// clause catches a type that uses a generic parameter of this method) this flag will be set.
Expand Down Expand Up @@ -2773,13 +2773,13 @@ inline unsigned Compiler::compMapILargNum(unsigned ILargNum)
assert(ILargNum < info.compLocalsCount); // compLocals count already adjusted.
}

if (ILargNum >= (unsigned)info.compTypeCtxtArg)
if (ILargNum >= info.compTypeCtxtArg)
{
ILargNum++;
assert(ILargNum < info.compLocalsCount); // compLocals count already adjusted.
}

if (ILargNum >= (unsigned)lvaVarargsHandleArg)
if (ILargNum >= lvaVarargsHandleArg)
{
ILargNum++;
assert(ILargNum < info.compLocalsCount); // compLocals count already adjusted.
Expand Down
Loading
Loading