-
Notifications
You must be signed in to change notification settings - Fork 140
/
Copy pathOMRInstruction.hpp
320 lines (257 loc) · 9.88 KB
/
OMRInstruction.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
/*******************************************************************************
* Copyright IBM Corp. and others 2000
*
* 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 https://www.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] https://openjdk.org/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
*******************************************************************************/
#ifndef OMR_INSTRUCTION_INCL
#define OMR_INSTRUCTION_INCL
/*
* The following #define and typedef must appear before any #includes in this file
*/
#ifndef OMR_INSTRUCTION_CONNECTOR
#define OMR_INSTRUCTION_CONNECTOR
namespace OMR { class Instruction; }
namespace OMR { typedef OMR::Instruction InstructionConnector; }
#endif
#include <stddef.h>
#include <stdint.h>
#include "codegen/InstOpCode.hpp"
#include "codegen/RegisterConstants.hpp"
#include "env/TRMemory.hpp"
#include "infra/Assert.hpp"
#include "infra/TRlist.hpp"
class TR_BitVector;
class TR_GCStackMap;
namespace TR { class CodeGenerator; }
namespace TR { class Instruction; }
namespace TR { class Node; }
namespace TR { class Register; }
namespace TR { class LabelSymbol; }
namespace TR { class RealRegister; }
namespace TR { class Snippet; }
#ifndef TO_MASK
#define TO_MASK(b) (1<<(uint16_t)b)
#endif
#define INSTRUCTION_INDEX_INCREMENT 32
namespace OMR
{
/**
* Instruction class
*
* OMR_EXTENSIBLE
*/
class OMR_EXTENSIBLE Instruction
{
protected:
Instruction(TR::CodeGenerator *cg, TR::InstOpCode::Mnemonic op, TR::Node *node = 0);
Instruction(TR::CodeGenerator *cg, TR::Instruction *precedingInstruction, TR::InstOpCode::Mnemonic op, TR::Node *node = 0);
public:
typedef uint32_t TCollectableReferenceMask;
inline TR::Instruction* self();
/*
* Need to move them to FE specific files once more clean up is done.
*/
virtual TR::Snippet *getSnippetForGC() { return 0; }
virtual bool isVirtualGuardNOPInstruction() { return false; }
virtual TR::LabelSymbol *getLabelSymbol() { return NULL; }
typedef uint32_t TIndex;
TR_ALLOC(TR_Memory::Instruction)
/*
* Instruction OpCodes
*/
TR::InstOpCode& getOpCode() { return _opcode; }
TR::InstOpCode::Mnemonic getOpCodeValue() { return _opcode.getMnemonic(); }
void setOpCodeValue(TR::InstOpCode::Mnemonic op) { _opcode.setMnemonic(op); }
/*
* Instruction stream links.
*/
TR::Instruction *getNext() { return _next; }
void setNext(TR::Instruction *n) { _next = n; }
TR::Instruction *getPrev() { return _prev; }
void setPrev(TR::Instruction *p) { _prev = p; }
void remove();
TR::Instruction *move(TR::Instruction *newLocation);
/*
* Address of binary buffer where this instruction was encoded. The binary buffer
* is NULL if this instruction has not been encoded yet.
*/
uint8_t *getBinaryEncoding() { return _binaryEncodingBuffer; }
void setBinaryEncoding(uint8_t *be) { _binaryEncodingBuffer = be; }
uint8_t getBinaryLength() { return _binaryLength; }
void setBinaryLength(uint8_t length) { _binaryLength = length; }
/*
* Cached estimate of an instruction's worst case length in bytes.
* Assumes that estimateBinaryLength() has been run before.
*/
uint8_t getEstimatedBinaryLength() { return _estimatedBinaryLength; }
void setEstimatedBinaryLength(uint8_t e) { _estimatedBinaryLength = e; }
/*
* Action to estimate the generated binary length of this instruction.
*/
virtual int32_t estimateBinaryLength(int32_t currentEstimate) = 0;
/*
* The minimum length in bytes this instruction could be when encoded.
*/
virtual uint8_t getBinaryLengthLowerBound() { return 0; }
/*
* Action to generate the binary representation of this instruction at
* the current buffer cursor.
*/
virtual uint8_t *generateBinaryEncoding() = 0;
/**
* @brief Expand this instruction prior to binary encoding.
*
* @returns the last instruction in the expansion or this instruction if no expansion was
* performed.
*/
virtual TR::Instruction *expandInstruction() { return self(); }
/*
* Assign the specified register kind(s) on this instruction to real registers.
*/
virtual void assignRegisters(TR_RegisterKinds kindsToBeAssigned) { return; }
/*
* Answers whether this instruction references the given virtual register.
*/
virtual bool refsRegister(TR::Register *reg) { return false; }
/*
* Answers whether this instruction defines the given virtual register.
*/
virtual bool defsRegister(TR::Register *reg) { return false; }
/*
* Answers whether this instruction uses the given virtual register.
*/
virtual bool usesRegister(TR::Register *reg) { return false; }
/*
* Answers whether a dependency condition associated with this instruction
* references the given virtual register.
*/
virtual bool dependencyRefsRegister(TR::Register *reg) { return false; }
/*
* The IR node whence this instruction was created.
*/
TR::Node *getNode() { return _node; }
void setNode(TR::Node * n) { _node = n; }
/*
* Answers whether the instruction can be included in a guard patch point
*
* @param[in] cg : CodeGenerator object
*/
virtual bool isPatchBarrier(TR::CodeGenerator *cg) { return false; }
/*
* A 24-bit value indicating an approximate ordering of instructions. Note that for an
* instruction 'I1' followed by an instruction 'I2' it is not guaranteed that
* I2.index > I1.index, though it is usually true.
*/
TIndex getIndex() { return _index & ~FlagsMask; }
void setIndex(TIndex i) { TR_ASSERT((i & FlagsMask) == 0, "instruction flags overwrite"); _index = i | (_index & FlagsMask); }
/*
* Instruction kind.
*/
enum Kind
{
#include "codegen/InstructionKindEnum.hpp"
};
virtual Kind getKind() = 0;
/*
* OMRTODO: TR specific?
*/
void useRegister(TR::Register *reg);
/*
* Cached code generator object.
* OMRTODO: should be retrievable from TLS.
*/
TR::CodeGenerator *cg() { return _cg; }
bool needsGCMap() { return (_index & TO_MASK(NeedsGCMapBit)) != 0; }
void setNeedsGCMap(TCollectableReferenceMask regMask = 0xFFFFFFFF) { _gc._GCRegisterMask = regMask; _index |= TO_MASK(NeedsGCMapBit); }
bool needsAOTRelocation() { return (_index & TO_MASK(NeedsAOTRelocation)) != 0; }
void setNeedsAOTRelocation(bool v = true) { v ? _index |= TO_MASK(NeedsAOTRelocation) : _index &= ~TO_MASK(NeedsAOTRelocation); }
/**
* @brief Indicates instruction after which binary encoding should switch to a cold cache
*
* @returns true iff instruction is a last warm instruction
*/
bool isLastWarmInstruction() { return (_index & TO_MASK(LastWarmInstruction)) != 0; }
/**
* @brief Identifies instruction as a last warm instruction.
* Instructions after that will be placed into a cold cache.
* Code that sets it is responsible for maintaining the correct value
* in case the instruction is removed or a new instruction is appended
*/
void setLastWarmInstruction(bool v = true) { v ? _index |= TO_MASK(LastWarmInstruction) : _index &= ~TO_MASK(LastWarmInstruction); }
TR_GCStackMap *getGCMap() { return _gc._GCMap; }
TR_GCStackMap *setGCMap(TR_GCStackMap *map) { return (_gc._GCMap = map); }
TCollectableReferenceMask getGCRegisterMask() { return _gc._GCRegisterMask; }
TR_BitVector *getLiveLocals() { return _liveLocals; }
TR_BitVector *setLiveLocals(TR_BitVector *v) { return (_liveLocals = v); }
TR_BitVector *getLiveMonitors() { return _liveMonitors; }
TR_BitVector *setLiveMonitors(TR_BitVector *v) { return (_liveMonitors = v); }
bool requiresAtomicPatching();
int32_t getMaxPatchableInstructionLength() { return 0; }
bool isMergeableGuard();
protected:
uint8_t *_binaryEncodingBuffer;
uint8_t _binaryLength;
uint8_t _estimatedBinaryLength;
TR::InstOpCode _opcode;
/*
* A 32-bit field where the lower 24-bits contain an integer that represents an
* approximate ordering of instructions.
*
* The upper 8 bits are available for use for flags.
*/
TIndex _index;
/*
* Instruction flags encoded by their bit position. Subclasses may use any
* available bits between FirstBaseFlag and MaxBaseFlag-1 inclusive.
*/
enum
{
// First possible bit for flags
//
FirstBaseFlag = 24,
// Last possible bit for flags
//
MaxBaseFlag = 31,
FlagsMask = 0xff000000,
BeforeFirstBaseFlag = FirstBaseFlag-1,
#include "codegen/InstructionFlagEnum.hpp"
LastBaseFlag
};
static_assert(LastBaseFlag <= MaxBaseFlag+1, "OMR::Instruction too many flag bits for flag width");
private:
Instruction() {}
TR::Instruction *_next;
TR::Instruction *_prev;
TR::Node *_node;
TR::CodeGenerator *_cg;
protected:
TR_BitVector *_liveLocals;
TR_BitVector *_liveMonitors;
union TR_GCInfo
{
TCollectableReferenceMask _GCRegisterMask;
TR_GCStackMap *_GCMap;
TR_GCInfo()
{
_GCRegisterMask = 0;
_GCMap = 0;
}
} _gc;
};
}
#endif