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