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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
|
//===-- llvm/CodeGen/MachineOperand.h - MachineOperand class ----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains the declaration of the MachineOperand class.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CODEGEN_MACHINEOPERAND_H
#define LLVM_CODEGEN_MACHINEOPERAND_H
#include "llvm/Support/DataTypes.h"
#include <vector>
#include <cassert>
#include <iosfwd>
namespace llvm {
class MachineBasicBlock;
class GlobalValue;
class MachineInstr;
/// MachineOperand class - Representation of each machine instruction operand.
///
class MachineOperand {
public:
enum MachineOperandType {
MO_Register, // Register operand.
MO_Immediate, // Immediate Operand
MO_MachineBasicBlock, // MachineBasicBlock reference
MO_FrameIndex, // Abstract Stack Frame Index
MO_ConstantPoolIndex, // Address of indexed Constant in Constant Pool
MO_JumpTableIndex, // Address of indexed Jump Table for switch
MO_ExternalSymbol, // Name of external global symbol
MO_GlobalAddress // Address of a global value
};
private:
union {
GlobalValue *GV; // For MO_GlobalAddress.
MachineBasicBlock *MBB; // For MO_MachineBasicBlock.
const char *SymbolName; // For MO_ExternalSymbol.
unsigned RegNo; // For MO_Register.
int64_t ImmVal; // For MO_Immediate.
int Index; // For MO_FrameIndex/CPI/JTI.
} contents;
/// ParentMI - This is the instruction that this operand is embedded into.
MachineInstr *ParentMI;
MachineOperandType opType:8; // Discriminate the union.
bool IsDef : 1; // True if this is a def, false if this is a use.
bool IsImp : 1; // True if this is an implicit def or use.
bool IsKill : 1; // True if this is a reg use and the reg is dead
// immediately after the read.
bool IsDead : 1; // True if this is a reg def and the reg is dead
// immediately after the write. i.e. A register
// that is defined but never used.
/// SubReg - Subregister number, only valid for MO_Register. A value of 0
/// indicates the MO_Register has no subReg.
unsigned char SubReg;
/// auxInfo - auxiliary information used by the MachineOperand
union {
/// offset - Offset to address of global or external, only valid for
/// MO_GlobalAddress, MO_ExternalSym and MO_ConstantPoolIndex
int offset;
} auxInfo;
MachineOperand() : ParentMI(0) {}
void print(std::ostream &os) const;
void print(std::ostream *os) const { if (os) print(*os); }
public:
MachineOperand(const MachineOperand &M) {
*this = M;
}
~MachineOperand() {}
/// getType - Returns the MachineOperandType for this operand.
///
MachineOperandType getType() const { return opType; }
/// getParent - Return the instruction that this operand belongs to.
///
MachineInstr *getParent() { return ParentMI; }
const MachineInstr *getParent() const { return ParentMI; }
/// Accessors that tell you what kind of MachineOperand you're looking at.
///
bool isRegister() const { return opType == MO_Register; }
bool isImmediate() const { return opType == MO_Immediate; }
bool isMachineBasicBlock() const { return opType == MO_MachineBasicBlock; }
bool isFrameIndex() const { return opType == MO_FrameIndex; }
bool isConstantPoolIndex() const { return opType == MO_ConstantPoolIndex; }
bool isJumpTableIndex() const { return opType == MO_JumpTableIndex; }
bool isGlobalAddress() const { return opType == MO_GlobalAddress; }
bool isExternalSymbol() const { return opType == MO_ExternalSymbol; }
int64_t getImm() const {
assert(isImmediate() && "Wrong MachineOperand accessor");
return contents.ImmVal;
}
MachineBasicBlock *getMBB() const {
assert(isMachineBasicBlock() && "Wrong MachineOperand accessor");
return contents.MBB;
}
MachineBasicBlock *getMachineBasicBlock() const {
assert(isMachineBasicBlock() && "Wrong MachineOperand accessor");
return contents.MBB;
}
void setMachineBasicBlock(MachineBasicBlock *MBB) {
assert(isMachineBasicBlock() && "Wrong MachineOperand accessor");
contents.MBB = MBB;
}
int getFrameIndex() const {
assert(isFrameIndex() && "Wrong MachineOperand accessor");
return (int)contents.Index;
}
unsigned getConstantPoolIndex() const {
assert(isConstantPoolIndex() && "Wrong MachineOperand accessor");
return (unsigned)contents.Index;
}
unsigned getJumpTableIndex() const {
assert(isJumpTableIndex() && "Wrong MachineOperand accessor");
return (unsigned)contents.Index;
}
GlobalValue *getGlobal() const {
assert(isGlobalAddress() && "Wrong MachineOperand accessor");
return contents.GV;
}
int getOffset() const {
assert((isGlobalAddress() || isExternalSymbol() || isConstantPoolIndex()) &&
"Wrong MachineOperand accessor");
return auxInfo.offset;
}
unsigned getSubReg() const {
assert(isRegister() && "Wrong MachineOperand accessor");
return (unsigned)SubReg;
}
const char *getSymbolName() const {
assert(isExternalSymbol() && "Wrong MachineOperand accessor");
return contents.SymbolName;
}
bool isUse() const {
assert(isRegister() && "Wrong MachineOperand accessor");
return !IsDef;
}
bool isDef() const {
assert(isRegister() && "Wrong MachineOperand accessor");
return IsDef;
}
void setIsUse() {
assert(isRegister() && "Wrong MachineOperand accessor");
IsDef = false;
}
void setIsDef() {
assert(isRegister() && "Wrong MachineOperand accessor");
IsDef = true;
}
bool isImplicit() const {
assert(isRegister() && "Wrong MachineOperand accessor");
return IsImp;
}
void setImplicit() {
assert(isRegister() && "Wrong MachineOperand accessor");
IsImp = true;
}
bool isKill() const {
assert(isRegister() && "Wrong MachineOperand accessor");
return IsKill;
}
bool isDead() const {
assert(isRegister() && "Wrong MachineOperand accessor");
return IsDead;
}
void setIsKill() {
assert(isRegister() && !IsDef && "Wrong MachineOperand accessor");
IsKill = true;
}
void setIsDead() {
assert(isRegister() && IsDef && "Wrong MachineOperand accessor");
IsDead = true;
}
void unsetIsKill() {
assert(isRegister() && !IsDef && "Wrong MachineOperand accessor");
IsKill = false;
}
void unsetIsDead() {
assert(isRegister() && IsDef && "Wrong MachineOperand accessor");
IsDead = false;
}
/// getReg - Returns the register number.
///
unsigned getReg() const {
assert(isRegister() && "This is not a register operand!");
return contents.RegNo;
}
/// MachineOperand mutators.
///
void setReg(unsigned Reg) {
assert(isRegister() && "This is not a register operand!");
contents.RegNo = Reg;
}
void setImm(int64_t immVal) {
assert(isImmediate() && "Wrong MachineOperand mutator");
contents.ImmVal = immVal;
}
void setOffset(int Offset) {
assert((isGlobalAddress() || isExternalSymbol() || isConstantPoolIndex()) &&
"Wrong MachineOperand accessor");
auxInfo.offset = Offset;
}
void setSubReg(unsigned subReg) {
assert(isRegister() && "Wrong MachineOperand accessor");
SubReg = (unsigned char)subReg;
}
void setConstantPoolIndex(unsigned Idx) {
assert(isConstantPoolIndex() && "Wrong MachineOperand accessor");
contents.Index = Idx;
}
void setJumpTableIndex(unsigned Idx) {
assert(isJumpTableIndex() && "Wrong MachineOperand accessor");
contents.Index = Idx;
}
/// isIdenticalTo - Return true if this operand is identical to the specified
/// operand. Note: This method ignores isKill and isDead properties.
bool isIdenticalTo(const MachineOperand &Other) const;
/// ChangeToImmediate - Replace this operand with a new immediate operand of
/// the specified value. If an operand is known to be an immediate already,
/// the setImm method should be used.
void ChangeToImmediate(int64_t ImmVal) {
opType = MO_Immediate;
contents.ImmVal = ImmVal;
}
/// ChangeToRegister - Replace this operand with a new register operand of
|