| OLD | NEW |
| 1 //===- subzero/src/IceRegAlloc.h - Linear-scan reg. allocation --*- C++ -*-===// | 1 //===- subzero/src/IceRegAlloc.h - Linear-scan reg. allocation --*- 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 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 class LinearScan { | 26 class LinearScan { |
| 27 LinearScan() = delete; | 27 LinearScan() = delete; |
| 28 LinearScan(const LinearScan &) = delete; | 28 LinearScan(const LinearScan &) = delete; |
| 29 LinearScan &operator=(const LinearScan &) = delete; | 29 LinearScan &operator=(const LinearScan &) = delete; |
| 30 | 30 |
| 31 public: | 31 public: |
| 32 explicit LinearScan(Cfg *Func); | 32 explicit LinearScan(Cfg *Func); |
| 33 void init(RegAllocKind Kind); | 33 void init(RegAllocKind Kind); |
| 34 void scan(const llvm::SmallBitVector &RegMask, bool Randomized); | 34 void scan(const llvm::SmallBitVector &RegMask, bool Randomized); |
| 35 // Returns the number of times some variable has been assigned a register but |
| 36 // later evicted because of a higher-priority allocation. The idea is that we |
| 37 // can implement "second-chance bin-packing" by rerunning register allocation |
| 38 // until there are no more evictions. |
| 39 SizeT getNumEvictions() const { return Evicted.size(); } |
| 40 bool hasEvictions() const { return !Evicted.empty(); } |
| 35 void dump(Cfg *Func) const; | 41 void dump(Cfg *Func) const; |
| 36 | 42 |
| 37 // TODO(stichnot): Statically choose the size based on the target being | 43 // TODO(stichnot): Statically choose the size based on the target being |
| 38 // compiled. | 44 // compiled. |
| 39 static constexpr size_t REGS_SIZE = 32; | 45 static constexpr size_t REGS_SIZE = 32; |
| 40 | 46 |
| 41 private: | 47 private: |
| 42 using OrderedRanges = CfgVector<Variable *>; | 48 using OrderedRanges = CfgVector<Variable *>; |
| 43 using UnorderedRanges = CfgVector<Variable *>; | 49 using UnorderedRanges = CfgVector<Variable *>; |
| 44 using DefUseErrorList = llvm::SmallVector<SizeT, 10>; | 50 using DefUseErrorList = llvm::SmallVector<SizeT, 10>; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 58 llvm::SmallBitVector PrecoloredUnhandledMask; // Note: only used for dumping | 64 llvm::SmallBitVector PrecoloredUnhandledMask; // Note: only used for dumping |
| 59 llvm::SmallVector<RegWeight, REGS_SIZE> Weights; | 65 llvm::SmallVector<RegWeight, REGS_SIZE> Weights; |
| 60 }; | 66 }; |
| 61 | 67 |
| 62 bool livenessValidateIntervals(const DefUseErrorList &DefsWithoutUses, | 68 bool livenessValidateIntervals(const DefUseErrorList &DefsWithoutUses, |
| 63 const DefUseErrorList &UsesBeforeDefs, | 69 const DefUseErrorList &UsesBeforeDefs, |
| 64 const CfgVector<InstNumberT> &LRBegin, | 70 const CfgVector<InstNumberT> &LRBegin, |
| 65 const CfgVector<InstNumberT> &LREnd) const; | 71 const CfgVector<InstNumberT> &LREnd) const; |
| 66 void initForGlobal(); | 72 void initForGlobal(); |
| 67 void initForInfOnly(); | 73 void initForInfOnly(); |
| 74 void initForSecondChance(); |
| 68 /// Move an item from the From set to the To set. From[Index] is pushed onto | 75 /// Move an item from the From set to the To set. From[Index] is pushed onto |
| 69 /// the end of To[], then the item is efficiently removed from From[] by | 76 /// the end of To[], then the item is efficiently removed from From[] by |
| 70 /// effectively swapping it with the last item in From[] and then popping it | 77 /// effectively swapping it with the last item in From[] and then popping it |
| 71 /// from the back. As such, the caller is best off iterating over From[] in | 78 /// from the back. As such, the caller is best off iterating over From[] in |
| 72 /// reverse order to avoid the need for special handling of the iterator. | 79 /// reverse order to avoid the need for special handling of the iterator. |
| 73 void moveItem(UnorderedRanges &From, SizeT Index, UnorderedRanges &To) { | 80 void moveItem(UnorderedRanges &From, SizeT Index, UnorderedRanges &To) { |
| 74 To.push_back(From[Index]); | 81 To.push_back(From[Index]); |
| 75 From[Index] = From.back(); | 82 From[Index] = From.back(); |
| 76 From.pop_back(); | 83 From.pop_back(); |
| 77 } | 84 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 101 | 108 |
| 102 Cfg *const Func; | 109 Cfg *const Func; |
| 103 GlobalContext *const Ctx; | 110 GlobalContext *const Ctx; |
| 104 TargetLowering *const Target; | 111 TargetLowering *const Target; |
| 105 | 112 |
| 106 OrderedRanges Unhandled; | 113 OrderedRanges Unhandled; |
| 107 /// UnhandledPrecolored is a subset of Unhandled, specially collected for | 114 /// UnhandledPrecolored is a subset of Unhandled, specially collected for |
| 108 /// faster processing. | 115 /// faster processing. |
| 109 OrderedRanges UnhandledPrecolored; | 116 OrderedRanges UnhandledPrecolored; |
| 110 UnorderedRanges Active, Inactive, Handled; | 117 UnorderedRanges Active, Inactive, Handled; |
| 118 UnorderedRanges Evicted; |
| 111 CfgVector<InstNumberT> Kills; | 119 CfgVector<InstNumberT> Kills; |
| 112 RegAllocKind Kind = RAK_Unknown; | 120 RegAllocKind Kind = RAK_Unknown; |
| 113 /// RegUses[I] is the number of live ranges (variables) that register I is | 121 /// RegUses[I] is the number of live ranges (variables) that register I is |
| 114 /// currently assigned to. It can be greater than 1 as a result of | 122 /// currently assigned to. It can be greater than 1 as a result of |
| 115 /// AllowOverlap inference. | 123 /// AllowOverlap inference. |
| 116 llvm::SmallVector<int32_t, REGS_SIZE> RegUses; | 124 llvm::SmallVector<int32_t, REGS_SIZE> RegUses; |
| 117 // TODO(jpp): for some architectures a SmallBitVector might not be big | 125 // TODO(jpp): for some architectures a SmallBitVector might not be big |
| 118 // enough. Evaluate what the performance impact on those architectures is. | 126 // enough. Evaluate what the performance impact on those architectures is. |
| 119 llvm::SmallVector<const llvm::SmallBitVector *, REGS_SIZE> RegAliases; | 127 llvm::SmallVector<const llvm::SmallBitVector *, REGS_SIZE> RegAliases; |
| 120 bool FindPreference = false; | 128 bool FindPreference = false; |
| 121 bool FindOverlap = false; | 129 bool FindOverlap = false; |
| 122 | 130 |
| 123 const bool Verbose; | 131 const bool Verbose; |
| 124 }; | 132 }; |
| 125 | 133 |
| 126 } // end of namespace Ice | 134 } // end of namespace Ice |
| 127 | 135 |
| 128 #endif // SUBZERO_SRC_ICEREGALLOC_H | 136 #endif // SUBZERO_SRC_ICEREGALLOC_H |
| OLD | NEW |