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"
43 typedef hash_map<const Value*, LiveRange*> LiveRangeMapType;
45 //----------------------------------------------------------------------------
46 // Class LiveRangeInfo
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 //----------------------------------------------------------------------------
53 const Function *const Meth; // Func for which live range info is held
54 LiveRangeMapType LiveRangeMap; // A map from Value * to LiveRange * to
55 // record all live ranges in a method
56 // created by constructLiveRanges
58 const TargetMachine& TM; // target machine description
60 std::vector<RegClass *> & RegClassList;// vector containing register classess
62 const SparcV9RegInfo& MRI; // machine reg info
64 std::vector<MachineInstr*> CallRetInstrList; // a list of all call/ret instrs
66 //------------ Private methods (see LiveRangeInfo.cpp for description)-------
68 LiveRange* createNewLiveRange (const Value* Def,
71 LiveRange* createOrAddToLiveRange (const Value* Def,
74 void unionAndUpdateLRs (LiveRange *L1,
77 void suggestRegs4CallRets ();
80 LiveRangeInfo(const Function *F,
81 const TargetMachine& tm,
82 std::vector<RegClass *> & RCList);
85 /// Destructor to destroy all LiveRanges in the LiveRange Map
89 // Main entry point for live range construction
91 void constructLiveRanges();
93 /// return the common live range map for this method
95 inline const LiveRangeMapType *getLiveRangeMap() const
96 { return &LiveRangeMap; }
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)
101 inline LiveRange *getLiveRangeForValue(const Value *Val) {
102 return LiveRangeMap[Val];
104 inline const LiveRange *getLiveRangeForValue(const Value *Val) const {
105 LiveRangeMapType::const_iterator I = LiveRangeMap.find(Val);
109 /// Method for coalescing live ranges. Called only after interference info
114 /// debugging method to print the live ranges
116 void printLiveRanges();
119 } // End llvm namespace