Make LoopDeptCalculator be an internal artifact of how RegAlloc is implemented,
[oota-llvm.git] / lib / Target / SparcV9 / RegAlloc / LiveRangeInfo.h
1 //===-- LiveRangeInfo.h - Track all LiveRanges for a Method ------*- C++ -*-==//
2 //
3 // This file contains the class LiveRangeInfo which constructs and keeps 
4 // the LiveRangMap which contains all the live ranges used in a method.
5 //
6 // Assumptions: 
7 //
8 // All variables (llvm Values) are defined before they are used. However, a 
9 // constant may not be defined in the machine instruction stream if it can be
10 // used as an immediate value within a machine instruction. However, register
11 // allocation does not have to worry about immediate constants since they
12 // do not require registers.
13 //
14 // Since an llvm Value has a list of uses associated, it is sufficient to
15 // record only the defs in a Live Range.
16 //
17 //===----------------------------------------------------------------------===//
18
19 #ifndef LIVE_RANGE_INFO_H
20 #define LIVE_RANGE_INFO_H
21
22 #include "Support/HashExtras.h"
23
24 class LiveRange;
25 class MachineInstr;
26 class LiveVarSet;
27 class RegClass;
28 class MachineRegInfo;
29 class TargetMachine;
30 class Value;
31 class Method;
32 class Instruction;
33
34 typedef std::hash_map<const Value*, LiveRange*> LiveRangeMapType;
35 typedef std::vector<const MachineInstr*> CallRetInstrListType;
36
37 //----------------------------------------------------------------------------
38 // Class LiveRangeInfo
39 //
40 // Constructs and keeps the LiveRangMap which contains all the live 
41 // ranges used in a method. Also contain methods to coalesce live ranges.
42 //----------------------------------------------------------------------------
43
44 class LiveRangeInfo {
45   const Method *const Meth;         // Method for which live range info is held
46   LiveRangeMapType  LiveRangeMap;   // A map from Value * to LiveRange * to 
47                                     // record all live ranges in a method
48                                     // created by constructLiveRanges
49   
50   const TargetMachine& TM;          // target machine description
51
52   std::vector<RegClass *> & RegClassList;// vector containing register classess
53
54   const MachineRegInfo& MRI;        // machine reg info
55
56   CallRetInstrListType  CallRetInstrList;  // a list of all call/ret instrs
57
58
59   //------------ Private methods (see LiveRangeInfo.cpp for description)-------
60
61   void unionAndUpdateLRs(LiveRange *L1, LiveRange *L2);
62
63   void addInterference(const Instruction *const Inst, 
64                        const LiveVarSet *const LVSet);
65   
66   void suggestRegs4CallRets();
67
68   const Method* getMethod() { return Meth; }
69
70
71 public:
72   
73   LiveRangeInfo(const Method *const M, 
74                 const TargetMachine& tm,
75                 std::vector<RegClass *> & RCList);
76
77
78   // Destructor to destroy all LiveRanges in the LiveRange Map
79   ~LiveRangeInfo();
80
81   // Main entry point for live range construction
82   //
83   void constructLiveRanges();
84
85   // This method is used to add a live range created elsewhere (e.g.,
86   // in machine specific code) to the common live range map
87   //
88   inline void addLRToMap(const Value *Val, LiveRange *LR) {
89     assert(Val && LR && "Val/LR is NULL!\n");
90     assert((!LiveRangeMap[Val]) && "LR already set in map");
91     LiveRangeMap[Val] = LR;
92   }
93   
94   // return the common live range map for this method
95   //
96   inline const LiveRangeMapType *const getLiveRangeMap() const 
97     { return &LiveRangeMap; }
98
99   // Method sed to get the corresponding live range of a Value
100   //
101   inline LiveRange *getLiveRangeForValue( const Value *const Val) 
102     { return LiveRangeMap[Val]; }
103
104   // Method used to get the Call and Return instruction list
105   //
106   inline  CallRetInstrListType &getCallRetInstrList() {
107     return CallRetInstrList;
108   }
109
110   // Method for coalescing live ranges. Called only after interference info
111   // is calculated.
112   //
113   void coalesceLRs();  
114
115   // debugging method to print the live ranges
116   //
117   void printLiveRanges();
118 };
119
120 #endif