2002-02-04 05:59:25 +00:00
|
|
|
#include "SparcRegClassInfo.h"
|
2002-01-20 22:54:45 +00:00
|
|
|
#include "llvm/CodeGen/IGNode.h"
|
2001-09-18 22:52:44 +00:00
|
|
|
#include "llvm/Target/Sparc.h"
|
2002-01-20 22:54:45 +00:00
|
|
|
#include <iostream>
|
|
|
|
using std::cerr;
|
2001-09-18 22:52:44 +00:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2002-01-07 19:20:28 +00:00
|
|
|
// Int Register Class - method for coloring a node in the interference graph.
|
|
|
|
//
|
|
|
|
// Algorithm:
|
|
|
|
// 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 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.
|
|
|
|
//
|
2001-09-18 22:52:44 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2002-02-04 05:59:25 +00:00
|
|
|
void SparcIntRegClass::colorIGNode(IGNode * Node, bool IsColorUsedArr[]) const {
|
|
|
|
LiveRange *LR = Node->getParentLR();
|
2001-09-18 22:52:44 +00:00
|
|
|
unsigned NumNeighbors = Node->getNumOfNeighbors(); // total # of neighbors
|
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
for (unsigned n=0; n < NumNeighbors; n++) { // for each neigh
|
2001-09-18 22:52:44 +00:00
|
|
|
IGNode *NeighIGNode = Node->getAdjIGNode(n);
|
2001-09-30 23:16:47 +00:00
|
|
|
LiveRange *NeighLR = NeighIGNode->getParentLR();
|
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
if(NeighLR->hasColor()) // if has a color
|
|
|
|
IsColorUsedArr[NeighLR->getColor()] = true; // record that color
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
else if (NeighLR->hasSuggestedColor()) {
|
2001-10-19 21:41:16 +00:00
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
// if the neighbout can use the suggested color
|
|
|
|
if(NeighLR->isSuggestedColorUsable())
|
|
|
|
IsColorUsedArr[NeighLR->getSuggestedColor()] = true;
|
2001-10-19 21:41:16 +00:00
|
|
|
}
|
2001-09-18 22:52:44 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 17:23:43 +00:00
|
|
|
if( DEBUG_RA ) {
|
2002-01-20 22:54:45 +00:00
|
|
|
cerr << "\nColoring LR [CallInt=" << LR->isCallInterference() <<"]:";
|
2002-02-05 02:52:05 +00:00
|
|
|
printSet(*LR);
|
2001-10-19 17:23:43 +00:00
|
|
|
}
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
if( LR->hasSuggestedColor() ) {
|
2001-10-19 17:23:43 +00:00
|
|
|
|
|
|
|
unsigned SugCol = LR->getSuggestedColor();
|
|
|
|
|
|
|
|
if( ! IsColorUsedArr[ SugCol ] ) {
|
|
|
|
|
2001-10-19 21:41:16 +00:00
|
|
|
if( LR->isSuggestedColorUsable() ) {
|
2001-10-19 17:23:43 +00:00
|
|
|
|
|
|
|
// if the suggested color is volatile, we should use it only if
|
|
|
|
// there are no call interferences. Otherwise, it will get spilled.
|
|
|
|
|
|
|
|
if (DEBUG_RA)
|
2002-01-20 22:54:45 +00:00
|
|
|
cerr << "\n -Coloring with sug color: " << SugCol;
|
2001-10-19 17:23:43 +00:00
|
|
|
|
|
|
|
LR->setColor( LR->getSuggestedColor() );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if(DEBUG_RA)
|
2002-01-20 22:54:45 +00:00
|
|
|
cerr << "\n Couldn't alloc Sug col - LR voloatile & calls interf";
|
2001-10-19 17:23:43 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
}
|
2001-10-18 22:38:52 +00:00
|
|
|
else if ( DEBUG_RA ) { // can't allocate the suggested col
|
2001-10-19 17:23:43 +00:00
|
|
|
cerr << " \n Could NOT allocate the suggested color (already used) ";
|
2002-02-05 02:52:05 +00:00
|
|
|
printSet(*LR); cerr << "\n";
|
2001-09-30 23:16:47 +00:00
|
|
|
}
|
|
|
|
}
|
2001-09-18 22:52:44 +00:00
|
|
|
|
|
|
|
unsigned SearchStart; // start pos of color in pref-order
|
|
|
|
bool ColorFound= false; // have we found a color yet?
|
|
|
|
|
|
|
|
//if this Node is between calls
|
2001-10-19 17:23:43 +00:00
|
|
|
if( ! LR->isCallInterference() ) {
|
2001-09-18 22:52:44 +00:00
|
|
|
|
|
|
|
// start with volatiles (we can allocate volatiles safely)
|
|
|
|
SearchStart = SparcIntRegOrder::StartOfAllRegs;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// start with non volatiles (no non-volatiles)
|
|
|
|
SearchStart = SparcIntRegOrder::StartOfNonVolatileRegs;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned c=0; // color
|
|
|
|
|
|
|
|
// find first unused color
|
|
|
|
for( c=SearchStart; c < SparcIntRegOrder::NumOfAvailRegs; c++) {
|
|
|
|
if( ! IsColorUsedArr[ c ] ) { ColorFound = true; break; }
|
|
|
|
}
|
|
|
|
|
2001-10-19 17:23:43 +00:00
|
|
|
if( ColorFound) {
|
2001-09-30 23:16:47 +00:00
|
|
|
LR->setColor(c); // first color found in preffered order
|
2002-01-20 22:54:45 +00:00
|
|
|
if (DEBUG_RA) cerr << "\n Colored after first search with col " << c ;
|
2001-10-19 17:23:43 +00:00
|
|
|
}
|
2001-09-18 22:52:44 +00:00
|
|
|
|
|
|
|
// if color is not found because of call interference
|
|
|
|
// try even finding a volatile color and insert save across calls
|
2002-01-07 19:20:28 +00:00
|
|
|
//
|
2001-10-19 17:23:43 +00:00
|
|
|
else if( LR->isCallInterference() )
|
2001-09-18 22:52:44 +00:00
|
|
|
{
|
|
|
|
// start from 0 - try to find even a volatile this time
|
|
|
|
SearchStart = SparcIntRegOrder::StartOfAllRegs;
|
|
|
|
|
|
|
|
// find first unused volatile color
|
|
|
|
for(c=SearchStart; c < SparcIntRegOrder::StartOfNonVolatileRegs; c++) {
|
|
|
|
if( ! IsColorUsedArr[ c ] ) { ColorFound = true; break; }
|
|
|
|
}
|
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
if (ColorFound) {
|
2001-10-19 17:23:43 +00:00
|
|
|
LR->setColor(c);
|
|
|
|
// get the live range corresponding to live var
|
|
|
|
// since LR span across calls, must save across calls
|
2002-01-07 19:20:28 +00:00
|
|
|
//
|
2001-10-19 17:23:43 +00:00
|
|
|
LR->markForSaveAcrossCalls();
|
2002-01-20 22:54:45 +00:00
|
|
|
if(DEBUG_RA) cerr << "\n Colored after SECOND search with col " << c ;
|
2001-09-18 22:52:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-09-18 22:52:44 +00:00
|
|
|
// 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
|
2002-01-07 19:20:28 +00:00
|
|
|
//
|
2002-02-04 05:59:25 +00:00
|
|
|
if (!ColorFound)
|
2001-09-30 23:16:47 +00:00
|
|
|
LR->markForSpill(); // no color found - must spill
|
2001-09-18 22:52:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2002-01-07 19:20:28 +00:00
|
|
|
// Float Register Class - method for coloring a node in the interference graph.
|
|
|
|
//
|
|
|
|
// Algorithm:
|
|
|
|
//
|
|
|
|
// If the LR is a double try to allocate f32 - f63
|
|
|
|
// If the above fails or LR is single precision
|
|
|
|
// If the LR does not interfere with a call
|
|
|
|
// start allocating from f0
|
|
|
|
// Else start allocating from f6
|
|
|
|
// If a color is still not found because LR interferes with a call
|
|
|
|
// Search in f0 - f6. If found mark for spill across calls.
|
|
|
|
// If a color is still not fond, mark for spilling
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
2001-09-18 22:52:44 +00:00
|
|
|
void SparcFloatRegClass::colorIGNode(IGNode * Node,bool IsColorUsedArr[]) const
|
|
|
|
{
|
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
LiveRange * LR = Node->getParentLR();
|
2001-09-18 22:52:44 +00:00
|
|
|
unsigned NumNeighbors = Node->getNumOfNeighbors(); // total # of neighbors
|
|
|
|
|
|
|
|
for(unsigned n=0; n < NumNeighbors; n++) { // for each neigh
|
|
|
|
IGNode *NeighIGNode = Node->getAdjIGNode(n);
|
2001-09-30 23:16:47 +00:00
|
|
|
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
|
2001-10-19 21:41:16 +00:00
|
|
|
|
|
|
|
if( NeighLR-> isSuggestedColorUsable() ) {
|
|
|
|
|
|
|
|
// if the neighbout can use the suggested color
|
|
|
|
|
|
|
|
IsColorUsedArr[ NeighLR->getSuggestedColor() ] = true;
|
|
|
|
if( NeighLR->getTypeID() == Type::DoubleTyID )
|
|
|
|
IsColorUsedArr[ (NeighLR->getSuggestedColor()) + 1 ] = true;
|
|
|
|
}
|
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-19 17:23:43 +00:00
|
|
|
// **NOTE: We don't check for call interferences in allocating suggested
|
|
|
|
// color in this class since ALL registers are volatile. If this fact
|
|
|
|
// changes, we should change the following part
|
|
|
|
//- see SparcIntRegClass::colorIGNode()
|
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
if( LR->hasSuggestedColor() ) {
|
|
|
|
if( ! IsColorUsedArr[ LR->getSuggestedColor() ] ) {
|
|
|
|
LR->setColor( LR->getSuggestedColor() );
|
|
|
|
return;
|
2002-02-05 02:52:05 +00:00
|
|
|
} else if (DEBUG_RA) { // can't allocate the suggested col
|
2001-10-15 18:15:27 +00:00
|
|
|
cerr << " Could NOT allocate the suggested color for LR ";
|
2002-02-05 02:52:05 +00:00
|
|
|
printSet(*LR); cerr << "\n";
|
2001-09-18 22:52:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-09-18 22:52:44 +00:00
|
|
|
int ColorFound = -1; // have we found a color yet?
|
2001-10-19 17:23:43 +00:00
|
|
|
bool isCallInterf = LR->isCallInterference();
|
2001-09-18 22:52:44 +00:00
|
|
|
|
|
|
|
// if value is a double - search the double only reigon (f32 - f63)
|
2002-01-07 19:20:28 +00:00
|
|
|
// i.e. we try to allocate f32 - f63 first for doubles since singles
|
|
|
|
// cannot go there. By doing that, we provide more space for singles
|
|
|
|
// in f0 - f31
|
|
|
|
//
|
2001-09-30 23:16:47 +00:00
|
|
|
if( LR->getTypeID() == Type::DoubleTyID )
|
|
|
|
ColorFound = findFloatColor( LR, 32, 64, IsColorUsedArr );
|
2001-09-18 22:52:44 +00:00
|
|
|
|
|
|
|
|
2002-01-07 19:20:28 +00:00
|
|
|
if( ColorFound >= 0 ) { // if we could find a color
|
2001-09-30 23:16:47 +00:00
|
|
|
LR->setColor(ColorFound);
|
2001-09-18 22:52:44 +00:00
|
|
|
return;
|
2002-02-04 05:59:25 +00:00
|
|
|
} else {
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2002-01-07 19:20:28 +00:00
|
|
|
// if we didn't find a color becuase the LR was single precision or
|
|
|
|
// all f32-f63 range is filled, we try to allocate a register from
|
|
|
|
// the f0 - f31 region
|
2001-09-18 22:52:44 +00:00
|
|
|
|
|
|
|
unsigned SearchStart; // start pos of color in pref-order
|
|
|
|
|
|
|
|
//if this Node is between calls (i.e., no call interferences )
|
2001-10-19 17:23:43 +00:00
|
|
|
if( ! isCallInterf ) {
|
2001-09-18 22:52:44 +00:00
|
|
|
// start with volatiles (we can allocate volatiles safely)
|
|
|
|
SearchStart = SparcFloatRegOrder::StartOfAllRegs;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// start with non volatiles (no non-volatiles)
|
|
|
|
SearchStart = SparcFloatRegOrder::StartOfNonVolatileRegs;
|
|
|
|
}
|
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
ColorFound = findFloatColor( LR, SearchStart, 32, IsColorUsedArr );
|
2001-09-18 22:52:44 +00:00
|
|
|
}
|
|
|
|
|
2002-01-07 19:20:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
if( ColorFound >= 0 ) { // if we could find a color
|
2001-09-30 23:16:47 +00:00
|
|
|
LR->setColor(ColorFound);
|
2001-09-18 22:52:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-10-19 17:23:43 +00:00
|
|
|
else if( isCallInterf ) {
|
2001-09-18 22:52:44 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
ColorFound = findFloatColor( LR, SparcFloatRegOrder::StartOfAllRegs,
|
2001-09-18 22:52:44 +00:00
|
|
|
SparcFloatRegOrder::StartOfNonVolatileRegs,
|
|
|
|
IsColorUsedArr);
|
|
|
|
}
|
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
|
|
|
|
|
2001-09-18 22:52:44 +00:00
|
|
|
if( ColorFound >= 0 ) {
|
2001-09-30 23:16:47 +00:00
|
|
|
LR->setColor(ColorFound); // first color found in preffered order
|
|
|
|
LR->markForSaveAcrossCalls();
|
2002-02-04 05:59:25 +00:00
|
|
|
} else {
|
|
|
|
// we are here because no color could be found
|
|
|
|
LR->markForSpill(); // no color found - must spill
|
2001-09-18 22:52:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-07 19:20:28 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Helper method for coloring a node of Float Reg class.
|
|
|
|
// Finds the first available color in the range [Start,End] depending on the
|
|
|
|
// type of the Node (i.e., float/double)
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
int SparcFloatRegClass::findFloatColor(const LiveRange *LR,
|
|
|
|
unsigned Start, unsigned End,
|
|
|
|
bool IsColorUsedArr[] ) const {
|
2002-01-07 19:20:28 +00:00
|
|
|
bool ColorFound = false;
|
|
|
|
unsigned c;
|
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
if (LR->getTypeID() == Type::DoubleTyID) {
|
2002-01-07 19:20:28 +00:00
|
|
|
// find first unused color for a double
|
2002-02-04 05:59:25 +00:00
|
|
|
for (c=Start; c < End ; c+= 2)
|
|
|
|
if (!IsColorUsedArr[c] && !IsColorUsedArr[c+1])
|
|
|
|
return c;
|
2002-01-07 19:20:28 +00:00
|
|
|
} else {
|
|
|
|
// find first unused color for a single
|
2002-02-04 05:59:25 +00:00
|
|
|
for (c = Start; c < End; c++)
|
|
|
|
if (!IsColorUsedArr[c])
|
|
|
|
return c;
|
2002-01-07 19:20:28 +00:00
|
|
|
}
|
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
return -1;
|
2002-01-07 19:20:28 +00:00
|
|
|
}
|