blob: 09aca44f30c6297f02d2e888083eb8667a3ce073 [file] [log] [blame]
Chris Lattnerb0da8b22002-02-04 05:52:08 +00001//===-- LiveRangeInfo.h - Track all LiveRanges for a Method ------*- C++ -*-==//
2//
3// This file contains the class LiveRangeInfo which constructs and keeps
4// the LiveRangMap which contains all the live ranges used in a method.
5//
6// Assumptions:
7//
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.
13//
14// Since an llvm Value has a list of uses associated, it is sufficient to
15// record only the defs in a Live Range.
16//
17//===----------------------------------------------------------------------===//
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000018
19#ifndef LIVE_RANGE_INFO_H
20#define LIVE_RANGE_INFO_H
21
Chris Lattnerb0da8b22002-02-04 05:52:08 +000022#include "Support/HashExtras.h"
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000023
Chris Lattnerb0da8b22002-02-04 05:52:08 +000024class LiveRange;
25class MachineInstr;
26class LiveVarSet;
27class RegClass;
28class MachineRegInfo;
29class TargetMachine;
30class Value;
31class Method;
32class Instruction;
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000033
Chris Lattner7f74a562002-01-20 22:54:45 +000034typedef std::hash_map<const Value*, LiveRange*> LiveRangeMapType;
35typedef std::vector<const MachineInstr*> CallRetInstrListType;
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000036
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000037//----------------------------------------------------------------------------
38// Class LiveRangeInfo
39//
40// Constructs and keeps the LiveRangMap which contains all the live
41// ranges used in a method. Also contain methods to coalesce live ranges.
42//----------------------------------------------------------------------------
43
Chris Lattnerb0da8b22002-02-04 05:52:08 +000044class LiveRangeInfo {
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000045 const Method *const Meth; // Method for which live range info is held
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000046 LiveRangeMapType LiveRangeMap; // A map from Value * to LiveRange * to
47 // record all live ranges in a method
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000048 // created by constructLiveRanges
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000049
Ruchira Sasankaf60342a2001-09-15 00:33:26 +000050 const TargetMachine& TM; // target machine description
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000051
Chris Lattner7f74a562002-01-20 22:54:45 +000052 std::vector<RegClass *> & RegClassList;// vector containing register classess
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000053
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +000054 const MachineRegInfo& MRI; // machine reg info
Ruchira Sasankaf60342a2001-09-15 00:33:26 +000055
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +000056 CallRetInstrListType CallRetInstrList; // a list of all call/ret instrs
Ruchira Sasankaf60342a2001-09-15 00:33:26 +000057
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000058
59 //------------ Private methods (see LiveRangeInfo.cpp for description)-------
60
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000061 void unionAndUpdateLRs(LiveRange *L1, LiveRange *L2);
62
63 void addInterference(const Instruction *const Inst,
64 const LiveVarSet *const LVSet);
65
Ruchira Sasanka33535772001-10-15 16:22:44 +000066 void suggestRegs4CallRets();
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000067
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000068 const Method* getMethod() { return Meth; }
69
70
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000071public:
72
Ruchira Sasankaf60342a2001-09-15 00:33:26 +000073 LiveRangeInfo(const Method *const M,
74 const TargetMachine& tm,
Chris Lattner7f74a562002-01-20 22:54:45 +000075 std::vector<RegClass *> & RCList);
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000076
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000077
78 // Destructor to destroy all LiveRanges in the LiveRange Map
79 ~LiveRangeInfo();
80
81 // Main entry point for live range construction
82 //
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000083 void constructLiveRanges();
84
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000085 // This method is used to add a live range created elsewhere (e.g.,
86 // in machine specific code) to the common live range map
87 //
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +000088 inline void addLRToMap(const Value *Val, LiveRange *LR) {
Chris Lattnerb0da8b22002-02-04 05:52:08 +000089 assert(Val && LR && "Val/LR is NULL!\n");
90 assert((!LiveRangeMap[Val]) && "LR already set in map");
91 LiveRangeMap[Val] = LR;
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +000092 }
93
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000094 // return the common live range map for this method
95 //
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000096 inline const LiveRangeMapType *const getLiveRangeMap() const
97 { return &LiveRangeMap; }
98
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000099 // Method sed to get the corresponding live range of a Value
100 //
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000101 inline LiveRange *getLiveRangeForValue( const Value *const Val)
Chris Lattnerb0da8b22002-02-04 05:52:08 +0000102 { return LiveRangeMap[Val]; }
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000103
Ruchira Sasankaf20079d2002-01-07 19:16:26 +0000104 // Method used to get the Call and Return instruction list
105 //
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000106 inline CallRetInstrListType &getCallRetInstrList() {
107 return CallRetInstrList;
108 }
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000109
Ruchira Sasankaf20079d2002-01-07 19:16:26 +0000110 // Method for coalescing live ranges. Called only after interference info
111 // is calculated.
112 //
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000113 void coalesceLRs();
114
Ruchira Sasankaf20079d2002-01-07 19:16:26 +0000115 // debugging method to print the live ranges
116 //
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000117 void printLiveRanges();
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000118};
119
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000120#endif