1 //===-- LiveRangeInfo.h - Track all LiveRanges for a Function ----*- C++ -*-==//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file contains the class LiveRangeInfo which constructs and keeps
11 // the LiveRangeMap which contains all the live ranges used in a method.
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.
21 // Since an llvm Value has a list of uses associated, it is sufficient to
22 // record only the defs in a Live Range.
24 //===----------------------------------------------------------------------===//
26 #ifndef LIVERANGEINFO_H
27 #define LIVERANGEINFO_H
29 #include "llvm/CodeGen/ValueSet.h"
30 #include "Support/hash_map"
41 typedef hash_map<const Value*, LiveRange*> LiveRangeMapType;
43 //----------------------------------------------------------------------------
44 // Class LiveRangeInfo
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 //----------------------------------------------------------------------------
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
56 const TargetMachine& TM; // target machine description
58 std::vector<RegClass *> & RegClassList;// vector containing register classess
60 const TargetRegInfo& MRI; // machine reg info
62 std::vector<MachineInstr*> CallRetInstrList; // a list of all call/ret instrs
65 //------------ Private methods (see LiveRangeInfo.cpp for description)-------
67 LiveRange* createNewLiveRange (const Value* Def,
70 LiveRange* createOrAddToLiveRange (const Value* Def,
73 void unionAndUpdateLRs (LiveRange *L1,
76 void addInterference (const Instruction *Inst,
77 const ValueSet *LVSet);
79 void suggestRegs4CallRets ();
81 const Function *getMethod () const { return Meth; }
85 LiveRangeInfo(const Function *F,
86 const TargetMachine& tm,
87 std::vector<RegClass *> & RCList);
90 /// Destructor to destroy all LiveRanges in the LiveRange Map
94 // Main entry point for live range construction
96 void constructLiveRanges();
98 /// return the common live range map for this method
100 inline const LiveRangeMapType *getLiveRangeMap() const
101 { return &LiveRangeMap; }
103 /// Method used to get the live range containing a Value.
104 /// This may return NULL if no live range exists for a Value (eg, some consts)
106 inline LiveRange *getLiveRangeForValue(const Value *Val) {
107 return LiveRangeMap[Val];
109 inline const LiveRange *getLiveRangeForValue(const Value *Val) const {
110 LiveRangeMapType::const_iterator I = LiveRangeMap.find(Val);
114 /// Method for coalescing live ranges. Called only after interference info
119 /// debugging method to print the live ranges
121 void printLiveRanges();