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