1 /* Title: LiveRangeInfo.h
2 Author: Ruchira Sasanka
6 This file contains the class LiveRangeInfo which constructs and keeps
7 the LiveRangMap which contains all the live ranges used in a method.
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.
17 Since an llvm Value has a list of uses associated, it is sufficient to
18 record only the defs in a Live Range.
23 #ifndef LIVE_RANGE_INFO_H
24 #define LIVE_RANGE_INFO_H
26 #include "llvm/Type.h"
27 #include "llvm/Method.h"
28 #include "llvm/CodeGen/MachineInstr.h"
30 #include "llvm/Analysis/LiveVar/LiveVarSet.h"
32 #include "llvm/CodeGen/IGNode.h"
33 #include "llvm/CodeGen/LiveRange.h"
34 #include "llvm/CodeGen/RegClass.h"
37 typedef hash_map <const Value *, LiveRange *, hashFuncValue> LiveRangeMapType;
38 typedef vector <const MachineInstr *> CallRetInstrListType;
42 //----------------------------------------------------------------------------
43 // Class LiveRangeInfo
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 //----------------------------------------------------------------------------
54 const Method *const Meth; // Method for which live range info is held
56 LiveRangeMapType LiveRangeMap; // A map from Value * to LiveRange * to
57 // record all live ranges in a method
58 // created by constructLiveRanges
60 const TargetMachine& TM; // target machine description
62 vector<RegClass *> & RegClassList;// a vector containing register classess
64 const MachineRegInfo& MRI; // machine reg info
66 CallRetInstrListType CallRetInstrList; // a list of all call/ret instrs
69 //------------ Private methods (see LiveRangeInfo.cpp for description)-------
71 void unionAndUpdateLRs(LiveRange *L1, LiveRange *L2);
73 void addInterference(const Instruction *const Inst,
74 const LiveVarSet *const LVSet);
76 void suggestRegs4CallRets();
78 const Method* getMethod() { return Meth; }
83 LiveRangeInfo(const Method *const M,
84 const TargetMachine& tm,
85 vector<RegClass *> & RCList);
88 // Destructor to destroy all LiveRanges in the LiveRange Map
91 // Main entry point for live range construction
93 void constructLiveRanges();
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
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;
104 // return the common live range map for this method
106 inline const LiveRangeMapType *const getLiveRangeMap() const
107 { return &LiveRangeMap; }
109 // Method sed to get the corresponding live range of a Value
111 inline LiveRange *getLiveRangeForValue( const Value *const Val)
112 { return LiveRangeMap[ Val ]; }
114 // Method used to get the Call and Return instruction list
116 inline CallRetInstrListType &getCallRetInstrList() {
117 return CallRetInstrList;
120 // Method for coalescing live ranges. Called only after interference info
125 // debugging method to print the live ranges
127 void printLiveRanges();