Handle tGPR register class in a few more places. This fixes some llvm-gcc
[oota-llvm.git] / lib / CodeGen / ExactHazardRecognizer.cpp
index 2d07b76a362d69bd87efdabdec93dc0366e817f6..61959bba0e2314e368f1818499976b69de8d3787 100644 (file)
@@ -7,12 +7,12 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// This implements a hazard recognizer using the instructions itineraries
+// This implements a hazard recognizer using the instructions itineraries
 // defined for the current target.
 //
 //===----------------------------------------------------------------------===//
 
-#define DEBUG_TYPE "exact-hazards"
+#define DEBUG_TYPE "post-RA-sched"
 #include "ExactHazardRecognizer.h"
 #include "llvm/CodeGen/ScheduleHazardRecognizer.h"
 #include "llvm/Support/Debug.h"
@@ -22,7 +22,8 @@
 
 using namespace llvm;
 
-ExactHazardRecognizer::ExactHazardRecognizer(const InstrItineraryData &LItinData) :
+ExactHazardRecognizer::
+ExactHazardRecognizer(const InstrItineraryData &LItinData) :
   ScheduleHazardRecognizer(), ItinData(LItinData) 
 {
   // Determine the maximum depth of any itinerary. This determines the
@@ -31,13 +32,11 @@ ExactHazardRecognizer::ExactHazardRecognizer(const InstrItineraryData &LItinData
   ScoreboardDepth = 1;
   if (!ItinData.isEmpty()) {
     for (unsigned idx = 0; ; ++idx) {
-      // If the begin stage of an itinerary has 0 cycles and units,
-      // then we have reached the end of the itineraries.
-      const InstrStage *IS = ItinData.beginStage(idx);
-      const InstrStage *E = ItinData.endStage(idx);
-      if ((IS->getCycles() == 0) && (IS->getUnits() == 0))
+      if (ItinData.isEndMarker(idx))
         break;
 
+      const InstrStage *IS = ItinData.beginStage(idx);
+      const InstrStage *E = ItinData.endStage(idx);
       unsigned ItinDepth = 0;
       for (; IS != E; ++IS)
         ItinDepth += IS->getCycles();
@@ -49,12 +48,12 @@ ExactHazardRecognizer::ExactHazardRecognizer(const InstrItineraryData &LItinData
   Scoreboard = new unsigned[ScoreboardDepth];
   ScoreboardHead = 0;
 
-  DEBUG(errs() << "Using exact hazard recognizer: ScoreboardDepth = " 
+  DEBUG(dbgs() << "Using exact hazard recognizer: ScoreboardDepth = " 
                << ScoreboardDepth << '\n');
 }
 
 ExactHazardRecognizer::~ExactHazardRecognizer() {
-  delete Scoreboard;
+  delete [] Scoreboard;
 }
 
 void ExactHazardRecognizer::Reset() {
@@ -67,7 +66,7 @@ unsigned ExactHazardRecognizer::getFutureIndex(unsigned offset) {
 }
 
 void ExactHazardRecognizer::dumpScoreboard() {
-  errs() << "Scoreboard:\n";
+  dbgs() << "Scoreboard:\n";
   
   unsigned last = ScoreboardDepth - 1;
   while ((last > 0) && (Scoreboard[getFutureIndex(last)] == 0))
@@ -75,14 +74,17 @@ void ExactHazardRecognizer::dumpScoreboard() {
 
   for (unsigned i = 0; i <= last; i++) {
     unsigned FUs = Scoreboard[getFutureIndex(i)];
-    errs() << "\t";
+    dbgs() << "\t";
     for (int j = 31; j >= 0; j--)
-      errs() << ((FUs & (1 << j)) ? '1' : '0');
-    errs() << '\n';
+      dbgs() << ((FUs & (1 << j)) ? '1' : '0');
+    dbgs() << '\n';
   }
 }
 
 ExactHazardRecognizer::HazardType ExactHazardRecognizer::getHazardType(SUnit *SU) {
+  if (ItinData.isEmpty())
+    return NoHazard;
+
   unsigned cycle = 0;
 
   // Use the itinerary for the underlying instruction to check for
@@ -96,17 +98,17 @@ ExactHazardRecognizer::HazardType ExactHazardRecognizer::getHazardType(SUnit *SU
     for (unsigned int i = 0; i < IS->getCycles(); ++i) {
       assert(((cycle + i) < ScoreboardDepth) && 
              "Scoreboard depth exceeded!");
-
+      
       unsigned index = getFutureIndex(cycle + i);
       unsigned freeUnits = IS->getUnits() & ~Scoreboard[index];
       if (!freeUnits) {
-        DEBUG(errs() << "*** Hazard in cycle " << (cycle + i) << ", ");
-        DEBUG(errs() << "SU(" << SU->NodeNum << "): ");
+        DEBUG(dbgs() << "*** Hazard in cycle " << (cycle + i) << ", ");
+        DEBUG(dbgs() << "SU(" << SU->NodeNum << "): ");
         DEBUG(SU->getInstr()->dump());
         return Hazard;
       }
     }
-
+    
     // Advance the cycle to the next stage.
     cycle += IS->getNextCycles();
   }
@@ -115,6 +117,9 @@ ExactHazardRecognizer::HazardType ExactHazardRecognizer::getHazardType(SUnit *SU
 }
     
 void ExactHazardRecognizer::EmitInstruction(SUnit *SU) {
+  if (ItinData.isEmpty())
+    return;
+
   unsigned cycle = 0;
 
   // Use the itinerary for the underlying instruction to reserve FU's
@@ -128,7 +133,7 @@ void ExactHazardRecognizer::EmitInstruction(SUnit *SU) {
     for (unsigned int i = 0; i < IS->getCycles(); ++i) {
       assert(((cycle + i) < ScoreboardDepth) &&
              "Scoreboard depth exceeded!");
-
+      
       unsigned index = getFutureIndex(cycle + i);
       unsigned freeUnits = IS->getUnits() & ~Scoreboard[index];
       
@@ -138,15 +143,15 @@ void ExactHazardRecognizer::EmitInstruction(SUnit *SU) {
         freeUnit = freeUnits;
         freeUnits = freeUnit & (freeUnit - 1);
       } while (freeUnits);
-
+      
       assert(freeUnit && "No function unit available!");
       Scoreboard[index] |= freeUnit;
     }
-
+    
     // Advance the cycle to the next stage.
     cycle += IS->getNextCycles();
   }
-
+  
   DEBUG(dumpScoreboard());
 }