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