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 // This file declares the LinearScan data structure used during | 10 // This file declares the LinearScan data structure used during |
11 // linear-scan register allocation, which holds the various work | 11 // linear-scan register allocation, which holds the various work |
12 // queues for the linear-scan algorithm. | 12 // queues for the linear-scan algorithm. |
13 // | 13 // |
14 //===----------------------------------------------------------------------===// | 14 //===----------------------------------------------------------------------===// |
15 | 15 |
16 #ifndef SUBZERO_SRC_ICEREGALLOC_H | 16 #ifndef SUBZERO_SRC_ICEREGALLOC_H |
17 #define SUBZERO_SRC_ICEREGALLOC_H | 17 #define SUBZERO_SRC_ICEREGALLOC_H |
18 | 18 |
19 #include "IceDefs.h" | 19 #include "IceDefs.h" |
20 #include "IceTypes.h" | 20 #include "IceTypes.h" |
21 | 21 |
22 namespace Ice { | 22 namespace Ice { |
23 | 23 |
24 class LinearScan { | 24 class LinearScan { |
25 LinearScan() = delete; | 25 LinearScan() = delete; |
26 LinearScan(const LinearScan &) = delete; | 26 LinearScan(const LinearScan &) = delete; |
27 LinearScan &operator=(const LinearScan &) = delete; | 27 LinearScan &operator=(const LinearScan &) = delete; |
28 | 28 |
29 public: | 29 public: |
30 explicit LinearScan(Cfg *Func) | 30 explicit LinearScan(Cfg *Func) : Func(Func) {} |
31 : Func(Func), FindPreference(false), FindOverlap(false) {} | |
32 void init(RegAllocKind Kind); | 31 void init(RegAllocKind Kind); |
33 void scan(const llvm::SmallBitVector &RegMask, bool Randomized); | 32 void scan(const llvm::SmallBitVector &RegMask, bool Randomized); |
34 void dump(Cfg *Func) const; | 33 void dump(Cfg *Func) const; |
35 | 34 |
36 private: | 35 private: |
37 typedef std::vector<Variable *> OrderedRanges; | 36 typedef std::vector<Variable *> OrderedRanges; |
38 typedef std::vector<Variable *> UnorderedRanges; | 37 typedef std::vector<Variable *> UnorderedRanges; |
39 | 38 |
40 void initForGlobal(); | 39 void initForGlobal(); |
41 void initForInfOnly(); | 40 void initForInfOnly(); |
42 // Move an item from the From set to the To set. From[Index] is | 41 // Move an item from the From set to the To set. From[Index] is |
43 // pushed onto the end of To[], then the item is efficiently removed | 42 // pushed onto the end of To[], then the item is efficiently removed |
44 // from From[] by effectively swapping it with the last item in | 43 // from From[] by effectively swapping it with the last item in |
45 // From[] and then popping it from the back. As such, the caller is | 44 // From[] and then popping it from the back. As such, the caller is |
46 // best off iterating over From[] in reverse order to avoid the need | 45 // best off iterating over From[] in reverse order to avoid the need |
47 // for special handling of the iterator. | 46 // for special handling of the iterator. |
48 void moveItem(UnorderedRanges &From, SizeT Index, UnorderedRanges &To) { | 47 void moveItem(UnorderedRanges &From, SizeT Index, UnorderedRanges &To) { |
49 To.push_back(From[Index]); | 48 To.push_back(From[Index]); |
50 From[Index] = From.back(); | 49 From[Index] = From.back(); |
51 From.pop_back(); | 50 From.pop_back(); |
52 } | 51 } |
53 | 52 |
54 Cfg *const Func; | 53 Cfg *const Func; |
55 OrderedRanges Unhandled; | 54 OrderedRanges Unhandled; |
56 // UnhandledPrecolored is a subset of Unhandled, specially collected | 55 // UnhandledPrecolored is a subset of Unhandled, specially collected |
57 // for faster processing. | 56 // for faster processing. |
58 OrderedRanges UnhandledPrecolored; | 57 OrderedRanges UnhandledPrecolored; |
59 UnorderedRanges Active, Inactive, Handled; | 58 UnorderedRanges Active, Inactive, Handled; |
60 std::vector<InstNumberT> Kills; | 59 std::vector<InstNumberT> Kills; |
61 bool FindPreference; | 60 bool FindPreference = false; |
62 bool FindOverlap; | 61 bool FindOverlap = false; |
63 // TODO(stichnot): We're not really using FindOverlap yet, but we | 62 // TODO(stichnot): We're not really using FindOverlap yet, but we |
64 // may want a flavor of register allocation where FindPreference is | 63 // may want a flavor of register allocation where FindPreference is |
65 // useful but we didn't want to initialize VMetadata with VMK_All | 64 // useful but we didn't want to initialize VMetadata with VMK_All |
66 // and therefore we can't safely allow overlap. | 65 // and therefore we can't safely allow overlap. |
67 }; | 66 }; |
68 | 67 |
69 } // end of namespace Ice | 68 } // end of namespace Ice |
70 | 69 |
71 #endif // SUBZERO_SRC_ICEREGALLOC_H | 70 #endif // SUBZERO_SRC_ICEREGALLOC_H |
OLD | NEW |