Skip to content

Commit

Permalink
Simpler change
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo committed Mar 5, 2024
1 parent 68f7885 commit 5095668
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
13 changes: 13 additions & 0 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1570,6 +1570,19 @@ GenTree* Compiler::getRuntimeContextTree(CORINFO_RUNTIME_LOOKUP_KIND kind)
{
assert(kind == CORINFO_LOOKUP_METHODPARAM || kind == CORINFO_LOOKUP_CLASSPARAM);

if (compIsForInlining() && (kind == CORINFO_LOOKUP_METHODPARAM))
{
// Grab the generic context from the callsite for current inlinee
CallArg* instParam = impInlineInfo->iciCall->gtArgs.FindWellKnownArg(WellKnownArg::InstParam);
if (instParam != nullptr)
{
assert(instParam->GetNode()->OperIs(GT_LCL_VAR));
ctxTree = gtNewLclvNode(instParam->GetNode()->AsLclVar()->GetLclNum(), TYP_I_IMPL);
ctxTree->gtFlags |= GTF_VAR_CONTEXT;
return ctxTree;
}
}

// Exact method descriptor as passed in
ctxTree = gtNewLclvNode(pRoot->info.compTypeCtxtArg, TYP_I_IMPL);
ctxTree->gtFlags |= GTF_VAR_CONTEXT;
Expand Down
11 changes: 11 additions & 0 deletions src/coreclr/jit/importercalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6730,6 +6730,17 @@ void Compiler::impMarkInlineCandidate(GenTree* callNode,
// candidate, we're done.
if (call->IsInlineCandidate() || !call->IsGuardedDevirtualizationCandidate())
{
// Runtime lookup is expected to be spilled into a temp for inline candidates.
CallArg* instParam = call->gtArgs.FindWellKnownArg(WellKnownArg::InstParam);
if ((instParam != nullptr) && instParam->GetNode()->OperIs(GT_RUNTIMELOOKUP))
{
const unsigned lookupTmp = lvaGrabTemp(true DEBUGARG("spilling runtimelookup"));
impStoreTemp(lookupTmp, instParam->GetNode(), CHECK_SPILL_NONE);
GenTreeLclVar* lcl = gtNewLclvNode(lookupTmp, TYP_I_IMPL);
lcl->gtFlags |= GTF_VAR_CONTEXT;
instParam->SetEarlyNode(lcl);
}

return;
}

Expand Down
20 changes: 13 additions & 7 deletions src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3086,24 +3086,30 @@ void CEEInfo::ComputeRuntimeLookupForSharedGenericToken(DictionaryEntryKind entr
// Unless we decide otherwise, just do the lookup via a helper function
pResult->indirections = CORINFO_USEHELPER;

// Runtime lookups in inlined contexts are not supported by the runtime for now
if (pResolvedToken->tokenContext != METHOD_BEING_COMPILED_CONTEXT())
MethodDesc* pContextMD = GetMethodFromContext(pResolvedToken->tokenContext);
if (pContextMD == nullptr)
{
// Class context is not yet supported
pResultLookup->lookupKind.runtimeLookupKind = CORINFO_LOOKUP_NOT_SUPPORTED;
return;
}

MethodDesc* pContextMD = GetMethodFromContext(pResolvedToken->tokenContext);
bool inlinedRuntimeLookup = pResolvedToken->tokenContext != METHOD_BEING_COMPILED_CONTEXT();
MethodTable* pContextMT = pContextMD->GetMethodTable();
bool isStaticVirtual = (pConstrainedResolvedToken != nullptr && pContextMD != nullptr && pContextMD->IsStatic());

if (inlinedRuntimeLookup && !pContextMD->HasMethodInstantiation())
{
pResultLookup->lookupKind.runtimeLookupKind = CORINFO_LOOKUP_NOT_SUPPORTED;
return;
}

// There is a pathological case where invalid IL refereces __Canon type directly, but there is no dictionary availabled to store the lookup.
if (!pContextMD->IsSharedByGenericInstantiations())
if (!inlinedRuntimeLookup && !pContextMD->IsSharedByGenericInstantiations())
COMPlusThrow(kInvalidProgramException);

BOOL fInstrument = FALSE;

if (pContextMD->RequiresInstMethodDescArg())
if (pContextMD->RequiresInstMethodDescArg() || inlinedRuntimeLookup)
{
pResultLookup->lookupKind.runtimeLookupKind = CORINFO_LOOKUP_METHODPARAM;
}
Expand All @@ -3116,7 +3122,7 @@ void CEEInfo::ComputeRuntimeLookupForSharedGenericToken(DictionaryEntryKind entr
}

// If we've got a method type parameter of any kind then we must look in the method desc arg
if (pContextMD->RequiresInstMethodDescArg())
if (pContextMD->RequiresInstMethodDescArg() || inlinedRuntimeLookup)
{
pResult->helper = fInstrument ? CORINFO_HELP_RUNTIMEHANDLE_METHOD_LOG : CORINFO_HELP_RUNTIMEHANDLE_METHOD;

Expand Down

0 comments on commit 5095668

Please sign in to comment.