added support for suggesting colors

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@671 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Ruchira Sasanka 2001-09-30 23:16:47 +00:00
parent a5ab9648a8
commit 91442282d8
3 changed files with 736 additions and 392 deletions

View File

@ -11,8 +11,9 @@ void SparcIntRegClass::colorIGNode(IGNode * Node, bool IsColorUsedArr[]) const
{ {
/* Algorithm: /* Algorithm:
Record the color of all neighbors. Record the colors/suggested colors of all neighbors.
If there is a suggested color, try to allocate it
If there is no call interf, try to allocate volatile, then non volatile If there is no call interf, try to allocate volatile, then non volatile
If there is call interf, try to allocate non-volatile. If that fails If there is call interf, try to allocate non-volatile. If that fails
try to allocate a volatile and insert save across calls try to allocate a volatile and insert save across calls
@ -20,22 +21,38 @@ void SparcIntRegClass::colorIGNode(IGNode * Node, bool IsColorUsedArr[]) const
*/ */
LiveRange * LR = Node->getParentLR();
unsigned NumNeighbors = Node->getNumOfNeighbors(); // total # of neighbors unsigned NumNeighbors = Node->getNumOfNeighbors(); // total # of neighbors
for(unsigned n=0; n < NumNeighbors; n++) { // for each neigh for(unsigned n=0; n < NumNeighbors; n++) { // for each neigh
IGNode *NeighIGNode = Node->getAdjIGNode(n); IGNode *NeighIGNode = Node->getAdjIGNode(n);
if( NeighIGNode->hasColor() ) { // if neigh has a color LiveRange *NeighLR = NeighIGNode->getParentLR();
IsColorUsedArr[ NeighIGNode->getColor() ] = true; // record that color
} if( NeighLR->hasColor() ) // if has a color
IsColorUsedArr[ NeighLR->getColor() ] = true; // record that color
else if( NeighLR->hasSuggestedColor() ) // or has a suggest col
IsColorUsedArr[ NeighLR->getSuggestedColor() ] = true;
} }
if( LR->hasSuggestedColor() ) {
if( ! IsColorUsedArr[ LR->getSuggestedColor() ] ) {
LR->setColor( LR->getSuggestedColor() );
return;
}
else { // can't allocate the suggested col
cout << " Coud NOT allocate the suggested color for LR ";
LR->printSet(); cout << endl;
}
}
unsigned SearchStart; // start pos of color in pref-order unsigned SearchStart; // start pos of color in pref-order
bool ColorFound= false; // have we found a color yet? bool ColorFound= false; // have we found a color yet?
//if this Node is between calls //if this Node is between calls
if( Node->getNumOfCallInterferences() == 0) { if( LR->getNumOfCallInterferences() == 0) {
// start with volatiles (we can allocate volatiles safely) // start with volatiles (we can allocate volatiles safely)
SearchStart = SparcIntRegOrder::StartOfAllRegs; SearchStart = SparcIntRegOrder::StartOfAllRegs;
@ -53,11 +70,12 @@ void SparcIntRegClass::colorIGNode(IGNode * Node, bool IsColorUsedArr[]) const
} }
if( ColorFound) if( ColorFound)
Node->setColor(c); // first color found in preffered order LR->setColor(c); // first color found in preffered order
// if color is not found because of call interference // if color is not found because of call interference
// try even finding a volatile color and insert save across calls // try even finding a volatile color and insert save across calls
else if( Node->getNumOfCallInterferences() ) else if( LR->getNumOfCallInterferences() )
{ {
// start from 0 - try to find even a volatile this time // start from 0 - try to find even a volatile this time
SearchStart = SparcIntRegOrder::StartOfAllRegs; SearchStart = SparcIntRegOrder::StartOfAllRegs;
@ -68,21 +86,22 @@ void SparcIntRegClass::colorIGNode(IGNode * Node, bool IsColorUsedArr[]) const
} }
if( ColorFound) { if( ColorFound) {
Node->setColor(c); LR->setColor(c);
// since LR span across calls, must save across calls // since LR span across calls, must save across calls
Node->markForSaveAcrossCalls(); LR->markForSaveAcrossCalls();
} }
} }
// If we couldn't find a color regardless of call interference - i.e., we // If we couldn't find a color regardless of call interference - i.e., we
// don't have either a volatile or non-volatile color left // don't have either a volatile or non-volatile color left
if( !ColorFound ) if( !ColorFound )
Node->markForSpill(); // no color found - must spill LR->markForSpill(); // no color found - must spill
if( DEBUG_RA) if( DEBUG_RA)
UltraSparcRegInfo::printReg( Node->getParentLR() ); UltraSparcRegInfo::printReg( LR );
} }
@ -98,7 +117,8 @@ void SparcIntRegClass::colorIGNode(IGNode * Node, bool IsColorUsedArr[]) const
// find the first available color in the range [Start,End] depending on the // find the first available color in the range [Start,End] depending on the
// type of the Node (i.e., float/double) // type of the Node (i.e., float/double)
int SparcFloatRegClass::findFloatColor(const IGNode *const Node, unsigned Start, int SparcFloatRegClass::findFloatColor(const LiveRange *const LR,
unsigned Start,
unsigned End, unsigned End,
bool IsColorUsedArr[] ) const bool IsColorUsedArr[] ) const
{ {
@ -106,7 +126,7 @@ int SparcFloatRegClass::findFloatColor(const IGNode *const Node, unsigned Start,
bool ColorFound = false; bool ColorFound = false;
unsigned c; unsigned c;
if( Node->getTypeID() == Type::DoubleTyID ) { if( LR->getTypeID() == Type::DoubleTyID ) {
// find first unused color for a double // find first unused color for a double
for( c=Start; c < End ;c+= 2){ for( c=Start; c < End ;c+= 2){
@ -146,28 +166,50 @@ void SparcFloatRegClass::colorIGNode(IGNode * Node,bool IsColorUsedArr[]) const
*/ */
LiveRange * LR = Node->getParentLR();
unsigned NumNeighbors = Node->getNumOfNeighbors(); // total # of neighbors unsigned NumNeighbors = Node->getNumOfNeighbors(); // total # of neighbors
for(unsigned n=0; n < NumNeighbors; n++) { // for each neigh for(unsigned n=0; n < NumNeighbors; n++) { // for each neigh
IGNode *NeighIGNode = Node->getAdjIGNode(n); IGNode *NeighIGNode = Node->getAdjIGNode(n);
if( NeighIGNode->hasColor() ) { // if neigh has a color LiveRange *NeighLR = NeighIGNode->getParentLR();
IsColorUsedArr[ NeighIGNode->getColor() ] = true; // record that color
if( NeighIGNode->getTypeID() == Type::DoubleTyID ) if( NeighLR->hasColor() ) { // if neigh has a color
IsColorUsedArr[ (NeighIGNode->getColor()) + 1 ] = true; IsColorUsedArr[ NeighLR->getColor() ] = true; // record that color
if( NeighLR->getTypeID() == Type::DoubleTyID )
IsColorUsedArr[ (NeighLR->getColor()) + 1 ] = true;
}
else if( NeighLR->hasSuggestedColor() ) { // if neigh has sugg color
IsColorUsedArr[ NeighLR->getSuggestedColor() ] = true;
if( NeighLR->getTypeID() == Type::DoubleTyID )
IsColorUsedArr[ (NeighLR->getSuggestedColor()) + 1 ] = true;
}
}
if( LR->hasSuggestedColor() ) {
if( ! IsColorUsedArr[ LR->getSuggestedColor() ] ) {
LR->setColor( LR->getSuggestedColor() );
return;
}
else { // can't allocate the suggested col
cout << " Coud NOT allocate the suggested color for LR ";
LR->printSet(); cout << endl;
} }
} }
int ColorFound = -1; // have we found a color yet? int ColorFound = -1; // have we found a color yet?
unsigned NumOfCallInterf = Node->getNumOfCallInterferences(); unsigned NumOfCallInterf = LR->getNumOfCallInterferences();
// if value is a double - search the double only reigon (f32 - f63) // if value is a double - search the double only reigon (f32 - f63)
if( Node->getTypeID() == Type::DoubleTyID ) if( LR->getTypeID() == Type::DoubleTyID )
ColorFound = findFloatColor( Node, 32, 64, IsColorUsedArr ); ColorFound = findFloatColor( LR, 32, 64, IsColorUsedArr );
if( ColorFound >= 0 ) { if( ColorFound >= 0 ) {
Node->setColor(ColorFound); LR->setColor(ColorFound);
if( DEBUG_RA) UltraSparcRegInfo::printReg( Node->getParentLR() ); if( DEBUG_RA) UltraSparcRegInfo::printReg( LR );
return; return;
} }
@ -185,38 +227,42 @@ void SparcFloatRegClass::colorIGNode(IGNode * Node,bool IsColorUsedArr[]) const
SearchStart = SparcFloatRegOrder::StartOfNonVolatileRegs; SearchStart = SparcFloatRegOrder::StartOfNonVolatileRegs;
} }
ColorFound = findFloatColor( Node, SearchStart, 32, IsColorUsedArr ); ColorFound = findFloatColor( LR, SearchStart, 32, IsColorUsedArr );
} }
if( ColorFound >= 0 ) { if( ColorFound >= 0 ) {
Node->setColor(ColorFound); LR->setColor(ColorFound);
if( DEBUG_RA) UltraSparcRegInfo::printReg( Node->getParentLR() ); if( DEBUG_RA) UltraSparcRegInfo::printReg( LR );
return; return;
} }
else if( NumOfCallInterf ) { else if( NumOfCallInterf ) {
// We are here because there is a call interference and no non-volatile // We are here because there is a call interference and no non-volatile
// color could be found. // color could be found.
// Now try to allocate even a volatile color // Now try to allocate even a volatile color
ColorFound = findFloatColor( Node, SparcFloatRegOrder::StartOfAllRegs, ColorFound = findFloatColor( LR, SparcFloatRegOrder::StartOfAllRegs,
SparcFloatRegOrder::StartOfNonVolatileRegs, SparcFloatRegOrder::StartOfNonVolatileRegs,
IsColorUsedArr); IsColorUsedArr);
} }
if( ColorFound >= 0 ) { if( ColorFound >= 0 ) {
Node->setColor(ColorFound); // first color found in preffered order LR->setColor(ColorFound); // first color found in preffered order
Node->markForSaveAcrossCalls(); LR->markForSaveAcrossCalls();
if( DEBUG_RA) UltraSparcRegInfo::printReg( Node->getParentLR() ); if( DEBUG_RA) UltraSparcRegInfo::printReg( LR );
return; return;
} }
else {
Node->markForSpill(); // no color found - must spill // we are here because no color could be found
if( DEBUG_RA) UltraSparcRegInfo::printReg( Node->getParentLR() );
} LR->markForSpill(); // no color found - must spill
if( DEBUG_RA) UltraSparcRegInfo::printReg( LR );
} }

View File

@ -19,11 +19,11 @@
// Int register names in same order as enum in class SparcIntRegOrder // Int register names in same order as enum in class SparcIntRegOrder
static string const IntRegNames[] = static string const IntRegNames[] =
{ "g1", "g2", "g3", "g4", "g5", "g6", "g7", { "g1", "g2", "g3", "g4", "g5",
"o0", "o1", "o2", "o3", "o4", "o5", "o7", "o0", "o1", "o2", "o3", "o4", "o5", "o7",
"l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7", "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7",
"i0", "i1", "i2", "i3", "i4", "i5", "i0", "i1", "i2", "i3", "i4", "i5", "i7",
"g0", "i6", "i7", "o6" }; "g0", "g6", "g7", "i6", "o6" };
@ -36,7 +36,7 @@ class SparcIntRegOrder{
// --- following colors are volatile across function calls // --- following colors are volatile across function calls
// %g0 can't be used for coloring - always 0 // %g0 can't be used for coloring - always 0
g1, g2, g3, g4, g5, g6, g7, //%g1-%g7 g1, g2, g3, g4, g5, //%g1-%g5 (g6-7 are reserved for system)
o0, o1, o2, o3, o4, o5, o7, // %o0-%o5, o0, o1, o2, o3, o4, o5, o7, // %o0-%o5,
// %o6 is sp, // %o6 is sp,
@ -45,17 +45,17 @@ class SparcIntRegOrder{
// --- following colors are NON-volatile across function calls // --- following colors are NON-volatile across function calls
l0, l1, l2, l3, l4, l5, l6, l7, // %l0-%l7 l0, l1, l2, l3, l4, l5, l6, l7, // %l0-%l7
i0, i1, i2, i3, i4, i5, // %i0-%i5: i's need not be preserved i0, i1, i2, i3, i4, i5, i7, // %i0-%i5: i's need not be preserved
// %i6 is the fp - so not allocated // %i6 is the fp - so not allocated
// %i7 is the ret address - can be used if saved // %i7 is the ret address by convention - can be used for others
// max # of colors reg coloring can allocate (NumOfAvailRegs) // max # of colors reg coloring can allocate (NumOfAvailRegs)
// --- following colors are not available for allocation within this phase // --- following colors are not available for allocation within this phase
// --- but can appear for pre-colored ranges // --- but can appear for pre-colored ranges
g0, i6, i7, o6 g0, g6, g7, i6, o6
@ -130,7 +130,7 @@ class SparcFloatRegOrder{
static unsigned int const NumOfAvailRegs = 32; static unsigned int const NumOfAvailRegs = 32;
static unsigned int const NumOfAllRegs = 64; static unsigned int const NumOfAllRegs = 64;
static unsigned int const StartOfNonVolatileRegs = f6; static unsigned int const StartOfNonVolatileRegs = f32;
static unsigned int const StartOfAllRegs = f0; static unsigned int const StartOfAllRegs = f0;
@ -149,7 +149,7 @@ class SparcFloatRegClass : public MachineRegClassInfo
{ {
private: private:
int findFloatColor(const IGNode *const Node, unsigned Start, int findFloatColor(const LiveRange *const LR, unsigned Start,
unsigned End, bool IsColorUsedArr[] ) const; unsigned End, bool IsColorUsedArr[] ) const;
public: public:

File diff suppressed because it is too large Load Diff