[llvm-commits] CVS: reopt/lib/TraceToFunction/TraceToFunction.cpp

Brian Gaeke gaeke at cs.uiuc.edu
Thu May 20 14:52:03 PDT 2004


Changes in directory reopt/lib/TraceToFunction:

TraceToFunction.cpp updated: 1.49 -> 1.50

---
Log message:

In fixupPhis(), only iterate over Phi nodes in each cloned BasicBlock, not the
whole BasicBlock. Also, untabify most of this function.

Merge two asserts in fixupFunctionBodyBB().


---
Diffs of the changes:  (+48 -61)

Index: reopt/lib/TraceToFunction/TraceToFunction.cpp
diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.49 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.50
--- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.49	Thu May 20 14:34:26 2004
+++ reopt/lib/TraceToFunction/TraceToFunction.cpp	Thu May 20 14:50:44 2004
@@ -320,66 +320,61 @@
   std::vector<Instruction *> goners;
   Function *F = dstB->getParent ();
   // Fix up Phi nodes:
-  for (BasicBlock::iterator BI = dstB->begin (), BE = dstB->end ();
-       BI != BE; ++BI) {
-    Instruction &I = *BI;
-    // In all cases, if a Phi node source in T was an on-trace basic
-    // block, then it will already have been fixed up to point to
-    // that block's clone, so we find off-trace sources by looking
-    // for source BBs which are not in F.
-    if (PHINode *PN = dyn_cast<PHINode> (&I)) {
-      unsigned onTraceSources = 0;
-      int lastSrcFound = -1;
-      for (unsigned i = 0; i < PN->getNumIncomingValues (); ++i)
-	if (PN->getIncomingBlock (i)->getParent () == F) {
-	  lastSrcFound = i;
-	  ++onTraceSources;
-	}
-      // Case 0. If the phi node has 0 sources on the trace, abort,
-      // because that should really never happen.
-      assert (onTraceSources != 0
-	      && "Phi node on trace has ALL its sources from off-trace!");
-      // Case 1. If it has 1 source S on the trace, replace its uses
-      // with S.
-      if (onTraceSources == 1) {
-	DEBUG(std::cerr << "Replacing Phi node" << *PN
-	      << " with its lone on-trace input "
-	      << *PN->getIncomingValue (lastSrcFound) << "\n");
-	PN->replaceAllUsesWith (PN->getIncomingValue (lastSrcFound));
-	goners.push_back (BI); // Delete non-used phi node later.
-      } else {
-	// Case N. If the phi node has >1 source on the trace, just
-	// delete sources from the Phi node that are not on the trace.
-	int lastOffTraceSrcFound;
-	do {
-	  lastOffTraceSrcFound = -1;
-	  for (unsigned i = 0; i < PN->getNumIncomingValues (); ++i)
-	    if (PN->getIncomingBlock (i)->getParent () != F) {
-	      lastOffTraceSrcFound = i; // Found an off-trace source.
-	      break;
-	    }
-	  if (lastOffTraceSrcFound != -1) { // Found one?
-	    DEBUG(std::cerr << "Removing off-trace input "
-		  << *PN->getIncomingValue (lastOffTraceSrcFound)
-		  << " from Phi node " << *PN << "\n");
-	    PN->removeIncomingValue (lastOffTraceSrcFound); // Delete it.
-	  }
-	} while (lastOffTraceSrcFound != -1); // Continue until none found.
+  for (BasicBlock::iterator Inst = dstB->begin ();
+       PHINode *PN = dyn_cast<PHINode> (Inst); ++Inst) {
+    // If a Phi node source in T was an on-trace basic block, then it
+    // will already have been fixed up to point to that block's clone, so we
+    // find off-trace sources by looking for source BBs which are not in F.
+    unsigned onTraceSources = 0;
+    int lastSrcFound = -1;
+    for (unsigned i = 0; i < PN->getNumIncomingValues (); ++i)
+      if (PN->getIncomingBlock (i)->getParent () == F) {
+        lastSrcFound = i;
+        ++onTraceSources;
       }
+    // Case 0. If the phi node has 0 sources on the trace, abort,
+    // because that should really never happen.
+    assert (onTraceSources != 0
+            && "Phi node on trace has ALL its sources from off-trace!");
+    // Case 1. If it has 1 source S on the trace, replace its uses
+    // with S.
+    if (onTraceSources == 1) {
+      DEBUG(std::cerr << "Replacing Phi node" << *PN << " with its lone"
+        << " on-trace input " << *PN->getIncomingValue (lastSrcFound) << "\n");
+      PN->replaceAllUsesWith (PN->getIncomingValue (lastSrcFound));
+      goners.push_back (PN); // Delete non-used phi node later.
+    } else {
+      // Case N. If the phi node has >1 source on the trace, just
+      // delete sources from the Phi node that are not on the trace.
+      int lastOffTraceSrcFound;
+      do {
+        lastOffTraceSrcFound = -1;
+        for (unsigned i = 0; i < PN->getNumIncomingValues (); ++i)
+          if (PN->getIncomingBlock (i)->getParent () != F) {
+            lastOffTraceSrcFound = i; // Found an off-trace source.
+            break;
+          }
+        if (lastOffTraceSrcFound != -1) { // Found one?
+          DEBUG(std::cerr << "Removing off-trace input "
+                << *PN->getIncomingValue (lastOffTraceSrcFound)
+                << " from Phi node " << *PN << "\n");
+          PN->removeIncomingValue (lastOffTraceSrcFound); // Delete it.
+        }
+      } while (lastOffTraceSrcFound != -1); // Continue until none found.
+    }
     // Make sure that our Phi fixups did the Right Thing.
     DEBUG(if (PN->use_size () != 0) // 0-use nodes get deleted later
-	  for (unsigned i = 0; i < PN->getNumIncomingValues (); ++i)
-	  assert (PN->getIncomingBlock (i)->getParent () == F &&
-		  "Sorry, fixupPhis mishandled a Phi node"));
-    }
+          for (unsigned i = 0; i < PN->getNumIncomingValues (); ++i)
+          assert (PN->getIncomingBlock (i)->getParent () == F &&
+                  "Sorry, fixupPhis mishandled a Phi node"));
   }
 
   while (!goners.empty ()) {
     assert (goners.back ()->use_size () == 0
-	    && "Whoops, I was going to delete something which still has uses");
+            && "Whoops, I was going to delete something which still has uses");
     dstB->getInstList ().erase (goners.back ());
     for (ValueMap::iterator i = O2CMap.begin(), e = O2CMap.end(); i != e; ++i) {
-	  if (i->second == goners.back ()) {
+      if (i->second == goners.back ()) {
         O2CMap.erase (i);
         break;
       }
@@ -630,16 +625,8 @@
 	// This is a non-trace-exiting destination of branch BI. Fix up
 	// its clone's destination to point to its successor's clone.
 	Value *V2 = O2CMap[successor];
-	DEBUG(if (!V2) {
-	  std::cerr
-	    << "I'm confused: saw non-trace-exiting dest. of branch "
-	    << *BI << " whose clone is " << *BIinF
-	    << " successor number is " << i << " and successor is "
-	    << *successor << ", but where's its clone?\n";
-	  assert(V2 && "Clone of basic block on trace is null?");
-	});
-	assert(isa<BasicBlock> (V2)
-	       && "Clone of basic block on trace is not a basic block?");
+	assert(V2 && isa<BasicBlock> (V2)
+	       && "Clone of basic block on trace not found, or not a basic block");
 	BIinF->setSuccessor (i, cast<BasicBlock> (V2));
       }
     }





More information about the llvm-commits mailing list