Skip to content
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

Convert some old style intrinsics to NamedIntrinsic #62271

Merged
merged 9 commits into from
Dec 9, 2021
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
2 changes: 1 addition & 1 deletion docs/design/coreclr/botr/clr-abi.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ ARM64-only: When a method returns a structure that is larger than 16 bytes the c

*Calli Pinvoke* - The VM wants the address of the PInvoke in (AMD64) `R10` / (ARM) `R12` / (ARM64) `R14` (In the JIT: `REG_PINVOKE_TARGET_PARAM`), and the signature (the pinvoke cookie) in (AMD64) `R11` / (ARM) `R4` / (ARM64) `R15` (in the JIT: `REG_PINVOKE_COOKIE_PARAM`).

*Normal PInvoke* - The VM shares IL stubs based on signatures, but wants the right method to show up in call stack and exceptions, so the MethodDesc for the exact PInvoke is passed in the (x86) `EAX` / (AMD64) `R10` / (ARM, ARM64) `R12` (in the JIT: `REG_SECRET_STUB_PARAM`). Then in the IL stub, when the JIT gets `CORJIT_FLG_PUBLISH_SECRET_PARAM`, it must move the register into a compiler temp. The value is returned for the intrinsic `CORINFO_INTRINSIC_StubHelpers_GetStubContext`, and the address of that location is returned for `CORINFO_INTRINSIC_StubHelpers_GetStubContextAddr`.
*Normal PInvoke* - The VM shares IL stubs based on signatures, but wants the right method to show up in call stack and exceptions, so the MethodDesc for the exact PInvoke is passed in the (x86) `EAX` / (AMD64) `R10` / (ARM, ARM64) `R12` (in the JIT: `REG_SECRET_STUB_PARAM`). Then in the IL stub, when the JIT gets `CORJIT_FLG_PUBLISH_SECRET_PARAM`, it must move the register into a compiler temp. The value is returned for the intrinsic `NI_System_StubHelpers_GetStubContext`.

# PInvokes

Expand Down
8 changes: 2 additions & 6 deletions src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ internal static class StubHelpers
internal static extern IntPtr GetNDirectTarget(IntPtr pMD);

[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern IntPtr GetDelegateTarget(Delegate pThis, ref IntPtr pStubArg);
internal static extern IntPtr GetDelegateTarget(Delegate pThis);

[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void ClearLastError();
Expand Down Expand Up @@ -1348,11 +1348,6 @@ internal static void CheckStringLength(uint length)
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern IntPtr GetStubContext();

#if TARGET_64BIT
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern IntPtr GetStubContextAddr();
#endif // TARGET_64BIT

#if FEATURE_ARRAYSTUB_AS_IL
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void ArrayTypeCheck(object o, object[] arr);
Expand All @@ -1363,6 +1358,7 @@ internal static void CheckStringLength(uint length)
internal static extern void MulticastDebuggerTraceHelper(object o, int count);
#endif

[Intrinsic]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern IntPtr NextCallReturnAddress();
} // class StubHelpers
Expand Down
5 changes: 0 additions & 5 deletions src/coreclr/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -885,11 +885,6 @@ enum CorInfoIntrinsics
CORINFO_INTRINSIC_Array_Get, // Get the value of an element in an array
CORINFO_INTRINSIC_Array_Address, // Get the address of an element in an array
CORINFO_INTRINSIC_Array_Set, // Set the value of an element in an array
CORINFO_INTRINSIC_RTH_GetValueInternal,
CORINFO_INTRINSIC_Object_GetType,
CORINFO_INTRINSIC_StubHelpers_GetStubContext,
CORINFO_INTRINSIC_StubHelpers_GetStubContextAddr,
CORINFO_INTRINSIC_StubHelpers_NextCallReturnAddress,

CORINFO_INTRINSIC_ByReference_Ctor,
CORINFO_INTRINSIC_ByReference_Value,
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 = { /* 0c6f2d8d-f1b7-4c28-bbe8-36c8f6b35fbf */
0xc6f2d8d,
0xf1b7,
0x4c28,
{ 0xbb, 0xe8, 0x36, 0xc8, 0xf6, 0xb3, 0x5f, 0xbf}
constexpr GUID JITEEVersionIdentifier = { /* 3d9496d4-03f7-4eb0-bf7a-a88794e74537 */
0x3d9496d4,
0x03f7,
0x4eb0,
{0xbf, 0x7a, 0xa8, 0x87, 0x94, 0xe7, 0x45, 0x37}
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -4411,6 +4411,7 @@ class Compiler
CORINFO_RESOLVED_TOKEN* pContstrainedResolvedToken,
CORINFO_THIS_TRANSFORM constraintCallThisTransform,
CorInfoIntrinsics* pIntrinsicID,
NamedIntrinsic* pIntrinsicName,
bool* isSpecialIntrinsic = nullptr);
GenTree* impMathIntrinsic(CORINFO_METHOD_HANDLE method,
CORINFO_SIG_INFO* sig,
Expand Down
208 changes: 99 additions & 109 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3784,21 +3784,16 @@ unsigned Compiler::gtSetEvalOrder(GenTree* tree)
}
break;
}

case NI_System_Object_GetType:
// Giving intrinsics a large fixed execution cost is because we'd like to CSE
// them, even if they are implemented by calls. This is different from modeling
// user calls since we never CSE user calls.
costEx = 36;
costSz = 4;
break;
}
}
else
{
// old style intrinsic (only Object_GetType is expected)
assert(intrinsic->gtIntrinsicName == NI_Illegal);
assert(intrinsic->gtIntrinsicId == CORINFO_INTRINSIC_Object_GetType);

// Giving intrinsics a large fixed execution cost is because we'd like to CSE
// them, even if they are implemented by calls. This is different from modeling
// user calls since we never CSE user calls.
costEx = 36;
costSz = 4;
break;
}
level++;
break;

Expand Down Expand Up @@ -10791,101 +10786,96 @@ void Compiler::gtDispTree(GenTree* tree,
{
GenTreeIntrinsic* intrinsic = tree->AsIntrinsic();

if (intrinsic->gtIntrinsicId == CORINFO_INTRINSIC_Object_GetType)
assert(intrinsic->gtIntrinsicId == CORINFO_INTRINSIC_Illegal);
switch (intrinsic->gtIntrinsicName)
{
assert(intrinsic->gtIntrinsicName == NI_Illegal);
printf(" objGetType");
}
else
{
assert(intrinsic->gtIntrinsicId == CORINFO_INTRINSIC_Illegal);
switch (intrinsic->gtIntrinsicName)
{
case NI_System_Math_Abs:
printf(" abs");
break;
case NI_System_Math_Acos:
printf(" acos");
break;
case NI_System_Math_Acosh:
printf(" acosh");
break;
case NI_System_Math_Asin:
printf(" asin");
break;
case NI_System_Math_Asinh:
printf(" asinh");
break;
case NI_System_Math_Atan:
printf(" atan");
break;
case NI_System_Math_Atanh:
printf(" atanh");
break;
case NI_System_Math_Atan2:
printf(" atan2");
break;
case NI_System_Math_Cbrt:
printf(" cbrt");
break;
case NI_System_Math_Ceiling:
printf(" ceiling");
break;
case NI_System_Math_Cos:
printf(" cos");
break;
case NI_System_Math_Cosh:
printf(" cosh");
break;
case NI_System_Math_Exp:
printf(" exp");
break;
case NI_System_Math_Floor:
printf(" floor");
break;
case NI_System_Math_FMod:
printf(" fmod");
break;
case NI_System_Math_FusedMultiplyAdd:
printf(" fma");
break;
case NI_System_Math_ILogB:
printf(" ilogb");
break;
case NI_System_Math_Log:
printf(" log");
break;
case NI_System_Math_Log2:
printf(" log2");
break;
case NI_System_Math_Log10:
printf(" log10");
break;
case NI_System_Math_Pow:
printf(" pow");
break;
case NI_System_Math_Round:
printf(" round");
break;
case NI_System_Math_Sin:
printf(" sin");
break;
case NI_System_Math_Sinh:
printf(" sinh");
break;
case NI_System_Math_Sqrt:
printf(" sqrt");
break;
case NI_System_Math_Tan:
printf(" tan");
break;
case NI_System_Math_Tanh:
printf(" tanh");
break;
case NI_System_Math_Abs:
printf(" abs");
break;
case NI_System_Math_Acos:
printf(" acos");
break;
case NI_System_Math_Acosh:
printf(" acosh");
break;
case NI_System_Math_Asin:
printf(" asin");
break;
case NI_System_Math_Asinh:
printf(" asinh");
break;
case NI_System_Math_Atan:
printf(" atan");
break;
case NI_System_Math_Atanh:
printf(" atanh");
break;
case NI_System_Math_Atan2:
printf(" atan2");
break;
case NI_System_Math_Cbrt:
printf(" cbrt");
break;
case NI_System_Math_Ceiling:
printf(" ceiling");
break;
case NI_System_Math_Cos:
printf(" cos");
break;
case NI_System_Math_Cosh:
printf(" cosh");
break;
case NI_System_Math_Exp:
printf(" exp");
break;
case NI_System_Math_Floor:
printf(" floor");
break;
case NI_System_Math_FMod:
printf(" fmod");
break;
case NI_System_Math_FusedMultiplyAdd:
printf(" fma");
break;
case NI_System_Math_ILogB:
printf(" ilogb");
break;
case NI_System_Math_Log:
printf(" log");
break;
case NI_System_Math_Log2:
printf(" log2");
break;
case NI_System_Math_Log10:
printf(" log10");
break;
case NI_System_Math_Pow:
printf(" pow");
break;
case NI_System_Math_Round:
printf(" round");
break;
case NI_System_Math_Sin:
printf(" sin");
break;
case NI_System_Math_Sinh:
printf(" sinh");
break;
case NI_System_Math_Sqrt:
printf(" sqrt");
break;
case NI_System_Math_Tan:
printf(" tan");
break;
case NI_System_Math_Tanh:
printf(" tanh");
break;
case NI_System_Object_GetType:
printf(" objGetType");
break;

default:
unreached();
}
default:
unreached();
}
}

Expand Down Expand Up @@ -15146,13 +15136,13 @@ Compiler::TypeProducerKind Compiler::gtGetTypeProducerKind(GenTree* tree)
}
else if (tree->AsCall()->gtCallMoreFlags & GTF_CALL_M_SPECIAL_INTRINSIC)
{
if (info.compCompHnd->getIntrinsicID(tree->AsCall()->gtCallMethHnd) == CORINFO_INTRINSIC_Object_GetType)
if (lookupNamedIntrinsic(tree->AsCall()->gtCallMethHnd) == NI_System_Object_GetType)
{
return TPK_GetType;
}
}
}
else if ((tree->gtOper == GT_INTRINSIC) && (tree->AsIntrinsic()->gtIntrinsicId == CORINFO_INTRINSIC_Object_GetType))
else if ((tree->gtOper == GT_INTRINSIC) && (tree->AsIntrinsic()->gtIntrinsicName == NI_System_Object_GetType))
{
return TPK_GetType;
}
Expand Down Expand Up @@ -16737,7 +16727,7 @@ CORINFO_CLASS_HANDLE Compiler::gtGetClassHandle(GenTree* tree, bool* pIsExact, b
{
GenTreeIntrinsic* intrinsic = obj->AsIntrinsic();

if (intrinsic->gtIntrinsicId == CORINFO_INTRINSIC_Object_GetType)
if (intrinsic->gtIntrinsicName == NI_System_Object_GetType)
{
CORINFO_CLASS_HANDLE runtimeType = info.compCompHnd->getBuiltinClass(CLASSID_RUNTIME_TYPE);
assert(runtimeType != NO_CLASS_HANDLE);
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/gtlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ GTNODE(JMPTABLE , GenTree ,0, (GTK_LEAF|GTK_NOCONTAIN)) // Ge
GTNODE(SWITCH_TABLE , GenTreeOp ,0, (GTK_BINOP|GTK_NOVALUE)) // Jump Table based switch construct
#ifdef TARGET_ARM64
GTNODE(ADDEX, GenTreeOp ,0, GTK_BINOP) // Add with sign/zero extension
GTNODE(BFIZ , GenTreeOp ,0, GTK_BINOP) // Bitfield Insert in Zero
GTNODE(BFIZ , GenTreeOp ,0, GTK_BINOP) // Bitfield Insert in Zero
#endif

//-----------------------------------------------------------------------------
Expand Down
Loading