1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
5 extern ICorJitHost* g_jitHost;
7 class CILJit : public ICorJitCompiler
9 CorJitResult __stdcall compileMethod(ICorJitInfo* comp, /* IN */
10 CORINFO_METHOD_INFO* methodInfo, /* IN */
11 unsigned flags, /* IN */
12 BYTE** nativeEntry, /* OUT */
13 ULONG* nativeSizeOfCode /* OUT */
16 void clearCache(void);
17 BOOL isCacheCleanupRequired(void);
19 void ProcessShutdownWork(ICorStaticInfo* statInfo);
21 void getVersionIdentifier(GUID* versionIdentifier /* OUT */
24 unsigned getMaxIntrinsicSIMDVectorLength(CORJIT_FLAGS cpuCompileFlags);
26 void setRealJit(ICorJitCompiler* realJitCompiler);
29 /*****************************************************************************
31 * Functions to get various handles
35 void Compiler::eeGetCallInfo(CORINFO_RESOLVED_TOKEN* pResolvedToken,
36 CORINFO_RESOLVED_TOKEN* pConstrainedToken,
37 CORINFO_CALLINFO_FLAGS flags,
38 CORINFO_CALL_INFO* pResult)
40 info.compCompHnd->getCallInfo(pResolvedToken, pConstrainedToken, info.compMethodHnd, flags, pResult);
44 void Compiler::eeGetFieldInfo(CORINFO_RESOLVED_TOKEN* pResolvedToken,
45 CORINFO_ACCESS_FLAGS accessFlags,
46 CORINFO_FIELD_INFO* pResult)
48 info.compCompHnd->getFieldInfo(pResolvedToken, info.compMethodHnd, accessFlags, pResult);
51 /*****************************************************************************
53 * VOS info, method sigs, etc
57 BOOL Compiler::eeIsValueClass(CORINFO_CLASS_HANDLE clsHnd)
59 return info.compCompHnd->isValueClass(clsHnd);
63 void Compiler::eeGetSig(unsigned sigTok,
64 CORINFO_MODULE_HANDLE scope,
65 CORINFO_CONTEXT_HANDLE context,
66 CORINFO_SIG_INFO* retSig)
68 info.compCompHnd->findSig(scope, sigTok, context, retSig);
70 assert(!varTypeIsComposite(JITtype2varType(retSig->retType)) || retSig->retTypeClass != nullptr);
74 void Compiler::eeGetMethodSig(CORINFO_METHOD_HANDLE methHnd, CORINFO_SIG_INFO* sigRet, CORINFO_CLASS_HANDLE owner)
76 info.compCompHnd->getMethodSig(methHnd, sigRet, owner);
78 assert(!varTypeIsComposite(JITtype2varType(sigRet->retType)) || sigRet->retTypeClass != nullptr);
81 /**********************************************************************
82 * For varargs we need the number of arguments at the call site
86 void Compiler::eeGetCallSiteSig(unsigned sigTok,
87 CORINFO_MODULE_HANDLE scope,
88 CORINFO_CONTEXT_HANDLE context,
89 CORINFO_SIG_INFO* sigRet)
91 info.compCompHnd->findCallSiteSig(scope, sigTok, context, sigRet);
93 assert(!varTypeIsComposite(JITtype2varType(sigRet->retType)) || sigRet->retTypeClass != nullptr);
96 /*****************************************************************************/
97 inline var_types Compiler::eeGetArgType(CORINFO_ARG_LIST_HANDLE list, CORINFO_SIG_INFO* sig)
99 CORINFO_CLASS_HANDLE argClass;
100 return (JITtype2varType(strip(info.compCompHnd->getArgType(sig, list, &argClass))));
103 /*****************************************************************************/
104 inline var_types Compiler::eeGetArgType(CORINFO_ARG_LIST_HANDLE list, CORINFO_SIG_INFO* sig, bool* isPinned)
106 CORINFO_CLASS_HANDLE argClass;
107 CorInfoTypeWithMod type = info.compCompHnd->getArgType(sig, list, &argClass);
108 *isPinned = ((type & ~CORINFO_TYPE_MASK) != 0);
109 return JITtype2varType(strip(type));
112 /*****************************************************************************
114 * Native Direct Optimizations
117 inline CORINFO_EE_INFO* Compiler::eeGetEEInfo()
119 if (!eeInfoInitialized)
121 info.compCompHnd->getEEInfo(&eeInfo);
122 eeInfoInitialized = true;
128 /*****************************************************************************
130 * Convert the type returned from the VM to a var_type.
133 inline var_types JITtype2varType(CorInfoType type)
136 static const unsigned char varTypeMap[CORINFO_TYPE_COUNT] = {
137 // see the definition of enum CorInfoType in file inc/corinfo.h
138 TYP_UNDEF, // CORINFO_TYPE_UNDEF = 0x0,
139 TYP_VOID, // CORINFO_TYPE_VOID = 0x1,
140 TYP_BOOL, // CORINFO_TYPE_BOOL = 0x2,
141 TYP_USHORT, // CORINFO_TYPE_CHAR = 0x3,
142 TYP_BYTE, // CORINFO_TYPE_BYTE = 0x4,
143 TYP_UBYTE, // CORINFO_TYPE_UBYTE = 0x5,
144 TYP_SHORT, // CORINFO_TYPE_SHORT = 0x6,
145 TYP_USHORT, // CORINFO_TYPE_USHORT = 0x7,
146 TYP_INT, // CORINFO_TYPE_INT = 0x8,
147 TYP_INT, // CORINFO_TYPE_UINT = 0x9,
148 TYP_LONG, // CORINFO_TYPE_LONG = 0xa,
149 TYP_LONG, // CORINFO_TYPE_ULONG = 0xb,
150 TYP_I_IMPL, // CORINFO_TYPE_NATIVEINT = 0xc,
151 TYP_I_IMPL, // CORINFO_TYPE_NATIVEUINT = 0xd,
152 TYP_FLOAT, // CORINFO_TYPE_FLOAT = 0xe,
153 TYP_DOUBLE, // CORINFO_TYPE_DOUBLE = 0xf,
154 TYP_REF, // CORINFO_TYPE_STRING = 0x10, // Not used, should remove
155 TYP_I_IMPL, // CORINFO_TYPE_PTR = 0x11,
156 TYP_BYREF, // CORINFO_TYPE_BYREF = 0x12,
157 TYP_STRUCT, // CORINFO_TYPE_VALUECLASS = 0x13,
158 TYP_REF, // CORINFO_TYPE_CLASS = 0x14,
159 TYP_STRUCT, // CORINFO_TYPE_REFANY = 0x15,
161 // Generic type variables only appear when we're doing
162 // verification of generic code, in which case we're running
163 // in "import only" mode. Annoyingly the "import only"
164 // mode of the JIT actually does a fair bit of compilation,
165 // so we have to trick the compiler into thinking it's compiling
166 // a real instantiation. We do that by just pretending we're
167 // compiling the "object" instantiation of the code, i.e. by
168 // turing all generic type variables refs, except for a few
169 // choice places to do with verification, where we use
170 // verification types and CLASS_HANDLEs to track the difference.
172 TYP_REF, // CORINFO_TYPE_VAR = 0x16,
175 // spot check to make certain enumerations have not changed
177 assert(varTypeMap[CORINFO_TYPE_CLASS] == TYP_REF);
178 assert(varTypeMap[CORINFO_TYPE_BYREF] == TYP_BYREF);
179 assert(varTypeMap[CORINFO_TYPE_PTR] == TYP_I_IMPL);
180 assert(varTypeMap[CORINFO_TYPE_INT] == TYP_INT);
181 assert(varTypeMap[CORINFO_TYPE_UINT] == TYP_INT);
182 assert(varTypeMap[CORINFO_TYPE_DOUBLE] == TYP_DOUBLE);
183 assert(varTypeMap[CORINFO_TYPE_VOID] == TYP_VOID);
184 assert(varTypeMap[CORINFO_TYPE_VALUECLASS] == TYP_STRUCT);
185 assert(varTypeMap[CORINFO_TYPE_REFANY] == TYP_STRUCT);
187 assert(type < CORINFO_TYPE_COUNT);
188 assert(varTypeMap[type] != TYP_UNDEF);
190 return ((var_types)varTypeMap[type]);
193 inline CORINFO_CALLINFO_FLAGS combine(CORINFO_CALLINFO_FLAGS flag1, CORINFO_CALLINFO_FLAGS flag2)
195 return (CORINFO_CALLINFO_FLAGS)(flag1 | flag2);
197 inline CORINFO_CALLINFO_FLAGS Compiler::addVerifyFlag(CORINFO_CALLINFO_FLAGS flags)
199 if (tiVerificationNeeded)
201 flags = combine(flags, CORINFO_CALLINFO_VERIFICATION);