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 TargetRegInfo& MRI; // machine reg info
64 std::vector<MachineInstr*> CallRetInstrList; // a list of all call/ret instrs
67 //------------ Private methods (see LiveRangeInfo.cpp for description)-------
69 LiveRange* createNewLiveRange (const Value* Def,
72 LiveRange* createOrAddToLiveRange (const Value* Def,
75 void unionAndUpdateLRs (LiveRange *L1,
78 void addInterference (const Instruction *Inst,
79 const ValueSet *LVSet);
81 void suggestRegs4CallRets ();
83 const Function *getMethod () const { return Meth; }
87 LiveRangeInfo(const Function *F,
88 const TargetMachine& tm,
89 std::vector<RegClass *> & RCList);
92 /// Destructor to destroy all LiveRanges in the LiveRange Map
96 // Main entry point for live range construction
98 void constructLiveRanges();
100 /// return the common live range map for this method
102 inline const LiveRangeMapType *getLiveRangeMap() const
103 { return &LiveRangeMap; }
105 /// Method used to get the live range containing a Value.
106 /// This may return NULL if no live range exists for a Value (eg, some consts)
108 inline LiveRange *getLiveRangeForValue(const Value *Val) {
109 return LiveRangeMap[Val];
111 inline const LiveRange *getLiveRangeForValue(const Value *Val) const {
112 LiveRangeMapType::const_iterator I = LiveRangeMap.find(Val);
116 /// Method for coalescing live ranges. Called only after interference info
121 /// debugging method to print the live ranges
123 void printLiveRanges();
126 } // End llvm namespace