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