blob: 0ce7e0c3b5f687da732c5230f484f2b0c2e816ac [file] [log] [blame]
Jakob Stoklund Olesenc9672cb2010-12-10 18:36:02 +00001//===-- llvm/CodeGen/AllocationOrder.h - Allocation Order -*- C++ -*-------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements an allocation order for virtual registers.
11//
12// The preferred allocation order for a virtual register depends on allocation
13// hints and target hooks. The AllocationOrder class encapsulates all of that.
14//
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_CODEGEN_ALLOCATIONORDER_H
18#define LLVM_CODEGEN_ALLOCATIONORDER_H
19
20namespace llvm {
21
Jakob Stoklund Olesen5f2316a2011-06-03 20:34:53 +000022class RegisterClassInfo;
Jakob Stoklund Olesenc9672cb2010-12-10 18:36:02 +000023class VirtRegMap;
24
25class AllocationOrder {
26 const unsigned *Begin;
27 const unsigned *End;
28 const unsigned *Pos;
Jakob Stoklund Olesen5f2316a2011-06-03 20:34:53 +000029 const RegisterClassInfo &RCI;
Jakob Stoklund Olesenc9672cb2010-12-10 18:36:02 +000030 unsigned Hint;
Jakob Stoklund Olesena46a1002011-06-06 21:02:04 +000031 bool OwnedBegin;
Jakob Stoklund Olesenc9672cb2010-12-10 18:36:02 +000032public:
33
34 /// AllocationOrder - Create a new AllocationOrder for VirtReg.
35 /// @param VirtReg Virtual register to allocate for.
36 /// @param VRM Virtual register map for function.
Jakob Stoklund Olesen10c6fdc2012-01-24 18:09:18 +000037 /// @param RegClassInfo Information about reserved and allocatable registers.
Jakob Stoklund Olesenc9672cb2010-12-10 18:36:02 +000038 AllocationOrder(unsigned VirtReg,
39 const VirtRegMap &VRM,
Jakob Stoklund Olesen5f2316a2011-06-03 20:34:53 +000040 const RegisterClassInfo &RegClassInfo);
Jakob Stoklund Olesenc9672cb2010-12-10 18:36:02 +000041
Jakob Stoklund Olesena46a1002011-06-06 21:02:04 +000042 ~AllocationOrder();
43
Jakob Stoklund Olesenc9672cb2010-12-10 18:36:02 +000044 /// next - Return the next physical register in the allocation order, or 0.
45 /// It is safe to call next again after it returned 0.
46 /// It will keep returning 0 until rewind() is called.
Jakob Stoklund Olesena46a1002011-06-06 21:02:04 +000047 unsigned next() {
48 // First take the hint.
49 if (!Pos) {
50 Pos = Begin;
51 if (Hint)
52 return Hint;
53 }
54 // Then look at the order from TRI.
55 while (Pos != End) {
56 unsigned Reg = *Pos++;
57 if (Reg != Hint)
58 return Reg;
59 }
60 return 0;
61 }
Jakob Stoklund Olesenc9672cb2010-12-10 18:36:02 +000062
63 /// rewind - Start over from the beginning.
64 void rewind() { Pos = 0; }
65
Jakob Stoklund Olesen57f1e2c2011-02-25 01:04:22 +000066 /// isHint - Return true if PhysReg is a preferred register.
67 bool isHint(unsigned PhysReg) const { return PhysReg == Hint; }
Jakob Stoklund Olesenc9672cb2010-12-10 18:36:02 +000068};
69
70} // end namespace llvm
71
72#endif