OLD | NEW |
(Empty) | |
| 1 //===- subzero/src/IceOperand.h - High-level operands -----------*- C++ -*-===// |
| 2 // |
| 3 // The Subzero Code Generator |
| 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 declares the IceOperand class and its target-independent |
| 11 // subclasses. The main classes are IceVariable, which represents an |
| 12 // LLVM variable that is either register- or stack-allocated, and the |
| 13 // IceConstant hierarchy, which represents integer, floating-point, |
| 14 // and/or symbolic constants. |
| 15 // |
| 16 //===----------------------------------------------------------------------===// |
| 17 |
| 18 #ifndef SUBZERO_SRC_ICEOPERAND_H |
| 19 #define SUBZERO_SRC_ICEOPERAND_H |
| 20 |
| 21 #include "IceDefs.h" |
| 22 #include "IceTypes.h" |
| 23 |
| 24 class IceOperand { |
| 25 public: |
| 26 enum OperandKind { |
| 27 Constant, |
| 28 ConstantInteger, |
| 29 ConstantFloat, |
| 30 ConstantDouble, |
| 31 ConstantRelocatable, |
| 32 Constant_Num, |
| 33 Variable, |
| 34 // Target-specific operand classes use Target as the starting |
| 35 // point for their Kind enum space. |
| 36 Target |
| 37 }; |
| 38 OperandKind getKind() const { return Kind; } |
| 39 IceType getType() const { return Type; } |
| 40 |
| 41 // Every IceOperand keeps an array of the IceVariables referenced in |
| 42 // the operand. This is so that the liveness operations can get |
| 43 // quick access to the variables of interest, without having to dig |
| 44 // so far into the operand. |
| 45 uint32_t getNumVars() const { return NumVars; } |
| 46 IceVariable *getVar(uint32_t I) const { |
| 47 assert(I < getNumVars()); |
| 48 return Vars[I]; |
| 49 } |
| 50 virtual void setUse(const IceInst *Inst, const IceCfgNode *Node) {} |
| 51 virtual void dump(IceOstream &Str) const; |
| 52 |
| 53 virtual ~IceOperand() {} |
| 54 |
| 55 protected: |
| 56 IceOperand(IceCfg *Cfg, OperandKind Kind, IceType Type) |
| 57 : Type(Type), Kind(Kind) {} |
| 58 const IceType Type; |
| 59 const OperandKind Kind; |
| 60 // Vars and NumVars are initialized by the derived class. |
| 61 uint32_t NumVars; |
| 62 IceVariable **Vars; |
| 63 }; |
| 64 |
| 65 IceOstream &operator<<(IceOstream &Str, const IceOperand *O); |
| 66 |
| 67 // IceConstant is the abstract base class for constants. |
| 68 // TODO: better design of a minimal per-module constant pool, |
| 69 // including synchronized access for parallel translation. |
| 70 class IceConstant : public IceOperand { |
| 71 public: |
| 72 virtual void dump(IceOstream &Str) const = 0; |
| 73 |
| 74 static bool classof(const IceOperand *Operand) { |
| 75 OperandKind Kind = Operand->getKind(); |
| 76 return Kind >= Constant && Kind <= Constant_Num; |
| 77 } |
| 78 |
| 79 protected: |
| 80 IceConstant(IceCfg *Cfg, OperandKind Kind, IceType Type) |
| 81 : IceOperand(Cfg, Kind, Type) { |
| 82 Vars = NULL; |
| 83 NumVars = 0; |
| 84 } |
| 85 }; |
| 86 |
| 87 // IceConstantPrimitive<> wraps a primitive type. |
| 88 template <typename T, IceOperand::OperandKind K> |
| 89 class IceConstantPrimitive : public IceConstant { |
| 90 public: |
| 91 static IceConstantPrimitive *create(IceCfg *Cfg, IceType Type, T Value) { |
| 92 // Use non-placement allocation for constants for now, until |
| 93 // global constant pool issues are worked out. |
| 94 return new IceConstantPrimitive(Cfg, Type, Value); |
| 95 } |
| 96 T getValue() const { return Value; } |
| 97 virtual void dump(IceOstream &Str) const { Str << getValue(); } |
| 98 |
| 99 static bool classof(const IceOperand *Operand) { |
| 100 return Operand->getKind() == K; |
| 101 } |
| 102 |
| 103 private: |
| 104 IceConstantPrimitive(IceCfg *Cfg, IceType Type, T Value) |
| 105 : IceConstant(Cfg, K, Type), Value(Value) {} |
| 106 const T Value; |
| 107 }; |
| 108 |
| 109 typedef IceConstantPrimitive<uint64_t, IceOperand::ConstantInteger> |
| 110 IceConstantInteger; |
| 111 typedef IceConstantPrimitive<float, IceOperand::ConstantFloat> IceConstantFloat; |
| 112 typedef IceConstantPrimitive<double, IceOperand::ConstantDouble> |
| 113 IceConstantDouble; |
| 114 |
| 115 // IceConstantRelocatable represents a symbolic constant combined with |
| 116 // a fixed offset. |
| 117 class IceConstantRelocatable : public IceConstant { |
| 118 public: |
| 119 static IceConstantRelocatable *create(IceCfg *Cfg, uint32_t CPIndex, |
| 120 IceType Type, const void *Handle, |
| 121 int64_t Offset, |
| 122 const IceString &Name = "") { |
| 123 // Use non-placement allocation for constants for now, until |
| 124 // global constant pool issues are worked out. |
| 125 return new IceConstantRelocatable(Cfg, Type, Handle, Offset, Name, CPIndex); |
| 126 } |
| 127 uint32_t getCPIndex() const { return CPIndex; } |
| 128 const void *getHandle() const { return Handle; } |
| 129 int64_t getOffset() const { return Offset; } |
| 130 IceString getName() const { return Name; } |
| 131 void setSuppressMangling(bool Value) { SuppressMangling = Value; } |
| 132 bool getSuppressMangling() const { return SuppressMangling; } |
| 133 virtual void dump(IceOstream &Str) const; |
| 134 |
| 135 static bool classof(const IceOperand *Operand) { |
| 136 OperandKind Kind = Operand->getKind(); |
| 137 return Kind == ConstantRelocatable; |
| 138 } |
| 139 |
| 140 private: |
| 141 IceConstantRelocatable(IceCfg *Cfg, IceType Type, const void *Handle, |
| 142 int64_t Offset, const IceString &Name, |
| 143 uint32_t CPIndex) |
| 144 : IceConstant(Cfg, ConstantRelocatable, Type), CPIndex(CPIndex), |
| 145 Handle(Handle), Offset(Offset), Name(Name), SuppressMangling(false) {} |
| 146 const uint32_t CPIndex; // index into ICE constant pool |
| 147 const void *const Handle; // opaque handle e.g. to LLVM |
| 148 const int64_t Offset; // fixed offset to add |
| 149 const IceString Name; // optional for debug/dump |
| 150 bool SuppressMangling; |
| 151 }; |
| 152 |
| 153 // IceVariable represents an operand that is register-allocated or |
| 154 // stack-allocated. If it is register-allocated, it will ultimately |
| 155 // have a non-negative RegNum field. |
| 156 class IceVariable : public IceOperand { |
| 157 public: |
| 158 static IceVariable *create(IceCfg *Cfg, IceType Type, const IceCfgNode *Node, |
| 159 uint32_t Index, const IceString &Name) { |
| 160 return new (Cfg->allocate<IceVariable>()) IceVariable(Cfg, Type, Node, Index
, Name); |
| 161 } |
| 162 |
| 163 uint32_t getIndex() const { return Number; } |
| 164 IceString getName() const; |
| 165 |
| 166 IceInst *getDefinition() const { return DefInst; } |
| 167 void setDefinition(IceInst *Inst, const IceCfgNode *Node); |
| 168 void replaceDefinition(IceInst *Inst, const IceCfgNode *Node); |
| 169 |
| 170 const IceCfgNode *getLocalUseNode() const { return DefNode; } |
| 171 bool isMultiblockLife() const { return (DefNode == NULL); } |
| 172 void setUse(const IceInst *Inst, const IceCfgNode *Node); |
| 173 |
| 174 bool getIsArg() const { return IsArgument; } |
| 175 void setIsArg(IceCfg *Cfg); |
| 176 |
| 177 virtual void dump(IceOstream &Str) const; |
| 178 |
| 179 static bool classof(const IceOperand *Operand) { |
| 180 return Operand->getKind() == Variable; |
| 181 } |
| 182 |
| 183 private: |
| 184 IceVariable(IceCfg *Cfg, IceType Type, const IceCfgNode *Node, uint32_t Index, |
| 185 const IceString &Name) |
| 186 : IceOperand(Cfg, Variable, Type), Number(Index), Name(Name), |
| 187 DefInst(NULL), DefNode(Node), IsArgument(false) { |
| 188 Vars = Cfg->allocateArrayOf<IceVariable *>(1); |
| 189 Vars[0] = this; |
| 190 NumVars = 1; |
| 191 } |
| 192 // Number is unique across all variables, and is used as a |
| 193 // (bit)vector index for liveness analysis. |
| 194 const uint32_t Number; |
| 195 // Name is optional. |
| 196 const IceString Name; |
| 197 // DefInst is the instruction that produces this variable as its |
| 198 // dest. |
| 199 IceInst *DefInst; |
| 200 // DefNode is the node where this variable was produced, and is |
| 201 // reset to NULL if it is used outside that node. This is used for |
| 202 // detecting isMultiblockLife(). |
| 203 const IceCfgNode *DefNode; |
| 204 bool IsArgument; |
| 205 }; |
| 206 |
| 207 #endif // SUBZERO_SRC_ICEOPERAND_H |
OLD | NEW |