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

Chris Lattner lattner at cs.uiuc.edu
Thu Aug 12 20:27:20 PDT 2004



Changes in directory llvm/lib/Transforms/Utils:

CodeExtractor.cpp updated: 1.29 -> 1.30
---
Log message:

If we are extracting a block that has multiple successors that are the same
block (common in a switch), make sure to remove extra edges in successor 
blocks.  This fixes CodeExtractor/2004-08-12-BlockExtractPHI.ll and should
be pulled into LLVM 1.3 (though the regression test need not be, as that
would require pulling in the LoopExtract.cpp changes).



---
Diffs of the changes:  (+11 -2)

Index: llvm/lib/Transforms/Utils/CodeExtractor.cpp
diff -u llvm/lib/Transforms/Utils/CodeExtractor.cpp:1.29 llvm/lib/Transforms/Utils/CodeExtractor.cpp:1.30
--- llvm/lib/Transforms/Utils/CodeExtractor.cpp:1.29	Thu Aug 12 22:17:39 2004
+++ llvm/lib/Transforms/Utils/CodeExtractor.cpp	Thu Aug 12 22:27:07 2004
@@ -657,10 +657,19 @@
                                  succ_end(codeReplacer));
   for (unsigned i = 0, e = Succs.size(); i != e; ++i)
     for (BasicBlock::iterator I = Succs[i]->begin();
-         PHINode *PN = dyn_cast<PHINode>(I); ++I)
+         PHINode *PN = dyn_cast<PHINode>(I); ++I) {
+      std::set<BasicBlock*> ProcessedPreds;
       for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
         if (BlocksToExtract.count(PN->getIncomingBlock(i)))
-          PN->setIncomingBlock(i, codeReplacer);
+          if (ProcessedPreds.insert(PN->getIncomingBlock(i)).second)
+            PN->setIncomingBlock(i, codeReplacer);
+          else {
+            // There were multiple entries in the PHI for this block, now there
+            // is only one, so remove the duplicated entries.
+            PN->removeIncomingValue(i, false);
+            --i; --e;
+          }
+    }
   
   //std::cerr << "NEW FUNCTION: " << *newFunction;
   //  verifyFunction(*newFunction);






More information about the llvm-commits mailing list