Remove separate vector of implicit refs from MachineInstr, and
[oota-llvm.git] / lib / Target / SparcV9 / SparcV9RegClassInfo.cpp
index 96ff39ef046ffcebb6bc358fb6512d76482ad572..4d35f5d3e2b4d8fb047520c84e51c15df2df736a 100644 (file)
@@ -1,8 +1,15 @@
+//===-- SparcRegClassInfo.cpp - Register class def'ns for Sparc -----------===//
+//
+//  This file defines the register classes used by the Sparc target description.
+//
+//===----------------------------------------------------------------------===//
+
 #include "SparcRegClassInfo.h"
-#include "llvm/CodeGen/IGNode.h"
+#include "llvm/CodeGen/RegAllocCommon.h"
 #include "llvm/Target/Sparc.h"
-#include <iostream>
+#include "llvm/Type.h"
 using std::cerr;
+using std::vector;
 
 //-----------------------------------------------------------------------------
 // Int Register Class - method for coloring a node in the interference graph.
@@ -17,24 +24,8 @@ using std::cerr;
 //     If both above fail, spill.
 //  
 //-----------------------------------------------------------------------------
-void SparcIntRegClass::colorIGNode(IGNode * Node, bool IsColorUsedArr[]) const {
+void SparcIntRegClass::colorIGNode(IGNode * Node, vector<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);
-    LiveRange *NeighLR = NeighIGNode->getParentLR();
-
-    if(NeighLR->hasColor())                        // if has a color
-      IsColorUsedArr[NeighLR->getColor()] = true; // record that color
-
-    else if (NeighLR->hasSuggestedColor()) {
-
-      // if the neighbout can use the suggested color 
-      if(NeighLR->isSuggestedColorUsable()) 
-        IsColorUsedArr[NeighLR->getSuggestedColor()] = true; 
-    }    
-  }
 
   if( DEBUG_RA ) {
     cerr << "\nColoring LR [CallInt=" << LR->isCallInterference() <<"]:"; 
@@ -45,7 +36,7 @@ void SparcIntRegClass::colorIGNode(IGNode * Node, bool IsColorUsedArr[]) const {
 
     unsigned SugCol = LR->getSuggestedColor();
 
-    if( ! IsColorUsedArr[ SugCol ] ) {
+    if (!IsColorUsedArr[SugCol]) {
 
       if( LR->isSuggestedColorUsable()  ) {
 
@@ -75,18 +66,18 @@ void SparcIntRegClass::colorIGNode(IGNode * Node, bool IsColorUsedArr[]) const {
   if( ! LR->isCallInterference() ) { 
 
     // start with volatiles (we can  allocate volatiles safely)
-    SearchStart = SparcIntRegOrder::StartOfAllRegs;  
+    SearchStart = SparcIntRegClass::StartOfAllRegs;  
   }
   else {           
     // start with non volatiles (no non-volatiles)
-    SearchStart =  SparcIntRegOrder::StartOfNonVolatileRegs;  
+    SearchStart =  SparcIntRegClass::StartOfNonVolatileRegs;  
   }
 
   unsigned c=0;                         // color
  
   // find first unused color
-  for( c=SearchStart; c < SparcIntRegOrder::NumOfAvailRegs; c++) { 
-    if( ! IsColorUsedArr[ c ] ) { ColorFound = true; break; }
+  for( c=SearchStart; c < SparcIntRegClass::NumOfAvailRegs; c++) { 
+    if(!IsColorUsedArr[c] ) { ColorFound = true; break; }
   }
 
   if( ColorFound) {
@@ -100,10 +91,10 @@ void SparcIntRegClass::colorIGNode(IGNode * Node, bool IsColorUsedArr[]) const {
   else if( LR->isCallInterference() ) 
   { 
     // start from 0 - try to find even a volatile this time
-    SearchStart = SparcIntRegOrder::StartOfAllRegs;  
+    SearchStart = SparcIntRegClass::StartOfAllRegs;  
 
     // find first unused volatile color
-    for(c=SearchStart; c < SparcIntRegOrder::StartOfNonVolatileRegs; c++) { 
+    for(c=SearchStart; c < SparcIntRegClass::StartOfNonVolatileRegs; c++) { 
       if( ! IsColorUsedArr[ c ] ) { ColorFound = true; break; }
     }
 
@@ -145,42 +136,38 @@ void SparcIntRegClass::colorIGNode(IGNode * Node, bool IsColorUsedArr[]) const {
 //     If a color is still not fond, mark for spilling
 //
 //----------------------------------------------------------------------------
-void SparcFloatRegClass::colorIGNode(IGNode * Node,bool IsColorUsedArr[]) const
-{
+void SparcFloatRegClass::colorIGNode(IGNode * Node,
+                                     vector<bool> &IsColorUsedArr) const{
+  LiveRange *LR = Node->getParentLR();
 
-  LiveRange * LR = Node->getParentLR();
+  // Mark the second color for double-precision registers:
+  // This is UGLY and should be merged into nearly identical code
+  // in RegClass::colorIGNode that handles the first color.
+  // 
   unsigned NumNeighbors =  Node->getNumOfNeighbors();   // total # of neighbors
-
   for(unsigned n=0; n < NumNeighbors; n++) {            // for each neigh 
     IGNode *NeighIGNode = Node->getAdjIGNode(n);
     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
-
-       if( NeighLR-> isSuggestedColorUsable() ) {
-
-         // if the neighbout can use the suggested color 
-         
+    
+    if( NeighLR->hasColor() &&
+       NeighLR->getType() == Type::DoubleTy) {
+      IsColorUsedArr[ (NeighLR->getColor()) + 1 ] = true;  
+      
+    } else if (NeighLR->hasSuggestedColor() &&
+               NeighLR-> isSuggestedColorUsable() ) {
+
+         // if the neighbour can use the suggested color 
          IsColorUsedArr[ NeighLR->getSuggestedColor() ] = true;
-         if( NeighLR->getTypeID() == Type::DoubleTyID )
+         if (NeighLR->getType() == Type::DoubleTy)
            IsColorUsedArr[ (NeighLR->getSuggestedColor()) + 1 ] = true;  
-       }
-
-      }
-
+    }
   }
 
-
   // **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()
-
+  // 
   if( LR->hasSuggestedColor() ) {
     if( ! IsColorUsedArr[ LR->getSuggestedColor() ] ) {
       LR->setColor(  LR->getSuggestedColor() );
@@ -195,12 +182,12 @@ void SparcFloatRegClass::colorIGNode(IGNode * Node,bool IsColorUsedArr[]) const
   int ColorFound = -1;               // have we found a color yet?
   bool isCallInterf = LR->isCallInterference();
 
-  // if value is a double - search the double only reigon (f32 - f63)
+  // if value is a double - search the double only region (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 )       
+  if (LR->getType() == Type::DoubleTy)       
     ColorFound = findFloatColor( LR, 32, 64, IsColorUsedArr );
     
 
@@ -218,11 +205,11 @@ void SparcFloatRegClass::colorIGNode(IGNode * Node,bool IsColorUsedArr[]) const
     //if this Node is between calls (i.e., no call interferences )
     if( ! isCallInterf ) {
       // start with volatiles (we can  allocate volatiles safely)
-      SearchStart = SparcFloatRegOrder::StartOfAllRegs;  
+      SearchStart = SparcFloatRegClass::StartOfAllRegs;  
     }
     else {           
       // start with non volatiles (no non-volatiles)
-      SearchStart =  SparcFloatRegOrder::StartOfNonVolatileRegs;  
+      SearchStart =  SparcFloatRegClass::StartOfNonVolatileRegs;  
     }
     
     ColorFound = findFloatColor( LR, SearchStart, 32, IsColorUsedArr );
@@ -240,15 +227,13 @@ void SparcFloatRegClass::colorIGNode(IGNode * Node,bool IsColorUsedArr[]) const
     // color could be found.
     // Now try to allocate even a volatile color
 
-    ColorFound = findFloatColor( LR, SparcFloatRegOrder::StartOfAllRegs, 
-                               SparcFloatRegOrder::StartOfNonVolatileRegs,
+    ColorFound = findFloatColor( LR, SparcFloatRegClass::StartOfAllRegs, 
+                               SparcFloatRegClass::StartOfNonVolatileRegs,
                                IsColorUsedArr);
   }
 
-
-
   if( ColorFound >= 0 ) {
-    LR->setColor(ColorFound);         // first color found in preffered order
+    LR->setColor(ColorFound);         // first color found in prefered order
     LR->markForSaveAcrossCalls();  
   } else {
     // we are here because no color could be found
@@ -265,11 +250,11 @@ void SparcFloatRegClass::colorIGNode(IGNode * Node,bool IsColorUsedArr[]) const
 
 int SparcFloatRegClass::findFloatColor(const LiveRange *LR, 
                                       unsigned Start, unsigned End, 
-                                      bool IsColorUsedArr[] ) const {
+                                      vector<bool> &IsColorUsedArr) const {
   bool ColorFound = false;
   unsigned c;
 
-  if (LR->getTypeID() == Type::DoubleTyID) { 
+  if (LR->getType() == Type::DoubleTy) { 
     // find first unused color for a double 
     for (c=Start; c < End ; c+= 2)
       if (!IsColorUsedArr[c] && !IsColorUsedArr[c+1])