Chromium Code Reviews| 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 /// \file | 10 /// \file |
| 11 /// \brief Declares the Operand class and its target-independent subclasses. | 11 /// \brief Declares the Operand class and its target-independent subclasses. |
| 12 /// | 12 /// |
| 13 /// The main classes are Variable, which represents an LLVM variable that is | 13 /// The main classes are Variable, which represents an LLVM variable that is |
| 14 /// either register- or stack-allocated, and the Constant hierarchy, which | 14 /// either register- or stack-allocated, and the Constant hierarchy, which |
| 15 /// represents integer, floating-point, and/or symbolic constants. | 15 /// represents integer, floating-point, and/or symbolic constants. |
| 16 /// | 16 /// |
| 17 //===----------------------------------------------------------------------===// | 17 //===----------------------------------------------------------------------===// |
| 18 | 18 |
| 19 #ifndef SUBZERO_SRC_ICEOPERAND_H | 19 #ifndef SUBZERO_SRC_ICEOPERAND_H |
| 20 #define SUBZERO_SRC_ICEOPERAND_H | 20 #define SUBZERO_SRC_ICEOPERAND_H |
| 21 | 21 |
| 22 #include "IceCfg.h" | 22 #include "IceCfg.h" |
| 23 #include "IceDefs.h" | 23 #include "IceDefs.h" |
| 24 #include "IceGlobalContext.h" | 24 #include "IceGlobalContext.h" |
| 25 #include "IceTypes.h" | 25 #include "IceTypes.h" |
| 26 | 26 |
| 27 #include "llvm/Support/Format.h" | 27 #include "llvm/Support/Format.h" |
| 28 | 28 |
| 29 #include <limits> | |
| 30 | |
| 29 namespace Ice { | 31 namespace Ice { |
| 30 | 32 |
| 31 class Operand { | 33 class Operand { |
| 32 Operand() = delete; | 34 Operand() = delete; |
| 33 Operand(const Operand &) = delete; | 35 Operand(const Operand &) = delete; |
| 34 Operand &operator=(const Operand &) = delete; | 36 Operand &operator=(const Operand &) = delete; |
| 35 | 37 |
| 36 public: | 38 public: |
| 37 static constexpr size_t MaxTargetKinds = 10; | 39 static constexpr size_t MaxTargetKinds = 10; |
| 38 enum OperandKind { | 40 enum OperandKind { |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 bool ConstantInteger32::shouldBeRandomizedOrPooled(const GlobalContext *Ctx); | 242 bool ConstantInteger32::shouldBeRandomizedOrPooled(const GlobalContext *Ctx); |
| 241 | 243 |
| 242 template <> | 244 template <> |
| 243 inline void ConstantInteger64::dump(const Cfg *, Ostream &Str) const { | 245 inline void ConstantInteger64::dump(const Cfg *, Ostream &Str) const { |
| 244 if (!BuildDefs::dump()) | 246 if (!BuildDefs::dump()) |
| 245 return; | 247 return; |
| 246 assert(getType() == IceType_i64); | 248 assert(getType() == IceType_i64); |
| 247 Str << static_cast<int64_t>(getValue()); | 249 Str << static_cast<int64_t>(getValue()); |
| 248 } | 250 } |
| 249 | 251 |
| 252 /// RelocOffset allows symbolic references in ConstantRelocatables' offsets, | |
| 253 /// e.g., 8 + LabelOffset, where label offset is the location (code or data) | |
| 254 /// of a Label that is only determinable during ELF emission. | |
| 255 class RelocOffset final { | |
| 256 RelocOffset(const RelocOffset &) = delete; | |
| 257 RelocOffset &operator=(const RelocOffset &) = delete; | |
| 258 | |
| 259 public: | |
| 260 static RelocOffset *create(GlobalContext *Ctx) { | |
| 261 return new (Ctx->allocate<RelocOffset>()) RelocOffset(); | |
| 262 } | |
| 263 | |
| 264 static RelocOffset *create(GlobalContext *Ctx, RelocOffsetT Value) { | |
| 265 return new (Ctx->allocate<RelocOffset>()) RelocOffset(Value); | |
| 266 } | |
| 267 | |
| 268 bool hasOffset() const { return HasOffset; } | |
| 269 | |
| 270 RelocOffsetT getOffset() const { | |
| 271 assert(HasOffset); | |
| 272 return Offset; | |
| 273 } | |
| 274 | |
| 275 void setOffset(const RelocOffsetT Value) { | |
| 276 assert(!HasOffset); | |
| 277 Offset = Value; | |
| 278 HasOffset = true; | |
| 279 } | |
| 280 | |
| 281 private: | |
| 282 RelocOffset() = default; | |
| 283 explicit RelocOffset(RelocOffsetT Offset) { setOffset(Offset); } | |
| 284 | |
| 285 bool HasOffset = false; | |
| 286 RelocOffsetT Offset; | |
| 287 }; | |
| 288 | |
| 250 /// RelocatableTuple bundles the parameters that are used to construct an | 289 /// RelocatableTuple bundles the parameters that are used to construct an |
| 251 /// ConstantRelocatable. It is done this way so that ConstantRelocatable can fit | 290 /// ConstantRelocatable. It is done this way so that ConstantRelocatable can fit |
| 252 /// into the global constant pool template mechanism. | 291 /// into the global constant pool template mechanism. |
| 253 class RelocatableTuple { | 292 class RelocatableTuple { |
| 254 RelocatableTuple() = delete; | 293 RelocatableTuple() = delete; |
| 255 RelocatableTuple &operator=(const RelocatableTuple &) = delete; | 294 RelocatableTuple &operator=(const RelocatableTuple &) = delete; |
| 256 | 295 |
| 257 public: | 296 public: |
| 258 RelocatableTuple(const RelocOffsetT Offset, const IceString &Name, | 297 RelocatableTuple(std::vector<RelocOffset *> OffsetExpr, const IceString &Name, |
| 259 bool SuppressMangling) | 298 bool SuppressMangling) |
| 260 : Offset(Offset), Name(Name), SuppressMangling(SuppressMangling) {} | 299 : OffsetExpr(OffsetExpr), Name(Name), SuppressMangling(SuppressMangling) { |
| 300 } | |
| 261 RelocatableTuple(const RelocatableTuple &) = default; | 301 RelocatableTuple(const RelocatableTuple &) = default; |
| 262 | 302 |
| 263 const RelocOffsetT Offset; | 303 std::vector<RelocOffset *> OffsetExpr; |
|
Jim Stichnoth
2016/02/02 17:13:44
const
John
2016/02/02 19:36:39
Done.
| |
| 264 const IceString Name; | 304 const IceString Name; |
| 265 bool SuppressMangling; | 305 bool SuppressMangling; |
| 266 }; | 306 }; |
| 267 | 307 |
| 268 bool operator==(const RelocatableTuple &A, const RelocatableTuple &B); | 308 bool operator==(const RelocatableTuple &A, const RelocatableTuple &B); |
| 269 | 309 |
| 270 /// ConstantRelocatable represents a symbolic constant combined with a fixed | 310 /// ConstantRelocatable represents a symbolic constant combined with a fixed |
| 271 /// offset. | 311 /// offset. |
| 272 class ConstantRelocatable : public Constant { | 312 class ConstantRelocatable : public Constant { |
| 273 ConstantRelocatable() = delete; | 313 ConstantRelocatable() = delete; |
| 274 ConstantRelocatable(const ConstantRelocatable &) = delete; | 314 ConstantRelocatable(const ConstantRelocatable &) = delete; |
| 275 ConstantRelocatable &operator=(const ConstantRelocatable &) = delete; | 315 ConstantRelocatable &operator=(const ConstantRelocatable &) = delete; |
| 276 | 316 |
| 277 public: | 317 public: |
| 278 static ConstantRelocatable *create(GlobalContext *Ctx, Type Ty, | 318 static ConstantRelocatable *create(GlobalContext *Ctx, Type Ty, |
| 279 const RelocatableTuple &Tuple) { | 319 const RelocatableTuple &Tuple) { |
| 280 return new (Ctx->allocate<ConstantRelocatable>()) ConstantRelocatable( | 320 return new (Ctx->allocate<ConstantRelocatable>()) ConstantRelocatable( |
| 281 Ty, Tuple.Offset, Tuple.Name, Tuple.SuppressMangling); | 321 Ty, Tuple.OffsetExpr, Tuple.Name, Tuple.SuppressMangling); |
| 282 } | 322 } |
| 283 | 323 |
| 284 RelocOffsetT getOffset() const { return Offset; } | 324 RelocOffsetT getOffset() const { |
| 325 RelocOffsetT Offset = 0; | |
| 326 for (const auto *const OffsetReloc : OffsetExpr) { | |
| 327 Offset += OffsetReloc->getOffset(); | |
| 328 } | |
| 329 return Offset; | |
| 330 } | |
| 331 | |
| 332 void setEmitString(IceString Value) { | |
|
Jim Stichnoth
2016/02/02 17:13:44
Generally, Constants should not have setters, sinc
John
2016/02/02 19:36:39
Done.
| |
| 333 EmitString = std::move(Value); | |
| 334 HasEmitString = true; | |
| 335 } | |
| 336 | |
| 337 const IceString &getEmitString() const { return EmitString; } | |
| 338 | |
| 285 const IceString &getName() const { return Name; } | 339 const IceString &getName() const { return Name; } |
| 286 void setSuppressMangling(bool Value) { SuppressMangling = Value; } | 340 void setSuppressMangling(bool Value) { SuppressMangling = Value; } |
| 287 bool getSuppressMangling() const { return SuppressMangling; } | 341 bool getSuppressMangling() const { return SuppressMangling; } |
| 288 using Constant::emit; | 342 using Constant::emit; |
| 289 void emit(TargetLowering *Target) const final; | 343 void emit(TargetLowering *Target) const final; |
| 290 void emitWithoutPrefix(const TargetLowering *Target, | 344 void emitWithoutPrefix(const TargetLowering *Target, |
| 291 const char *Suffix = "") const; | 345 const char *Suffix = "") const; |
| 292 using Constant::dump; | 346 using Constant::dump; |
| 293 void dump(const Cfg *Func, Ostream &Str) const override; | 347 void dump(const Cfg *Func, Ostream &Str) const override; |
| 294 | 348 |
| 295 static bool classof(const Operand *Operand) { | 349 static bool classof(const Operand *Operand) { |
| 296 OperandKind Kind = Operand->getKind(); | 350 OperandKind Kind = Operand->getKind(); |
| 297 return Kind == kConstRelocatable; | 351 return Kind == kConstRelocatable; |
| 298 } | 352 } |
| 299 | 353 |
| 300 private: | 354 private: |
| 301 ConstantRelocatable(Type Ty, RelocOffsetT Offset, const IceString &Name, | 355 ConstantRelocatable(Type Ty, std::vector<RelocOffset *> OffsetExpr, |
| 302 bool SuppressMangling) | 356 const IceString &Name, bool SuppressMangling) |
| 303 : Constant(kConstRelocatable, Ty), Offset(Offset), Name(Name), | 357 : Constant(kConstRelocatable, Ty), OffsetExpr(std::move(OffsetExpr)), |
| 304 SuppressMangling(SuppressMangling) {} | 358 Name(Name), SuppressMangling(SuppressMangling) {} |
| 305 const RelocOffsetT Offset; /// fixed offset to add | 359 bool HasEmitString = false; |
| 306 const IceString Name; /// optional for debug/dump | 360 IceString EmitString; |
| 361 const std::vector<RelocOffset *> OffsetExpr; /// fixed offset to add | |
| 362 const IceString Name; /// optional for debug/dump | |
| 307 bool SuppressMangling; | 363 bool SuppressMangling; |
| 308 }; | 364 }; |
| 309 | 365 |
| 310 /// ConstantUndef represents an unspecified bit pattern. Although it is legal to | 366 /// ConstantUndef represents an unspecified bit pattern. Although it is legal to |
| 311 /// lower ConstantUndef to any value, backends should try to make code | 367 /// lower ConstantUndef to any value, backends should try to make code |
| 312 /// generation deterministic by lowering ConstantUndefs to 0. | 368 /// generation deterministic by lowering ConstantUndefs to 0. |
| 313 class ConstantUndef : public Constant { | 369 class ConstantUndef : public Constant { |
| 314 ConstantUndef() = delete; | 370 ConstantUndef() = delete; |
| 315 ConstantUndef(const ConstantUndef &) = delete; | 371 ConstantUndef(const ConstantUndef &) = delete; |
| 316 ConstantUndef &operator=(const ConstantUndef &) = delete; | 372 ConstantUndef &operator=(const ConstantUndef &) = delete; |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 746 private: | 802 private: |
| 747 const Cfg *Func; | 803 const Cfg *Func; |
| 748 MetadataKind Kind; | 804 MetadataKind Kind; |
| 749 CfgVector<VariableTracking> Metadata; | 805 CfgVector<VariableTracking> Metadata; |
| 750 const static InstDefList NoDefinitions; | 806 const static InstDefList NoDefinitions; |
| 751 }; | 807 }; |
| 752 | 808 |
| 753 } // end of namespace Ice | 809 } // end of namespace Ice |
| 754 | 810 |
| 755 #endif // SUBZERO_SRC_ICEOPERAND_H | 811 #endif // SUBZERO_SRC_ICEOPERAND_H |
| OLD | NEW |