Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add notifyInstructionSetUsage api to jit interface #34209

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1025,4 +1025,5 @@ DWORD getJitFlags(CORJIT_FLAGS* flags, /* IN: Points to a buffer that will
version number for the CORJIT_FLAGS value. */
);

void notifyInstructionSetUsage(CORINFO_InstructionSet instructionSet, bool supported);
#endif // _ICorJitInfoImpl
Original file line number Diff line number Diff line change
Expand Up @@ -2087,3 +2087,8 @@ DWORD interceptor_ICJI::getExpectedTargetArchitecture()
{
return original_ICorJitInfo->getExpectedTargetArchitecture();
}

void interceptor_ICJI::notifyInstructionSetUsage(CORINFO_InstructionSet instructionSet, bool supported)
{
original_ICorJitInfo->notifyInstructionSetUsage(instructionSet, supported);
}
Original file line number Diff line number Diff line change
Expand Up @@ -1663,3 +1663,9 @@ DWORD interceptor_ICJI::getExpectedTargetArchitecture()
mcs->AddCall("getExpectedTargetArchitecture");
return original_ICorJitInfo->getExpectedTargetArchitecture();
}

void interceptor_ICJI::notifyInstructionSetUsage(CORINFO_InstructionSet instructionSet, bool supported)
{
mcs->AddCall("notifyInstructionSetUsage");
original_ICorJitInfo->notifyInstructionSetUsage(instructionSet, supported);
}
Original file line number Diff line number Diff line change
Expand Up @@ -1477,3 +1477,8 @@ DWORD interceptor_ICJI::getExpectedTargetArchitecture()
{
return original_ICorJitInfo->getExpectedTargetArchitecture();
}

void interceptor_ICJI::notifyInstructionSetUsage(CORINFO_InstructionSet instructionSet, bool supported)
{
original_ICorJitInfo->notifyInstructionSetUsage(instructionSet, supported);
}
5 changes: 5 additions & 0 deletions src/coreclr/src/ToolBox/superpmi/superpmi/icorjitinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,11 @@ bool MyICJI::convertPInvokeCalliToCall(CORINFO_RESOLVED_TOKEN* pResolvedToken, b
return jitInstance->mc->repConvertPInvokeCalliToCall(pResolvedToken, fMustConvert);
}

void MyICJI::notifyInstructionSetUsage(CORINFO_InstructionSet instructionSet, bool supported)
{
jitInstance->mc->cr->AddCall("notifyInstructionSetUsage");
}

// Stuff directly on ICorJitInfo

// Returns extended flags for a particular compilation instance.
Expand Down
17 changes: 12 additions & 5 deletions src/coreclr/src/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ TODO: Talk about initializing strutures before use
#endif
#endif

SELECTANY const GUID JITEEVersionIdentifier = { /* 2296da7b-3823-4d8a-8a6d-b7d4481d41e0 */
0x2296da7b,
0x3823,
0x4d8a,
{0x8a, 0x6d, 0xb7, 0xd4, 0x48, 0x1d, 0x41, 0xe0}
SELECTANY const GUID JITEEVersionIdentifier = { /* 6ae798bf-44bd-4e8a-b8fc-dbe1d1f4029e */
0x6ae798bf,
0x44bd,
0x4e8a,
{0xb8, 0xfc, 0xdb, 0xe1, 0xd1, 0xf4, 0x02, 0x9e}
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -338,6 +338,8 @@ struct SYSTEMV_AMD64_CORINFO_STRUCT_REG_PASSING_DESCRIPTOR
}
};

#include "corinfoinstructionset.h"

// CorInfoHelpFunc defines the set of helpers (accessed via the ICorDynamicInfo::getHelperFtn())
// These helpers can be called by native code which executes in the runtime.
// Compilers can emit calls to these helpers.
Expand Down Expand Up @@ -3124,6 +3126,11 @@ class ICorDynamicInfo : public ICorStaticInfo
CORINFO_RESOLVED_TOKEN * pResolvedToken,
bool fMustConvert
) = 0;

virtual void notifyInstructionSetUsage(
CORINFO_InstructionSet instructionSet,
bool supportEnabled
) = 0;
};

/**********************************************************************************/
Expand Down
133 changes: 133 additions & 0 deletions src/coreclr/src/inc/corinfoinstructionset.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#ifndef CORINFOINSTRUCTIONSET_H
#define CORINFOINSTRUCTIONSET_H

#include "readytoruninstructionset.h"
#include <stdint.h>

enum CORINFO_InstructionSet
{
InstructionSet_ILLEGAL = 0,
Expand Down Expand Up @@ -293,6 +296,136 @@ inline CORINFO_InstructionSetFlags EnsureInstructionSetFlagsAreValid(CORINFO_Ins
return resultflags;
}

inline const char *InstructionSetToString(CORINFO_InstructionSet instructionSet)
lpereira marked this conversation as resolved.
Show resolved Hide resolved
{
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4065) // disable warning for switch statement with only default label.
#endif

switch (instructionSet)
{
#ifdef TARGET_ARM64
case InstructionSet_ArmBase :
return "ArmBase";
case InstructionSet_ArmBase_Arm64 :
return "ArmBase_Arm64";
case InstructionSet_AdvSimd :
return "AdvSimd";
case InstructionSet_AdvSimd_Arm64 :
return "AdvSimd_Arm64";
case InstructionSet_Aes :
return "Aes";
case InstructionSet_Crc32 :
return "Crc32";
case InstructionSet_Crc32_Arm64 :
return "Crc32_Arm64";
case InstructionSet_Sha1 :
return "Sha1";
case InstructionSet_Sha256 :
return "Sha256";
case InstructionSet_Atomics :
return "Atomics";
case InstructionSet_Vector64 :
return "Vector64";
case InstructionSet_Vector128 :
return "Vector128";
#endif // TARGET_ARM64
#ifdef TARGET_AMD64
case InstructionSet_SSE :
return "SSE";
case InstructionSet_SSE_X64 :
return "SSE_X64";
case InstructionSet_SSE2 :
return "SSE2";
case InstructionSet_SSE2_X64 :
return "SSE2_X64";
case InstructionSet_SSE3 :
return "SSE3";
case InstructionSet_SSSE3 :
return "SSSE3";
case InstructionSet_SSE41 :
return "SSE41";
case InstructionSet_SSE41_X64 :
return "SSE41_X64";
case InstructionSet_SSE42 :
return "SSE42";
case InstructionSet_SSE42_X64 :
return "SSE42_X64";
case InstructionSet_AVX :
return "AVX";
case InstructionSet_AVX2 :
return "AVX2";
case InstructionSet_AES :
return "AES";
case InstructionSet_BMI1 :
return "BMI1";
case InstructionSet_BMI1_X64 :
return "BMI1_X64";
case InstructionSet_BMI2 :
return "BMI2";
case InstructionSet_BMI2_X64 :
return "BMI2_X64";
case InstructionSet_FMA :
return "FMA";
case InstructionSet_LZCNT :
return "LZCNT";
case InstructionSet_LZCNT_X64 :
return "LZCNT_X64";
case InstructionSet_PCLMULQDQ :
return "PCLMULQDQ";
case InstructionSet_POPCNT :
return "POPCNT";
case InstructionSet_POPCNT_X64 :
return "POPCNT_X64";
case InstructionSet_Vector128 :
return "Vector128";
case InstructionSet_Vector256 :
return "Vector256";
#endif // TARGET_AMD64
#ifdef TARGET_X86
case InstructionSet_SSE :
return "SSE";
case InstructionSet_SSE2 :
return "SSE2";
case InstructionSet_SSE3 :
return "SSE3";
case InstructionSet_SSSE3 :
return "SSSE3";
case InstructionSet_SSE41 :
return "SSE41";
case InstructionSet_SSE42 :
return "SSE42";
case InstructionSet_AVX :
return "AVX";
case InstructionSet_AVX2 :
return "AVX2";
case InstructionSet_AES :
return "AES";
case InstructionSet_BMI1 :
return "BMI1";
case InstructionSet_BMI2 :
return "BMI2";
case InstructionSet_FMA :
return "FMA";
case InstructionSet_LZCNT :
return "LZCNT";
case InstructionSet_PCLMULQDQ :
return "PCLMULQDQ";
case InstructionSet_POPCNT :
return "POPCNT";
case InstructionSet_Vector128 :
return "Vector128";
case InstructionSet_Vector256 :
return "Vector256";
#endif // TARGET_X86

default:
return "UnknownInstructionSet";
}
#ifdef _MSC_VER
#pragma warning(pop)
#endif
}

#endif // CORINFOINSTRUCTIONSET_H
1 change: 1 addition & 0 deletions src/coreclr/src/jit/ICorJitInfo_API_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ DEF_CLR_API(GetDelegateCtor)
DEF_CLR_API(MethodCompileComplete)
DEF_CLR_API(getTailCallCopyArgsThunk)
DEF_CLR_API(convertPInvokeCalliToCall)
DEF_CLR_API(notifyInstructionSetUsage)
DEF_CLR_API(getMemoryManager)
DEF_CLR_API(allocMem)
DEF_CLR_API(reserveUnwindInfo)
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/src/jit/ICorJitInfo_API_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,16 @@ bool WrapICorJitInfo::convertPInvokeCalliToCall(
return temp;
}

void WrapICorJitInfo::notifyInstructionSetUsage(
CORINFO_InstructionSet instructionSet,
bool supported
)
{
API_ENTER(notifyInstructionSetUsage);
wrapHnd->notifyInstructionSetUsage(instructionSetName, supported);
API_LEAVE(notifyInstructionSetUsage);
}

/*********************************************************************************/
//
// ICorJitInfo
Expand Down
7 changes: 7 additions & 0 deletions src/coreclr/src/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2368,6 +2368,13 @@ void Compiler::compSetProcessor()
#endif // TARGET_XARCH
}

void Compiler::notifyInstructionSetUsage(CORINFO_InstructionSet isa, bool supported) const
{
const char* isaString = InstructionSetToString(isa);
JITDUMP("Notify VM instruction set (%s) %s be supported.\n", isaString, supported ? "must" : "must not");
info.compCompHnd->notifyInstructionSetUsage(isa, supported);
}

#ifdef PROFILING_SUPPORTED
// A Dummy routine to receive Enter/Leave/Tailcall profiler callbacks.
// These are used when complus_JitEltHookEnabled=1
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/src/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -8281,6 +8281,8 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#endif
}

void notifyInstructionSetUsage(CORINFO_InstructionSet isa, bool supported) const;

bool canUseVexEncoding() const
{
#ifdef TARGET_XARCH
Expand Down
54 changes: 36 additions & 18 deletions src/coreclr/src/tools/Common/JitInterface/CorInfoBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ unsafe partial class CorInfoImpl
[UnmanagedFunctionPointerAttribute(default(CallingConvention))]
[return: MarshalAs(UnmanagedType.I1)]delegate bool __convertPInvokeCalliToCall(IntPtr _this, IntPtr* ppException, ref CORINFO_RESOLVED_TOKEN pResolvedToken, [MarshalAs(UnmanagedType.I1)]bool mustConvert);
[UnmanagedFunctionPointerAttribute(default(CallingConvention))]
delegate void __notifyInstructionSetUsage(IntPtr _this, IntPtr* ppException, InstructionSet instructionSet, [MarshalAs(UnmanagedType.I1)]bool supportEnabled);
[UnmanagedFunctionPointerAttribute(default(CallingConvention))]
delegate void __allocMem(IntPtr _this, IntPtr* ppException, uint hotCodeSize, uint coldCodeSize, uint roDataSize, uint xcptnsCount, CorJitAllocMemFlag flag, ref void* hotCodeBlock, ref void* coldCodeBlock, ref void* roDataBlock);
[UnmanagedFunctionPointerAttribute(default(CallingConvention))]
delegate void __reserveUnwindInfo(IntPtr _this, IntPtr* ppException, [MarshalAs(UnmanagedType.Bool)]bool isFunclet, [MarshalAs(UnmanagedType.Bool)]bool isColdCode, uint unwindSize);
Expand Down Expand Up @@ -2455,6 +2457,19 @@ static void _MethodCompileComplete(IntPtr thisHandle, IntPtr* ppException, CORIN
}
}

static void _notifyInstructionSetUsage(IntPtr thisHandle, IntPtr* ppException, InstructionSet instructionSet, [MarshalAs(UnmanagedType.I1)]bool supportEnabled)
{
var _this = GetThis(thisHandle);
try
{
_this.notifyInstructionSetUsage(instructionSet, supportEnabled);
}
catch (Exception ex)
{
*ppException = _this.AllocException(ex);
}
}

static void _allocMem(IntPtr thisHandle, IntPtr* ppException, uint hotCodeSize, uint coldCodeSize, uint roDataSize, uint xcptnsCount, CorJitAllocMemFlag flag, ref void* hotCodeBlock, ref void* coldCodeBlock, ref void* roDataBlock)
{
var _this = GetThis(thisHandle);
Expand Down Expand Up @@ -2674,8 +2689,8 @@ static uint _getJitFlags(IntPtr thisHandle, IntPtr* ppException, ref CORJIT_FLAG

static IntPtr GetUnmanagedCallbacks(out Object keepAlive)
{
IntPtr * callbacks = (IntPtr *)Marshal.AllocCoTaskMem(sizeof(IntPtr) * 169);
Object[] delegates = new Object[169];
IntPtr * callbacks = (IntPtr *)Marshal.AllocCoTaskMem(sizeof(IntPtr) * 170);
Object[] delegates = new Object[170];

var d0 = new __getMethodAttribs(_getMethodAttribs);
callbacks[0] = Marshal.GetFunctionPointerForDelegate(d0);
Expand Down Expand Up @@ -3136,54 +3151,57 @@ static IntPtr GetUnmanagedCallbacks(out Object keepAlive)
var d152 = new __convertPInvokeCalliToCall(_convertPInvokeCalliToCall);
callbacks[152] = Marshal.GetFunctionPointerForDelegate(d152);
delegates[152] = d152;
var d153 = new __allocMem(_allocMem);
var d153 = new __notifyInstructionSetUsage(_notifyInstructionSetUsage);
callbacks[153] = Marshal.GetFunctionPointerForDelegate(d153);
delegates[153] = d153;
var d154 = new __reserveUnwindInfo(_reserveUnwindInfo);
var d154 = new __allocMem(_allocMem);
callbacks[154] = Marshal.GetFunctionPointerForDelegate(d154);
delegates[154] = d154;
var d155 = new __allocUnwindInfo(_allocUnwindInfo);
var d155 = new __reserveUnwindInfo(_reserveUnwindInfo);
callbacks[155] = Marshal.GetFunctionPointerForDelegate(d155);
delegates[155] = d155;
var d156 = new __allocGCInfo(_allocGCInfo);
var d156 = new __allocUnwindInfo(_allocUnwindInfo);
callbacks[156] = Marshal.GetFunctionPointerForDelegate(d156);
delegates[156] = d156;
var d157 = new __setEHcount(_setEHcount);
var d157 = new __allocGCInfo(_allocGCInfo);
callbacks[157] = Marshal.GetFunctionPointerForDelegate(d157);
delegates[157] = d157;
var d158 = new __setEHinfo(_setEHinfo);
var d158 = new __setEHcount(_setEHcount);
callbacks[158] = Marshal.GetFunctionPointerForDelegate(d158);
delegates[158] = d158;
var d159 = new __logMsg(_logMsg);
var d159 = new __setEHinfo(_setEHinfo);
callbacks[159] = Marshal.GetFunctionPointerForDelegate(d159);
delegates[159] = d159;
var d160 = new __doAssert(_doAssert);
var d160 = new __logMsg(_logMsg);
callbacks[160] = Marshal.GetFunctionPointerForDelegate(d160);
delegates[160] = d160;
var d161 = new __reportFatalError(_reportFatalError);
var d161 = new __doAssert(_doAssert);
callbacks[161] = Marshal.GetFunctionPointerForDelegate(d161);
delegates[161] = d161;
var d162 = new __allocMethodBlockCounts(_allocMethodBlockCounts);
var d162 = new __reportFatalError(_reportFatalError);
callbacks[162] = Marshal.GetFunctionPointerForDelegate(d162);
delegates[162] = d162;
var d163 = new __getMethodBlockCounts(_getMethodBlockCounts);
var d163 = new __allocMethodBlockCounts(_allocMethodBlockCounts);
callbacks[163] = Marshal.GetFunctionPointerForDelegate(d163);
delegates[163] = d163;
var d164 = new __recordCallSite(_recordCallSite);
var d164 = new __getMethodBlockCounts(_getMethodBlockCounts);
callbacks[164] = Marshal.GetFunctionPointerForDelegate(d164);
delegates[164] = d164;
var d165 = new __recordRelocation(_recordRelocation);
var d165 = new __recordCallSite(_recordCallSite);
callbacks[165] = Marshal.GetFunctionPointerForDelegate(d165);
delegates[165] = d165;
var d166 = new __getRelocTypeHint(_getRelocTypeHint);
var d166 = new __recordRelocation(_recordRelocation);
callbacks[166] = Marshal.GetFunctionPointerForDelegate(d166);
delegates[166] = d166;
var d167 = new __getExpectedTargetArchitecture(_getExpectedTargetArchitecture);
var d167 = new __getRelocTypeHint(_getRelocTypeHint);
callbacks[167] = Marshal.GetFunctionPointerForDelegate(d167);
delegates[167] = d167;
var d168 = new __getJitFlags(_getJitFlags);
var d168 = new __getExpectedTargetArchitecture(_getExpectedTargetArchitecture);
callbacks[168] = Marshal.GetFunctionPointerForDelegate(d168);
delegates[168] = d168;
var d169 = new __getJitFlags(_getJitFlags);
callbacks[169] = Marshal.GetFunctionPointerForDelegate(d169);
delegates[169] = d169;

keepAlive = delegates;
return (IntPtr)callbacks;
Expand Down
Loading