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 "IceDefs.h" |
22 #include "IceCfg.h" | 23 #include "IceCfg.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> | 29 #include <limits> |
30 | 30 |
31 namespace Ice { | 31 namespace Ice { |
32 | 32 |
33 class Operand { | 33 class Operand { |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 }; | 294 }; |
295 | 295 |
296 /// RelocatableTuple bundles the parameters that are used to construct an | 296 /// RelocatableTuple bundles the parameters that are used to construct an |
297 /// ConstantRelocatable. It is done this way so that ConstantRelocatable can fit | 297 /// ConstantRelocatable. It is done this way so that ConstantRelocatable can fit |
298 /// into the global constant pool template mechanism. | 298 /// into the global constant pool template mechanism. |
299 class RelocatableTuple { | 299 class RelocatableTuple { |
300 RelocatableTuple() = delete; | 300 RelocatableTuple() = delete; |
301 RelocatableTuple &operator=(const RelocatableTuple &) = delete; | 301 RelocatableTuple &operator=(const RelocatableTuple &) = delete; |
302 | 302 |
303 public: | 303 public: |
304 RelocatableTuple(const RelocOffsetArray &OffsetExpr, const IceString &Name, | 304 RelocatableTuple(const RelocOffsetT Offset, |
| 305 const RelocOffsetArray &OffsetExpr, const IceString &Name, |
305 bool SuppressMangling) | 306 bool SuppressMangling) |
306 : OffsetExpr(OffsetExpr), Name(Name), SuppressMangling(SuppressMangling) { | 307 : Offset(Offset), OffsetExpr(OffsetExpr), Name(Name), |
307 } | 308 SuppressMangling(SuppressMangling) {} |
308 | 309 |
309 RelocatableTuple(const RelocOffsetArray &OffsetExpr, const IceString &Name, | 310 RelocatableTuple(const RelocOffsetT Offset, |
| 311 const RelocOffsetArray &OffsetExpr, const IceString &Name, |
310 const IceString &EmitString, bool SuppressMangling) | 312 const IceString &EmitString, bool SuppressMangling) |
311 : OffsetExpr(OffsetExpr), Name(Name), EmitString(EmitString), | 313 : Offset(Offset), OffsetExpr(OffsetExpr), Name(Name), |
312 SuppressMangling(SuppressMangling) {} | 314 EmitString(EmitString), SuppressMangling(SuppressMangling) {} |
313 | 315 |
314 RelocatableTuple(const RelocatableTuple &) = default; | 316 RelocatableTuple(const RelocatableTuple &) = default; |
315 | 317 |
| 318 const RelocOffsetT Offset; |
316 const RelocOffsetArray OffsetExpr; | 319 const RelocOffsetArray OffsetExpr; |
317 const IceString Name; | 320 const IceString Name; |
318 const IceString EmitString; | 321 const IceString EmitString; |
319 const bool SuppressMangling; | 322 const bool SuppressMangling; |
320 }; | 323 }; |
321 | 324 |
322 bool operator==(const RelocatableTuple &A, const RelocatableTuple &B); | 325 bool operator==(const RelocatableTuple &A, const RelocatableTuple &B); |
323 | 326 |
324 /// ConstantRelocatable represents a symbolic constant combined with a fixed | 327 /// ConstantRelocatable represents a symbolic constant combined with a fixed |
325 /// offset. | 328 /// offset. |
326 class ConstantRelocatable : public Constant { | 329 class ConstantRelocatable : public Constant { |
327 ConstantRelocatable() = delete; | 330 ConstantRelocatable() = delete; |
328 ConstantRelocatable(const ConstantRelocatable &) = delete; | 331 ConstantRelocatable(const ConstantRelocatable &) = delete; |
329 ConstantRelocatable &operator=(const ConstantRelocatable &) = delete; | 332 ConstantRelocatable &operator=(const ConstantRelocatable &) = delete; |
330 | 333 |
331 public: | 334 public: |
332 static ConstantRelocatable *create(GlobalContext *Ctx, Type Ty, | 335 static ConstantRelocatable *create(GlobalContext *Ctx, Type Ty, |
333 const RelocatableTuple &Tuple) { | 336 const RelocatableTuple &Tuple) { |
334 return new (Ctx->allocate<ConstantRelocatable>()) | 337 return new (Ctx->allocate<ConstantRelocatable>()) |
335 ConstantRelocatable(Ty, Tuple.OffsetExpr, Tuple.Name, Tuple.EmitString, | 338 ConstantRelocatable(Ty, Tuple.Offset, Tuple.OffsetExpr, Tuple.Name, |
336 Tuple.SuppressMangling); | 339 Tuple.EmitString, Tuple.SuppressMangling); |
337 } | 340 } |
338 | 341 |
339 RelocOffsetT getOffset() const { | 342 RelocOffsetT getOffset() const { |
340 RelocOffsetT Offset = 0; | 343 RelocOffsetT Ret = Offset; |
341 for (const auto *const OffsetReloc : OffsetExpr) { | 344 for (const auto *const OffsetReloc : OffsetExpr) { |
342 Offset += OffsetReloc->getOffset(); | 345 Ret += OffsetReloc->getOffset(); |
343 } | 346 } |
344 return Offset; | 347 return Ret; |
345 } | 348 } |
346 | 349 |
347 const IceString &getEmitString() const { return EmitString; } | 350 const IceString &getEmitString() const { return EmitString; } |
348 | 351 |
349 const IceString &getName() const { return Name; } | 352 const IceString &getName() const { return Name; } |
350 bool getSuppressMangling() const { return SuppressMangling; } | 353 bool getSuppressMangling() const { return SuppressMangling; } |
351 using Constant::emit; | 354 using Constant::emit; |
352 void emit(TargetLowering *Target) const final; | 355 void emit(TargetLowering *Target) const final; |
353 void emitWithoutPrefix(const TargetLowering *Target, | 356 void emitWithoutPrefix(const TargetLowering *Target, |
354 const char *Suffix = "") const; | 357 const char *Suffix = "") const; |
355 using Constant::dump; | 358 using Constant::dump; |
356 void dump(const Cfg *Func, Ostream &Str) const override; | 359 void dump(const Cfg *Func, Ostream &Str) const override; |
357 | 360 |
358 static bool classof(const Operand *Operand) { | 361 static bool classof(const Operand *Operand) { |
359 OperandKind Kind = Operand->getKind(); | 362 OperandKind Kind = Operand->getKind(); |
360 return Kind == kConstRelocatable; | 363 return Kind == kConstRelocatable; |
361 } | 364 } |
362 | 365 |
363 private: | 366 private: |
364 ConstantRelocatable(Type Ty, const RelocOffsetArray &OffsetExpr, | 367 ConstantRelocatable(Type Ty, const RelocOffsetT Offset, |
365 const IceString &Name, const IceString &EmitString, | 368 const RelocOffsetArray &OffsetExpr, const IceString &Name, |
366 bool SuppressMangling) | 369 const IceString &EmitString, bool SuppressMangling) |
367 : Constant(kConstRelocatable, Ty), OffsetExpr(OffsetExpr), Name(Name), | 370 : Constant(kConstRelocatable, Ty), Offset(Offset), OffsetExpr(OffsetExpr), |
368 EmitString(EmitString), SuppressMangling(SuppressMangling) {} | 371 Name(Name), EmitString(EmitString), SuppressMangling(SuppressMangling) { |
| 372 } |
369 | 373 |
370 const RelocOffsetArray OffsetExpr; /// fixed offset to add | 374 const RelocOffsetT Offset; /// fixed, known offset to add |
| 375 const RelocOffsetArray OffsetExpr; /// fixed, unknown offset to add |
371 const IceString Name; /// optional for debug/dump | 376 const IceString Name; /// optional for debug/dump |
372 const IceString EmitString; /// optional for textual emission | 377 const IceString EmitString; /// optional for textual emission |
373 const bool SuppressMangling; | 378 const bool SuppressMangling; |
374 }; | 379 }; |
375 | 380 |
376 /// ConstantUndef represents an unspecified bit pattern. Although it is legal to | 381 /// ConstantUndef represents an unspecified bit pattern. Although it is legal to |
377 /// lower ConstantUndef to any value, backends should try to make code | 382 /// lower ConstantUndef to any value, backends should try to make code |
378 /// generation deterministic by lowering ConstantUndefs to 0. | 383 /// generation deterministic by lowering ConstantUndefs to 0. |
379 class ConstantUndef : public Constant { | 384 class ConstantUndef : public Constant { |
380 ConstantUndef() = delete; | 385 ConstantUndef() = delete; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 assert(Value == NoRegisterValue || Value < Limit); | 461 assert(Value == NoRegisterValue || Value < Limit); |
457 } | 462 } |
458 /// Disallow operators that inappropriately make assumptions about register | 463 /// Disallow operators that inappropriately make assumptions about register |
459 /// enum value ordering. | 464 /// enum value ordering. |
460 bool operator<(const RegNumT &) = delete; | 465 bool operator<(const RegNumT &) = delete; |
461 bool operator<=(const RegNumT &) = delete; | 466 bool operator<=(const RegNumT &) = delete; |
462 bool operator>(const RegNumT &) = delete; | 467 bool operator>(const RegNumT &) = delete; |
463 bool operator>=(const RegNumT &) = delete; | 468 bool operator>=(const RegNumT &) = delete; |
464 }; | 469 }; |
465 | 470 |
466 /// RegNumBVIter wraps llvm::SmallBitVector so that instead of this pattern: | 471 /// RegNumBVIter wraps SmallBitVector so that instead of this pattern: |
467 /// | 472 /// |
468 /// for (int i = V.find_first(); i != -1; i = V.find_next(i)) { | 473 /// for (int i = V.find_first(); i != -1; i = V.find_next(i)) { |
469 /// RegNumT RegNum = RegNumT::fromInt(i); | 474 /// RegNumT RegNum = RegNumT::fromInt(i); |
470 /// ... | 475 /// ... |
471 /// } | 476 /// } |
472 /// | 477 /// |
473 /// this cleaner pattern can be used: | 478 /// this cleaner pattern can be used: |
474 /// | 479 /// |
475 /// for (RegNumT RegNum : RegNumBVIter(V)) { | 480 /// for (RegNumT RegNum : RegNumBVIter(V)) { |
476 /// ... | 481 /// ... |
477 /// } | 482 /// } |
478 class RegNumBVIter { | 483 template <class B> class RegNumBVIterImpl { |
479 using T = llvm::SmallBitVector; | 484 using T = B; |
480 static constexpr int Sentinel = -1; | 485 static constexpr int Sentinel = -1; |
481 RegNumBVIter() = delete; | 486 RegNumBVIterImpl() = delete; |
482 RegNumBVIter(const RegNumBVIter &) = delete; | |
483 RegNumBVIter &operator=(const RegNumBVIter &) = delete; | |
484 | 487 |
485 public: | 488 public: |
486 class Iterator { | 489 class Iterator { |
487 Iterator() = delete; | 490 Iterator() = delete; |
488 Iterator &operator=(const Iterator &) = delete; | 491 Iterator &operator=(const Iterator &) = delete; |
489 | 492 |
490 public: | 493 public: |
491 explicit Iterator(const T &V) : V(V), Current(V.find_first()) {} | 494 explicit Iterator(const T &V) : V(V), Current(V.find_first()) {} |
492 Iterator(const T &V, int Value) : V(V), Current(Value) {} | 495 Iterator(const T &V, int Value) : V(V), Current(Value) {} |
493 Iterator(const Iterator &) = default; | 496 Iterator(const Iterator &) = default; |
494 RegNumT operator*() { | 497 RegNumT operator*() { |
495 assert(Current != Sentinel); | 498 assert(Current != Sentinel); |
496 return RegNumT::fromInt(Current); | 499 return RegNumT::fromInt(Current); |
497 } | 500 } |
498 Iterator &operator++() { | 501 Iterator &operator++() { |
499 assert(Current != Sentinel); | 502 assert(Current != Sentinel); |
500 Current = V.find_next(Current); | 503 Current = V.find_next(Current); |
501 return *this; | 504 return *this; |
502 } | 505 } |
503 bool operator!=(Iterator &Other) { return Current != Other.Current; } | 506 bool operator!=(Iterator &Other) { return Current != Other.Current; } |
504 | 507 |
505 private: | 508 private: |
506 const T &V; | 509 const T &V; |
507 int Current; | 510 int Current; |
508 }; | 511 }; |
509 | 512 |
510 explicit RegNumBVIter(const T &V) : V(V) {} | 513 RegNumBVIterImpl(const RegNumBVIterImpl &) = default; |
| 514 RegNumBVIterImpl &operator=(const RegNumBVIterImpl &) = delete; |
| 515 explicit RegNumBVIterImpl(const T &V) : V(V) {} |
511 Iterator begin() { return Iterator(V); } | 516 Iterator begin() { return Iterator(V); } |
512 Iterator end() { return Iterator(V, Sentinel); } | 517 Iterator end() { return Iterator(V, Sentinel); } |
513 | 518 |
514 private: | 519 private: |
515 const T &V; | 520 const T &V; |
516 }; | 521 }; |
517 | 522 |
| 523 template <class B> RegNumBVIterImpl<B> RegNumBVIter(const B &BV) { |
| 524 return RegNumBVIterImpl<B>(BV); |
| 525 } |
| 526 |
518 /// RegWeight is a wrapper for a uint32_t weight value, with a special value | 527 /// RegWeight is a wrapper for a uint32_t weight value, with a special value |
519 /// that represents infinite weight, and an addWeight() method that ensures that | 528 /// that represents infinite weight, and an addWeight() method that ensures that |
520 /// W+infinity=infinity. | 529 /// W+infinity=infinity. |
521 class RegWeight { | 530 class RegWeight { |
522 public: | 531 public: |
523 using BaseType = uint32_t; | 532 using BaseType = uint32_t; |
524 RegWeight() = default; | 533 RegWeight() = default; |
525 explicit RegWeight(BaseType Weight) : Weight(Weight) {} | 534 explicit RegWeight(BaseType Weight) : Weight(Weight) {} |
526 RegWeight(const RegWeight &) = default; | 535 RegWeight(const RegWeight &) = default; |
527 RegWeight &operator=(const RegWeight &) = default; | 536 RegWeight &operator=(const RegWeight &) = default; |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
924 private: | 933 private: |
925 const Cfg *Func; | 934 const Cfg *Func; |
926 MetadataKind Kind; | 935 MetadataKind Kind; |
927 CfgVector<VariableTracking> Metadata; | 936 CfgVector<VariableTracking> Metadata; |
928 const static InstDefList NoDefinitions; | 937 const static InstDefList NoDefinitions; |
929 }; | 938 }; |
930 | 939 |
931 } // end of namespace Ice | 940 } // end of namespace Ice |
932 | 941 |
933 #endif // SUBZERO_SRC_ICEOPERAND_H | 942 #endif // SUBZERO_SRC_ICEOPERAND_H |
OLD | NEW |