summaryrefslogtreecommitdiff
path: root/lib/VMCore
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2011-09-02 21:17:08 +0000
committerBill Wendling <isanbard@gmail.com>2011-09-02 21:17:08 +0000
commit271439053d583b39e128a06ed6122593d76b3164 (patch)
treee5f2c53ad3e05f6a6f7a17ec86d5a4edbfe3c7bf /lib/VMCore
parent011dca7fac07100695dd3685bfaddbea58a468b9 (diff)
downloadllvm-271439053d583b39e128a06ed6122593d76b3164.tar.gz
llvm-271439053d583b39e128a06ed6122593d76b3164.tar.bz2
llvm-271439053d583b39e128a06ed6122593d76b3164.tar.xz
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@139035 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/AutoUpgrade.cpp58
1 files changed, 15 insertions, 43 deletions
diff --git a/lib/VMCore/AutoUpgrade.cpp b/lib/VMCore/AutoUpgrade.cpp
index 2c327660d4..dc66ad7c47 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<Function*, std::pair<Value*, Value*> > FnToLPadSlotMap;
-
- // This maps the old intrinsic calls (eh.exception & eh.selector) to the new
- // landingpad instruction(s).
- DenseMap<std::pair<CallInst*, CallInst*>,
- SmallVector<std::pair<Value*, Value*>, 8> > OldExnToNewExnMap;
-
SmallPtrSet<Instruction*, 32> DeadInsts;
for (DenseMap<InvokeInst*, std::pair<Value*, Value*> >::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<std::pair<CallInst*, CallInst*>,
- SmallVector<std::pair<Value*, Value*>, 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<InvokeInst*, std::pair<Value*, Value*> >::iterator
+ I = InvokeToIntrinsicsMap.begin(), E = InvokeToIntrinsicsMap.end();
I != E; ++I) {
- std::pair<CallInst*, CallInst*> OldExnSel = I->first;
- CallInst *Exn = OldExnSel.first;
- CallInst *Sel = OldExnSel.second;
- SmallVector<std::pair<Value*, Value*>, 8> &LPExnSel = I->second;
- unsigned Size = LPExnSel.size();
- Value *LPExn = LPExnSel[0].first;
- Value *LPSel = LPExnSel[0].second;
-
- if (Size != 1) {
- BasicBlock *Parent = Exn->getParent();
- IRBuilder<> Builder(Context);
- Builder.SetInsertPoint(Parent, Parent->getFirstInsertionPt());
-
- PHINode *PN = Builder.CreatePHI(Exn->getType(), Size, "exn.phi");
- for (SmallVector<std::pair<Value*, Value*>, 8>::iterator
- II = LPExnSel.begin(), IE = LPExnSel.end(); II != IE; ++II)
- PN->addIncoming(II->first, cast<Instruction>(II->first)->getParent());
-
- LPExn = PN;
-
- Parent = Sel->getParent();
- Builder.SetInsertPoint(Parent, Parent->getFirstInsertionPt());
-
- PN = Builder.CreatePHI(Sel->getType(), Size, "sel.phi");
- for (SmallVector<std::pair<Value*, Value*>, 8>::iterator
- II = LPExnSel.begin(), IE = LPExnSel.end(); II != IE; ++II)
- PN->addIncoming(II->second, cast<Instruction>(II->second)->getParent());
-
- LPSel = PN;
- }
+ std::pair<Value*, Value*> EHIntrinsics = I->second;
+ CallInst *Exn = cast<CallInst>(EHIntrinsics.first);
+ CallInst *Sel = cast<CallInst>(EHIntrinsics.second);
+ BasicBlock *Parent = Exn->getParent();
+
+ std::pair<Value*,Value*> ExnSelSlots = FnToLPadSlotMap[Parent->getParent()];
+
+ 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);