From daa2965c8d8205168cb7e60ce3e0c723ec817ab5 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Sun, 12 Dec 2021 19:25:36 +0200 Subject: [PATCH] Replace CorInfoIntrinsics with NamedIntrinsic (#62639) * Replace CorInfoIntrinsics with NamedIntrinsic * Implement NI_ARRAY_* intrinsics * Rename IsJitIntrinsic to IsIntrinsic --- .../superpmi/superpmi-shared/lwmlist.h | 4 +- .../superpmi-shared/methodcontext.cpp | 79 ++-- .../superpmi/superpmi-shared/methodcontext.h | 18 +- .../superpmi-shared/spmidumphelper.cpp | 1 - .../superpmi-shim-collector/icorjitinfo.cpp | 30 +- .../superpmi-shim-counter/icorjitinfo.cpp | 21 +- .../superpmi-shim-simple/icorjitinfo.cpp | 17 +- .../ToolBox/superpmi/superpmi/icorjitinfo.cpp | 24 +- src/coreclr/inc/corinfo.h | 53 +-- src/coreclr/inc/icorjitinfoimpl_generated.h | 9 +- src/coreclr/inc/jiteeversionguid.h | 10 +- src/coreclr/jit/ICorJitInfo_API_names.h | 4 +- src/coreclr/jit/ICorJitInfo_API_wrapper.hpp | 27 +- src/coreclr/jit/compiler.h | 9 +- src/coreclr/jit/ee_il_dll.hpp | 4 +- src/coreclr/jit/fgbasic.cpp | 14 +- src/coreclr/jit/flowgraph.cpp | 2 +- src/coreclr/jit/gentree.cpp | 137 +++---- src/coreclr/jit/gentree.h | 29 +- src/coreclr/jit/importer.cpp | 377 +++++++++--------- src/coreclr/jit/namedintrinsiclist.h | 11 + src/coreclr/jit/simd.cpp | 2 +- .../tools/Common/JitInterface/CorInfoBase.cs | 170 ++++---- .../JitInterface/CorInfoImpl.Intrinsics.cs | 150 ------- .../tools/Common/JitInterface/CorInfoImpl.cs | 24 +- .../tools/Common/JitInterface/CorInfoTypes.cs | 17 +- .../ThunkGenerator/ThunkInput.txt | 6 +- .../ILCompiler.ReadyToRun.csproj | 3 - .../JitInterface/CorInfoImpl.ReadyToRun.cs | 3 +- .../ILCompiler.RyuJit.csproj | 7 +- .../tools/aot/jitinterface/jitinterface.h | 27 +- src/coreclr/vm/array.cpp | 18 - src/coreclr/vm/ceeload.cpp | 2 +- src/coreclr/vm/ecall.h | 1 - src/coreclr/vm/genmeth.cpp | 6 +- src/coreclr/vm/interpreter.cpp | 17 +- src/coreclr/vm/jitinterface.cpp | 109 +++-- src/coreclr/vm/method.cpp | 17 - src/coreclr/vm/method.hpp | 15 +- src/coreclr/vm/methodtable.cpp | 18 - src/coreclr/vm/methodtable.h | 1 - src/coreclr/vm/methodtablebuilder.cpp | 2 +- 42 files changed, 613 insertions(+), 882 deletions(-) delete mode 100644 src/coreclr/tools/Common/JitInterface/CorInfoImpl.Intrinsics.cs diff --git a/src/coreclr/ToolBox/superpmi/superpmi-shared/lwmlist.h b/src/coreclr/ToolBox/superpmi/superpmi-shared/lwmlist.h index bb756ea722462..aae223f728562 100644 --- a/src/coreclr/ToolBox/superpmi/superpmi-shared/lwmlist.h +++ b/src/coreclr/ToolBox/superpmi/superpmi-shared/lwmlist.h @@ -53,6 +53,7 @@ LWM(GetArgNext, DWORDLONG, DWORDLONG) LWM(GetArgType, Agnostic_GetArgType_Key, Agnostic_GetArgType_Value) LWM(GetArrayInitializationData, DLD, DWORDLONG) LWM(GetArrayRank, DWORDLONG, DWORD) +LWM(GetArrayIntrinsicID, DWORDLONG, DWORD) LWM(GetBoundaries, DWORDLONG, Agnostic_GetBoundaries) LWM(GetBoxHelper, DWORDLONG, DWORD) LWM(GetBuiltinClass, DWORD, DWORDLONG) @@ -94,13 +95,12 @@ LWM(GetHelperName, DWORD, DWORD) LWM(GetHFAType, DWORDLONG, DWORD) LWM(GetInlinedCallFrameVptr, DWORD, DLDL) LWM(GetIntConfigValue, Agnostic_ConfigIntInfo, DWORD) -LWM(GetIntrinsicID, DWORDLONG, DD) LWM(GetJitFlags, DWORD, DD) LWM(GetJitTimeLogFilename, DWORD, DWORD) LWM(GetJustMyCodeHandle, DWORDLONG, DLDL) LWM(GetLazyStringLiteralHelper, DWORDLONG, DWORD) LWM(GetLocationOfThisType, DWORDLONG, Agnostic_CORINFO_LOOKUP_KIND) -LWM(IsJitIntrinsic, DWORDLONG, DWORD) +LWM(IsIntrinsic, DWORDLONG, DWORD) LWM(GetMethodAttribs, DWORDLONG, DWORD) LWM(GetClassModule, DWORDLONG, DWORDLONG) LWM(GetModuleAssembly, DWORDLONG, DWORDLONG) diff --git a/src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontext.cpp b/src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontext.cpp index 9ed65b7a5d1e0..ab8717dae42e8 100644 --- a/src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontext.cpp +++ b/src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontext.cpp @@ -778,26 +778,26 @@ DWORD MethodContext::repGetClassAttribs(CORINFO_CLASS_HANDLE classHandle) return value; } -void MethodContext::recIsJitIntrinsic(CORINFO_METHOD_HANDLE ftn, bool result) +void MethodContext::recIsIntrinsic(CORINFO_METHOD_HANDLE ftn, bool result) { - if (IsJitIntrinsic == nullptr) - IsJitIntrinsic = new LightWeightMap(); + if (IsIntrinsic == nullptr) + IsIntrinsic = new LightWeightMap(); DWORDLONG key = CastHandle(ftn); DWORD value = result ? 1 : 0; - IsJitIntrinsic->Add(key, value); - DEBUG_REC(dmpIsJitIntrinsic(key, value)); + IsIntrinsic->Add(key, value); + DEBUG_REC(dmpIsIntrinsic(key, value)); } -void MethodContext::dmpIsJitIntrinsic(DWORDLONG key, DWORD value) +void MethodContext::dmpIsIntrinsic(DWORDLONG key, DWORD value) { - printf("IsJitIntrinsic key ftn-%016llX, value res-%u", key, value); + printf("IsIntrinsic key ftn-%016llX, value res-%u", key, value); } -bool MethodContext::repIsJitIntrinsic(CORINFO_METHOD_HANDLE ftn) +bool MethodContext::repIsIntrinsic(CORINFO_METHOD_HANDLE ftn) { DWORDLONG key = CastHandle(ftn); - AssertMapAndKeyExist(IsJitIntrinsic, key, ": key %016llX", key); - DWORD value = IsJitIntrinsic->Get(key); - DEBUG_REP(dmpIsJitIntrinsic(key, value)); + AssertMapAndKeyExist(IsIntrinsic, key, ": key %016llX", key); + DWORD value = IsIntrinsic->Get(key); + DEBUG_REP(dmpIsIntrinsic(key, value)); return value != 0; } @@ -1710,39 +1710,6 @@ void MethodContext::repGetCallInfoFromMethodHandle(CORINFO_METHOD_HANDLE methodH LogException(EXCEPTIONCODE_MC, "Didn't find key %016llX.", methodHandle); } -void MethodContext::recGetIntrinsicID(CORINFO_METHOD_HANDLE method, bool* pMustExpand, CorInfoIntrinsics result) -{ - if (GetIntrinsicID == nullptr) - GetIntrinsicID = new LightWeightMap(); - - DD value; - value.A = (pMustExpand != nullptr) ? (DWORD)(*pMustExpand ? 1 : 0) : (DWORD)0; - value.B = (DWORD)result; - - DWORDLONG key = CastHandle(method); - GetIntrinsicID->Add(key, value); - DEBUG_REC(dmpGetIntrinsicID(key, value)); -} -void MethodContext::dmpGetIntrinsicID(DWORDLONG key, DD value) -{ - printf("GetIntrinsicID key mth-%016llX, mustExpand-%u, value intr-%u", key, value.A, value.B); -} -CorInfoIntrinsics MethodContext::repGetIntrinsicID(CORINFO_METHOD_HANDLE method, bool* pMustExpand) -{ - DWORDLONG key = CastHandle(method); - AssertMapAndKeyExist(GetIntrinsicID, key, ": key %016llX", key); - - DD value = GetIntrinsicID->Get(key); - DEBUG_REP(dmpGetIntrinsicID(key, value)); - - if (pMustExpand != nullptr) - { - *pMustExpand = (value.A == 0) ? false : true; - } - CorInfoIntrinsics result = (CorInfoIntrinsics)value.B; - return result; -} - void MethodContext::recIsIntrinsicType(CORINFO_CLASS_HANDLE cls, bool result) { if (IsIntrinsicType == nullptr) @@ -6725,6 +6692,30 @@ unsigned MethodContext::repGetArrayRank(CORINFO_CLASS_HANDLE cls) return result; } +void MethodContext::recGetArrayIntrinsicID(CORINFO_METHOD_HANDLE hMethod, CorInfoArrayIntrinsic result) +{ + if (GetArrayIntrinsicID == nullptr) + GetArrayIntrinsicID = new LightWeightMap(); + + DWORDLONG key = CastHandle(hMethod); + DWORD value = (DWORD)result; + GetArrayIntrinsicID->Add(key, value); + DEBUG_REC(dmpGetArrayIntrinsicID(key, value)); +} +void MethodContext::dmpGetArrayIntrinsicID(DWORDLONG key, DWORD value) +{ + printf("GetArrayIntrinsicID key %016llX, value %u", key, value); +} +CorInfoArrayIntrinsic MethodContext::repGetArrayIntrinsicID(CORINFO_METHOD_HANDLE hMethod) +{ + DWORDLONG key = CastHandle(hMethod); + AssertMapAndKeyExist(GetArrayIntrinsicID, key, ": key %016llX", key); + DWORD value = GetArrayIntrinsicID->Get(key); + DEBUG_REP(dmpGetArrayIntrinsicID(key, value)); + CorInfoArrayIntrinsic result = (CorInfoArrayIntrinsic)value; + return result; +} + void MethodContext::recIsFieldStatic(CORINFO_FIELD_HANDLE fhld, bool result) { if (IsFieldStatic == nullptr) diff --git a/src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontext.h b/src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontext.h index 2e695c6d22177..d18c531dd8648 100644 --- a/src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontext.h +++ b/src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontext.h @@ -125,9 +125,9 @@ class MethodContext void dmpGetClassAttribs(DWORDLONG key, DWORD value); DWORD repGetClassAttribs(CORINFO_CLASS_HANDLE classHandle); - void recIsJitIntrinsic(CORINFO_METHOD_HANDLE ftn, bool result); - void dmpIsJitIntrinsic(DWORDLONG key, DWORD value); - bool repIsJitIntrinsic(CORINFO_METHOD_HANDLE ftn); + void recIsIntrinsic(CORINFO_METHOD_HANDLE ftn, bool result); + void dmpIsIntrinsic(DWORDLONG key, DWORD value); + bool repIsIntrinsic(CORINFO_METHOD_HANDLE ftn); void recGetMethodAttribs(CORINFO_METHOD_HANDLE methodHandle, DWORD attribs); void dmpGetMethodAttribs(DWORDLONG key, DWORD value); @@ -225,10 +225,6 @@ class MethodContext DWORD* exceptionCode); void repGetCallInfoFromMethodHandle(CORINFO_METHOD_HANDLE methodHandle, CORINFO_CALL_INFO* pResult); - void recGetIntrinsicID(CORINFO_METHOD_HANDLE method, bool* pMustExpand, CorInfoIntrinsics result); - void dmpGetIntrinsicID(DWORDLONG key, DD value); - CorInfoIntrinsics repGetIntrinsicID(CORINFO_METHOD_HANDLE method, bool* pMustExpand); - void recAsCorInfoType(CORINFO_CLASS_HANDLE cls, CorInfoType result); void dmpAsCorInfoType(DWORDLONG key, DWORD value); CorInfoType repAsCorInfoType(CORINFO_CLASS_HANDLE cls); @@ -818,6 +814,10 @@ class MethodContext void dmpGetArrayRank(DWORDLONG key, DWORD value); unsigned repGetArrayRank(CORINFO_CLASS_HANDLE cls); + void recGetArrayIntrinsicID(CORINFO_METHOD_HANDLE hMethod, CorInfoArrayIntrinsic result); + void dmpGetArrayIntrinsicID(DWORDLONG key, DWORD value); + CorInfoArrayIntrinsic repGetArrayIntrinsicID(CORINFO_METHOD_HANDLE hMethod); + void recIsFieldStatic(CORINFO_FIELD_HANDLE fhld, bool result); void dmpIsFieldStatic(DWORDLONG key, DWORD value); bool repIsFieldStatic(CORINFO_FIELD_HANDLE fhld); @@ -970,7 +970,7 @@ enum mcPackets Packet_GetHelperFtn = 63, Packet_GetHelperName = 64, Packet_GetInlinedCallFrameVptr = 65, - Packet_GetIntrinsicID = 66, + Packet_GetArrayIntrinsicID = 66, Packet_GetJitTimeLogFilename = 67, Packet_GetJustMyCodeHandle = 68, Packet_GetLocationOfThisType = 69, @@ -1095,7 +1095,7 @@ enum mcPackets Packet_GetClassModule = 189, Packet_GetModuleAssembly = 190, Packet_GetAssemblyName = 191, - Packet_IsJitIntrinsic = 192, + Packet_IsIntrinsic = 192, Packet_UpdateEntryPointForTailCall = 193, }; diff --git a/src/coreclr/ToolBox/superpmi/superpmi-shared/spmidumphelper.cpp b/src/coreclr/ToolBox/superpmi/superpmi-shared/spmidumphelper.cpp index 9f32d6897ee69..ad4aee9fcd945 100644 --- a/src/coreclr/ToolBox/superpmi/superpmi-shared/spmidumphelper.cpp +++ b/src/coreclr/ToolBox/superpmi/superpmi-shared/spmidumphelper.cpp @@ -178,7 +178,6 @@ std::string SpmiDumpHelper::DumpCorInfoFlag(CorInfoFlag flags) AddFlag(CORINFO_FLG_DISABLE_TIER0_FOR_LOOPS); AddFlag(CORINFO_FLG_DONT_INLINE); AddFlag(CORINFO_FLG_DONT_INLINE_CALLER); - AddFlag(CORINFO_FLG_JIT_INTRINSIC); AddFlag(CORINFO_FLG_VALUECLASS); AddFlag(CORINFO_FLG_VAROBJSIZE); AddFlag(CORINFO_FLG_ARRAY); diff --git a/src/coreclr/ToolBox/superpmi/superpmi-shim-collector/icorjitinfo.cpp b/src/coreclr/ToolBox/superpmi/superpmi-shim-collector/icorjitinfo.cpp index 50fed27bb63bc..ad4830fa73b1a 100644 --- a/src/coreclr/ToolBox/superpmi/superpmi-shim-collector/icorjitinfo.cpp +++ b/src/coreclr/ToolBox/superpmi/superpmi-shim-collector/icorjitinfo.cpp @@ -19,12 +19,12 @@ /**********************************************************************************/ // Quick check whether the method is a jit intrinsic. Returns the same value as getMethodAttribs(ftn) & -// CORINFO_FLG_JIT_INTRINSIC, except faster. -bool interceptor_ICJI::isJitIntrinsic(CORINFO_METHOD_HANDLE ftn) +// CORINFO_FLG_INTRINSIC, except faster. +bool interceptor_ICJI::isIntrinsic(CORINFO_METHOD_HANDLE ftn) { - mc->cr->AddCall("isJitIntrinsic"); - bool temp = original_ICorJitInfo->isJitIntrinsic(ftn); - mc->recIsJitIntrinsic(ftn, temp); + mc->cr->AddCall("isIntrinsic"); + bool temp = original_ICorJitInfo->isIntrinsic(ftn); + mc->recIsIntrinsic(ftn, temp); return temp; } @@ -251,17 +251,6 @@ void interceptor_ICJI::expandRawHandleIntrinsic(CORINFO_RESOLVED_TOKEN* pR original_ICorJitInfo->expandRawHandleIntrinsic(pResolvedToken, pResult); } -// If a method's attributes have (getMethodAttribs) CORINFO_FLG_INTRINSIC set, -// getIntrinsicID() returns the intrinsic ID. -CorInfoIntrinsics interceptor_ICJI::getIntrinsicID(CORINFO_METHOD_HANDLE method, bool* pMustExpand /* OUT */ - ) -{ - mc->cr->AddCall("getIntrinsicID"); - CorInfoIntrinsics temp = original_ICorJitInfo->getIntrinsicID(method, pMustExpand); - mc->recGetIntrinsicID(method, pMustExpand, temp); - return temp; -} - // Is the given type in System.Private.Corelib and marked with IntrinsicAttribute? bool interceptor_ICJI::isIntrinsicType(CORINFO_CLASS_HANDLE classHnd) { @@ -962,6 +951,15 @@ unsigned interceptor_ICJI::getArrayRank(CORINFO_CLASS_HANDLE cls) return result; } +// Get the index of runtime provided array method +CorInfoArrayIntrinsic interceptor_ICJI::getArrayIntrinsicID(CORINFO_METHOD_HANDLE ftn) +{ + mc->cr->AddCall("getArrayIntrinsicID"); + CorInfoArrayIntrinsic result = original_ICorJitInfo->getArrayIntrinsicID(ftn); + mc->recGetArrayIntrinsicID(ftn, result); + return result; +} + // Get static field data for an array void* interceptor_ICJI::getArrayInitializationData(CORINFO_FIELD_HANDLE field, uint32_t size) { diff --git a/src/coreclr/ToolBox/superpmi/superpmi-shim-counter/icorjitinfo.cpp b/src/coreclr/ToolBox/superpmi/superpmi-shim-counter/icorjitinfo.cpp index 0b0507ddb121d..88e0e03e42d98 100644 --- a/src/coreclr/ToolBox/superpmi/superpmi-shim-counter/icorjitinfo.cpp +++ b/src/coreclr/ToolBox/superpmi/superpmi-shim-counter/icorjitinfo.cpp @@ -12,11 +12,11 @@ #include "spmiutil.h" -bool interceptor_ICJI::isJitIntrinsic( +bool interceptor_ICJI::isIntrinsic( CORINFO_METHOD_HANDLE ftn) { - mcs->AddCall("isJitIntrinsic"); - return original_ICorJitInfo->isJitIntrinsic(ftn); + mcs->AddCall("isIntrinsic"); + return original_ICorJitInfo->isIntrinsic(ftn); } uint32_t interceptor_ICJI::getMethodAttribs( @@ -161,14 +161,6 @@ void interceptor_ICJI::expandRawHandleIntrinsic( original_ICorJitInfo->expandRawHandleIntrinsic(pResolvedToken, pResult); } -CorInfoIntrinsics interceptor_ICJI::getIntrinsicID( - CORINFO_METHOD_HANDLE method, - bool* pMustExpand) -{ - mcs->AddCall("getIntrinsicID"); - return original_ICorJitInfo->getIntrinsicID(method, pMustExpand); -} - bool interceptor_ICJI::isIntrinsicType( CORINFO_CLASS_HANDLE classHnd) { @@ -682,6 +674,13 @@ unsigned interceptor_ICJI::getArrayRank( return original_ICorJitInfo->getArrayRank(cls); } +CorInfoArrayIntrinsic interceptor_ICJI::getArrayIntrinsicID( + CORINFO_METHOD_HANDLE ftn) +{ + mcs->AddCall("getArrayIntrinsicID"); + return original_ICorJitInfo->getArrayIntrinsicID(ftn); +} + void* interceptor_ICJI::getArrayInitializationData( CORINFO_FIELD_HANDLE field, uint32_t size) diff --git a/src/coreclr/ToolBox/superpmi/superpmi-shim-simple/icorjitinfo.cpp b/src/coreclr/ToolBox/superpmi/superpmi-shim-simple/icorjitinfo.cpp index 6e1d86a176271..1692685887178 100644 --- a/src/coreclr/ToolBox/superpmi/superpmi-shim-simple/icorjitinfo.cpp +++ b/src/coreclr/ToolBox/superpmi/superpmi-shim-simple/icorjitinfo.cpp @@ -12,10 +12,10 @@ #include "spmiutil.h" -bool interceptor_ICJI::isJitIntrinsic( +bool interceptor_ICJI::isIntrinsic( CORINFO_METHOD_HANDLE ftn) { - return original_ICorJitInfo->isJitIntrinsic(ftn); + return original_ICorJitInfo->isIntrinsic(ftn); } uint32_t interceptor_ICJI::getMethodAttribs( @@ -143,13 +143,6 @@ void interceptor_ICJI::expandRawHandleIntrinsic( original_ICorJitInfo->expandRawHandleIntrinsic(pResolvedToken, pResult); } -CorInfoIntrinsics interceptor_ICJI::getIntrinsicID( - CORINFO_METHOD_HANDLE method, - bool* pMustExpand) -{ - return original_ICorJitInfo->getIntrinsicID(method, pMustExpand); -} - bool interceptor_ICJI::isIntrinsicType( CORINFO_CLASS_HANDLE classHnd) { @@ -597,6 +590,12 @@ unsigned interceptor_ICJI::getArrayRank( return original_ICorJitInfo->getArrayRank(cls); } +CorInfoArrayIntrinsic interceptor_ICJI::getArrayIntrinsicID( + CORINFO_METHOD_HANDLE ftn) +{ + return original_ICorJitInfo->getArrayIntrinsicID(ftn); +} + void* interceptor_ICJI::getArrayInitializationData( CORINFO_FIELD_HANDLE field, uint32_t size) diff --git a/src/coreclr/ToolBox/superpmi/superpmi/icorjitinfo.cpp b/src/coreclr/ToolBox/superpmi/superpmi/icorjitinfo.cpp index 350931cf3aaf9..e633a1ab385af 100644 --- a/src/coreclr/ToolBox/superpmi/superpmi/icorjitinfo.cpp +++ b/src/coreclr/ToolBox/superpmi/superpmi/icorjitinfo.cpp @@ -24,11 +24,11 @@ ICorJitInfo* InitICorJitInfo(JitInstance* jitInstance) /**********************************************************************************/ // Quick check whether the method is a jit intrinsic. Returns the same value as getMethodAttribs(ftn) & -// CORINFO_FLG_JIT_INTRINSIC, except faster. -bool MyICJI::isJitIntrinsic(CORINFO_METHOD_HANDLE ftn) +// CORINFO_FLG_INTRINSIC, except faster. +bool MyICJI::isIntrinsic(CORINFO_METHOD_HANDLE ftn) { - jitInstance->mc->cr->AddCall("isJitIntrinsic"); - return jitInstance->mc->repIsJitIntrinsic(ftn); + jitInstance->mc->cr->AddCall("isIntrinsic"); + return jitInstance->mc->repIsIntrinsic(ftn); } // return flags (defined above, CORINFO_FLG_PUBLIC ...) @@ -217,15 +217,6 @@ void MyICJI::expandRawHandleIntrinsic(CORINFO_RESOLVED_TOKEN* pResolvedToken, CO DebugBreakorAV(129); } -// If a method's attributes have (getMethodAttribs) CORINFO_FLG_INTRINSIC set, -// getIntrinsicID() returns the intrinsic ID. -CorInfoIntrinsics MyICJI::getIntrinsicID(CORINFO_METHOD_HANDLE method, bool* pMustExpand /* OUT */ - ) -{ - jitInstance->mc->cr->AddCall("getIntrinsicID"); - return jitInstance->mc->repGetIntrinsicID(method, pMustExpand); -} - // Is the given type in System.Private.Corelib and marked with IntrinsicAttribute? bool MyICJI::isIntrinsicType(CORINFO_CLASS_HANDLE classHnd) { @@ -823,6 +814,13 @@ unsigned MyICJI::getArrayRank(CORINFO_CLASS_HANDLE cls) return jitInstance->mc->repGetArrayRank(cls); } +// Get the index of runtime provided array method +CorInfoArrayIntrinsic MyICJI::getArrayIntrinsicID(CORINFO_METHOD_HANDLE hMethod) +{ + jitInstance->mc->cr->AddCall("getArrayIntrinsicID"); + return jitInstance->mc->repGetArrayIntrinsicID(hMethod); +} + // Get static field data for an array void* MyICJI::getArrayInitializationData(CORINFO_FIELD_HANDLE field, uint32_t size) { diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index ae24d18c2c966..f6f341e56f32a 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -795,7 +795,7 @@ enum CorInfoFlag // CORINFO_FLG_UNUSED = 0x08000000, CORINFO_FLG_DONT_INLINE = 0x10000000, // The method should not be inlined CORINFO_FLG_DONT_INLINE_CALLER = 0x20000000, // The method should not be inlined, nor should its callers. It cannot be tail called. - CORINFO_FLG_JIT_INTRINSIC = 0x40000000, // Method is a potential jit intrinsic; verify identity by name check +// CORINFO_FLG_UNUSED = 0x40000000, // These are internal flags that can only be on Classes CORINFO_FLG_VALUECLASS = 0x00010000, // is the class a value class @@ -874,24 +874,15 @@ enum CorInfoException CORINFO_Exception_Count, }; - -// This enumeration is returned by getIntrinsicID. Methods corresponding to -// these values will have "well-known" specified behavior. Calls to these -// methods could be replaced with inlined code corresponding to the -// specified behavior (without having to examine the IL beforehand). - -enum CorInfoIntrinsics +// These are used to detect array methods as NamedIntrinsic in JIT importer, +// which otherwise don't have a name. +enum class CorInfoArrayIntrinsic { - 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 + GET = 0, + SET = 1, + ADDRESS = 2, - CORINFO_INTRINSIC_ByReference_Ctor, - CORINFO_INTRINSIC_ByReference_Value, - CORINFO_INTRINSIC_GetRawHandle, - - CORINFO_INTRINSIC_Count, - CORINFO_INTRINSIC_Illegal = -1, // Not a true intrinsic, + ILLEGAL }; // Can a value be accessed directly from JITed code. @@ -1962,8 +1953,8 @@ class ICorStaticInfo // /**********************************************************************************/ - // Quick check whether the method is a jit intrinsic. Returns the same value as getMethodAttribs(ftn) & CORINFO_FLG_JIT_INTRINSIC, except faster. - virtual bool isJitIntrinsic(CORINFO_METHOD_HANDLE ftn) = 0; + // Quick check whether the method is a jit intrinsic. Returns the same value as getMethodAttribs(ftn) & CORINFO_FLG_INTRINSIC, except faster. + virtual bool isIntrinsic(CORINFO_METHOD_HANDLE ftn) = 0; // return flags (a bitfield of CorInfoFlags values) virtual uint32_t getMethodAttribs ( @@ -2094,23 +2085,16 @@ class ICorStaticInfo CORINFO_CLASS_HANDLE elemType ) = 0; - // Given resolved token that corresponds to an intrinsic classified as - // a CORINFO_INTRINSIC_GetRawHandle intrinsic, fetch the handle associated - // with the token. If this is not possible at compile-time (because the current method's - // code is shared and the token contains generic parameters) then indicate - // how the handle should be looked up at runtime. + // Given resolved token that corresponds to an intrinsic classified to + // get a raw handle (NI_System_Activator_AllocatorOf etc.), fetch the + // handle associated with the token. If this is not possible at + // compile-time (because the current method's code is shared and the + // token contains generic parameters) then indicate how the handle + // should be looked up at runtime. virtual void expandRawHandleIntrinsic( CORINFO_RESOLVED_TOKEN * pResolvedToken, CORINFO_GENERICHANDLE_RESULT * pResult) = 0; - // If a method's attributes have (getMethodAttribs) CORINFO_FLG_INTRINSIC set, - // getIntrinsicID() returns the intrinsic ID. - // *pMustExpand tells whether or not JIT must expand the intrinsic. - virtual CorInfoIntrinsics getIntrinsicID( - CORINFO_METHOD_HANDLE method, - bool* pMustExpand = NULL /* OUT */ - ) = 0; - // Is the given type in System.Private.Corelib and marked with IntrinsicAttribute? // This defaults to false. virtual bool isIntrinsicType( @@ -2559,6 +2543,11 @@ class ICorStaticInfo CORINFO_CLASS_HANDLE cls ) = 0; + // Get the index of runtime provided array method + virtual CorInfoArrayIntrinsic getArrayIntrinsicID( + CORINFO_METHOD_HANDLE ftn + ) = 0; + // Get static field data for an array virtual void * getArrayInitializationData( CORINFO_FIELD_HANDLE field, diff --git a/src/coreclr/inc/icorjitinfoimpl_generated.h b/src/coreclr/inc/icorjitinfoimpl_generated.h index d912b90b8612b..602bfc74c1a68 100644 --- a/src/coreclr/inc/icorjitinfoimpl_generated.h +++ b/src/coreclr/inc/icorjitinfoimpl_generated.h @@ -21,7 +21,7 @@ public: -bool isJitIntrinsic( +bool isIntrinsic( CORINFO_METHOD_HANDLE ftn) override; uint32_t getMethodAttribs( @@ -98,10 +98,6 @@ void expandRawHandleIntrinsic( CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_GENERICHANDLE_RESULT* pResult) override; -CorInfoIntrinsics getIntrinsicID( - CORINFO_METHOD_HANDLE method, - bool* pMustExpand) override; - bool isIntrinsicType( CORINFO_CLASS_HANDLE classHnd) override; @@ -351,6 +347,9 @@ bool isSDArray( unsigned getArrayRank( CORINFO_CLASS_HANDLE cls) override; +CorInfoArrayIntrinsic getArrayIntrinsicID( + CORINFO_METHOD_HANDLE ftn) override; + void* getArrayInitializationData( CORINFO_FIELD_HANDLE field, uint32_t size) override; diff --git a/src/coreclr/inc/jiteeversionguid.h b/src/coreclr/inc/jiteeversionguid.h index 21679993f73a6..a32a05ad530b1 100644 --- a/src/coreclr/inc/jiteeversionguid.h +++ b/src/coreclr/inc/jiteeversionguid.h @@ -43,11 +43,11 @@ typedef const GUID *LPCGUID; #define GUID_DEFINED #endif // !GUID_DEFINED -constexpr GUID JITEEVersionIdentifier = { /* 3d9496d4-03f7-4eb0-bf7a-a88794e74537 */ - 0x3d9496d4, - 0x03f7, - 0x4eb0, - {0xbf, 0x7a, 0xa8, 0x87, 0x94, 0xe7, 0x45, 0x37} +constexpr GUID JITEEVersionIdentifier = { /* 29ff53ef-3c61-4fc4-bdab-82e39a3d7970 */ + 0x29ff53ef, + 0x3c61, + 0x4fc4, + {0xbd, 0xab, 0x82, 0xe3, 0x9a, 0x3d, 0x79, 0x70} }; ////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/coreclr/jit/ICorJitInfo_API_names.h b/src/coreclr/jit/ICorJitInfo_API_names.h index 64e8db858b944..d373091453220 100644 --- a/src/coreclr/jit/ICorJitInfo_API_names.h +++ b/src/coreclr/jit/ICorJitInfo_API_names.h @@ -4,7 +4,7 @@ // DO NOT EDIT THIS FILE! IT IS AUTOGENERATED // To regenerate run the gen script in src/coreclr/tools/Common/JitInterface/ThunkGenerator // and follow the instructions in docs/project/updating-jitinterface.md -DEF_CLR_API(isJitIntrinsic) +DEF_CLR_API(isIntrinsic) DEF_CLR_API(getMethodAttribs) DEF_CLR_API(setMethodAttribs) DEF_CLR_API(getMethodSig) @@ -22,7 +22,6 @@ DEF_CLR_API(getUnboxedEntry) DEF_CLR_API(getDefaultComparerClass) DEF_CLR_API(getDefaultEqualityComparerClass) DEF_CLR_API(expandRawHandleIntrinsic) -DEF_CLR_API(getIntrinsicID) DEF_CLR_API(isIntrinsicType) DEF_CLR_API(getUnmanagedCallConv) DEF_CLR_API(pInvokeMarshalingRequired) @@ -89,6 +88,7 @@ DEF_CLR_API(getChildType) DEF_CLR_API(satisfiesClassConstraints) DEF_CLR_API(isSDArray) DEF_CLR_API(getArrayRank) +DEF_CLR_API(getArrayIntrinsicID) DEF_CLR_API(getArrayInitializationData) DEF_CLR_API(canAccessClass) DEF_CLR_API(getFieldName) diff --git a/src/coreclr/jit/ICorJitInfo_API_wrapper.hpp b/src/coreclr/jit/ICorJitInfo_API_wrapper.hpp index 031d2ba75b505..1e2627ccb3c9a 100644 --- a/src/coreclr/jit/ICorJitInfo_API_wrapper.hpp +++ b/src/coreclr/jit/ICorJitInfo_API_wrapper.hpp @@ -12,12 +12,12 @@ // clang-format off /**********************************************************************************/ -bool WrapICorJitInfo::isJitIntrinsic( +bool WrapICorJitInfo::isIntrinsic( CORINFO_METHOD_HANDLE ftn) { - API_ENTER(isJitIntrinsic); - bool temp = wrapHnd->isJitIntrinsic(ftn); - API_LEAVE(isJitIntrinsic); + API_ENTER(isIntrinsic); + bool temp = wrapHnd->isIntrinsic(ftn); + API_LEAVE(isIntrinsic); return temp; } @@ -190,16 +190,6 @@ void WrapICorJitInfo::expandRawHandleIntrinsic( API_LEAVE(expandRawHandleIntrinsic); } -CorInfoIntrinsics WrapICorJitInfo::getIntrinsicID( - CORINFO_METHOD_HANDLE method, - bool* pMustExpand) -{ - API_ENTER(getIntrinsicID); - CorInfoIntrinsics temp = wrapHnd->getIntrinsicID(method, pMustExpand); - API_LEAVE(getIntrinsicID); - return temp; -} - bool WrapICorJitInfo::isIntrinsicType( CORINFO_CLASS_HANDLE classHnd) { @@ -836,6 +826,15 @@ unsigned WrapICorJitInfo::getArrayRank( return temp; } +CorInfoArrayIntrinsic WrapICorJitInfo::getArrayIntrinsicID( + CORINFO_METHOD_HANDLE ftn) +{ + API_ENTER(getArrayIntrinsicID); + CorInfoArrayIntrinsic temp = wrapHnd->getArrayIntrinsicID(ftn); + API_LEAVE(getArrayIntrinsicID); + return temp; +} + void* WrapICorJitInfo::getArrayInitializationData( CORINFO_FIELD_HANDLE field, uint32_t size) diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 17878f92806bf..a7a7a55b9f46f 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -4396,10 +4396,6 @@ class Compiler void impResetLeaveBlock(BasicBlock* block, unsigned jmpAddr); GenTree* impTypeIsAssignable(GenTree* typeTo, GenTree* typeFrom); -#ifdef DEBUG - const char* impGetIntrinsicName(CorInfoIntrinsics intrinsicID); -#endif // DEBUG - GenTree* impIntrinsic(GenTree* newobjThis, CORINFO_CLASS_HANDLE clsHnd, CORINFO_METHOD_HANDLE method, @@ -4410,7 +4406,6 @@ class Compiler bool tailCall, CORINFO_RESOLVED_TOKEN* pContstrainedResolvedToken, CORINFO_THIS_TRANSFORM constraintCallThisTransform, - CorInfoIntrinsics* pIntrinsicID, NamedIntrinsic* pIntrinsicName, bool* isSpecialIntrinsic = nullptr); GenTree* impMathIntrinsic(CORINFO_METHOD_HANDLE method, @@ -4482,7 +4477,7 @@ class Compiler CORINFO_SIG_INFO* sig, int memberRef, bool readonlyCall, - CorInfoIntrinsics intrinsicID); + NamedIntrinsic intrinsicName); GenTree* impInitializeArrayIntrinsic(CORINFO_SIG_INFO* sig); GenTree* impCreateSpanIntrinsic(CORINFO_SIG_INFO* sig); @@ -8035,7 +8030,7 @@ class Compiler // Get the flags bool eeIsValueClass(CORINFO_CLASS_HANDLE clsHnd); - bool eeIsJitIntrinsic(CORINFO_METHOD_HANDLE ftn); + bool eeIsIntrinsic(CORINFO_METHOD_HANDLE ftn); bool eeIsFieldStatic(CORINFO_FIELD_HANDLE fldHnd); var_types eeGetFieldType(CORINFO_FIELD_HANDLE fldHnd, CORINFO_CLASS_HANDLE* pStructHnd = nullptr); diff --git a/src/coreclr/jit/ee_il_dll.hpp b/src/coreclr/jit/ee_il_dll.hpp index abedfa4ddf077..33d5fab12ac5b 100644 --- a/src/coreclr/jit/ee_il_dll.hpp +++ b/src/coreclr/jit/ee_il_dll.hpp @@ -56,9 +56,9 @@ bool Compiler::eeIsValueClass(CORINFO_CLASS_HANDLE clsHnd) } FORCEINLINE -bool Compiler::eeIsJitIntrinsic(CORINFO_METHOD_HANDLE ftn) +bool Compiler::eeIsIntrinsic(CORINFO_METHOD_HANDLE ftn) { - return info.compCompHnd->isJitIntrinsic(ftn); + return info.compCompHnd->isIntrinsic(ftn); } FORCEINLINE diff --git a/src/coreclr/jit/fgbasic.cpp b/src/coreclr/jit/fgbasic.cpp index e763e2390930f..fb868e4566e32 100644 --- a/src/coreclr/jit/fgbasic.cpp +++ b/src/coreclr/jit/fgbasic.cpp @@ -1097,18 +1097,18 @@ void Compiler::fgFindJumpTargets(const BYTE* codeAddr, IL_OFFSET codeSize, Fixed break; } - CORINFO_METHOD_HANDLE methodHnd = nullptr; - bool isJitIntrinsic = false; - NamedIntrinsic ni = NI_Illegal; + CORINFO_METHOD_HANDLE methodHnd = nullptr; + bool isIntrinsic = false; + NamedIntrinsic ni = NI_Illegal; if (resolveTokens) { impResolveToken(codeAddr, &resolvedToken, CORINFO_TOKENKIND_Method); - methodHnd = resolvedToken.hMethod; - isJitIntrinsic = eeIsJitIntrinsic(methodHnd); + methodHnd = resolvedToken.hMethod; + isIntrinsic = eeIsIntrinsic(methodHnd); } - if (isJitIntrinsic) + if (isIntrinsic) { ni = lookupNamedIntrinsic(methodHnd); @@ -1244,7 +1244,7 @@ void Compiler::fgFindJumpTargets(const BYTE* codeAddr, IL_OFFSET codeSize, Fixed compInlineResult->Note(InlineObservation::CALLEE_LOOKS_LIKE_WRAPPER); } - if (!isJitIntrinsic && !handled && FgStack::IsArgument(pushedStack.Top())) + if (!isIntrinsic && !handled && FgStack::IsArgument(pushedStack.Top())) { // Optimistically assume that "call(arg)" returns something arg-dependent. // However, we don't know how many args it expects and its return type. diff --git a/src/coreclr/jit/flowgraph.cpp b/src/coreclr/jit/flowgraph.cpp index 859ea08aed822..63e2c53c97df5 100644 --- a/src/coreclr/jit/flowgraph.cpp +++ b/src/coreclr/jit/flowgraph.cpp @@ -920,7 +920,7 @@ GenTreeCall* Compiler::fgGetStaticsCCtorHelper(CORINFO_CLASS_HANDLE cls, CorInfo // If we're importing the special EqualityComparer.Default or Comparer.Default // intrinsics, flag the helper call. Later during inlining, we can // remove the helper call if the associated field lookup is unused. - if ((info.compFlags & CORINFO_FLG_JIT_INTRINSIC) != 0) + if ((info.compFlags & CORINFO_FLG_INTRINSIC) != 0) { NamedIntrinsic ni = lookupNamedIntrinsic(info.compMethodHnd); if ((ni == NI_System_Collections_Generic_EqualityComparer_get_Default) || diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index 7c0f79288f522..af0a2a1e47fe5 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -1468,7 +1468,7 @@ bool GenTree::Compare(GenTree* op1, GenTree* op2, bool swapOK) switch (oper) { case GT_INTRINSIC: - if (op1->AsIntrinsic()->gtIntrinsicId != op2->AsIntrinsic()->gtIntrinsicId) + if (op1->AsIntrinsic()->gtIntrinsicName != op2->AsIntrinsic()->gtIntrinsicName) { return false; } @@ -1924,7 +1924,7 @@ unsigned Compiler::gtHashValue(GenTree* tree) switch (oper) { case GT_INTRINSIC: - hash += tree->AsIntrinsic()->gtIntrinsicId; + hash += tree->AsIntrinsic()->gtIntrinsicName; break; case GT_LEA: hash += static_cast(tree->AsAddrMode()->Offset() << 3) + tree->AsAddrMode()->gtScale; @@ -3719,80 +3719,77 @@ unsigned Compiler::gtSetEvalOrder(GenTree* tree) case GT_INTRINSIC: intrinsic = tree->AsIntrinsic(); - if (intrinsic->gtIntrinsicId == CORINFO_INTRINSIC_Illegal) + // named intrinsic + assert(intrinsic->gtIntrinsicName != NI_Illegal); + + // GT_INTRINSIC intrinsics Sin, Cos, Sqrt, Abs ... have higher costs. + // TODO: tune these costs target specific as some of these are + // target intrinsics and would cost less to generate code. + switch (intrinsic->gtIntrinsicName) { - // named intrinsic - assert(intrinsic->gtIntrinsicName != NI_Illegal); + default: + assert(!"missing case for gtIntrinsicName"); + costEx = 12; + costSz = 12; + break; - // GT_INTRINSIC intrinsics Sin, Cos, Sqrt, Abs ... have higher costs. - // TODO: tune these costs target specific as some of these are - // target intrinsics and would cost less to generate code. - switch (intrinsic->gtIntrinsicName) - { - default: - assert(!"missing case for gtIntrinsicName"); - costEx = 12; - costSz = 12; - break; + case NI_System_Math_Abs: + costEx = 5; + costSz = 15; + break; - case NI_System_Math_Abs: - costEx = 5; - costSz = 15; - break; + case NI_System_Math_Acos: + case NI_System_Math_Acosh: + case NI_System_Math_Asin: + case NI_System_Math_Asinh: + case NI_System_Math_Atan: + case NI_System_Math_Atanh: + case NI_System_Math_Atan2: + case NI_System_Math_Cbrt: + case NI_System_Math_Ceiling: + case NI_System_Math_Cos: + case NI_System_Math_Cosh: + case NI_System_Math_Exp: + case NI_System_Math_Floor: + case NI_System_Math_FMod: + case NI_System_Math_FusedMultiplyAdd: + case NI_System_Math_ILogB: + case NI_System_Math_Log: + case NI_System_Math_Log2: + case NI_System_Math_Log10: + case NI_System_Math_Pow: + case NI_System_Math_Round: + case NI_System_Math_Sin: + case NI_System_Math_Sinh: + case NI_System_Math_Sqrt: + case NI_System_Math_Tan: + case NI_System_Math_Tanh: + { + // 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. We don't do this for target intrinsics + // however as they typically represent single instruction calls - case NI_System_Math_Acos: - case NI_System_Math_Acosh: - case NI_System_Math_Asin: - case NI_System_Math_Asinh: - case NI_System_Math_Atan: - case NI_System_Math_Atanh: - case NI_System_Math_Atan2: - case NI_System_Math_Cbrt: - case NI_System_Math_Ceiling: - case NI_System_Math_Cos: - case NI_System_Math_Cosh: - case NI_System_Math_Exp: - case NI_System_Math_Floor: - case NI_System_Math_FMod: - case NI_System_Math_FusedMultiplyAdd: - case NI_System_Math_ILogB: - case NI_System_Math_Log: - case NI_System_Math_Log2: - case NI_System_Math_Log10: - case NI_System_Math_Pow: - case NI_System_Math_Round: - case NI_System_Math_Sin: - case NI_System_Math_Sinh: - case NI_System_Math_Sqrt: - case NI_System_Math_Tan: - case NI_System_Math_Tanh: + if (IsIntrinsicImplementedByUserCall(intrinsic->gtIntrinsicName)) { - // 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. We don't do this for target intrinsics - // however as they typically represent single instruction calls - - if (IsIntrinsicImplementedByUserCall(intrinsic->gtIntrinsicName)) - { - costEx = 36; - costSz = 4; - } - else - { - costEx = 3; - costSz = 4; - } - 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 + { + costEx = 3; + costSz = 4; + } + 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; } level++; break; @@ -7494,8 +7491,7 @@ GenTree* Compiler::gtCloneExpr( case GT_INTRINSIC: copy = new (this, GT_INTRINSIC) GenTreeIntrinsic(tree->TypeGet(), tree->AsOp()->gtOp1, tree->AsOp()->gtOp2, - tree->AsIntrinsic()->gtIntrinsicId, tree->AsIntrinsic()->gtIntrinsicName, - tree->AsIntrinsic()->gtMethodHandle); + tree->AsIntrinsic()->gtIntrinsicName, tree->AsIntrinsic()->gtMethodHandle); #ifdef FEATURE_READYTORUN copy->AsIntrinsic()->gtEntryPoint = tree->AsIntrinsic()->gtEntryPoint; #endif @@ -10786,7 +10782,6 @@ void Compiler::gtDispTree(GenTree* tree, { GenTreeIntrinsic* intrinsic = tree->AsIntrinsic(); - assert(intrinsic->gtIntrinsicId == CORINFO_INTRINSIC_Illegal); switch (intrinsic->gtIntrinsicName) { case NI_System_Math_Abs: diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index 1cad150ac5e35..3fd3792eb8b1f 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -5007,7 +5007,6 @@ struct GenTreeQmark : public GenTreeOp struct GenTreeIntrinsic : public GenTreeOp { - CorInfoIntrinsics gtIntrinsicId; NamedIntrinsic gtIntrinsicName; CORINFO_METHOD_HANDLE gtMethodHandle; // Method handle of the method which is treated as an intrinsic. @@ -5016,31 +5015,17 @@ struct GenTreeIntrinsic : public GenTreeOp CORINFO_CONST_LOOKUP gtEntryPoint; #endif - GenTreeIntrinsic(var_types type, - GenTree* op1, - CorInfoIntrinsics intrinsicId, - NamedIntrinsic intrinsicName, - CORINFO_METHOD_HANDLE methodHandle) - : GenTreeOp(GT_INTRINSIC, type, op1, nullptr) - , gtIntrinsicId(intrinsicId) - , gtIntrinsicName(intrinsicName) - , gtMethodHandle(methodHandle) + GenTreeIntrinsic(var_types type, GenTree* op1, NamedIntrinsic intrinsicName, CORINFO_METHOD_HANDLE methodHandle) + : GenTreeOp(GT_INTRINSIC, type, op1, nullptr), gtIntrinsicName(intrinsicName), gtMethodHandle(methodHandle) { - assert(intrinsicId != CORINFO_INTRINSIC_Illegal || intrinsicName != NI_Illegal); + assert(intrinsicName != NI_Illegal); } - GenTreeIntrinsic(var_types type, - GenTree* op1, - GenTree* op2, - CorInfoIntrinsics intrinsicId, - NamedIntrinsic intrinsicName, - CORINFO_METHOD_HANDLE methodHandle) - : GenTreeOp(GT_INTRINSIC, type, op1, op2) - , gtIntrinsicId(intrinsicId) - , gtIntrinsicName(intrinsicName) - , gtMethodHandle(methodHandle) + GenTreeIntrinsic( + var_types type, GenTree* op1, GenTree* op2, NamedIntrinsic intrinsicName, CORINFO_METHOD_HANDLE methodHandle) + : GenTreeOp(GT_INTRINSIC, type, op1, op2), gtIntrinsicName(intrinsicName), gtMethodHandle(methodHandle) { - assert(intrinsicId != CORINFO_INTRINSIC_Illegal || intrinsicName != NI_Illegal); + assert(intrinsicName != NI_Illegal); } #if DEBUGGABLE_GENTREE diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index dc4f56eb4b469..bcbb62f29d0c9 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -3633,37 +3633,6 @@ GenTree* Compiler::impInitializeArrayIntrinsic(CORINFO_SIG_INFO* sig) true); // copyBlock } -#ifdef DEBUG - -//------------------------------------------------------------------------ -// impGetIntrinsicName: Get a string representing a CorInfoIntrinsics value, -// for use in debug output. -// -// Arguments: -// intrinsicID -- intrinsic ID for which to get the name -// -// Returns: -// string representing intrinsic -// -const char* Compiler::impGetIntrinsicName(CorInfoIntrinsics intrinsicID) -{ - static const char* const intrinsicNameMap[CORINFO_INTRINSIC_Count] = { - "CORINFO_INTRINSIC_Array_Get", "CORINFO_INTRINSIC_Array_Address", "CORINFO_INTRINSIC_Array_Set", - "CORINFO_INTRINSIC_ByReference_Ctor", "CORINFO_INTRINSIC_ByReference_Value", "CORINFO_INTRINSIC_GetRawHandle", - }; - - if ((0 <= intrinsicID) && (intrinsicID < CORINFO_INTRINSIC_Count)) - { - return intrinsicNameMap[intrinsicID]; - } - else - { - return "ILLEGAL"; - } -} - -#endif // DEBUG - GenTree* Compiler::impCreateSpanIntrinsic(CORINFO_SIG_INFO* sig) { assert(sig->numArgs == 1); @@ -3793,7 +3762,7 @@ GenTree* Compiler::impCreateSpanIntrinsic(CORINFO_SIG_INFO* sig) // pConstrainedResolvedToken -- resolved token for constrained call, or nullptr // if call is not constrained // constraintCallThisTransform -- this transform to apply for a constrained call -// pIntrinsicID [OUT] -- intrinsic ID (see enumeration in corinfo.h) +// pIntrinsicName [OUT] -- intrinsic name (see enumeration in namedintrinsiclist.h) // for "traditional" jit intrinsics // isSpecialIntrinsic [OUT] -- set true if intrinsic expansion is a call // that is amenable to special downstream optimization opportunities @@ -3802,7 +3771,7 @@ GenTree* Compiler::impCreateSpanIntrinsic(CORINFO_SIG_INFO* sig) // IR tree to use in place of the call, or nullptr if the jit should treat // the intrinsic call like a normal call. // -// pIntrinsicID set to non-illegal value if the call is recognized as a +// pIntrinsicName set to non-illegal value if the call is recognized as a // traditional jit intrinsic, even if the intrinsic is not expaned. // // isSpecial set true if the expansion is subject to special @@ -3834,84 +3803,66 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, bool tailCall, CORINFO_RESOLVED_TOKEN* pConstrainedResolvedToken, CORINFO_THIS_TRANSFORM constraintCallThisTransform, - CorInfoIntrinsics* pIntrinsicID, NamedIntrinsic* pIntrinsicName, bool* isSpecialIntrinsic) { - assert((methodFlags & (CORINFO_FLG_INTRINSIC | CORINFO_FLG_JIT_INTRINSIC)) != 0); + assert((methodFlags & CORINFO_FLG_INTRINSIC) != 0); - bool mustExpand = false; - bool isSpecial = false; - CorInfoIntrinsics intrinsicID = CORINFO_INTRINSIC_Illegal; - NamedIntrinsic ni = NI_Illegal; + bool mustExpand = false; + bool isSpecial = false; + NamedIntrinsic ni = NI_Illegal; if ((methodFlags & CORINFO_FLG_INTRINSIC) != 0) - { - intrinsicID = info.compCompHnd->getIntrinsicID(method, &mustExpand); - -#ifdef DEBUG - if (intrinsicID != CORINFO_INTRINSIC_Illegal) - { - JITDUMP("Intrinsic %s Recognized\n", impGetIntrinsicName(intrinsicID)); - } -#endif // DEBUG - } - - if ((methodFlags & CORINFO_FLG_JIT_INTRINSIC) != 0) { // The recursive non-virtual calls to Jit intrinsics are must-expand by convention. mustExpand = mustExpand || (gtIsRecursiveCall(method) && !(methodFlags & CORINFO_FLG_VIRTUAL)); - if (intrinsicID == CORINFO_INTRINSIC_Illegal) - { - ni = lookupNamedIntrinsic(method); + ni = lookupNamedIntrinsic(method); - // We specially support the following on all platforms to allow for dead - // code optimization and to more generally support recursive intrinsics. + // We specially support the following on all platforms to allow for dead + // code optimization and to more generally support recursive intrinsics. - if (ni == NI_IsSupported_True) - { - assert(sig->numArgs == 0); - return gtNewIconNode(true); - } + if (ni == NI_IsSupported_True) + { + assert(sig->numArgs == 0); + return gtNewIconNode(true); + } - if (ni == NI_IsSupported_False) - { - assert(sig->numArgs == 0); - return gtNewIconNode(false); - } + if (ni == NI_IsSupported_False) + { + assert(sig->numArgs == 0); + return gtNewIconNode(false); + } - if (ni == NI_Throw_PlatformNotSupportedException) - { - return impUnsupportedNamedIntrinsic(CORINFO_HELP_THROW_PLATFORM_NOT_SUPPORTED, method, sig, mustExpand); - } + if (ni == NI_Throw_PlatformNotSupportedException) + { + return impUnsupportedNamedIntrinsic(CORINFO_HELP_THROW_PLATFORM_NOT_SUPPORTED, method, sig, mustExpand); + } #ifdef FEATURE_HW_INTRINSICS - if ((ni > NI_HW_INTRINSIC_START) && (ni < NI_HW_INTRINSIC_END)) - { - GenTree* hwintrinsic = impHWIntrinsic(ni, clsHnd, method, sig, mustExpand); - - if (mustExpand && (hwintrinsic == nullptr)) - { - return impUnsupportedNamedIntrinsic(CORINFO_HELP_THROW_NOT_IMPLEMENTED, method, sig, mustExpand); - } + if ((ni > NI_HW_INTRINSIC_START) && (ni < NI_HW_INTRINSIC_END)) + { + GenTree* hwintrinsic = impHWIntrinsic(ni, clsHnd, method, sig, mustExpand); - return hwintrinsic; + if (mustExpand && (hwintrinsic == nullptr)) + { + return impUnsupportedNamedIntrinsic(CORINFO_HELP_THROW_NOT_IMPLEMENTED, method, sig, mustExpand); } - if ((ni > NI_SIMD_AS_HWINTRINSIC_START) && (ni < NI_SIMD_AS_HWINTRINSIC_END)) - { - // These intrinsics aren't defined recursively and so they will never be mustExpand - // Instead, they provide software fallbacks that will be executed instead. + return hwintrinsic; + } - assert(!mustExpand); - return impSimdAsHWIntrinsic(ni, clsHnd, method, sig, newobjThis); - } -#endif // FEATURE_HW_INTRINSICS + if ((ni > NI_SIMD_AS_HWINTRINSIC_START) && (ni < NI_SIMD_AS_HWINTRINSIC_END)) + { + // These intrinsics aren't defined recursively and so they will never be mustExpand + // Instead, they provide software fallbacks that will be executed instead. + + assert(!mustExpand); + return impSimdAsHWIntrinsic(ni, clsHnd, method, sig, newobjThis); } +#endif // FEATURE_HW_INTRINSICS } - *pIntrinsicID = intrinsicID; *pIntrinsicName = ni; if (ni == NI_System_StubHelpers_GetStubContext) @@ -3938,6 +3889,13 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, mustExpand = true; } + if ((ni == NI_System_ByReference_ctor) || (ni == NI_System_ByReference_get_Value) || + (ni == NI_System_Activator_AllocatorOf) || (ni == NI_System_Activator_DefaultConstructorOf) || + (ni == NI_System_Object_MethodTableOf) || (ni == NI_System_EETypePtr_EETypePtrOf)) + { + mustExpand = true; + } + GenTree* retNode = nullptr; // Under debug and minopts, only expand what is required. @@ -3947,7 +3905,7 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, // the NextCallReturnAddress intrinsic. if (!mustExpand && (opts.OptimizationDisabled() || info.compHasNextCallRetAddr)) { - *pIntrinsicID = CORINFO_INTRINSIC_Illegal; + *pIntrinsicName = NI_Illegal; return retNode; } @@ -3956,88 +3914,17 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, /* First do the intrinsics which are always smaller than a call */ - switch (intrinsicID) - { - GenTree* op1; - - case CORINFO_INTRINSIC_Array_Address: - case CORINFO_INTRINSIC_Array_Get: - case CORINFO_INTRINSIC_Array_Set: - retNode = impArrayAccessIntrinsic(clsHnd, sig, memberRef, readonlyCall, intrinsicID); - break; - - // Implement ByReference Ctor. This wraps the assignment of the ref into a byref-like field - // in a value type. The canonical example of this is Span. In effect this is just a - // substitution. The parameter byref will be assigned into the newly allocated object. - case CORINFO_INTRINSIC_ByReference_Ctor: - { - // Remove call to constructor and directly assign the byref passed - // to the call to the first slot of the ByReference struct. - op1 = impPopStack().val; - GenTree* thisptr = newobjThis; - CORINFO_FIELD_HANDLE fldHnd = info.compCompHnd->getFieldInClass(clsHnd, 0); - GenTree* field = gtNewFieldRef(TYP_BYREF, fldHnd, thisptr, 0); - GenTree* assign = gtNewAssignNode(field, op1); - GenTree* byReferenceStruct = gtCloneExpr(thisptr->gtGetOp1()); - assert(byReferenceStruct != nullptr); - impPushOnStack(byReferenceStruct, typeInfo(TI_STRUCT, clsHnd)); - retNode = assign; - break; - } - // Implement ptr value getter for ByReference struct. - case CORINFO_INTRINSIC_ByReference_Value: - { - op1 = impPopStack().val; - CORINFO_FIELD_HANDLE fldHnd = info.compCompHnd->getFieldInClass(clsHnd, 0); - GenTree* field = gtNewFieldRef(TYP_BYREF, fldHnd, op1, 0); - retNode = field; - break; - } - - case CORINFO_INTRINSIC_GetRawHandle: - { - noway_assert(IsTargetAbi(CORINFO_CORERT_ABI)); // Only CoreRT supports it. - CORINFO_RESOLVED_TOKEN resolvedToken; - resolvedToken.tokenContext = impTokenLookupContextHandle; - resolvedToken.tokenScope = info.compScopeHnd; - resolvedToken.token = memberRef; - resolvedToken.tokenType = CORINFO_TOKENKIND_Method; - - CORINFO_GENERICHANDLE_RESULT embedInfo; - info.compCompHnd->expandRawHandleIntrinsic(&resolvedToken, &embedInfo); - - GenTree* rawHandle = impLookupToTree(&resolvedToken, &embedInfo.lookup, gtTokenToIconFlags(memberRef), - embedInfo.compileTimeHandle); - if (rawHandle == nullptr) - { - return nullptr; - } - - noway_assert(genTypeSize(rawHandle->TypeGet()) == genTypeSize(TYP_I_IMPL)); - - unsigned rawHandleSlot = lvaGrabTemp(true DEBUGARG("rawHandle")); - impAssignTempGen(rawHandleSlot, rawHandle, clsHnd, (unsigned)CHECK_SPILL_NONE); - - GenTree* lclVar = gtNewLclvNode(rawHandleSlot, TYP_I_IMPL); - GenTree* lclVarAddr = gtNewOperNode(GT_ADDR, TYP_I_IMPL, lclVar); - var_types resultType = JITtype2varType(sig->retType); - retNode = gtNewOperNode(GT_IND, resultType, lclVarAddr); - - break; - } - - default: - /* Unknown intrinsic */ - intrinsicID = CORINFO_INTRINSIC_Illegal; - break; - } - - // Look for new-style jit intrinsics by name if (ni != NI_Illegal) { assert(retNode == nullptr); switch (ni) { + case NI_Array_Address: + case NI_Array_Get: + case NI_Array_Set: + retNode = impArrayAccessIntrinsic(clsHnd, sig, memberRef, readonlyCall, ni); + break; + case NI_System_String_get_Chars: { GenTree* op2 = impPopStack().val; @@ -4081,6 +3968,35 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, break; } + // Implement ByReference Ctor. This wraps the assignment of the ref into a byref-like field + // in a value type. The canonical example of this is Span. In effect this is just a + // substitution. The parameter byref will be assigned into the newly allocated object. + case NI_System_ByReference_ctor: + { + // Remove call to constructor and directly assign the byref passed + // to the call to the first slot of the ByReference struct. + GenTree* op1 = impPopStack().val; + GenTree* thisptr = newobjThis; + CORINFO_FIELD_HANDLE fldHnd = info.compCompHnd->getFieldInClass(clsHnd, 0); + GenTree* field = gtNewFieldRef(TYP_BYREF, fldHnd, thisptr, 0); + GenTree* assign = gtNewAssignNode(field, op1); + GenTree* byReferenceStruct = gtCloneExpr(thisptr->gtGetOp1()); + assert(byReferenceStruct != nullptr); + impPushOnStack(byReferenceStruct, typeInfo(TI_STRUCT, clsHnd)); + retNode = assign; + break; + } + + // Implement ptr value getter for ByReference struct. + case NI_System_ByReference_get_Value: + { + GenTree* op1 = impPopStack().val; + CORINFO_FIELD_HANDLE fldHnd = info.compCompHnd->getFieldInClass(clsHnd, 0); + GenTree* field = gtNewFieldRef(TYP_BYREF, fldHnd, op1, 0); + retNode = field; + break; + } + case NI_System_Runtime_CompilerServices_RuntimeHelpers_CreateSpan: { retNode = impCreateSpanIntrinsic(sig); @@ -4093,6 +4009,41 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, break; } + case NI_System_Activator_AllocatorOf: + case NI_System_Activator_DefaultConstructorOf: + case NI_System_Object_MethodTableOf: + case NI_System_EETypePtr_EETypePtrOf: + { + assert(IsTargetAbi(CORINFO_CORERT_ABI)); // Only CoreRT supports it. + CORINFO_RESOLVED_TOKEN resolvedToken; + resolvedToken.tokenContext = impTokenLookupContextHandle; + resolvedToken.tokenScope = info.compScopeHnd; + resolvedToken.token = memberRef; + resolvedToken.tokenType = CORINFO_TOKENKIND_Method; + + CORINFO_GENERICHANDLE_RESULT embedInfo; + info.compCompHnd->expandRawHandleIntrinsic(&resolvedToken, &embedInfo); + + GenTree* rawHandle = impLookupToTree(&resolvedToken, &embedInfo.lookup, gtTokenToIconFlags(memberRef), + embedInfo.compileTimeHandle); + if (rawHandle == nullptr) + { + return nullptr; + } + + noway_assert(genTypeSize(rawHandle->TypeGet()) == genTypeSize(TYP_I_IMPL)); + + unsigned rawHandleSlot = lvaGrabTemp(true DEBUGARG("rawHandle")); + impAssignTempGen(rawHandleSlot, rawHandle, clsHnd, (unsigned)CHECK_SPILL_NONE); + + GenTree* lclVar = gtNewLclvNode(rawHandleSlot, TYP_I_IMPL); + GenTree* lclVarAddr = gtNewOperNode(GT_ADDR, TYP_I_IMPL, lclVar); + var_types resultType = JITtype2varType(sig->retType); + retNode = gtNewOperNode(GT_IND, resultType, lclVarAddr); + + break; + } + case NI_System_Span_get_Item: case NI_System_ReadOnlySpan_get_Item: { @@ -4643,8 +4594,7 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, { JITDUMP("Expanding as special intrinsic\n"); impPopStack(); - op1 = new (this, GT_INTRINSIC) - GenTreeIntrinsic(genActualType(callType), op1, intrinsicID, ni, method); + op1 = new (this, GT_INTRINSIC) GenTreeIntrinsic(genActualType(callType), op1, ni, method); // Set the CALL flag to indicate that the operator is implemented by a call. // Set also the EXCEPTION flag because the native implementation of @@ -4952,8 +4902,7 @@ GenTree* Compiler::impMathIntrinsic(CORINFO_METHOD_HANDLE method, op1 = gtNewCastNode(callType, op1, false, callType); } - op1 = new (this, GT_INTRINSIC) - GenTreeIntrinsic(genActualType(callType), op1, CORINFO_INTRINSIC_Illegal, intrinsicName, method); + op1 = new (this, GT_INTRINSIC) GenTreeIntrinsic(genActualType(callType), op1, intrinsicName, method); break; case 2: @@ -4978,8 +4927,8 @@ GenTree* Compiler::impMathIntrinsic(CORINFO_METHOD_HANDLE method, op2 = gtNewCastNode(callType, op2, false, callType); } - op1 = new (this, GT_INTRINSIC) GenTreeIntrinsic(genActualType(callType), op1, op2, - CORINFO_INTRINSIC_Illegal, intrinsicName, method); + op1 = + new (this, GT_INTRINSIC) GenTreeIntrinsic(genActualType(callType), op1, op2, intrinsicName, method); break; default: @@ -5005,7 +4954,7 @@ GenTree* Compiler::impMathIntrinsic(CORINFO_METHOD_HANDLE method, // Id for the named intrinsic, or Illegal if none. // // Notes: -// method should have CORINFO_FLG_JIT_INTRINSIC set in its attributes, +// method should have CORINFO_FLG_INTRINSIC set in its attributes, // otherwise it is not a named jit intrinsic. // NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method) @@ -5034,14 +4983,32 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method) { JITDUMP("%s", methodName); } - JITDUMP(": "); if ((namespaceName == nullptr) || (className == nullptr) || (methodName == nullptr)) { - JITDUMP("Not recognized, not enough metadata\n"); + // Check if we are dealing with an MD array's known runtime method + CorInfoArrayIntrinsic arrayFuncIndex = info.compCompHnd->getArrayIntrinsicID(method); + switch (arrayFuncIndex) + { + case CorInfoArrayIntrinsic::GET: + JITDUMP("ARRAY_FUNC_GET: Recognized\n"); + return NI_Array_Get; + case CorInfoArrayIntrinsic::SET: + JITDUMP("ARRAY_FUNC_SET: Recognized\n"); + return NI_Array_Set; + case CorInfoArrayIntrinsic::ADDRESS: + JITDUMP("ARRAY_FUNC_ADDRESS: Recognized\n"); + return NI_Array_Address; + default: + break; + } + + JITDUMP(": Not recognized, not enough metadata\n"); return NI_Illegal; } + JITDUMP(": "); + NamedIntrinsic result = NI_Illegal; if (strcmp(namespaceName, "System") == 0) @@ -5050,6 +5017,28 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method) { result = NI_System_Enum_HasFlag; } + else if (strcmp(className, "Activator") == 0) + { + if (strcmp(methodName, "AllocatorOf") == 0) + { + result = NI_System_Activator_AllocatorOf; + } + else if (strcmp(methodName, "DefaultConstructorOf") == 0) + { + result = NI_System_Activator_DefaultConstructorOf; + } + } + else if (strcmp(className, "ByReference`1") == 0) + { + if (strcmp(methodName, ".ctor") == 0) + { + result = NI_System_ByReference_ctor; + } + else if (strcmp(methodName, "get_Value") == 0) + { + result = NI_System_ByReference_get_Value; + } + } else if (strcmp(className, "Math") == 0 || strcmp(className, "MathF") == 0) { if (strcmp(methodName, "Abs") == 0) @@ -5197,6 +5186,10 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method) { result = NI_System_Object_GetType; } + else if (strcmp(methodName, "MethodTableOf") == 0) + { + result = NI_System_Object_MethodTableOf; + } } else if (strcmp(className, "RuntimeTypeHandle") == 0) { @@ -5257,6 +5250,13 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method) result = NI_System_ReadOnlySpan_get_Item; } } + else if (strcmp(className, "EETypePtr") == 0) + { + if (strcmp(methodName, "EETypePtrOf") == 0) + { + result = NI_System_EETypePtr_EETypePtrOf; + } + } } else if (strcmp(namespaceName, "System.Threading") == 0) { @@ -5499,7 +5499,7 @@ GenTree* Compiler::impUnsupportedNamedIntrinsic(unsigned helper, /*****************************************************************************/ GenTree* Compiler::impArrayAccessIntrinsic( - CORINFO_CLASS_HANDLE clsHnd, CORINFO_SIG_INFO* sig, int memberRef, bool readonlyCall, CorInfoIntrinsics intrinsicID) + CORINFO_CLASS_HANDLE clsHnd, CORINFO_SIG_INFO* sig, int memberRef, bool readonlyCall, NamedIntrinsic intrinsicName) { /* If we are generating SMALL_CODE, we don't want to use intrinsics for the following, as it generates fatter code. @@ -5513,7 +5513,7 @@ GenTree* Compiler::impArrayAccessIntrinsic( /* These intrinsics generate fatter (but faster) code and are only done if we don't need SMALL_CODE */ - unsigned rank = (intrinsicID == CORINFO_INTRINSIC_Array_Set) ? (sig->numArgs - 1) : sig->numArgs; + unsigned rank = (intrinsicName == NI_Array_Set) ? (sig->numArgs - 1) : sig->numArgs; // The rank 1 case is special because it has to handle two array formats // we will simply not do that case @@ -5528,7 +5528,7 @@ GenTree* Compiler::impArrayAccessIntrinsic( // For the ref case, we will only be able to inline if the types match // (verifier checks for this, we don't care for the nonverified case and the // type is final (so we don't need to do the cast) - if ((intrinsicID != CORINFO_INTRINSIC_Array_Get) && !readonlyCall && varTypeIsGC(elemType)) + if ((intrinsicName != NI_Array_Get) && !readonlyCall && varTypeIsGC(elemType)) { // Get the call site signature CORINFO_SIG_INFO LocalSig; @@ -5537,7 +5537,7 @@ GenTree* Compiler::impArrayAccessIntrinsic( CORINFO_CLASS_HANDLE actualElemClsHnd; - if (intrinsicID == CORINFO_INTRINSIC_Array_Set) + if (intrinsicName == NI_Array_Set) { // Fetch the last argument, the one that indicates the type we are setting. CORINFO_ARG_LIST_HANDLE argType = LocalSig.args; @@ -5551,7 +5551,7 @@ GenTree* Compiler::impArrayAccessIntrinsic( } else { - assert(intrinsicID == CORINFO_INTRINSIC_Array_Address); + assert(intrinsicName == NI_Array_Address); // Fetch the return type typeInfo retInfo = verMakeTypeInfo(LocalSig.retType, LocalSig.retTypeClass); @@ -5587,7 +5587,7 @@ GenTree* Compiler::impArrayAccessIntrinsic( GenTree* val = nullptr; - if (intrinsicID == CORINFO_INTRINSIC_Array_Set) + if (intrinsicName == NI_Array_Set) { // Assignment of a struct is more work, and there are more gets than sets. if (elemType == TYP_STRUCT) @@ -5617,7 +5617,7 @@ GenTree* Compiler::impArrayAccessIntrinsic( new (this, GT_ARR_ELEM) GenTreeArrElem(TYP_BYREF, arr, static_cast(rank), static_cast(arrayElemSize), elemType, &inds[0]); - if (intrinsicID != CORINFO_INTRINSIC_Array_Address) + if (intrinsicName != NI_Array_Address) { if (varTypeIsStruct(elemType)) { @@ -5629,7 +5629,7 @@ GenTree* Compiler::impArrayAccessIntrinsic( } } - if (intrinsicID == CORINFO_INTRINSIC_Array_Set) + if (intrinsicName == NI_Array_Set) { assert(val != nullptr); return gtNewAssignNode(arrElem, val); @@ -8781,8 +8781,7 @@ var_types Compiler::impImportCall(OPCODE opcode, } else // (opcode != CEE_CALLI) { - CorInfoIntrinsics intrinsicID = CORINFO_INTRINSIC_Count; - NamedIntrinsic ni = NI_Illegal; + NamedIntrinsic ni = NI_Illegal; // Passing CORINFO_CALLINFO_ALLOWINSTPARAM indicates that this JIT is prepared to // supply the instantiation parameters necessary to make direct calls to underlying @@ -8865,13 +8864,13 @@ var_types Compiler::impImportCall(OPCODE opcode, // Factor this into getCallInfo bool isSpecialIntrinsic = false; - if ((mflags & (CORINFO_FLG_INTRINSIC | CORINFO_FLG_JIT_INTRINSIC)) != 0) + if ((mflags & (CORINFO_FLG_INTRINSIC | CORINFO_FLG_INTRINSIC)) != 0) { const bool isTailCall = canTailCall && (tailCallFlags != 0); - call = impIntrinsic(newobjThis, clsHnd, methHnd, sig, mflags, pResolvedToken->token, isReadonlyCall, - isTailCall, pConstrainedResolvedToken, callInfo->thisTransform, &intrinsicID, &ni, - &isSpecialIntrinsic); + call = + impIntrinsic(newobjThis, clsHnd, methHnd, sig, mflags, pResolvedToken->token, isReadonlyCall, + isTailCall, pConstrainedResolvedToken, callInfo->thisTransform, &ni, &isSpecialIntrinsic); if (compDonotInline()) { diff --git a/src/coreclr/jit/namedintrinsiclist.h b/src/coreclr/jit/namedintrinsiclist.h index 5d07e88b576ae..25733a41a9c9e 100644 --- a/src/coreclr/jit/namedintrinsiclist.h +++ b/src/coreclr/jit/namedintrinsiclist.h @@ -65,6 +65,17 @@ enum NamedIntrinsic : unsigned short NI_System_StubHelpers_GetStubContext, NI_System_StubHelpers_NextCallReturnAddress, + NI_Array_Address, + NI_Array_Get, + NI_Array_Set, + + NI_System_ByReference_ctor, + NI_System_ByReference_get_Value, + NI_System_Activator_AllocatorOf, + NI_System_Activator_DefaultConstructorOf, + NI_System_Object_MethodTableOf, + NI_System_EETypePtr_EETypePtrOf, + NI_System_Runtime_CompilerServices_RuntimeHelpers_CreateSpan, NI_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray, diff --git a/src/coreclr/jit/simd.cpp b/src/coreclr/jit/simd.cpp index cfcc8f0285624..dd81504a7c948 100644 --- a/src/coreclr/jit/simd.cpp +++ b/src/coreclr/jit/simd.cpp @@ -1904,7 +1904,7 @@ GenTree* Compiler::impSIMDIntrinsic(OPCODE opcode, } // Exit early if the method is not a JIT Intrinsic (which requires the [Intrinsic] attribute). - if ((methodFlags & CORINFO_FLG_JIT_INTRINSIC) == 0) + if ((methodFlags & CORINFO_FLG_INTRINSIC) == 0) { return nullptr; } diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoBase.cs b/src/coreclr/tools/Common/JitInterface/CorInfoBase.cs index 9ef70518bd0c3..f660b55ebe192 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoBase.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoBase.cs @@ -13,12 +13,12 @@ namespace Internal.JitInterface unsafe partial class CorInfoImpl { [UnmanagedCallersOnly] - static byte _isJitIntrinsic(IntPtr thisHandle, IntPtr* ppException, CORINFO_METHOD_STRUCT_* ftn) + static byte _isIntrinsic(IntPtr thisHandle, IntPtr* ppException, CORINFO_METHOD_STRUCT_* ftn) { var _this = GetThis(thisHandle); try { - return _this.isJitIntrinsic(ftn) ? (byte)1 : (byte)0; + return _this.isIntrinsic(ftn) ? (byte)1 : (byte)0; } catch (Exception ex) { @@ -275,21 +275,6 @@ static void _expandRawHandleIntrinsic(IntPtr thisHandle, IntPtr* ppException, CO } } - [UnmanagedCallersOnly] - static CorInfoIntrinsics _getIntrinsicID(IntPtr thisHandle, IntPtr* ppException, CORINFO_METHOD_STRUCT_* method, byte* pMustExpand) - { - var _this = GetThis(thisHandle); - try - { - return _this.getIntrinsicID(method, pMustExpand); - } - catch (Exception ex) - { - *ppException = _this.AllocException(ex); - return default; - } - } - [UnmanagedCallersOnly] static byte _isIntrinsicType(IntPtr thisHandle, IntPtr* ppException, CORINFO_CLASS_STRUCT_* classHnd) { @@ -1271,6 +1256,21 @@ static uint _getArrayRank(IntPtr thisHandle, IntPtr* ppException, CORINFO_CLASS_ } } + [UnmanagedCallersOnly] + static CorInfoArrayIntrinsic _getArrayIntrinsicID(IntPtr thisHandle, IntPtr* ppException, CORINFO_METHOD_STRUCT_* ftn) + { + var _this = GetThis(thisHandle); + try + { + return _this.getArrayIntrinsicID(ftn); + } + catch (Exception ex) + { + *ppException = _this.AllocException(ex); + return default; + } + } + [UnmanagedCallersOnly] static void* _getArrayInitializationData(IntPtr thisHandle, IntPtr* ppException, CORINFO_FIELD_STRUCT_* field, uint size) { @@ -2568,7 +2568,7 @@ static IntPtr GetUnmanagedCallbacks() { void** callbacks = (void**)Marshal.AllocCoTaskMem(sizeof(IntPtr) * 173); - callbacks[0] = (delegate* unmanaged)&_isJitIntrinsic; + callbacks[0] = (delegate* unmanaged)&_isIntrinsic; callbacks[1] = (delegate* unmanaged)&_getMethodAttribs; callbacks[2] = (delegate* unmanaged)&_setMethodAttribs; callbacks[3] = (delegate* unmanaged)&_getMethodSig; @@ -2586,73 +2586,73 @@ static IntPtr GetUnmanagedCallbacks() callbacks[15] = (delegate* unmanaged)&_getDefaultComparerClass; callbacks[16] = (delegate* unmanaged)&_getDefaultEqualityComparerClass; callbacks[17] = (delegate* unmanaged)&_expandRawHandleIntrinsic; - callbacks[18] = (delegate* unmanaged)&_getIntrinsicID; - callbacks[19] = (delegate* unmanaged)&_isIntrinsicType; - callbacks[20] = (delegate* unmanaged)&_getUnmanagedCallConv; - callbacks[21] = (delegate* unmanaged)&_pInvokeMarshalingRequired; - callbacks[22] = (delegate* unmanaged)&_satisfiesMethodConstraints; - callbacks[23] = (delegate* unmanaged)&_isCompatibleDelegate; - callbacks[24] = (delegate* unmanaged)&_methodMustBeLoadedBeforeCodeIsRun; - callbacks[25] = (delegate* unmanaged)&_mapMethodDeclToMethodImpl; - callbacks[26] = (delegate* unmanaged)&_getGSCookie; - callbacks[27] = (delegate* unmanaged)&_setPatchpointInfo; - callbacks[28] = (delegate* unmanaged)&_getOSRInfo; - callbacks[29] = (delegate* unmanaged)&_resolveToken; - callbacks[30] = (delegate* unmanaged)&_tryResolveToken; - callbacks[31] = (delegate* unmanaged)&_findSig; - callbacks[32] = (delegate* unmanaged)&_findCallSiteSig; - callbacks[33] = (delegate* unmanaged)&_getTokenTypeAsHandle; - callbacks[34] = (delegate* unmanaged)&_isValidToken; - callbacks[35] = (delegate* unmanaged)&_isValidStringRef; - callbacks[36] = (delegate* unmanaged)&_getStringLiteral; - callbacks[37] = (delegate* unmanaged)&_asCorInfoType; - callbacks[38] = (delegate* unmanaged)&_getClassName; - callbacks[39] = (delegate* unmanaged)&_getClassNameFromMetadata; - callbacks[40] = (delegate* unmanaged)&_getTypeInstantiationArgument; - callbacks[41] = (delegate* unmanaged)&_appendClassName; - callbacks[42] = (delegate* unmanaged)&_isValueClass; - callbacks[43] = (delegate* unmanaged)&_canInlineTypeCheck; - callbacks[44] = (delegate* unmanaged)&_getClassAttribs; - callbacks[45] = (delegate* unmanaged)&_getClassModule; - callbacks[46] = (delegate* unmanaged)&_getModuleAssembly; - callbacks[47] = (delegate* unmanaged)&_getAssemblyName; - callbacks[48] = (delegate* unmanaged)&_LongLifetimeMalloc; - callbacks[49] = (delegate* unmanaged)&_LongLifetimeFree; - callbacks[50] = (delegate* unmanaged)&_getClassModuleIdForStatics; - callbacks[51] = (delegate* unmanaged)&_getClassSize; - callbacks[52] = (delegate* unmanaged)&_getHeapClassSize; - callbacks[53] = (delegate* unmanaged)&_canAllocateOnStack; - callbacks[54] = (delegate* unmanaged)&_getClassAlignmentRequirement; - callbacks[55] = (delegate* unmanaged)&_getClassGClayout; - callbacks[56] = (delegate* unmanaged)&_getClassNumInstanceFields; - callbacks[57] = (delegate* unmanaged)&_getFieldInClass; - callbacks[58] = (delegate* unmanaged)&_checkMethodModifier; - callbacks[59] = (delegate* unmanaged)&_getNewHelper; - callbacks[60] = (delegate* unmanaged)&_getNewArrHelper; - callbacks[61] = (delegate* unmanaged)&_getCastingHelper; - callbacks[62] = (delegate* unmanaged)&_getSharedCCtorHelper; - callbacks[63] = (delegate* unmanaged)&_getTypeForBox; - callbacks[64] = (delegate* unmanaged)&_getBoxHelper; - callbacks[65] = (delegate* unmanaged)&_getUnBoxHelper; - callbacks[66] = (delegate* unmanaged)&_getReadyToRunHelper; - callbacks[67] = (delegate* unmanaged)&_getReadyToRunDelegateCtorHelper; - callbacks[68] = (delegate* unmanaged)&_getHelperName; - callbacks[69] = (delegate* unmanaged)&_initClass; - callbacks[70] = (delegate* unmanaged)&_classMustBeLoadedBeforeCodeIsRun; - callbacks[71] = (delegate* unmanaged)&_getBuiltinClass; - callbacks[72] = (delegate* unmanaged)&_getTypeForPrimitiveValueClass; - callbacks[73] = (delegate* unmanaged)&_getTypeForPrimitiveNumericClass; - callbacks[74] = (delegate* unmanaged)&_canCast; - callbacks[75] = (delegate* unmanaged)&_areTypesEquivalent; - callbacks[76] = (delegate* unmanaged)&_compareTypesForCast; - callbacks[77] = (delegate* unmanaged)&_compareTypesForEquality; - callbacks[78] = (delegate* unmanaged)&_mergeClasses; - callbacks[79] = (delegate* unmanaged)&_isMoreSpecificType; - callbacks[80] = (delegate* unmanaged)&_getParentType; - callbacks[81] = (delegate* unmanaged)&_getChildType; - callbacks[82] = (delegate* unmanaged)&_satisfiesClassConstraints; - callbacks[83] = (delegate* unmanaged)&_isSDArray; - callbacks[84] = (delegate* unmanaged)&_getArrayRank; + callbacks[18] = (delegate* unmanaged)&_isIntrinsicType; + callbacks[19] = (delegate* unmanaged)&_getUnmanagedCallConv; + callbacks[20] = (delegate* unmanaged)&_pInvokeMarshalingRequired; + callbacks[21] = (delegate* unmanaged)&_satisfiesMethodConstraints; + callbacks[22] = (delegate* unmanaged)&_isCompatibleDelegate; + callbacks[23] = (delegate* unmanaged)&_methodMustBeLoadedBeforeCodeIsRun; + callbacks[24] = (delegate* unmanaged)&_mapMethodDeclToMethodImpl; + callbacks[25] = (delegate* unmanaged)&_getGSCookie; + callbacks[26] = (delegate* unmanaged)&_setPatchpointInfo; + callbacks[27] = (delegate* unmanaged)&_getOSRInfo; + callbacks[28] = (delegate* unmanaged)&_resolveToken; + callbacks[29] = (delegate* unmanaged)&_tryResolveToken; + callbacks[30] = (delegate* unmanaged)&_findSig; + callbacks[31] = (delegate* unmanaged)&_findCallSiteSig; + callbacks[32] = (delegate* unmanaged)&_getTokenTypeAsHandle; + callbacks[33] = (delegate* unmanaged)&_isValidToken; + callbacks[34] = (delegate* unmanaged)&_isValidStringRef; + callbacks[35] = (delegate* unmanaged)&_getStringLiteral; + callbacks[36] = (delegate* unmanaged)&_asCorInfoType; + callbacks[37] = (delegate* unmanaged)&_getClassName; + callbacks[38] = (delegate* unmanaged)&_getClassNameFromMetadata; + callbacks[39] = (delegate* unmanaged)&_getTypeInstantiationArgument; + callbacks[40] = (delegate* unmanaged)&_appendClassName; + callbacks[41] = (delegate* unmanaged)&_isValueClass; + callbacks[42] = (delegate* unmanaged)&_canInlineTypeCheck; + callbacks[43] = (delegate* unmanaged)&_getClassAttribs; + callbacks[44] = (delegate* unmanaged)&_getClassModule; + callbacks[45] = (delegate* unmanaged)&_getModuleAssembly; + callbacks[46] = (delegate* unmanaged)&_getAssemblyName; + callbacks[47] = (delegate* unmanaged)&_LongLifetimeMalloc; + callbacks[48] = (delegate* unmanaged)&_LongLifetimeFree; + callbacks[49] = (delegate* unmanaged)&_getClassModuleIdForStatics; + callbacks[50] = (delegate* unmanaged)&_getClassSize; + callbacks[51] = (delegate* unmanaged)&_getHeapClassSize; + callbacks[52] = (delegate* unmanaged)&_canAllocateOnStack; + callbacks[53] = (delegate* unmanaged)&_getClassAlignmentRequirement; + callbacks[54] = (delegate* unmanaged)&_getClassGClayout; + callbacks[55] = (delegate* unmanaged)&_getClassNumInstanceFields; + callbacks[56] = (delegate* unmanaged)&_getFieldInClass; + callbacks[57] = (delegate* unmanaged)&_checkMethodModifier; + callbacks[58] = (delegate* unmanaged)&_getNewHelper; + callbacks[59] = (delegate* unmanaged)&_getNewArrHelper; + callbacks[60] = (delegate* unmanaged)&_getCastingHelper; + callbacks[61] = (delegate* unmanaged)&_getSharedCCtorHelper; + callbacks[62] = (delegate* unmanaged)&_getTypeForBox; + callbacks[63] = (delegate* unmanaged)&_getBoxHelper; + callbacks[64] = (delegate* unmanaged)&_getUnBoxHelper; + callbacks[65] = (delegate* unmanaged)&_getReadyToRunHelper; + callbacks[66] = (delegate* unmanaged)&_getReadyToRunDelegateCtorHelper; + callbacks[67] = (delegate* unmanaged)&_getHelperName; + callbacks[68] = (delegate* unmanaged)&_initClass; + callbacks[69] = (delegate* unmanaged)&_classMustBeLoadedBeforeCodeIsRun; + callbacks[70] = (delegate* unmanaged)&_getBuiltinClass; + callbacks[71] = (delegate* unmanaged)&_getTypeForPrimitiveValueClass; + callbacks[72] = (delegate* unmanaged)&_getTypeForPrimitiveNumericClass; + callbacks[73] = (delegate* unmanaged)&_canCast; + callbacks[74] = (delegate* unmanaged)&_areTypesEquivalent; + callbacks[75] = (delegate* unmanaged)&_compareTypesForCast; + callbacks[76] = (delegate* unmanaged)&_compareTypesForEquality; + callbacks[77] = (delegate* unmanaged)&_mergeClasses; + callbacks[78] = (delegate* unmanaged)&_isMoreSpecificType; + callbacks[79] = (delegate* unmanaged)&_getParentType; + callbacks[80] = (delegate* unmanaged)&_getChildType; + callbacks[81] = (delegate* unmanaged)&_satisfiesClassConstraints; + callbacks[82] = (delegate* unmanaged)&_isSDArray; + callbacks[83] = (delegate* unmanaged)&_getArrayRank; + callbacks[84] = (delegate* unmanaged)&_getArrayIntrinsicID; callbacks[85] = (delegate* unmanaged)&_getArrayInitializationData; callbacks[86] = (delegate* unmanaged)&_canAccessClass; callbacks[87] = (delegate* unmanaged)&_getFieldName; diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.Intrinsics.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.Intrinsics.cs deleted file mode 100644 index 364b0c1384232..0000000000000 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.Intrinsics.cs +++ /dev/null @@ -1,150 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Diagnostics; - -using Internal.TypeSystem; - -namespace Internal.JitInterface -{ - internal unsafe partial class CorInfoImpl - { - private struct IntrinsicKey - { - public string MethodName; - public string TypeNamespace; - public string TypeName; - - public bool Equals(IntrinsicKey other) - { - return (MethodName == other.MethodName) && - (TypeNamespace == other.TypeNamespace) && - (TypeName == other.TypeName); - } - - public override int GetHashCode() - { - return MethodName.GetHashCode() + - ((TypeNamespace != null) ? TypeNamespace.GetHashCode() : 0) + - ((TypeName != null) ? TypeName.GetHashCode() : 0); - } - } - - private class IntrinsicEntry - { - public IntrinsicKey Key; - public CorInfoIntrinsics Id; - } - - private class IntrinsicHashtable : LockFreeReaderHashtable - { - protected override bool CompareKeyToValue(IntrinsicKey key, IntrinsicEntry value) - { - return key.Equals(value.Key); - } - protected override bool CompareValueToValue(IntrinsicEntry value1, IntrinsicEntry value2) - { - return value1.Key.Equals(value2.Key); - } - protected override IntrinsicEntry CreateValueFromKey(IntrinsicKey key) - { - Debug.Fail("CreateValueFromKey not supported"); - return null; - } - protected override int GetKeyHashCode(IntrinsicKey key) - { - return key.GetHashCode(); - } - protected override int GetValueHashCode(IntrinsicEntry value) - { - return value.Key.GetHashCode(); - } - - public void Add(CorInfoIntrinsics id, string methodName, string typeNamespace, string typeName) - { - var entry = new IntrinsicEntry(); - entry.Id = id; - entry.Key.MethodName = methodName; - entry.Key.TypeNamespace = typeNamespace; - entry.Key.TypeName = typeName; - AddOrGetExisting(entry); - } - } - - static IntrinsicHashtable InitializeIntrinsicHashtable() - { - IntrinsicHashtable table = new IntrinsicHashtable(); - - table.Add(CorInfoIntrinsics.CORINFO_INTRINSIC_Array_Get, "Get", null, null); - table.Add(CorInfoIntrinsics.CORINFO_INTRINSIC_Array_Address, "Address", null, null); - table.Add(CorInfoIntrinsics.CORINFO_INTRINSIC_Array_Set, "Set", null, null); - table.Add(CorInfoIntrinsics.CORINFO_INTRINSIC_ByReference_Ctor, ".ctor", "System", "ByReference`1"); - table.Add(CorInfoIntrinsics.CORINFO_INTRINSIC_ByReference_Value, "get_Value", "System", "ByReference`1"); - table.Add(CorInfoIntrinsics.CORINFO_INTRINSIC_GetRawHandle, "EETypePtrOf", "System", "EETypePtr"); - table.Add(CorInfoIntrinsics.CORINFO_INTRINSIC_GetRawHandle, "MethodTableOf", "System", "Object"); - table.Add(CorInfoIntrinsics.CORINFO_INTRINSIC_GetRawHandle, "DefaultConstructorOf", "System", "Activator"); - table.Add(CorInfoIntrinsics.CORINFO_INTRINSIC_GetRawHandle, "AllocatorOf", "System", "Activator"); - - return table; - } - - static IntrinsicHashtable s_IntrinsicHashtable = InitializeIntrinsicHashtable(); - - private CorInfoIntrinsics getIntrinsicID(CORINFO_METHOD_STRUCT_* ftn, byte* pMustExpand) - { - var method = HandleToObject(ftn); - return getIntrinsicID(method, pMustExpand); - } - - private CorInfoIntrinsics getIntrinsicID(MethodDesc method, byte* pMustExpand) - { - if (pMustExpand != null) - *pMustExpand = 0; - - Debug.Assert(method.IsIntrinsic); - - IntrinsicKey key = new IntrinsicKey(); - key.MethodName = method.Name; - - var metadataType = method.OwningType as MetadataType; - if (metadataType != null) - { - key.TypeNamespace = metadataType.Namespace; - key.TypeName = metadataType.Name; - } - - IntrinsicEntry entry; - if (!s_IntrinsicHashtable.TryGetValue(key, out entry)) - return CorInfoIntrinsics.CORINFO_INTRINSIC_Illegal; - - // Some intrinsics need further disambiguation - CorInfoIntrinsics id = entry.Id; - switch (id) - { - case CorInfoIntrinsics.CORINFO_INTRINSIC_Array_Get: - case CorInfoIntrinsics.CORINFO_INTRINSIC_Array_Address: - case CorInfoIntrinsics.CORINFO_INTRINSIC_Array_Set: - if (!method.OwningType.IsArray) - return CorInfoIntrinsics.CORINFO_INTRINSIC_Illegal; - break; - - case CorInfoIntrinsics.CORINFO_INTRINSIC_ByReference_Ctor: - case CorInfoIntrinsics.CORINFO_INTRINSIC_ByReference_Value: - if (pMustExpand != null) - *pMustExpand = 1; - break; - - case CorInfoIntrinsics.CORINFO_INTRINSIC_GetRawHandle: - if (pMustExpand != null) - *pMustExpand = 1; - break; - - default: - break; - } - - return id; - } - } -} diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index 4377fb6f784b9..f800dadf43159 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -1023,10 +1023,10 @@ private TypeSystemEntity entityFromContext(CORINFO_CONTEXT_STRUCT* contextStruct return (TypeSystemEntity)HandleToObject((IntPtr)((ulong)contextStruct & ~(ulong)CorInfoContextFlags.CORINFO_CONTEXTFLAGS_MASK)); } - private bool isJitIntrinsic(CORINFO_METHOD_STRUCT_* ftn) + private bool isIntrinsic(CORINFO_METHOD_STRUCT_* ftn) { MethodDesc method = HandleToObject(ftn); - return method.IsIntrinsic; + return method.IsIntrinsic || HardwareIntrinsicHelpers.IsHardwareIntrinsic(method); } private uint getMethodAttribsInternal(MethodDesc method) @@ -1041,7 +1041,7 @@ private uint getMethodAttribsInternal(MethodDesc method) if (method.IsSynchronized) result |= CorInfoFlag.CORINFO_FLG_SYNCH; if (method.IsIntrinsic) - result |= CorInfoFlag.CORINFO_FLG_INTRINSIC | CorInfoFlag.CORINFO_FLG_JIT_INTRINSIC; + result |= CorInfoFlag.CORINFO_FLG_INTRINSIC; if (method.IsVirtual) result |= CorInfoFlag.CORINFO_FLG_VIRTUAL; if (method.IsAbstract) @@ -1115,7 +1115,7 @@ private uint getMethodAttribsInternal(MethodDesc method) // Check for hardware intrinsics if (HardwareIntrinsicHelpers.IsHardwareIntrinsic(method)) { - result |= CorInfoFlag.CORINFO_FLG_JIT_INTRINSIC; + result |= CorInfoFlag.CORINFO_FLG_INTRINSIC; } return (uint)result; @@ -2746,6 +2746,22 @@ private uint getArrayRank(CORINFO_CLASS_STRUCT_* cls) return rank; } + private CorInfoArrayIntrinsic getArrayIntrinsicID(CORINFO_METHOD_STRUCT_* ftn) + { + CorInfoArrayIntrinsic kind = CorInfoArrayIntrinsic.ILLEGAL; + if (HandleToObject(ftn) is ArrayMethod am) + { + kind = am.Kind switch + { + ArrayMethodKind.Get => CorInfoArrayIntrinsic.GET, + ArrayMethodKind.Set => CorInfoArrayIntrinsic.SET, + ArrayMethodKind.Address => CorInfoArrayIntrinsic.ADDRESS, + _ => CorInfoArrayIntrinsic.ILLEGAL + }; + } + return kind; + } + private void* getArrayInitializationData(CORINFO_FIELD_STRUCT_* field, uint size) { var fd = HandleToObject(field); diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs index 4d59d99a771d3..4a7d254d583fc 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs @@ -437,17 +437,15 @@ public enum CorInfoOptions CORINFO_GENERICS_CTXT_KEEP_ALIVE = 0x00000100, // Keep the generics context alive throughout the method even if there is no explicit use, and report its location to the CLR } - public enum CorInfoIntrinsics + // These are used to detect array methods as NamedIntrinsic in JIT importer, + // which otherwise don't have a name. + public enum CorInfoArrayIntrinsic { - 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_ByReference_Ctor, - CORINFO_INTRINSIC_ByReference_Value, - CORINFO_INTRINSIC_GetRawHandle, + GET = 0, + SET = 1, + ADDRESS = 2, - CORINFO_INTRINSIC_Count, - CORINFO_INTRINSIC_Illegal = -1, // Not a true intrinsic, + ILLEGAL } // Can a value be accessed directly from JITed code. @@ -597,7 +595,6 @@ public enum CorInfoFlag : uint // CORINFO_FLG_UNUSED = 0x04000000, CORINFO_FLG_DONT_INLINE = 0x10000000, // The method should not be inlined CORINFO_FLG_DONT_INLINE_CALLER = 0x20000000, // The method should not be inlined, nor should its callers. It cannot be tail called. - CORINFO_FLG_JIT_INTRINSIC = 0x40000000, // Method is a potential jit intrinsic; verify identity by name check // These are internal flags that can only be on Classes CORINFO_FLG_VALUECLASS = 0x00010000, // is the class a value class diff --git a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt index 2e62a489400f7..dbe775e1e0246 100644 --- a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt +++ b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt @@ -109,7 +109,7 @@ CorInfoInitClassResult CorInfoInlineTypeCheck CorInfoInlineTypeCheckSource CorInfoInline -CorInfoIntrinsics +CorInfoArrayIntrinsic CorInfoIsAccessAllowedResult CorInfoMethodRuntimeFlags CorInfoTailCall @@ -153,7 +153,7 @@ struct _EXCEPTION_POINTERS*,_EXCEPTION_POINTERS* ICorJitInfo::errorTrapFunction,void* FUNCTIONS - bool isJitIntrinsic( CORINFO_METHOD_HANDLE ftn ); + bool isIntrinsic( CORINFO_METHOD_HANDLE ftn ); uint32_t getMethodAttribs( CORINFO_METHOD_HANDLE ftn ); void setMethodAttribs( CORINFO_METHOD_HANDLE ftn, CorInfoMethodRuntimeFlags attribs ); void getMethodSig( CORINFO_METHOD_HANDLE ftn, CORINFO_SIG_INFO *sig, CORINFO_CLASS_HANDLE memberParent ); @@ -171,7 +171,6 @@ FUNCTIONS CORINFO_CLASS_HANDLE getDefaultComparerClass(CORINFO_CLASS_HANDLE elemType); CORINFO_CLASS_HANDLE getDefaultEqualityComparerClass(CORINFO_CLASS_HANDLE elemType); void expandRawHandleIntrinsic(CORINFO_RESOLVED_TOKEN * pResolvedToken, CORINFO_GENERICHANDLE_RESULT * pResult); - CorInfoIntrinsics getIntrinsicID( CORINFO_METHOD_HANDLE method , BoolStar pMustExpand); bool isIntrinsicType( CORINFO_CLASS_HANDLE classHnd ); CorInfoCallConvExtension getUnmanagedCallConv( CORINFO_METHOD_HANDLE method, CORINFO_SIG_INFO* callSiteSig, bool* pSuppressGCTransition); bool pInvokeMarshalingRequired( CORINFO_METHOD_HANDLE method, CORINFO_SIG_INFO* callSiteSig ); @@ -238,6 +237,7 @@ FUNCTIONS bool satisfiesClassConstraints(CORINFO_CLASS_HANDLE cls) bool isSDArray(CORINFO_CLASS_HANDLE cls) unsigned getArrayRank(CORINFO_CLASS_HANDLE cls) + CorInfoArrayIntrinsic getArrayIntrinsicID(CORINFO_METHOD_HANDLE ftn) void* getArrayInitializationData(CORINFO_FIELD_HANDLE field, uint32_t size) CorInfoIsAccessAllowedResult canAccessClass(CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_METHOD_HANDLE callerHandle, CORINFO_HELPER_DESC* pAccessHelper) const char* getFieldName(CORINFO_FIELD_HANDLE ftn, const char** moduleName) diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ILCompiler.ReadyToRun.csproj b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ILCompiler.ReadyToRun.csproj index 8a1dc4eca0d17..40f19bfefc78a 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ILCompiler.ReadyToRun.csproj +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ILCompiler.ReadyToRun.csproj @@ -274,9 +274,6 @@ JitInterface\JitConfigProvider.cs - - JitInterface\CorInfoImpl.Intrinsics.cs - JitInterface\MemoryHelper.cs diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs index da50f5bbf458e..c5f8251ccb739 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs @@ -1645,8 +1645,7 @@ private void ceeInfoGetCallInfo( // 3) JIT intrinsics - since they have pre-defined behavior devirt = targetMethod.OwningType.IsValueType || (targetMethod.OwningType.IsDelegate && targetMethod.Name == "Invoke") || - (targetMethod.OwningType.IsObject && targetMethod.Name == "GetType") || - (targetMethod.IsIntrinsic && getIntrinsicID(targetMethod, null) != CorInfoIntrinsics.CORINFO_INTRINSIC_Illegal); + (targetMethod.OwningType.IsObject && targetMethod.Name == "GetType"); callVirtCrossingVersionBubble = true; } diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/ILCompiler.RyuJit.csproj b/src/coreclr/tools/aot/ILCompiler.RyuJit/ILCompiler.RyuJit.csproj index b1325a2a7a339..efff02a77708c 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/ILCompiler.RyuJit.csproj +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/ILCompiler.RyuJit.csproj @@ -16,7 +16,7 @@ false Debug;Release;Checked - + @@ -73,9 +73,6 @@ JitInterface\CorInfoImpl.cs - - JitInterface\CorInfoImpl.Intrinsics.cs - JitInterface\MemoryHelper.cs @@ -98,6 +95,6 @@ - + diff --git a/src/coreclr/tools/aot/jitinterface/jitinterface.h b/src/coreclr/tools/aot/jitinterface/jitinterface.h index c620b9b29f948..f0158199fea1a 100644 --- a/src/coreclr/tools/aot/jitinterface/jitinterface.h +++ b/src/coreclr/tools/aot/jitinterface/jitinterface.h @@ -11,7 +11,7 @@ struct JitInterfaceCallbacks { - bool (* isJitIntrinsic)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE ftn); + bool (* isIntrinsic)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE ftn); uint32_t (* getMethodAttribs)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE ftn); void (* setMethodAttribs)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE ftn, CorInfoMethodRuntimeFlags attribs); void (* getMethodSig)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE ftn, CORINFO_SIG_INFO* sig, CORINFO_CLASS_HANDLE memberParent); @@ -29,7 +29,6 @@ struct JitInterfaceCallbacks CORINFO_CLASS_HANDLE (* getDefaultComparerClass)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE elemType); CORINFO_CLASS_HANDLE (* getDefaultEqualityComparerClass)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE elemType); void (* expandRawHandleIntrinsic)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_GENERICHANDLE_RESULT* pResult); - CorInfoIntrinsics (* getIntrinsicID)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE method, bool* pMustExpand); bool (* isIntrinsicType)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE classHnd); CorInfoCallConvExtension (* getUnmanagedCallConv)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE method, CORINFO_SIG_INFO* callSiteSig, bool* pSuppressGCTransition); bool (* pInvokeMarshalingRequired)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE method, CORINFO_SIG_INFO* callSiteSig); @@ -96,6 +95,7 @@ struct JitInterfaceCallbacks bool (* satisfiesClassConstraints)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE cls); bool (* isSDArray)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE cls); unsigned (* getArrayRank)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE cls); + CorInfoArrayIntrinsic (* getArrayIntrinsicID)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE ftn); void* (* getArrayInitializationData)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_FIELD_HANDLE field, uint32_t size); CorInfoIsAccessAllowedResult (* canAccessClass)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_METHOD_HANDLE callerHandle, CORINFO_HELPER_DESC* pAccessHelper); const char* (* getFieldName)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_FIELD_HANDLE ftn, const char** moduleName); @@ -199,11 +199,11 @@ class JitInterfaceWrapper : public ICorJitInfo } - virtual bool isJitIntrinsic( + virtual bool isIntrinsic( CORINFO_METHOD_HANDLE ftn) { CorInfoExceptionClass* pException = nullptr; - bool temp = _callbacks->isJitIntrinsic(_thisHandle, &pException, ftn); + bool temp = _callbacks->isIntrinsic(_thisHandle, &pException, ftn); if (pException != nullptr) throw pException; return temp; } @@ -377,16 +377,6 @@ class JitInterfaceWrapper : public ICorJitInfo if (pException != nullptr) throw pException; } - virtual CorInfoIntrinsics getIntrinsicID( - CORINFO_METHOD_HANDLE method, - bool* pMustExpand) -{ - CorInfoExceptionClass* pException = nullptr; - CorInfoIntrinsics temp = _callbacks->getIntrinsicID(_thisHandle, &pException, method, pMustExpand); - if (pException != nullptr) throw pException; - return temp; -} - virtual bool isIntrinsicType( CORINFO_CLASS_HANDLE classHnd) { @@ -1023,6 +1013,15 @@ class JitInterfaceWrapper : public ICorJitInfo return temp; } + virtual CorInfoArrayIntrinsic getArrayIntrinsicID( + CORINFO_METHOD_HANDLE ftn) +{ + CorInfoExceptionClass* pException = nullptr; + CorInfoArrayIntrinsic temp = _callbacks->getArrayIntrinsicID(_thisHandle, &pException, ftn); + if (pException != nullptr) throw pException; + return temp; +} + virtual void* getArrayInitializationData( CORINFO_FIELD_HANDLE field, uint32_t size) diff --git a/src/coreclr/vm/array.cpp b/src/coreclr/vm/array.cpp index a83c577b72c86..804a936d42cda 100644 --- a/src/coreclr/vm/array.cpp +++ b/src/coreclr/vm/array.cpp @@ -58,24 +58,6 @@ DWORD ArrayMethodDesc::GetAttrs() return (GetArrayFuncIndex() >= ARRAY_FUNC_CTOR) ? (mdPublic | mdRTSpecialName) : mdPublic; } -/*****************************************************************************************/ -CorInfoIntrinsics ArrayMethodDesc::GetIntrinsicID() -{ - LIMITED_METHOD_CONTRACT; - - switch (GetArrayFuncIndex()) - { - case ARRAY_FUNC_GET: - return CORINFO_INTRINSIC_Array_Get; - case ARRAY_FUNC_SET: - return CORINFO_INTRINSIC_Array_Set; - case ARRAY_FUNC_ADDRESS: - return CORINFO_INTRINSIC_Array_Address; - default: - return CORINFO_INTRINSIC_Illegal; - } -} - #ifndef DACCESS_COMPILE /*****************************************************************************************/ diff --git a/src/coreclr/vm/ceeload.cpp b/src/coreclr/vm/ceeload.cpp index b8d69bc36669f..e41efa704c72f 100644 --- a/src/coreclr/vm/ceeload.cpp +++ b/src/coreclr/vm/ceeload.cpp @@ -7705,7 +7705,7 @@ void Module::ExpandAll() //These are the only methods we can jit && (pMD->IsStatic() || pMD->GetNumGenericMethodArgs() == 0 || pMD->HasClassInstantiation()) - && (pMD->MayHaveNativeCode() && !pMD->IsFCallOrIntrinsic())) + && (pMD->MayHaveNativeCode() && !pMD->IsFCall())) { pMD->PrepareInitialCode(); } diff --git a/src/coreclr/vm/ecall.h b/src/coreclr/vm/ecall.h index 1a538db3c67e5..538227cf13d6a 100644 --- a/src/coreclr/vm/ecall.h +++ b/src/coreclr/vm/ecall.h @@ -50,7 +50,6 @@ struct ECFunc { bool IsEndOfArray() { LIMITED_METHOD_CONTRACT; return !!(m_dwFlags & FCFuncFlag_EndOfArray); } bool HasSignature() { LIMITED_METHOD_CONTRACT; return !!(m_dwFlags & FCFuncFlag_HasSignature); } bool IsUnreferenced(){ LIMITED_METHOD_CONTRACT; return !!(m_dwFlags & FCFuncFlag_Unreferenced); } - CorInfoIntrinsics IntrinsicID() { LIMITED_METHOD_CONTRACT; return (CorInfoIntrinsics)((INT8)(m_dwFlags >> 16)); } int DynamicID() { LIMITED_METHOD_CONTRACT; return (int) ((INT8)(m_dwFlags >> 24)); } ECFunc* NextInArray() diff --git a/src/coreclr/vm/genmeth.cpp b/src/coreclr/vm/genmeth.cpp index f847fbbd0d5d6..8237f147c6166 100644 --- a/src/coreclr/vm/genmeth.cpp +++ b/src/coreclr/vm/genmeth.cpp @@ -5,8 +5,6 @@ // Most functionality for generic methods is put here // - - #include "common.h" #include "method.hpp" #include "field.h" @@ -117,9 +115,9 @@ static MethodDesc* CreateMethodDesc(LoaderAllocator *pAllocator, { pMD->SetSynchronized(); } - if (pTemplateMD->IsJitIntrinsic()) + if (pTemplateMD->IsIntrinsic()) { - pMD->SetIsJitIntrinsic(); + pMD->SetIsIntrinsic(); } pMD->SetMemberDef(token); diff --git a/src/coreclr/vm/interpreter.cpp b/src/coreclr/vm/interpreter.cpp index 0f3490ade5a05..6ca5bb6935a62 100644 --- a/src/coreclr/vm/interpreter.cpp +++ b/src/coreclr/vm/interpreter.cpp @@ -9129,16 +9129,19 @@ void Interpreter::DoCallWork(bool virtualCall, void* thisArg, CORINFO_RESOLVED_T // Point A in our cycle count. + // TODO: enable when NamedIntrinsic is available to interpreter + + /* // Is the method an intrinsic? If so, and if it's one we've written special-case code for // handle intrinsically. - CorInfoIntrinsics intrinsicId; + NamedIntrinsic intrinsicName; { GCX_PREEMP(); - intrinsicId = m_interpCeeInfo.getIntrinsicID(CORINFO_METHOD_HANDLE(methToCall), nullptr); + intrinsicName = getIntrinsicName(CORINFO_METHOD_HANDLE(methToCall), nullptr); } #if INTERP_TRACING - if (intrinsicId != CORINFO_INTRINSIC_Illegal) + if (intrinsicName == NI_Illegal) InterlockedIncrement(&s_totalInterpCallsToIntrinsics); #endif // INTERP_TRACING bool didIntrinsic = false; @@ -9146,23 +9149,20 @@ void Interpreter::DoCallWork(bool virtualCall, void* thisArg, CORINFO_RESOLVED_T { switch (intrinsicId) { - case CORINFO_INTRINSIC_ByReference_Ctor: + case NI_System_ByReference_ctor: DoByReferenceCtor(); didIntrinsic = true; break; - case CORINFO_INTRINSIC_ByReference_Value: + case NI_System_ByReference_get_Value: DoByReferenceValue(); didIntrinsic = true; break; #if INTERP_ILSTUBS - // TODO: enable when NamedIntrinsic is available to interpreter - /* case NI_System_StubHelpers_GetStubContext: OpStackSet(m_curStackHt, GetStubContext()); OpStackTypeSet(m_curStackHt, InterpreterType(CORINFO_TYPE_NATIVEINT)); m_curStackHt++; didIntrinsic = true; break; - */ #endif // INTERP_ILSTUBS default: #if INTERP_TRACING @@ -9253,6 +9253,7 @@ void Interpreter::DoCallWork(bool virtualCall, void* thisArg, CORINFO_RESOLVED_T // Now we can return. return; } + */ // Handle other simple special cases: diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index 1433856f3378a..df4e985fda1e6 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -6,7 +6,6 @@ // =========================================================================== - #include "common.h" #include "jitinterface.h" #include "codeman.h" @@ -4671,6 +4670,44 @@ unsigned CEEInfo::getArrayRank(CORINFO_CLASS_HANDLE cls) return result; } +/*********************************************************************/ +// Get the index of runtime provided array method +CorInfoArrayIntrinsic CEEInfo::getArrayIntrinsicID(CORINFO_METHOD_HANDLE ftn) +{ + CONTRACTL { + THROWS; + GC_TRIGGERS; + MODE_PREEMPTIVE; + } CONTRACTL_END; + + CorInfoArrayIntrinsic result = CorInfoArrayIntrinsic::ILLEGAL; + + JIT_TO_EE_TRANSITION(); + + MethodDesc* pMD = GetMethod(ftn); + + if (pMD->IsArray()) + { + DWORD index = ((ArrayMethodDesc*)pMD)->GetArrayFuncIndex(); + switch (index) + { + case 0: // ARRAY_FUNC_GET + result = CorInfoArrayIntrinsic::GET; + break; + case 1: // ARRAY_FUNC_SET + result = CorInfoArrayIntrinsic::SET; + break; + case 2: // ARRAY_FUNC_ADDRESS + result = CorInfoArrayIntrinsic::ADDRESS; + break; + } + } + + EE_TO_JIT_TRANSITION(); + + return result; +} + /*********************************************************************/ // Get static field data for an array // Note that it's OK to return NULL from this method. This will cause @@ -6308,7 +6345,7 @@ CORINFO_CLASS_HANDLE CEEInfo::getTypeInstantiationArgument(CORINFO_CLASS_HANDLE } /*********************************************************************/ -bool CEEInfo::isJitIntrinsic(CORINFO_METHOD_HANDLE ftn) +bool CEEInfo::isIntrinsic(CORINFO_METHOD_HANDLE ftn) { CONTRACTL { NOTHROW; @@ -6323,7 +6360,7 @@ bool CEEInfo::isJitIntrinsic(CORINFO_METHOD_HANDLE ftn) _ASSERTE(ftn); MethodDesc *pMD = (MethodDesc*)ftn; - ret = pMD->IsJitIntrinsic(); + ret = pMD->IsIntrinsic(); EE_TO_JIT_TRANSITION_LEAF(); @@ -6379,10 +6416,10 @@ DWORD CEEInfo::getMethodAttribsInternal (CORINFO_METHOD_HANDLE ftn) result |= CORINFO_FLG_STATIC; if (pMD->IsSynchronized()) result |= CORINFO_FLG_SYNCH; - if (pMD->IsFCallOrIntrinsic()) - result |= CORINFO_FLG_NOGCCHECK | CORINFO_FLG_INTRINSIC; - if (pMD->IsJitIntrinsic()) - result |= CORINFO_FLG_JIT_INTRINSIC; + if (pMD->IsFCall()) + result |= CORINFO_FLG_NOGCCHECK; + if (pMD->IsIntrinsic() || pMD->IsArray()) + result |= CORINFO_FLG_INTRINSIC; if (IsMdVirtual(attribs)) result |= CORINFO_FLG_VIRTUAL; if (IsMdAbstract(attribs)) @@ -7275,7 +7312,7 @@ getMethodInfoHelper( MethodTable * pMT = ftn->GetMethodTable(); - if (ftn->IsJitIntrinsic()) + if (ftn->IsIntrinsic()) { if (CoreLibBinder::IsClass(pMT, CLASS__UNSAFE)) { @@ -8338,62 +8375,6 @@ CORINFO_MODULE_HANDLE CEEInfo::getMethodModule (CORINFO_METHOD_HANDLE methodHnd) return result; } -/*********************************************************************/ -CorInfoIntrinsics CEEInfo::getIntrinsicID(CORINFO_METHOD_HANDLE methodHnd, - bool * pMustExpand) -{ - CONTRACTL { - THROWS; - GC_TRIGGERS; - MODE_PREEMPTIVE; - } CONTRACTL_END; - - CorInfoIntrinsics result = CORINFO_INTRINSIC_Illegal; - - JIT_TO_EE_TRANSITION(); - - if (pMustExpand != NULL) - { - *pMustExpand = false; - } - - MethodDesc* method = GetMethod(methodHnd); - - if (method->IsArray()) - { - ArrayMethodDesc * arrMethod = (ArrayMethodDesc *)method; - result = arrMethod->GetIntrinsicID(); - } - else - { - MethodTable * pMT = method->GetMethodTable(); - if (pMT->GetModule()->IsSystem() && pMT->IsByRefLike()) - { - if (pMT->HasSameTypeDefAs(g_pByReferenceClass)) - { - // ByReference has just two methods: constructor and Value property - if (method->IsCtor()) - { - result = CORINFO_INTRINSIC_ByReference_Ctor; - } - else - { - _ASSERTE(strcmp(method->GetName(), "get_Value") == 0); - result = CORINFO_INTRINSIC_ByReference_Value; - } - if (pMustExpand != nullptr) - { - *pMustExpand = true; - } - } - } - } - - EE_TO_JIT_TRANSITION(); - - return result; -} - /*********************************************************************/ bool CEEInfo::isIntrinsicType(CORINFO_CLASS_HANDLE classHnd) { diff --git a/src/coreclr/vm/method.cpp b/src/coreclr/vm/method.cpp index 0461aa6b50283..6e20c4d28f51c 100644 --- a/src/coreclr/vm/method.cpp +++ b/src/coreclr/vm/method.cpp @@ -9,7 +9,6 @@ // file:../../doc/BookOfTheRuntime/ClassLoader/MethodDescDesign.doc // - #include "common.h" #include "excep.h" #include "dbginterface.h" @@ -2163,22 +2162,6 @@ MethodDesc* Entry2MethodDesc(PCODE entryPoint, MethodTable *pMT) RETURN (NULL); } -//******************************************************************************* -BOOL MethodDesc::IsFCallOrIntrinsic() -{ - WRAPPER_NO_CONTRACT; - - if (IsFCall() || IsArray()) - return TRUE; - - // Intrinsic methods on ByReference, Span, or ReadOnlySpan - MethodTable * pMT = GetMethodTable(); - if (pMT->IsByRefLike() && pMT->GetModule()->IsSystem()) - return TRUE; - - return FALSE; -} - //******************************************************************************* BOOL MethodDesc::IsPointingToPrestub() { diff --git a/src/coreclr/vm/method.hpp b/src/coreclr/vm/method.hpp index fc23cd0506dea..79d6fd612ff76 100644 --- a/src/coreclr/vm/method.hpp +++ b/src/coreclr/vm/method.hpp @@ -611,7 +611,6 @@ class MethodDesc || mcArray == GetClassification(); } - inline DWORD IsArray() const { LIMITED_METHOD_DAC_CONTRACT; @@ -711,8 +710,6 @@ class MethodDesc return mcFCall == GetClassification(); } - BOOL IsFCallOrIntrinsic(); - BOOL IsQCall(); //================================================================ @@ -1694,7 +1691,7 @@ class MethodDesc enum_flag2_IsUnboxingStub = 0x04, // unused = 0x08, - enum_flag2_IsJitIntrinsic = 0x10, // Jit may expand method as an intrinsic + enum_flag2_IsIntrinsic = 0x10, // Jit may expand method as an intrinsic enum_flag2_IsEligibleForTieredCompilation = 0x20, @@ -1750,16 +1747,16 @@ class MethodDesc m_wFlags |= mdcHasNativeCodeSlot; } - inline BOOL IsJitIntrinsic() + inline BOOL IsIntrinsic() { LIMITED_METHOD_DAC_CONTRACT; - return (m_bFlags2 & enum_flag2_IsJitIntrinsic) != 0; + return (m_bFlags2 & enum_flag2_IsIntrinsic) != 0; } - inline void SetIsJitIntrinsic() + inline void SetIsIntrinsic() { LIMITED_METHOD_CONTRACT; - m_bFlags2 |= enum_flag2_IsJitIntrinsic; + m_bFlags2 |= enum_flag2_IsIntrinsic; } BOOL RequiresCovariantReturnTypeChecking() @@ -2641,7 +2638,6 @@ class ArrayMethodDesc : public StoredSigMethodDesc { LIMITED_METHOD_DAC_CONTRACT; - // The ru DWORD dwSlot = GetSlot(); DWORD dwVirtuals = GetMethodTable()->GetNumVirtuals(); _ASSERTE(dwSlot >= dwVirtuals); @@ -2650,7 +2646,6 @@ class ArrayMethodDesc : public StoredSigMethodDesc LPCUTF8 GetMethodName(); DWORD GetAttrs(); - CorInfoIntrinsics GetIntrinsicID(); }; #ifdef HAS_NDIRECT_IMPORT_PRECODE diff --git a/src/coreclr/vm/methodtable.cpp b/src/coreclr/vm/methodtable.cpp index 1d63103cb36f1..a05fe5531ba8f 100644 --- a/src/coreclr/vm/methodtable.cpp +++ b/src/coreclr/vm/methodtable.cpp @@ -650,24 +650,6 @@ BOOL MethodTable::HasSameTypeDefAs(MethodTable *pMT) return (GetModule() == pMT->GetModule()); } -//========================================================================================== -BOOL MethodTable::HasSameTypeDefAs_NoLogging(MethodTable *pMT) -{ - LIMITED_METHOD_DAC_CONTRACT; - - if (this == pMT) - return TRUE; - - // optimize for the negative case where we expect RID mismatch - if (GetTypeDefRid_NoLogging() != pMT->GetTypeDefRid_NoLogging()) - return FALSE; - - if (GetCanonicalMethodTable() == pMT->GetCanonicalMethodTable()) - return TRUE; - - return (GetModule_NoLogging() == pMT->GetModule_NoLogging()); -} - #ifndef DACCESS_COMPILE //========================================================================================== diff --git a/src/coreclr/vm/methodtable.h b/src/coreclr/vm/methodtable.h index a56c575636318..c69cf8ed01ff0 100644 --- a/src/coreclr/vm/methodtable.h +++ b/src/coreclr/vm/methodtable.h @@ -1183,7 +1183,6 @@ class MethodTable } BOOL HasSameTypeDefAs(MethodTable *pMT); - BOOL HasSameTypeDefAs_NoLogging(MethodTable *pMT); //------------------------------------------------------------------- // GENERICS & CODE SHARING diff --git a/src/coreclr/vm/methodtablebuilder.cpp b/src/coreclr/vm/methodtablebuilder.cpp index d5feeae4425e2..d5d0140939b9f 100644 --- a/src/coreclr/vm/methodtablebuilder.cpp +++ b/src/coreclr/vm/methodtablebuilder.cpp @@ -5154,7 +5154,7 @@ MethodTableBuilder::InitNewMethodDesc( NULL, NULL))) { - pNewMD->SetIsJitIntrinsic(); + pNewMD->SetIsIntrinsic(); } }