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
49 changes: 49 additions & 0 deletions src/coreclr/jit/importercalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3898,6 +3898,12 @@ GenTree* Compiler::impIntrinsic(CORINFO_CLASS_HANDLE clsHnd,
break;
}

case NI_System_Activator_CreateInstance_T:
{
isSpecial = true;
break;
}

case NI_System_Span_get_Item:
case NI_System_ReadOnlySpan_get_Item:
{
Expand Down Expand Up @@ -9989,6 +9995,40 @@ CORINFO_CLASS_HANDLE Compiler::impGetSpecialIntrinsicExactReturnType(GenTreeCall
break;
}

case NI_System_Activator_CreateInstance_T:
{
// Expect one method generic parameter; figure out which it is.
CORINFO_SIG_INFO sig;
info.compCompHnd->getMethodSig(methodHnd, &sig);
assert(sig.sigInst.methInstCount == 1);
assert(sig.sigInst.classInstCount == 0);

CORINFO_CLASS_HANDLE typeHnd = sig.sigInst.methInst[0];
assert(typeHnd != nullptr);
Comment thread
JulieLeeMSFT marked this conversation as resolved.

CallArg* instParam = call->gtArgs.FindWellKnownArg(WellKnownArg::InstParam);
if (instParam != nullptr)
{
assert(instParam->GetNext() == nullptr);
CORINFO_METHOD_HANDLE hMethod = gtGetHelperArgMethodHandle(instParam->GetNode());
if (hMethod != NO_METHOD_HANDLE)
{
result = getMethodInstantiationArgument(hMethod, 0);
}
}

if (result != NO_CLASS_HANDLE)
{
JITDUMP("Special intrinsic: return type is %s\n",
result != nullptr ? eeGetClassName(result) : "unknown");
}
else
{
JITDUMP("Special intrinsic: return type undetermined or inexact, so deferring opt\n");
}
break;
}

default:
{
JITDUMP("This special intrinsic not handled, sorry...\n");
Expand Down Expand Up @@ -10726,6 +10766,15 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method)
{
result = NI_System_Activator_AllocatorOf;
}
else if (strcmp(methodName, "CreateInstance") == 0)
{
CORINFO_SIG_INFO sig;
eeGetMethodSig(method, &sig);
if ((sig.sigInst.methInstCount == 1) && (sig.sigInst.classInstCount == 0))
{
result = NI_System_Activator_CreateInstance_T;
}
}
Comment thread
Copilot marked this conversation as resolved.
else if (strcmp(methodName, "DefaultConstructorOf") == 0)
{
result = NI_System_Activator_DefaultConstructorOf;
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/namedintrinsiclist.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ enum NamedIntrinsic : unsigned short
NI_System_Type_op_Inequality,
NI_System_Type_GetTypeFromHandle,
NI_System_Type_GetGenericTypeDefinition,
NI_System_Activator_CreateInstance_T,
NI_System_Array_Clone,
NI_System_Array_GetLength,
NI_System_Array_GetLowerBound,
Expand Down
Loading