forked from OSchip/llvm-project
* Eliminate `using' directive
* Fix order of #includes * Make code layout more consistent * Eliminate extraneous whitespace and comment-lines llvm-svn: 9433
This commit is contained in:
parent
dc07775d58
commit
88df876012
|
@ -11,12 +11,11 @@
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "RegAllocCommon.h"
|
|
||||||
#include "InterferenceGraph.h"
|
|
||||||
#include "IGNode.h"
|
#include "IGNode.h"
|
||||||
|
#include "InterferenceGraph.h"
|
||||||
|
#include "RegAllocCommon.h"
|
||||||
#include "Support/STLExtras.h"
|
#include "Support/STLExtras.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
using std::cerr;
|
|
||||||
|
|
||||||
// for asserting this IG node is infact in the IGNodeList of this class
|
// for asserting this IG node is infact in the IGNodeList of this class
|
||||||
inline static void assertIGNode(const InterferenceGraph *IG,
|
inline static void assertIGNode(const InterferenceGraph *IG,
|
||||||
|
|
|
@ -11,9 +11,9 @@
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "RegClass.h"
|
|
||||||
#include "RegAllocCommon.h"
|
|
||||||
#include "IGNode.h"
|
#include "IGNode.h"
|
||||||
|
#include "RegAllocCommon.h"
|
||||||
|
#include "RegClass.h"
|
||||||
#include "llvm/Target/TargetRegInfo.h"
|
#include "llvm/Target/TargetRegInfo.h"
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
@ -26,7 +26,7 @@ RegClass::RegClass(const Function *M,
|
||||||
: Meth(M), MRI(_MRI_), MRC(_MRC_),
|
: Meth(M), MRI(_MRI_), MRC(_MRC_),
|
||||||
RegClassID( _MRC_->getRegClassID() ),
|
RegClassID( _MRC_->getRegClassID() ),
|
||||||
IG(this), IGNodeStack() {
|
IG(this), IGNodeStack() {
|
||||||
if( DEBUG_RA >= RA_DEBUG_Interference)
|
if (DEBUG_RA >= RA_DEBUG_Interference)
|
||||||
std::cerr << "Created Reg Class: " << RegClassID << "\n";
|
std::cerr << "Created Reg Class: " << RegClassID << "\n";
|
||||||
|
|
||||||
IsColorUsedArr.resize(MRC->getNumOfAllRegs());
|
IsColorUsedArr.resize(MRC->getNumOfAllRegs());
|
||||||
|
@ -39,23 +39,19 @@ RegClass::RegClass(const Function *M,
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void RegClass::colorAllRegs()
|
void RegClass::colorAllRegs()
|
||||||
{
|
{
|
||||||
if(DEBUG_RA >= RA_DEBUG_Coloring)
|
if (DEBUG_RA >= RA_DEBUG_Coloring)
|
||||||
std::cerr << "Coloring IG of reg class " << RegClassID << " ...\n";
|
std::cerr << "Coloring IG of reg class " << RegClassID << " ...\n";
|
||||||
|
|
||||||
// pre-color IGNodes
|
// pre-color IGNodes
|
||||||
pushAllIGNodes(); // push all IG Nodes
|
pushAllIGNodes(); // push all IG Nodes
|
||||||
|
|
||||||
unsigned int StackSize = IGNodeStack.size();
|
unsigned int StackSize = IGNodeStack.size();
|
||||||
IGNode *CurIGNode;
|
IGNode *CurIGNode;
|
||||||
|
|
||||||
// for all LRs on stack
|
// for all LRs on stack
|
||||||
for( unsigned int IGN=0; IGN < StackSize; IGN++) {
|
for (unsigned int IGN=0; IGN < StackSize; IGN++) {
|
||||||
|
|
||||||
CurIGNode = IGNodeStack.top(); // pop the IGNode on top of stack
|
CurIGNode = IGNodeStack.top(); // pop the IGNode on top of stack
|
||||||
IGNodeStack.pop();
|
IGNodeStack.pop();
|
||||||
colorIGNode (CurIGNode); // color it
|
colorIGNode (CurIGNode); // color it
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,13 +69,13 @@ void RegClass::pushAllIGNodes()
|
||||||
// push non-constrained IGNodes
|
// push non-constrained IGNodes
|
||||||
bool PushedAll = pushUnconstrainedIGNodes();
|
bool PushedAll = pushUnconstrainedIGNodes();
|
||||||
|
|
||||||
if( DEBUG_RA >= RA_DEBUG_Coloring) {
|
if (DEBUG_RA >= RA_DEBUG_Coloring) {
|
||||||
std::cerr << " Puhsed all-unconstrained IGNodes. ";
|
std::cerr << " Puhsed all-unconstrained IGNodes. ";
|
||||||
if( PushedAll ) std::cerr << " No constrained nodes left.";
|
if( PushedAll ) std::cerr << " No constrained nodes left.";
|
||||||
std::cerr << "\n";
|
std::cerr << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if( PushedAll ) // if NO constrained nodes left
|
if (PushedAll) // if NO constrained nodes left
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
@ -89,24 +85,15 @@ void RegClass::pushAllIGNodes()
|
||||||
|
|
||||||
do {
|
do {
|
||||||
//get node with min spill cost
|
//get node with min spill cost
|
||||||
//
|
|
||||||
IGNode *IGNodeSpill = getIGNodeWithMinSpillCost();
|
IGNode *IGNodeSpill = getIGNodeWithMinSpillCost();
|
||||||
|
|
||||||
// push that node on to stack
|
// push that node on to stack
|
||||||
//
|
|
||||||
IGNodeStack.push(IGNodeSpill);
|
IGNodeStack.push(IGNodeSpill);
|
||||||
|
|
||||||
// set its OnStack flag and decrement degree of neighs
|
// set its OnStack flag and decrement degree of neighs
|
||||||
//
|
|
||||||
IGNodeSpill->pushOnStack();
|
IGNodeSpill->pushOnStack();
|
||||||
|
|
||||||
// now push NON-constrained ones, if any
|
// now push NON-constrained ones, if any
|
||||||
//
|
|
||||||
NeedMoreSpills = !pushUnconstrainedIGNodes();
|
NeedMoreSpills = !pushUnconstrainedIGNodes();
|
||||||
|
|
||||||
if (DEBUG_RA >= RA_DEBUG_Coloring)
|
if (DEBUG_RA >= RA_DEBUG_Coloring)
|
||||||
std::cerr << "\nConstrained IG Node found !@!" << IGNodeSpill->getIndex();
|
std::cerr << "\nConstrained IG Node found !@!" << IGNodeSpill->getIndex();
|
||||||
|
|
||||||
} while(NeedMoreSpills); // repeat until we have pushed all
|
} while(NeedMoreSpills); // repeat until we have pushed all
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -127,21 +114,21 @@ bool RegClass::pushUnconstrainedIGNodes()
|
||||||
bool pushedall = true;
|
bool pushedall = true;
|
||||||
|
|
||||||
// a pass over IGNodeList
|
// a pass over IGNodeList
|
||||||
for( unsigned i =0; i < IGNodeListSize; i++) {
|
for (unsigned i =0; i < IGNodeListSize; i++) {
|
||||||
|
|
||||||
// get IGNode i from IGNodeList
|
// get IGNode i from IGNodeList
|
||||||
IGNode *IGNode = IG.getIGNodeList()[i];
|
IGNode *IGNode = IG.getIGNodeList()[i];
|
||||||
|
|
||||||
if( !IGNode ) // can be null due to merging
|
if (!IGNode ) // can be null due to merging
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// if already pushed on stack, continue. This can happen since this
|
// if already pushed on stack, continue. This can happen since this
|
||||||
// method can be called repeatedly until all constrained nodes are
|
// method can be called repeatedly until all constrained nodes are
|
||||||
// pushed
|
// pushed
|
||||||
if( IGNode->isOnStack() )
|
if (IGNode->isOnStack() )
|
||||||
continue;
|
continue;
|
||||||
// if the degree of IGNode is lower
|
// if the degree of IGNode is lower
|
||||||
if( (unsigned) IGNode->getCurDegree() < MRC->getNumOfAvailRegs()) {
|
if ((unsigned) IGNode->getCurDegree() < MRC->getNumOfAvailRegs()) {
|
||||||
IGNodeStack.push( IGNode ); // push IGNode on to the stack
|
IGNodeStack.push( IGNode ); // push IGNode on to the stack
|
||||||
IGNode->pushOnStack(); // set OnStack and dec deg of neighs
|
IGNode->pushOnStack(); // set OnStack and dec deg of neighs
|
||||||
|
|
||||||
|
@ -163,9 +150,7 @@ bool RegClass::pushUnconstrainedIGNodes()
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
// Get the IGNode with the minimum spill cost
|
// Get the IGNode with the minimum spill cost
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
IGNode * RegClass::getIGNodeWithMinSpillCost()
|
IGNode * RegClass::getIGNodeWithMinSpillCost() {
|
||||||
{
|
|
||||||
|
|
||||||
unsigned int IGNodeListSize = IG.getIGNodeList().size();
|
unsigned int IGNodeListSize = IG.getIGNodeList().size();
|
||||||
double MinSpillCost = 0;
|
double MinSpillCost = 0;
|
||||||
IGNode *MinCostIGNode = NULL;
|
IGNode *MinCostIGNode = NULL;
|
||||||
|
@ -173,45 +158,37 @@ IGNode * RegClass::getIGNodeWithMinSpillCost()
|
||||||
|
|
||||||
// pass over IGNodeList to find the IGNode with minimum spill cost
|
// pass over IGNodeList to find the IGNode with minimum spill cost
|
||||||
// among all IGNodes that are not yet pushed on to the stack
|
// among all IGNodes that are not yet pushed on to the stack
|
||||||
//
|
for (unsigned int i =0; i < IGNodeListSize; i++) {
|
||||||
for( unsigned int i =0; i < IGNodeListSize; i++) {
|
|
||||||
IGNode *IGNode = IG.getIGNodeList()[i];
|
IGNode *IGNode = IG.getIGNodeList()[i];
|
||||||
|
|
||||||
if( ! IGNode ) // can be null due to merging
|
if (!IGNode) // can be null due to merging
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if( ! IGNode->isOnStack() ) {
|
if (!IGNode->isOnStack()) {
|
||||||
|
|
||||||
double SpillCost = (double) IGNode->getParentLR()->getSpillCost() /
|
double SpillCost = (double) IGNode->getParentLR()->getSpillCost() /
|
||||||
(double) (IGNode->getCurDegree() + 1);
|
(double) (IGNode->getCurDegree() + 1);
|
||||||
|
|
||||||
if( isFirstNode ) { // for the first IG node
|
if (isFirstNode) { // for the first IG node
|
||||||
MinSpillCost = SpillCost;
|
MinSpillCost = SpillCost;
|
||||||
MinCostIGNode = IGNode;
|
MinCostIGNode = IGNode;
|
||||||
isFirstNode = false;
|
isFirstNode = false;
|
||||||
}
|
} else if (MinSpillCost > SpillCost) {
|
||||||
|
|
||||||
else if( MinSpillCost > SpillCost) {
|
|
||||||
MinSpillCost = SpillCost;
|
MinSpillCost = SpillCost;
|
||||||
MinCostIGNode = IGNode;
|
MinCostIGNode = IGNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert( MinCostIGNode && "No IGNode to spill");
|
assert (MinCostIGNode && "No IGNode to spill");
|
||||||
return MinCostIGNode;
|
return MinCostIGNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
// Color the IGNode using the machine specific code.
|
// Color the IGNode using the machine specific code.
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void RegClass::colorIGNode(IGNode *const Node)
|
void RegClass::colorIGNode(IGNode *const Node) {
|
||||||
{
|
if (! Node->hasColor()) { // not colored as an arg etc.
|
||||||
|
|
||||||
if( ! Node->hasColor() ) { // not colored as an arg etc.
|
|
||||||
|
|
||||||
// init all elements of to IsColorUsedAr false;
|
// init all elements of to IsColorUsedAr false;
|
||||||
clearColorsUsed();
|
clearColorsUsed();
|
||||||
|
@ -242,22 +219,20 @@ void RegClass::colorIGNode(IGNode *const Node)
|
||||||
// call the target specific code for coloring
|
// call the target specific code for coloring
|
||||||
//
|
//
|
||||||
MRC->colorIGNode(Node, IsColorUsedArr);
|
MRC->colorIGNode(Node, IsColorUsedArr);
|
||||||
}
|
} else {
|
||||||
else {
|
if (DEBUG_RA >= RA_DEBUG_Coloring) {
|
||||||
if( DEBUG_RA >= RA_DEBUG_Coloring) {
|
|
||||||
std::cerr << " Node " << Node->getIndex();
|
std::cerr << " Node " << Node->getIndex();
|
||||||
std::cerr << " already colored with color " << Node->getColor() << "\n";
|
std::cerr << " already colored with color " << Node->getColor() << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if( !Node->hasColor() ) {
|
if (!Node->hasColor() ) {
|
||||||
if( DEBUG_RA >= RA_DEBUG_Coloring) {
|
if (DEBUG_RA >= RA_DEBUG_Coloring) {
|
||||||
std::cerr << " Node " << Node->getIndex();
|
std::cerr << " Node " << Node->getIndex();
|
||||||
std::cerr << " - could not find a color (needs spilling)\n";
|
std::cerr << " - could not find a color (needs spilling)\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegClass::printIGNodeList() const {
|
void RegClass::printIGNodeList() const {
|
||||||
|
|
Loading…
Reference in New Issue