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
14 changes: 14 additions & 0 deletions src/coreclr/interpreter/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4032,6 +4032,19 @@ bool InterpCompiler::EmitNamedIntrinsicCall(NamedIntrinsic ni, bool nonVirtualCa
return true;
}

case NI_System_Runtime_CompilerServices_RuntimeHelpers_IsRuntimeAsync:
{
int32_t result = m_methodInfo->args.isAsyncCall() ? 1 : 0;

AddIns(INTOP_LDC_I4);
m_pLastNewIns->data[0] = result;

PushInterpType(InterpTypeI4, nullptr);
m_pLastNewIns->SetDVar(m_pStackPointer[-1].var);

return true;
}

case NI_System_Runtime_CompilerServices_RuntimeHelpers_IsReferenceOrContainsReferences:
{
CORINFO_CLASS_HANDLE clsHnd = sig.sigInst.methInst[0];
Expand Down Expand Up @@ -5140,6 +5153,7 @@ void InterpCompiler::EmitCall(CORINFO_RESOLVED_TOKEN* pConstrainedToken, bool re
ni == NI_System_StubHelpers_NextCallReturnAddress ||
ni == NI_System_Runtime_CompilerServices_RuntimeHelpers_SetNextCallGenericContext ||
ni == NI_System_Runtime_CompilerServices_RuntimeHelpers_SetNextCallAsyncContinuation ||
ni == NI_System_Runtime_CompilerServices_RuntimeHelpers_IsRuntimeAsync ||
ni == NI_System_Runtime_CompilerServices_AsyncHelpers_AsyncCallContinuation ||
ni == NI_System_Runtime_CompilerServices_AsyncHelpers_AsyncSuspend ||
ni == NI_System_Runtime_CompilerServices_AsyncHelpers_TailAwait);
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/interpreter/intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ NamedIntrinsic GetNamedIntrinsic(COMP_HANDLE compHnd, CORINFO_METHOD_HANDLE comp
{
if (!strcmp(methodName, "IsReferenceOrContainsReferences"))
return NI_System_Runtime_CompilerServices_RuntimeHelpers_IsReferenceOrContainsReferences;
else if (!strcmp(methodName, "IsRuntimeAsync"))
return NI_System_Runtime_CompilerServices_RuntimeHelpers_IsRuntimeAsync;
else if (!strcmp(methodName, "GetMethodTable"))
return NI_System_Runtime_CompilerServices_RuntimeHelpers_GetMethodTable;
else if (!strcmp(methodName, "SetNextCallGenericContext"))
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/jit/fgbasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,12 @@ void Compiler::fgFindJumpTargets(const BYTE* codeAddr, IL_OFFSET codeSize, Fixed
foldableIntrinsic = true;
break;

case NI_System_Runtime_CompilerServices_RuntimeHelpers_IsRuntimeAsync:
// RuntimeHelpers.IsRuntimeAsync is always folded into a const
pushedStack.PushConstant();
foldableIntrinsic = true;
break;

// These are foldable if the first argument is a constant
case NI_PRIMITIVE_LeadingZeroCount:
case NI_PRIMITIVE_Log2:
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/jit/importercalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3508,6 +3508,12 @@ GenTree* Compiler::impIntrinsic(CORINFO_CLASS_HANDLE clsHnd,
return gtNewNothingNode();
}

if (ni == NI_System_Runtime_CompilerServices_RuntimeHelpers_IsRuntimeAsync)
{
JITDUMP("\nExpanding RuntimeHelpers.IsRuntimeAsync to %s early\n", compIsAsync() ? "true" : "false");
return compIsAsync() ? gtNewTrue() : gtNewFalse();
}

bool betterToExpand = false;

// Allow some lightweight intrinsics in Tier0 which can improve throughput
Expand Down Expand Up @@ -11429,6 +11435,10 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method)
{
result = NI_System_Runtime_CompilerServices_RuntimeHelpers_IsKnownConstant;
}
else if (strcmp(methodName, "IsRuntimeAsync") == 0)
{
result = NI_System_Runtime_CompilerServices_RuntimeHelpers_IsRuntimeAsync;
}
else if (strcmp(methodName, "WriteBarrier") == 0)
{
result = NI_System_Runtime_CompilerServices_RuntimeHelpers_WriteBarrier;
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 @@ -124,6 +124,7 @@ enum NamedIntrinsic : unsigned short
NI_System_Runtime_CompilerServices_RuntimeHelpers_CreateSpan,
NI_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray,
NI_System_Runtime_CompilerServices_RuntimeHelpers_IsKnownConstant,
NI_System_Runtime_CompilerServices_RuntimeHelpers_IsRuntimeAsync,
NI_System_Runtime_CompilerServices_RuntimeHelpers_IsReferenceOrContainsReferences,
NI_System_Runtime_CompilerServices_RuntimeHelpers_GetMethodTable,
NI_System_Runtime_CompilerServices_RuntimeHelpers_WriteBarrier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ public static ReadOnlySpan<T> CreateSpan<T>(RuntimeFieldHandle fldHandle)
internal static bool IsKnownConstant<T>(T t) where T : struct => false;
#pragma warning restore IDE0060

// Returns true if the method being compiled is a runtime-async method.
// This is folded to a compile-time constant by the JIT and the interpreter.
[Intrinsic]
internal static bool IsRuntimeAsync() => false;

/// <returns>true if the given type is a reference type or a value type that contains references or by-refs; otherwise, false.</returns>
[Intrinsic]
public static bool IsReferenceOrContainsReferences<T>() where T : allows ref struct => IsReferenceOrContainsReferences<T>();
Expand Down
Loading