diff options
author | Bill Wendling <isanbard@gmail.com> | 2011-08-19 23:46:30 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2011-08-19 23:46:30 +0000 |
commit | 94657b964f90107989c61a63a214451c03922649 (patch) | |
tree | 967594044f78ad1b2f9fe8ed7457172980e19c88 /lib/Transforms/Utils | |
parent | 483699c2961f21b76914bbf8c1b5a29a3c15672b (diff) | |
download | llvm-94657b964f90107989c61a63a214451c03922649.tar.gz llvm-94657b964f90107989c61a63a214451c03922649.tar.bz2 llvm-94657b964f90107989c61a63a214451c03922649.tar.xz |
If we're splitting the landing pad block and assigning it only one predecessor,
then don't split it a second time, since that block will be dead.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@138153 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils')
-rw-r--r-- | lib/Transforms/Utils/BasicBlockUtils.cpp | 66 |
1 files changed, 40 insertions, 26 deletions
diff --git a/lib/Transforms/Utils/BasicBlockUtils.cpp b/lib/Transforms/Utils/BasicBlockUtils.cpp index 5d7f330bfd..27120eeeb3 100644 --- a/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/lib/Transforms/Utils/BasicBlockUtils.cpp @@ -541,50 +541,64 @@ void llvm::SplitLandingPadPredecessors(BasicBlock *OrigBB, // Update the PHI nodes in OrigBB with the values coming from NewBB1. UpdatePHINodes(OrigBB, NewBB1, Preds, BI1, P, HasLoopExit); - // Create another basic block for the rest of OrigBB's predecessors. - BasicBlock *NewBB2 = BasicBlock::Create(OrigBB->getContext(), - OrigBB->getName() + Suffix2, - OrigBB->getParent(), OrigBB); - NewBBs.push_back(NewBB2); - - // The new block unconditionally branches to the old block. - BranchInst *BI2 = BranchInst::Create(OrigBB, NewBB2); - // Move the remaining edges from OrigBB to point to NewBB2. SmallVector<BasicBlock*, 8> NewBB2Preds; for (pred_iterator i = pred_begin(OrigBB), e = pred_end(OrigBB); i != e; ) { BasicBlock *Pred = *i++; - if (Pred == NewBB1 || Pred == NewBB2 ) continue; + if (Pred == NewBB1) continue; assert(!isa<IndirectBrInst>(Pred->getTerminator()) && "Cannot split an edge from an IndirectBrInst"); - Pred->getTerminator()->replaceUsesOfWith(OrigBB, NewBB2); NewBB2Preds.push_back(Pred); e = pred_end(OrigBB); } - // Update DominatorTree, LoopInfo, and LCCSA analysis information. - HasLoopExit = false; - UpdateAnalysisInformation(OrigBB, NewBB2, NewBB2Preds, P, HasLoopExit); + BasicBlock *NewBB2 = 0; + if (!NewBB2Preds.empty()) { + // Create another basic block for the rest of OrigBB's predecessors. + NewBB2 = BasicBlock::Create(OrigBB->getContext(), + OrigBB->getName() + Suffix2, + OrigBB->getParent(), OrigBB); + NewBBs.push_back(NewBB2); + + // The new block unconditionally branches to the old block. + BranchInst *BI2 = BranchInst::Create(OrigBB, NewBB2); - // Update the PHI nodes in OrigBB with the values coming from NewBB2. - UpdatePHINodes(OrigBB, NewBB2, NewBB2Preds, BI2, P, HasLoopExit); + // Move the remaining edges from OrigBB to point to NewBB2. + for (SmallVectorImpl<BasicBlock*>::iterator + i = NewBB2Preds.begin(), e = NewBB2Preds.end(); i != e; ++i) + (*i)->getTerminator()->replaceUsesOfWith(OrigBB, NewBB2); + + // Update DominatorTree, LoopInfo, and LCCSA analysis information. + HasLoopExit = false; + UpdateAnalysisInformation(OrigBB, NewBB2, NewBB2Preds, P, HasLoopExit); + + // Update the PHI nodes in OrigBB with the values coming from NewBB2. + UpdatePHINodes(OrigBB, NewBB2, NewBB2Preds, BI2, P, HasLoopExit); + } LandingPadInst *LPad = OrigBB->getLandingPadInst(); Instruction *Clone1 = LPad->clone(); Clone1->setName(Twine("lpad") + Suffix1); NewBB1->getInstList().insert(NewBB1->getFirstInsertionPt(), Clone1); - Instruction *Clone2 = LPad->clone(); - Clone2->setName(Twine("lpad") + Suffix2); - NewBB2->getInstList().insert(NewBB2->getFirstInsertionPt(), Clone2); - - // Create a PHI node for the two cloned landingpad instructions. - PHINode *PN = PHINode::Create(LPad->getType(), 2, "lpad.phi", LPad); - PN->addIncoming(Clone1, NewBB1); - PN->addIncoming(Clone2, NewBB2); - LPad->replaceAllUsesWith(PN); - LPad->eraseFromParent(); + if (NewBB2) { + Instruction *Clone2 = LPad->clone(); + Clone2->setName(Twine("lpad") + Suffix2); + NewBB2->getInstList().insert(NewBB2->getFirstInsertionPt(), Clone2); + + // Create a PHI node for the two cloned landingpad instructions. + PHINode *PN = PHINode::Create(LPad->getType(), 2, "lpad.phi", LPad); + PN->addIncoming(Clone1, NewBB1); + PN->addIncoming(Clone2, NewBB2); + LPad->replaceAllUsesWith(PN); + LPad->eraseFromParent(); + } else { + // There is no second clone. Just replace the landing pad with the first + // clone. + LPad->replaceAllUsesWith(Clone1); + LPad->eraseFromParent(); + } } /// FindFunctionBackedges - Analyze the specified function to find all of the |