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.
4
5/************************************************************************/
6/* Overall emitter control (including startup and shutdown) */
7/************************************************************************/
8
9static void emitInit();
10static void emitDone();
11
12void emitBegCG(Compiler* comp, COMP_HANDLE cmpHandle);
13void emitEndCG();
14
15void emitBegFN(bool hasFramePtr
16#if defined(DEBUG)
17 ,
18 bool checkAlign
19#endif
20 ,
21 unsigned maxTmpSize);
22
23void emitEndFN();
24
25void emitComputeCodeSizes();
26
27unsigned emitEndCodeGen(Compiler* comp,
28 bool contTrkPtrLcls,
29 bool fullyInt,
30 bool fullPtrMap,
31 bool returnsGCr,
32 unsigned xcptnsCount,
33 unsigned* prologSize,
34 unsigned* epilogSize,
35 void** codeAddr,
36 void** coldCodeAddr,
37 void** consAddr);
38
39/************************************************************************/
40/* Method prolog and epilog */
41/************************************************************************/
42
43unsigned emitGetEpilogCnt();
44
45template <typename Callback>
46bool emitGenNoGCLst(Callback& cb);
47
48void emitBegProlog();
49unsigned emitGetPrologOffsetEstimate();
50void emitMarkPrologEnd();
51void emitEndProlog();
52
53void emitCreatePlaceholderIG(insGroupPlaceholderType igType,
54 BasicBlock* igBB,
55 VARSET_VALARG_TP GCvars,
56 regMaskTP gcrefRegs,
57 regMaskTP byrefRegs,
58 bool last);
59
60void emitGeneratePrologEpilog();
61void emitStartPrologEpilogGeneration();
62void emitFinishPrologEpilogGeneration();
63
64/************************************************************************/
65/* Record a code position and later convert it to offset */
66/************************************************************************/
67
68void* emitCurBlock();
69unsigned emitCurOffset();
70
71UNATIVE_OFFSET emitCodeOffset(void* blockPtr, unsigned codeOffs);
72
73#ifdef DEBUG
74const char* emitOffsetToLabel(unsigned offs);
75#endif // DEBUG
76
77/************************************************************************/
78/* Output target-independent instructions */
79/************************************************************************/
80
81void emitIns_J(instruction ins, BasicBlock* dst, int instrCount = 0);
82
83/************************************************************************/
84/* Emit initialized data sections */
85/************************************************************************/
86
87UNATIVE_OFFSET emitDataGenBeg(UNATIVE_OFFSET size, bool dblAlign, bool codeLtab);
88
89UNATIVE_OFFSET emitBBTableDataGenBeg(unsigned numEntries, bool relativeAddr);
90
91void emitDataGenData(unsigned offs, const void* data, size_t size);
92
93void emitDataGenData(unsigned offs, BasicBlock* label);
94
95void emitDataGenEnd();
96
97UNATIVE_OFFSET emitDataConst(const void* cnsAddr, unsigned cnsSize, bool dblAlign);
98
99UNATIVE_OFFSET emitDataSize();
100
101/************************************************************************/
102/* Instruction information */
103/************************************************************************/
104
105#ifdef _TARGET_XARCH_
106static bool instrIs3opImul(instruction ins);
107static bool instrIsExtendedReg3opImul(instruction ins);
108static bool instrHasImplicitRegPairDest(instruction ins);
109static void check3opImulValues();
110static regNumber inst3opImulReg(instruction ins);
111static instruction inst3opImulForReg(regNumber reg);
112#endif
113
114/************************************************************************/
115/* Emit PDB offset translation information */
116/************************************************************************/
117
118#ifdef TRANSLATE_PDB
119
120static void SetILBaseOfCode(BYTE* pTextBase);
121static void SetILMethodBase(BYTE* pMethodEntry);
122static void SetILMethodStart(BYTE* pMethodCode);
123static void SetImgBaseOfCode(BYTE* pTextBase);
124
125void SetIDBaseToProlog();
126void SetIDBaseToOffset(int methodOffset);
127
128static void DisablePDBTranslation();
129static bool IsPDBEnabled();
130
131static void InitTranslationMaps(int ilCodeSize);
132static void DeleteTranslationMaps();
133static void InitTranslator(PDBRewriter* pPDB, int* rgSecMap, IMAGE_SECTION_HEADER** rgpHeader, int numSections);
134#endif
135
136/************************************************************************/
137/* Interface for generating unwind information */
138/************************************************************************/
139
140#ifdef _TARGET_ARMARCH_
141
142bool emitIsFuncEnd(emitLocation* emitLoc, emitLocation* emitLocNextFragment = NULL);
143
144void emitSplit(emitLocation* startLoc,
145 emitLocation* endLoc,
146 UNATIVE_OFFSET maxSplitSize,
147 void* context,
148 emitSplitCallbackType callbackFunc);
149
150void emitUnwindNopPadding(emitLocation* locFrom, Compiler* comp);
151
152#endif // _TARGET_ARMARCH_
153
154#if defined(_TARGET_ARM_)
155
156unsigned emitGetInstructionSize(emitLocation* emitLoc);
157
158#endif // defined(_TARGET_ARM_)
159