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