[llvm-commits] [llvm] r82554 - /llvm/trunk/lib/CodeGen/ExactHazardRecognizer.cpp

David Goodwin david_goodwin at apple.com
Tue Sep 22 09:47:52 PDT 2009


Author: david_goodwin
Date: Tue Sep 22 11:47:52 2009
New Revision: 82554

URL: http://llvm.org/viewvc/llvm-project?rev=82554&view=rev
Log:
Use early returns.

Modified:
    llvm/trunk/lib/CodeGen/ExactHazardRecognizer.cpp

Modified: llvm/trunk/lib/CodeGen/ExactHazardRecognizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ExactHazardRecognizer.cpp?rev=82554&r1=82553&r2=82554&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/ExactHazardRecognizer.cpp (original)
+++ llvm/trunk/lib/CodeGen/ExactHazardRecognizer.cpp Tue Sep 22 11:47:52 2009
@@ -83,75 +83,77 @@
 }
 
 ExactHazardRecognizer::HazardType ExactHazardRecognizer::getHazardType(SUnit *SU) {
-  if (!ItinData.isEmpty()) {
-    unsigned cycle = 0;
+  if (ItinData.isEmpty())
+    return NoHazard;
 
-    // Use the itinerary for the underlying instruction to check for
-    // free FU's in the scoreboard at the appropriate future cycles.
-    unsigned idx = SU->getInstr()->getDesc().getSchedClass();
-    for (const InstrStage *IS = ItinData.beginStage(idx),
-           *E = ItinData.endStage(idx); IS != E; ++IS) {
-      // We must find one of the stage's units free for every cycle the
-      // stage is occupied. FIXME it would be more accurate to find the
-      // same unit free in all the cycles.
-      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(SU->getInstr()->dump());
-          return Hazard;
-        }
-      }
+  unsigned cycle = 0;
+
+  // Use the itinerary for the underlying instruction to check for
+  // free FU's in the scoreboard at the appropriate future cycles.
+  unsigned idx = SU->getInstr()->getDesc().getSchedClass();
+  for (const InstrStage *IS = ItinData.beginStage(idx),
+         *E = ItinData.endStage(idx); IS != E; ++IS) {
+    // We must find one of the stage's units free for every cycle the
+    // stage is occupied. FIXME it would be more accurate to find the
+    // same unit free in all the cycles.
+    for (unsigned int i = 0; i < IS->getCycles(); ++i) {
+      assert(((cycle + i) < ScoreboardDepth) && 
+             "Scoreboard depth exceeded!");
       
-      // Advance the cycle to the next stage.
-      cycle += IS->getNextCycles();
+      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(SU->getInstr()->dump());
+        return Hazard;
+      }
     }
+    
+    // Advance the cycle to the next stage.
+    cycle += IS->getNextCycles();
   }
 
   return NoHazard;
 }
     
 void ExactHazardRecognizer::EmitInstruction(SUnit *SU) {
-  if (!ItinData.isEmpty()) {
-    unsigned cycle = 0;
+  if (ItinData.isEmpty())
+    return;
 
-    // Use the itinerary for the underlying instruction to reserve FU's
-    // in the scoreboard at the appropriate future cycles.
-    unsigned idx = SU->getInstr()->getDesc().getSchedClass();
-    for (const InstrStage *IS = ItinData.beginStage(idx), 
-           *E = ItinData.endStage(idx); IS != E; ++IS) {
-      // We must reserve one of the stage's units for every cycle the
-      // stage is occupied. FIXME it would be more accurate to reserve
-      // the same unit free in all the cycles.
-      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];
-        
-        // reduce to a single unit
-        unsigned freeUnit = 0;
-        do {
-          freeUnit = freeUnits;
-          freeUnits = freeUnit & (freeUnit - 1);
-        } while (freeUnits);
-        
-        assert(freeUnit && "No function unit available!");
-        Scoreboard[index] |= freeUnit;
-      }
+  unsigned cycle = 0;
 
-      // Advance the cycle to the next stage.
-      cycle += IS->getNextCycles();
+  // Use the itinerary for the underlying instruction to reserve FU's
+  // in the scoreboard at the appropriate future cycles.
+  unsigned idx = SU->getInstr()->getDesc().getSchedClass();
+  for (const InstrStage *IS = ItinData.beginStage(idx), 
+         *E = ItinData.endStage(idx); IS != E; ++IS) {
+    // We must reserve one of the stage's units for every cycle the
+    // stage is occupied. FIXME it would be more accurate to reserve
+    // the same unit free in all the cycles.
+    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];
+      
+      // reduce to a single unit
+      unsigned freeUnit = 0;
+      do {
+        freeUnit = freeUnits;
+        freeUnits = freeUnit & (freeUnit - 1);
+      } while (freeUnits);
+      
+      assert(freeUnit && "No function unit available!");
+      Scoreboard[index] |= freeUnit;
     }
-
-    DEBUG(dumpScoreboard());
+    
+    // Advance the cycle to the next stage.
+    cycle += IS->getNextCycles();
   }
+  
+  DEBUG(dumpScoreboard());
 }
     
 void ExactHazardRecognizer::AdvanceCycle() {





More information about the llvm-commits mailing list