blob: 1658a7d4d97e27468ce1e183929e681f00fd5d2f [file] [log] [blame]
Jim Stichnothd97c7df2014-06-04 11:57:08 -07001//===- 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 Stichnoth5ce0abb2014-10-15 10:16:54 -070010// 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 Stichnothd97c7df2014-06-04 11:57:08 -070013//
14//===----------------------------------------------------------------------===//
15
16#ifndef SUBZERO_SRC_ICEREGALLOC_H
17#define SUBZERO_SRC_ICEREGALLOC_H
18
19#include "IceDefs.h"
20#include "IceTypes.h"
21
22namespace Ice {
23
Jim Stichnothd97c7df2014-06-04 11:57:08 -070024class LinearScan {
Jim Stichnothc6ead202015-02-24 09:30:30 -080025 LinearScan() = delete;
Jim Stichnoth5ce0abb2014-10-15 10:16:54 -070026 LinearScan(const LinearScan &) = delete;
27 LinearScan &operator=(const LinearScan &) = delete;
28
Jim Stichnothd97c7df2014-06-04 11:57:08 -070029public:
Jim Stichnotheafb56c2015-06-22 10:35:22 -070030 explicit LinearScan(Cfg *Func) : Func(Func) {}
Jim Stichnoth70d0a052014-11-14 15:53:46 -080031 void init(RegAllocKind Kind);
Jim Stichnothe6d24782014-12-19 05:42:24 -080032 void scan(const llvm::SmallBitVector &RegMask, bool Randomized);
Jim Stichnothd97c7df2014-06-04 11:57:08 -070033 void dump(Cfg *Func) const;
34
35private:
Jim Stichnoth4ead35a2014-12-03 20:30:34 -080036 typedef std::vector<Variable *> OrderedRanges;
37 typedef std::vector<Variable *> UnorderedRanges;
38
Jim Stichnoth70d0a052014-11-14 15:53:46 -080039 void initForGlobal();
40 void initForInfOnly();
Jim Stichnoth4ead35a2014-12-03 20:30:34 -080041 // 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 Stichnoth70d0a052014-11-14 15:53:46 -080052
Jim Stichnothd97c7df2014-06-04 11:57:08 -070053 Cfg *const Func;
Jim Stichnothd97c7df2014-06-04 11:57:08 -070054 OrderedRanges Unhandled;
Jim Stichnoth541ba662014-10-02 12:58:21 -070055 // UnhandledPrecolored is a subset of Unhandled, specially collected
56 // for faster processing.
57 OrderedRanges UnhandledPrecolored;
Jim Stichnothd97c7df2014-06-04 11:57:08 -070058 UnorderedRanges Active, Inactive, Handled;
Jim Stichnoth87ff3a12014-11-14 10:27:29 -080059 std::vector<InstNumberT> Kills;
Jim Stichnotheafb56c2015-06-22 10:35:22 -070060 bool FindPreference = false;
61 bool FindOverlap = false;
Jim Stichnoth70d0a052014-11-14 15:53:46 -080062 // 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 Stichnothd97c7df2014-06-04 11:57:08 -070066};
67
68} // end of namespace Ice
69
70#endif // SUBZERO_SRC_ICEREGALLOC_H