diff options
Diffstat (limited to 'llvm/lib/Target/Sparc/SparcRegClassInfo.cpp')
| -rw-r--r-- | llvm/lib/Target/Sparc/SparcRegClassInfo.cpp | 151 |
1 files changed, 73 insertions, 78 deletions
diff --git a/llvm/lib/Target/Sparc/SparcRegClassInfo.cpp b/llvm/lib/Target/Sparc/SparcRegClassInfo.cpp index f79dd5817bb..6b39d61f5e1 100644 --- a/llvm/lib/Target/Sparc/SparcRegClassInfo.cpp +++ b/llvm/lib/Target/Sparc/SparcRegClassInfo.cpp @@ -4,23 +4,20 @@ #include "llvm/Target/Sparc.h" //----------------------------------------------------------------------------- -// Int Register Class +// 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. +// //----------------------------------------------------------------------------- - void SparcIntRegClass::colorIGNode(IGNode * Node, bool IsColorUsedArr[]) const { - - /* 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. - - */ - LiveRange * LR = Node->getParentLR(); unsigned NumNeighbors = Node->getNumOfNeighbors(); // total # of neighbors @@ -37,7 +34,6 @@ void SparcIntRegClass::colorIGNode(IGNode * Node, bool IsColorUsedArr[]) const if( NeighLR-> isSuggestedColorUsable() ) IsColorUsedArr[ NeighLR->getSuggestedColor() ] = true; } - } if( DEBUG_RA ) { @@ -49,8 +45,6 @@ void SparcIntRegClass::colorIGNode(IGNode * Node, bool IsColorUsedArr[]) const unsigned SugCol = LR->getSuggestedColor(); - // cout << "\n -Has sug color: " << SugCol; - if( ! IsColorUsedArr[ SugCol ] ) { if( LR->isSuggestedColorUsable() ) { @@ -102,6 +96,7 @@ void SparcIntRegClass::colorIGNode(IGNode * Node, bool IsColorUsedArr[]) const // if color is not found because of call interference // try even finding a volatile color and insert save across calls + // else if( LR->isCallInterference() ) { // start from 0 - try to find even a volatile this time @@ -116,16 +111,16 @@ void SparcIntRegClass::colorIGNode(IGNode * Node, bool IsColorUsedArr[]) const LR->setColor(c); // get the live range corresponding to live var // since LR span across calls, must save across calls + // LR->markForSaveAcrossCalls(); - if(DEBUG_RA) cout << "\n Colored after SECOND search with col " << c ; } - } // 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 ) LR->markForSpill(); // no color found - must spill @@ -141,61 +136,23 @@ void SparcIntRegClass::colorIGNode(IGNode * Node, bool IsColorUsedArr[]) const //----------------------------------------------------------------------------- -// Float Register Class -//----------------------------------------------------------------------------- - -// 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 LiveRange *const LR, - unsigned Start, - unsigned End, - bool IsColorUsedArr[] ) const -{ - - bool ColorFound = false; - unsigned c; - - if( LR->getTypeID() == Type::DoubleTyID ) { - - // find first unused color for a double - for( c=Start; c < End ;c+= 2){ - if( ! IsColorUsedArr[ c ] && ! IsColorUsedArr[ c+1 ]) - { ColorFound=true; break; } - } - - } else { - - // find first unused color for a single - for( c=Start; c < End; c++) { - if( ! IsColorUsedArr[ c ] ) { ColorFound=true; break; } - } - } - - if( ColorFound ) return c; - else return -1; -} - - - - - +// 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 +// +//---------------------------------------------------------------------------- void SparcFloatRegClass::colorIGNode(IGNode * Node,bool IsColorUsedArr[]) const { - /* 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 - */ - - LiveRange * LR = Node->getParentLR(); unsigned NumNeighbors = Node->getNumOfNeighbors(); // total # of neighbors @@ -245,17 +202,24 @@ void SparcFloatRegClass::colorIGNode(IGNode * Node,bool IsColorUsedArr[]) const bool isCallInterf = LR->isCallInterference(); // if value is a double - search the double only reigon (f32 - f63) + // 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 + // if( LR->getTypeID() == Type::DoubleTyID ) ColorFound = findFloatColor( LR, 32, 64, IsColorUsedArr ); - if( ColorFound >= 0 ) { + if( ColorFound >= 0 ) { // if we could find a color LR->setColor(ColorFound); if( DEBUG_RA) UltraSparcRegInfo::printReg( LR ); return; } + else { - else { // the above fails or LR is single precision + // 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 unsigned SearchStart; // start pos of color in pref-order @@ -270,16 +234,15 @@ void SparcFloatRegClass::colorIGNode(IGNode * Node,bool IsColorUsedArr[]) const } ColorFound = findFloatColor( LR, SearchStart, 32, IsColorUsedArr ); - } - if( ColorFound >= 0 ) { + + + if( ColorFound >= 0 ) { // if we could find a color LR->setColor(ColorFound); if( DEBUG_RA) UltraSparcRegInfo::printReg( LR ); return; } - - else if( isCallInterf ) { // We are here because there is a call interference and no non-volatile @@ -306,11 +269,43 @@ void SparcFloatRegClass::colorIGNode(IGNode * Node,bool IsColorUsedArr[]) const LR->markForSpill(); // no color found - must spill if( DEBUG_RA) UltraSparcRegInfo::printReg( LR ); - } +//----------------------------------------------------------------------------- +// 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) +//----------------------------------------------------------------------------- +int SparcFloatRegClass::findFloatColor(const LiveRange *const LR, + unsigned Start, + unsigned End, + bool IsColorUsedArr[] ) const { + + bool ColorFound = false; + unsigned c; + + if( LR->getTypeID() == Type::DoubleTyID ) { + + // find first unused color for a double + for( c=Start; c < End ;c+= 2){ + if( ! IsColorUsedArr[ c ] && ! IsColorUsedArr[ c+1 ]) + { ColorFound=true; break; } + } + + } else { + + // find first unused color for a single + for( c=Start; c < End; c++) { + if( ! IsColorUsedArr[ c ] ) { ColorFound=true; break; } + } + } + + if( ColorFound ) return c; + else return -1; +} + |

