mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-03 17:39:48 +00:00
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
This commit is contained in:
parent
9cb3b3dd2e
commit
e35fdee39e
@ -414,12 +414,6 @@ void llvm::UpgradeExceptionHandling(Module *M) {
|
|||||||
// This map stores the slots where the exception object and selector value are
|
// This map stores the slots where the exception object and selector value are
|
||||||
// stored within a function.
|
// stored within a function.
|
||||||
DenseMap<Function*, std::pair<Value*, Value*> > FnToLPadSlotMap;
|
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;
|
SmallPtrSet<Instruction*, 32> DeadInsts;
|
||||||
for (DenseMap<InvokeInst*, std::pair<Value*, Value*> >::iterator
|
for (DenseMap<InvokeInst*, std::pair<Value*, Value*> >::iterator
|
||||||
I = InvokeToIntrinsicsMap.begin(), E = InvokeToIntrinsicsMap.end();
|
I = InvokeToIntrinsicsMap.begin(), E = InvokeToIntrinsicsMap.end();
|
||||||
@ -476,48 +470,26 @@ void llvm::UpgradeExceptionHandling(Module *M) {
|
|||||||
|
|
||||||
TransferClausesToLandingPadInst(LPI, Sel);
|
TransferClausesToLandingPadInst(LPI, Sel);
|
||||||
|
|
||||||
OldExnToNewExnMap[std::make_pair(Exn, Sel)].
|
|
||||||
push_back(std::make_pair(LPExn, LPSel));
|
|
||||||
|
|
||||||
DeadInsts.insert(Exn);
|
DeadInsts.insert(Exn);
|
||||||
DeadInsts.insert(Sel);
|
DeadInsts.insert(Sel);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace the old intrinsic calls with the new (possibly PHI'ed) values.
|
// Replace the old intrinsic calls with the values from the landingpad
|
||||||
for (DenseMap<std::pair<CallInst*, CallInst*>,
|
// instruction(s). These values were stored in allocas for us to use here.
|
||||||
SmallVector<std::pair<Value*, Value*>, 8> >::iterator
|
for (DenseMap<InvokeInst*, std::pair<Value*, Value*> >::iterator
|
||||||
I = OldExnToNewExnMap.begin(), E = OldExnToNewExnMap.end();
|
I = InvokeToIntrinsicsMap.begin(), E = InvokeToIntrinsicsMap.end();
|
||||||
I != E; ++I) {
|
I != E; ++I) {
|
||||||
std::pair<CallInst*, CallInst*> OldExnSel = I->first;
|
std::pair<Value*, Value*> EHIntrinsics = I->second;
|
||||||
CallInst *Exn = OldExnSel.first;
|
CallInst *Exn = cast<CallInst>(EHIntrinsics.first);
|
||||||
CallInst *Sel = OldExnSel.second;
|
CallInst *Sel = cast<CallInst>(EHIntrinsics.second);
|
||||||
SmallVector<std::pair<Value*, Value*>, 8> &LPExnSel = I->second;
|
BasicBlock *Parent = Exn->getParent();
|
||||||
unsigned Size = LPExnSel.size();
|
|
||||||
Value *LPExn = LPExnSel[0].first;
|
|
||||||
Value *LPSel = LPExnSel[0].second;
|
|
||||||
|
|
||||||
if (Size != 1) {
|
std::pair<Value*,Value*> ExnSelSlots = FnToLPadSlotMap[Parent->getParent()];
|
||||||
BasicBlock *Parent = Exn->getParent();
|
|
||||||
IRBuilder<> Builder(Context);
|
|
||||||
Builder.SetInsertPoint(Parent, Parent->getFirstInsertionPt());
|
|
||||||
|
|
||||||
PHINode *PN = Builder.CreatePHI(Exn->getType(), Size, "exn.phi");
|
IRBuilder<> Builder(Context);
|
||||||
for (SmallVector<std::pair<Value*, Value*>, 8>::iterator
|
Builder.SetInsertPoint(Parent, Parent->getFirstInsertionPt());
|
||||||
II = LPExnSel.begin(), IE = LPExnSel.end(); II != IE; ++II)
|
LoadInst *LPExn = Builder.CreateLoad(ExnSelSlots.first, "exn.load");
|
||||||
PN->addIncoming(II->first, cast<Instruction>(II->first)->getParent());
|
LoadInst *LPSel = Builder.CreateLoad(ExnSelSlots.second, "sel.load");
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
Exn->replaceAllUsesWith(LPExn);
|
Exn->replaceAllUsesWith(LPExn);
|
||||||
Sel->replaceAllUsesWith(LPSel);
|
Sel->replaceAllUsesWith(LPSel);
|
||||||
|
Loading…
Reference in New Issue
Block a user