blob: 9e7ef06fe280f9d27a9bea2df02d9600fba9d312 [file] [log] [blame]
Chris Lattner7f74a562002-01-20 22:54:45 +00001/* Title: LiveRangeInfo.h -*- C++ -*-
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +00002 Author: Ruchira Sasanka
3 Date: Jun 30, 01
4 Purpose:
5
Ruchira Sasankaf20079d2002-01-07 19:16:26 +00006 This file contains the class LiveRangeInfo which constructs and keeps
7 the LiveRangMap which contains all the live ranges used in a method.
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +00008
9 Assumptions:
10
11 All variables (llvm Values) are defined before they are used. However, a
12 constant may not be defined in the machine instruction stream if it can be
13 used as an immediate value within a machine instruction. However, register
14 allocation does not have to worry about immediate constants since they
15 do not require registers.
16
17 Since an llvm Value has a list of uses associated, it is sufficient to
18 record only the defs in a Live Range.
19
20*/
21
22
23#ifndef LIVE_RANGE_INFO_H
24#define LIVE_RANGE_INFO_H
25
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000026#include "llvm/Type.h"
27#include "llvm/Method.h"
28#include "llvm/CodeGen/MachineInstr.h"
29
30#include "llvm/Analysis/LiveVar/LiveVarSet.h"
31
32#include "llvm/CodeGen/IGNode.h"
33#include "llvm/CodeGen/LiveRange.h"
34#include "llvm/CodeGen/RegClass.h"
35
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000036
Chris Lattner7f74a562002-01-20 22:54:45 +000037typedef std::hash_map<const Value*, LiveRange*> LiveRangeMapType;
38typedef std::vector<const MachineInstr*> CallRetInstrListType;
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000039
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000040
41
42//----------------------------------------------------------------------------
43// Class LiveRangeInfo
44//
45// Constructs and keeps the LiveRangMap which contains all the live
46// ranges used in a method. Also contain methods to coalesce live ranges.
47//----------------------------------------------------------------------------
48
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000049class LiveRangeInfo
50{
51
52private:
53
54 const Method *const Meth; // Method for which live range info is held
55
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000056 LiveRangeMapType LiveRangeMap; // A map from Value * to LiveRange * to
57 // record all live ranges in a method
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000058 // created by constructLiveRanges
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000059
Ruchira Sasankaf60342a2001-09-15 00:33:26 +000060 const TargetMachine& TM; // target machine description
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000061
Chris Lattner7f74a562002-01-20 22:54:45 +000062 std::vector<RegClass *> & RegClassList;// vector containing register classess
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000063
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +000064 const MachineRegInfo& MRI; // machine reg info
Ruchira Sasankaf60342a2001-09-15 00:33:26 +000065
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +000066 CallRetInstrListType CallRetInstrList; // a list of all call/ret instrs
Ruchira Sasankaf60342a2001-09-15 00:33:26 +000067
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000068
69 //------------ Private methods (see LiveRangeInfo.cpp for description)-------
70
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000071 void unionAndUpdateLRs(LiveRange *L1, LiveRange *L2);
72
73 void addInterference(const Instruction *const Inst,
74 const LiveVarSet *const LVSet);
75
Ruchira Sasanka33535772001-10-15 16:22:44 +000076 void suggestRegs4CallRets();
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000077
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000078 const Method* getMethod() { return Meth; }
79
80
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000081public:
82
Ruchira Sasankaf60342a2001-09-15 00:33:26 +000083 LiveRangeInfo(const Method *const M,
84 const TargetMachine& tm,
Chris Lattner7f74a562002-01-20 22:54:45 +000085 std::vector<RegClass *> & RCList);
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000086
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000087
88 // Destructor to destroy all LiveRanges in the LiveRange Map
89 ~LiveRangeInfo();
90
91 // Main entry point for live range construction
92 //
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000093 void constructLiveRanges();
94
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000095 // This method is used to add a live range created elsewhere (e.g.,
96 // in machine specific code) to the common live range map
97 //
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +000098 inline void addLRToMap(const Value *Val, LiveRange *LR) {
99 assert( Val && LR && "Val/LR is NULL!\n");
100 assert( (! LiveRangeMap[ Val ]) && "LR already set in map");
101 LiveRangeMap[ Val ] = LR;
102 }
103
Ruchira Sasankaf20079d2002-01-07 19:16:26 +0000104 // return the common live range map for this method
105 //
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000106 inline const LiveRangeMapType *const getLiveRangeMap() const
107 { return &LiveRangeMap; }
108
Ruchira Sasankaf20079d2002-01-07 19:16:26 +0000109 // Method sed to get the corresponding live range of a Value
110 //
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000111 inline LiveRange *getLiveRangeForValue( const Value *const Val)
112 { return LiveRangeMap[ Val ]; }
113
Ruchira Sasankaf20079d2002-01-07 19:16:26 +0000114 // Method used to get the Call and Return instruction list
115 //
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000116 inline CallRetInstrListType &getCallRetInstrList() {
117 return CallRetInstrList;
118 }
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000119
Ruchira Sasankaf20079d2002-01-07 19:16:26 +0000120 // Method for coalescing live ranges. Called only after interference info
121 // is calculated.
122 //
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000123 void coalesceLRs();
124
Ruchira Sasankaf20079d2002-01-07 19:16:26 +0000125 // debugging method to print the live ranges
126 //
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000127 void printLiveRanges();
128
129};
130
131
132
133
134#endif