blob: 48abdc0da5ab59909d5f9aecdf1343d6c8ba6623 [file] [log] [blame]
Chris Lattner4e8c4872002-03-23 22:51:58 +00001//===-- LiveRangeInfo.h - Track all LiveRanges for a Function ----*- C++ -*-==//
Chris Lattnerb0da8b22002-02-04 05:52:08 +00002//
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"
Chris Lattnerb1def732002-02-05 02:51:01 +000023#include "llvm/Analysis/LiveVar/ValueSet.h"
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000024
Chris Lattnerb0da8b22002-02-04 05:52:08 +000025class LiveRange;
26class MachineInstr;
Chris Lattnerb0da8b22002-02-04 05:52:08 +000027class RegClass;
28class MachineRegInfo;
29class TargetMachine;
30class Value;
Chris Lattner4e8c4872002-03-23 22:51:58 +000031class Function;
Chris Lattnerb0da8b22002-02-04 05:52:08 +000032class Instruction;
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000033
Chris Lattnere5833332002-07-24 21:21:33 +000034typedef hash_map<const Value*, LiveRange*> LiveRangeMapType;
Vikram S. Adveff045b22002-07-08 22:34:40 +000035typedef std::vector<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 {
Chris Lattner4e8c4872002-03-23 22:51:58 +000045 const Function *const Meth; // Func 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
Vikram S. Adve90119032002-09-28 17:05:43 +000061 LiveRange* createNewLiveRange (const Value* Def,
62 bool isCC = false);
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000063
Vikram S. Adve90119032002-09-28 17:05:43 +000064 LiveRange* createOrAddToLiveRange (const Value* Def,
65 bool isCC = false);
66
67 void unionAndUpdateLRs (LiveRange *L1,
68 LiveRange *L2);
69
70 void addInterference (const Instruction *Inst,
71 const ValueSet *LVSet);
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000072
Vikram S. Adve90119032002-09-28 17:05:43 +000073 void suggestRegs4CallRets ();
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000074
Vikram S. Adve90119032002-09-28 17:05:43 +000075 const Function *getMethod () const { return Meth; }
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000076
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000077public:
78
Chris Lattner4e8c4872002-03-23 22:51:58 +000079 LiveRangeInfo(const Function *F,
Ruchira Sasankaf60342a2001-09-15 00:33:26 +000080 const TargetMachine& tm,
Chris Lattner7f74a562002-01-20 22:54:45 +000081 std::vector<RegClass *> & RCList);
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000082
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000083
84 // Destructor to destroy all LiveRanges in the LiveRange Map
85 ~LiveRangeInfo();
86
87 // Main entry point for live range construction
88 //
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000089 void constructLiveRanges();
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +000090
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000091 // return the common live range map for this method
92 //
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000093 inline const LiveRangeMapType *const getLiveRangeMap() const
94 { return &LiveRangeMap; }
95
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000096 // Method sed to get the corresponding live range of a Value
97 //
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000098 inline LiveRange *getLiveRangeForValue( const Value *const Val)
Chris Lattnerb0da8b22002-02-04 05:52:08 +000099 { return LiveRangeMap[Val]; }
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000100
Ruchira Sasankaf20079d2002-01-07 19:16:26 +0000101 // Method used to get the Call and Return instruction list
102 //
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000103 inline CallRetInstrListType &getCallRetInstrList() {
104 return CallRetInstrList;
105 }
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000106
Ruchira Sasankaf20079d2002-01-07 19:16:26 +0000107 // Method for coalescing live ranges. Called only after interference info
108 // is calculated.
109 //
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000110 void coalesceLRs();
111
Ruchira Sasankaf20079d2002-01-07 19:16:26 +0000112 // debugging method to print the live ranges
113 //
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000114 void printLiveRanges();
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000115};
116
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000117#endif