Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

698 lines
25 KiB

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