Skip to content

Commit b9c6d68

Browse files
authored
JIT: Set method context for delegate GDV (#89499)
Instead of passing through the IL context, update the method context to be the exact method that were recorded in the delegate (which will include the full instantiation). Also do a bit of clean up. Fix #89495
1 parent e4cca32 commit b9c6d68

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

src/coreclr/jit/importercalls.cpp

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5897,10 +5897,10 @@ void Compiler::considerGuardedDevirtualization(GenTreeCall* call,
58975897

58985898
bool hasPgoData = true;
58995899

5900-
CORINFO_CLASS_HANDLE likelyClasses[MAX_GDV_TYPE_CHECKS] = {};
5901-
CORINFO_METHOD_HANDLE likelyMethodes[MAX_GDV_TYPE_CHECKS] = {};
5902-
unsigned likelihoods[MAX_GDV_TYPE_CHECKS] = {};
5903-
int candidatesCount = 0;
5900+
CORINFO_CLASS_HANDLE likelyClasses[MAX_GDV_TYPE_CHECKS] = {};
5901+
CORINFO_METHOD_HANDLE likelyMethods[MAX_GDV_TYPE_CHECKS] = {};
5902+
unsigned likelihoods[MAX_GDV_TYPE_CHECKS] = {};
5903+
int candidatesCount = 0;
59045904

59055905
// We currently only get likely class guesses when there is PGO data
59065906
// with class profiles.
@@ -5911,7 +5911,7 @@ void Compiler::considerGuardedDevirtualization(GenTreeCall* call,
59115911
}
59125912
else
59135913
{
5914-
pickGDV(call, ilOffset, isInterface, likelyClasses, likelyMethodes, &candidatesCount, likelihoods);
5914+
pickGDV(call, ilOffset, isInterface, likelyClasses, likelyMethods, &candidatesCount, likelihoods);
59155915
assert((unsigned)candidatesCount <= MAX_GDV_TYPE_CHECKS);
59165916
assert((unsigned)candidatesCount <= (unsigned)getGDVMaxTypeChecks());
59175917
if (candidatesCount == 0)
@@ -6015,7 +6015,7 @@ void Compiler::considerGuardedDevirtualization(GenTreeCall* call,
60156015
for (int candidateId = 0; candidateId < candidatesCount; candidateId++)
60166016
{
60176017
CORINFO_CLASS_HANDLE likelyClass = likelyClasses[candidateId];
6018-
CORINFO_METHOD_HANDLE likelyMethod = likelyMethodes[candidateId];
6018+
CORINFO_METHOD_HANDLE likelyMethod = likelyMethods[candidateId];
60196019
unsigned likelihood = likelihoods[candidateId];
60206020

60216021
CORINFO_CONTEXT_HANDLE likelyContext = NULL;
@@ -6058,6 +6058,10 @@ void Compiler::considerGuardedDevirtualization(GenTreeCall* call,
60586058
likelyContext = dvInfo.exactContext;
60596059
likelyMethod = dvInfo.devirtualizedMethod;
60606060
}
6061+
else
6062+
{
6063+
likelyContext = MAKE_METHODCONTEXT(likelyMethod);
6064+
}
60616065

60626066
uint32_t likelyMethodAttribs = info.compCompHnd->getMethodAttribs(likelyMethod);
60636067

@@ -6291,14 +6295,8 @@ void Compiler::impMarkInlineCandidate(GenTree* callNode,
62916295
{
62926296
InlineResult inlineResult(this, call, nullptr, "impMarkInlineCandidate for GDV");
62936297

6294-
CORINFO_CONTEXT_HANDLE moreExactContext = call->GetGDVCandidateInfo(candidateId)->exactContextHnd;
6295-
if (moreExactContext == NULL)
6296-
{
6297-
moreExactContext = exactContextHnd;
6298-
}
6299-
63006298
// Do the actual evaluation
6301-
impMarkInlineCandidateHelper(call, candidateId, moreExactContext, exactContextNeedsRuntimeLookup, callInfo,
6299+
impMarkInlineCandidateHelper(call, candidateId, exactContextHnd, exactContextNeedsRuntimeLookup, callInfo,
63026300
ilOffset, &inlineResult);
63036301
// Ignore non-inlineable candidates
63046302
// TODO: Consider keeping them to just devirtualize without inlining, at least for interface
@@ -6464,15 +6462,17 @@ void Compiler::impMarkInlineCandidateHelper(GenTreeCall* call,
64646462

64656463
if (call->IsGuardedDevirtualizationCandidate())
64666464
{
6467-
if (call->GetGDVCandidateInfo(candidateIndex)->guardedMethodUnboxedEntryHandle != nullptr)
6465+
InlineCandidateInfo* gdvCandidate = call->GetGDVCandidateInfo(candidateIndex);
6466+
if (gdvCandidate->guardedMethodUnboxedEntryHandle != nullptr)
64686467
{
6469-
fncHandle = call->GetGDVCandidateInfo(candidateIndex)->guardedMethodUnboxedEntryHandle;
6468+
fncHandle = gdvCandidate->guardedMethodUnboxedEntryHandle;
64706469
}
64716470
else
64726471
{
6473-
fncHandle = call->GetGDVCandidateInfo(candidateIndex)->guardedMethodHandle;
6472+
fncHandle = gdvCandidate->guardedMethodHandle;
64746473
}
6475-
methAttr = info.compCompHnd->getMethodAttribs(fncHandle);
6474+
exactContextHnd = gdvCandidate->exactContextHnd;
6475+
methAttr = info.compCompHnd->getMethodAttribs(fncHandle);
64766476
}
64776477
else
64786478
{
@@ -7784,32 +7784,25 @@ void Compiler::impCheckCanInline(GenTreeCall* call,
77847784
JITDUMP("\nCheckCanInline: fetching method info for inline candidate %s -- context %p\n",
77857785
compiler->eeGetMethodName(ftn), pParam->exactContextHnd);
77867786

7787-
if (pParam->exactContextHnd == nullptr)
7788-
{
7789-
JITDUMP("NULL context\n");
7790-
}
7791-
else if (pParam->exactContextHnd == METHOD_BEING_COMPILED_CONTEXT())
7787+
if (pParam->exactContextHnd == METHOD_BEING_COMPILED_CONTEXT())
77927788
{
77937789
JITDUMP("Current method context\n");
77947790
}
77957791
else if ((((size_t)pParam->exactContextHnd & CORINFO_CONTEXTFLAGS_MASK) == CORINFO_CONTEXTFLAGS_METHOD))
77967792
{
77977793
JITDUMP("Method context: %s\n",
7798-
compiler->eeGetMethodName((CORINFO_METHOD_HANDLE)pParam->exactContextHnd));
7794+
compiler->eeGetMethodFullName((CORINFO_METHOD_HANDLE)pParam->exactContextHnd));
77997795
}
78007796
else
78017797
{
78027798
JITDUMP("Class context: %s\n", compiler->eeGetClassName((CORINFO_CLASS_HANDLE)(
78037799
(size_t)pParam->exactContextHnd & ~CORINFO_CONTEXTFLAGS_MASK)));
78047800
}
78057801

7806-
const bool isGdv = pParam->call->IsGuardedDevirtualizationCandidate();
7807-
78087802
// Fetch method info. This may fail, if the method doesn't have IL.
7809-
// NOTE: For GDV we're expected to use a different context (per candidate)
78107803
//
78117804
CORINFO_METHOD_INFO methInfo;
7812-
if (!compCompHnd->getMethodInfo(ftn, &methInfo, isGdv ? nullptr : pParam->exactContextHnd))
7805+
if (!compCompHnd->getMethodInfo(ftn, &methInfo, pParam->exactContextHnd))
78137806
{
78147807
inlineResult->NoteFatal(InlineObservation::CALLEE_NO_METHOD_INFO);
78157808
return;

0 commit comments

Comments
 (0)