6df502f7b86ba89baf3170d79c0deb635a16a366
[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   /// Return the offset from the symbol in this operand. This always returns 0
454   /// for ExternalSymbol operands.
455   int64_t getOffset() const {
456     assert((isGlobal() || isSymbol() || isMCSymbol() || isCPI() ||
457             isTargetIndex() || isBlockAddress()) &&
458            "Wrong MachineOperand accessor");
459     return int64_t(uint64_t(Contents.OffsetedInfo.OffsetHi) << 32) |
460            SmallContents.OffsetLo;
461   }
462
463   const char *getSymbolName() const {
464     assert(isSymbol() && "Wrong MachineOperand accessor");
465     return Contents.OffsetedInfo.Val.SymbolName;
466   }
467
468   /// clobbersPhysReg - Returns true if this RegMask clobbers PhysReg.
469   /// It is sometimes necessary to detach the register mask pointer from its
470   /// machine operand. This static method can be used for such detached bit
471   /// mask pointers.
472   static bool clobbersPhysReg(const uint32_t *RegMask, unsigned PhysReg) {
473     // See TargetRegisterInfo.h.
474     assert(PhysReg < (1u << 30) && "Not a physical register");
475     return !(RegMask[PhysReg / 32] & (1u << PhysReg % 32));
476   }
477
478   /// clobbersPhysReg - Returns true if this RegMask operand clobbers PhysReg.
479   bool clobbersPhysReg(unsigned PhysReg) const {
480      return clobbersPhysReg(getRegMask(), PhysReg);
481   }
482
483   /// getRegMask - Returns a bit mask of registers preserved by this RegMask
484   /// operand.
485   const uint32_t *getRegMask() const {
486     assert(isRegMask() && "Wrong MachineOperand accessor");
487     return Contents.RegMask;
488   }
489
490   /// getRegLiveOut - Returns a bit mask of live-out registers.
491   const uint32_t *getRegLiveOut() const {
492     assert(isRegLiveOut() && "Wrong MachineOperand accessor");
493     return Contents.RegMask;
494   }
495
496   const MDNode *getMetadata() const {
497     assert(isMetadata() && "Wrong MachineOperand accessor");
498     return Contents.MD;
499   }
500
501   //===--------------------------------------------------------------------===//
502   // Mutators for various operand types.
503   //===--------------------------------------------------------------------===//
504
505   void setImm(int64_t immVal) {
506     assert(isImm() && "Wrong MachineOperand mutator");
507     Contents.ImmVal = immVal;
508   }
509
510   void setFPImm(const ConstantFP *CFP) {
511     assert(isFPImm() && "Wrong MachineOperand mutator");
512     Contents.CFP = CFP;
513   }
514
515   void setOffset(int64_t Offset) {
516     assert((isGlobal() || isSymbol() || isMCSymbol() || isCPI() ||
517             isTargetIndex() || isBlockAddress()) &&
518            "Wrong MachineOperand accessor");
519     SmallContents.OffsetLo = unsigned(Offset);
520     Contents.OffsetedInfo.OffsetHi = int(Offset >> 32);
521   }
522
523   void setIndex(int Idx) {
524     assert((isFI() || isCPI() || isTargetIndex() || isJTI()) &&
525            "Wrong MachineOperand accessor");
526     Contents.OffsetedInfo.Val.Index = Idx;
527   }
528
529   void setMBB(MachineBasicBlock *MBB) {
530     assert(isMBB() && "Wrong MachineOperand accessor");
531     Contents.MBB = MBB;
532   }
533
534   //===--------------------------------------------------------------------===//
535   // Other methods.
536   //===--------------------------------------------------------------------===//
537
538   /// isIdenticalTo - Return true if this operand is identical to the specified
539   /// operand. Note: This method ignores isKill and isDead properties.
540   bool isIdenticalTo(const MachineOperand &Other) const;
541
542   /// \brief MachineOperand hash_value overload.
543   ///
544   /// Note that this includes the same information in the hash that
545   /// isIdenticalTo uses for comparison. It is thus suited for use in hash
546   /// tables which use that function for equality comparisons only.
547   friend hash_code hash_value(const MachineOperand &MO);
548
549   /// ChangeToImmediate - Replace this operand with a new immediate operand of
550   /// the specified value.  If an operand is known to be an immediate already,
551   /// the setImm method should be used.
552   void ChangeToImmediate(int64_t ImmVal);
553
554   /// ChangeToFPImmediate - Replace this operand with a new FP immediate operand
555   /// of the specified value.  If an operand is known to be an FP immediate
556   /// already, the setFPImm method should be used.
557   void ChangeToFPImmediate(const ConstantFP *FPImm);
558
559   /// ChangeToES - Replace this operand with a new external symbol operand.
560   void ChangeToES(const char *SymName, unsigned char TargetFlags = 0);
561
562   /// ChangeToMCSymbol - Replace this operand with a new MC symbol operand.
563   void ChangeToMCSymbol(MCSymbol *Sym);
564
565   /// ChangeToRegister - Replace this operand with a new register operand of
566   /// the specified value.  If an operand is known to be an register already,
567   /// the setReg method should be used.
568   void ChangeToRegister(unsigned Reg, bool isDef, bool isImp = false,
569                         bool isKill = false, bool isDead = false,
570                         bool isUndef = false, bool isDebug = false);
571
572   //===--------------------------------------------------------------------===//
573   // Construction methods.
574   //===--------------------------------------------------------------------===//
575
576   static MachineOperand CreateImm(int64_t Val) {
577     MachineOperand Op(MachineOperand::MO_Immediate);
578     Op.setImm(Val);
579     return Op;
580   }
581
582   static MachineOperand CreateCImm(const ConstantInt *CI) {
583     MachineOperand Op(MachineOperand::MO_CImmediate);
584     Op.Contents.CI = CI;
585     return Op;
586   }
587
588   static MachineOperand CreateFPImm(const ConstantFP *CFP) {
589     MachineOperand Op(MachineOperand::MO_FPImmediate);
590     Op.Contents.CFP = CFP;
591     return Op;
592   }
593
594   static MachineOperand CreateReg(unsigned Reg, bool isDef, bool isImp = false,
595                                   bool isKill = false, bool isDead = false,
596                                   bool isUndef = false,
597                                   bool isEarlyClobber = false,
598                                   unsigned SubReg = 0,
599                                   bool isDebug = false,
600                                   bool isInternalRead = false) {
601     assert(!(isDead && !isDef) && "Dead flag on non-def");
602     assert(!(isKill && isDef) && "Kill flag on def");
603     MachineOperand Op(MachineOperand::MO_Register);
604     Op.IsDef = isDef;
605     Op.IsImp = isImp;
606     Op.IsKill = isKill;
607     Op.IsDead = isDead;
608     Op.IsUndef = isUndef;
609     Op.IsInternalRead = isInternalRead;
610     Op.IsEarlyClobber = isEarlyClobber;
611     Op.TiedTo = 0;
612     Op.IsDebug = isDebug;
613     Op.SmallContents.RegNo = Reg;
614     Op.Contents.Reg.Prev = nullptr;
615     Op.Contents.Reg.Next = nullptr;
616     Op.setSubReg(SubReg);
617     return Op;
618   }
619   static MachineOperand CreateMBB(MachineBasicBlock *MBB,
620                                   unsigned char TargetFlags = 0) {
621     MachineOperand Op(MachineOperand::MO_MachineBasicBlock);
622     Op.setMBB(MBB);
623     Op.setTargetFlags(TargetFlags);
624     return Op;
625   }
626   static MachineOperand CreateFI(int Idx) {
627     MachineOperand Op(MachineOperand::MO_FrameIndex);
628     Op.setIndex(Idx);
629     return Op;
630   }
631   static MachineOperand CreateCPI(unsigned Idx, int Offset,
632                                   unsigned char TargetFlags = 0) {
633     MachineOperand Op(MachineOperand::MO_ConstantPoolIndex);
634     Op.setIndex(Idx);
635     Op.setOffset(Offset);
636     Op.setTargetFlags(TargetFlags);
637     return Op;
638   }
639   static MachineOperand CreateTargetIndex(unsigned Idx, int64_t Offset,
640                                           unsigned char TargetFlags = 0) {
641     MachineOperand Op(MachineOperand::MO_TargetIndex);
642     Op.setIndex(Idx);
643     Op.setOffset(Offset);
644     Op.setTargetFlags(TargetFlags);
645     return Op;
646   }
647   static MachineOperand CreateJTI(unsigned Idx,
648                                   unsigned char TargetFlags = 0) {
649     MachineOperand Op(MachineOperand::MO_JumpTableIndex);
650     Op.setIndex(Idx);
651     Op.setTargetFlags(TargetFlags);
652     return Op;
653   }
654   static MachineOperand CreateGA(const GlobalValue *GV, int64_t Offset,
655                                  unsigned char TargetFlags = 0) {
656     MachineOperand Op(MachineOperand::MO_GlobalAddress);
657     Op.Contents.OffsetedInfo.Val.GV = GV;
658     Op.setOffset(Offset);
659     Op.setTargetFlags(TargetFlags);
660     return Op;
661   }
662   static MachineOperand CreateES(const char *SymName,
663                                  unsigned char TargetFlags = 0) {
664     MachineOperand Op(MachineOperand::MO_ExternalSymbol);
665     Op.Contents.OffsetedInfo.Val.SymbolName = SymName;
666     Op.setOffset(0); // Offset is always 0.
667     Op.setTargetFlags(TargetFlags);
668     return Op;
669   }
670   static MachineOperand CreateBA(const BlockAddress *BA, int64_t Offset,
671                                  unsigned char TargetFlags = 0) {
672     MachineOperand Op(MachineOperand::MO_BlockAddress);
673     Op.Contents.OffsetedInfo.Val.BA = BA;
674     Op.setOffset(Offset);
675     Op.setTargetFlags(TargetFlags);
676     return Op;
677   }
678   /// CreateRegMask - Creates a register mask operand referencing Mask.  The
679   /// operand does not take ownership of the memory referenced by Mask, it must
680   /// remain valid for the lifetime of the operand.
681   ///
682   /// A RegMask operand represents a set of non-clobbered physical registers on
683   /// an instruction that clobbers many registers, typically a call.  The bit
684   /// mask has a bit set for each physreg that is preserved by this
685   /// instruction, as described in the documentation for
686   /// TargetRegisterInfo::getCallPreservedMask().
687   ///
688   /// Any physreg with a 0 bit in the mask is clobbered by the instruction.
689   ///
690   static MachineOperand CreateRegMask(const uint32_t *Mask) {
691     assert(Mask && "Missing register mask");
692     MachineOperand Op(MachineOperand::MO_RegisterMask);
693     Op.Contents.RegMask = Mask;
694     return Op;
695   }
696   static MachineOperand CreateRegLiveOut(const uint32_t *Mask) {
697     assert(Mask && "Missing live-out register mask");
698     MachineOperand Op(MachineOperand::MO_RegisterLiveOut);
699     Op.Contents.RegMask = Mask;
700     return Op;
701   }
702   static MachineOperand CreateMetadata(const MDNode *Meta) {
703     MachineOperand Op(MachineOperand::MO_Metadata);
704     Op.Contents.MD = Meta;
705     return Op;
706   }
707
708   static MachineOperand CreateMCSymbol(MCSymbol *Sym) {
709     MachineOperand Op(MachineOperand::MO_MCSymbol);
710     Op.Contents.Sym = Sym;
711     Op.setOffset(0);
712     return Op;
713   }
714
715   static MachineOperand CreateCFIIndex(unsigned CFIIndex) {
716     MachineOperand Op(MachineOperand::MO_CFIIndex);
717     Op.Contents.CFIIndex = CFIIndex;
718     return Op;
719   }
720
721   friend class MachineInstr;
722   friend class MachineRegisterInfo;
723 private:
724   void removeRegFromUses();
725
726   //===--------------------------------------------------------------------===//
727   // Methods for handling register use/def lists.
728   //===--------------------------------------------------------------------===//
729
730   /// isOnRegUseList - Return true if this operand is on a register use/def list
731   /// or false if not.  This can only be called for register operands that are
732   /// part of a machine instruction.
733   bool isOnRegUseList() const {
734     assert(isReg() && "Can only add reg operand to use lists");
735     return Contents.Reg.Prev != nullptr;
736   }
737 };
738
739 inline raw_ostream &operator<<(raw_ostream &OS, const MachineOperand& MO) {
740   MO.print(OS, nullptr);
741   return OS;
742 }
743
744   // See friend declaration above. This additional declaration is required in
745   // order to compile LLVM with IBM xlC compiler.
746   hash_code hash_value(const MachineOperand &MO);
747 } // namespace llvm
748
749 #endif