11
11
//
12
12
// ===----------------------------------------------------------------------===//
13
13
14
- #include " RegClass.h"
15
- #include " RegAllocCommon.h"
16
14
#include " IGNode.h"
15
+ #include " RegAllocCommon.h"
16
+ #include " RegClass.h"
17
17
#include " llvm/Target/TargetRegInfo.h"
18
18
19
19
// ----------------------------------------------------------------------------
@@ -26,7 +26,7 @@ RegClass::RegClass(const Function *M,
26
26
: Meth(M), MRI(_MRI_), MRC(_MRC_),
27
27
RegClassID( _MRC_->getRegClassID () ),
28
28
IG(this ), IGNodeStack() {
29
- if ( DEBUG_RA >= RA_DEBUG_Interference)
29
+ if ( DEBUG_RA >= RA_DEBUG_Interference)
30
30
std::cerr << " Created Reg Class: " << RegClassID << " \n " ;
31
31
32
32
IsColorUsedArr.resize (MRC->getNumOfAllRegs ());
@@ -39,23 +39,19 @@ RegClass::RegClass(const Function *M,
39
39
// ----------------------------------------------------------------------------
40
40
void RegClass::colorAllRegs ()
41
41
{
42
- if (DEBUG_RA >= RA_DEBUG_Coloring)
42
+ if (DEBUG_RA >= RA_DEBUG_Coloring)
43
43
std::cerr << " Coloring IG of reg class " << RegClassID << " ...\n " ;
44
-
45
44
// pre-color IGNodes
46
45
pushAllIGNodes (); // push all IG Nodes
47
46
48
47
unsigned int StackSize = IGNodeStack.size ();
49
48
IGNode *CurIGNode;
50
-
51
49
// for all LRs on stack
52
- for ( unsigned int IGN=0 ; IGN < StackSize; IGN++) {
53
-
50
+ for (unsigned int IGN=0 ; IGN < StackSize; IGN++) {
54
51
CurIGNode = IGNodeStack.top (); // pop the IGNode on top of stack
55
52
IGNodeStack.pop ();
56
53
colorIGNode (CurIGNode); // color it
57
54
}
58
-
59
55
}
60
56
61
57
@@ -73,13 +69,13 @@ void RegClass::pushAllIGNodes()
73
69
// push non-constrained IGNodes
74
70
bool PushedAll = pushUnconstrainedIGNodes ();
75
71
76
- if ( DEBUG_RA >= RA_DEBUG_Coloring) {
72
+ if ( DEBUG_RA >= RA_DEBUG_Coloring) {
77
73
std::cerr << " Puhsed all-unconstrained IGNodes. " ;
78
74
if ( PushedAll ) std::cerr << " No constrained nodes left." ;
79
75
std::cerr << " \n " ;
80
76
}
81
77
82
- if ( PushedAll ) // if NO constrained nodes left
78
+ if ( PushedAll) // if NO constrained nodes left
83
79
return ;
84
80
85
81
@@ -89,24 +85,15 @@ void RegClass::pushAllIGNodes()
89
85
90
86
do {
91
87
// get node with min spill cost
92
- //
93
88
IGNode *IGNodeSpill = getIGNodeWithMinSpillCost ();
94
-
95
89
// push that node on to stack
96
- //
97
90
IGNodeStack.push (IGNodeSpill);
98
-
99
91
// set its OnStack flag and decrement degree of neighs
100
- //
101
92
IGNodeSpill->pushOnStack ();
102
-
103
93
// now push NON-constrained ones, if any
104
- //
105
94
NeedMoreSpills = !pushUnconstrainedIGNodes ();
106
-
107
95
if (DEBUG_RA >= RA_DEBUG_Coloring)
108
96
std::cerr << " \n Constrained IG Node found !@!" << IGNodeSpill->getIndex ();
109
-
110
97
} while (NeedMoreSpills); // repeat until we have pushed all
111
98
112
99
}
@@ -127,21 +114,21 @@ bool RegClass::pushUnconstrainedIGNodes()
127
114
bool pushedall = true ;
128
115
129
116
// a pass over IGNodeList
130
- for ( unsigned i =0 ; i < IGNodeListSize; i++) {
117
+ for ( unsigned i =0 ; i < IGNodeListSize; i++) {
131
118
132
119
// get IGNode i from IGNodeList
133
120
IGNode *IGNode = IG.getIGNodeList ()[i];
134
121
135
- if ( !IGNode ) // can be null due to merging
122
+ if ( !IGNode ) // can be null due to merging
136
123
continue ;
137
124
138
125
// if already pushed on stack, continue. This can happen since this
139
126
// method can be called repeatedly until all constrained nodes are
140
127
// pushed
141
- if ( IGNode->isOnStack () )
128
+ if ( IGNode->isOnStack () )
142
129
continue ;
143
130
// if the degree of IGNode is lower
144
- if ( ( unsigned ) IGNode->getCurDegree () < MRC->getNumOfAvailRegs ()) {
131
+ if (( unsigned ) IGNode->getCurDegree () < MRC->getNumOfAvailRegs ()) {
145
132
IGNodeStack.push ( IGNode ); // push IGNode on to the stack
146
133
IGNode->pushOnStack (); // set OnStack and dec deg of neighs
147
134
@@ -163,55 +150,45 @@ bool RegClass::pushUnconstrainedIGNodes()
163
150
// ----------------------------------------------------------------------------
164
151
// Get the IGNode with the minimum spill cost
165
152
// ----------------------------------------------------------------------------
166
- IGNode * RegClass::getIGNodeWithMinSpillCost ()
167
- {
168
-
153
+ IGNode * RegClass::getIGNodeWithMinSpillCost () {
169
154
unsigned int IGNodeListSize = IG.getIGNodeList ().size ();
170
155
double MinSpillCost = 0 ;
171
156
IGNode *MinCostIGNode = NULL ;
172
157
bool isFirstNode = true ;
173
158
174
159
// pass over IGNodeList to find the IGNode with minimum spill cost
175
160
// among all IGNodes that are not yet pushed on to the stack
176
- //
177
- for ( unsigned int i =0 ; i < IGNodeListSize; i++) {
161
+ for (unsigned int i =0 ; i < IGNodeListSize; i++) {
178
162
IGNode *IGNode = IG.getIGNodeList ()[i];
179
163
180
- if ( ! IGNode ) // can be null due to merging
164
+ if (! IGNode) // can be null due to merging
181
165
continue ;
182
166
183
- if ( ! IGNode->isOnStack () ) {
184
-
167
+ if (!IGNode->isOnStack ()) {
185
168
double SpillCost = (double ) IGNode->getParentLR ()->getSpillCost () /
186
169
(double ) (IGNode->getCurDegree () + 1 );
187
170
188
- if ( isFirstNode ) { // for the first IG node
171
+ if ( isFirstNode) { // for the first IG node
189
172
MinSpillCost = SpillCost;
190
173
MinCostIGNode = IGNode;
191
174
isFirstNode = false ;
192
- }
193
-
194
- else if ( MinSpillCost > SpillCost) {
175
+ } else if (MinSpillCost > SpillCost) {
195
176
MinSpillCost = SpillCost;
196
177
MinCostIGNode = IGNode;
197
178
}
198
-
199
179
}
200
180
}
201
181
202
- assert ( MinCostIGNode && " No IGNode to spill" );
182
+ assert ( MinCostIGNode && " No IGNode to spill" );
203
183
return MinCostIGNode;
204
184
}
205
185
206
186
207
-
208
187
// ----------------------------------------------------------------------------
209
188
// Color the IGNode using the machine specific code.
210
189
// ----------------------------------------------------------------------------
211
- void RegClass::colorIGNode (IGNode *const Node)
212
- {
213
-
214
- if ( ! Node->hasColor () ) { // not colored as an arg etc.
190
+ void RegClass::colorIGNode (IGNode *const Node) {
191
+ if (! Node->hasColor ()) { // not colored as an arg etc.
215
192
216
193
// init all elements of to IsColorUsedAr false;
217
194
clearColorsUsed ();
@@ -242,22 +219,20 @@ void RegClass::colorIGNode(IGNode *const Node)
242
219
// call the target specific code for coloring
243
220
//
244
221
MRC->colorIGNode (Node, IsColorUsedArr);
245
- }
246
- else {
247
- if ( DEBUG_RA >= RA_DEBUG_Coloring) {
222
+ } else {
223
+ if (DEBUG_RA >= RA_DEBUG_Coloring) {
248
224
std::cerr << " Node " << Node->getIndex ();
249
225
std::cerr << " already colored with color " << Node->getColor () << " \n " ;
250
226
}
251
227
}
252
228
253
229
254
- if ( !Node->hasColor () ) {
255
- if ( DEBUG_RA >= RA_DEBUG_Coloring) {
230
+ if ( !Node->hasColor () ) {
231
+ if ( DEBUG_RA >= RA_DEBUG_Coloring) {
256
232
std::cerr << " Node " << Node->getIndex ();
257
233
std::cerr << " - could not find a color (needs spilling)\n " ;
258
234
}
259
235
}
260
-
261
236
}
262
237
263
238
void RegClass::printIGNodeList () const {
0 commit comments