blob: c0548d7fb9dc2206036486a44b85000be1dba242 [file] [log] [blame]
Ruchira Sasankac7136d22001-09-08 14:10:34 +00001/* Title: LiveRange.h
2 Author: Ruchira Sasanka
3 Date: July 25, 01
4 Purpose: To keep info about a live range.
5 Asuumptions:
6
7 Since the Value pointed by a use is the same as of its def, it is sufficient
8 to keep only defs in a LiveRange.
9*/
10
11#ifndef LIVE_RANGE_H
12#define LIVE_RANGE_H
13
14#include "llvm/Analysis/LiveVar/ValueSet.h"
15#include "llvm/Type.h"
16
17
18
19
20class RegClass;
21class IGNode;
22
23
24class LiveRange : public ValueSet
25{
26 private:
27
28 RegClass *MyRegClass; // register classs (e.g., int, FP) for this LR
29
30 // a list of call instructions that interferes with this live range
Ruchira Sasanka36f77072001-10-19 17:21:59 +000031 //vector<const Instruction *> CallInterferenceList;
32
33 // does this live range span across calls?
34 // This information is used by graph
35 // coloring algo to avoid allocating volatile colors to live ranges
36 // that span across calls (since they have to be saved/restored)
37
38 bool doesSpanAcrossCalls;
Ruchira Sasankac7136d22001-09-08 14:10:34 +000039
40 IGNode *UserIGNode; // IGNode which uses this LR
41 int Color; // color assigned to this live range
42 bool mustSpill; // whether this LR must be spilt
43
Ruchira Sasanka36f77072001-10-19 17:21:59 +000044 // whether this LR must be saved accross calls ***TODO REMOVE this
Ruchira Sasankac7136d22001-09-08 14:10:34 +000045 bool mustSaveAcrossCalls;
46
47 // bool mustLoadFromStack; // must load from stack at start of method
48
Ruchira Sasankaab304c42001-09-30 23:19:57 +000049
50 int SuggestedColor; // The suggested color for this LR
51
Ruchira Sasankac7136d22001-09-08 14:10:34 +000052 public:
53
54
55 ~LiveRange() {} // empty destructor
56
57 void setRegClass(RegClass *const RC)
58 { MyRegClass = RC; }
59
60 inline RegClass *const getRegClass() const
61 { assert(MyRegClass); return MyRegClass; }
62
63 inline bool hasColor() const
64 { return Color != -1; }
Ruchira Sasanka36f77072001-10-19 17:21:59 +000065
Ruchira Sasankac7136d22001-09-08 14:10:34 +000066 inline unsigned int getColor() const
67 { assert( Color != -1); return (unsigned) Color ; }
68
69 inline void setColor(unsigned int Col)
70 { Color = (int) Col ; }
71
72
Ruchira Sasanka36f77072001-10-19 17:21:59 +000073 inline void setCallInterference()
74 { doesSpanAcrossCalls = 1;
75 //CallInterferenceList.push_back( Inst );
76 }
Ruchira Sasankac7136d22001-09-08 14:10:34 +000077
Ruchira Sasanka36f77072001-10-19 17:21:59 +000078
79
80 /*
Ruchira Sasankac7136d22001-09-08 14:10:34 +000081 inline const Instruction *const getCallInterference(const unsigned i) const {
82 assert( i < CallInterferenceList.size() );
83 return CallInterferenceList[i];
84 }
Ruchira Sasanka36f77072001-10-19 17:21:59 +000085 */
Ruchira Sasankac7136d22001-09-08 14:10:34 +000086
Ruchira Sasanka36f77072001-10-19 17:21:59 +000087 inline bool isCallInterference() const
88 { return (doesSpanAcrossCalls == 1); }
Ruchira Sasankac7136d22001-09-08 14:10:34 +000089
90
91 inline void markForSpill() { mustSpill = true; }
92
93 inline void markForSaveAcrossCalls() { mustSaveAcrossCalls = true; }
94
95 // inline void markForLoadFromStack() { mustLoadFromStack = true;
96
97
98 inline void setUserIGNode( IGNode *const IGN)
99 { assert( !UserIGNode); UserIGNode = IGN; }
100
101 inline IGNode * getUserIGNode() const
102 { return UserIGNode; } // NULL if the user is not allocated
103
104 inline Type::PrimitiveID getTypeID() const {
105 const Value *val = *begin();
106 assert(val && "Can't find type - Live range is empty" );
107 return (val->getType())->getPrimitiveID();
108 }
109
110
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000111 inline void setSuggestedColor(int Col) {
112 //assert( (SuggestedColor == -1) && "Changing an already suggested color");
113
114 if(SuggestedColor == -1 )
115 SuggestedColor = Col;
116 else if (DEBUG_RA)
Chris Lattner634b3522001-10-15 18:30:06 +0000117 cerr << "Already has a suggested color " << Col << endl;
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000118 }
119
120 inline unsigned getSuggestedColor() const {
121 assert( SuggestedColor != -1); // only a valid color is obtained
122 return (unsigned) SuggestedColor;
123 }
124
125 inline bool hasSuggestedColor() const {
126 return ( SuggestedColor > -1);
127 }
128
Ruchira Sasanka36f77072001-10-19 17:21:59 +0000129 inline LiveRange() : ValueSet() /* , CallInterferenceList() */
Ruchira Sasankac7136d22001-09-08 14:10:34 +0000130 {
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000131 Color = SuggestedColor = -1; // not yet colored
Ruchira Sasankac7136d22001-09-08 14:10:34 +0000132 mustSpill = mustSaveAcrossCalls = false;
133 MyRegClass = NULL;
134 UserIGNode = NULL;
Ruchira Sasanka36f77072001-10-19 17:21:59 +0000135 doesSpanAcrossCalls = false;
136
Ruchira Sasankac7136d22001-09-08 14:10:34 +0000137 }
138
139};
140
141
142
143
144
145#endif
146