Skip to content
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
8 changes: 3 additions & 5 deletions src/coreclr/jit/fginline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,8 @@ class SubstitutePlaceholdersAndDevirtualizeWalker : public GenTreeVisitor<Substi

if (tree->OperIs(GT_CALL))
{
GenTreeCall* call = tree->AsCall();
CORINFO_METHOD_HANDLE method = NO_METHOD_HANDLE;
bool tryLateDevirt = call->IsDevirtualizationCandidate(m_compiler, &method);
GenTreeCall* call = tree->AsCall();
bool tryLateDevirt = call->IsDevirtualizationCandidate(m_compiler);

#ifdef DEBUG
tryLateDevirt = tryLateDevirt && (JitConfig.JitEnableLateDevirtualization() == 1);
Expand All @@ -604,14 +603,13 @@ class SubstitutePlaceholdersAndDevirtualizeWalker : public GenTreeVisitor<Substi
}
#endif // DEBUG

CORINFO_METHOD_HANDLE method = call->gtLateDevirtualizationInfo->methodHnd;
CORINFO_CONTEXT_HANDLE context = call->gtLateDevirtualizationInfo->exactContextHnd;
InlineContext* inlinersContext = call->gtLateDevirtualizationInfo->inlinersContext;
unsigned methodFlags = 0;
const bool isLateDevirtualization = true;
const bool explicitTailCall = call->IsTailPrefixedCall();

assert(method != NO_METHOD_HANDLE);

CORINFO_CONTEXT_HANDLE contextInput = context;
context = nullptr;
m_compiler->impDevirtualizeCall(call, nullptr, &method, &methodFlags, &contextInput, &context,
Expand Down
40 changes: 2 additions & 38 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2370,49 +2370,13 @@ int GenTreeCall::GetNonStandardAddedArgCount(Compiler* compiler) const
//
// Arguments:
// compiler - [In] the compiler instance so that we can call eeFindHelper
// pMethHandle - [Out] the method handle if the call is a devirtualization candidate
//
// Return Value:
// Returns true if this GT_CALL node is a devirtualization candidate.
//
bool GenTreeCall::IsDevirtualizationCandidate(Compiler* compiler, CORINFO_METHOD_HANDLE* pMethHandle) const
bool GenTreeCall::IsDevirtualizationCandidate(Compiler* compiler) const
{
CORINFO_METHOD_HANDLE methHandleToDevirt = NO_METHOD_HANDLE;
bool isDevirtCandidate = false;

if (IsVirtual() && gtCallType == CT_USER_FUNC)
{
methHandleToDevirt = gtCallMethHnd;
isDevirtCandidate = true;
}
else if (IsGenericVirtual(compiler) && (JitConfig.JitEnableGenericVirtualDevirtualization() != 0))
{
GenTree* runtimeMethHndNode =
gtCallAddr->AsCall()->gtArgs.FindWellKnownArg(WellKnownArg::RuntimeMethodHandle)->GetNode();
assert(runtimeMethHndNode != nullptr);
switch (runtimeMethHndNode->OperGet())
{
case GT_RUNTIMELOOKUP:
methHandleToDevirt = runtimeMethHndNode->AsRuntimeLookup()->GetMethodHandle();
isDevirtCandidate = true;
break;
case GT_CNS_INT:
methHandleToDevirt = CORINFO_METHOD_HANDLE(runtimeMethHndNode->AsIntCon()->gtCompileTimeHandle);
isDevirtCandidate = true;
break;
default:
// Unable to get method handle for devirtualization.
// This can happen if the method handle is not an RUNTIMELOOKUP or CNS_INT for generic virtuals,
break;
}
}

if (pMethHandle)
{
*pMethHandle = methHandleToDevirt;
}

return isDevirtCandidate;
return IsVirtual() || (IsGenericVirtual(compiler) && (JitConfig.JitEnableGenericVirtualDevirtualization() != 0));
}

//-------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/gentree.h
Original file line number Diff line number Diff line change
Expand Up @@ -5273,7 +5273,7 @@ struct GenTreeCall final : public GenTree
gtCallAddr->IsHelperCall(compiler, CORINFO_HELP_GVMLOOKUP_FOR_SLOT)));
}

bool IsDevirtualizationCandidate(Compiler* compiler, CORINFO_METHOD_HANDLE* pMethHandle = nullptr) const;
bool IsDevirtualizationCandidate(Compiler* compiler) const;

bool IsInlineCandidate() const
{
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/importercalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,7 @@ var_types Compiler::impImportCall(OPCODE opcode,
JITDUMP("\nSaving generic context %p and inline context %p for call [%06u]\n", dspPtr(exactContextHnd),
dspPtr(compInlineContext), dspTreeID(call->AsCall()));
LateDevirtualizationInfo* const info = new (this, CMK_Inlining) LateDevirtualizationInfo;
info->methodHnd = callInfo->hMethod;
info->exactContextHnd = exactContextHnd;
info->inlinersContext = compInlineContext;
call->AsCall()->gtLateDevirtualizationInfo = info;
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ struct InlineCandidateInfo : public HandleHistogramProfileCandidateInfo
//
struct LateDevirtualizationInfo
{
CORINFO_METHOD_HANDLE methodHnd;
CORINFO_CONTEXT_HANDLE exactContextHnd;
InlineContext* inlinersContext;
};
Expand Down
Loading