Fixed/added namespace ending comments using clang-tidy. NFC
[oota-llvm.git] / include / llvm / CodeGen / MachineOperand.h
1 //===-- llvm/CodeGen/MachineOperand.h - MachineOperand class ----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the declaration of the MachineOperand class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CODEGEN_MACHINEOPERAND_H
15 #define LLVM_CODEGEN_MACHINEOPERAND_H
16
17 #include "llvm/Support/DataTypes.h"
18 #include <cassert>
19
20 namespace llvm {
21
22 class BlockAddress;
23 class ConstantFP;
24 class ConstantInt;
25 class GlobalValue;
26 class MachineBasicBlock;
27 class MachineInstr;
28 class MachineRegisterInfo;
29 class MDNode;
30 class TargetMachine;
31 class TargetRegisterInfo;
32 class hash_code;
33 class raw_ostream;
34 class MCSymbol;
35
36 /// MachineOperand class - Representation of each machine instruction operand.
37 ///
38 /// This class isn't a POD type because it has a private constructor, but its
39 /// destructor must be trivial. Functions like MachineInstr::addOperand(),
40 /// MachineRegisterInfo::moveOperands(), and MF::DeleteMachineInstr() depend on
41 /// not having to call the MachineOperand destructor.
42 ///
43 class MachineOperand {
44 public:
45   enum MachineOperandType : unsigned char {
46     MO_Register,          ///< Register operand.
47     MO_Immediate,         ///< Immediate operand
48     MO_CImmediate,        ///< Immediate >64bit operand
49     MO_FPImmediate,       ///< Floating-point immediate operand
50     MO_MachineBasicBlock, ///< MachineBasicBlock reference
51     MO_FrameIndex,        ///< Abstract Stack Frame Index
52     MO_ConstantPoolIndex, ///< Address of indexed Constant in Constant Pool
53     MO_TargetIndex,       ///< Target-dependent index+offset operand.
54     MO_JumpTableIndex,    ///< Address of indexed Jump Table for switch
55     MO_ExternalSymbol,    ///< Name of external global symbol
56     MO_GlobalAddress,     ///< Address of a global value
57     MO_BlockAddress,      ///< Address of a basic block
58     MO_RegisterMask,      ///< Mask of preserved registers.
59     MO_RegisterLiveOut,   ///< Mask of live-out registers.
60     MO_Metadata,          ///< Metadata reference (for debug info)
61     MO_MCSymbol,          ///< MCSymbol reference (for debug/eh info)
62     MO_CFIIndex           ///< MCCFIInstruction index.
63   };
64
65 private:
66   /// OpKind - Specify what kind of operand this is.  This discriminates the
67   /// union.
68   MachineOperandType OpKind : 8;
69
70   /// Subregister number for MO_Register.  A value of 0 indicates the
71   /// MO_Register has no subReg.
72   ///
73   /// For all other kinds of operands, this field holds target-specific flags.
74   unsigned SubReg_TargetFlags : 12;
75
76   /// TiedTo - Non-zero when this register operand is tied to another register
77   /// operand. The encoding of this field is described in the block comment
78   /// before MachineInstr::tieOperands().
79   unsigned char TiedTo : 4;
80
81   /// IsDef/IsImp/IsKill/IsDead flags - These are only valid for MO_Register
82   /// operands.
83
84   /// IsDef - True if this is a def, false if this is a use of the register.
85   ///
86   bool IsDef : 1;
87
88   /// IsImp - True if this is an implicit def or use, false if it is explicit.
89   ///
90   bool IsImp : 1;
91
92   /// IsKill - True if this instruction is the last use of the register on this
93   /// path through the function.  This is only valid on uses of registers.
94   bool IsKill : 1;
95
96   /// IsDead - True if this register is never used by a subsequent instruction.
97   /// This is only valid on definitions of registers.
98   bool IsDead : 1;
99
100   /// IsUndef - True if this register operand reads an "undef" value, i.e. the
101   /// read value doesn't matter.  This flag can be set on both use and def
102   /// operands.  On a sub-register def operand, it refers to the part of the
103   /// register that isn't written.  On a full-register def operand, it is a
104   /// noop.  See readsReg().
105   ///
106   /// This is only valid on registers.
107   ///
108   /// Note that an instruction may have multiple <undef> operands referring to
109   /// the same register.  In that case, the instruction may depend on those
110   /// operands reading the same dont-care value.  For example:
111   ///
112   ///   %vreg1<def> = XOR %vreg2<undef>, %vreg2<undef>
113   ///
114   /// Any register can be used for %vreg2, and its value doesn't matter, but
115   /// the two operands must be the same register.
116   ///
117   bool IsUndef : 1;
118
119   /// IsInternalRead - True if this operand reads a value that was defined
120   /// inside the same instruction or bundle.  This flag can be set on both use
121   /// and def operands.  On a sub-register def operand, it refers to the part
122   /// of the register that isn't written.  On a full-register def operand, it
123   /// is a noop.
124   ///
125   /// When this flag is set, the instruction bundle must contain at least one
126   /// other def of the register.  If multiple instructions in the bundle define
127   /// the register, the meaning is target-defined.
128   bool IsInternalRead : 1;
129
130   /// IsEarlyClobber - True if this MO_Register 'def' operand is written to
131   /// by the MachineInstr before all input registers are read.  This is used to
132   /// model the GCC inline asm '&' constraint modifier.
133   bool IsEarlyClobber : 1;
134
135   /// IsDebug - True if this MO_Register 'use' operand is in a debug pseudo,
136   /// not a real instruction.  Such uses should be ignored during codegen.
137   bool IsDebug : 1;
138
139   /// SmallContents - This really should be part of the Contents union, but
140   /// lives out here so we can get a better packed struct.
141   /// MO_Register: Register number.
142   /// OffsetedInfo: Low bits of offset.
143   union {
144     unsigned RegNo;           // For MO_Register.
145     unsigned OffsetLo;        // Matches Contents.OffsetedInfo.OffsetHi.
146   } SmallContents;
147
148   /// ParentMI - This is the instruction that this operand is embedded into.
149   /// This is valid for all operand types, when the operand is in an instr.
150   MachineInstr *ParentMI;
151
152   /// Contents union - This contains the payload for the various operand types.
153   union {
154     MachineBasicBlock *MBB;  // For MO_MachineBasicBlock.
155     const ConstantFP *CFP;   // For MO_FPImmediate.
156     const ConstantInt *CI;   // For MO_CImmediate. Integers > 64bit.
157     int64_t ImmVal;          // For MO_Immediate.
158     const uint32_t *RegMask; // For MO_RegisterMask and MO_RegisterLiveOut.
159     const MDNode *MD;        // For MO_Metadata.
160     MCSymbol *Sym;           // For MO_MCSymbol.
161     unsigned CFIIndex;       // For MO_CFI.
162
163     struct {                  // For MO_Register.
164       // Register number is in SmallContents.RegNo.
165       MachineOperand *Prev;   // Access list for register. See MRI.
166       MachineOperand *Next;
167     } Reg;
168
169     /// OffsetedInfo - This struct contains the offset and an object identifier.
170     /// this represent the object as with an optional offset from it.
171     struct {
172       union {
173         int Index;                // For MO_*Index - The index itself.
174         const char *SymbolName;   // For MO_ExternalSymbol.
175         const GlobalValue *GV;    // For MO_GlobalAddress.
176         const BlockAddress *BA;   // For MO_BlockAddress.
177       } Val;
178       // Low bits of offset are in SmallContents.OffsetLo.
179       int OffsetHi;               // An offset from the object, high 32 bits.
180     } OffsetedInfo;
181   } Contents;
182
183   explicit MachineOperand(MachineOperandType K)
184     : OpKind(K), SubReg_TargetFlags(0), ParentMI(nullptr) {}
185 public:
186   /// getType - Returns the MachineOperandType for this operand.
187   ///
188   MachineOperandType getType() const { return (MachineOperandType)OpKind; }
189
190   unsigned getTargetFlags() const {
191     return isReg() ? 0 : SubReg_TargetFlags;
192   }
193   void setTargetFlags(unsigned F) {
194     assert(!isReg() && "Register operands can't have target flags");
195     SubReg_TargetFlags = F;
196     assert(SubReg_TargetFlags == F && "Target flags out of range");
197   }
198   void addTargetFlag(unsigned F) {
199     assert(!isReg() && "Register operands can't have target flags");
200     SubReg_TargetFlags |= F;
201     assert((SubReg_TargetFlags & F) && "Target flags out of range");
202   }
203
204
205   /// getParent - Return the instruction that this operand belongs to.
206   ///
207   MachineInstr *getParent() { return ParentMI; }
208   const MachineInstr *getParent() const { return ParentMI; }
209
210   /// clearParent - Reset the parent pointer.
211   ///
212   /// The MachineOperand copy constructor also copies ParentMI, expecting the
213   /// original to be deleted. If a MachineOperand is ever stored outside a
214   /// MachineInstr, the parent pointer must be cleared.
215   ///
216   /// Never call clearParent() on an operand in a MachineInstr.
217   ///
218   void clearParent() { ParentMI = nullptr; }
219
220   void print(raw_ostream &os, const TargetRegisterInfo *TRI = nullptr) const;
221
222   //===--------------------------------------------------------------------===//
223   // Accessors that tell you what kind of MachineOperand you're looking at.
224   //===--------------------------------------------------------------------===//
225
226   /// isReg - Tests if this is a MO_Register operand.
227   bool isReg() const { return OpKind == MO_Register; }
228   /// isImm - Tests if this is a MO_Immediate operand.
229   bool isImm() const { return OpKind == MO_Immediate; }
230   /// isCImm - Test if this is a MO_CImmediate operand.
231   bool isCImm() const { return OpKind == MO_CImmediate; }
232   /// isFPImm - Tests if this is a MO_FPImmediate operand.
233   bool isFPImm() const { return OpKind == MO_FPImmediate; }
234   /// isMBB - Tests if this is a MO_MachineBasicBlock operand.
235   bool isMBB() const { return OpKind == MO_MachineBasicBlock; }
236   /// isFI - Tests if this is a MO_FrameIndex operand.
237   bool isFI() const { return OpKind == MO_FrameIndex; }
238   /// isCPI - Tests if this is a MO_ConstantPoolIndex operand.
239   bool isCPI() const { return OpKind == MO_ConstantPoolIndex; }
240   /// isTargetIndex - Tests if this is a MO_TargetIndex operand.
241   bool isTargetIndex() const { return OpKind == MO_TargetIndex; }
242   /// isJTI - Tests if this is a MO_JumpTableIndex operand.
243   bool isJTI() const { return OpKind == MO_JumpTableIndex; }
244   /// isGlobal - Tests if this is a MO_GlobalAddress operand.
245   bool isGlobal() const { return OpKind == MO_GlobalAddress; }
246   /// isSymbol - Tests if this is a MO_ExternalSymbol operand.
247   bool isSymbol() const { return OpKind == MO_ExternalSymbol; }
248   /// isBlockAddress - Tests if this is a MO_BlockAddress operand.
249   bool isBlockAddress() const { return OpKind == MO_BlockAddress; }
250   /// isRegMask - Tests if this is a MO_RegisterMask operand.
251   bool isRegMask() const { return OpKind == MO_RegisterMask; }
252   /// isRegLiveOut - Tests if this is a MO_RegisterLiveOut operand.
253   bool isRegLiveOut() const { return OpKind == MO_RegisterLiveOut; }
254   /// isMetadata - Tests if this is a MO_Metadata operand.
255   bool isMetadata() const { return OpKind == MO_Metadata; }
256   bool isMCSymbol() const { return OpKind == MO_MCSymbol; }
257   bool isCFIIndex() const { return OpKind == MO_CFIIndex; }
258
259   //===--------------------------------------------------------------------===//
260   // Accessors for Register Operands
261   //===--------------------------------------------------------------------===//
262
263   /// getReg - Returns the register number.
264   unsigned getReg() const {
265     assert(isReg() && "This is not a register operand!");
266     return SmallContents.RegNo;
267   }
268
269   unsigned getSubReg() const {
270     assert(isReg() && "Wrong MachineOperand accessor");
271     return SubReg_TargetFlags;
272   }
273
274   bool isUse() const {
275     assert(isReg() && "Wrong MachineOperand accessor");
276     return !IsDef;
277   }
278
279   bool isDef() const {
280     assert(isReg() && "Wrong MachineOperand accessor");
281     return IsDef;
282   }
283
284   bool isImplicit() const {
285     assert(isReg() && "Wrong MachineOperand accessor");
286     return IsImp;
287   }
288
289   bool isDead() const {
290     assert(isReg() && "Wrong MachineOperand accessor");
291     return IsDead;
292   }
293
294   bool isKill() const {
295     assert(isReg() && "Wrong MachineOperand accessor");
296     return IsKill;
297   }
298
299   bool isUndef() const {
300     assert(isReg() && "Wrong MachineOperand accessor");
301     return IsUndef;
302   }
303
304   bool isInternalRead() const {
305     assert(isReg() && "Wrong MachineOperand accessor");
306     return IsInternalRead;
307   }
308
309   bool isEarlyClobber() const {
310     assert(isReg() && "Wrong MachineOperand accessor");
311     return IsEarlyClobber;
312   }
313
314   bool isTied() const {
315     assert(isReg() && "Wrong MachineOperand accessor");
316     return TiedTo;
317   }
318
319   bool isDebug() const {
320     assert(isReg() && "Wrong MachineOperand accessor");
321     return IsDebug;
322   }
323
324   /// readsReg - Returns true if this operand reads the previous value of its
325   /// register.  A use operand with the <undef> flag set doesn't read its
326   /// register.  A sub-register def implicitly reads the other parts of the
327   /// register being redefined unless the <undef> flag is set.
328   ///
329   /// This refers to reading the register value from before the current
330   /// instruction or bundle. Internal bundle reads are not included.
331   bool readsReg() const {
332     assert(isReg() && "Wrong MachineOperand accessor");
333     return !isUndef() && !isInternalRead() && (isUse() || getSubReg());
334   }
335
336   //===--------------------------------------------------------------------===//
337   // Mutators for Register Operands
338   //===--------------------------------------------------------------------===//
339
340   /// Change the register this operand corresponds to.
341   ///
342   void setReg(unsigned Reg);
343
344   void setSubReg(unsigned subReg) {
345     assert(isReg() && "Wrong MachineOperand accessor");
346     SubReg_TargetFlags = subReg;
347     assert(SubReg_TargetFlags == subReg && "SubReg out of range");
348   }
349
350   /// substVirtReg - Substitute the current register with the virtual
351   /// subregister Reg:SubReg. Take any existing SubReg index into account,
352   /// using TargetRegisterInfo to compose the subreg indices if necessary.
353   /// Reg must be a virtual register, SubIdx can be 0.
354   ///
355   void substVirtReg(unsigned Reg, unsigned SubIdx, const TargetRegisterInfo&);
356
357   /// substPhysReg - Substitute the current register with the physical register
358   /// Reg, taking any existing SubReg into account. For instance,
359   /// substPhysReg(%EAX) will change %reg1024:sub_8bit to %AL.
360   ///
361   void substPhysReg(unsigned Reg, const TargetRegisterInfo&);
362
363   void setIsUse(bool Val = true) { setIsDef(!Val); }
364
365   void setIsDef(bool Val = true);
366
367   void setImplicit(bool Val = true) {
368     assert(isReg() && "Wrong MachineOperand accessor");
369     IsImp = Val;
370   }
371
372   void setIsKill(bool Val = true) {
373     assert(isReg() && !IsDef && "Wrong MachineOperand accessor");
374     assert((!Val || !isDebug()) && "Marking a debug operation as kill");
375     IsKill = Val;
376   }
377
378   void setIsDead(bool Val = true) {
379     assert(isReg() && IsDef && "Wrong MachineOperand accessor");
380     IsDead = Val;
381   }
382
383   void setIsUndef(bool Val = true) {
384     assert(isReg() && "Wrong MachineOperand accessor");
385     IsUndef = Val;
386   }
387
388   void setIsInternalRead(bool Val = true) {
389     assert(isReg() && "Wrong MachineOperand accessor");
390     IsInternalRead = Val;
391   }
392
393   void setIsEarlyClobber(bool Val = true) {
394     assert(isReg() && IsDef && "Wrong MachineOperand accessor");
395     IsEarlyClobber = Val;
396   }
397
398   void setIsDebug(bool Val = true) {
399     assert(isReg() && !IsDef && "Wrong MachineOperand accessor");
400     IsDebug = Val;
401   }
402
403   //===--------------------------------------------------------------------===//
404   // Accessors for various operand types.
405   //===--------------------------------------------------------------------===//
406
407   int64_t getImm() const {
408     assert(isImm() && "Wrong MachineOperand accessor");
409     return Contents.ImmVal;
410   }
411
412   const ConstantInt *getCImm() const {
413     assert(isCImm() && "Wrong MachineOperand accessor");
414     return Contents.CI;
415   }
416
417   const ConstantFP *getFPImm() const {
418     assert(isFPImm() && "Wrong MachineOperand accessor");
419     return Contents.CFP;
420   }
421
422   MachineBasicBlock *getMBB() const {
423     assert(isMBB() && "Wrong MachineOperand accessor");
424     return Contents.MBB;
425   }
426
427   int getIndex() const {
428     assert((isFI() || isCPI() || isTargetIndex() || isJTI()) &&
429            "Wrong MachineOperand accessor");
430     return Contents.OffsetedInfo.Val.Index;
431   }
432
433   const GlobalValue *getGlobal() const {
434     assert(isGlobal() && "Wrong MachineOperand accessor");
435     return Contents.OffsetedInfo.Val.GV;
436   }
437
438   const BlockAddress *getBlockAddress() const {
439     assert(isBlockAddress() && "Wrong MachineOperand accessor");
440     return Contents.OffsetedInfo.Val.BA;
441   }
442
443   MCSymbol *getMCSymbol() const {
444     assert(isMCSymbol() && "Wrong MachineOperand accessor");
445     return Contents.Sym;
446   }
447
448   unsigned getCFIIndex() const {
449     assert(isCFIIndex() && "Wrong MachineOperand accessor");
450     return Contents.CFIIndex;
451   }
452
453   /// getOffset - Return the offset from the symbol in this operand. This always
454   /// returns 0 for ExternalSymbol operands.
455   int64_t getOffset() const {
456     assert((isGlobal() || isSymbol() || isCPI() || isTargetIndex() ||
457             isBlockAddress()) && "Wrong MachineOperand accessor");
458     return int64_t(uint64_t(Contents.OffsetedInfo.OffsetHi) << 32) |
459            SmallContents.OffsetLo;
460   }
461
462   const char *getSymbolName() const {
463     assert(isSymbol() && "Wrong MachineOperand accessor");
464     return Contents.OffsetedInfo.Val.SymbolName;
465   }
466
467   /// clobbersPhysReg - Returns true if this RegMask clobbers PhysReg.
468   /// It is sometimes necessary to detach the register mask pointer from its
469   /// machine operand. This static method can be used for such detached bit
470   /// mask pointers.
471   static bool clobbersPhysReg(const uint32_t *RegMask, unsigned PhysReg) {
472     // See TargetRegisterInfo.h.
473     assert(PhysReg < (1u << 30) && "Not a physical register");
474     return !(RegMask[PhysReg / 32] & (1u << PhysReg % 32));
475   }
476
477   /// clobbersPhysReg - Returns true if this RegMask operand clobbers PhysReg.
478   bool clobbersPhysReg(unsigned PhysReg) const {
479      return clobbersPhysReg(getRegMask(), PhysReg);
480   }
481
482   /// getRegMask - Returns a bit mask of registers preserved by this RegMask
483   /// operand.
484   const uint32_t *getRegMask() const {
485     assert(isRegMask() && "Wrong MachineOperand accessor");
486     return Contents.RegMask;
487   }
488
489   /// getRegLiveOut - Returns a bit mask of live-out registers.
490   const uint32_t *getRegLiveOut() const {
491     assert(isRegLiveOut() && "Wrong MachineOperand accessor");
492     return Contents.RegMask;
493   }
494
495   const MDNode *getMetadata() const {
496     assert(isMetadata() && "Wrong MachineOperand accessor");
497     return Contents.MD;
498   }
499
500   //===--------------------------------------------------------------------===//
501   // Mutators for various operand types.
502   //===--------------------------------------------------------------------===//
503
504   void setImm(int64_t immVal) {
505     assert(isImm() && "Wrong MachineOperand mutator");
506     Contents.ImmVal = immVal;
507   }
508
509   void setFPImm(const ConstantFP *CFP) {
510     assert(isFPImm() && "Wrong MachineOperand mutator");
511     Contents.CFP = CFP;
512   }
513
514   void setOffset(int64_t Offset) {
515     assert((isGlobal() || isSymbol() || isCPI() || isTargetIndex() ||
516             isBlockAddress()) && "Wrong MachineOperand accessor");
517     SmallContents.OffsetLo = unsigned(Offset);
518     Contents.OffsetedInfo.OffsetHi = int(Offset >> 32);
519   }
520
521   void setIndex(int Idx) {
522     assert((isFI() || isCPI() || isTargetIndex() || isJTI()) &&
523            "Wrong MachineOperand accessor");
524     Contents.OffsetedInfo.Val.Index = Idx;
525   }
526
527   void setMBB(MachineBasicBlock *MBB) {
528     assert(isMBB() && "Wrong MachineOperand accessor");
529     Contents.MBB = MBB;
530   }
531
532   //===--------------------------------------------------------------------===//
533   // Other methods.
534   //===--------------------------------------------------------------------===//
535
536   /// isIdenticalTo - Return true if this operand is identical to the specified
537   /// operand. Note: This method ignores isKill and isDead properties.
538   bool isIdenticalTo(const MachineOperand &Other) const;
539
540   /// \brief MachineOperand hash_value overload.
541   ///
542   /// Note that this includes the same information in the hash that
543   /// isIdenticalTo uses for comparison. It is thus suited for use in hash
544   /// tables which use that function for equality comparisons only.
545   friend hash_code hash_value(const MachineOperand &MO);
546
547   /// ChangeToImmediate - Replace this operand with a new immediate operand of
548   /// the specified value.  If an operand is known to be an immediate already,
549   /// the setImm method should be used.
550   void ChangeToImmediate(int64_t ImmVal);
551
552   /// ChangeToFPImmediate - Replace this operand with a new FP immediate operand
553   /// of the specified value.  If an operand is known to be an FP immediate
554   /// already, the setFPImm method should be used.
555   void ChangeToFPImmediate(const ConstantFP *FPImm);
556
557   /// ChangeToES - Replace this operand with a new external symbol operand.
558   void ChangeToES(const char *SymName, unsigned char TargetFlags = 0);
559
560   /// ChangeToMCSymbol - Replace this operand with a new MC symbol operand.
561   void ChangeToMCSymbol(MCSymbol *Sym);
562
563   /// ChangeToRegister - Replace this operand with a new register operand of
564   /// the specified value.  If an operand is known to be an register already,
565   /// the setReg method should be used.
566   void ChangeToRegister(unsigned Reg, bool isDef, bool isImp = false,
567                         bool isKill = false, bool isDead = false,
568                         bool isUndef = false, bool isDebug = false);
569
570   //===--------------------------------------------------------------------===//
571   // Construction methods.
572   //===--------------------------------------------------------------------===//
573
574   static MachineOperand CreateImm(int64_t Val) {
575     MachineOperand Op(MachineOperand::MO_Immediate);
576     Op.setImm(Val);
577     return Op;
578   }
579
580   static MachineOperand CreateCImm(const ConstantInt *CI) {
581     MachineOperand Op(MachineOperand::MO_CImmediate);
582     Op.Contents.CI = CI;
583     return Op;
584   }
585
586   static MachineOperand CreateFPImm(const ConstantFP *CFP) {
587     MachineOperand Op(MachineOperand::MO_FPImmediate);
588     Op.Contents.CFP = CFP;
589     return Op;
590   }
591
592   static MachineOperand CreateReg(unsigned Reg, bool isDef, bool isImp = false,
593                                   bool isKill = false, bool isDead = false,
594                                   bool isUndef = false,
595                                   bool isEarlyClobber = false,
596                                   unsigned SubReg = 0,
597                                   bool isDebug = false,
598                                   bool isInternalRead = false) {
599     assert(!(isDead && !isDef) && "Dead flag on non-def");
600     assert(!(isKill && isDef) && "Kill flag on def");
601     MachineOperand Op(MachineOperand::MO_Register);
602     Op.IsDef = isDef;
603     Op.IsImp = isImp;
604     Op.IsKill = isKill;
605     Op.IsDead = isDead;
606     Op.IsUndef = isUndef;
607     Op.IsInternalRead = isInternalRead;
608     Op.IsEarlyClobber = isEarlyClobber;
609     Op.TiedTo = 0;
610     Op.IsDebug = isDebug;
611     Op.SmallContents.RegNo = Reg;
612     Op.Contents.Reg.Prev = nullptr;
613     Op.Contents.Reg.Next = nullptr;
614     Op.setSubReg(SubReg);
615     return Op;
616   }
617   static MachineOperand CreateMBB(MachineBasicBlock *MBB,
618                                   unsigned char TargetFlags = 0) {
619     MachineOperand Op(MachineOperand::MO_MachineBasicBlock);
620     Op.setMBB(MBB);
621     Op.setTargetFlags(TargetFlags);
622     return Op;
623   }
624   static MachineOperand CreateFI(int Idx) {
625     MachineOperand Op(MachineOperand::MO_FrameIndex);
626     Op.setIndex(Idx);
627     return Op;
628   }
629   static MachineOperand CreateCPI(unsigned Idx, int Offset,
630                                   unsigned char TargetFlags = 0) {
631     MachineOperand Op(MachineOperand::MO_ConstantPoolIndex);
632     Op.setIndex(Idx);
633     Op.setOffset(Offset);
634     Op.setTargetFlags(TargetFlags);
635     return Op;
636   }
637   static MachineOperand CreateTargetIndex(unsigned Idx, int64_t Offset,
638                                           unsigned char TargetFlags = 0) {
639     MachineOperand Op(MachineOperand::MO_TargetIndex);
640     Op.setIndex(Idx);
641     Op.setOffset(Offset);
642     Op.setTargetFlags(TargetFlags);
643     return Op;
644   }
645   static MachineOperand CreateJTI(unsigned Idx,
646                                   unsigned char TargetFlags = 0) {
647     MachineOperand Op(MachineOperand::MO_JumpTableIndex);
648     Op.setIndex(Idx);
649     Op.setTargetFlags(TargetFlags);
650     return Op;
651   }
652   static MachineOperand CreateGA(const GlobalValue *GV, int64_t Offset,
653                                  unsigned char TargetFlags = 0) {
654     MachineOperand Op(MachineOperand::MO_GlobalAddress);
655     Op.Contents.OffsetedInfo.Val.GV = GV;
656     Op.setOffset(Offset);
657     Op.setTargetFlags(TargetFlags);
658     return Op;
659   }
660   static MachineOperand CreateES(const char *SymName,
661                                  unsigned char TargetFlags = 0) {
662     MachineOperand Op(MachineOperand::MO_ExternalSymbol);
663     Op.Contents.OffsetedInfo.Val.SymbolName = SymName;
664     Op.setOffset(0); // Offset is always 0.
665     Op.setTargetFlags(TargetFlags);
666     return Op;
667   }
668   static MachineOperand CreateBA(const BlockAddress *BA, int64_t Offset,
669                                  unsigned char TargetFlags = 0) {
670     MachineOperand Op(MachineOperand::MO_BlockAddress);
671     Op.Contents.OffsetedInfo.Val.BA = BA;
672     Op.setOffset(Offset);
673     Op.setTargetFlags(TargetFlags);
674     return Op;
675   }
676   /// CreateRegMask - Creates a register mask operand referencing Mask.  The
677   /// operand does not take ownership of the memory referenced by Mask, it must
678   /// remain valid for the lifetime of the operand.
679   ///
680   /// A RegMask operand represents a set of non-clobbered physical registers on
681   /// an instruction that clobbers many registers, typically a call.  The bit
682   /// mask has a bit set for each physreg that is preserved by this
683   /// instruction, as described in the documentation for
684   /// TargetRegisterInfo::getCallPreservedMask().
685   ///
686   /// Any physreg with a 0 bit in the mask is clobbered by the instruction.
687   ///
688   static MachineOperand CreateRegMask(const uint32_t *Mask) {
689     assert(Mask && "Missing register mask");
690     MachineOperand Op(MachineOperand::MO_RegisterMask);
691     Op.Contents.RegMask = Mask;
692     return Op;
693   }
694   static MachineOperand CreateRegLiveOut(const uint32_t *Mask) {
695     assert(Mask && "Missing live-out register mask");
696     MachineOperand Op(MachineOperand::MO_RegisterLiveOut);
697     Op.Contents.RegMask = Mask;
698     return Op;
699   }
700   static MachineOperand CreateMetadata(const MDNode *Meta) {
701     MachineOperand Op(MachineOperand::MO_Metadata);
702     Op.Contents.MD = Meta;
703     return Op;
704   }
705
706   static MachineOperand CreateMCSymbol(MCSymbol *Sym) {
707     MachineOperand Op(MachineOperand::MO_MCSymbol);
708     Op.Contents.Sym = Sym;
709     return Op;
710   }
711
712   static MachineOperand CreateCFIIndex(unsigned CFIIndex) {
713     MachineOperand Op(MachineOperand::MO_CFIIndex);
714     Op.Contents.CFIIndex = CFIIndex;
715     return Op;
716   }
717
718   friend class MachineInstr;
719   friend class MachineRegisterInfo;
720 private:
721   void removeRegFromUses();
722
723   //===--------------------------------------------------------------------===//
724   // Methods for handling register use/def lists.
725   //===--------------------------------------------------------------------===//
726
727   /// isOnRegUseList - Return true if this operand is on a register use/def list
728   /// or false if not.  This can only be called for register operands that are
729   /// part of a machine instruction.
730   bool isOnRegUseList() const {
731     assert(isReg() && "Can only add reg operand to use lists");
732     return Contents.Reg.Prev != nullptr;
733   }
734 };
735
736 inline raw_ostream &operator<<(raw_ostream &OS, const MachineOperand& MO) {
737   MO.print(OS, nullptr);
738   return OS;
739 }
740
741   // See friend declaration above. This additional declaration is required in
742   // order to compile LLVM with IBM xlC compiler.
743   hash_code hash_value(const MachineOperand &MO);
744 } // namespace llvm
745
746 #endif