aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-09-06 03:51:45 +0000
committerChris Lattner <sabre@nondot.org>2002-09-06 03:51:45 +0000
commita9d2bffeeb5b888618211cbe2b69721ad77d752c (patch)
treecb2eb64c79b3fe5fc4df5f9b6ba987a7e3322b39 /lib
parent9355b479c36a857b44862e8a4621f963b2991aef (diff)
downloadexternal_llvm-a9d2bffeeb5b888618211cbe2b69721ad77d752c.zip
external_llvm-a9d2bffeeb5b888618211cbe2b69721ad77d752c.tar.gz
external_llvm-a9d2bffeeb5b888618211cbe2b69721ad77d752c.tar.bz2
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3590 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/Utils/CriticalEdge.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/Transforms/Utils/CriticalEdge.cpp b/lib/Transforms/Utils/CriticalEdge.cpp
index 07a3a54..35eac3f 100644
--- a/lib/Transforms/Utils/CriticalEdge.cpp
+++ b/lib/Transforms/Utils/CriticalEdge.cpp
@@ -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 @@ void SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, Pass *P) {
// 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...
@@ -50,6 +51,15 @@ void SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, Pass *P) {
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.
//