summaryrefslogtreecommitdiff
path: root/src/jit/ee_il_dll.hpp
blob: 3899d9219291803526b85b1c4b7e8808bb394165 (plain)
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

extern ICorJitHost* g_jitHost;

class CILJit : public ICorJitCompiler
{
    CorJitResult __stdcall compileMethod(ICorJitInfo*         comp,            /* IN */
                                         CORINFO_METHOD_INFO* methodInfo,      /* IN */
                                         unsigned             flags,           /* IN */
                                         BYTE**               nativeEntry,     /* OUT */
                                         ULONG*               nativeSizeOfCode /* OUT */
                                         );

    void clearCache(void);
    BOOL isCacheCleanupRequired(void);

    void ProcessShutdownWork(ICorStaticInfo* statInfo);

    void getVersionIdentifier(GUID* versionIdentifier /* OUT */
                              );

#if COR_JIT_EE_VERSION > 460
    unsigned getMaxIntrinsicSIMDVectorLength(CORJIT_FLAGS cpuCompileFlags);
#else
    unsigned getMaxIntrinsicSIMDVectorLength(DWORD cpuCompileFlags);
#endif

    void setRealJit(ICorJitCompiler* realJitCompiler);
};

/*****************************************************************************
 *
 *              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
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));
}

/*****************************************************************************
 *
 *                  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_CHAR,   // CORINFO_TYPE_CHAR            = 0x3,
        TYP_BYTE,   // CORINFO_TYPE_BYTE            = 0x4,
        TYP_UBYTE,  // CORINFO_TYPE_UBYTE           = 0x5,
        TYP_SHORT,  // CORINFO_TYPE_SHORT           = 0x6,
        TYP_CHAR,   // 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]);
};

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;
}