-
Notifications
You must be signed in to change notification settings - Fork 397
/
Copy pathOMRMachine.hpp
329 lines (254 loc) · 13 KB
/
OMRMachine.hpp
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/*******************************************************************************
* Copyright (c) 2000, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at http://eclipse.org/legal/epl-2.0
* or the Apache License, Version 2.0 which accompanies this distribution
* and is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License, v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception [1] and GNU General Public
* License, version 2 with the OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] http://openjdk.java.net/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
*******************************************************************************/
#ifndef OMR_X86_MACHINE_INCL
#define OMR_X86_MACHINE_INCL
#ifndef OMR_MACHINE_CONNECTOR
#define OMR_MACHINE_CONNECTOR
namespace OMR { namespace X86 { class Machine; } }
namespace OMR { typedef OMR::X86::Machine MachineConnector; }
#endif
#include "compiler/codegen/OMRMachine.hpp"
#include <stdint.h>
#include <string.h>
#include "codegen/RealRegister.hpp"
#include "codegen/Register.hpp"
#include "codegen/RegisterConstants.hpp"
#include "env/FilePointerDecl.hpp"
#include "env/TRMemory.hpp"
#include "il/DataTypes.hpp"
#include "infra/Assert.hpp"
#include "x/codegen/X86Ops.hpp"
#include "x/codegen/X86Register.hpp"
#include "infra/TRlist.hpp"
class TR_BackingStore;
class TR_Debug;
class TR_FrontEnd;
class TR_OutlinedInstructions;
namespace OMR { class RegisterUsage; }
namespace TR { class CodeGenerator; }
namespace TR { class Instruction; }
namespace TR { class Machine; }
namespace TR { class MemoryReference; }
namespace TR { class Node; }
namespace TR { class RegisterDependencyConditions; }
namespace TR { class SymbolReference; }
namespace TR { struct X86LinkageProperties; }
template <typename ListKind> class List;
// Encapsulates the state of the register assigner at a particular point
// during assignment. Includes the state of the register file and all
// live registers.
//
// This does not capture X87 state.
//
class TR_RegisterAssignerState
{
TR::Machine *_machine;
TR::RealRegister **_registerFile;
TR::Register **_registerAssociations;
TR::list<TR::Register*> *_spilledRegistersList;
public:
TR_ALLOC(TR_Memory::Machine)
TR_RegisterAssignerState(TR::Machine *m) :
_machine(m),
_registerFile(NULL),
_registerAssociations(NULL),
_spilledRegistersList(NULL) {}
void capture();
void install();
TR::RegisterDependencyConditions *createDependenciesFromRegisterState(TR_OutlinedInstructions *oi);
bool isLive(TR::Register *virtReg);
void dump();
};
namespace OMR
{
namespace X86
{
class OMR_EXTENSIBLE Machine : public OMR::Machine
{
TR::Register **_registerAssociations;
/**
* Number of general purpose registers
*/
int8_t _numGPRs;
// Floating point stack pseudo-registers: they can be mapped to real
// registers on demand, based on their relative position from the top of
// stack marker.
//
TR_X86FPStackRegister *_fpStack[TR_X86FPStackRegister::NumRegisters];
TR_X86FPStackRegister *_fpRegisters[TR_X86FPStackRegister::NumRegisters];
TR_X86FPStackRegister *_copiedFpRegisters[TR_X86FPStackRegister::NumRegisters];
TR::Node *_fpRegisterNodes[TR_X86FPStackRegister::NumRegisters];
TR::Register **_xmmGlobalRegisters;
List<TR::Register> *_spilledRegistersList;
TR::SymbolReference *_dummyLocal[TR::NumTypes];
int32_t _fpStackShape[TR_X86FPStackRegister::NumRegisters];
int32_t _fpTopOfStack;
void initializeFPStackRegisterFile();
protected:
uint32_t *_globalRegisterNumberToRealRegisterMap;
public:
void initializeRegisterFile(const struct TR::X86LinkageProperties&);
uint32_t* getGlobalRegisterTable(const struct TR::X86LinkageProperties&);
int32_t getGlobalReg(TR::RealRegister::RegNum reg);
uint8_t getNumberOfGPRs() { return _numGPRs; }
TR::RealRegister **captureRegisterFile();
void installRegisterFile(TR::RealRegister **registerFileCopy);
TR::Register **captureRegisterAssociations();
TR::list<TR::Register*> *captureSpilledRegistersList();
void purgeDeadRegistersFromRegisterFile();
void adjustRegisterUseCountsUp(TR::list<OMR::RegisterUsage *> *rul, bool adjustFuture);
void adjustRegisterUseCountsDown(TR::list<OMR::RegisterUsage *> *rul, bool adjustFuture);
void disassociateUnspilledBackingStorage();
TR::Register **getRegisterAssociations() { return _registerAssociations; }
void setRegisterAssociations(TR::Register **ra) { _registerAssociations = ra; }
TR::Register *getVirtualAssociatedWithReal(TR::RealRegister::RegNum regNum)
{
return _registerAssociations[regNum];
}
TR::Register *setVirtualAssociatedWithReal(TR::RealRegister::RegNum regNum, TR::Register *virtReg)
{
return (_registerAssociations[regNum] = virtReg);
}
List<TR::Register> *getSpilledRegistersList() { return _spilledRegistersList; }
void setSpilledRegistersList(List<TR::Register> *srl) { _spilledRegistersList = srl; }
TR::RealRegister *findBestFreeGPRegister(TR::Instruction *currentInstruction,
TR::Register *virtReg,
TR_RegisterSizes requestedRegSize = TR_WordReg,
bool considerUnlatched = false);
TR::RealRegister *freeBestGPRegister(TR::Instruction *currentInstruction,
TR::Register *virtReg,
TR_RegisterSizes requestedRegSize = TR_WordReg,
TR::RealRegister::RegNum targetRegister = TR::RealRegister::NoReg,
bool considerVirtAsSpillCandidate = false);
TR::RealRegister *reverseGPRSpillState(TR::Instruction *currentInstruction,
TR::Register *spilledRegister,
TR::RealRegister *targetRegister = NULL,
TR_RegisterSizes requestedRegSize = TR_WordReg);
void coerceXMMRegisterAssignment(TR::Instruction *currentInstruction,
TR::Register *virtualRegister,
TR::RealRegister::RegNum registerNumber,
bool coerceToSatisfyRegDeps = false);
void coerceGPRegisterAssignment(TR::Instruction *currentInstruction,
TR::Register *virtualRegister,
TR::RealRegister::RegNum registerNumber,
bool coerceToSatisfyRegDeps = false);
void coerceGPRegisterAssignment(TR::Instruction *currentInstruction,
TR::Register *virtualRegister,
TR_RegisterSizes requestedRegSize = TR_WordReg);
void swapGPRegisters(TR::Instruction *currentInstruction,
TR::RealRegister::RegNum regNum1,
TR::RealRegister::RegNum regNum2);
void clearRegisterAssociations()
{
memset(_registerAssociations, 0, sizeof(TR::Register *) * TR::RealRegister::NumRegisters);
}
void setGPRWeightsFromAssociations();
void createRegisterAssociationDirective(TR::Instruction *cursor);
//
// Methods to support the IA32 floating point register stack.
//
TR_X86OpCodes fpDeterminePopOpCode(TR_X86OpCodes op);
TR_X86OpCodes fpDetermineReverseOpCode(TR_X86OpCodes op);
TR::MemoryReference *getDummyLocalMR(TR::DataType dt);
TR::RealRegister *fpMapToStackRelativeRegister(TR::Register *vreg);
TR::RealRegister *fpMapToStackRelativeRegister(int32_t stackReg)
{
return _registerFile[stackReg + TR::RealRegister::FirstFPR];
}
int32_t getFPTopOfStack() {return _fpTopOfStack;}
TR_X86FPStackRegister *getFPTopOfStackPtr() {return (_fpTopOfStack > TR_X86FPStackRegister::fpStackEmpty &&
_fpTopOfStack < TR_X86FPStackRegister::fpStackFull) ?
_fpStack[_fpTopOfStack] : NULL; }
TR_X86FPStackRegister *getFPStackLocationPtr(int32_t location) {return (location > TR_X86FPStackRegister::fpStackEmpty &&
location < TR_X86FPStackRegister::fpStackFull) ?
_fpStack[location] : NULL; }
void setFPTopOfStack(TR::Register *vreg);
bool isFPStackFull() { return (_fpTopOfStack+1 == TR_X86FPStackRegister::fpStackFull) ? true : false; }
bool isFPRTopOfStack(TR::Register *virtReg);
uint8_t fpGetNumberOfLiveFPRs() {return _fpTopOfStack+1;}
uint8_t fpGetNumberOfLiveXMMRs() {return 0;}
TR_X86FPStackRegister *getFPStackRegister(int32_t location) {return _fpRegisters[location];}
void setFPStackRegister(int32_t location, TR_X86FPStackRegister *reg) {_fpRegisters[location] = reg; }
TR_X86FPStackRegister *getCopiedFPStackRegister(int32_t location) {return _copiedFpRegisters[location];}
void setCopiedFPStackRegister(int32_t location, TR_X86FPStackRegister *reg) {_copiedFpRegisters[location] = reg; }
TR::Node *getFPStackRegisterNode(int32_t location) {return _fpRegisterNodes[location];}
void setFPStackRegisterNode(int32_t location, TR::Node *node) {_fpRegisterNodes[location] = node; }
void resetFPStackRegisters();
int32_t *getFPStackShape() {return _fpStackShape;}
void fpStackPush(TR::Register *virtReg);
void fpStackCoerce(TR::Register *virtReg, int32_t location);
TR::Register *fpStackPop();
void popEntireStack();
TR::Instruction *fpStackFXCH(TR::Instruction *currentInstruction,
TR::Register *virtReg,
bool generateCode = true);
TR::Instruction *fpStackFXCH(TR::Instruction *currentInstruction,
int32_t stackReg);
void fpCoerceRegistersToTopOfStack(TR::Instruction *currentInstruction,
TR::Register *X,
TR::Register *Y,
bool strict);
TR_X86FPStackRegister *findFreeFPRegister();
TR::Instruction *freeBestFPRegister(TR::Instruction *);
TR::Instruction *reverseFPRSpillState(TR::Instruction *currentInstruction,
TR::Register *spilledRegister);
TR::Instruction *fpSpillFPR(TR::Instruction *precedingInstruction,
TR::Register *vreg);
TR::Instruction *fpSpillStack(TR::Instruction *precedingInstruction);
TR::Register *getXMMGlobalRegister(int32_t regNum) {return _xmmGlobalRegisters[regNum];}
void setXMMGlobalRegister(int32_t regNum, TR::Register *reg) {_xmmGlobalRegisters[regNum] = reg;}
void resetXMMGlobalRegisters();
TR_Debug *getDebug();
uint8_t _numGlobalGPRs, _numGlobal8BitGPRs, _numGlobalFPRs;
// TODO:AMD64: Are these two still correct? What are they?
uint8_t getGlobalGPRPartitionLimit() {return 2;}
uint8_t getGlobalFPRPartitionLimit() {return 0;}
TR_GlobalRegisterNumber getNumGlobalGPRs()
{return _numGlobalGPRs;}
TR_GlobalRegisterNumber getLastGlobalGPRRegisterNumber()
{return _numGlobalGPRs - 1;}
TR_GlobalRegisterNumber getLast8BitGlobalGPRRegisterNumber()
{return _numGlobal8BitGPRs - 1;}
TR_GlobalRegisterNumber getLastGlobalFPRRegisterNumber()
{return _numGlobalGPRs + _numGlobalFPRs - 1;}
TR::RegisterDependencyConditions *createDepCondForLiveGPRs();
TR::RegisterDependencyConditions *createCondForLiveAndSpilledGPRs(TR::list<TR::Register*> *spilledRegisterList = NULL);
#if defined(DEBUG)
void printGPRegisterStatus(TR_FrontEnd *, TR::RealRegister **registerFile, TR::FILE *pOutFile);
void printFPRegisterStatus(TR_FrontEnd *, TR::FILE *pOutFile);
#endif
protected:
Machine
(
uint8_t numIntRegs,
uint8_t numFPRegs,
TR::CodeGenerator *cg,
TR::Register **registerAssociations,
uint8_t numGlobalGPRs,
uint8_t numGlobal8BitGPRs,
uint8_t numGlobalFPRs,
TR::Register **xmmGlobalRegisters,
uint32_t *globalRegisterNumberToRealRegisterMap
);
};
}
}
#endif