From e35fdee39e4bada0b78237954a0ca21a909c6b95 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Fri, 2 Sep 2011 21:17:08 +0000 Subject: [PATCH] No need to get fancy inserting a PHI node when the values are stored in stack slots. This fixes a bug where the number of nodes coming into the PHI node may not equal the number of predecessors. E.g., two or more landingpad instructions may require a PHI before reaching the eh.exception and eh.selector instructions. llvm-svn: 139035 --- lib/VMCore/AutoUpgrade.cpp | 54 +++++++++----------------------------- 1 file changed, 13 insertions(+), 41 deletions(-) diff --git a/lib/VMCore/AutoUpgrade.cpp b/lib/VMCore/AutoUpgrade.cpp index 2c327660d47..dc66ad7c47c 100644 --- a/lib/VMCore/AutoUpgrade.cpp +++ b/lib/VMCore/AutoUpgrade.cpp @@ -414,12 +414,6 @@ void llvm::UpgradeExceptionHandling(Module *M) { // This map stores the slots where the exception object and selector value are // stored within a function. DenseMap > FnToLPadSlotMap; - - // This maps the old intrinsic calls (eh.exception & eh.selector) to the new - // landingpad instruction(s). - DenseMap, - SmallVector, 8> > OldExnToNewExnMap; - SmallPtrSet DeadInsts; for (DenseMap >::iterator I = InvokeToIntrinsicsMap.begin(), E = InvokeToIntrinsicsMap.end(); @@ -476,48 +470,26 @@ void llvm::UpgradeExceptionHandling(Module *M) { TransferClausesToLandingPadInst(LPI, Sel); - OldExnToNewExnMap[std::make_pair(Exn, Sel)]. - push_back(std::make_pair(LPExn, LPSel)); - DeadInsts.insert(Exn); DeadInsts.insert(Sel); } - // Replace the old intrinsic calls with the new (possibly PHI'ed) values. - for (DenseMap, - SmallVector, 8> >::iterator - I = OldExnToNewExnMap.begin(), E = OldExnToNewExnMap.end(); + // Replace the old intrinsic calls with the values from the landingpad + // instruction(s). These values were stored in allocas for us to use here. + for (DenseMap >::iterator + I = InvokeToIntrinsicsMap.begin(), E = InvokeToIntrinsicsMap.end(); I != E; ++I) { - std::pair OldExnSel = I->first; - CallInst *Exn = OldExnSel.first; - CallInst *Sel = OldExnSel.second; - SmallVector, 8> &LPExnSel = I->second; - unsigned Size = LPExnSel.size(); - Value *LPExn = LPExnSel[0].first; - Value *LPSel = LPExnSel[0].second; + std::pair EHIntrinsics = I->second; + CallInst *Exn = cast(EHIntrinsics.first); + CallInst *Sel = cast(EHIntrinsics.second); + BasicBlock *Parent = Exn->getParent(); - if (Size != 1) { - BasicBlock *Parent = Exn->getParent(); - IRBuilder<> Builder(Context); - Builder.SetInsertPoint(Parent, Parent->getFirstInsertionPt()); + std::pair ExnSelSlots = FnToLPadSlotMap[Parent->getParent()]; - PHINode *PN = Builder.CreatePHI(Exn->getType(), Size, "exn.phi"); - for (SmallVector, 8>::iterator - II = LPExnSel.begin(), IE = LPExnSel.end(); II != IE; ++II) - PN->addIncoming(II->first, cast(II->first)->getParent()); - - LPExn = PN; - - Parent = Sel->getParent(); - Builder.SetInsertPoint(Parent, Parent->getFirstInsertionPt()); - - PN = Builder.CreatePHI(Sel->getType(), Size, "sel.phi"); - for (SmallVector, 8>::iterator - II = LPExnSel.begin(), IE = LPExnSel.end(); II != IE; ++II) - PN->addIncoming(II->second, cast(II->second)->getParent()); - - LPSel = PN; - } + IRBuilder<> Builder(Context); + Builder.SetInsertPoint(Parent, Parent->getFirstInsertionPt()); + LoadInst *LPExn = Builder.CreateLoad(ExnSelSlots.first, "exn.load"); + LoadInst *LPSel = Builder.CreateLoad(ExnSelSlots.second, "sel.load"); Exn->replaceAllUsesWith(LPExn); Sel->replaceAllUsesWith(LPSel);