60feeddf7ca6c1f55e929b0539b6a7adf471e43d
[oota-llvm.git] / lib / Target / SparcV9 / RegAlloc / LiveRangeInfo.h
1 //===-- LiveRangeInfo.h - Track all LiveRanges for a Function ----*- C++ -*-==//
2 //
3 // This file contains the class LiveRangeInfo which constructs and keeps 
4 // the LiveRangeMap 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 LIVERANGEINFO_H
20 #define LIVERANGEINFO_H
21
22 #include "llvm/CodeGen/ValueSet.h"
23 #include "Support/hash_map"
24
25 class LiveRange;
26 class MachineInstr;
27 class RegClass;
28 class TargetRegInfo;
29 class TargetMachine;
30 class Value;
31 class Function;
32 class Instruction;
33
34 typedef hash_map<const Value*, LiveRange*> LiveRangeMapType;
35
36 //----------------------------------------------------------------------------
37 // Class LiveRangeInfo
38 //
39 // Constructs and keeps the LiveRangeMap which contains all the live 
40 // ranges used in a method. Also contain methods to coalesce live ranges.
41 //----------------------------------------------------------------------------
42
43 class LiveRangeInfo {
44   const Function *const Meth;       // Func for which live range info is held
45   LiveRangeMapType  LiveRangeMap;   // A map from Value * to LiveRange * to 
46                                     // record all live ranges in a method
47                                     // created by constructLiveRanges
48   
49   const TargetMachine& TM;          // target machine description
50
51   std::vector<RegClass *> & RegClassList;// vector containing register classess
52
53   const TargetRegInfo& MRI;        // machine reg info
54
55   std::vector<MachineInstr*> CallRetInstrList;  // a list of all call/ret instrs
56
57
58   //------------ Private methods (see LiveRangeInfo.cpp for description)-------
59
60   LiveRange* createNewLiveRange         (const Value* Def,
61                                          bool isCC = false);
62
63   LiveRange* createOrAddToLiveRange     (const Value* Def,
64                                          bool isCC = false);
65
66   void unionAndUpdateLRs                (LiveRange *L1,
67                                          LiveRange *L2);
68
69   void addInterference                  (const Instruction *Inst,
70                                          const ValueSet *LVSet);
71   
72   void suggestRegs4CallRets             ();
73
74   const Function *getMethod             () const { return Meth; }
75
76 public:
77   
78   LiveRangeInfo(const Function *F, 
79                 const TargetMachine& tm,
80                 std::vector<RegClass *> & RCList);
81
82
83   // Destructor to destroy all LiveRanges in the LiveRange Map
84   ~LiveRangeInfo();
85
86   // Main entry point for live range construction
87   //
88   void constructLiveRanges();
89   
90   // return the common live range map for this method
91   //
92   inline const LiveRangeMapType *getLiveRangeMap() const 
93     { return &LiveRangeMap; }
94
95   // Method used to get the live range containing a Value.
96   // This may return NULL if no live range exists for a Value (eg, some consts)
97   inline LiveRange *getLiveRangeForValue(const Value *Val) {
98     return LiveRangeMap[Val];
99   }
100   inline const LiveRange *getLiveRangeForValue(const Value *Val) const {
101     LiveRangeMapType::const_iterator I = LiveRangeMap.find(Val);
102     return I->second;
103   }
104
105   // Method for coalescing live ranges. Called only after interference info
106   // is calculated.
107   //
108   void coalesceLRs();  
109
110   // debugging method to print the live ranges
111   //
112   void printLiveRanges();
113 };
114
115 #endif