29
29
#include " llvm/MC/MCInstrDesc.h"
30
30
#include " llvm/MC/MCSymbol.h"
31
31
#include " llvm/Support/ArrayRecycler.h"
32
+ #include " llvm/Support/MathExtras.h"
32
33
#include " llvm/Support/TrailingObjects.h"
33
34
#include < algorithm>
34
35
#include < cassert>
@@ -121,22 +122,27 @@ class MachineInstr
121
122
122
123
// Operands are allocated by an ArrayRecycler.
123
124
MachineOperand *Operands = nullptr ; // Pointer to the first operand.
124
- uint32_t Flags = 0 ; // Various bits of additional
125
- // information about machine
126
- // instruction.
127
- uint16_t NumOperands = 0 ; // Number of operands on instruction.
128
- uint8_t AsmPrinterFlags = 0 ; // Various bits of information used by
129
- // the AsmPrinter to emit helpful
130
- // comments. This is *not* semantic
131
- // information. Do not use this for
132
- // anything other than to convey comment
133
- // information to AsmPrinter.
134
-
135
- // OperandCapacity has uint8_t size, so it should be next to AsmPrinterFlags
125
+
126
+ #define LLVM_MI_NUMOPERANDS_BITS 24
127
+ #define LLVM_MI_FLAGS_BITS 24
128
+ #define LLVM_MI_ASMPRINTERFLAGS_BITS 8
129
+
130
+ // / Number of operands on instruction.
131
+ uint32_t NumOperands : LLVM_MI_NUMOPERANDS_BITS;
132
+
133
+ // OperandCapacity has uint8_t size, so it should be next to NumOperands
136
134
// to properly pack.
137
135
using OperandCapacity = ArrayRecycler<MachineOperand>::Capacity;
138
136
OperandCapacity CapOperands; // Capacity of the Operands array.
139
137
138
+ // / Various bits of additional information about the machine instruction.
139
+ uint32_t Flags : LLVM_MI_FLAGS_BITS;
140
+
141
+ // / Various bits of information used by the AsmPrinter to emit helpful
142
+ // / comments. This is *not* semantic information. Do not use this for
143
+ // / anything other than to convey comment information to AsmPrinter.
144
+ uint8_t AsmPrinterFlags : LLVM_MI_ASMPRINTERFLAGS_BITS;
145
+
140
146
// / Internal implementation detail class that provides out-of-line storage for
141
147
// / extra info used by the machine instruction when this info cannot be stored
142
148
// / in-line within the instruction itself.
@@ -342,16 +348,22 @@ class MachineInstr
342
348
343
349
// / Return whether an AsmPrinter flag is set.
344
350
bool getAsmPrinterFlag (CommentFlag Flag) const {
351
+ assert (isUInt<LLVM_MI_ASMPRINTERFLAGS_BITS>(unsigned (Flag)) &&
352
+ " Flag is out of range for the AsmPrinterFlags field" );
345
353
return AsmPrinterFlags & Flag;
346
354
}
347
355
348
356
// / Set a flag for the AsmPrinter.
349
357
void setAsmPrinterFlag (uint8_t Flag) {
358
+ assert (isUInt<LLVM_MI_ASMPRINTERFLAGS_BITS>(unsigned (Flag)) &&
359
+ " Flag is out of range for the AsmPrinterFlags field" );
350
360
AsmPrinterFlags |= Flag;
351
361
}
352
362
353
363
// / Clear specific AsmPrinter flags.
354
364
void clearAsmPrinterFlag (CommentFlag Flag) {
365
+ assert (isUInt<LLVM_MI_ASMPRINTERFLAGS_BITS>(unsigned (Flag)) &&
366
+ " Flag is out of range for the AsmPrinterFlags field" );
355
367
AsmPrinterFlags &= ~Flag;
356
368
}
357
369
@@ -362,22 +374,30 @@ class MachineInstr
362
374
363
375
// / Return whether an MI flag is set.
364
376
bool getFlag (MIFlag Flag) const {
377
+ assert (isUInt<LLVM_MI_FLAGS_BITS>(unsigned (Flag)) &&
378
+ " Flag is out of range for the Flags field" );
365
379
return Flags & Flag;
366
380
}
367
381
368
382
// / Set a MI flag.
369
383
void setFlag (MIFlag Flag) {
384
+ assert (isUInt<LLVM_MI_FLAGS_BITS>(unsigned (Flag)) &&
385
+ " Flag is out of range for the Flags field" );
370
386
Flags |= (uint32_t )Flag;
371
387
}
372
388
373
389
void setFlags (unsigned flags) {
390
+ assert (isUInt<LLVM_MI_FLAGS_BITS>(flags) &&
391
+ " flags to be set are out of range for the Flags field" );
374
392
// Filter out the automatically maintained flags.
375
393
unsigned Mask = BundledPred | BundledSucc;
376
394
Flags = (Flags & Mask) | (flags & ~Mask);
377
395
}
378
396
379
397
// / clearFlag - Clear a MI flag.
380
398
void clearFlag (MIFlag Flag) {
399
+ assert (isUInt<LLVM_MI_FLAGS_BITS>(unsigned (Flag)) &&
400
+ " Flag to clear is out of range for the Flags field" );
381
401
Flags &= ~((uint32_t )Flag);
382
402
}
383
403
0 commit comments