1894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===-- llvm/CodeGen/MachineOperand.h - MachineOperand class ----*- C++ -*-===//
2894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
3894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//                     The LLVM Compiler Infrastructure
4894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
5894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This file is distributed under the University of Illinois Open Source
6894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// License. See LICENSE.TXT for details.
7894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
8894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===//
9894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
10894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This file contains the declaration of the MachineOperand class.
11894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
12894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===//
13894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
14894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#ifndef LLVM_CODEGEN_MACHINEOPERAND_H
15894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#define LLVM_CODEGEN_MACHINEOPERAND_H
16894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman#include "llvm/Support/DataTypes.h"
18894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include <cassert>
19894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
20894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumannamespace llvm {
2119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
22894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass BlockAddress;
23894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass ConstantFP;
2419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Baumanclass ConstantInt;
25894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass GlobalValue;
26894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass MachineBasicBlock;
27894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass MachineInstr;
28894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass MachineRegisterInfo;
29894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass MDNode;
30894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass TargetMachine;
31894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass TargetRegisterInfo;
32894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass raw_ostream;
33894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass MCSymbol;
3419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
35894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// MachineOperand class - Representation of each machine instruction operand.
36894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman///
37894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass MachineOperand {
38894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanpublic:
39894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  enum MachineOperandType {
40894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MO_Register,               ///< Register operand.
41894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MO_Immediate,              ///< Immediate operand
4219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    MO_CImmediate,             ///< Immediate >64bit operand
43894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MO_FPImmediate,            ///< Floating-point immediate operand
44894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MO_MachineBasicBlock,      ///< MachineBasicBlock reference
45894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MO_FrameIndex,             ///< Abstract Stack Frame Index
46894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MO_ConstantPoolIndex,      ///< Address of indexed Constant in Constant Pool
47894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MO_JumpTableIndex,         ///< Address of indexed Jump Table for switch
48894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MO_ExternalSymbol,         ///< Name of external global symbol
49894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MO_GlobalAddress,          ///< Address of a global value
50894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MO_BlockAddress,           ///< Address of a basic block
51894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MO_Metadata,               ///< Metadata reference (for debug info)
52894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MO_MCSymbol                ///< MCSymbol reference (for debug/eh info)
53894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  };
54894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
55894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanprivate:
56894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// OpKind - Specify what kind of operand this is.  This discriminates the
57894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// union.
58894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  unsigned char OpKind; // MachineOperandType
5919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
60894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// SubReg - Subregister number, only valid for MO_Register.  A value of 0
61894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// indicates the MO_Register has no subReg.
62894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  unsigned char SubReg;
6319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
64894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// TargetFlags - This is a set of target-specific operand flags.
65894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  unsigned char TargetFlags;
6619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
67894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// IsDef/IsImp/IsKill/IsDead flags - These are only valid for MO_Register
68894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// operands.
6919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
70894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// IsDef - True if this is a def, false if this is a use of the register.
71894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
72894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool IsDef : 1;
7319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
74894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// IsImp - True if this is an implicit def or use, false if it is explicit.
75894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
76894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool IsImp : 1;
77894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
78894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// IsKill - True if this instruction is the last use of the register on this
79894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// path through the function.  This is only valid on uses of registers.
80894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool IsKill : 1;
81894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
82894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// IsDead - True if this register is never used by a subsequent instruction.
83894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// This is only valid on definitions of registers.
84894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool IsDead : 1;
85894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
8619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// IsUndef - True if this register operand reads an "undef" value, i.e. the
8719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// read value doesn't matter.  This flag can be set on both use and def
8819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// operands.  On a sub-register def operand, it refers to the part of the
8919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// register that isn't written.  On a full-register def operand, it is a
9019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// noop.  See readsReg().
9119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  ///
9219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// This is only valid on registers.
9319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  ///
9419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// Note that an instruction may have multiple <undef> operands referring to
9519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// the same register.  In that case, the instruction may depend on those
9619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// operands reading the same dont-care value.  For example:
9719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  ///
9819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  ///   %vreg1<def> = XOR %vreg2<undef>, %vreg2<undef>
9919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  ///
10019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// Any register can be used for %vreg2, and its value doesn't matter, but
10119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// the two operands must be the same register.
10219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  ///
103894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool IsUndef : 1;
104894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
105894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// IsEarlyClobber - True if this MO_Register 'def' operand is written to
106894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// by the MachineInstr before all input registers are read.  This is used to
107894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// model the GCC inline asm '&' constraint modifier.
108894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool IsEarlyClobber : 1;
109894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
110894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// IsDebug - True if this MO_Register 'use' operand is in a debug pseudo,
111894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// not a real instruction.  Such uses should be ignored during codegen.
112894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool IsDebug : 1;
113894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
11419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// SmallContents - This really should be part of the Contents union, but
11519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// lives out here so we can get a better packed struct.
11619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// MO_Register: Register number.
11719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// OffsetedInfo: Low bits of offset.
11819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  union {
11919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    unsigned RegNo;           // For MO_Register.
12019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    unsigned OffsetLo;        // Matches Contents.OffsetedInfo.OffsetHi.
12119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  } SmallContents;
12219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
12319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// ParentMI - This is the instruction that this operand is embedded into.
124894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// This is valid for all operand types, when the operand is in an instr.
125894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MachineInstr *ParentMI;
126894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
127894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// Contents union - This contains the payload for the various operand types.
128894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  union {
129894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MachineBasicBlock *MBB;   // For MO_MachineBasicBlock.
130894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    const ConstantFP *CFP;    // For MO_FPImmediate.
13119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    const ConstantInt *CI;    // For MO_CImmediate. Integers > 64bit.
132894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    int64_t ImmVal;           // For MO_Immediate.
133894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    const MDNode *MD;         // For MO_Metadata.
134894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MCSymbol *Sym;            // For MO_MCSymbol
135894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
136894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    struct {                  // For MO_Register.
13719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      // Register number is in SmallContents.RegNo.
138894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      MachineOperand **Prev;  // Access list for register.
139894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      MachineOperand *Next;
140894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    } Reg;
14119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
142894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// OffsetedInfo - This struct contains the offset and an object identifier.
143894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// this represent the object as with an optional offset from it.
144894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    struct {
145894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      union {
146894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        int Index;                // For MO_*Index - The index itself.
147894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        const char *SymbolName;   // For MO_ExternalSymbol.
148894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        const GlobalValue *GV;    // For MO_GlobalAddress.
149894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        const BlockAddress *BA;   // For MO_BlockAddress.
150894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      } Val;
15119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      // Low bits of offset are in SmallContents.OffsetLo.
15219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      int OffsetHi;               // An offset from the object, high 32 bits.
153894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    } OffsetedInfo;
154894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  } Contents;
15519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
156894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  explicit MachineOperand(MachineOperandType K) : OpKind(K), ParentMI(0) {
157894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    TargetFlags = 0;
158894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
159894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanpublic:
160894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// getType - Returns the MachineOperandType for this operand.
161894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
162894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MachineOperandType getType() const { return (MachineOperandType)OpKind; }
16319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
164894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  unsigned char getTargetFlags() const { return TargetFlags; }
165894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void setTargetFlags(unsigned char F) { TargetFlags = F; }
166894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void addTargetFlag(unsigned char F) { TargetFlags |= F; }
16719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
168894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
169894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// getParent - Return the instruction that this operand belongs to.
170894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
171894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MachineInstr *getParent() { return ParentMI; }
172894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  const MachineInstr *getParent() const { return ParentMI; }
17319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
17419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// clearParent - Reset the parent pointer.
17519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  ///
17619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// The MachineOperand copy constructor also copies ParentMI, expecting the
17719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// original to be deleted. If a MachineOperand is ever stored outside a
17819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// MachineInstr, the parent pointer must be cleared.
17919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  ///
18019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// Never call clearParent() on an operand in a MachineInstr.
18119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  ///
18219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  void clearParent() { ParentMI = 0; }
18319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
184894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void print(raw_ostream &os, const TargetMachine *TM = 0) const;
185894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
186894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  //===--------------------------------------------------------------------===//
187894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // Accessors that tell you what kind of MachineOperand you're looking at.
188894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  //===--------------------------------------------------------------------===//
189894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
190894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// isReg - Tests if this is a MO_Register operand.
191894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool isReg() const { return OpKind == MO_Register; }
192894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// isImm - Tests if this is a MO_Immediate operand.
193894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool isImm() const { return OpKind == MO_Immediate; }
19419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// isCImm - Test if t his is a MO_CImmediate operand.
19519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool isCImm() const { return OpKind == MO_CImmediate; }
196894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// isFPImm - Tests if this is a MO_FPImmediate operand.
197894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool isFPImm() const { return OpKind == MO_FPImmediate; }
198894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// isMBB - Tests if this is a MO_MachineBasicBlock operand.
199894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool isMBB() const { return OpKind == MO_MachineBasicBlock; }
200894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// isFI - Tests if this is a MO_FrameIndex operand.
201894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool isFI() const { return OpKind == MO_FrameIndex; }
202894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// isCPI - Tests if this is a MO_ConstantPoolIndex operand.
203894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool isCPI() const { return OpKind == MO_ConstantPoolIndex; }
204894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// isJTI - Tests if this is a MO_JumpTableIndex operand.
205894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool isJTI() const { return OpKind == MO_JumpTableIndex; }
206894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// isGlobal - Tests if this is a MO_GlobalAddress operand.
207894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool isGlobal() const { return OpKind == MO_GlobalAddress; }
208894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// isSymbol - Tests if this is a MO_ExternalSymbol operand.
209894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool isSymbol() const { return OpKind == MO_ExternalSymbol; }
210894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// isBlockAddress - Tests if this is a MO_BlockAddress operand.
211894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool isBlockAddress() const { return OpKind == MO_BlockAddress; }
212894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// isMetadata - Tests if this is a MO_Metadata operand.
213894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool isMetadata() const { return OpKind == MO_Metadata; }
214894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool isMCSymbol() const { return OpKind == MO_MCSymbol; }
215894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
216894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  //===--------------------------------------------------------------------===//
217894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // Accessors for Register Operands
218894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  //===--------------------------------------------------------------------===//
219894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
220894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// getReg - Returns the register number.
221894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  unsigned getReg() const {
222894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isReg() && "This is not a register operand!");
22319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return SmallContents.RegNo;
224894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
22519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
226894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  unsigned getSubReg() const {
227894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isReg() && "Wrong MachineOperand accessor");
228894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return (unsigned)SubReg;
229894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
23019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
23119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool isUse() const {
232894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isReg() && "Wrong MachineOperand accessor");
233894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return !IsDef;
234894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
23519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
236894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool isDef() const {
237894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isReg() && "Wrong MachineOperand accessor");
238894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return IsDef;
239894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
24019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
24119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool isImplicit() const {
242894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isReg() && "Wrong MachineOperand accessor");
243894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return IsImp;
244894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
24519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
246894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool isDead() const {
247894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isReg() && "Wrong MachineOperand accessor");
248894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return IsDead;
249894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
25019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
251894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool isKill() const {
252894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isReg() && "Wrong MachineOperand accessor");
253894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return IsKill;
254894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
25519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
256894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool isUndef() const {
257894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isReg() && "Wrong MachineOperand accessor");
258894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return IsUndef;
259894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
26019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
261894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool isEarlyClobber() const {
262894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isReg() && "Wrong MachineOperand accessor");
263894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return IsEarlyClobber;
264894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
265894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
266894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool isDebug() const {
267894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isReg() && "Wrong MachineOperand accessor");
268894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return IsDebug;
269894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
270894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
27119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// readsReg - Returns true if this operand reads the previous value of its
27219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// register.  A use operand with the <undef> flag set doesn't read its
27319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// register.  A sub-register def implicitly reads the other parts of the
27419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// register being redefined unless the <undef> flag is set.
27519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  bool readsReg() const {
27619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    assert(isReg() && "Wrong MachineOperand accessor");
27719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return !isUndef() && (isUse() || getSubReg());
27819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
27919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
280894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// getNextOperandForReg - Return the next MachineOperand in the function that
281894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// uses or defines this register.
282894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MachineOperand *getNextOperandForReg() const {
283894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isReg() && "This is not a register operand!");
284894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return Contents.Reg.Next;
285894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
286894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
287894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  //===--------------------------------------------------------------------===//
288894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // Mutators for Register Operands
289894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  //===--------------------------------------------------------------------===//
29019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
291894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// Change the register this operand corresponds to.
292894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
293894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void setReg(unsigned Reg);
29419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
295894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void setSubReg(unsigned subReg) {
296894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isReg() && "Wrong MachineOperand accessor");
297894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    SubReg = (unsigned char)subReg;
298894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
299894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
300894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// substVirtReg - Substitute the current register with the virtual
301894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// subregister Reg:SubReg. Take any existing SubReg index into account,
302894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// using TargetRegisterInfo to compose the subreg indices if necessary.
303894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// Reg must be a virtual register, SubIdx can be 0.
304894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
305894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void substVirtReg(unsigned Reg, unsigned SubIdx, const TargetRegisterInfo&);
306894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
307894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// substPhysReg - Substitute the current register with the physical register
308894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// Reg, taking any existing SubReg into account. For instance,
309894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// substPhysReg(%EAX) will change %reg1024:sub_8bit to %AL.
310894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
311894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void substPhysReg(unsigned Reg, const TargetRegisterInfo&);
312894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
313894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void setIsUse(bool Val = true) {
314894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isReg() && "Wrong MachineOperand accessor");
315894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert((Val || !isDebug()) && "Marking a debug operation as def");
316894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    IsDef = !Val;
317894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
31819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
319894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void setIsDef(bool Val = true) {
320894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isReg() && "Wrong MachineOperand accessor");
321894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert((!Val || !isDebug()) && "Marking a debug operation as def");
322894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    IsDef = Val;
323894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
324894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
32519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  void setImplicit(bool Val = true) {
326894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isReg() && "Wrong MachineOperand accessor");
327894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    IsImp = Val;
328894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
329894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
330894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void setIsKill(bool Val = true) {
331894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isReg() && !IsDef && "Wrong MachineOperand accessor");
332894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert((!Val || !isDebug()) && "Marking a debug operation as kill");
333894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    IsKill = Val;
334894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
33519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
336894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void setIsDead(bool Val = true) {
337894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isReg() && IsDef && "Wrong MachineOperand accessor");
338894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    IsDead = Val;
339894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
340894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
341894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void setIsUndef(bool Val = true) {
342894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isReg() && "Wrong MachineOperand accessor");
343894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    IsUndef = Val;
344894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
34519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
346894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void setIsEarlyClobber(bool Val = true) {
347894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isReg() && IsDef && "Wrong MachineOperand accessor");
348894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    IsEarlyClobber = Val;
349894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
350894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
351894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void setIsDebug(bool Val = true) {
352894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isReg() && IsDef && "Wrong MachineOperand accessor");
353894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    IsDebug = Val;
354894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
355894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
356894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  //===--------------------------------------------------------------------===//
357894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // Accessors for various operand types.
358894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  //===--------------------------------------------------------------------===//
35919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
360894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  int64_t getImm() const {
361894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isImm() && "Wrong MachineOperand accessor");
362894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return Contents.ImmVal;
363894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
36419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
36519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  const ConstantInt *getCImm() const {
36619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    assert(isCImm() && "Wrong MachineOperand accessor");
36719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Contents.CI;
36819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
36919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
370894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  const ConstantFP *getFPImm() const {
371894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isFPImm() && "Wrong MachineOperand accessor");
372894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return Contents.CFP;
373894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
37419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
375894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MachineBasicBlock *getMBB() const {
376894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isMBB() && "Wrong MachineOperand accessor");
377894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return Contents.MBB;
378894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
379894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
380894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  int getIndex() const {
381894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert((isFI() || isCPI() || isJTI()) &&
382894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman           "Wrong MachineOperand accessor");
383894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return Contents.OffsetedInfo.Val.Index;
384894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
38519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
386894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  const GlobalValue *getGlobal() const {
387894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isGlobal() && "Wrong MachineOperand accessor");
388894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return Contents.OffsetedInfo.Val.GV;
389894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
390894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
391894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  const BlockAddress *getBlockAddress() const {
392894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isBlockAddress() && "Wrong MachineOperand accessor");
393894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return Contents.OffsetedInfo.Val.BA;
394894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
395894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
396894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MCSymbol *getMCSymbol() const {
397894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isMCSymbol() && "Wrong MachineOperand accessor");
398894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return Contents.Sym;
399894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
40019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
401894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// getOffset - Return the offset from the symbol in this operand. This always
402894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// returns 0 for ExternalSymbol operands.
403894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  int64_t getOffset() const {
404894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert((isGlobal() || isSymbol() || isCPI() || isBlockAddress()) &&
405894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman           "Wrong MachineOperand accessor");
40619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return (int64_t(Contents.OffsetedInfo.OffsetHi) << 32) |
40719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman           SmallContents.OffsetLo;
408894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
40919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
410894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  const char *getSymbolName() const {
411894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isSymbol() && "Wrong MachineOperand accessor");
412894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return Contents.OffsetedInfo.Val.SymbolName;
413894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
414894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
415894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  const MDNode *getMetadata() const {
416894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isMetadata() && "Wrong MachineOperand accessor");
417894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return Contents.MD;
418894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
41919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
420894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  //===--------------------------------------------------------------------===//
421894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // Mutators for various operand types.
422894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  //===--------------------------------------------------------------------===//
42319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
424894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void setImm(int64_t immVal) {
425894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isImm() && "Wrong MachineOperand mutator");
426894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Contents.ImmVal = immVal;
427894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
428894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
429894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void setOffset(int64_t Offset) {
430894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert((isGlobal() || isSymbol() || isCPI() || isBlockAddress()) &&
431894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        "Wrong MachineOperand accessor");
43219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    SmallContents.OffsetLo = unsigned(Offset);
43319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    Contents.OffsetedInfo.OffsetHi = int(Offset >> 32);
434894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
43519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
436894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void setIndex(int Idx) {
437894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert((isFI() || isCPI() || isJTI()) &&
438894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman           "Wrong MachineOperand accessor");
439894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Contents.OffsetedInfo.Val.Index = Idx;
440894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
44119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
442894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void setMBB(MachineBasicBlock *MBB) {
443894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isMBB() && "Wrong MachineOperand accessor");
444894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Contents.MBB = MBB;
445894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
44619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
447894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  //===--------------------------------------------------------------------===//
448894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // Other methods.
449894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  //===--------------------------------------------------------------------===//
45019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
451894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// isIdenticalTo - Return true if this operand is identical to the specified
452894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// operand. Note: This method ignores isKill and isDead properties.
453894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool isIdenticalTo(const MachineOperand &Other) const;
45419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
455894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// ChangeToImmediate - Replace this operand with a new immediate operand of
456894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// the specified value.  If an operand is known to be an immediate already,
457894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// the setImm method should be used.
458894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void ChangeToImmediate(int64_t ImmVal);
45919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
460894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// ChangeToRegister - Replace this operand with a new register operand of
461894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// the specified value.  If an operand is known to be an register already,
462894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// the setReg method should be used.
463894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void ChangeToRegister(unsigned Reg, bool isDef, bool isImp = false,
464894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                        bool isKill = false, bool isDead = false,
465894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                        bool isUndef = false, bool isDebug = false);
46619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
467894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  //===--------------------------------------------------------------------===//
468894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // Construction methods.
469894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  //===--------------------------------------------------------------------===//
47019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
471894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  static MachineOperand CreateImm(int64_t Val) {
472894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MachineOperand Op(MachineOperand::MO_Immediate);
473894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.setImm(Val);
474894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return Op;
475894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
47619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
47719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  static MachineOperand CreateCImm(const ConstantInt *CI) {
47819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    MachineOperand Op(MachineOperand::MO_CImmediate);
47919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    Op.Contents.CI = CI;
48019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    return Op;
48119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
48219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
483894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  static MachineOperand CreateFPImm(const ConstantFP *CFP) {
484894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MachineOperand Op(MachineOperand::MO_FPImmediate);
485894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.Contents.CFP = CFP;
486894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return Op;
487894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
48819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
489894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  static MachineOperand CreateReg(unsigned Reg, bool isDef, bool isImp = false,
490894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                  bool isKill = false, bool isDead = false,
491894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                  bool isUndef = false,
492894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                  bool isEarlyClobber = false,
493894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                  unsigned SubReg = 0,
494894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                  bool isDebug = false) {
495894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MachineOperand Op(MachineOperand::MO_Register);
496894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.IsDef = isDef;
497894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.IsImp = isImp;
498894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.IsKill = isKill;
499894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.IsDead = isDead;
500894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.IsUndef = isUndef;
501894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.IsEarlyClobber = isEarlyClobber;
502894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.IsDebug = isDebug;
50319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    Op.SmallContents.RegNo = Reg;
504894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.Contents.Reg.Prev = 0;
505894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.Contents.Reg.Next = 0;
506894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.SubReg = SubReg;
507894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return Op;
508894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
509894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  static MachineOperand CreateMBB(MachineBasicBlock *MBB,
510894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                  unsigned char TargetFlags = 0) {
511894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MachineOperand Op(MachineOperand::MO_MachineBasicBlock);
512894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.setMBB(MBB);
513894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.setTargetFlags(TargetFlags);
514894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return Op;
515894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
51619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  static MachineOperand CreateFI(int Idx) {
517894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MachineOperand Op(MachineOperand::MO_FrameIndex);
518894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.setIndex(Idx);
519894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return Op;
520894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
521894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  static MachineOperand CreateCPI(unsigned Idx, int Offset,
522894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                  unsigned char TargetFlags = 0) {
523894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MachineOperand Op(MachineOperand::MO_ConstantPoolIndex);
524894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.setIndex(Idx);
525894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.setOffset(Offset);
526894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.setTargetFlags(TargetFlags);
527894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return Op;
528894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
529894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  static MachineOperand CreateJTI(unsigned Idx,
530894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                  unsigned char TargetFlags = 0) {
531894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MachineOperand Op(MachineOperand::MO_JumpTableIndex);
532894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.setIndex(Idx);
533894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.setTargetFlags(TargetFlags);
534894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return Op;
535894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
536894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  static MachineOperand CreateGA(const GlobalValue *GV, int64_t Offset,
537894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                 unsigned char TargetFlags = 0) {
538894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MachineOperand Op(MachineOperand::MO_GlobalAddress);
539894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.Contents.OffsetedInfo.Val.GV = GV;
540894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.setOffset(Offset);
541894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.setTargetFlags(TargetFlags);
542894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return Op;
543894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
544894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  static MachineOperand CreateES(const char *SymName,
545894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                 unsigned char TargetFlags = 0) {
546894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MachineOperand Op(MachineOperand::MO_ExternalSymbol);
547894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.Contents.OffsetedInfo.Val.SymbolName = SymName;
548894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.setOffset(0); // Offset is always 0.
549894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.setTargetFlags(TargetFlags);
550894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return Op;
551894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
552894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  static MachineOperand CreateBA(const BlockAddress *BA,
553894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                 unsigned char TargetFlags = 0) {
554894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MachineOperand Op(MachineOperand::MO_BlockAddress);
555894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.Contents.OffsetedInfo.Val.BA = BA;
556894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.setOffset(0); // Offset is always 0.
557894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.setTargetFlags(TargetFlags);
558894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return Op;
559894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
560894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  static MachineOperand CreateMetadata(const MDNode *Meta) {
561894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MachineOperand Op(MachineOperand::MO_Metadata);
562894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.Contents.MD = Meta;
563894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return Op;
564894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
565894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
566894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  static MachineOperand CreateMCSymbol(MCSymbol *Sym) {
567894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MachineOperand Op(MachineOperand::MO_MCSymbol);
568894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    Op.Contents.Sym = Sym;
569894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return Op;
570894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
57119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
572894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  friend class MachineInstr;
573894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  friend class MachineRegisterInfo;
574894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanprivate:
575894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  //===--------------------------------------------------------------------===//
576894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // Methods for handling register use/def lists.
577894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  //===--------------------------------------------------------------------===//
578894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
579894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// isOnRegUseList - Return true if this operand is on a register use/def list
580894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// or false if not.  This can only be called for register operands that are
581894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// part of a machine instruction.
582894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool isOnRegUseList() const {
583894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(isReg() && "Can only add reg operand to use lists");
584894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return Contents.Reg.Prev != 0;
585894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
58619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
587894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// AddRegOperandToRegInfo - Add this register operand to the specified
588894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// MachineRegisterInfo.  If it is null, then the next/prev fields should be
589894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// explicitly nulled out.
590894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void AddRegOperandToRegInfo(MachineRegisterInfo *RegInfo);
591894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
592894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// RemoveRegOperandFromRegInfo - Remove this register operand from the
593894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// MachineRegisterInfo it is linked with.
594894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void RemoveRegOperandFromRegInfo();
595894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman};
596894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
597894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumaninline raw_ostream &operator<<(raw_ostream &OS, const MachineOperand& MO) {
598894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MO.print(OS, 0);
599894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  return OS;
600894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman}
601894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
602894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman} // End llvm namespace
603894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
604894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#endif
605