forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathee_il_dll.hpp
More file actions
304 lines (257 loc) · 12 KB
/
Copy pathee_il_dll.hpp
File metadata and controls
304 lines (257 loc) · 12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
extern ICorJitHost* g_jitHost;
class CILJit : public ICorJitCompiler
{
CorJitResult compileMethod(ICorJitInfo* comp, /* IN */
CORINFO_METHOD_INFO* methodInfo, /* IN */
unsigned flags, /* IN */
uint8_t** nativeEntry, /* OUT */
uint32_t* nativeSizeOfCode /* OUT */
);
void ProcessShutdownWork(ICorStaticInfo* statInfo);
void getVersionIdentifier(GUID* versionIdentifier /* OUT */
);
unsigned getMaxIntrinsicSIMDVectorLength(CORJIT_FLAGS cpuCompileFlags);
void setTargetOS(CORINFO_OS os);
};
/*****************************************************************************
*
* Functions to get various handles
*/
FORCEINLINE
void Compiler::eeGetCallInfo(CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_RESOLVED_TOKEN* pConstrainedToken,
CORINFO_CALLINFO_FLAGS flags,
CORINFO_CALL_INFO* pResult)
{
info.compCompHnd->getCallInfo(pResolvedToken, pConstrainedToken, info.compMethodHnd, flags, pResult);
}
FORCEINLINE
void Compiler::eeGetFieldInfo(CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_ACCESS_FLAGS accessFlags,
CORINFO_FIELD_INFO* pResult)
{
info.compCompHnd->getFieldInfo(pResolvedToken, info.compMethodHnd, accessFlags, pResult);
}
/*****************************************************************************
*
* VOS info, method sigs, etc
*/
FORCEINLINE
bool Compiler::eeIsValueClass(CORINFO_CLASS_HANDLE clsHnd)
{
return info.compCompHnd->isValueClass(clsHnd);
}
FORCEINLINE
bool Compiler::eeIsJitIntrinsic(CORINFO_METHOD_HANDLE ftn)
{
return info.compCompHnd->isJitIntrinsic(ftn);
}
FORCEINLINE
bool Compiler::eeIsFieldStatic(CORINFO_FIELD_HANDLE fldHnd)
{
return info.compCompHnd->isFieldStatic(fldHnd);
}
FORCEINLINE
var_types Compiler::eeGetFieldType(CORINFO_FIELD_HANDLE fldHnd, CORINFO_CLASS_HANDLE* pStructHnd)
{
return JITtype2varType(info.compCompHnd->getFieldType(fldHnd, pStructHnd));
}
FORCEINLINE
void Compiler::eeGetSig(unsigned sigTok,
CORINFO_MODULE_HANDLE scope,
CORINFO_CONTEXT_HANDLE context,
CORINFO_SIG_INFO* retSig)
{
info.compCompHnd->findSig(scope, sigTok, context, retSig);
assert(!varTypeIsComposite(JITtype2varType(retSig->retType)) || retSig->retTypeClass != nullptr);
}
FORCEINLINE
void Compiler::eeGetMethodSig(CORINFO_METHOD_HANDLE methHnd, CORINFO_SIG_INFO* sigRet, CORINFO_CLASS_HANDLE owner)
{
info.compCompHnd->getMethodSig(methHnd, sigRet, owner);
assert(!varTypeIsComposite(JITtype2varType(sigRet->retType)) || sigRet->retTypeClass != nullptr);
}
/**********************************************************************
* For varargs we need the number of arguments at the call site
*/
FORCEINLINE
void Compiler::eeGetCallSiteSig(unsigned sigTok,
CORINFO_MODULE_HANDLE scope,
CORINFO_CONTEXT_HANDLE context,
CORINFO_SIG_INFO* sigRet)
{
info.compCompHnd->findCallSiteSig(scope, sigTok, context, sigRet);
assert(!varTypeIsComposite(JITtype2varType(sigRet->retType)) || sigRet->retTypeClass != nullptr);
}
/*****************************************************************************/
inline var_types Compiler::eeGetArgType(CORINFO_ARG_LIST_HANDLE list, CORINFO_SIG_INFO* sig)
{
CORINFO_CLASS_HANDLE argClass;
return (JITtype2varType(strip(info.compCompHnd->getArgType(sig, list, &argClass))));
}
/*****************************************************************************/
inline var_types Compiler::eeGetArgType(CORINFO_ARG_LIST_HANDLE list, CORINFO_SIG_INFO* sig, bool* isPinned)
{
CORINFO_CLASS_HANDLE argClass;
CorInfoTypeWithMod type = info.compCompHnd->getArgType(sig, list, &argClass);
*isPinned = ((type & ~CORINFO_TYPE_MASK) != 0);
return JITtype2varType(strip(type));
}
/*****************************************************************************/
inline CORINFO_CLASS_HANDLE Compiler::eeGetArgClass(CORINFO_SIG_INFO* sig, CORINFO_ARG_LIST_HANDLE list)
{
CORINFO_CLASS_HANDLE argClass = info.compCompHnd->getArgClass(sig, list);
return argClass;
}
/*****************************************************************************/
inline CORINFO_CLASS_HANDLE Compiler::eeGetClassFromContext(CORINFO_CONTEXT_HANDLE context)
{
if (context == METHOD_BEING_COMPILED_CONTEXT())
{
return impInlineRoot()->info.compClassHnd;
}
if (((SIZE_T)context & CORINFO_CONTEXTFLAGS_MASK) == CORINFO_CONTEXTFLAGS_CLASS)
{
return CORINFO_CLASS_HANDLE((SIZE_T)context & ~CORINFO_CONTEXTFLAGS_MASK);
}
else
{
return info.compCompHnd->getMethodClass(CORINFO_METHOD_HANDLE((SIZE_T)context & ~CORINFO_CONTEXTFLAGS_MASK));
}
}
/*****************************************************************************
*
* Native Direct Optimizations
*/
inline CORINFO_EE_INFO* Compiler::eeGetEEInfo()
{
if (!eeInfoInitialized)
{
info.compCompHnd->getEEInfo(&eeInfo);
eeInfoInitialized = true;
}
return &eeInfo;
}
/*****************************************************************************
*
* Convert the type returned from the VM to a var_type.
*/
inline var_types JITtype2varType(CorInfoType type)
{
static const unsigned char varTypeMap[CORINFO_TYPE_COUNT] = {
// see the definition of enum CorInfoType in file inc/corinfo.h
TYP_UNDEF, // CORINFO_TYPE_UNDEF = 0x0,
TYP_VOID, // CORINFO_TYPE_VOID = 0x1,
TYP_BOOL, // CORINFO_TYPE_BOOL = 0x2,
TYP_USHORT, // CORINFO_TYPE_CHAR = 0x3,
TYP_BYTE, // CORINFO_TYPE_BYTE = 0x4,
TYP_UBYTE, // CORINFO_TYPE_UBYTE = 0x5,
TYP_SHORT, // CORINFO_TYPE_SHORT = 0x6,
TYP_USHORT, // CORINFO_TYPE_USHORT = 0x7,
TYP_INT, // CORINFO_TYPE_INT = 0x8,
TYP_INT, // CORINFO_TYPE_UINT = 0x9,
TYP_LONG, // CORINFO_TYPE_LONG = 0xa,
TYP_LONG, // CORINFO_TYPE_ULONG = 0xb,
TYP_I_IMPL, // CORINFO_TYPE_NATIVEINT = 0xc,
TYP_I_IMPL, // CORINFO_TYPE_NATIVEUINT = 0xd,
TYP_FLOAT, // CORINFO_TYPE_FLOAT = 0xe,
TYP_DOUBLE, // CORINFO_TYPE_DOUBLE = 0xf,
TYP_REF, // CORINFO_TYPE_STRING = 0x10, // Not used, should remove
TYP_I_IMPL, // CORINFO_TYPE_PTR = 0x11,
TYP_BYREF, // CORINFO_TYPE_BYREF = 0x12,
TYP_STRUCT, // CORINFO_TYPE_VALUECLASS = 0x13,
TYP_REF, // CORINFO_TYPE_CLASS = 0x14,
TYP_STRUCT, // CORINFO_TYPE_REFANY = 0x15,
// Generic type variables only appear when we're doing
// verification of generic code, in which case we're running
// in "import only" mode. Annoyingly the "import only"
// mode of the JIT actually does a fair bit of compilation,
// so we have to trick the compiler into thinking it's compiling
// a real instantiation. We do that by just pretending we're
// compiling the "object" instantiation of the code, i.e. by
// turing all generic type variables refs, except for a few
// choice places to do with verification, where we use
// verification types and CLASS_HANDLEs to track the difference.
TYP_REF, // CORINFO_TYPE_VAR = 0x16,
};
// spot check to make certain enumerations have not changed
assert(varTypeMap[CORINFO_TYPE_CLASS] == TYP_REF);
assert(varTypeMap[CORINFO_TYPE_BYREF] == TYP_BYREF);
assert(varTypeMap[CORINFO_TYPE_PTR] == TYP_I_IMPL);
assert(varTypeMap[CORINFO_TYPE_INT] == TYP_INT);
assert(varTypeMap[CORINFO_TYPE_UINT] == TYP_INT);
assert(varTypeMap[CORINFO_TYPE_DOUBLE] == TYP_DOUBLE);
assert(varTypeMap[CORINFO_TYPE_VOID] == TYP_VOID);
assert(varTypeMap[CORINFO_TYPE_VALUECLASS] == TYP_STRUCT);
assert(varTypeMap[CORINFO_TYPE_REFANY] == TYP_STRUCT);
assert(type < CORINFO_TYPE_COUNT);
assert(varTypeMap[type] != TYP_UNDEF);
return ((var_types)varTypeMap[type]);
};
// Convert the type returned from the VM to a precise var_type
inline var_types JitType2PreciseVarType(CorInfoType type)
{
static const unsigned char preciseVarTypeMap[CORINFO_TYPE_COUNT] = {
// see the definition of enum CorInfoType in file inc/corinfo.h
TYP_UNDEF, // CORINFO_TYPE_UNDEF = 0x0,
TYP_VOID, // CORINFO_TYPE_VOID = 0x1,
TYP_BOOL, // CORINFO_TYPE_BOOL = 0x2,
TYP_USHORT, // CORINFO_TYPE_CHAR = 0x3,
TYP_BYTE, // CORINFO_TYPE_BYTE = 0x4,
TYP_UBYTE, // CORINFO_TYPE_UBYTE = 0x5,
TYP_SHORT, // CORINFO_TYPE_SHORT = 0x6,
TYP_USHORT, // CORINFO_TYPE_USHORT = 0x7,
TYP_INT, // CORINFO_TYPE_INT = 0x8,
TYP_UINT, // CORINFO_TYPE_UINT = 0x9,
TYP_LONG, // CORINFO_TYPE_LONG = 0xa,
TYP_ULONG, // CORINFO_TYPE_ULONG = 0xb,
TYP_I_IMPL, // CORINFO_TYPE_NATIVEINT = 0xc,
TYP_U_IMPL, // CORINFO_TYPE_NATIVEUINT = 0xd,
TYP_FLOAT, // CORINFO_TYPE_FLOAT = 0xe,
TYP_DOUBLE, // CORINFO_TYPE_DOUBLE = 0xf,
TYP_REF, // CORINFO_TYPE_STRING = 0x10, // Not used, should remove
TYP_U_IMPL, // CORINFO_TYPE_PTR = 0x11,
TYP_BYREF, // CORINFO_TYPE_BYREF = 0x12,
TYP_STRUCT, // CORINFO_TYPE_VALUECLASS = 0x13,
TYP_REF, // CORINFO_TYPE_CLASS = 0x14,
TYP_STRUCT, // CORINFO_TYPE_REFANY = 0x15,
// Generic type variables only appear when we're doing
// verification of generic code, in which case we're running
// in "import only" mode. Annoyingly the "import only"
// mode of the JIT actually does a fair bit of compilation,
// so we have to trick the compiler into thinking it's compiling
// a real instantiation. We do that by just pretending we're
// compiling the "object" instantiation of the code, i.e. by
// turing all generic type variables refs, except for a few
// choice places to do with verification, where we use
// verification types and CLASS_HANDLEs to track the difference.
TYP_REF, // CORINFO_TYPE_VAR = 0x16,
};
// spot check to make certain enumerations have not changed
assert(preciseVarTypeMap[CORINFO_TYPE_CLASS] == TYP_REF);
assert(preciseVarTypeMap[CORINFO_TYPE_BYREF] == TYP_BYREF);
assert(preciseVarTypeMap[CORINFO_TYPE_PTR] == TYP_U_IMPL);
assert(preciseVarTypeMap[CORINFO_TYPE_INT] == TYP_INT);
assert(preciseVarTypeMap[CORINFO_TYPE_UINT] == TYP_UINT);
assert(preciseVarTypeMap[CORINFO_TYPE_DOUBLE] == TYP_DOUBLE);
assert(preciseVarTypeMap[CORINFO_TYPE_VOID] == TYP_VOID);
assert(preciseVarTypeMap[CORINFO_TYPE_VALUECLASS] == TYP_STRUCT);
assert(preciseVarTypeMap[CORINFO_TYPE_REFANY] == TYP_STRUCT);
assert(type < CORINFO_TYPE_COUNT);
assert(preciseVarTypeMap[type] != TYP_UNDEF);
return ((var_types)preciseVarTypeMap[type]);
};
inline CORINFO_CALLINFO_FLAGS combine(CORINFO_CALLINFO_FLAGS flag1, CORINFO_CALLINFO_FLAGS flag2)
{
return (CORINFO_CALLINFO_FLAGS)(flag1 | flag2);
}
inline CORINFO_CALLINFO_FLAGS Compiler::addVerifyFlag(CORINFO_CALLINFO_FLAGS flags)
{
if (tiVerificationNeeded)
{
flags = combine(flags, CORINFO_CALLINFO_VERIFICATION);
}
return flags;
}