Skip to content
Open
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
16 changes: 15 additions & 1 deletion src/coreclr/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,7 @@ enum CORINFO_RUNTIME_LOOKUP_KIND
CORINFO_LOOKUP_METHODPARAM,
CORINFO_LOOKUP_CLASSPARAM,
CORINFO_LOOKUP_NOT_SUPPORTED, // Returned for attempts to inline dictionary lookups
CORINFO_LOOKUP_DEFERRED, // Completed by prepareCallLookups before materialization
};

struct CORINFO_LOOKUP_KIND
Expand Down Expand Up @@ -1567,7 +1568,9 @@ struct CORINFO_CALL_INFO
CORINFO_LOOKUP codePointerLookup;
};

CORINFO_CONST_LOOKUP instParamLookup;
// Lookup for the hidden instantiation argument when sig.hasTypeArg().
// Runtime-dependent lookups are populated by prepareCallLookups, after intrinsic expansion.
CORINFO_LOOKUP instParamLookup;
};

enum CORINFO_DEVIRTUALIZATION_DETAIL
Expand Down Expand Up @@ -3420,6 +3423,8 @@ class ICorDynamicInfo : public ICorStaticInfo
) CORINFO_PURE;

// Returns instructions on how to make the call. See code:CORINFO_CALL_INFO for possible return values.
// Resolves the target and its signature. Call prepareCallLookups during import if a
// deferred lookup is needed, while the resolved tokens are still available.
CORINFO_VIRTUAL void getCallInfo(
// Token info (in)
CORINFO_RESOLVED_TOKEN * pResolvedToken,
Expand All @@ -3437,6 +3442,15 @@ class ICorDynamicInfo : public ICorStaticInfo
CORINFO_CALL_INFO *pResult
) CORINFO_PURE;

// Completes the deferred instantiation argument lookup using the same tokens and caller
// that were passed to getCallInfo.
CORINFO_VIRTUAL void prepareCallLookups(
CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_RESOLVED_TOKEN* pConstrainedResolvedToken,
CORINFO_METHOD_HANDLE callerHandle,
CORINFO_CALL_INFO* pCallInfo
) CORINFO_PURE;

//------------------------------------------------------------------------------
// getStaticFieldContent: returns true and the actual field's value if the given
// field represents a statically initialized readonly field of any type.
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/inc/icorjitinfoimpl_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/coreclr/inc/jiteeversionguid.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@

#include <minipal/guid.h>

constexpr GUID JITEEVersionIdentifier = { /* c77c1a0f-c8c6-4a68-90db-4d8c1253c5ea */
0xc77c1a0f,
0xc8c6,
0x4a68,
{0x90, 0xdb, 0x4d, 0x8c, 0x12, 0x53, 0xc5, 0xea}
constexpr GUID JITEEVersionIdentifier = { /* c4d74c1b-48c7-4260-9628-f36a6f6d6491 */
0xc4d74c1b,
0x48c7,
0x4260,
{0x96, 0x28, 0xf3, 0x6a, 0x6f, 0x6d, 0x64, 0x91}
};

#endif // JIT_EE_VERSIONING_GUID_H
58 changes: 13 additions & 45 deletions src/coreclr/interpreter/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4489,6 +4489,9 @@ void InterpCompiler::EmitPushHelperCall(const CorInfoHelpFunc ftn, const CORINFO

void InterpCompiler::EmitPushCORINFO_LOOKUP(const CORINFO_LOOKUP& lookup)
{
assert(!lookup.lookupKind.needsRuntimeLookup ||
(lookup.lookupKind.runtimeLookupKind != CORINFO_LOOKUP_DEFERRED));

PushStackType(StackTypeI, NULL);
int32_t resultVar = m_pStackPointer[-1].var;

Expand Down Expand Up @@ -5542,63 +5545,28 @@ void InterpCompiler::EmitCall(CORINFO_RESOLVED_TOKEN* pConstrainedToken, bool re
}
else
{
// Instantiated generic method
CORINFO_CONTEXT_HANDLE exactContextHnd = callInfo.contextHandle;
if (((SIZE_T)exactContextHnd & CORINFO_CONTEXTFLAGS_MASK) == CORINFO_CONTEXTFLAGS_METHOD)
if ((callInfo.classFlags & CORINFO_FLG_ARRAY) && readonly)
{
assert(exactContextHnd != METHOD_BEING_COMPILED_CONTEXT());

CORINFO_METHOD_HANDLE exactMethodHandle =
(CORINFO_METHOD_HANDLE)((SIZE_T)exactContextHnd & ~CORINFO_CONTEXTFLAGS_MASK);
DeclarePointerIsMethod(exactMethodHandle);

if (!callInfo.exactContextNeedsRuntimeLookup)
{
PushStackType(StackTypeI, NULL);
m_pStackPointer--;
contextParamVar = m_pStackPointer[0].var;
AddIns(INTOP_LDPTR);
m_pLastNewIns->SetDVar(contextParamVar);
m_pLastNewIns->data[0] = GetDataItemIndex((void*)exactMethodHandle);
}
else
{
contextParamVar = EmitGenericHandle(&resolvedCallToken, GenericHandleEmbedOptions::VarOnly).var;
}
// A null instantiation argument requests readonly array Address semantics.
EmitLoadPointer(0);
}
// otherwise must be an instance method in a generic struct,
// a static method in a generic type, or a runtime-generated array method
else
{
assert(((SIZE_T)exactContextHnd & CORINFO_CONTEXTFLAGS_MASK) == CORINFO_CONTEXTFLAGS_CLASS);
CORINFO_CLASS_HANDLE exactClassHandle = getClassFromContext(exactContextHnd);
DeclarePointerIsClass(exactClassHandle);

if ((callInfo.classFlags & CORINFO_FLG_ARRAY) && readonly)
if (callInfo.exactContextNeedsRuntimeLookup)
{
PushStackType(StackTypeI, NULL);
m_pStackPointer--;
contextParamVar = m_pStackPointer[0].var;
// We indicate "readonly" to the Address operation by using a null
// instParam.
AddIns(INTOP_LDPTR);
m_pLastNewIns->SetDVar(contextParamVar);
m_pLastNewIns->data[0] = GetDataItemIndex(NULL);
m_compHnd->prepareCallLookups(&resolvedCallToken, pConstrainedToken, m_methodInfo->ftn, &callInfo);
}
else if (!callInfo.exactContextNeedsRuntimeLookup)
if (callInfo.instParamLookup.lookupKind.needsRuntimeLookup)
{
PushStackType(StackTypeI, NULL);
m_pStackPointer--;
contextParamVar = m_pStackPointer[0].var;
AddIns(INTOP_LDPTR);
m_pLastNewIns->SetDVar(contextParamVar);
m_pLastNewIns->data[0] = GetDataItemIndex((void*)exactClassHandle);
EmitPushCORINFO_LOOKUP(callInfo.instParamLookup);
}
else
{
contextParamVar = EmitGenericHandle(&resolvedCallToken, GenericHandleEmbedOptions::VarOnly | GenericHandleEmbedOptions::EmbedParent).var;
assert(callInfo.instParamLookup.constLookup.accessType == IAT_VALUE);
EmitLoadPointer((intptr_t)callInfo.instParamLookup.constLookup.handle);
}
}
contextParamVar = (--m_pStackPointer)->var;
}
callArgs[extraParamArgLocation] = contextParamVar;
}
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/ICorJitInfo_names_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5415,11 +5415,8 @@ class Compiler
IL_OFFSET rawILOffset);

GenTree* impGetInstParamArg(CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_CALL_INFO* callInfo,
CORINFO_CONTEXT_HANDLE exactContextHnd,
bool exactContextNeedsRuntimeLookup,
unsigned clsFlags,
bool isReadonlyCall);
CORINFO_RESOLVED_TOKEN* pConstrainedResolvedToken,
CORINFO_CALL_INFO* callInfo, unsigned clsFlags, bool isReadonlyCall);

void impTryOptimizeAwaitAwaiter(GenTreeCall* call,
CORINFO_RESOLVED_TOKEN* pResolvedToken,
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,9 @@ GenTree* Compiler::impTokenToHandle(CORINFO_RESOLVED_TOKEN* pResolvedToken,

GenTree* Compiler::impLookupToTree(CORINFO_LOOKUP* pLookup, GenTreeFlags handleFlags, void* compileTimeHandle)
{
assert(!pLookup->lookupKind.needsRuntimeLookup ||
(pLookup->lookupKind.runtimeLookupKind != CORINFO_LOOKUP_DEFERRED));

if (!pLookup->lookupKind.needsRuntimeLookup)
{
// No runtime lookup is required.
Expand Down
141 changes: 36 additions & 105 deletions src/coreclr/jit/importercalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,125 +5,56 @@
#include "async.h"

//------------------------------------------------------------------------
// impGetInstParamArg: compute the hidden instantiation / generic-context argument
// for a call whose signature has a type arg (CORINFO_CALLCONV_PARAMTYPE).
// impGetInstParamArg: compute the hidden instantiation argument from the EE-supplied lookup.
//
// Arguments:
// pResolvedToken - resolved token for the call target
// callInfo - EE supplied info for the call
// exactContextHnd - the exact (method or class) context for the call
// exactContextNeedsRuntimeLookup - whether the exact context needs a runtime lookup
// clsFlags - flags for the class that owns the called method
// isReadonlyCall - whether this is a "readonly." prefixed call
// pResolvedToken - resolved call token
// pConstrainedResolvedToken - constrained type token, if present
// callInfo - EE supplied info for the call
// clsFlags - flags for the class that owns the called method
// isReadonlyCall - whether this is a "readonly." prefixed call
//
// Return Value:
// The IR node for the instantiation argument. This may be a null-handle constant
// for a "readonly." array Address call. Returns nullptr if the importer must abort
// the current method, in which case compDonotInline() is set and the caller should
// return TYP_UNDEF.
//
// Notes:
// This is the shared computation for the hidden "extra arg" described at the
// hasTypeArg() handling in impImportCall. It is also used by the wasm LDVIRTFTN
// path, which dispatches virtual calls (including the array Address accessor) that
// can carry a type arg but is otherwise outside the main hasTypeArg() handling.
// The instantiation argument, or nullptr if the importer must abandon an inline attempt.
//
GenTree* Compiler::impGetInstParamArg(CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_RESOLVED_TOKEN* pConstrainedResolvedToken,
CORINFO_CALL_INFO* callInfo,
CORINFO_CONTEXT_HANDLE exactContextHnd,
bool exactContextNeedsRuntimeLookup,
unsigned clsFlags,
bool isReadonlyCall)
{
GenTree* instParam = nullptr;
bool runtimeLookup;

// Instantiated generic method
if (((SIZE_T)exactContextHnd & CORINFO_CONTEXTFLAGS_MASK) == CORINFO_CONTEXTFLAGS_METHOD)
if (compIsForInlining() && (clsFlags & CORINFO_FLG_ARRAY) != 0)
{
assert(exactContextHnd != METHOD_BEING_COMPILED_CONTEXT());

CORINFO_METHOD_HANDLE exactMethodHandle =
(CORINFO_METHOD_HANDLE)((SIZE_T)exactContextHnd & ~CORINFO_CONTEXTFLAGS_MASK);

if (!exactContextNeedsRuntimeLookup)
{
#ifdef FEATURE_READYTORUN
if (IsAot())
{
instParam = gtNewIconEmbHndNode(&callInfo->instParamLookup, GTF_ICON_METHOD_HDL, exactMethodHandle);
if (instParam == nullptr)
{
assert(compDonotInline());
return nullptr;
}
}
else
#endif
{
instParam = gtNewIconEmbMethHndNode(exactMethodHandle);
}
}
else
{
instParam = impTokenToHandle(pResolvedToken, &runtimeLookup);
if (instParam == nullptr)
{
assert(compDonotInline());
return nullptr;
}
}
compInlineResult->NoteFatal(InlineObservation::CALLEE_IS_ARRAY_METHOD);
return nullptr;
}

// otherwise must be an instance method in a generic struct,
// a static method in a generic type, or a runtime-generated array method
else
if ((clsFlags & CORINFO_FLG_ARRAY) && isReadonlyCall)
{
assert(((SIZE_T)exactContextHnd & CORINFO_CONTEXTFLAGS_MASK) == CORINFO_CONTEXTFLAGS_CLASS);
CORINFO_CLASS_HANDLE exactClassHandle = eeGetClassFromContext(exactContextHnd);
// A null instantiation argument requests readonly array Address semantics.
return gtNewIconNode(0, TYP_REF);
}

if (compIsForInlining() && (clsFlags & CORINFO_FLG_ARRAY) != 0)
{
compInlineResult->NoteFatal(InlineObservation::CALLEE_IS_ARRAY_METHOD);
return nullptr;
}
// Intrinsics and explicit context arguments have already bypassed this path.
if (callInfo->exactContextNeedsRuntimeLookup)
{
info.compCompHnd->prepareCallLookups(pResolvedToken, pConstrainedResolvedToken, info.compMethodHnd, callInfo);
}

if ((clsFlags & CORINFO_FLG_ARRAY) && isReadonlyCall)
{
// We indicate "readonly" to the Address operation by using a null
// instParam.
instParam = gtNewIconNode(0, TYP_REF);
}
else if (!exactContextNeedsRuntimeLookup)
{
#ifdef FEATURE_READYTORUN
if (IsAot())
{
instParam = gtNewIconEmbHndNode(&callInfo->instParamLookup, GTF_ICON_CLASS_HDL, exactClassHandle);
if (instParam == nullptr)
{
assert(compDonotInline());
return nullptr;
}
}
else
#endif
{
instParam = gtNewIconEmbClsHndNode(exactClassHandle);
}
}
else
{
instParam = impParentClassTokenToHandle(pResolvedToken, &runtimeLookup);
if (instParam == nullptr)
{
assert(compDonotInline());
return nullptr;
}
}
CORINFO_CONTEXT_HANDLE context = callInfo->contextHandle;
bool methodContext = ((SIZE_T)context & CORINFO_CONTEXTFLAGS_MASK) == CORINFO_CONTEXTFLAGS_METHOD;
CORINFO_GENERIC_HANDLE handle = methodContext
? (CORINFO_GENERIC_HANDLE)((SIZE_T)context & ~CORINFO_CONTEXTFLAGS_MASK)
: (CORINFO_GENERIC_HANDLE)eeGetClassFromContext(context);
GenTreeFlags flags = methodContext ? GTF_ICON_METHOD_HDL : GTF_ICON_CLASS_HDL;
GenTree* result = impLookupToTree(&callInfo->instParamLookup, flags, handle);
if ((result != nullptr) && callInfo->instParamLookup.lookupKind.needsRuntimeLookup)
{
result =
gtNewRuntimeLookup(handle, methodContext ? CORINFO_HANDLETYPE_METHOD : CORINFO_HANDLETYPE_CLASS, result);
}

return instParam;
return result;
}

//------------------------------------------------------------------------
Expand Down Expand Up @@ -717,8 +648,8 @@ var_types Compiler::impImportCall(OPCODE opcode,
}
else
{
wasmInstParam = impGetInstParamArg(pResolvedToken, callInfo, exactContextHnd,
exactContextNeedsRuntimeLookup, clsFlags, isReadonlyCall);
wasmInstParam = impGetInstParamArg(pResolvedToken, pConstrainedResolvedToken, callInfo,
clsFlags, isReadonlyCall);
if (wasmInstParam == nullptr)
{
assert(compDonotInline());
Expand Down Expand Up @@ -986,8 +917,8 @@ var_types Compiler::impImportCall(OPCODE opcode,

assert(opcode != CEE_CALLI);

instParam = impGetInstParamArg(pResolvedToken, callInfo, exactContextHnd, exactContextNeedsRuntimeLookup,
clsFlags, isReadonlyCall);
instParam =
impGetInstParamArg(pResolvedToken, pConstrainedResolvedToken, callInfo, clsFlags, isReadonlyCall);
if (instParam == nullptr)
{
assert(compDonotInline());
Expand Down
Loading
Loading