llvm.org GIT mirror llvm / f54c437
* Eliminate `using' directive * Fix order of #includes * Make code layout more consistent * Eliminate extraneous whitespace and comment-lines git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9433 91177308-0d34-0410-b5e6-96231b3b80d8 Misha Brukman 16 years ago
4 changed file(s) with 52 addition(s) and 104 deletion(s). Raw diff Collapse all Expand all
1010 //
1111 //===----------------------------------------------------------------------===//
1212
13 #include "IGNode.h"
14 #include "InterferenceGraph.h"
1315 #include "RegAllocCommon.h"
14 #include "InterferenceGraph.h"
15 #include "IGNode.h"
1616 #include "Support/STLExtras.h"
1717 #include
18 using std::cerr;
1918
2019 // for asserting this IG node is infact in the IGNodeList of this class
2120 inline static void assertIGNode(const InterferenceGraph *IG,
1010 //
1111 //===----------------------------------------------------------------------===//
1212
13 #include "IGNode.h"
14 #include "RegAllocCommon.h"
1315 #include "RegClass.h"
14 #include "RegAllocCommon.h"
15 #include "IGNode.h"
1616 #include "llvm/Target/TargetRegInfo.h"
1717
1818 //----------------------------------------------------------------------------
2525 : Meth(M), MRI(_MRI_), MRC(_MRC_),
2626 RegClassID( _MRC_->getRegClassID() ),
2727 IG(this), IGNodeStack() {
28 if( DEBUG_RA >= RA_DEBUG_Interference)
28 if (DEBUG_RA >= RA_DEBUG_Interference)
2929 std::cerr << "Created Reg Class: " << RegClassID << "\n";
3030
3131 IsColorUsedArr.resize(MRC->getNumOfAllRegs());
3838 //----------------------------------------------------------------------------
3939 void RegClass::colorAllRegs()
4040 {
41 if(DEBUG_RA >= RA_DEBUG_Coloring)
41 if (DEBUG_RA >= RA_DEBUG_Coloring)
4242 std::cerr << "Coloring IG of reg class " << RegClassID << " ...\n";
43
4443 // pre-color IGNodes
4544 pushAllIGNodes(); // push all IG Nodes
4645
4746 unsigned int StackSize = IGNodeStack.size();
4847 IGNode *CurIGNode;
49
5048 // for all LRs on stack
51 for( unsigned int IGN=0; IGN < StackSize; IGN++) {
52
49 for (unsigned int IGN=0; IGN < StackSize; IGN++) {
5350 CurIGNode = IGNodeStack.top(); // pop the IGNode on top of stack
5451 IGNodeStack.pop();
5552 colorIGNode (CurIGNode); // color it
5653 }
57
5854 }
5955
6056
7268 // push non-constrained IGNodes
7369 bool PushedAll = pushUnconstrainedIGNodes();
7470
75 if( DEBUG_RA >= RA_DEBUG_Coloring) {
71 if (DEBUG_RA >= RA_DEBUG_Coloring) {
7672 std::cerr << " Puhsed all-unconstrained IGNodes. ";
7773 if( PushedAll ) std::cerr << " No constrained nodes left.";
7874 std::cerr << "\n";
7975 }
8076
81 if( PushedAll ) // if NO constrained nodes left
77 if (PushedAll) // if NO constrained nodes left
8278 return;
8379
8480
8884
8985 do {
9086 //get node with min spill cost
91 //
9287 IGNode *IGNodeSpill = getIGNodeWithMinSpillCost();
93
9488 // push that node on to stack
95 //
9689 IGNodeStack.push(IGNodeSpill);
97
9890 // set its OnStack flag and decrement degree of neighs
99 //
10091 IGNodeSpill->pushOnStack();
101
10292 // now push NON-constrained ones, if any
103 //
10493 NeedMoreSpills = !pushUnconstrainedIGNodes();
105
10694 if (DEBUG_RA >= RA_DEBUG_Coloring)
10795 std::cerr << "\nConstrained IG Node found !@!" << IGNodeSpill->getIndex();
108
10996 } while(NeedMoreSpills); // repeat until we have pushed all
11097
11198 }
126113 bool pushedall = true;
127114
128115 // a pass over IGNodeList
129 for( unsigned i =0; i < IGNodeListSize; i++) {
116 for (unsigned i =0; i < IGNodeListSize; i++) {
130117
131118 // get IGNode i from IGNodeList
132119 IGNode *IGNode = IG.getIGNodeList()[i];
133120
134 if( !IGNode ) // can be null due to merging
121 if (!IGNode ) // can be null due to merging
135122 continue;
136123
137124 // if already pushed on stack, continue. This can happen since this
138125 // method can be called repeatedly until all constrained nodes are
139126 // pushed
140 if( IGNode->isOnStack() )
127 if (IGNode->isOnStack() )
141128 continue;
142129 // if the degree of IGNode is lower
143 if( (unsigned) IGNode->getCurDegree() < MRC->getNumOfAvailRegs()) {
130 if ((unsigned) IGNode->getCurDegree() < MRC->getNumOfAvailRegs()) {
144131 IGNodeStack.push( IGNode ); // push IGNode on to the stack
145132 IGNode->pushOnStack(); // set OnStack and dec deg of neighs
146133
162149 //----------------------------------------------------------------------------
163150 // Get the IGNode with the minimum spill cost
164151 //----------------------------------------------------------------------------
165 IGNode * RegClass::getIGNodeWithMinSpillCost()
166 {
167
152 IGNode * RegClass::getIGNodeWithMinSpillCost() {
168153 unsigned int IGNodeListSize = IG.getIGNodeList().size();
169154 double MinSpillCost = 0;
170155 IGNode *MinCostIGNode = NULL;
172157
173158 // pass over IGNodeList to find the IGNode with minimum spill cost
174159 // among all IGNodes that are not yet pushed on to the stack
175 //
176 for( unsigned int i =0; i < IGNodeListSize; i++) {
160 for (unsigned int i =0; i < IGNodeListSize; i++) {
177161 IGNode *IGNode = IG.getIGNodeList()[i];
178162
179 if( ! IGNode ) // can be null due to merging
163 if (!IGNode) // can be null due to merging
180164 continue;
181165
182 if( ! IGNode->isOnStack() ) {
183
166 if (!IGNode->isOnStack()) {
184167 double SpillCost = (double) IGNode->getParentLR()->getSpillCost() /
185168 (double) (IGNode->getCurDegree() + 1);
186169
187 if( isFirstNode ) { // for the first IG node
170 if (isFirstNode) { // for the first IG node
188171 MinSpillCost = SpillCost;
189172 MinCostIGNode = IGNode;
190173 isFirstNode = false;
191 }
192
193 else if( MinSpillCost > SpillCost) {
174 } else if (MinSpillCost > SpillCost) {
194175 MinSpillCost = SpillCost;
195176 MinCostIGNode = IGNode;
196177 }
197
198178 }
199179 }
200180
201 assert( MinCostIGNode && "No IGNode to spill");
181 assert (MinCostIGNode && "No IGNode to spill");
202182 return MinCostIGNode;
203183 }
204184
205185
206
207186 //----------------------------------------------------------------------------
208187 // Color the IGNode using the machine specific code.
209188 //----------------------------------------------------------------------------
210 void RegClass::colorIGNode(IGNode *const Node)
211 {
212
213 if( ! Node->hasColor() ) { // not colored as an arg etc.
189 void RegClass::colorIGNode(IGNode *const Node) {
190 if (! Node->hasColor()) { // not colored as an arg etc.
214191
215192 // init all elements of to IsColorUsedAr false;
216193 clearColorsUsed();
241218 // call the target specific code for coloring
242219 //
243220 MRC->colorIGNode(Node, IsColorUsedArr);
244 }
245 else {
246 if( DEBUG_RA >= RA_DEBUG_Coloring) {
221 } else {
222 if (DEBUG_RA >= RA_DEBUG_Coloring) {
247223 std::cerr << " Node " << Node->getIndex();
248224 std::cerr << " already colored with color " << Node->getColor() << "\n";
249225 }
250226 }
251227
252228
253 if( !Node->hasColor() ) {
254 if( DEBUG_RA >= RA_DEBUG_Coloring) {
229 if (!Node->hasColor() ) {
230 if (DEBUG_RA >= RA_DEBUG_Coloring) {
255231 std::cerr << " Node " << Node->getIndex();
256232 std::cerr << " - could not find a color (needs spilling)\n";
257233 }
258234 }
259
260235 }
261236
262237 void RegClass::printIGNodeList() const {
1010 //
1111 //===----------------------------------------------------------------------===//
1212
13 #include "IGNode.h"
14 #include "InterferenceGraph.h"
1315 #include "RegAllocCommon.h"
14 #include "InterferenceGraph.h"
15 #include "IGNode.h"
1616 #include "Support/STLExtras.h"
1717 #include
18 using std::cerr;
1918
2019 // for asserting this IG node is infact in the IGNodeList of this class
2120 inline static void assertIGNode(const InterferenceGraph *IG,
1010 //
1111 //===----------------------------------------------------------------------===//
1212
13 #include "IGNode.h"
14 #include "RegAllocCommon.h"
1315 #include "RegClass.h"
14 #include "RegAllocCommon.h"
15 #include "IGNode.h"
1616 #include "llvm/Target/TargetRegInfo.h"
1717
1818 //----------------------------------------------------------------------------
2525 : Meth(M), MRI(_MRI_), MRC(_MRC_),
2626 RegClassID( _MRC_->getRegClassID() ),
2727 IG(this), IGNodeStack() {
28 if( DEBUG_RA >= RA_DEBUG_Interference)
28 if (DEBUG_RA >= RA_DEBUG_Interference)
2929 std::cerr << "Created Reg Class: " << RegClassID << "\n";
3030
3131 IsColorUsedArr.resize(MRC->getNumOfAllRegs());
3838 //----------------------------------------------------------------------------
3939 void RegClass::colorAllRegs()
4040 {
41 if(DEBUG_RA >= RA_DEBUG_Coloring)
41 if (DEBUG_RA >= RA_DEBUG_Coloring)
4242 std::cerr << "Coloring IG of reg class " << RegClassID << " ...\n";
43
4443 // pre-color IGNodes
4544 pushAllIGNodes(); // push all IG Nodes
4645
4746 unsigned int StackSize = IGNodeStack.size();
4847 IGNode *CurIGNode;
49
5048 // for all LRs on stack
51 for( unsigned int IGN=0; IGN < StackSize; IGN++) {
52
49 for (unsigned int IGN=0; IGN < StackSize; IGN++) {
5350 CurIGNode = IGNodeStack.top(); // pop the IGNode on top of stack
5451 IGNodeStack.pop();
5552 colorIGNode (CurIGNode); // color it
5653 }
57
5854 }
5955
6056
7268 // push non-constrained IGNodes
7369 bool PushedAll = pushUnconstrainedIGNodes();
7470
75 if( DEBUG_RA >= RA_DEBUG_Coloring) {
71 if (DEBUG_RA >= RA_DEBUG_Coloring) {
7672 std::cerr << " Puhsed all-unconstrained IGNodes. ";
7773 if( PushedAll ) std::cerr << " No constrained nodes left.";
7874 std::cerr << "\n";
7975 }
8076
81 if( PushedAll ) // if NO constrained nodes left
77 if (PushedAll) // if NO constrained nodes left
8278 return;
8379
8480
8884
8985 do {
9086 //get node with min spill cost
91 //
9287 IGNode *IGNodeSpill = getIGNodeWithMinSpillCost();
93
9488 // push that node on to stack
95 //
9689 IGNodeStack.push(IGNodeSpill);
97
9890 // set its OnStack flag and decrement degree of neighs
99 //
10091 IGNodeSpill->pushOnStack();
101
10292 // now push NON-constrained ones, if any
103 //
10493 NeedMoreSpills = !pushUnconstrainedIGNodes();
105
10694 if (DEBUG_RA >= RA_DEBUG_Coloring)
10795 std::cerr << "\nConstrained IG Node found !@!" << IGNodeSpill->getIndex();
108
10996 } while(NeedMoreSpills); // repeat until we have pushed all
11097
11198 }
126113 bool pushedall = true;
127114
128115 // a pass over IGNodeList
129 for( unsigned i =0; i < IGNodeListSize; i++) {
116 for (unsigned i =0; i < IGNodeListSize; i++) {
130117
131118 // get IGNode i from IGNodeList
132119 IGNode *IGNode = IG.getIGNodeList()[i];
133120
134 if( !IGNode ) // can be null due to merging
121 if (!IGNode ) // can be null due to merging
135122 continue;
136123
137124 // if already pushed on stack, continue. This can happen since this
138125 // method can be called repeatedly until all constrained nodes are
139126 // pushed
140 if( IGNode->isOnStack() )
127 if (IGNode->isOnStack() )
141128 continue;
142129 // if the degree of IGNode is lower
143 if( (unsigned) IGNode->getCurDegree() < MRC->getNumOfAvailRegs()) {
130 if ((unsigned) IGNode->getCurDegree() < MRC->getNumOfAvailRegs()) {
144131 IGNodeStack.push( IGNode ); // push IGNode on to the stack
145132 IGNode->pushOnStack(); // set OnStack and dec deg of neighs
146133
162149 //----------------------------------------------------------------------------
163150 // Get the IGNode with the minimum spill cost
164151 //----------------------------------------------------------------------------
165 IGNode * RegClass::getIGNodeWithMinSpillCost()
166 {
167
152 IGNode * RegClass::getIGNodeWithMinSpillCost() {
168153 unsigned int IGNodeListSize = IG.getIGNodeList().size();
169154 double MinSpillCost = 0;
170155 IGNode *MinCostIGNode = NULL;
172157
173158 // pass over IGNodeList to find the IGNode with minimum spill cost
174159 // among all IGNodes that are not yet pushed on to the stack
175 //
176 for( unsigned int i =0; i < IGNodeListSize; i++) {
160 for (unsigned int i =0; i < IGNodeListSize; i++) {
177161 IGNode *IGNode = IG.getIGNodeList()[i];
178162
179 if( ! IGNode ) // can be null due to merging
163 if (!IGNode) // can be null due to merging
180164 continue;
181165
182 if( ! IGNode->isOnStack() ) {
183
166 if (!IGNode->isOnStack()) {
184167 double SpillCost = (double) IGNode->getParentLR()->getSpillCost() /
185168 (double) (IGNode->getCurDegree() + 1);
186169
187 if( isFirstNode ) { // for the first IG node
170 if (isFirstNode) { // for the first IG node
188171 MinSpillCost = SpillCost;
189172 MinCostIGNode = IGNode;
190173 isFirstNode = false;
191 }
192
193 else if( MinSpillCost > SpillCost) {
174 } else if (MinSpillCost > SpillCost) {
194175 MinSpillCost = SpillCost;
195176 MinCostIGNode = IGNode;
196177 }
197
198178 }
199179 }
200180
201 assert( MinCostIGNode && "No IGNode to spill");
181 assert (MinCostIGNode && "No IGNode to spill");
202182 return MinCostIGNode;
203183 }
204184
205185
206
207186 //----------------------------------------------------------------------------
208187 // Color the IGNode using the machine specific code.
209188 //----------------------------------------------------------------------------
210 void RegClass::colorIGNode(IGNode *const Node)
211 {
212
213 if( ! Node->hasColor() ) { // not colored as an arg etc.
189 void RegClass::colorIGNode(IGNode *const Node) {
190 if (! Node->hasColor()) { // not colored as an arg etc.
214191
215192 // init all elements of to IsColorUsedAr false;
216193 clearColorsUsed();
241218 // call the target specific code for coloring
242219 //
243220 MRC->colorIGNode(Node, IsColorUsedArr);
244 }
245 else {
246 if( DEBUG_RA >= RA_DEBUG_Coloring) {
221 } else {
222 if (DEBUG_RA >= RA_DEBUG_Coloring) {
247223 std::cerr << " Node " << Node->getIndex();
248224 std::cerr << " already colored with color " << Node->getColor() << "\n";
249225 }
250226 }
251227
252228
253 if( !Node->hasColor() ) {
254 if( DEBUG_RA >= RA_DEBUG_Coloring) {
229 if (!Node->hasColor() ) {
230 if (DEBUG_RA >= RA_DEBUG_Coloring) {
255231 std::cerr << " Node " << Node->getIndex();
256232 std::cerr << " - could not find a color (needs spilling)\n";
257233 }
258234 }
259
260235 }
261236
262237 void RegClass::printIGNodeList() const {