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