blob: 4af73f069945a12c5d05ed41aeb5b0926a7c631d [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 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 {
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
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000061 void unionAndUpdateLRs(LiveRange *L1, LiveRange *L2);
62
Chris Lattnerb1def732002-02-05 02:51:01 +000063 void addInterference(const Instruction *Inst, const ValueSet *LVSet);
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000064
Ruchira Sasanka33535772001-10-15 16:22:44 +000065 void suggestRegs4CallRets();
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000066
Chris Lattner4e8c4872002-03-23 22:51:58 +000067 const Function *getMethod() { return Meth; }
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000068
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000069public:
70
Chris Lattner4e8c4872002-03-23 22:51:58 +000071 LiveRangeInfo(const Function *F,
Ruchira Sasankaf60342a2001-09-15 00:33:26 +000072 const TargetMachine& tm,
Chris Lattner7f74a562002-01-20 22:54:45 +000073 std::vector<RegClass *> & RCList);
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000074
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000075
76 // Destructor to destroy all LiveRanges in the LiveRange Map
77 ~LiveRangeInfo();
78
79 // Main entry point for live range construction
80 //
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000081 void constructLiveRanges();
82
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000083 // This method is used to add a live range created elsewhere (e.g.,
84 // in machine specific code) to the common live range map
85 //
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +000086 inline void addLRToMap(const Value *Val, LiveRange *LR) {
Chris Lattnerb0da8b22002-02-04 05:52:08 +000087 assert(Val && LR && "Val/LR is NULL!\n");
88 assert((!LiveRangeMap[Val]) && "LR already set in map");
89 LiveRangeMap[Val] = LR;
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +000090 }
91
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000092 // return the common live range map for this method
93 //
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000094 inline const LiveRangeMapType *const getLiveRangeMap() const
95 { return &LiveRangeMap; }
96
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000097 // Method sed to get the corresponding live range of a Value
98 //
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000099 inline LiveRange *getLiveRangeForValue( const Value *const Val)
Chris Lattnerb0da8b22002-02-04 05:52:08 +0000100 { return LiveRangeMap[Val]; }
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000101
Ruchira Sasankaf20079d2002-01-07 19:16:26 +0000102 // Method used to get the Call and Return instruction list
103 //
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000104 inline CallRetInstrListType &getCallRetInstrList() {
105 return CallRetInstrList;
106 }
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000107
Ruchira Sasankaf20079d2002-01-07 19:16:26 +0000108 // Method for coalescing live ranges. Called only after interference info
109 // is calculated.
110 //
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000111 void coalesceLRs();
112
Ruchira Sasankaf20079d2002-01-07 19:16:26 +0000113 // debugging method to print the live ranges
114 //
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000115 void printLiveRanges();
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000116};
117
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000118#endif