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