Include SparcV9RegInfo.h instead of TargetRegInfo.h.
[oota-llvm.git] / lib / Target / SparcV9 / RegAlloc / LiveRangeInfo.h
1 //===-- LiveRangeInfo.h - Track all LiveRanges for a Function ----*- C++ -*-==//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the class LiveRangeInfo which constructs and keeps 
11 // the LiveRangeMap which contains all the live ranges used in a method.
12 //
13 // Assumptions: 
14 //
15 // All variables (llvm Values) are defined before they are used. However, a 
16 // constant may not be defined in the machine instruction stream if it can be
17 // used as an immediate value within a machine instruction. However, register
18 // allocation does not have to worry about immediate constants since they
19 // do not require registers.
20 //
21 // Since an llvm Value has a list of uses associated, it is sufficient to
22 // record only the defs in a Live Range.
23 //
24 //===----------------------------------------------------------------------===//
25
26 #ifndef LIVERANGEINFO_H
27 #define LIVERANGEINFO_H
28
29 #include "llvm/CodeGen/ValueSet.h"
30 #include "Support/hash_map"
31
32 namespace llvm {
33
34 class LiveRange;
35 class MachineInstr;
36 class RegClass;
37 class TargetRegInfo;
38 class TargetMachine;
39 class Value;
40 class Function;
41 class Instruction;
42
43 typedef hash_map<const Value*, LiveRange*> LiveRangeMapType;
44
45 //----------------------------------------------------------------------------
46 // Class LiveRangeInfo
47 //
48 // Constructs and keeps the LiveRangeMap which contains all the live 
49 // ranges used in a method. Also contain methods to coalesce live ranges.
50 //----------------------------------------------------------------------------
51
52 class LiveRangeInfo {
53   const Function *const Meth;       // Func for which live range info is held
54   LiveRangeMapType  LiveRangeMap;   // A map from Value * to LiveRange * to 
55                                     // record all live ranges in a method
56                                     // created by constructLiveRanges
57   
58   const TargetMachine& TM;          // target machine description
59
60   std::vector<RegClass *> & RegClassList;// vector containing register classess
61
62   const TargetRegInfo& MRI;        // machine reg info
63
64   std::vector<MachineInstr*> CallRetInstrList;  // a list of all call/ret instrs
65
66
67   //------------ Private methods (see LiveRangeInfo.cpp for description)-------
68
69   LiveRange* createNewLiveRange         (const Value* Def,
70                                          bool isCC = false);
71
72   LiveRange* createOrAddToLiveRange     (const Value* Def,
73                                          bool isCC = false);
74
75   void unionAndUpdateLRs                (LiveRange *L1,
76                                          LiveRange *L2);
77
78   void addInterference                  (const Instruction *Inst,
79                                          const ValueSet *LVSet);
80   
81   void suggestRegs4CallRets             ();
82
83   const Function *getMethod             () const { return Meth; }
84
85 public:
86   
87   LiveRangeInfo(const Function *F, 
88                 const TargetMachine& tm,
89                 std::vector<RegClass *> & RCList);
90
91
92   /// Destructor to destroy all LiveRanges in the LiveRange Map
93   ///
94   ~LiveRangeInfo();
95
96   // Main entry point for live range construction
97   //
98   void constructLiveRanges();
99   
100   /// return the common live range map for this method
101   ///
102   inline const LiveRangeMapType *getLiveRangeMap() const 
103     { return &LiveRangeMap; }
104
105   /// Method used to get the live range containing a Value.
106   /// This may return NULL if no live range exists for a Value (eg, some consts)
107   ///
108   inline LiveRange *getLiveRangeForValue(const Value *Val) {
109     return LiveRangeMap[Val];
110   }
111   inline const LiveRange *getLiveRangeForValue(const Value *Val) const {
112     LiveRangeMapType::const_iterator I = LiveRangeMap.find(Val);
113     return I->second;
114   }
115
116   /// Method for coalescing live ranges. Called only after interference info
117   /// is calculated.
118   ///
119   void coalesceLRs();  
120
121   /// debugging method to print the live ranges
122   ///
123   void printLiveRanges();
124 };
125
126 } // End llvm namespace
127
128 #endif