X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTransforms%2FUtils%2FCriticalEdge.cpp;h=a9f4b611e3f04acb81e2a98e868c6bb42ff863e3;hb=d76efa018660e806cd87c0a24512e3c532fc1d36;hp=07a3a542e55fc8c76de91f6bb33dddce36003584;hpb=4af3ccbbea4f6d2cf2d90b9b004c3da59f33510c;p=oota-llvm.git diff --git a/lib/Transforms/Utils/CriticalEdge.cpp b/lib/Transforms/Utils/CriticalEdge.cpp index 07a3a542e55..a9f4b611e3f 100644 --- a/lib/Transforms/Utils/CriticalEdge.cpp +++ b/lib/Transforms/Utils/CriticalEdge.cpp @@ -1,12 +1,12 @@ -//===-- Local.h - Functions to perform local transformations -----*- C++ -*--=// +//===-- CriticalEdge.cpp - Functions to detect and split critical edges ---===// // -// This family of functions perform various local transformations to the -// program. +// These functions are here to detect and split critical edges in the CFG. // //===----------------------------------------------------------------------===// #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 +38,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 +50,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(&*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. //