forked from OSchip/llvm-project
parent
e3b9faddad
commit
5867c7ae80
|
@ -11,31 +11,48 @@ void SparcIntRegClass::colorIGNode(IGNode * Node, bool IsColorUsedArr[]) const
|
|||
{
|
||||
|
||||
/* Algorithm:
|
||||
Record the color of all neighbors.
|
||||
Record the colors/suggested colors of all neighbors.
|
||||
|
||||
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 a suggested color, try to allocate it
|
||||
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
|
||||
try to allocate a volatile and insert save across calls
|
||||
If both above fail, spill.
|
||||
If both above fail, spill.
|
||||
|
||||
*/
|
||||
|
||||
LiveRange * LR = Node->getParentLR();
|
||||
unsigned NumNeighbors = Node->getNumOfNeighbors(); // total # of neighbors
|
||||
|
||||
for(unsigned n=0; n < NumNeighbors; n++) { // for each neigh
|
||||
IGNode *NeighIGNode = Node->getAdjIGNode(n);
|
||||
if( NeighIGNode->hasColor() ) { // if neigh has a color
|
||||
IsColorUsedArr[ NeighIGNode->getColor() ] = true; // record that color
|
||||
}
|
||||
LiveRange *NeighLR = NeighIGNode->getParentLR();
|
||||
|
||||
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
|
||||
bool ColorFound= false; // have we found a color yet?
|
||||
|
||||
//if this Node is between calls
|
||||
if( Node->getNumOfCallInterferences() == 0) {
|
||||
if( LR->getNumOfCallInterferences() == 0) {
|
||||
|
||||
// start with volatiles (we can allocate volatiles safely)
|
||||
SearchStart = SparcIntRegOrder::StartOfAllRegs;
|
||||
|
@ -53,11 +70,12 @@ void SparcIntRegClass::colorIGNode(IGNode * Node, bool IsColorUsedArr[]) const
|
|||
}
|
||||
|
||||
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
|
||||
// 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
|
||||
SearchStart = SparcIntRegOrder::StartOfAllRegs;
|
||||
|
@ -68,21 +86,22 @@ void SparcIntRegClass::colorIGNode(IGNode * Node, bool IsColorUsedArr[]) const
|
|||
}
|
||||
|
||||
if( ColorFound) {
|
||||
Node->setColor(c);
|
||||
LR->setColor(c);
|
||||
// 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
|
||||
// don't have either a volatile or non-volatile color left
|
||||
if( !ColorFound )
|
||||
Node->markForSpill(); // no color found - must spill
|
||||
LR->markForSpill(); // no color found - must spill
|
||||
|
||||
|
||||
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
|
||||
// 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,
|
||||
bool IsColorUsedArr[] ) const
|
||||
{
|
||||
|
@ -106,7 +126,7 @@ int SparcFloatRegClass::findFloatColor(const IGNode *const Node, unsigned Start,
|
|||
bool ColorFound = false;
|
||||
unsigned c;
|
||||
|
||||
if( Node->getTypeID() == Type::DoubleTyID ) {
|
||||
if( LR->getTypeID() == Type::DoubleTyID ) {
|
||||
|
||||
// find first unused color for a double
|
||||
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
|
||||
|
||||
for(unsigned n=0; n < NumNeighbors; n++) { // for each neigh
|
||||
IGNode *NeighIGNode = Node->getAdjIGNode(n);
|
||||
if( NeighIGNode->hasColor() ) { // if neigh has a color
|
||||
IsColorUsedArr[ NeighIGNode->getColor() ] = true; // record that color
|
||||
if( NeighIGNode->getTypeID() == Type::DoubleTyID )
|
||||
IsColorUsedArr[ (NeighIGNode->getColor()) + 1 ] = true;
|
||||
LiveRange *NeighLR = NeighIGNode->getParentLR();
|
||||
|
||||
if( NeighLR->hasColor() ) { // if neigh has a color
|
||||
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?
|
||||
unsigned NumOfCallInterf = Node->getNumOfCallInterferences();
|
||||
unsigned NumOfCallInterf = LR->getNumOfCallInterferences();
|
||||
|
||||
// if value is a double - search the double only reigon (f32 - f63)
|
||||
if( Node->getTypeID() == Type::DoubleTyID )
|
||||
ColorFound = findFloatColor( Node, 32, 64, IsColorUsedArr );
|
||||
if( LR->getTypeID() == Type::DoubleTyID )
|
||||
ColorFound = findFloatColor( LR, 32, 64, IsColorUsedArr );
|
||||
|
||||
|
||||
if( ColorFound >= 0 ) {
|
||||
Node->setColor(ColorFound);
|
||||
if( DEBUG_RA) UltraSparcRegInfo::printReg( Node->getParentLR() );
|
||||
LR->setColor(ColorFound);
|
||||
if( DEBUG_RA) UltraSparcRegInfo::printReg( LR );
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -185,38 +227,42 @@ void SparcFloatRegClass::colorIGNode(IGNode * Node,bool IsColorUsedArr[]) const
|
|||
SearchStart = SparcFloatRegOrder::StartOfNonVolatileRegs;
|
||||
}
|
||||
|
||||
ColorFound = findFloatColor( Node, SearchStart, 32, IsColorUsedArr );
|
||||
ColorFound = findFloatColor( LR, SearchStart, 32, IsColorUsedArr );
|
||||
|
||||
}
|
||||
|
||||
if( ColorFound >= 0 ) {
|
||||
Node->setColor(ColorFound);
|
||||
if( DEBUG_RA) UltraSparcRegInfo::printReg( Node->getParentLR() );
|
||||
LR->setColor(ColorFound);
|
||||
if( DEBUG_RA) UltraSparcRegInfo::printReg( LR );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
else if( NumOfCallInterf ) {
|
||||
|
||||
// We are here because there is a call interference and no non-volatile
|
||||
// color could be found.
|
||||
// Now try to allocate even a volatile color
|
||||
|
||||
ColorFound = findFloatColor( Node, SparcFloatRegOrder::StartOfAllRegs,
|
||||
ColorFound = findFloatColor( LR, SparcFloatRegOrder::StartOfAllRegs,
|
||||
SparcFloatRegOrder::StartOfNonVolatileRegs,
|
||||
IsColorUsedArr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if( ColorFound >= 0 ) {
|
||||
Node->setColor(ColorFound); // first color found in preffered order
|
||||
Node->markForSaveAcrossCalls();
|
||||
if( DEBUG_RA) UltraSparcRegInfo::printReg( Node->getParentLR() );
|
||||
LR->setColor(ColorFound); // first color found in preffered order
|
||||
LR->markForSaveAcrossCalls();
|
||||
if( DEBUG_RA) UltraSparcRegInfo::printReg( LR );
|
||||
return;
|
||||
}
|
||||
|
||||
else {
|
||||
Node->markForSpill(); // no color found - must spill
|
||||
if( DEBUG_RA) UltraSparcRegInfo::printReg( Node->getParentLR() );
|
||||
}
|
||||
|
||||
// we are here because no color could be found
|
||||
|
||||
LR->markForSpill(); // no color found - must spill
|
||||
if( DEBUG_RA) UltraSparcRegInfo::printReg( LR );
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -19,11 +19,11 @@
|
|||
// Int register names in same order as enum in class SparcIntRegOrder
|
||||
|
||||
static string const IntRegNames[] =
|
||||
{ "g1", "g2", "g3", "g4", "g5", "g6", "g7",
|
||||
{ "g1", "g2", "g3", "g4", "g5",
|
||||
"o0", "o1", "o2", "o3", "o4", "o5", "o7",
|
||||
"l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7",
|
||||
"i0", "i1", "i2", "i3", "i4", "i5",
|
||||
"g0", "i6", "i7", "o6" };
|
||||
"i0", "i1", "i2", "i3", "i4", "i5", "i7",
|
||||
"g0", "g6", "g7", "i6", "o6" };
|
||||
|
||||
|
||||
|
||||
|
@ -36,7 +36,7 @@ class SparcIntRegOrder{
|
|||
// --- following colors are volatile across function calls
|
||||
// %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,
|
||||
|
||||
// %o6 is sp,
|
||||
|
@ -45,17 +45,17 @@ class SparcIntRegOrder{
|
|||
// --- following colors are NON-volatile across function calls
|
||||
|
||||
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
|
||||
// %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)
|
||||
|
||||
// --- following colors are not available for allocation within this phase
|
||||
// --- 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 NumOfAllRegs = 64;
|
||||
|
||||
static unsigned int const StartOfNonVolatileRegs = f6;
|
||||
static unsigned int const StartOfNonVolatileRegs = f32;
|
||||
static unsigned int const StartOfAllRegs = f0;
|
||||
|
||||
|
||||
|
@ -149,7 +149,7 @@ class SparcFloatRegClass : public MachineRegClassInfo
|
|||
{
|
||||
private:
|
||||
|
||||
int findFloatColor(const IGNode *const Node, unsigned Start,
|
||||
int findFloatColor(const LiveRange *const LR, unsigned Start,
|
||||
unsigned End, bool IsColorUsedArr[] ) const;
|
||||
|
||||
public:
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue