blob: 0425606b1c9cc3596ee85f901a72a6eaa76d5423 [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 Lattnerde1d7292003-01-14 22:56:37 +000022#include "llvm/CodeGen/ValueSet.h"
Chris Lattner981e5852003-07-26 23:00:29 +000023#include "Support/hash_map"
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;
Chris Lattnerf9781b52002-12-29 03:13:05 +000028class TargetRegInfo;
Chris Lattnerb0da8b22002-02-04 05:52:08 +000029class 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;
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000035
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000036//----------------------------------------------------------------------------
37// Class LiveRangeInfo
38//
39// Constructs and keeps the LiveRangMap which contains all the live
40// ranges used in a method. Also contain methods to coalesce live ranges.
41//----------------------------------------------------------------------------
42
Chris Lattnerb0da8b22002-02-04 05:52:08 +000043class LiveRangeInfo {
Chris Lattner4e8c4872002-03-23 22:51:58 +000044 const Function *const Meth; // Func for which live range info is held
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000045 LiveRangeMapType LiveRangeMap; // A map from Value * to LiveRange * to
46 // record all live ranges in a method
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000047 // created by constructLiveRanges
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000048
Ruchira Sasankaf60342a2001-09-15 00:33:26 +000049 const TargetMachine& TM; // target machine description
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000050
Chris Lattner7f74a562002-01-20 22:54:45 +000051 std::vector<RegClass *> & RegClassList;// vector containing register classess
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000052
Chris Lattnerf9781b52002-12-29 03:13:05 +000053 const TargetRegInfo& MRI; // machine reg info
Ruchira Sasankaf60342a2001-09-15 00:33:26 +000054
Chris Lattner6d6d87f2002-10-29 17:03:19 +000055 std::vector<MachineInstr*> CallRetInstrList; // a list of all call/ret instrs
Ruchira Sasankaf60342a2001-09-15 00:33:26 +000056
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000057
58 //------------ Private methods (see LiveRangeInfo.cpp for description)-------
59
Vikram S. Adve90119032002-09-28 17:05:43 +000060 LiveRange* createNewLiveRange (const Value* Def,
61 bool isCC = false);
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000062
Vikram S. Adve90119032002-09-28 17:05:43 +000063 LiveRange* createOrAddToLiveRange (const Value* Def,
64 bool isCC = false);
65
66 void unionAndUpdateLRs (LiveRange *L1,
67 LiveRange *L2);
68
69 void addInterference (const Instruction *Inst,
70 const ValueSet *LVSet);
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000071
Vikram S. Adve90119032002-09-28 17:05:43 +000072 void suggestRegs4CallRets ();
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000073
Vikram S. Adve90119032002-09-28 17:05:43 +000074 const Function *getMethod () const { return Meth; }
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000075
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000076public:
77
Chris Lattner4e8c4872002-03-23 22:51:58 +000078 LiveRangeInfo(const Function *F,
Ruchira Sasankaf60342a2001-09-15 00:33:26 +000079 const TargetMachine& tm,
Chris Lattner7f74a562002-01-20 22:54:45 +000080 std::vector<RegClass *> & RCList);
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000081
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000082
83 // Destructor to destroy all LiveRanges in the LiveRange Map
84 ~LiveRangeInfo();
85
86 // Main entry point for live range construction
87 //
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000088 void constructLiveRanges();
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +000089
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000090 // return the common live range map for this method
91 //
Chris Lattner6d6d87f2002-10-29 17:03:19 +000092 inline const LiveRangeMapType *getLiveRangeMap() const
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000093 { return &LiveRangeMap; }
94
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000095 // Method sed to get the corresponding live range of a Value
96 //
Chris Lattner6d6d87f2002-10-29 17:03:19 +000097 inline LiveRange *getLiveRangeForValue( const Value *Val)
Chris Lattnerb0da8b22002-02-04 05:52:08 +000098 { return LiveRangeMap[Val]; }
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000099
Ruchira Sasankaf20079d2002-01-07 19:16:26 +0000100 // Method for coalescing live ranges. Called only after interference info
101 // is calculated.
102 //
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000103 void coalesceLRs();
104
Ruchira Sasankaf20079d2002-01-07 19:16:26 +0000105 // debugging method to print the live ranges
106 //
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000107 void printLiveRanges();
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000108};
109
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000110#endif