1 //===-- LiveRangeInfo.h - Track all LiveRanges for a Function ----*- C++ -*-==//
3 // This file contains the class LiveRangeInfo which constructs and keeps
4 // the LiveRangMap which contains all the live ranges used in a method.
8 // All variables (llvm Values) are defined before they are used. However, a
9 // constant may not be defined in the machine instruction stream if it can be
10 // used as an immediate value within a machine instruction. However, register
11 // allocation does not have to worry about immediate constants since they
12 // do not require registers.
14 // Since an llvm Value has a list of uses associated, it is sufficient to
15 // record only the defs in a Live Range.
17 //===----------------------------------------------------------------------===//
19 #ifndef LIVE_RANGE_INFO_H
20 #define LIVE_RANGE_INFO_H
22 #include "Support/HashExtras.h"
23 #include "llvm/Analysis/LiveVar/ValueSet.h"
34 typedef hash_map<const Value*, LiveRange*> LiveRangeMapType;
36 //----------------------------------------------------------------------------
37 // Class LiveRangeInfo
39 // Constructs and keeps the LiveRangMap which contains all the live
40 // ranges used in a method. Also contain methods to coalesce live ranges.
41 //----------------------------------------------------------------------------
44 const Function *const Meth; // Func for which live range info is held
45 LiveRangeMapType LiveRangeMap; // A map from Value * to LiveRange * to
46 // record all live ranges in a method
47 // created by constructLiveRanges
49 const TargetMachine& TM; // target machine description
51 std::vector<RegClass *> & RegClassList;// vector containing register classess
53 const MachineRegInfo& MRI; // machine reg info
55 std::vector<MachineInstr*> CallRetInstrList; // a list of all call/ret instrs
58 //------------ Private methods (see LiveRangeInfo.cpp for description)-------
60 LiveRange* createNewLiveRange (const Value* Def,
63 LiveRange* createOrAddToLiveRange (const Value* Def,
66 void unionAndUpdateLRs (LiveRange *L1,
69 void addInterference (const Instruction *Inst,
70 const ValueSet *LVSet);
72 void suggestRegs4CallRets ();
74 const Function *getMethod () const { return Meth; }
78 LiveRangeInfo(const Function *F,
79 const TargetMachine& tm,
80 std::vector<RegClass *> & RCList);
83 // Destructor to destroy all LiveRanges in the LiveRange Map
86 // Main entry point for live range construction
88 void constructLiveRanges();
90 // return the common live range map for this method
92 inline const LiveRangeMapType *getLiveRangeMap() const
93 { return &LiveRangeMap; }
95 // Method sed to get the corresponding live range of a Value
97 inline LiveRange *getLiveRangeForValue( const Value *Val)
98 { return LiveRangeMap[Val]; }
100 // Method for coalescing live ranges. Called only after interference info
105 // debugging method to print the live ranges
107 void printLiveRanges();