[llvm-commits] CVS: llvm/lib/Transforms/Utils/CriticalEdge.cpp

Christopher Lattner lattner at cs.uiuc.edu
Thu Sep 5 22:52:01 PDT 2002


Changes in directory llvm/lib/Transforms/Utils:

CriticalEdge.cpp updated: 1.1 -> 1.2

---
Log message:

Fix bug with critical edge splitting code where it wouldn't update PHI nodes
in the old destination block to indicate that the value flows from the new
edge splitting block, not from the original multi-successor block.


---
Diffs of the changes:

Index: llvm/lib/Transforms/Utils/CriticalEdge.cpp
diff -u llvm/lib/Transforms/Utils/CriticalEdge.cpp:1.1 llvm/lib/Transforms/Utils/CriticalEdge.cpp:1.2
--- llvm/lib/Transforms/Utils/CriticalEdge.cpp:1.1	Thu Sep  5 21:35:34 2002
+++ llvm/lib/Transforms/Utils/CriticalEdge.cpp	Thu Sep  5 22:51:45 2002
@@ -7,6 +7,7 @@
 
 #include "llvm/Transforms/Utils/Local.h"
 #include "llvm/iTerminators.h"
+#include "llvm/iPHINode.h"
 #include "llvm/Analysis/Dominators.h"
 #include "llvm/Support/CFG.h"
 
@@ -38,9 +39,9 @@
 
   // Create a new basic block, linking it into the CFG.
   BasicBlock *NewBB = new BasicBlock(TIBB->getName()+"_crit_edge");
-
+  BasicBlock *DestBB = TI->getSuccessor(SuccNum);
   // Create our unconditional branch...
-  BranchInst *BI = new BranchInst(TI->getSuccessor(SuccNum));
+  BranchInst *BI = new BranchInst(DestBB);
   NewBB->getInstList().push_back(BI);
   
   // Branch to the new block, breaking the edge...
@@ -49,6 +50,15 @@
   // Insert the block into the function... right after the block TI lives in.
   Function &F = *TIBB->getParent();
   F.getBasicBlockList().insert(TIBB->getNext(), NewBB);
+
+  // If there are any PHI nodes in DestBB, we need to update them so that they
+  // merge incoming values from NewBB instead of from TIBB.
+  //
+  for (BasicBlock::iterator I = DestBB->begin();
+       PHINode *PN = dyn_cast<PHINode>(&*I); ++I) {
+    // We no longer enter through TIBB, now we come in through NewBB.
+    PN->replaceUsesOfWith(TIBB, NewBB);
+  }
 
   // Now if we have a pass object, update analysis information.  Currently we
   // update DominatorSet and DominatorTree information if it's available.





More information about the llvm-commits mailing list