Chromium Code Reviews| 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 |
| 11 /// This file declares the LinearScan data structure used during | 11 /// This file declares the LinearScan data structure used during linear-scan |
| 12 /// linear-scan register allocation, which holds the various work | 12 /// register allocation, which holds the various work queues for the linear-scan |
| 13 /// queues for the linear-scan algorithm. | 13 /// algorithm. |
| 14 /// | 14 /// |
| 15 //===----------------------------------------------------------------------===// | 15 //===----------------------------------------------------------------------===// |
| 16 | 16 |
| 17 #ifndef SUBZERO_SRC_ICEREGALLOC_H | 17 #ifndef SUBZERO_SRC_ICEREGALLOC_H |
| 18 #define SUBZERO_SRC_ICEREGALLOC_H | 18 #define SUBZERO_SRC_ICEREGALLOC_H |
| 19 | 19 |
| 20 #include "IceDefs.h" | 20 #include "IceDefs.h" |
| 21 #include "IceOperand.h" | |
| 21 #include "IceTypes.h" | 22 #include "IceTypes.h" |
| 22 | 23 |
| 23 namespace Ice { | 24 namespace Ice { |
| 24 | 25 |
| 25 class LinearScan { | 26 class LinearScan { |
| 26 LinearScan() = delete; | 27 LinearScan() = delete; |
| 27 LinearScan(const LinearScan &) = delete; | 28 LinearScan(const LinearScan &) = delete; |
| 28 LinearScan &operator=(const LinearScan &) = delete; | 29 LinearScan &operator=(const LinearScan &) = delete; |
| 29 | 30 |
| 30 public: | 31 public: |
| 31 explicit LinearScan(Cfg *Func) : Func(Func) {} | 32 explicit LinearScan(Cfg *Func); |
| 32 void init(RegAllocKind Kind); | 33 void init(RegAllocKind Kind); |
| 33 void scan(const llvm::SmallBitVector &RegMask, bool Randomized); | 34 void scan(const llvm::SmallBitVector &RegMask, bool Randomized); |
| 34 void dump(Cfg *Func) const; | 35 void dump(Cfg *Func) const; |
| 35 | 36 |
| 37 // TODO(stichnot): Statically choose the size based on the target being | |
| 38 // compiled. | |
| 39 static constexpr size_t REGS_SIZE = 32; | |
| 40 | |
| 36 private: | 41 private: |
| 37 typedef std::vector<Variable *> OrderedRanges; | 42 typedef std::vector<Variable *> OrderedRanges; |
| 38 typedef std::vector<Variable *> UnorderedRanges; | 43 typedef std::vector<Variable *> UnorderedRanges; |
| 39 | 44 |
| 45 struct IterationState { | |
|
Jim Stichnoth
2015/08/25 05:36:08
I think it would be safer to call this a class ins
| |
| 46 Variable *Cur; | |
| 47 llvm::SmallBitVector RegMask; | |
|
Jim Stichnoth
2015/08/25 05:36:08
Maybe move the llvm:: fields to the end.
| |
| 48 llvm::SmallBitVector Free; | |
| 49 llvm::SmallVector<RegWeight, REGS_SIZE> Weights; | |
| 50 llvm::SmallBitVector PrecoloredUnhandledMask; // Note: only used for dumping | |
| 51 Variable *Prefer; | |
| 52 int32_t PreferReg; | |
| 53 bool AllowOverlap; | |
| 54 }; | |
| 55 | |
| 40 void initForGlobal(); | 56 void initForGlobal(); |
| 41 void initForInfOnly(); | 57 void initForInfOnly(); |
| 42 /// Free up a register for infinite-weight Cur by spilling and reloading some | 58 /// Move an item from the From set to the To set. From[Index] is pushed onto |
| 43 /// register that isn't used during Cur's live range. | 59 /// the end of To[], then the item is efficiently removed from From[] by |
| 44 void addSpillFill(Variable *Cur, llvm::SmallBitVector RegMask); | 60 /// effectively swapping it with the last item in From[] and then popping it |
| 45 /// Move an item from the From set to the To set. From[Index] is | 61 /// from the back. As such, the caller is best off iterating over From[] in |
| 46 /// pushed onto the end of To[], then the item is efficiently removed | 62 /// reverse order to avoid the need for special handling of the iterator. |
| 47 /// from From[] by effectively swapping it with the last item in | |
| 48 /// From[] and then popping it from the back. As such, the caller is | |
| 49 /// best off iterating over From[] in reverse order to avoid the need | |
| 50 /// for special handling of the iterator. | |
| 51 void moveItem(UnorderedRanges &From, SizeT Index, UnorderedRanges &To) { | 63 void moveItem(UnorderedRanges &From, SizeT Index, UnorderedRanges &To) { |
| 52 To.push_back(From[Index]); | 64 To.push_back(From[Index]); |
| 53 From[Index] = From.back(); | 65 From[Index] = From.back(); |
| 54 From.pop_back(); | 66 From.pop_back(); |
| 55 } | 67 } |
| 56 | 68 |
| 69 /// \name scan helper functions. | |
| 70 /// @{ | |
| 71 /// Free up a register for infinite-weight Cur by spilling and reloading some | |
| 72 /// register that isn't used during Cur's live range. | |
| 73 void addSpillFill(IterationState &Iter); | |
| 74 /// Check for active ranges that have expired or become inactive. | |
| 75 void handleActiveRangeExpiredOrInactive(const Variable *Cur); | |
| 76 /// Check for inactive ranges that have expired or reactivated. | |
| 77 void handleInactiveRangeExpiredOrReactivated(const Variable *Cur); | |
| 78 void findRegisterPreference(IterationState &Iter); | |
| 79 void filterFreeWithInactiveRanges(IterationState &Iter); | |
| 80 void filterFreeWithPrecoloredRanges(IterationState &Iter); | |
| 81 void allocatePrecoloredRegister(Variable *Cur); | |
| 82 void allocatePreferredRegister(IterationState &Iter); | |
| 83 void allocateFreeRegister(IterationState &Iter); | |
| 84 void handleNoFreeRegisters(IterationState &Iter); | |
| 85 void assignFinalRegisters(llvm::SmallBitVector RegMaskFull, | |
|
jvoung (off chromium)
2015/08/25 12:50:48
re: passing llvm::SmallBitVector arguments which J
Jim Stichnoth
2015/08/25 15:19:03
Oh yeah, I missed this. Please pass these by ref,
| |
| 86 llvm::SmallBitVector PreDefinedRegisters, | |
| 87 bool Randomized); | |
| 88 /// @} | |
| 89 | |
| 90 void dumpLiveRangeTrace(const char *Label, const Variable *Item); | |
| 91 | |
| 57 Cfg *const Func; | 92 Cfg *const Func; |
| 93 GlobalContext *const Ctx; | |
| 94 | |
| 58 OrderedRanges Unhandled; | 95 OrderedRanges Unhandled; |
| 59 /// UnhandledPrecolored is a subset of Unhandled, specially collected | 96 /// UnhandledPrecolored is a subset of Unhandled, specially collected for |
| 60 /// for faster processing. | 97 /// faster processing. |
| 61 OrderedRanges UnhandledPrecolored; | 98 OrderedRanges UnhandledPrecolored; |
| 62 UnorderedRanges Active, Inactive, Handled; | 99 UnorderedRanges Active, Inactive, Handled; |
| 63 std::vector<InstNumberT> Kills; | 100 std::vector<InstNumberT> Kills; |
| 64 RegAllocKind Kind = RAK_Unknown; | 101 RegAllocKind Kind = RAK_Unknown; |
| 102 /// RegUses[I] is the number of live ranges (variables) that register I is | |
| 103 /// currently assigned to. It can be greater than 1 as a result of | |
| 104 /// AllowOverlap inference. | |
| 105 llvm::SmallVector<int32_t, REGS_SIZE> RegUses; | |
| 65 bool FindPreference = false; | 106 bool FindPreference = false; |
| 66 bool FindOverlap = false; | 107 bool FindOverlap = false; |
| 108 | |
| 109 const bool Verbose; | |
| 67 }; | 110 }; |
| 68 | 111 |
| 69 } // end of namespace Ice | 112 } // end of namespace Ice |
| 70 | 113 |
| 71 #endif // SUBZERO_SRC_ICEREGALLOC_H | 114 #endif // SUBZERO_SRC_ICEREGALLOC_H |
| OLD | NEW |