summaryrefslogtreecommitdiff
path: root/src/jit/emitpub.h
blob: a2f041a5f3cf86dec9ada16c5b53739ec6c3cd76 (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
// 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.

/************************************************************************/
/*       Overall emitter control (including startup and shutdown)       */
/************************************************************************/

static void emitInit();
static void emitDone();

void emitBegCG(Compiler* comp, COMP_HANDLE cmpHandle);
void emitEndCG();

void emitBegFN(bool hasFramePtr
#if defined(DEBUG)
               ,
               bool checkAlign
#endif
#ifdef LEGACY_BACKEND
               ,
               unsigned lclSize
#endif // LEGACY_BACKEND
               ,
               unsigned maxTmpSize);

void emitEndFN();

void emitComputeCodeSizes();

unsigned emitEndCodeGen(Compiler* comp,
                        bool      contTrkPtrLcls,
                        bool      fullyInt,
                        bool      fullPtrMap,
                        bool      returnsGCr,
                        unsigned  xcptnsCount,
                        unsigned* prologSize,
                        unsigned* epilogSize,
                        void**    codeAddr,
                        void**    coldCodeAddr,
                        void**    consAddr);

/************************************************************************/
/*                      Method prolog and epilog                        */
/************************************************************************/

unsigned emitGetEpilogCnt();

template <typename Callback>
bool emitGenNoGCLst(Callback& cb);

void     emitBegProlog();
unsigned emitGetPrologOffsetEstimate();
void     emitMarkPrologEnd();
void     emitEndProlog();

void emitCreatePlaceholderIG(insGroupPlaceholderType igType,
                             BasicBlock*             igBB,
                             VARSET_VALARG_TP        GCvars,
                             regMaskTP               gcrefRegs,
                             regMaskTP               byrefRegs,
                             bool                    last);

void emitGeneratePrologEpilog();
void emitStartPrologEpilogGeneration();
void emitFinishPrologEpilogGeneration();

/************************************************************************/
/*           Record a code position and later convert it to offset      */
/************************************************************************/

void*    emitCurBlock();
unsigned emitCurOffset();

UNATIVE_OFFSET emitCodeOffset(void* blockPtr, unsigned codeOffs);

#ifdef DEBUG
const char* emitOffsetToLabel(unsigned offs);
#endif // DEBUG

/************************************************************************/
/*                   Output target-independent instructions             */
/************************************************************************/

void emitIns_J(instruction ins, BasicBlock* dst, int instrCount = 0);

/************************************************************************/
/*                   Emit initialized data sections                     */
/************************************************************************/

UNATIVE_OFFSET emitDataGenBeg(UNATIVE_OFFSET size, bool dblAlign, bool codeLtab);

UNATIVE_OFFSET emitBBTableDataGenBeg(unsigned numEntries, bool relativeAddr);

void emitDataGenData(unsigned offs, const void* data, size_t size);

void emitDataGenData(unsigned offs, BasicBlock* label);

void emitDataGenEnd();

UNATIVE_OFFSET emitDataConst(const void* cnsAddr, unsigned cnsSize, bool dblAlign);

UNATIVE_OFFSET emitDataSize();

/************************************************************************/
/*                   Instruction information                            */
/************************************************************************/

#ifdef _TARGET_XARCH_
static bool instrIs3opImul(instruction ins);
static bool instrIsExtendedReg3opImul(instruction ins);
static bool instrHasImplicitRegPairDest(instruction ins);
static void      check3opImulValues();
static regNumber inst3opImulReg(instruction ins);
static instruction inst3opImulForReg(regNumber reg);
#endif

/************************************************************************/
/*                   Emit PDB offset translation information            */
/************************************************************************/

#ifdef TRANSLATE_PDB

static void SetILBaseOfCode(BYTE* pTextBase);
static void SetILMethodBase(BYTE* pMethodEntry);
static void SetILMethodStart(BYTE* pMethodCode);
static void SetImgBaseOfCode(BYTE* pTextBase);

void SetIDBaseToProlog();
void SetIDBaseToOffset(int methodOffset);

static void DisablePDBTranslation();
static bool IsPDBEnabled();

static void InitTranslationMaps(int ilCodeSize);
static void DeleteTranslationMaps();
static void InitTranslator(PDBRewriter* pPDB, int* rgSecMap, IMAGE_SECTION_HEADER** rgpHeader, int numSections);
#endif

/************************************************************************/
/*                   Interface for generating unwind information        */
/************************************************************************/

#ifdef _TARGET_ARMARCH_

bool emitIsFuncEnd(emitLocation* emitLoc, emitLocation* emitLocNextFragment = NULL);

void emitSplit(emitLocation*         startLoc,
               emitLocation*         endLoc,
               UNATIVE_OFFSET        maxSplitSize,
               void*                 context,
               emitSplitCallbackType callbackFunc);

void emitUnwindNopPadding(emitLocation* locFrom, Compiler* comp);

#endif // _TARGET_ARMARCH_

#if defined(_TARGET_ARM_)

unsigned emitGetInstructionSize(emitLocation* emitLoc);

#endif // defined(_TARGET_ARM_)