| OLD | NEW |
| 1 //===- subzero/src/IceOperand.h - High-level operands -----------*- C++ -*-===// | 1 //===- subzero/src/IceOperand.h - High-level operands -----------*- C++ -*-===// |
| 2 // | 2 // |
| 3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // This file declares the Operand class and its target-independent | 10 // This file declares the Operand class and its target-independent |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 // Every Operand keeps an array of the Variables referenced in | 44 // Every Operand keeps an array of the Variables referenced in |
| 45 // the operand. This is so that the liveness operations can get | 45 // the operand. This is so that the liveness operations can get |
| 46 // quick access to the variables of interest, without having to dig | 46 // quick access to the variables of interest, without having to dig |
| 47 // so far into the operand. | 47 // so far into the operand. |
| 48 SizeT getNumVars() const { return NumVars; } | 48 SizeT getNumVars() const { return NumVars; } |
| 49 Variable *getVar(SizeT I) const { | 49 Variable *getVar(SizeT I) const { |
| 50 assert(I < getNumVars()); | 50 assert(I < getNumVars()); |
| 51 return Vars[I]; | 51 return Vars[I]; |
| 52 } | 52 } |
| 53 virtual void emit(const Cfg *Func) const = 0; | 53 virtual void emit(const Cfg *Func) const = 0; |
| 54 virtual void dump(const Cfg *Func) const = 0; | 54 // The dump(Func,Str) implementation must be sure to handle the |
| 55 // situation where Func==NULL. |
| 56 virtual void dump(const Cfg *Func, Ostream &Str) const = 0; |
| 57 void dump(const Cfg *Func) const { |
| 58 assert(Func); |
| 59 dump(Func, Func->getContext()->getStrDump()); |
| 60 } |
| 61 void dump(Ostream &Str) const { dump(NULL, Str); } |
| 55 | 62 |
| 56 // Query whether this object was allocated in isolation, or added to | 63 // Query whether this object was allocated in isolation, or added to |
| 57 // some higher-level pool. This determines whether a containing | 64 // some higher-level pool. This determines whether a containing |
| 58 // object's destructor should delete this object. Generally, | 65 // object's destructor should delete this object. Generally, |
| 59 // constants are pooled globally, variables are pooled per-CFG, and | 66 // constants are pooled globally, variables are pooled per-CFG, and |
| 60 // target-specific operands are not pooled. | 67 // target-specific operands are not pooled. |
| 61 virtual bool isPooled() const { return false; } | 68 virtual bool isPooled() const { return false; } |
| 62 | 69 |
| 63 virtual ~Operand() {} | 70 virtual ~Operand() {} |
| 64 | 71 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 75 private: | 82 private: |
| 76 Operand(const Operand &) LLVM_DELETED_FUNCTION; | 83 Operand(const Operand &) LLVM_DELETED_FUNCTION; |
| 77 Operand &operator=(const Operand &) LLVM_DELETED_FUNCTION; | 84 Operand &operator=(const Operand &) LLVM_DELETED_FUNCTION; |
| 78 }; | 85 }; |
| 79 | 86 |
| 80 // Constant is the abstract base class for constants. All | 87 // Constant is the abstract base class for constants. All |
| 81 // constants are allocated from a global arena and are pooled. | 88 // constants are allocated from a global arena and are pooled. |
| 82 class Constant : public Operand { | 89 class Constant : public Operand { |
| 83 public: | 90 public: |
| 84 uint32_t getPoolEntryID() const { return PoolEntryID; } | 91 uint32_t getPoolEntryID() const { return PoolEntryID; } |
| 92 using Operand::dump; |
| 85 virtual void emit(const Cfg *Func) const { emit(Func->getContext()); } | 93 virtual void emit(const Cfg *Func) const { emit(Func->getContext()); } |
| 86 virtual void dump(const Cfg *Func) const { dump(Func->getContext()); } | |
| 87 virtual void emit(GlobalContext *Ctx) const = 0; | 94 virtual void emit(GlobalContext *Ctx) const = 0; |
| 88 virtual void dump(GlobalContext *Ctx) const = 0; | 95 virtual void dump(const Cfg *Func, Ostream &Str) const = 0; |
| 89 | 96 |
| 90 static bool classof(const Operand *Operand) { | 97 static bool classof(const Operand *Operand) { |
| 91 OperandKind Kind = Operand->getKind(); | 98 OperandKind Kind = Operand->getKind(); |
| 92 return Kind >= kConst_Base && Kind <= kConst_Num; | 99 return Kind >= kConst_Base && Kind <= kConst_Num; |
| 93 } | 100 } |
| 94 | 101 |
| 95 protected: | 102 protected: |
| 96 Constant(OperandKind Kind, Type Ty, uint32_t PoolEntryID) | 103 Constant(OperandKind Kind, Type Ty, uint32_t PoolEntryID) |
| 97 : Operand(Kind, Ty), PoolEntryID(PoolEntryID) { | 104 : Operand(Kind, Ty), PoolEntryID(PoolEntryID) { |
| 98 Vars = NULL; | 105 Vars = NULL; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 117 uint32_t PoolEntryID) { | 124 uint32_t PoolEntryID) { |
| 118 return new (Ctx->allocate<ConstantPrimitive>()) | 125 return new (Ctx->allocate<ConstantPrimitive>()) |
| 119 ConstantPrimitive(Ty, Value, PoolEntryID); | 126 ConstantPrimitive(Ty, Value, PoolEntryID); |
| 120 } | 127 } |
| 121 T getValue() const { return Value; } | 128 T getValue() const { return Value; } |
| 122 using Constant::emit; | 129 using Constant::emit; |
| 123 // The target needs to implement this for each ConstantPrimitive | 130 // The target needs to implement this for each ConstantPrimitive |
| 124 // specialization. | 131 // specialization. |
| 125 virtual void emit(GlobalContext *Ctx) const; | 132 virtual void emit(GlobalContext *Ctx) const; |
| 126 using Constant::dump; | 133 using Constant::dump; |
| 127 virtual void dump(GlobalContext *Ctx) const { | 134 virtual void dump(const Cfg *, Ostream &Str) const { Str << getValue(); } |
| 128 Ostream &Str = Ctx->getStrDump(); | |
| 129 Str << getValue(); | |
| 130 } | |
| 131 | 135 |
| 132 static bool classof(const Operand *Operand) { | 136 static bool classof(const Operand *Operand) { |
| 133 return Operand->getKind() == K; | 137 return Operand->getKind() == K; |
| 134 } | 138 } |
| 135 | 139 |
| 136 private: | 140 private: |
| 137 ConstantPrimitive(Type Ty, T Value, uint32_t PoolEntryID) | 141 ConstantPrimitive(Type Ty, T Value, uint32_t PoolEntryID) |
| 138 : Constant(K, Ty, PoolEntryID), Value(Value) {} | 142 : Constant(K, Ty, PoolEntryID), Value(Value) {} |
| 139 ConstantPrimitive(const ConstantPrimitive &) LLVM_DELETED_FUNCTION; | 143 ConstantPrimitive(const ConstantPrimitive &) LLVM_DELETED_FUNCTION; |
| 140 ConstantPrimitive &operator=(const ConstantPrimitive &) LLVM_DELETED_FUNCTION; | 144 ConstantPrimitive &operator=(const ConstantPrimitive &) LLVM_DELETED_FUNCTION; |
| 141 virtual ~ConstantPrimitive() {} | 145 virtual ~ConstantPrimitive() {} |
| 142 const T Value; | 146 const T Value; |
| 143 }; | 147 }; |
| 144 | 148 |
| 145 typedef ConstantPrimitive<uint64_t, Operand::kConstInteger> ConstantInteger; | 149 typedef ConstantPrimitive<uint64_t, Operand::kConstInteger> ConstantInteger; |
| 146 typedef ConstantPrimitive<float, Operand::kConstFloat> ConstantFloat; | 150 typedef ConstantPrimitive<float, Operand::kConstFloat> ConstantFloat; |
| 147 typedef ConstantPrimitive<double, Operand::kConstDouble> ConstantDouble; | 151 typedef ConstantPrimitive<double, Operand::kConstDouble> ConstantDouble; |
| 148 | 152 |
| 149 template <> inline void ConstantInteger::dump(GlobalContext *Ctx) const { | 153 template <> inline void ConstantInteger::dump(const Cfg *, Ostream &Str) const { |
| 150 Ostream &Str = Ctx->getStrDump(); | |
| 151 if (getType() == IceType_i1) | 154 if (getType() == IceType_i1) |
| 152 Str << (getValue() ? "true" : "false"); | 155 Str << (getValue() ? "true" : "false"); |
| 153 else | 156 else |
| 154 Str << static_cast<int64_t>(getValue()); | 157 Str << static_cast<int64_t>(getValue()); |
| 155 } | 158 } |
| 156 | 159 |
| 157 // RelocatableTuple bundles the parameters that are used to | 160 // RelocatableTuple bundles the parameters that are used to |
| 158 // construct an ConstantRelocatable. It is done this way so that | 161 // construct an ConstantRelocatable. It is done this way so that |
| 159 // ConstantRelocatable can fit into the global constant pool | 162 // ConstantRelocatable can fit into the global constant pool |
| 160 // template mechanism. | 163 // template mechanism. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 186 return new (Ctx->allocate<ConstantRelocatable>()) ConstantRelocatable( | 189 return new (Ctx->allocate<ConstantRelocatable>()) ConstantRelocatable( |
| 187 Ty, Tuple.Offset, Tuple.Name, Tuple.SuppressMangling, PoolEntryID); | 190 Ty, Tuple.Offset, Tuple.Name, Tuple.SuppressMangling, PoolEntryID); |
| 188 } | 191 } |
| 189 int64_t getOffset() const { return Offset; } | 192 int64_t getOffset() const { return Offset; } |
| 190 IceString getName() const { return Name; } | 193 IceString getName() const { return Name; } |
| 191 void setSuppressMangling(bool Value) { SuppressMangling = Value; } | 194 void setSuppressMangling(bool Value) { SuppressMangling = Value; } |
| 192 bool getSuppressMangling() const { return SuppressMangling; } | 195 bool getSuppressMangling() const { return SuppressMangling; } |
| 193 using Constant::emit; | 196 using Constant::emit; |
| 194 using Constant::dump; | 197 using Constant::dump; |
| 195 virtual void emit(GlobalContext *Ctx) const; | 198 virtual void emit(GlobalContext *Ctx) const; |
| 196 virtual void dump(GlobalContext *Ctx) const; | 199 virtual void dump(const Cfg *Func, Ostream &Str) const; |
| 197 | 200 |
| 198 static bool classof(const Operand *Operand) { | 201 static bool classof(const Operand *Operand) { |
| 199 OperandKind Kind = Operand->getKind(); | 202 OperandKind Kind = Operand->getKind(); |
| 200 return Kind == kConstRelocatable; | 203 return Kind == kConstRelocatable; |
| 201 } | 204 } |
| 202 | 205 |
| 203 private: | 206 private: |
| 204 ConstantRelocatable(Type Ty, int64_t Offset, const IceString &Name, | 207 ConstantRelocatable(Type Ty, int64_t Offset, const IceString &Name, |
| 205 bool SuppressMangling, uint32_t PoolEntryID) | 208 bool SuppressMangling, uint32_t PoolEntryID) |
| 206 : Constant(kConstRelocatable, Ty, PoolEntryID), Offset(Offset), | 209 : Constant(kConstRelocatable, Ty, PoolEntryID), Offset(Offset), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 218 // legal to lower ConstantUndef to any value, backends should try to | 221 // legal to lower ConstantUndef to any value, backends should try to |
| 219 // make code generation deterministic by lowering ConstantUndefs to 0. | 222 // make code generation deterministic by lowering ConstantUndefs to 0. |
| 220 class ConstantUndef : public Constant { | 223 class ConstantUndef : public Constant { |
| 221 public: | 224 public: |
| 222 static ConstantUndef *create(GlobalContext *Ctx, Type Ty, | 225 static ConstantUndef *create(GlobalContext *Ctx, Type Ty, |
| 223 uint32_t PoolEntryID) { | 226 uint32_t PoolEntryID) { |
| 224 return new (Ctx->allocate<ConstantUndef>()) ConstantUndef(Ty, PoolEntryID); | 227 return new (Ctx->allocate<ConstantUndef>()) ConstantUndef(Ty, PoolEntryID); |
| 225 } | 228 } |
| 226 | 229 |
| 227 using Constant::emit; | 230 using Constant::emit; |
| 231 using Constant::dump; |
| 228 // The target needs to implement this. | 232 // The target needs to implement this. |
| 229 virtual void emit(GlobalContext *Ctx) const; | 233 virtual void emit(GlobalContext *Ctx) const; |
| 230 | 234 virtual void dump(const Cfg *, Ostream &Str) const { Str << "undef"; } |
| 231 using Constant::dump; | |
| 232 virtual void dump(GlobalContext *Ctx) const { | |
| 233 Ostream &Str = Ctx->getStrEmit(); | |
| 234 Str << "undef"; | |
| 235 } | |
| 236 | 235 |
| 237 static bool classof(const Operand *Operand) { | 236 static bool classof(const Operand *Operand) { |
| 238 return Operand->getKind() == kConstUndef; | 237 return Operand->getKind() == kConstUndef; |
| 239 } | 238 } |
| 240 | 239 |
| 241 private: | 240 private: |
| 242 ConstantUndef(Type Ty, uint32_t PoolEntryID) | 241 ConstantUndef(Type Ty, uint32_t PoolEntryID) |
| 243 : Constant(kConstUndef, Ty, PoolEntryID) {} | 242 : Constant(kConstUndef, Ty, PoolEntryID) {} |
| 244 ConstantUndef(const ConstantUndef &) LLVM_DELETED_FUNCTION; | 243 ConstantUndef(const ConstantUndef &) LLVM_DELETED_FUNCTION; |
| 245 ConstantUndef &operator=(const ConstantUndef &) LLVM_DELETED_FUNCTION; | 244 ConstantUndef &operator=(const ConstantUndef &) LLVM_DELETED_FUNCTION; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 HiVar = Hi; | 407 HiVar = Hi; |
| 409 } | 408 } |
| 410 // Creates a temporary copy of the variable with a different type. | 409 // Creates a temporary copy of the variable with a different type. |
| 411 // Used primarily for syntactic correctness of textual assembly | 410 // Used primarily for syntactic correctness of textual assembly |
| 412 // emission. Note that only basic information is copied, in | 411 // emission. Note that only basic information is copied, in |
| 413 // particular not DefInst, IsArgument, Weight, RegisterPreference, | 412 // particular not DefInst, IsArgument, Weight, RegisterPreference, |
| 414 // AllowRegisterOverlap, LoVar, HiVar, VarsReal. | 413 // AllowRegisterOverlap, LoVar, HiVar, VarsReal. |
| 415 Variable asType(Type Ty); | 414 Variable asType(Type Ty); |
| 416 | 415 |
| 417 virtual void emit(const Cfg *Func) const; | 416 virtual void emit(const Cfg *Func) const; |
| 418 virtual void dump(const Cfg *Func) const; | 417 using Operand::dump; |
| 418 virtual void dump(const Cfg *Func, Ostream &Str) const; |
| 419 | 419 |
| 420 static bool classof(const Operand *Operand) { | 420 static bool classof(const Operand *Operand) { |
| 421 return Operand->getKind() == kVariable; | 421 return Operand->getKind() == kVariable; |
| 422 } | 422 } |
| 423 | 423 |
| 424 // The destructor is public because of the asType() method. | 424 // The destructor is public because of the asType() method. |
| 425 virtual ~Variable() {} | 425 virtual ~Variable() {} |
| 426 | 426 |
| 427 private: | 427 private: |
| 428 Variable(Type Ty, const CfgNode *Node, SizeT Index, const IceString &Name) | 428 Variable(Type Ty, const CfgNode *Node, SizeT Index, const IceString &Name) |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 Variable *LoVar; | 484 Variable *LoVar; |
| 485 Variable *HiVar; | 485 Variable *HiVar; |
| 486 // VarsReal (and Operand::Vars) are set up such that Vars[0] == | 486 // VarsReal (and Operand::Vars) are set up such that Vars[0] == |
| 487 // this. | 487 // this. |
| 488 Variable *VarsReal[1]; | 488 Variable *VarsReal[1]; |
| 489 }; | 489 }; |
| 490 | 490 |
| 491 } // end of namespace Ice | 491 } // end of namespace Ice |
| 492 | 492 |
| 493 #endif // SUBZERO_SRC_ICEOPERAND_H | 493 #endif // SUBZERO_SRC_ICEOPERAND_H |
| OLD | NEW |