2 Author: Ruchira Sasanka
4 Purpose: To keep info about a live range.
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.
14 #include "llvm/Analysis/LiveVar/ValueSet.h"
15 #include "llvm/Type.h"
24 class LiveRange : public ValueSet
28 RegClass *MyRegClass; // register classs (e.g., int, FP) for this LR
30 // a list of call instructions that interferes with this live range
31 vector<const Instruction *> CallInterferenceList;
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
37 // whether this LR must be saved accross calls
38 bool mustSaveAcrossCalls;
40 // bool mustLoadFromStack; // must load from stack at start of method
43 int SuggestedColor; // The suggested color for this LR
48 ~LiveRange() {} // empty destructor
50 void setRegClass(RegClass *const RC)
53 inline RegClass *const getRegClass() const
54 { assert(MyRegClass); return MyRegClass; }
56 inline bool hasColor() const
57 { return Color != -1; }
59 inline unsigned int getColor() const
60 { assert( Color != -1); return (unsigned) Color ; }
62 inline void setColor(unsigned int Col)
63 { Color = (int) Col ; }
66 inline void addCallInterference(const Instruction *const Inst)
67 { CallInterferenceList.push_back( Inst ); }
69 inline const Instruction *const getCallInterference(const unsigned i) const {
70 assert( i < CallInterferenceList.size() );
71 return CallInterferenceList[i];
74 inline unsigned int getNumOfCallInterferences() const
75 { return CallInterferenceList.size(); }
78 inline void markForSpill() { mustSpill = true; }
80 inline void markForSaveAcrossCalls() { mustSaveAcrossCalls = true; }
82 // inline void markForLoadFromStack() { mustLoadFromStack = true;
85 inline void setUserIGNode( IGNode *const IGN)
86 { assert( !UserIGNode); UserIGNode = IGN; }
88 inline IGNode * getUserIGNode() const
89 { return UserIGNode; } // NULL if the user is not allocated
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();
98 inline void setSuggestedColor(int Col) {
99 //assert( (SuggestedColor == -1) && "Changing an already suggested color");
101 if(SuggestedColor == -1 )
102 SuggestedColor = Col;
104 cerr << "Already has a suggested color " << Col << endl;
107 inline unsigned getSuggestedColor() const {
108 assert( SuggestedColor != -1); // only a valid color is obtained
109 return (unsigned) SuggestedColor;
112 inline bool hasSuggestedColor() const {
113 return ( SuggestedColor > -1);
116 inline LiveRange() : ValueSet() , CallInterferenceList()
118 Color = SuggestedColor = -1; // not yet colored
119 mustSpill = mustSaveAcrossCalls = false;