SHUFP* are two address code.
[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 "llvm/ADT/hash_map"
31
32 namespace llvm {
33
34 class V9LiveRange;
35 class MachineInstr;
36 class RegClass;
37 class SparcV9RegInfo;
38 class TargetMachine;
39 class Value;
40 class Function;
41 class Instruction;
42
43 typedef hash_map<const Value*, V9LiveRange*> 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 V9LiveRange * 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 SparcV9RegInfo& MRI;        // machine reg info
63
64   std::vector<MachineInstr*> CallRetInstrList;  // a list of all call/ret instrs
65
66   //------------ Private methods (see LiveRangeInfo.cpp for description)-------
67
68   V9LiveRange* createNewLiveRange         (const Value* Def,
69                                          bool isCC = false);
70
71   V9LiveRange* createOrAddToLiveRange     (const Value* Def,
72                                          bool isCC = false);
73
74   void unionAndUpdateLRs                (V9LiveRange *L1,
75                                          V9LiveRange *L2);
76
77   void suggestRegs4CallRets             ();
78 public:
79
80   LiveRangeInfo(const Function *F,
81                 const TargetMachine& tm,
82                 std::vector<RegClass *> & RCList);
83
84
85   /// Destructor to destroy all LiveRanges in the V9LiveRange Map
86   ///
87   ~LiveRangeInfo();
88
89   // Main entry point for live range construction
90   //
91   void constructLiveRanges();
92
93   /// return the common live range map for this method
94   ///
95   inline const LiveRangeMapType *getLiveRangeMap() const
96     { return &LiveRangeMap; }
97
98   /// Method used to get the live range containing a Value.
99   /// This may return NULL if no live range exists for a Value (eg, some consts)
100   ///
101   inline V9LiveRange *getLiveRangeForValue(const Value *Val) {
102     return LiveRangeMap[Val];
103   }
104   inline const V9LiveRange *getLiveRangeForValue(const Value *Val) const {
105     LiveRangeMapType::const_iterator I = LiveRangeMap.find(Val);
106     return I->second;
107   }
108
109   /// Method for coalescing live ranges. Called only after interference info
110   /// is calculated.
111   ///
112   void coalesceLRs();
113
114   /// debugging method to print the live ranges
115   ///
116   void printLiveRanges();
117 };
118
119 } // End llvm namespace
120
121 #endif