llvm.org GIT mirror llvm / 8410b22
[WinEH] Split the landingpad BB instead of cloning it This means we don't have to RAUW the landingpad instruction and landingpad BB, which is a nice win. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235725 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 5 years ago
7 changed file(s) with 17 addition(s) and 29 deletion(s). Raw diff Collapse all Expand all
669669 outlineHandler(Action, &F, LPad, StartBB, FrameVarInfo);
670670 }
671671
672 // Replace the landing pad with a new llvm.eh.action based landing pad.
673 BasicBlock *NewLPadBB = BasicBlock::Create(Context, "lpad", &F, LPadBB);
674 assert(!isa(LPadBB->begin()));
675 auto *NewLPad = cast(LPad->clone());
676 NewLPadBB->getInstList().push_back(NewLPad);
677 while (!pred_empty(LPadBB)) {
678 auto *pred = *pred_begin(LPadBB);
679 InvokeInst *Invoke = cast(pred->getTerminator());
680 Invoke->setUnwindDest(NewLPadBB);
681 }
682
683 // Replace the mapping of any nested landing pad that previously mapped
684 // to this landing pad with a referenced to the cloned version.
685 for (auto &LPadPair : NestedLPtoOriginalLP) {
686 const LandingPadInst *OriginalLPad = LPadPair.second;
687 if (OriginalLPad == LPad) {
688 LPadPair.second = NewLPad;
689 }
690 }
672 // Split the block after the landingpad instruction so that it is just a
673 // call to llvm.eh.actions followed by indirectbr.
674 assert(!isa(LPadBB->begin()) && "lpad phi not removed");
675 LPadBB->splitBasicBlock(LPad->getNextNode(),
676 LPadBB->getName() + ".prepsplit");
677 // Erase the branch inserted by the split so we can insert indirectbr.
678 LPadBB->getTerminator()->eraseFromParent();
691679
692680 // Replace all extracted values with undef and ultimately replace the
693681 // landingpad with undef.
732720 ActionArgs.push_back(Action->getHandlerBlockOrFunc());
733721 }
734722 CallInst *Recover =
735 CallInst::Create(ActionIntrin, ActionArgs, "recover", NewLPadBB);
723 CallInst::Create(ActionIntrin, ActionArgs, "recover", LPadBB);
736724
737725 // Add an indirect branch listing possible successors of the catch handlers.
738726 SetVector ReturnTargets;
743731 }
744732 }
745733 IndirectBrInst *Branch =
746 IndirectBrInst::Create(Recover, ReturnTargets.size(), NewLPadBB);
734 IndirectBrInst::Create(Recover, ReturnTargets.size(), LPadBB);
747735 for (BasicBlock *Target : ReturnTargets)
748736 Branch->addDestination(Target);
749737 } // End for each landingpad
2121 ; CHECK: define void @_Z4testv()
2222 ; CHECK: entry:
2323 ; CHECK: invoke void @_Z9may_throwv()
24 ; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]+]]
24 ; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
2525
2626 ; Function Attrs: uwtable
2727 define void @_Z4testv() #0 {
2525 ; CHECK: [[I_PTR:\%.+]] = alloca i32, align 4
2626 ; CHECK: call void (...) @llvm.frameescape(i32* [[I_PTR]])
2727 ; CHECK: invoke void @_Z9may_throwv()
28 ; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]+]]
28 ; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
2929
3030 ; Function Attrs: uwtable
3131 define void @_Z4testv() #0 {
3737 ; CHECK: [[TMP1:\%.+]] = alloca i32, align 4
3838 ; CHECK: call void (...) @llvm.frameescape(i32* [[TMP1]], %class.SomeClass* [[OBJ_PTR]], i32* [[TMP0]])
3939 ; CHECK: %call = invoke %class.SomeClass* @"\01??0SomeClass@@QEAA@XZ"(%class.SomeClass* %obj)
40 ; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]+]]
40 ; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
4141
4242 ; Function Attrs: uwtable
4343 define void @"\01?test@@YAXXZ"() #0 {
5050
5151 ; CHECK: invoke.cont:
5252 ; CHECK: invoke void @"\01?may_throw@@YAXXZ"()
53 ; CHECK: to label %invoke.cont2 unwind label %[[LPAD1_LABEL:lpad[0-9]+]]
53 ; CHECK: to label %invoke.cont2 unwind label %[[LPAD1_LABEL:lpad[0-9]*]]
5454
5555 invoke.cont: ; preds = %entry
5656 invoke void @"\01?may_throw@@YAXXZ"()
5858
5959 ; CHECK: invoke.cont2:
6060 ; CHECK: invoke void @"\01?may_throw@@YAXXZ"()
61 ; CHECK: to label %try.cont unwind label %[[LPAD3_LABEL:lpad[0-9]+]]
61 ; CHECK: to label %try.cont unwind label %[[LPAD3_LABEL:lpad[0-9]*]]
6262
6363 invoke.cont2: ; preds = %invoke.cont
6464 invoke void @"\01?may_throw@@YAXXZ"()
8383
8484 ; CHECK: for.body:
8585 ; CHECK: invoke void @"\01?may_throw@@YAXXZ"()
86 ; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]+]]
86 ; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
8787
8888 for.body: ; preds = %for.cond
8989 invoke void @"\01?may_throw@@YAXXZ"()
2626 ; CHECK: call void @_ZN9SomeClassC1Ev(%class.SomeClass* [[OBJ_PTR]])
2727 ; CHECK: call void (...) @llvm.frameescape(%class.SomeClass* [[OBJ_PTR]])
2828 ; CHECK: invoke void @_Z9may_throwv()
29 ; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]+]]
29 ; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
3030
3131 ; Function Attrs: uwtable
3232 define void @_Z4testv() #0 {
5151 ; CHECK: [[I_PTR:\%.+]] = alloca i32, align 4
5252 ; CHECK: call void (...) @llvm.frameescape(i32* [[I_PTR]], i64* [[LL_PTR]], %class.SomeClass** [[OBJ_PTR]])
5353 ; CHECK: invoke void @"\01?may_throw@@YAXXZ"()
54 ; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]+]]
54 ; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
5555
5656 ; Function Attrs: uwtable
5757 define void @"\01?test@@YAXXZ"() #0 {