blob: 28e0712283917592977a7d6df90d1856ab93f1cc [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
31 vector<const Instruction *> CallInterferenceList;
32
33 IGNode *UserIGNode; // IGNode which uses this LR
34 int Color; // color assigned to this live range
35 bool mustSpill; // whether this LR must be spilt
36
37 // whether this LR must be saved accross calls
38 bool mustSaveAcrossCalls;
39
40 // bool mustLoadFromStack; // must load from stack at start of method
41
Ruchira Sasankaab304c42001-09-30 23:19:57 +000042
43 int SuggestedColor; // The suggested color for this LR
44
Ruchira Sasankac7136d22001-09-08 14:10:34 +000045 public:
46
47
48 ~LiveRange() {} // empty destructor
49
50 void setRegClass(RegClass *const RC)
51 { MyRegClass = RC; }
52
53 inline RegClass *const getRegClass() const
54 { assert(MyRegClass); return MyRegClass; }
55
56 inline bool hasColor() const
57 { return Color != -1; }
58
59 inline unsigned int getColor() const
60 { assert( Color != -1); return (unsigned) Color ; }
61
62 inline void setColor(unsigned int Col)
63 { Color = (int) Col ; }
64
65
66 inline void addCallInterference(const Instruction *const Inst)
67 { CallInterferenceList.push_back( Inst ); }
68
69 inline const Instruction *const getCallInterference(const unsigned i) const {
70 assert( i < CallInterferenceList.size() );
71 return CallInterferenceList[i];
72 }
73
74 inline unsigned int getNumOfCallInterferences() const
75 { return CallInterferenceList.size(); }
76
77
78 inline void markForSpill() { mustSpill = true; }
79
80 inline void markForSaveAcrossCalls() { mustSaveAcrossCalls = true; }
81
82 // inline void markForLoadFromStack() { mustLoadFromStack = true;
83
84
85 inline void setUserIGNode( IGNode *const IGN)
86 { assert( !UserIGNode); UserIGNode = IGN; }
87
88 inline IGNode * getUserIGNode() const
89 { return UserIGNode; } // NULL if the user is not allocated
90
91 inline Type::PrimitiveID getTypeID() const {
92 const Value *val = *begin();
93 assert(val && "Can't find type - Live range is empty" );
94 return (val->getType())->getPrimitiveID();
95 }
96
97
Ruchira Sasankaab304c42001-09-30 23:19:57 +000098 inline void setSuggestedColor(int Col) {
99 //assert( (SuggestedColor == -1) && "Changing an already suggested color");
100
101 if(SuggestedColor == -1 )
102 SuggestedColor = Col;
103 else if (DEBUG_RA)
Chris Lattner634b3522001-10-15 18:30:06 +0000104 cerr << "Already has a suggested color " << Col << endl;
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000105 }
106
107 inline unsigned getSuggestedColor() const {
108 assert( SuggestedColor != -1); // only a valid color is obtained
109 return (unsigned) SuggestedColor;
110 }
111
112 inline bool hasSuggestedColor() const {
113 return ( SuggestedColor > -1);
114 }
115
Ruchira Sasankac7136d22001-09-08 14:10:34 +0000116 inline LiveRange() : ValueSet() , CallInterferenceList()
117 {
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000118 Color = SuggestedColor = -1; // not yet colored
Ruchira Sasankac7136d22001-09-08 14:10:34 +0000119 mustSpill = mustSaveAcrossCalls = false;
120 MyRegClass = NULL;
121 UserIGNode = NULL;
122 }
123
124};
125
126
127
128
129
130#endif
131