OLD | NEW |
(Empty) | |
| 1 //===- subzero/src/IceRegAlloc.h - Linear-scan reg. allocation --*- C++ -*-===// |
| 2 // |
| 3 // The Subzero Code Generator |
| 4 // |
| 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. |
| 7 // |
| 8 //===----------------------------------------------------------------------===// |
| 9 // |
| 10 // This file declares the data structures used during linear-scan |
| 11 // register allocation. This includes LiveRangeWrapper which |
| 12 // encapsulates a variable and its live range, and LinearScan which |
| 13 // holds the various work queues for the linear-scan algorithm. |
| 14 // |
| 15 //===----------------------------------------------------------------------===// |
| 16 |
| 17 #ifndef SUBZERO_SRC_ICEREGALLOC_H |
| 18 #define SUBZERO_SRC_ICEREGALLOC_H |
| 19 |
| 20 #include "IceDefs.h" |
| 21 #include "IceTypes.h" |
| 22 |
| 23 namespace Ice { |
| 24 |
| 25 // Currently this just wraps an Variable pointer, so in principle |
| 26 // we could use containers of Variable* instead of |
| 27 // LiveRangeWrapper. But in the future, we may want to do more |
| 28 // complex things such as live range splitting, and keeping a wrapper |
| 29 // should make that simpler. |
| 30 class LiveRangeWrapper { |
| 31 public: |
| 32 LiveRangeWrapper(Variable *Var) : Var(Var) {} |
| 33 const LiveRange &range() const { return Var->getLiveRange(); } |
| 34 bool endsBefore(const LiveRangeWrapper &Other) const { |
| 35 return range().endsBefore(Other.range()); |
| 36 } |
| 37 bool overlaps(const LiveRangeWrapper &Other) const { |
| 38 return range().overlaps(Other.range()); |
| 39 } |
| 40 Variable *const Var; |
| 41 void dump(const Cfg *Func) const; |
| 42 |
| 43 private: |
| 44 // LiveRangeWrapper(const LiveRangeWrapper &) LLVM_DELETED_FUNCTION; |
| 45 LiveRangeWrapper &operator=(const LiveRangeWrapper &) LLVM_DELETED_FUNCTION; |
| 46 }; |
| 47 |
| 48 class LinearScan { |
| 49 public: |
| 50 LinearScan(Cfg *Func) : Func(Func) {} |
| 51 void scan(const llvm::SmallBitVector &RegMask); |
| 52 void dump(Cfg *Func) const; |
| 53 |
| 54 private: |
| 55 Cfg *const Func; |
| 56 // RangeCompare is the comparator for sorting an LiveRangeWrapper |
| 57 // by starting point in a std::set<>. Ties are broken by variable |
| 58 // number so that sorting is stable. |
| 59 struct RangeCompare { |
| 60 bool operator()(const LiveRangeWrapper &L, |
| 61 const LiveRangeWrapper &R) const { |
| 62 int32_t Lstart = L.Var->getLiveRange().getStart(); |
| 63 int32_t Rstart = R.Var->getLiveRange().getStart(); |
| 64 if (Lstart == Rstart) |
| 65 return L.Var->getIndex() < R.Var->getIndex(); |
| 66 return Lstart < Rstart; |
| 67 } |
| 68 }; |
| 69 typedef std::set<LiveRangeWrapper, RangeCompare> OrderedRanges; |
| 70 typedef std::list<LiveRangeWrapper> UnorderedRanges; |
| 71 OrderedRanges Unhandled; |
| 72 UnorderedRanges Active, Inactive, Handled; |
| 73 LinearScan(const LinearScan &) LLVM_DELETED_FUNCTION; |
| 74 LinearScan &operator=(const LinearScan &) LLVM_DELETED_FUNCTION; |
| 75 }; |
| 76 |
| 77 } // end of namespace Ice |
| 78 |
| 79 #endif // SUBZERO_SRC_ICEREGALLOC_H |
OLD | NEW |