Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
192e804
Centralize instantiation argument preparation in the EE
NinoFloris Nov 20, 2026
8c69e5d
Apply jit-format to instantiation argument call sites
NinoFloris Nov 24, 2026
ddce734
Finish populating call info before returning to the JIT
NinoFloris Nov 24, 2026
b206a76
Wrap lookup preparation in the JIT to EE transition
NinoFloris Nov 24, 2026
77bfbd7
Defer runtime code-pointer lookups until import needs the entry point
NinoFloris Nov 24, 2026
3c74b0b
Defer interface dispatch lookups until after import-time devirtualiza…
NinoFloris Nov 20, 2026
c6b4210
Defer runtime call entry lookups in NativeAOT and ReadyToRun
NinoFloris Nov 24, 2026
05de926
Skip the NativeAOT function-pointer lookup for delegate construction
NinoFloris Nov 24, 2026
db3fbdc
Devirtualize shared generic virtual methods on known receivers
NinoFloris Nov 25, 2026
4739760
Use precomputed method entries for NativeAOT fat function pointers
NinoFloris Nov 25, 2026
502fb32
Use the caller's method type argument when inlining ldtoken
NinoFloris Nov 25, 2026
128fa9c
Compose forwarded method type arguments across inlines
NinoFloris Nov 25, 2026
1404d88
Defer forwarded method context lookups through inlining
NinoFloris Nov 25, 2026
294800a
Delay shared GVM dispatch lookups until after devirtualization
NinoFloris Nov 25, 2026
9a07252
Prepare devirtualized GVM dictionaries only for surviving uses
NinoFloris Nov 25, 2026
c9f512f
Compose vector array types through generic inlines
NinoFloris Nov 25, 2026
40540c0
Compose constructed generic type arguments through inlines
NinoFloris Nov 25, 2026
ec83438
Preserve foreign type definitions through generic inlines
NinoFloris Nov 25, 2026
47a204b
Forward exact allocation types between generic inlines
NinoFloris Nov 25, 2026
74b5419
Compose enclosing type arguments in root method dictionaries
NinoFloris Nov 25, 2026
4f70a13
Fold casts of exact generic allocations after inlining
NinoFloris Nov 25, 2026
03f815e
Prove generic casts across agreeing control-flow paths
NinoFloris Nov 25, 2026
144bf8f
Compose declaring-type arguments across generic inlines
NinoFloris Nov 25, 2026
ca45ac5
Forward generic arguments from class-context roots
NinoFloris Nov 25, 2026
70de9b8
Forward declaring-type bindings for calls without method arguments
NinoFloris Nov 25, 2026
f8949c4
Forward generic static field owners through inlines
NinoFloris Nov 25, 2026
926e81d
Forward type handles for object and array allocations and casts
NinoFloris Nov 25, 2026
9edaa13
Compose surviving generic call contexts in the root dictionary
NinoFloris Nov 26, 2026
de4339d
Compose fixed type arguments in shared generic calls
NinoFloris Nov 26, 2026
ee234f2
Look up inlined generic method entries in the root dictionary
NinoFloris Nov 26, 2026
40107a9
Forward generic arguments through class instance inlines
NinoFloris Nov 26, 2026
e89975f
Forward generic arguments for direct callvirt and resolved interface …
NinoFloris Nov 26, 2026
d303061
Look up inlined interface dispatch cells in the root dictionary
NinoFloris Nov 26, 2026
17beeb2
Pass the constrained value type context to resolved shared calls
NinoFloris Nov 26, 2026
70b30c3
Fold a discarded null check into an adjacent load
NinoFloris Nov 25, 2026
e5fab20
Remove inline return self-stores before propagating type facts
NinoFloris Nov 26, 2026
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
50 changes: 48 additions & 2 deletions 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 @@ -1496,6 +1497,18 @@ enum CorInfoTokenKind
// token comes from devirtualizing a method
CORINFO_TOKENKIND_DevirtualizedMethod = 0x800 | CORINFO_TOKENKIND_Method,

// A resolved method template with its owner and MethodSpec expressed in the root context.
CORINFO_TOKENKIND_MethodExpression = 0x10000 | CORINFO_TOKENKIND_Method,
CORINFO_TOKENKIND_MethodEntryExpression = 0x20000 | CORINFO_TOKENKIND_Method,
CORINFO_TOKENKIND_DispatchStubExpression = 0x40000 | CORINFO_TOKENKIND_Method,

// Signature-only query to embedGenericHandle in the root method context.
CORINFO_TOKENKIND_TypeExpression = 0x4000 | CORINFO_TOKENKIND_Class,

// Resolve a TypeDef/TypeRef for use as a named type in a root TypeExpression.
// A null hClass means the root dictionary cannot safely retain this definition.
CORINFO_TOKENKIND_TypeExpressionDefinition = 0x8000 | CORINFO_TOKENKIND_Class,

// token comes from runtime async awaiting pattern
CORINFO_TOKENKIND_Await = 0x2000 | CORINFO_TOKENKIND_Method,
};
Expand Down Expand Up @@ -1557,17 +1570,26 @@ struct CORINFO_CALL_INFO
// Context for inlining and hidden arg
CORINFO_CONTEXT_HANDLE contextHandle;
bool exactContextNeedsRuntimeLookup; // Set if contextHandle is approx handle. Runtime lookup is required to get the exact handle.
// The token can supply argument bindings for inlining. An override supplies its own declaring type.
bool canForwardTypeArguments;
// The root dictionary can retain the method template for a composed context, callable entry or dispatch stub.
bool canForwardMethodContext;
// Only for method contexts: offset of the argument vector from the caller's MethodDesc.
unsigned short methodInstantiationOffset;

// If kind.CORINFO_VIRTUALCALL_STUB then stubLookup will be set.
// If kind.CORINFO_CALL_CODE_POINTER then entryPointLookup will be set.
// If kind.CORINFO_CALL_CODE_POINTER then codePointerLookup will be set.
// Either lookup may require prepareCallLookups before materialization.
union
{
CORINFO_LOOKUP stubLookup;

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 @@ -1616,6 +1638,7 @@ struct CORINFO_DEVIRTUALIZATION_INFO
// an R2R image.
// - instParamLookup contains all the information necessary to pass the instantiation parameter for
// the devirtualized method or its unboxed entry point.
// A deferred lookup is prepared using the resolved target token if devirtualization is accepted.
//
CORINFO_METHOD_HANDLE devirtualizedMethod;
CORINFO_CONTEXT_HANDLE tokenLookupContext;
Expand Down Expand Up @@ -3373,6 +3396,15 @@ class ICorDynamicInfo : public ICorStaticInfo
// code is shared and the token contains generic parameters)
// then indicate how the handle should be looked up at run-time.
//
// A TypeExpression supplies pTypeSpec/cbTypeSpec in the caller's scope
// without a metadata token. Metadata tokens are relative to tokenScope. A named type from
// another scope may instead be encoded using INTERNAL and the opaque class handle
// returned by resolveToken(TypeExpressionDefinition).
// A MethodExpression additionally supplies pMethodSpec in that same context and the
// resolved hMethod/hClass of a call for which getCallInfo set canForwardMethodContext.
// MethodEntryExpression uses the same inputs to obtain the callable entry for ldftn.
// DispatchStubExpression requests the dispatch cell for a non-generic interface method
// using its resolved template and the composed interface TypeSpec.
CORINFO_VIRTUAL void embedGenericHandle(
CORINFO_RESOLVED_TOKEN * pResolvedToken,
bool fEmbedParent, // `true` - embeds parent type handle of the field/method handle
Expand Down Expand Up @@ -3420,6 +3452,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 if a deferred
// lookup survives optimization and needs to be materialized.
CORINFO_VIRTUAL void getCallInfo(
// Token info (in)
CORINFO_RESOLVED_TOKEN * pResolvedToken,
Expand All @@ -3437,6 +3471,18 @@ class ICorDynamicInfo : public ICorStaticInfo
CORINFO_CALL_INFO *pResult
) CORINFO_PURE;

// Completes the runtime-dependent lookups of a call: instParamLookup for a call
// with sig.hasTypeArg() and exactContextNeedsRuntimeLookup, codePointerLookup for
// CORINFO_CALL_CODE_POINTER, or stubLookup for CORINFO_VIRTUALCALL_STUB.
// Other call information is unchanged.
// The tokens and caller must match the getCallInfo query that produced pCallInfo.
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 = { /* c8632a38-2268-40f0-8bd7-a155f0c3cf77 */
0xc8632a38,
0x2268,
0x40f0,
{0x8b, 0xd7, 0xa1, 0x55, 0xf0, 0xc3, 0xcf, 0x77}
};

#endif // JIT_EE_VERSIONING_GUID_H
89 changes: 34 additions & 55 deletions src/coreclr/interpreter/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4487,8 +4487,33 @@ void InterpCompiler::EmitPushHelperCall(const CorInfoHelpFunc ftn, const CORINFO
}
}

// Prepare the selected call lookup before pushing its value.
void InterpCompiler::EmitPushCallLookup(CORINFO_RESOLVED_TOKEN* token, CORINFO_RESOLVED_TOKEN* constrainedToken,
CORINFO_CALL_INFO* callInfo, CORINFO_LOOKUP& lookup)
{
assert((&lookup == &callInfo->instParamLookup) || (&lookup == &callInfo->codePointerLookup));
if (lookup.lookupKind.needsRuntimeLookup && (lookup.lookupKind.runtimeLookupKind == CORINFO_LOOKUP_DEFERRED))
{
m_compHnd->prepareCallLookups(token, constrainedToken, m_methodInfo->ftn, callInfo);
}
if (lookup.lookupKind.needsRuntimeLookup)
{
EmitPushCORINFO_LOOKUP(lookup);
}
else
{
assert(lookup.constLookup.accessType == IAT_VALUE);
EmitLoadPointer((intptr_t)lookup.constLookup.handle);
}
}

void InterpCompiler::EmitPushCORINFO_LOOKUP(const CORINFO_LOOKUP& lookup)
{
// A lookup deferred by getCallInfo carries CORINFO_LOOKUP_DEFERRED until prepareCallLookups
// completes it. Reaching materialization in that state means prepareCallLookups was not called.
assert(!lookup.lookupKind.needsRuntimeLookup ||
(lookup.lookupKind.runtimeLookupKind != CORINFO_LOOKUP_DEFERRED));

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

Expand Down Expand Up @@ -4975,7 +5000,8 @@ void InterpCompiler::EmitLdftn(CORINFO_RESOLVED_TOKEN* pResolvedToken, bool isVi
{
callInfoFlags = (CORINFO_CALLINFO_FLAGS)(CORINFO_CALLINFO_SECURITYCHECKS | CORINFO_CALLINFO_LDFTN);
}
m_compHnd->getCallInfo(pResolvedToken, m_pConstrainedToken, m_methodInfo->ftn, callInfoFlags, &callInfo);
CORINFO_RESOLVED_TOKEN* pConstrainedToken = m_pConstrainedToken;
m_compHnd->getCallInfo(pResolvedToken, pConstrainedToken, m_methodInfo->ftn, callInfoFlags, &callInfo);
m_pConstrainedToken = NULL;

// This check really only applies to intrinsic Array.Address methods
Expand Down Expand Up @@ -5023,7 +5049,7 @@ void InterpCompiler::EmitLdftn(CORINFO_RESOLVED_TOKEN* pResolvedToken, bool isVi
}
else
{
EmitPushCORINFO_LOOKUP(callInfo.codePointerLookup);
EmitPushCallLookup(pResolvedToken, pConstrainedToken, &callInfo, callInfo.codePointerLookup);
}
}

Expand Down Expand Up @@ -5542,63 +5568,16 @@ 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)
{
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);
}
else 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*)exactClassHandle);
}
else
{
contextParamVar = EmitGenericHandle(&resolvedCallToken, GenericHandleEmbedOptions::VarOnly | GenericHandleEmbedOptions::EmbedParent).var;
}
EmitPushCallLookup(&resolvedCallToken, pConstrainedToken, &callInfo, callInfo.instParamLookup);
}
contextParamVar = (--m_pStackPointer)->var;
}
callArgs[extraParamArgLocation] = contextParamVar;
}
Expand Down Expand Up @@ -5816,7 +5795,7 @@ void InterpCompiler::EmitCall(CORINFO_RESOLVED_TOKEN* pConstrainedToken, bool re
m_pLastNewIns->SetSVar(callArgs[0]);
}

EmitPushCORINFO_LOOKUP(callInfo.codePointerLookup);
EmitPushCallLookup(&resolvedCallToken, pConstrainedToken, &callInfo, callInfo.codePointerLookup);
m_pStackPointer--;
int codePointerLookupResult = m_pStackPointer[0].var;

Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/interpreter/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,8 @@ class InterpCompiler
// Emit a generic dictionary lookup and push the result onto the interpreter stack
void CopyToInterpGenericLookup(InterpGenericLookup* dst, const CORINFO_RUNTIME_LOOKUP *src);
void EmitPushCORINFO_LOOKUP(const CORINFO_LOOKUP& lookup);
void EmitPushCallLookup(CORINFO_RESOLVED_TOKEN* token, CORINFO_RESOLVED_TOKEN* constrainedToken,
CORINFO_CALL_INFO* callInfo, CORINFO_LOOKUP& lookup);
void EmitPushLdvirtftn(int thisVar, CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_CALL_INFO* pCallInfo);
void EmitPushHelperCall_2(const CorInfoHelpFunc ftn, const CORINFO_GENERICHANDLE_RESULT& arg1, int arg2, StackType resultStackType, CORINFO_CLASS_HANDLE clsHndStack);
void EmitPushHelperCall_Addr2(const CorInfoHelpFunc ftn, const CORINFO_GENERICHANDLE_RESULT& arg1, int arg2, StackType resultStackType, CORINFO_CLASS_HANDLE clsHndStack);
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.

Loading
Loading