LLVM API Documentation

MachineOperand.h
Go to the documentation of this file.
00001 //===-- llvm/CodeGen/MachineOperand.h - MachineOperand class ----*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file contains the declaration of the MachineOperand class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_CODEGEN_MACHINEOPERAND_H
00015 #define LLVM_CODEGEN_MACHINEOPERAND_H
00016 
00017 #include "llvm/Support/DataTypes.h"
00018 #include <cassert>
00019 
00020 namespace llvm {
00021 
00022 class BlockAddress;
00023 class ConstantFP;
00024 class ConstantInt;
00025 class GlobalValue;
00026 class MachineBasicBlock;
00027 class MachineInstr;
00028 class MachineRegisterInfo;
00029 class MDNode;
00030 class TargetMachine;
00031 class TargetRegisterInfo;
00032 class hash_code;
00033 class raw_ostream;
00034 class MCSymbol;
00035 
00036 /// MachineOperand class - Representation of each machine instruction operand.
00037 ///
00038 /// This class isn't a POD type because it has a private constructor, but its
00039 /// destructor must be trivial. Functions like MachineInstr::addOperand(),
00040 /// MachineRegisterInfo::moveOperands(), and MF::DeleteMachineInstr() depend on
00041 /// not having to call the MachineOperand destructor.
00042 ///
00043 class MachineOperand {
00044 public:
00045   enum MachineOperandType : unsigned char {
00046     MO_Register,          ///< Register operand.
00047     MO_Immediate,         ///< Immediate operand
00048     MO_CImmediate,        ///< Immediate >64bit operand
00049     MO_FPImmediate,       ///< Floating-point immediate operand
00050     MO_MachineBasicBlock, ///< MachineBasicBlock reference
00051     MO_FrameIndex,        ///< Abstract Stack Frame Index
00052     MO_ConstantPoolIndex, ///< Address of indexed Constant in Constant Pool
00053     MO_TargetIndex,       ///< Target-dependent index+offset operand.
00054     MO_JumpTableIndex,    ///< Address of indexed Jump Table for switch
00055     MO_ExternalSymbol,    ///< Name of external global symbol
00056     MO_GlobalAddress,     ///< Address of a global value
00057     MO_BlockAddress,      ///< Address of a basic block
00058     MO_RegisterMask,      ///< Mask of preserved registers.
00059     MO_RegisterLiveOut,   ///< Mask of live-out registers.
00060     MO_Metadata,          ///< Metadata reference (for debug info)
00061     MO_MCSymbol,          ///< MCSymbol reference (for debug/eh info)
00062     MO_CFIIndex           ///< MCCFIInstruction index.
00063   };
00064 
00065 private:
00066   /// OpKind - Specify what kind of operand this is.  This discriminates the
00067   /// union.
00068   MachineOperandType OpKind;
00069 
00070   /// Subregister number for MO_Register.  A value of 0 indicates the
00071   /// MO_Register has no subReg.
00072   ///
00073   /// For all other kinds of operands, this field holds target-specific flags.
00074   unsigned SubReg_TargetFlags : 12;
00075 
00076   /// TiedTo - Non-zero when this register operand is tied to another register
00077   /// operand. The encoding of this field is described in the block comment
00078   /// before MachineInstr::tieOperands().
00079   unsigned char TiedTo : 4;
00080 
00081   /// IsDef/IsImp/IsKill/IsDead flags - These are only valid for MO_Register
00082   /// operands.
00083 
00084   /// IsDef - True if this is a def, false if this is a use of the register.
00085   ///
00086   bool IsDef : 1;
00087 
00088   /// IsImp - True if this is an implicit def or use, false if it is explicit.
00089   ///
00090   bool IsImp : 1;
00091 
00092   /// IsKill - True if this instruction is the last use of the register on this
00093   /// path through the function.  This is only valid on uses of registers.
00094   bool IsKill : 1;
00095 
00096   /// IsDead - True if this register is never used by a subsequent instruction.
00097   /// This is only valid on definitions of registers.
00098   bool IsDead : 1;
00099 
00100   /// IsUndef - True if this register operand reads an "undef" value, i.e. the
00101   /// read value doesn't matter.  This flag can be set on both use and def
00102   /// operands.  On a sub-register def operand, it refers to the part of the
00103   /// register that isn't written.  On a full-register def operand, it is a
00104   /// noop.  See readsReg().
00105   ///
00106   /// This is only valid on registers.
00107   ///
00108   /// Note that an instruction may have multiple <undef> operands referring to
00109   /// the same register.  In that case, the instruction may depend on those
00110   /// operands reading the same dont-care value.  For example:
00111   ///
00112   ///   %vreg1<def> = XOR %vreg2<undef>, %vreg2<undef>
00113   ///
00114   /// Any register can be used for %vreg2, and its value doesn't matter, but
00115   /// the two operands must be the same register.
00116   ///
00117   bool IsUndef : 1;
00118 
00119   /// IsInternalRead - True if this operand reads a value that was defined
00120   /// inside the same instruction or bundle.  This flag can be set on both use
00121   /// and def operands.  On a sub-register def operand, it refers to the part
00122   /// of the register that isn't written.  On a full-register def operand, it
00123   /// is a noop.
00124   ///
00125   /// When this flag is set, the instruction bundle must contain at least one
00126   /// other def of the register.  If multiple instructions in the bundle define
00127   /// the register, the meaning is target-defined.
00128   bool IsInternalRead : 1;
00129 
00130   /// IsEarlyClobber - True if this MO_Register 'def' operand is written to
00131   /// by the MachineInstr before all input registers are read.  This is used to
00132   /// model the GCC inline asm '&' constraint modifier.
00133   bool IsEarlyClobber : 1;
00134 
00135   /// IsDebug - True if this MO_Register 'use' operand is in a debug pseudo,
00136   /// not a real instruction.  Such uses should be ignored during codegen.
00137   bool IsDebug : 1;
00138 
00139   /// SmallContents - This really should be part of the Contents union, but
00140   /// lives out here so we can get a better packed struct.
00141   /// MO_Register: Register number.
00142   /// OffsetedInfo: Low bits of offset.
00143   union {
00144     unsigned RegNo;           // For MO_Register.
00145     unsigned OffsetLo;        // Matches Contents.OffsetedInfo.OffsetHi.
00146   } SmallContents;
00147 
00148   /// ParentMI - This is the instruction that this operand is embedded into.
00149   /// This is valid for all operand types, when the operand is in an instr.
00150   MachineInstr *ParentMI;
00151 
00152   /// Contents union - This contains the payload for the various operand types.
00153   union {
00154     MachineBasicBlock *MBB;  // For MO_MachineBasicBlock.
00155     const ConstantFP *CFP;   // For MO_FPImmediate.
00156     const ConstantInt *CI;   // For MO_CImmediate. Integers > 64bit.
00157     int64_t ImmVal;          // For MO_Immediate.
00158     const uint32_t *RegMask; // For MO_RegisterMask and MO_RegisterLiveOut.
00159     const MDNode *MD;        // For MO_Metadata.
00160     MCSymbol *Sym;           // For MO_MCSymbol.
00161     unsigned CFIIndex;       // For MO_CFI.
00162 
00163     struct {                  // For MO_Register.
00164       // Register number is in SmallContents.RegNo.
00165       MachineOperand *Prev;   // Access list for register. See MRI.
00166       MachineOperand *Next;
00167     } Reg;
00168 
00169     /// OffsetedInfo - This struct contains the offset and an object identifier.
00170     /// this represent the object as with an optional offset from it.
00171     struct {
00172       union {
00173         int Index;                // For MO_*Index - The index itself.
00174         const char *SymbolName;   // For MO_ExternalSymbol.
00175         const GlobalValue *GV;    // For MO_GlobalAddress.
00176         const BlockAddress *BA;   // For MO_BlockAddress.
00177       } Val;
00178       // Low bits of offset are in SmallContents.OffsetLo.
00179       int OffsetHi;               // An offset from the object, high 32 bits.
00180     } OffsetedInfo;
00181   } Contents;
00182 
00183   explicit MachineOperand(MachineOperandType K)
00184     : OpKind(K), SubReg_TargetFlags(0), ParentMI(nullptr) {}
00185 public:
00186   /// getType - Returns the MachineOperandType for this operand.
00187   ///
00188   MachineOperandType getType() const { return (MachineOperandType)OpKind; }
00189 
00190   unsigned getTargetFlags() const {
00191     return isReg() ? 0 : SubReg_TargetFlags;
00192   }
00193   void setTargetFlags(unsigned F) {
00194     assert(!isReg() && "Register operands can't have target flags");
00195     SubReg_TargetFlags = F;
00196     assert(SubReg_TargetFlags == F && "Target flags out of range");
00197   }
00198   void addTargetFlag(unsigned F) {
00199     assert(!isReg() && "Register operands can't have target flags");
00200     SubReg_TargetFlags |= F;
00201     assert((SubReg_TargetFlags & F) && "Target flags out of range");
00202   }
00203 
00204 
00205   /// getParent - Return the instruction that this operand belongs to.
00206   ///
00207   MachineInstr *getParent() { return ParentMI; }
00208   const MachineInstr *getParent() const { return ParentMI; }
00209 
00210   /// clearParent - Reset the parent pointer.
00211   ///
00212   /// The MachineOperand copy constructor also copies ParentMI, expecting the
00213   /// original to be deleted. If a MachineOperand is ever stored outside a
00214   /// MachineInstr, the parent pointer must be cleared.
00215   ///
00216   /// Never call clearParent() on an operand in a MachineInstr.
00217   ///
00218   void clearParent() { ParentMI = nullptr; }
00219 
00220   void print(raw_ostream &os, const TargetMachine *TM = nullptr) const;
00221 
00222   //===--------------------------------------------------------------------===//
00223   // Accessors that tell you what kind of MachineOperand you're looking at.
00224   //===--------------------------------------------------------------------===//
00225 
00226   /// isReg - Tests if this is a MO_Register operand.
00227   bool isReg() const { return OpKind == MO_Register; }
00228   /// isImm - Tests if this is a MO_Immediate operand.
00229   bool isImm() const { return OpKind == MO_Immediate; }
00230   /// isCImm - Test if this is a MO_CImmediate operand.
00231   bool isCImm() const { return OpKind == MO_CImmediate; }
00232   /// isFPImm - Tests if this is a MO_FPImmediate operand.
00233   bool isFPImm() const { return OpKind == MO_FPImmediate; }
00234   /// isMBB - Tests if this is a MO_MachineBasicBlock operand.
00235   bool isMBB() const { return OpKind == MO_MachineBasicBlock; }
00236   /// isFI - Tests if this is a MO_FrameIndex operand.
00237   bool isFI() const { return OpKind == MO_FrameIndex; }
00238   /// isCPI - Tests if this is a MO_ConstantPoolIndex operand.
00239   bool isCPI() const { return OpKind == MO_ConstantPoolIndex; }
00240   /// isTargetIndex - Tests if this is a MO_TargetIndex operand.
00241   bool isTargetIndex() const { return OpKind == MO_TargetIndex; }
00242   /// isJTI - Tests if this is a MO_JumpTableIndex operand.
00243   bool isJTI() const { return OpKind == MO_JumpTableIndex; }
00244   /// isGlobal - Tests if this is a MO_GlobalAddress operand.
00245   bool isGlobal() const { return OpKind == MO_GlobalAddress; }
00246   /// isSymbol - Tests if this is a MO_ExternalSymbol operand.
00247   bool isSymbol() const { return OpKind == MO_ExternalSymbol; }
00248   /// isBlockAddress - Tests if this is a MO_BlockAddress operand.
00249   bool isBlockAddress() const { return OpKind == MO_BlockAddress; }
00250   /// isRegMask - Tests if this is a MO_RegisterMask operand.
00251   bool isRegMask() const { return OpKind == MO_RegisterMask; }
00252   /// isRegLiveOut - Tests if this is a MO_RegisterLiveOut operand.
00253   bool isRegLiveOut() const { return OpKind == MO_RegisterLiveOut; }
00254   /// isMetadata - Tests if this is a MO_Metadata operand.
00255   bool isMetadata() const { return OpKind == MO_Metadata; }
00256   bool isMCSymbol() const { return OpKind == MO_MCSymbol; }
00257   bool isCFIIndex() const { return OpKind == MO_CFIIndex; }
00258 
00259   //===--------------------------------------------------------------------===//
00260   // Accessors for Register Operands
00261   //===--------------------------------------------------------------------===//
00262 
00263   /// getReg - Returns the register number.
00264   unsigned getReg() const {
00265     assert(isReg() && "This is not a register operand!");
00266     return SmallContents.RegNo;
00267   }
00268 
00269   unsigned getSubReg() const {
00270     assert(isReg() && "Wrong MachineOperand accessor");
00271     return SubReg_TargetFlags;
00272   }
00273 
00274   bool isUse() const {
00275     assert(isReg() && "Wrong MachineOperand accessor");
00276     return !IsDef;
00277   }
00278 
00279   bool isDef() const {
00280     assert(isReg() && "Wrong MachineOperand accessor");
00281     return IsDef;
00282   }
00283 
00284   bool isImplicit() const {
00285     assert(isReg() && "Wrong MachineOperand accessor");
00286     return IsImp;
00287   }
00288 
00289   bool isDead() const {
00290     assert(isReg() && "Wrong MachineOperand accessor");
00291     return IsDead;
00292   }
00293 
00294   bool isKill() const {
00295     assert(isReg() && "Wrong MachineOperand accessor");
00296     return IsKill;
00297   }
00298 
00299   bool isUndef() const {
00300     assert(isReg() && "Wrong MachineOperand accessor");
00301     return IsUndef;
00302   }
00303 
00304   bool isInternalRead() const {
00305     assert(isReg() && "Wrong MachineOperand accessor");
00306     return IsInternalRead;
00307   }
00308 
00309   bool isEarlyClobber() const {
00310     assert(isReg() && "Wrong MachineOperand accessor");
00311     return IsEarlyClobber;
00312   }
00313 
00314   bool isTied() const {
00315     assert(isReg() && "Wrong MachineOperand accessor");
00316     return TiedTo;
00317   }
00318 
00319   bool isDebug() const {
00320     assert(isReg() && "Wrong MachineOperand accessor");
00321     return IsDebug;
00322   }
00323 
00324   /// readsReg - Returns true if this operand reads the previous value of its
00325   /// register.  A use operand with the <undef> flag set doesn't read its
00326   /// register.  A sub-register def implicitly reads the other parts of the
00327   /// register being redefined unless the <undef> flag is set.
00328   ///
00329   /// This refers to reading the register value from before the current
00330   /// instruction or bundle. Internal bundle reads are not included.
00331   bool readsReg() const {
00332     assert(isReg() && "Wrong MachineOperand accessor");
00333     return !isUndef() && !isInternalRead() && (isUse() || getSubReg());
00334   }
00335 
00336   //===--------------------------------------------------------------------===//
00337   // Mutators for Register Operands
00338   //===--------------------------------------------------------------------===//
00339 
00340   /// Change the register this operand corresponds to.
00341   ///
00342   void setReg(unsigned Reg);
00343 
00344   void setSubReg(unsigned subReg) {
00345     assert(isReg() && "Wrong MachineOperand accessor");
00346     SubReg_TargetFlags = subReg;
00347     assert(SubReg_TargetFlags == subReg && "SubReg out of range");
00348   }
00349 
00350   /// substVirtReg - Substitute the current register with the virtual
00351   /// subregister Reg:SubReg. Take any existing SubReg index into account,
00352   /// using TargetRegisterInfo to compose the subreg indices if necessary.
00353   /// Reg must be a virtual register, SubIdx can be 0.
00354   ///
00355   void substVirtReg(unsigned Reg, unsigned SubIdx, const TargetRegisterInfo&);
00356 
00357   /// substPhysReg - Substitute the current register with the physical register
00358   /// Reg, taking any existing SubReg into account. For instance,
00359   /// substPhysReg(%EAX) will change %reg1024:sub_8bit to %AL.
00360   ///
00361   void substPhysReg(unsigned Reg, const TargetRegisterInfo&);
00362 
00363   void setIsUse(bool Val = true) { setIsDef(!Val); }
00364 
00365   void setIsDef(bool Val = true);
00366 
00367   void setImplicit(bool Val = true) {
00368     assert(isReg() && "Wrong MachineOperand accessor");
00369     IsImp = Val;
00370   }
00371 
00372   void setIsKill(bool Val = true) {
00373     assert(isReg() && !IsDef && "Wrong MachineOperand accessor");
00374     assert((!Val || !isDebug()) && "Marking a debug operation as kill");
00375     IsKill = Val;
00376   }
00377 
00378   void setIsDead(bool Val = true) {
00379     assert(isReg() && IsDef && "Wrong MachineOperand accessor");
00380     IsDead = Val;
00381   }
00382 
00383   void setIsUndef(bool Val = true) {
00384     assert(isReg() && "Wrong MachineOperand accessor");
00385     IsUndef = Val;
00386   }
00387 
00388   void setIsInternalRead(bool Val = true) {
00389     assert(isReg() && "Wrong MachineOperand accessor");
00390     IsInternalRead = Val;
00391   }
00392 
00393   void setIsEarlyClobber(bool Val = true) {
00394     assert(isReg() && IsDef && "Wrong MachineOperand accessor");
00395     IsEarlyClobber = Val;
00396   }
00397 
00398   void setIsDebug(bool Val = true) {
00399     assert(isReg() && !IsDef && "Wrong MachineOperand accessor");
00400     IsDebug = Val;
00401   }
00402 
00403   //===--------------------------------------------------------------------===//
00404   // Accessors for various operand types.
00405   //===--------------------------------------------------------------------===//
00406 
00407   int64_t getImm() const {
00408     assert(isImm() && "Wrong MachineOperand accessor");
00409     return Contents.ImmVal;
00410   }
00411 
00412   const ConstantInt *getCImm() const {
00413     assert(isCImm() && "Wrong MachineOperand accessor");
00414     return Contents.CI;
00415   }
00416 
00417   const ConstantFP *getFPImm() const {
00418     assert(isFPImm() && "Wrong MachineOperand accessor");
00419     return Contents.CFP;
00420   }
00421 
00422   MachineBasicBlock *getMBB() const {
00423     assert(isMBB() && "Wrong MachineOperand accessor");
00424     return Contents.MBB;
00425   }
00426 
00427   int getIndex() const {
00428     assert((isFI() || isCPI() || isTargetIndex() || isJTI()) &&
00429            "Wrong MachineOperand accessor");
00430     return Contents.OffsetedInfo.Val.Index;
00431   }
00432 
00433   const GlobalValue *getGlobal() const {
00434     assert(isGlobal() && "Wrong MachineOperand accessor");
00435     return Contents.OffsetedInfo.Val.GV;
00436   }
00437 
00438   const BlockAddress *getBlockAddress() const {
00439     assert(isBlockAddress() && "Wrong MachineOperand accessor");
00440     return Contents.OffsetedInfo.Val.BA;
00441   }
00442 
00443   MCSymbol *getMCSymbol() const {
00444     assert(isMCSymbol() && "Wrong MachineOperand accessor");
00445     return Contents.Sym;
00446   }
00447 
00448   unsigned getCFIIndex() const {
00449     assert(isCFIIndex() && "Wrong MachineOperand accessor");
00450     return Contents.CFIIndex;
00451   }
00452 
00453   /// getOffset - Return the offset from the symbol in this operand. This always
00454   /// returns 0 for ExternalSymbol operands.
00455   int64_t getOffset() const {
00456     assert((isGlobal() || isSymbol() || isCPI() || isTargetIndex() ||
00457             isBlockAddress()) && "Wrong MachineOperand accessor");
00458     return int64_t(uint64_t(Contents.OffsetedInfo.OffsetHi) << 32) |
00459            SmallContents.OffsetLo;
00460   }
00461 
00462   const char *getSymbolName() const {
00463     assert(isSymbol() && "Wrong MachineOperand accessor");
00464     return Contents.OffsetedInfo.Val.SymbolName;
00465   }
00466 
00467   /// clobbersPhysReg - Returns true if this RegMask clobbers PhysReg.
00468   /// It is sometimes necessary to detach the register mask pointer from its
00469   /// machine operand. This static method can be used for such detached bit
00470   /// mask pointers.
00471   static bool clobbersPhysReg(const uint32_t *RegMask, unsigned PhysReg) {
00472     // See TargetRegisterInfo.h.
00473     assert(PhysReg < (1u << 30) && "Not a physical register");
00474     return !(RegMask[PhysReg / 32] & (1u << PhysReg % 32));
00475   }
00476 
00477   /// clobbersPhysReg - Returns true if this RegMask operand clobbers PhysReg.
00478   bool clobbersPhysReg(unsigned PhysReg) const {
00479      return clobbersPhysReg(getRegMask(), PhysReg);
00480   }
00481 
00482   /// getRegMask - Returns a bit mask of registers preserved by this RegMask
00483   /// operand.
00484   const uint32_t *getRegMask() const {
00485     assert(isRegMask() && "Wrong MachineOperand accessor");
00486     return Contents.RegMask;
00487   }
00488 
00489   /// getRegLiveOut - Returns a bit mask of live-out registers.
00490   const uint32_t *getRegLiveOut() const {
00491     assert(isRegLiveOut() && "Wrong MachineOperand accessor");
00492     return Contents.RegMask;
00493   }
00494 
00495   const MDNode *getMetadata() const {
00496     assert(isMetadata() && "Wrong MachineOperand accessor");
00497     return Contents.MD;
00498   }
00499 
00500   //===--------------------------------------------------------------------===//
00501   // Mutators for various operand types.
00502   //===--------------------------------------------------------------------===//
00503 
00504   void setImm(int64_t immVal) {
00505     assert(isImm() && "Wrong MachineOperand mutator");
00506     Contents.ImmVal = immVal;
00507   }
00508 
00509   void setOffset(int64_t Offset) {
00510     assert((isGlobal() || isSymbol() || isCPI() || isTargetIndex() ||
00511             isBlockAddress()) && "Wrong MachineOperand accessor");
00512     SmallContents.OffsetLo = unsigned(Offset);
00513     Contents.OffsetedInfo.OffsetHi = int(Offset >> 32);
00514   }
00515 
00516   void setIndex(int Idx) {
00517     assert((isFI() || isCPI() || isTargetIndex() || isJTI()) &&
00518            "Wrong MachineOperand accessor");
00519     Contents.OffsetedInfo.Val.Index = Idx;
00520   }
00521 
00522   void setMBB(MachineBasicBlock *MBB) {
00523     assert(isMBB() && "Wrong MachineOperand accessor");
00524     Contents.MBB = MBB;
00525   }
00526 
00527   //===--------------------------------------------------------------------===//
00528   // Other methods.
00529   //===--------------------------------------------------------------------===//
00530 
00531   /// isIdenticalTo - Return true if this operand is identical to the specified
00532   /// operand. Note: This method ignores isKill and isDead properties.
00533   bool isIdenticalTo(const MachineOperand &Other) const;
00534 
00535   /// \brief MachineOperand hash_value overload.
00536   ///
00537   /// Note that this includes the same information in the hash that
00538   /// isIdenticalTo uses for comparison. It is thus suited for use in hash
00539   /// tables which use that function for equality comparisons only.
00540   friend hash_code hash_value(const MachineOperand &MO);
00541 
00542   /// ChangeToImmediate - Replace this operand with a new immediate operand of
00543   /// the specified value.  If an operand is known to be an immediate already,
00544   /// the setImm method should be used.
00545   void ChangeToImmediate(int64_t ImmVal);
00546 
00547   /// ChangeToRegister - Replace this operand with a new register operand of
00548   /// the specified value.  If an operand is known to be an register already,
00549   /// the setReg method should be used.
00550   void ChangeToRegister(unsigned Reg, bool isDef, bool isImp = false,
00551                         bool isKill = false, bool isDead = false,
00552                         bool isUndef = false, bool isDebug = false);
00553 
00554   //===--------------------------------------------------------------------===//
00555   // Construction methods.
00556   //===--------------------------------------------------------------------===//
00557 
00558   static MachineOperand CreateImm(int64_t Val) {
00559     MachineOperand Op(MachineOperand::MO_Immediate);
00560     Op.setImm(Val);
00561     return Op;
00562   }
00563 
00564   static MachineOperand CreateCImm(const ConstantInt *CI) {
00565     MachineOperand Op(MachineOperand::MO_CImmediate);
00566     Op.Contents.CI = CI;
00567     return Op;
00568   }
00569 
00570   static MachineOperand CreateFPImm(const ConstantFP *CFP) {
00571     MachineOperand Op(MachineOperand::MO_FPImmediate);
00572     Op.Contents.CFP = CFP;
00573     return Op;
00574   }
00575 
00576   static MachineOperand CreateReg(unsigned Reg, bool isDef, bool isImp = false,
00577                                   bool isKill = false, bool isDead = false,
00578                                   bool isUndef = false,
00579                                   bool isEarlyClobber = false,
00580                                   unsigned SubReg = 0,
00581                                   bool isDebug = false,
00582                                   bool isInternalRead = false) {
00583     assert(!(isDead && !isDef) && "Dead flag on non-def");
00584     assert(!(isKill && isDef) && "Kill flag on def");
00585     MachineOperand Op(MachineOperand::MO_Register);
00586     Op.IsDef = isDef;
00587     Op.IsImp = isImp;
00588     Op.IsKill = isKill;
00589     Op.IsDead = isDead;
00590     Op.IsUndef = isUndef;
00591     Op.IsInternalRead = isInternalRead;
00592     Op.IsEarlyClobber = isEarlyClobber;
00593     Op.TiedTo = 0;
00594     Op.IsDebug = isDebug;
00595     Op.SmallContents.RegNo = Reg;
00596     Op.Contents.Reg.Prev = nullptr;
00597     Op.Contents.Reg.Next = nullptr;
00598     Op.setSubReg(SubReg);
00599     return Op;
00600   }
00601   static MachineOperand CreateMBB(MachineBasicBlock *MBB,
00602                                   unsigned char TargetFlags = 0) {
00603     MachineOperand Op(MachineOperand::MO_MachineBasicBlock);
00604     Op.setMBB(MBB);
00605     Op.setTargetFlags(TargetFlags);
00606     return Op;
00607   }
00608   static MachineOperand CreateFI(int Idx) {
00609     MachineOperand Op(MachineOperand::MO_FrameIndex);
00610     Op.setIndex(Idx);
00611     return Op;
00612   }
00613   static MachineOperand CreateCPI(unsigned Idx, int Offset,
00614                                   unsigned char TargetFlags = 0) {
00615     MachineOperand Op(MachineOperand::MO_ConstantPoolIndex);
00616     Op.setIndex(Idx);
00617     Op.setOffset(Offset);
00618     Op.setTargetFlags(TargetFlags);
00619     return Op;
00620   }
00621   static MachineOperand CreateTargetIndex(unsigned Idx, int64_t Offset,
00622                                           unsigned char TargetFlags = 0) {
00623     MachineOperand Op(MachineOperand::MO_TargetIndex);
00624     Op.setIndex(Idx);
00625     Op.setOffset(Offset);
00626     Op.setTargetFlags(TargetFlags);
00627     return Op;
00628   }
00629   static MachineOperand CreateJTI(unsigned Idx,
00630                                   unsigned char TargetFlags = 0) {
00631     MachineOperand Op(MachineOperand::MO_JumpTableIndex);
00632     Op.setIndex(Idx);
00633     Op.setTargetFlags(TargetFlags);
00634     return Op;
00635   }
00636   static MachineOperand CreateGA(const GlobalValue *GV, int64_t Offset,
00637                                  unsigned char TargetFlags = 0) {
00638     MachineOperand Op(MachineOperand::MO_GlobalAddress);
00639     Op.Contents.OffsetedInfo.Val.GV = GV;
00640     Op.setOffset(Offset);
00641     Op.setTargetFlags(TargetFlags);
00642     return Op;
00643   }
00644   static MachineOperand CreateES(const char *SymName,
00645                                  unsigned char TargetFlags = 0) {
00646     MachineOperand Op(MachineOperand::MO_ExternalSymbol);
00647     Op.Contents.OffsetedInfo.Val.SymbolName = SymName;
00648     Op.setOffset(0); // Offset is always 0.
00649     Op.setTargetFlags(TargetFlags);
00650     return Op;
00651   }
00652   static MachineOperand CreateBA(const BlockAddress *BA, int64_t Offset,
00653                                  unsigned char TargetFlags = 0) {
00654     MachineOperand Op(MachineOperand::MO_BlockAddress);
00655     Op.Contents.OffsetedInfo.Val.BA = BA;
00656     Op.setOffset(Offset);
00657     Op.setTargetFlags(TargetFlags);
00658     return Op;
00659   }
00660   /// CreateRegMask - Creates a register mask operand referencing Mask.  The
00661   /// operand does not take ownership of the memory referenced by Mask, it must
00662   /// remain valid for the lifetime of the operand.
00663   ///
00664   /// A RegMask operand represents a set of non-clobbered physical registers on
00665   /// an instruction that clobbers many registers, typically a call.  The bit
00666   /// mask has a bit set for each physreg that is preserved by this
00667   /// instruction, as described in the documentation for
00668   /// TargetRegisterInfo::getCallPreservedMask().
00669   ///
00670   /// Any physreg with a 0 bit in the mask is clobbered by the instruction.
00671   ///
00672   static MachineOperand CreateRegMask(const uint32_t *Mask) {
00673     assert(Mask && "Missing register mask");
00674     MachineOperand Op(MachineOperand::MO_RegisterMask);
00675     Op.Contents.RegMask = Mask;
00676     return Op;
00677   }
00678   static MachineOperand CreateRegLiveOut(const uint32_t *Mask) {
00679     assert(Mask && "Missing live-out register mask");
00680     MachineOperand Op(MachineOperand::MO_RegisterLiveOut);
00681     Op.Contents.RegMask = Mask;
00682     return Op;
00683   }
00684   static MachineOperand CreateMetadata(const MDNode *Meta) {
00685     MachineOperand Op(MachineOperand::MO_Metadata);
00686     Op.Contents.MD = Meta;
00687     return Op;
00688   }
00689 
00690   static MachineOperand CreateMCSymbol(MCSymbol *Sym) {
00691     MachineOperand Op(MachineOperand::MO_MCSymbol);
00692     Op.Contents.Sym = Sym;
00693     return Op;
00694   }
00695 
00696   static MachineOperand CreateCFIIndex(unsigned CFIIndex) {
00697     MachineOperand Op(MachineOperand::MO_CFIIndex);
00698     Op.Contents.CFIIndex = CFIIndex;
00699     return Op;
00700   }
00701 
00702   friend class MachineInstr;
00703   friend class MachineRegisterInfo;
00704 private:
00705   //===--------------------------------------------------------------------===//
00706   // Methods for handling register use/def lists.
00707   //===--------------------------------------------------------------------===//
00708 
00709   /// isOnRegUseList - Return true if this operand is on a register use/def list
00710   /// or false if not.  This can only be called for register operands that are
00711   /// part of a machine instruction.
00712   bool isOnRegUseList() const {
00713     assert(isReg() && "Can only add reg operand to use lists");
00714     return Contents.Reg.Prev != nullptr;
00715   }
00716 };
00717 
00718 inline raw_ostream &operator<<(raw_ostream &OS, const MachineOperand& MO) {
00719   MO.print(OS, nullptr);
00720   return OS;
00721 }
00722 
00723   // See friend declaration above. This additional declaration is required in
00724   // order to compile LLVM with IBM xlC compiler.
00725   hash_code hash_value(const MachineOperand &MO);
00726 } // End llvm namespace
00727 
00728 #endif