[llvm-commits] [llvm] r48085 - in /llvm/trunk: include/llvm/BasicBlock.h lib/Transforms/Utils/BasicBlockUtils.cpp lib/VMCore/BasicBlock.cpp

Nick Lewycky nicholas at mxc.ca
Sat Mar 8 21:04:48 PST 2008


Author: nicholas
Date: Sat Mar  8 23:04:48 2008
New Revision: 48085

URL: http://llvm.org/viewvc/llvm-project?rev=48085&view=rev
Log:
Two things. Preserve the unwind_to when splitting a BB.
Add the ability to remove just one instance of a BB from a phi node. This fixes
the compile error in the tree now.

Modified:
    llvm/trunk/include/llvm/BasicBlock.h
    llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp
    llvm/trunk/lib/VMCore/BasicBlock.cpp

Modified: llvm/trunk/include/llvm/BasicBlock.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/BasicBlock.h?rev=48085&r1=48084&r2=48085&view=diff

==============================================================================
--- llvm/trunk/include/llvm/BasicBlock.h (original)
+++ llvm/trunk/include/llvm/BasicBlock.h Sat Mar  8 23:04:48 2008
@@ -185,7 +185,11 @@
   /// DontDeleteUselessPHIs will keep PHIs that have one value or the same 
   /// value for all entries.
   ///
-  void removePredecessor(BasicBlock *Pred, bool DontDeleteUselessPHIs = false);
+  /// OnlyDeleteOne will only remove one entry from a PHI, in case there were
+  /// duplicate entries for the Pred.
+  ///
+  void removePredecessor(BasicBlock *Pred, bool DontDeleteUselessPHIs = false,
+                         bool OnlyDeleteOne = false);
 
   /// splitBasicBlock - This splits a basic block into two at the specified
   /// instruction.  Note that all instructions BEFORE the specified iterator

Modified: llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp?rev=48085&r1=48084&r2=48085&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp Sat Mar  8 23:04:48 2008
@@ -160,6 +160,7 @@
   while (isa<PHINode>(SplitIt))
     ++SplitIt;
   BasicBlock *New = Old->splitBasicBlock(SplitIt, Old->getName()+".split");
+  New->setUnwindDest(Old->getUnwindDest());
 
   // The new block lives in whichever loop the old one did.
   if (Loop *L = LI.getLoopFor(Old))

Modified: llvm/trunk/lib/VMCore/BasicBlock.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/BasicBlock.cpp?rev=48085&r1=48084&r2=48085&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/BasicBlock.cpp (original)
+++ llvm/trunk/lib/VMCore/BasicBlock.cpp Sat Mar  8 23:04:48 2008
@@ -188,14 +188,12 @@
 /// called while the predecessor still refers to this block.
 ///
 void BasicBlock::removePredecessor(BasicBlock *Pred,
-                                   bool DontDeleteUselessPHIs) {
+                                   bool DontDeleteUselessPHIs,
+                                   bool OnlyDeleteOne) {
   assert((hasNUsesOrMore(16)||// Reduce cost of this assertion for complex CFGs.
           find(pred_begin(this), pred_end(this), Pred) != pred_end(this)) &&
          "removePredecessor: BB is not a predecessor!");
 
-  if (Pred == getUnwindDest())
-    setUnwindDest(NULL);
-
   if (InstList.empty()) return;
   PHINode *APN = dyn_cast<PHINode>(&front());
   if (!APN) return;   // Quick exit.
@@ -226,7 +224,11 @@
     // Yup, loop through and nuke the PHI nodes
     while (PHINode *PN = dyn_cast<PHINode>(&front())) {
       // Remove the predecessor first.
-      PN->removeIncomingValue(Pred, !DontDeleteUselessPHIs);
+      if (OnlyDeleteOne) {
+        int idx = PN->getBasicBlockIndex(Pred);
+        PN->removeIncomingValue(idx, !DontDeleteUselessPHIs);
+      } else
+        PN->removeIncomingValue(Pred, !DontDeleteUselessPHIs);
 
       // If the PHI _HAD_ two uses, replace PHI node with its now *single* value
       if (max_idx == 2) {
@@ -247,7 +249,12 @@
     PHINode *PN;
     for (iterator II = begin(); (PN = dyn_cast<PHINode>(II)); ) {
       ++II;
-      PN->removeIncomingValue(Pred, false);
+      if (OnlyDeleteOne) {
+        int idx = PN->getBasicBlockIndex(Pred);
+        PN->removeIncomingValue(idx, false);
+      } else 
+        PN->removeIncomingValue(Pred, false);
+
       // If all incoming values to the Phi are the same, we can replace the Phi
       // with that value.
       Value* PNV = 0;





More information about the llvm-commits mailing list