| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 Str << ".L$" << getType() << "$" << PoolEntryID; | 110 Str << ".L$" << getType() << "$" << PoolEntryID; |
| 111 } | 111 } |
| 112 void emit(const Cfg *Func) const override { emit(Func->getTarget()); } | 112 void emit(const Cfg *Func) const override { emit(Func->getTarget()); } |
| 113 virtual void emit(TargetLowering *Target) const = 0; | 113 virtual void emit(TargetLowering *Target) const = 0; |
| 114 | 114 |
| 115 static bool classof(const Operand *Operand) { | 115 static bool classof(const Operand *Operand) { |
| 116 OperandKind Kind = Operand->getKind(); | 116 OperandKind Kind = Operand->getKind(); |
| 117 return Kind >= kConst_Base && Kind <= kConst_Num; | 117 return Kind >= kConst_Base && Kind <= kConst_Num; |
| 118 } | 118 } |
| 119 | 119 |
| 120 // Judge if this given immediate should be randomized or pooled |
| 121 // By default should return false, only constant integers should |
| 122 // truly go through this method. |
| 123 virtual bool shouldBeRandomizedOrPooled(const GlobalContext *Ctx) { |
| 124 (void)Ctx; |
| 125 return false; |
| 126 } |
| 127 |
| 128 void setShouldBePooled(bool R) { shouldBePooled = R; } |
| 129 |
| 130 bool getShouldBePooled() const { return shouldBePooled; } |
| 131 |
| 120 protected: | 132 protected: |
| 121 Constant(OperandKind Kind, Type Ty, uint32_t PoolEntryID) | 133 Constant(OperandKind Kind, Type Ty, uint32_t PoolEntryID) |
| 122 : Operand(Kind, Ty), PoolEntryID(PoolEntryID) { | 134 : Operand(Kind, Ty), PoolEntryID(PoolEntryID), shouldBePooled(false) { |
| 123 Vars = nullptr; | 135 Vars = nullptr; |
| 124 NumVars = 0; | 136 NumVars = 0; |
| 125 } | 137 } |
| 126 ~Constant() override {} | 138 ~Constant() override {} |
| 127 // PoolEntryID is an integer that uniquely identifies the constant | 139 // PoolEntryID is an integer that uniquely identifies the constant |
| 128 // within its constant pool. It is used for building the constant | 140 // within its constant pool. It is used for building the constant |
| 129 // pool in the object code and for referencing its entries. | 141 // pool in the object code and for referencing its entries. |
| 130 const uint32_t PoolEntryID; | 142 const uint32_t PoolEntryID; |
| 143 // Whether we should pool this constant. Usually Float/Double and pooled |
| 144 // Integers should be flagged true. |
| 145 bool shouldBePooled; |
| 131 }; | 146 }; |
| 132 | 147 |
| 133 // ConstantPrimitive<> wraps a primitive type. | 148 // ConstantPrimitive<> wraps a primitive type. |
| 134 template <typename T, Operand::OperandKind K> | 149 template <typename T, Operand::OperandKind K> |
| 135 class ConstantPrimitive : public Constant { | 150 class ConstantPrimitive : public Constant { |
| 136 ConstantPrimitive() = delete; | 151 ConstantPrimitive() = delete; |
| 137 ConstantPrimitive(const ConstantPrimitive &) = delete; | 152 ConstantPrimitive(const ConstantPrimitive &) = delete; |
| 138 ConstantPrimitive &operator=(const ConstantPrimitive &) = delete; | 153 ConstantPrimitive &operator=(const ConstantPrimitive &) = delete; |
| 139 | 154 |
| 140 public: | 155 public: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 153 using Constant::dump; | 168 using Constant::dump; |
| 154 void dump(const Cfg *, Ostream &Str) const override { | 169 void dump(const Cfg *, Ostream &Str) const override { |
| 155 if (ALLOW_DUMP) | 170 if (ALLOW_DUMP) |
| 156 Str << getValue(); | 171 Str << getValue(); |
| 157 } | 172 } |
| 158 | 173 |
| 159 static bool classof(const Operand *Operand) { | 174 static bool classof(const Operand *Operand) { |
| 160 return Operand->getKind() == K; | 175 return Operand->getKind() == K; |
| 161 } | 176 } |
| 162 | 177 |
| 178 virtual bool shouldBeRandomizedOrPooled(const GlobalContext *Ctx) override { |
| 179 (void)Ctx; |
| 180 return false; |
| 181 } |
| 182 |
| 163 private: | 183 private: |
| 164 ConstantPrimitive(Type Ty, PrimType Value, uint32_t PoolEntryID) | 184 ConstantPrimitive(Type Ty, PrimType Value, uint32_t PoolEntryID) |
| 165 : Constant(K, Ty, PoolEntryID), Value(Value) {} | 185 : Constant(K, Ty, PoolEntryID), Value(Value) {} |
| 166 ~ConstantPrimitive() override {} | 186 ~ConstantPrimitive() override {} |
| 167 const PrimType Value; | 187 const PrimType Value; |
| 168 }; | 188 }; |
| 169 | 189 |
| 170 typedef ConstantPrimitive<int32_t, Operand::kConstInteger32> ConstantInteger32; | 190 typedef ConstantPrimitive<int32_t, Operand::kConstInteger32> ConstantInteger32; |
| 171 typedef ConstantPrimitive<int64_t, Operand::kConstInteger64> ConstantInteger64; | 191 typedef ConstantPrimitive<int64_t, Operand::kConstInteger64> ConstantInteger64; |
| 172 typedef ConstantPrimitive<float, Operand::kConstFloat> ConstantFloat; | 192 typedef ConstantPrimitive<float, Operand::kConstFloat> ConstantFloat; |
| 173 typedef ConstantPrimitive<double, Operand::kConstDouble> ConstantDouble; | 193 typedef ConstantPrimitive<double, Operand::kConstDouble> ConstantDouble; |
| 174 | 194 |
| 175 template <> | 195 template <> |
| 176 inline void ConstantInteger32::dump(const Cfg *, Ostream &Str) const { | 196 inline void ConstantInteger32::dump(const Cfg *, Ostream &Str) const { |
| 177 if (!ALLOW_DUMP) | 197 if (!ALLOW_DUMP) |
| 178 return; | 198 return; |
| 179 if (getType() == IceType_i1) | 199 if (getType() == IceType_i1) |
| 180 Str << (getValue() ? "true" : "false"); | 200 Str << (getValue() ? "true" : "false"); |
| 181 else | 201 else |
| 182 Str << static_cast<int32_t>(getValue()); | 202 Str << static_cast<int32_t>(getValue()); |
| 183 } | 203 } |
| 184 | 204 |
| 205 // Specialization of the template member function for ConstantInteger32 |
| 206 template <> |
| 207 bool ConstantInteger32::shouldBeRandomizedOrPooled(const GlobalContext *Ctx); |
| 208 |
| 185 template <> | 209 template <> |
| 186 inline void ConstantInteger64::dump(const Cfg *, Ostream &Str) const { | 210 inline void ConstantInteger64::dump(const Cfg *, Ostream &Str) const { |
| 187 if (!ALLOW_DUMP) | 211 if (!ALLOW_DUMP) |
| 188 return; | 212 return; |
| 189 assert(getType() == IceType_i64); | 213 assert(getType() == IceType_i64); |
| 190 Str << static_cast<int64_t>(getValue()); | 214 Str << static_cast<int64_t>(getValue()); |
| 191 } | 215 } |
| 192 | 216 |
| 193 // RelocatableTuple bundles the parameters that are used to | 217 // RelocatableTuple bundles the parameters that are used to |
| 194 // construct an ConstantRelocatable. It is done this way so that | 218 // construct an ConstantRelocatable. It is done this way so that |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 private: | 655 private: |
| 632 const Cfg *Func; | 656 const Cfg *Func; |
| 633 MetadataKind Kind; | 657 MetadataKind Kind; |
| 634 std::vector<VariableTracking> Metadata; | 658 std::vector<VariableTracking> Metadata; |
| 635 const static InstDefList NoDefinitions; | 659 const static InstDefList NoDefinitions; |
| 636 }; | 660 }; |
| 637 | 661 |
| 638 } // end of namespace Ice | 662 } // end of namespace Ice |
| 639 | 663 |
| 640 #endif // SUBZERO_SRC_ICEOPERAND_H | 664 #endif // SUBZERO_SRC_ICEOPERAND_H |
| OLD | NEW |