Skip to content

JIT: Support for devirtualizing array interface methods #108153

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

Merged
merged 8 commits into from
Oct 2, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,8 @@ private SZArrayHelper()
Debug.Fail("Hey! How'd I get here?");
}

[Intrinsic]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal IEnumerator<T> GetEnumerator<T>()
{
// ! Warning: "this" is an array, not an SZArrayHelper. See comments above
Expand Down
13 changes: 11 additions & 2 deletions src/coreclr/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1526,18 +1526,21 @@ struct CORINFO_DEVIRTUALIZATION_INFO
// [Out] results of resolveVirtualMethod.
// - devirtualizedMethod is set to MethodDesc of devirt'ed method iff we were able to devirtualize.
// invariant is `resolveVirtualMethod(...) == (devirtualizedMethod != nullptr)`.
// - requiresInstMethodTableArg is set to TRUE if the devirtualized method requires a type handle arg.
// - exactContext is set to wrapped CORINFO_CLASS_HANDLE of devirt'ed method table.
// - details on the computation done by the jit host
// - If pResolvedTokenDevirtualizedMethod is not set to NULL and targeting an R2R image
// use it as the parameter to getCallInfo
// - requiresInstMethodTableArg is set to TRUE if the devirtualized method requires a type handle arg.
// - wasArrayInterfaceDevirt is set TRUE for array interface method devirtualization
// (in which case the method handle and context will be a generic method)
//
CORINFO_METHOD_HANDLE devirtualizedMethod;
bool requiresInstMethodTableArg;
CORINFO_CONTEXT_HANDLE exactContext;
CORINFO_DEVIRTUALIZATION_DETAIL detail;
CORINFO_RESOLVED_TOKEN resolvedTokenDevirtualizedMethod;
CORINFO_RESOLVED_TOKEN resolvedTokenDevirtualizedUnboxedMethod;
bool requiresInstMethodTableArg;
bool wasArrayInterfaceDevirt;
};

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -2139,6 +2142,12 @@ class ICorStaticInfo
CORINFO_CLASS_HANDLE elemType
) = 0;

// Given T, return the type of the SZArrayHelper enumerator
// Returns null if the type can't be determined exactly.
virtual CORINFO_CLASS_HANDLE getSZArrayHelperEnumeratorClass(
CORINFO_CLASS_HANDLE elemType
) = 0;

// Given resolved token that corresponds to an intrinsic classified to
// get a raw handle (NI_System_Activator_AllocatorOf etc.), fetch the
// handle associated with the token. If this is not possible at
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/inc/icorjitinfoimpl_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ CORINFO_CLASS_HANDLE getDefaultComparerClass(
CORINFO_CLASS_HANDLE getDefaultEqualityComparerClass(
CORINFO_CLASS_HANDLE elemType) override;

CORINFO_CLASS_HANDLE getSZArrayHelperEnumeratorClass(
CORINFO_CLASS_HANDLE elemType) override;

void expandRawHandleIntrinsic(
CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_METHOD_HANDLE callerHandle,
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 = { /* b75a5475-ff22-4078-9551-2024ce03d383 */
0xb75a5475,
0xff22,
0x4078,
{0x95, 0x51, 0x20, 0x24, 0xce, 0x03, 0xd3, 0x83}
constexpr GUID JITEEVersionIdentifier = { /* 9b8ef809-94d4-41b6-9d4c-dd61379abbe0 */
0x9b8ef809,
0x94d4,
0x41b6,
{0x9d, 0x4c, 0xdd, 0x61, 0x37, 0x9a, 0xbb, 0xe0}
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/ICorJitInfo_names_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ DEF_CLR_API(resolveVirtualMethod)
DEF_CLR_API(getUnboxedEntry)
DEF_CLR_API(getDefaultComparerClass)
DEF_CLR_API(getDefaultEqualityComparerClass)
DEF_CLR_API(getSZArrayHelperEnumeratorClass)
DEF_CLR_API(expandRawHandleIntrinsic)
DEF_CLR_API(isIntrinsicType)
DEF_CLR_API(getUnmanagedCallConv)
Expand Down
9 changes: 9 additions & 0 deletions src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,15 @@ CORINFO_CLASS_HANDLE WrapICorJitInfo::getDefaultEqualityComparerClass(
return temp;
}

CORINFO_CLASS_HANDLE WrapICorJitInfo::getSZArrayHelperEnumeratorClass(
CORINFO_CLASS_HANDLE elemType)
{
API_ENTER(getSZArrayHelperEnumeratorClass);
CORINFO_CLASS_HANDLE temp = wrapHnd->getSZArrayHelperEnumeratorClass(elemType);
API_LEAVE(getSZArrayHelperEnumeratorClass);
return temp;
}

void WrapICorJitInfo::expandRawHandleIntrinsic(
CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_METHOD_HANDLE callerHandle,
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -7551,7 +7551,9 @@ class Compiler
CORINFO_CONTEXT_HANDLE contextHandle,
unsigned methodAttr,
unsigned classAttr,
unsigned likelihood);
unsigned likelihood,
bool arrayInterface,
CORINFO_CONTEXT_HANDLE originalContextHandle);

int getGDVMaxTypeChecks()
{
Expand Down
8 changes: 4 additions & 4 deletions src/coreclr/jit/fginline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ bool Compiler::IsDisallowedRecursiveInline(InlineContext* ancestor, InlineInfo*
{
// We disallow inlining the exact same instantiation.
if ((ancestor->GetCallee() == inlineInfo->fncHandle) &&
(ancestor->GetRuntimeContext() == inlineInfo->inlineCandidateInfo->exactContextHnd))
(ancestor->GetRuntimeContext() == inlineInfo->inlineCandidateInfo->exactContextHandle))
{
JITDUMP("Call site is trivially recursive\n");
return true;
Expand All @@ -80,7 +80,7 @@ bool Compiler::IsDisallowedRecursiveInline(InlineContext* ancestor, InlineInfo*
// involved this can quickly consume a large amount of resources, so try to
// verify that we aren't inlining recursively with complex contexts.
if (info.compCompHnd->haveSameMethodDefinition(inlineInfo->fncHandle, ancestor->GetCallee()) &&
ContextComplexityExceeds(inlineInfo->inlineCandidateInfo->exactContextHnd, 64))
ContextComplexityExceeds(inlineInfo->inlineCandidateInfo->exactContextHandle, 64))
{
JITDUMP("Call site is recursive with a complex generic context\n");
return true;
Expand Down Expand Up @@ -1300,7 +1300,7 @@ void Compiler::fgInvokeInlineeCompiler(GenTreeCall* call, InlineResult* inlineRe
->NewContext(pParam->inlineInfo->inlineCandidateInfo->inlinersContext, pParam->inlineInfo->iciStmt,
pParam->inlineInfo->iciCall);
pParam->inlineInfo->argCnt = pParam->inlineCandidateInfo->methInfo.args.totalILArgs();
pParam->inlineInfo->tokenLookupContextHandle = pParam->inlineCandidateInfo->exactContextHnd;
pParam->inlineInfo->tokenLookupContextHandle = pParam->inlineCandidateInfo->exactContextHandle;

JITLOG_THIS(pParam->pThis,
(LL_INFO100000, "INLINER: inlineInfo.tokenLookupContextHandle for %s set to 0x%p:\n",
Expand Down Expand Up @@ -2042,7 +2042,7 @@ Statement* Compiler::fgInlinePrependStatements(InlineInfo* inlineInfo)

if (inlineInfo->inlineCandidateInfo->initClassResult & CORINFO_INITCLASS_USE_HELPER)
{
CORINFO_CLASS_HANDLE exactClass = eeGetClassFromContext(inlineInfo->inlineCandidateInfo->exactContextHnd);
CORINFO_CLASS_HANDLE exactClass = eeGetClassFromContext(inlineInfo->inlineCandidateInfo->exactContextHandle);

tree = fgGetSharedCCtor(exactClass);
newStmt = gtNewStmt(tree, callDI);
Expand Down
7 changes: 4 additions & 3 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12981,9 +12981,10 @@ void Compiler::gtDispTree(GenTree* tree,
{
inlineInfo = call->GetSingleInlineCandidateInfo();
}
if ((inlineInfo != nullptr) && (inlineInfo->exactContextHnd != nullptr))

if ((inlineInfo != nullptr) && (inlineInfo->exactContextHandle != nullptr))
{
printf(" (exactContextHnd=0x%p)", dspPtr(inlineInfo->exactContextHnd));
printf(" (exactContextHandle=0x%p)", dspPtr(inlineInfo->exactContextHandle));
}
}

Expand Down Expand Up @@ -19048,7 +19049,7 @@ CORINFO_CLASS_HANDLE Compiler::gtGetClassHandle(GenTree* tree, bool* pIsExact, b
// of the inlinee.
if (eeIsSharedInst(objClass))
{
CORINFO_CONTEXT_HANDLE context = inlInfo->exactContextHnd;
CORINFO_CONTEXT_HANDLE context = inlInfo->exactContextHandle;

if (context != nullptr)
{
Expand Down
Loading
Loading