Clean up interface.
[oota-llvm.git] / include / llvm / CodeGen / RegisterScavenging.h
1 //===-- RegisterScavenging.h - Machine register scavenging ------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the Evan Cheng and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the machine register scavenger class. It can provide
11 // information such as unused register at any point in a machine basic block.
12 // It also provides a mechanism to make registers availbale by evicting them
13 // to spill slots.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #ifndef LLVM_CODEGEN_REGISTER_SCAVENGING_H
18 #define LLVM_CODEGEN_REGISTER_SCAVENGING_H
19
20 #include "llvm/CodeGen/MachineBasicBlock.h"
21 #include "llvm/ADT/BitVector.h"
22
23 namespace llvm {
24
25 class TargetRegisterClass;
26
27 class RegScavenger {
28   MachineBasicBlock *MBB;
29   MachineBasicBlock::iterator MBBI;
30   unsigned NumPhysRegs;
31
32   /// Tracking - True if RegScavenger is currently tracking the liveness of 
33   /// registers.
34   bool Tracking;
35
36   /// RegStates - The current state of all the physical registers immediately
37   /// before MBBI. One bit per physical register. If bit is set that means it's
38   /// available, unset means the register is currently being used.
39   BitVector RegStates;
40
41 public:
42   RegScavenger()
43     : MBB(NULL), NumPhysRegs(0), Tracking(false) {};
44
45   RegScavenger(MachineBasicBlock *mbb)
46     : MBB(mbb), NumPhysRegs(0), Tracking(false) {};
47
48   /// enterBasicBlock - Start tracking liveness from the begin of the specific
49   /// basic block.
50   void enterBasicBlock(MachineBasicBlock *mbb);
51
52   /// forward / backward - Move the internal MBB iterator and update register
53   /// states.
54   void forward();
55   void backward();
56
57   /// forward / backward - Move the internal MBB iterator and update register
58   /// states until it has reached but not processed the specific iterator.
59   void forward(MachineBasicBlock::iterator I) {
60     while (MBBI != I) forward();
61   }
62   void backward(MachineBasicBlock::iterator I) {
63     while (MBBI != I) backward();
64   }
65
66   /// isReserved - Returns true if a register is reserved. It is never "unused".
67   bool isReserved(unsigned Reg) const { return ReservedRegs[Reg]; }
68
69   /// isUsed / isUsed - Test if a register is currently being used.
70   ///
71   bool isUsed(unsigned Reg) const   { return !RegStates[Reg]; }
72   bool isUnused(unsigned Reg) const { return RegStates[Reg]; }
73
74   /// setUsed / setUnused - Mark the state of one or a number of registers.
75   ///
76   void setUsed(unsigned Reg)     { RegStates.reset(Reg); }
77   void setUsed(BitVector Regs)   { RegStates &= ~Regs; }
78   void setUnused(unsigned Reg)   { RegStates.set(Reg); }
79   void setUnused(BitVector Regs) { RegStates |= Regs; }
80
81   /// FindUnusedReg - Find a unused register of the specified register class.
82   /// Exclude callee saved registers if directed. It return 0 is none is found.
83   unsigned FindUnusedReg(const TargetRegisterClass *RegClass,
84                          bool ExCalleeSaved = false) const;
85
86 private:
87   /// CalleeSavedrRegs - A bitvector of callee saved registers for the target.
88   ///
89   BitVector CalleeSavedRegs;
90
91   /// ReservedRegs - A bitvector of reserved registers.
92   ///
93   BitVector ReservedRegs;
94 };
95  
96 } // End llvm namespace
97
98 #endif