| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 return; | 73 return; |
| 74 assert(Func); | 74 assert(Func); |
| 75 dump(Func, Func->getContext()->getStrDump()); | 75 dump(Func, Func->getContext()->getStrDump()); |
| 76 } | 76 } |
| 77 void dump(Ostream &Str) const { | 77 void dump(Ostream &Str) const { |
| 78 if (BuildDefs::dump()) | 78 if (BuildDefs::dump()) |
| 79 dump(nullptr, Str); | 79 dump(nullptr, Str); |
| 80 } | 80 } |
| 81 | 81 |
| 82 protected: | 82 protected: |
| 83 Operand(OperandKind Kind, Type Ty) : Ty(Ty), Kind(Kind) {} | 83 Operand(OperandKind MyKind, Type MyTy) : Ty(MyTy), Kind(MyKind) {} |
| 84 virtual ~Operand() = default; | 84 virtual ~Operand() = default; |
| 85 | 85 |
| 86 const Type Ty; | 86 const Type Ty; |
| 87 const OperandKind Kind; | 87 const OperandKind Kind; |
| 88 // Vars and NumVars are initialized by the derived class. | 88 // Vars and NumVars are initialized by the derived class. |
| 89 SizeT NumVars = 0; | 89 SizeT NumVars = 0; |
| 90 Variable **Vars = nullptr; | 90 Variable **Vars = nullptr; |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 template <class StreamType> | 93 template <class StreamType> |
| (...skipping 27 matching lines...) Expand all Loading... |
| 121 virtual bool shouldBeRandomizedOrPooled(const GlobalContext *Ctx) { | 121 virtual bool shouldBeRandomizedOrPooled(const GlobalContext *Ctx) { |
| 122 (void)Ctx; | 122 (void)Ctx; |
| 123 return false; | 123 return false; |
| 124 } | 124 } |
| 125 | 125 |
| 126 void setShouldBePooled(bool R) { shouldBePooled = R; } | 126 void setShouldBePooled(bool R) { shouldBePooled = R; } |
| 127 | 127 |
| 128 bool getShouldBePooled() const { return shouldBePooled; } | 128 bool getShouldBePooled() const { return shouldBePooled; } |
| 129 | 129 |
| 130 protected: | 130 protected: |
| 131 Constant(OperandKind Kind, Type Ty, uint32_t PoolEntryID) | 131 Constant(OperandKind Kind, Type Ty, uint32_t MyPoolEntryID) |
| 132 : Operand(Kind, Ty), PoolEntryID(PoolEntryID), shouldBePooled(false) { | 132 : Operand(Kind, Ty), PoolEntryID(MyPoolEntryID), shouldBePooled(false) { |
| 133 Vars = nullptr; | 133 Vars = nullptr; |
| 134 NumVars = 0; | 134 NumVars = 0; |
| 135 } | 135 } |
| 136 // PoolEntryID is an integer that uniquely identifies the constant | 136 // PoolEntryID is an integer that uniquely identifies the constant |
| 137 // within its constant pool. It is used for building the constant | 137 // within its constant pool. It is used for building the constant |
| 138 // pool in the object code and for referencing its entries. | 138 // pool in the object code and for referencing its entries. |
| 139 const uint32_t PoolEntryID; | 139 const uint32_t PoolEntryID; |
| 140 // Whether we should pool this constant. Usually Float/Double and pooled | 140 // Whether we should pool this constant. Usually Float/Double and pooled |
| 141 // Integers should be flagged true. | 141 // Integers should be flagged true. |
| 142 bool shouldBePooled; | 142 bool shouldBePooled; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 171 static bool classof(const Operand *Operand) { | 171 static bool classof(const Operand *Operand) { |
| 172 return Operand->getKind() == K; | 172 return Operand->getKind() == K; |
| 173 } | 173 } |
| 174 | 174 |
| 175 virtual bool shouldBeRandomizedOrPooled(const GlobalContext *Ctx) override { | 175 virtual bool shouldBeRandomizedOrPooled(const GlobalContext *Ctx) override { |
| 176 (void)Ctx; | 176 (void)Ctx; |
| 177 return false; | 177 return false; |
| 178 } | 178 } |
| 179 | 179 |
| 180 private: | 180 private: |
| 181 ConstantPrimitive(Type Ty, PrimType Value, uint32_t PoolEntryID) | 181 ConstantPrimitive(Type Ty, PrimType MyValue, uint32_t PoolEntryID) |
| 182 : Constant(K, Ty, PoolEntryID), Value(Value) {} | 182 : Constant(K, Ty, PoolEntryID), Value(MyValue) {} |
| 183 const PrimType Value; | 183 const PrimType Value; |
| 184 }; | 184 }; |
| 185 | 185 |
| 186 typedef ConstantPrimitive<int32_t, Operand::kConstInteger32> ConstantInteger32; | 186 typedef ConstantPrimitive<int32_t, Operand::kConstInteger32> ConstantInteger32; |
| 187 typedef ConstantPrimitive<int64_t, Operand::kConstInteger64> ConstantInteger64; | 187 typedef ConstantPrimitive<int64_t, Operand::kConstInteger64> ConstantInteger64; |
| 188 typedef ConstantPrimitive<float, Operand::kConstFloat> ConstantFloat; | 188 typedef ConstantPrimitive<float, Operand::kConstFloat> ConstantFloat; |
| 189 typedef ConstantPrimitive<double, Operand::kConstDouble> ConstantDouble; | 189 typedef ConstantPrimitive<double, Operand::kConstDouble> ConstantDouble; |
| 190 | 190 |
| 191 template <> | 191 template <> |
| 192 inline void ConstantInteger32::dump(const Cfg *, Ostream &Str) const { | 192 inline void ConstantInteger32::dump(const Cfg *, Ostream &Str) const { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 212 | 212 |
| 213 // RelocatableTuple bundles the parameters that are used to | 213 // RelocatableTuple bundles the parameters that are used to |
| 214 // construct an ConstantRelocatable. It is done this way so that | 214 // construct an ConstantRelocatable. It is done this way so that |
| 215 // ConstantRelocatable can fit into the global constant pool | 215 // ConstantRelocatable can fit into the global constant pool |
| 216 // template mechanism. | 216 // template mechanism. |
| 217 class RelocatableTuple { | 217 class RelocatableTuple { |
| 218 RelocatableTuple() = delete; | 218 RelocatableTuple() = delete; |
| 219 RelocatableTuple &operator=(const RelocatableTuple &) = delete; | 219 RelocatableTuple &operator=(const RelocatableTuple &) = delete; |
| 220 | 220 |
| 221 public: | 221 public: |
| 222 RelocatableTuple(const RelocOffsetT Offset, const IceString &Name, | 222 RelocatableTuple(const RelocOffsetT MyOffset, const IceString &MyName, |
| 223 bool SuppressMangling) | 223 bool MySuppressMangling) |
| 224 : Offset(Offset), Name(Name), SuppressMangling(SuppressMangling) {} | 224 : Offset(MyOffset), Name(MyName), SuppressMangling(MySuppressMangling) {} |
| 225 RelocatableTuple(const RelocatableTuple &) = default; | 225 RelocatableTuple(const RelocatableTuple &) = default; |
| 226 | 226 |
| 227 const RelocOffsetT Offset; | 227 const RelocOffsetT Offset; |
| 228 const IceString Name; | 228 const IceString Name; |
| 229 bool SuppressMangling; | 229 bool SuppressMangling; |
| 230 }; | 230 }; |
| 231 | 231 |
| 232 bool operator==(const RelocatableTuple &A, const RelocatableTuple &B); | 232 bool operator==(const RelocatableTuple &A, const RelocatableTuple &B); |
| 233 | 233 |
| 234 // ConstantRelocatable represents a symbolic constant combined with | 234 // ConstantRelocatable represents a symbolic constant combined with |
| (...skipping 22 matching lines...) Expand all Loading... |
| 257 void emitWithoutPrefix(TargetLowering *Target) const; | 257 void emitWithoutPrefix(TargetLowering *Target) const; |
| 258 using Constant::dump; | 258 using Constant::dump; |
| 259 void dump(const Cfg *Func, Ostream &Str) const override; | 259 void dump(const Cfg *Func, Ostream &Str) const override; |
| 260 | 260 |
| 261 static bool classof(const Operand *Operand) { | 261 static bool classof(const Operand *Operand) { |
| 262 OperandKind Kind = Operand->getKind(); | 262 OperandKind Kind = Operand->getKind(); |
| 263 return Kind == kConstRelocatable; | 263 return Kind == kConstRelocatable; |
| 264 } | 264 } |
| 265 | 265 |
| 266 private: | 266 private: |
| 267 ConstantRelocatable(Type Ty, RelocOffsetT Offset, const IceString &Name, | 267 ConstantRelocatable(Type Ty, RelocOffsetT MyOffset, const IceString &MyName, |
| 268 bool SuppressMangling, uint32_t PoolEntryID) | 268 bool MySuppressMangling, uint32_t PoolEntryID) |
| 269 : Constant(kConstRelocatable, Ty, PoolEntryID), Offset(Offset), | 269 : Constant(kConstRelocatable, Ty, PoolEntryID), Offset(MyOffset), |
| 270 Name(Name), SuppressMangling(SuppressMangling) {} | 270 Name(MyName), SuppressMangling(MySuppressMangling) {} |
| 271 const RelocOffsetT Offset; // fixed offset to add | 271 const RelocOffsetT Offset; // fixed offset to add |
| 272 const IceString Name; // optional for debug/dump | 272 const IceString Name; // optional for debug/dump |
| 273 bool SuppressMangling; | 273 bool SuppressMangling; |
| 274 }; | 274 }; |
| 275 | 275 |
| 276 // ConstantUndef represents an unspecified bit pattern. Although it is | 276 // ConstantUndef represents an unspecified bit pattern. Although it is |
| 277 // legal to lower ConstantUndef to any value, backends should try to | 277 // legal to lower ConstantUndef to any value, backends should try to |
| 278 // make code generation deterministic by lowering ConstantUndefs to 0. | 278 // make code generation deterministic by lowering ConstantUndefs to 0. |
| 279 class ConstantUndef : public Constant { | 279 class ConstantUndef : public Constant { |
| 280 ConstantUndef() = delete; | 280 ConstantUndef() = delete; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 305 ConstantUndef(Type Ty, uint32_t PoolEntryID) | 305 ConstantUndef(Type Ty, uint32_t PoolEntryID) |
| 306 : Constant(kConstUndef, Ty, PoolEntryID) {} | 306 : Constant(kConstUndef, Ty, PoolEntryID) {} |
| 307 }; | 307 }; |
| 308 | 308 |
| 309 // RegWeight is a wrapper for a uint32_t weight value, with a | 309 // RegWeight is a wrapper for a uint32_t weight value, with a |
| 310 // special value that represents infinite weight, and an addWeight() | 310 // special value that represents infinite weight, and an addWeight() |
| 311 // method that ensures that W+infinity=infinity. | 311 // method that ensures that W+infinity=infinity. |
| 312 class RegWeight { | 312 class RegWeight { |
| 313 public: | 313 public: |
| 314 RegWeight() = default; | 314 RegWeight() = default; |
| 315 explicit RegWeight(uint32_t Weight) : Weight(Weight) {} | 315 explicit RegWeight(uint32_t MyWeight) : Weight(MyWeight) {} |
| 316 RegWeight(const RegWeight &) = default; | 316 RegWeight(const RegWeight &) = default; |
| 317 RegWeight &operator=(const RegWeight &) = default; | 317 RegWeight &operator=(const RegWeight &) = default; |
| 318 const static uint32_t Inf = ~0; // Force regalloc to give a register | 318 const static uint32_t Inf = ~0; // Force regalloc to give a register |
| 319 const static uint32_t Zero = 0; // Force regalloc NOT to give a register | 319 const static uint32_t Zero = 0; // Force regalloc NOT to give a register |
| 320 void addWeight(uint32_t Delta) { | 320 void addWeight(uint32_t Delta) { |
| 321 if (Delta == Inf) | 321 if (Delta == Inf) |
| 322 Weight = Inf; | 322 Weight = Inf; |
| 323 else if (Weight != Inf) | 323 else if (Weight != Inf) |
| 324 Weight += Delta; | 324 Weight += Delta; |
| 325 } | 325 } |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 }; | 590 }; |
| 591 | 591 |
| 592 // VariablesMetadata analyzes and summarizes the metadata for the | 592 // VariablesMetadata analyzes and summarizes the metadata for the |
| 593 // complete set of Variables. | 593 // complete set of Variables. |
| 594 class VariablesMetadata { | 594 class VariablesMetadata { |
| 595 VariablesMetadata() = delete; | 595 VariablesMetadata() = delete; |
| 596 VariablesMetadata(const VariablesMetadata &) = delete; | 596 VariablesMetadata(const VariablesMetadata &) = delete; |
| 597 VariablesMetadata &operator=(const VariablesMetadata &) = delete; | 597 VariablesMetadata &operator=(const VariablesMetadata &) = delete; |
| 598 | 598 |
| 599 public: | 599 public: |
| 600 explicit VariablesMetadata(const Cfg *Func) : Func(Func) {} | 600 explicit VariablesMetadata(const Cfg *MyFunc) : Func(MyFunc) {} |
| 601 // Initialize the state by traversing all instructions/variables in | 601 // Initialize the state by traversing all instructions/variables in |
| 602 // the CFG. | 602 // the CFG. |
| 603 void init(MetadataKind TrackingKind); | 603 void init(MetadataKind TrackingKind); |
| 604 // Add a single node. This is called by init(), and can be called | 604 // Add a single node. This is called by init(), and can be called |
| 605 // incrementally from elsewhere, e.g. after edge-splitting. | 605 // incrementally from elsewhere, e.g. after edge-splitting. |
| 606 void addNode(CfgNode *Node); | 606 void addNode(CfgNode *Node); |
| 607 // Returns whether the given Variable is tracked in this object. It | 607 // Returns whether the given Variable is tracked in this object. It |
| 608 // should only return false if changes were made to the CFG after | 608 // should only return false if changes were made to the CFG after |
| 609 // running init(), in which case the state is stale and the results | 609 // running init(), in which case the state is stale and the results |
| 610 // shouldn't be trusted (but it may be OK e.g. for dumping). | 610 // shouldn't be trusted (but it may be OK e.g. for dumping). |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 private: | 644 private: |
| 645 const Cfg *Func; | 645 const Cfg *Func; |
| 646 MetadataKind Kind; | 646 MetadataKind Kind; |
| 647 std::vector<VariableTracking> Metadata; | 647 std::vector<VariableTracking> Metadata; |
| 648 const static InstDefList NoDefinitions; | 648 const static InstDefList NoDefinitions; |
| 649 }; | 649 }; |
| 650 | 650 |
| 651 } // end of namespace Ice | 651 } // end of namespace Ice |
| 652 | 652 |
| 653 #endif // SUBZERO_SRC_ICEOPERAND_H | 653 #endif // SUBZERO_SRC_ICEOPERAND_H |
| OLD | NEW |