[WinEH] Split the landingpad BB instead of cloning it
authorReid Kleckner <reid@kleckner.net>
Fri, 24 Apr 2015 16:22:19 +0000 (16:22 +0000)
committerReid Kleckner <reid@kleckner.net>
Fri, 24 Apr 2015 16:22:19 +0000 (16:22 +0000)
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

lib/CodeGen/WinEHPrepare.cpp
test/CodeGen/WinEH/cppeh-catch-all.ll
test/CodeGen/WinEH/cppeh-catch-scalar.ll
test/CodeGen/WinEH/cppeh-catch-unwind.ll
test/CodeGen/WinEH/cppeh-frame-vars.ll
test/CodeGen/WinEH/cppeh-min-unwind.ll
test/CodeGen/WinEH/cppeh-multi-catch.ll

index 09f3e13252bf91000f4a74e24340d1b35afae3d4..8a0fb7fd1bccbedc491b281d3ae79ea41ec9f181 100644 (file)
@@ -670,25 +670,13 @@ bool WinEHPrepare::prepareExceptionHandlers(
       outlineHandler(Action, &F, LPad, StartBB, FrameVarInfo);
     }
 
-    // Replace the landing pad with a new llvm.eh.action based landing pad.
-    BasicBlock *NewLPadBB = BasicBlock::Create(Context, "lpad", &F, LPadBB);
-    assert(!isa<PHINode>(LPadBB->begin()));
-    auto *NewLPad = cast<LandingPadInst>(LPad->clone());
-    NewLPadBB->getInstList().push_back(NewLPad);
-    while (!pred_empty(LPadBB)) {
-      auto *pred = *pred_begin(LPadBB);
-      InvokeInst *Invoke = cast<InvokeInst>(pred->getTerminator());
-      Invoke->setUnwindDest(NewLPadBB);
-    }
-
-    // Replace the mapping of any nested landing pad that previously mapped
-    // to this landing pad with a referenced to the cloned version.
-    for (auto &LPadPair : NestedLPtoOriginalLP) {
-      const LandingPadInst *OriginalLPad = LPadPair.second;
-      if (OriginalLPad == LPad) {
-        LPadPair.second = NewLPad;
-      }
-    }
+    // Split the block after the landingpad instruction so that it is just a
+    // call to llvm.eh.actions followed by indirectbr.
+    assert(!isa<PHINode>(LPadBB->begin()) && "lpad phi not removed");
+    LPadBB->splitBasicBlock(LPad->getNextNode(),
+                            LPadBB->getName() + ".prepsplit");
+    // Erase the branch inserted by the split so we can insert indirectbr.
+    LPadBB->getTerminator()->eraseFromParent();
 
     // Replace all extracted values with undef and ultimately replace the
     // landingpad with undef.
@@ -733,7 +721,7 @@ bool WinEHPrepare::prepareExceptionHandlers(
       ActionArgs.push_back(Action->getHandlerBlockOrFunc());
     }
     CallInst *Recover =
-        CallInst::Create(ActionIntrin, ActionArgs, "recover", NewLPadBB);
+        CallInst::Create(ActionIntrin, ActionArgs, "recover", LPadBB);
 
     // Add an indirect branch listing possible successors of the catch handlers.
     SetVector<BasicBlock *> ReturnTargets;
@@ -744,7 +732,7 @@ bool WinEHPrepare::prepareExceptionHandlers(
       }
     }
     IndirectBrInst *Branch =
-        IndirectBrInst::Create(Recover, ReturnTargets.size(), NewLPadBB);
+        IndirectBrInst::Create(Recover, ReturnTargets.size(), LPadBB);
     for (BasicBlock *Target : ReturnTargets)
       Branch->addDestination(Target);
   } // End for each landingpad
index 4d017fde862d27cdf4d3026ebf2794571ceed3f3..a6c94d4007973e57a2e26ec8b7c730b5ab267162 100644 (file)
@@ -22,7 +22,7 @@ target triple = "x86_64-pc-windows-msvc"
 ; CHECK: define void @_Z4testv()
 ; CHECK: entry:
 ; CHECK:   invoke void @_Z9may_throwv()
-; CHECK:           to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]+]]
+; CHECK:           to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
 
 ; Function Attrs: uwtable
 define void @_Z4testv() #0 {
index 4ea383857ae838aaaff7b2d3998f128575ada230..4faef82a75fc31bed5971a5438130b792c9039c0 100644 (file)
@@ -26,7 +26,7 @@ target triple = "x86_64-pc-windows-msvc"
 ; CHECK:   [[I_PTR:\%.+]] = alloca i32, align 4
 ; CHECK:   call void (...) @llvm.frameescape(i32* [[I_PTR]])
 ; CHECK:   invoke void @_Z9may_throwv()
-; CHECK:           to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]+]]
+; CHECK:           to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
 
 ; Function Attrs: uwtable
 define void @_Z4testv() #0 {
index 37a542941eb45a4c855fe5b88378111b850a0d74..1a5a7b07b0a6436296b70794f6f24967b91e00bc 100644 (file)
@@ -38,7 +38,7 @@ $"\01??_R0H@8" = comdat any
 ; CHECK:   [[TMP1:\%.+]] = alloca i32, align 4
 ; CHECK:   call void (...) @llvm.frameescape(i32* [[TMP1]], %class.SomeClass* [[OBJ_PTR]], i32* [[TMP0]])
 ; CHECK:   %call = invoke %class.SomeClass* @"\01??0SomeClass@@QEAA@XZ"(%class.SomeClass* %obj)
-; CHECK:           to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]+]]
+; CHECK:           to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
 
 ; Function Attrs: uwtable
 define void @"\01?test@@YAXXZ"() #0 {
@@ -51,7 +51,7 @@ entry:
 
 ; CHECK: invoke.cont:
 ; CHECK:   invoke void @"\01?may_throw@@YAXXZ"()
-; CHECK:           to label %invoke.cont2 unwind label %[[LPAD1_LABEL:lpad[0-9]+]]
+; CHECK:           to label %invoke.cont2 unwind label %[[LPAD1_LABEL:lpad[0-9]*]]
 
 invoke.cont:                                      ; preds = %entry
   invoke void @"\01?may_throw@@YAXXZ"()
@@ -59,7 +59,7 @@ invoke.cont:                                      ; preds = %entry
 
 ; CHECK: invoke.cont2:
 ; CHECK:   invoke void @"\01?may_throw@@YAXXZ"()
-; CHECK:           to label %try.cont unwind label %[[LPAD3_LABEL:lpad[0-9]+]]
+; CHECK:           to label %try.cont unwind label %[[LPAD3_LABEL:lpad[0-9]*]]
 
 invoke.cont2:                                     ; preds = %invoke.cont
   invoke void @"\01?may_throw@@YAXXZ"()
index 773dc942c19ed266fb933ba5eb71821d27b9d8d2..eeda4319a6e6c11fad40b25f310b2311b548d512 100644 (file)
@@ -84,7 +84,7 @@ for.cond:                                         ; preds = %for.inc, %entry
 
 ; CHECK: for.body:
 ; CHECK:   invoke void @"\01?may_throw@@YAXXZ"()
-; CHECK:           to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]+]]
+; CHECK:           to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
 
 for.body:                                         ; preds = %for.cond
   invoke void @"\01?may_throw@@YAXXZ"()
index 7868b33f716c067576c46a64ce4e883f0f348bab..3fffa47a081b5396e8a819599eef53fa216f2b05 100644 (file)
@@ -27,7 +27,7 @@ target triple = "x86_64-pc-windows-msvc"
 ; CHECK:   call void @_ZN9SomeClassC1Ev(%class.SomeClass* [[OBJ_PTR]])
 ; CHECK:   call void (...) @llvm.frameescape(%class.SomeClass* [[OBJ_PTR]])
 ; CHECK:   invoke void @_Z9may_throwv()
-; CHECK:           to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]+]]
+; CHECK:           to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
 
 ; Function Attrs: uwtable
 define void @_Z4testv() #0 {
index 9844eb5735ce20b100cc471e4e07a14ca159d968..e8965ee35313bc899110054309159b268a67bbf4 100644 (file)
@@ -52,7 +52,7 @@ $"\01??_R0?AVSomeClass@@@8" = comdat any
 ; CHECK:   [[I_PTR:\%.+]] = alloca i32, align 4
 ; CHECK:   call void (...) @llvm.frameescape(i32* [[I_PTR]], i64* [[LL_PTR]], %class.SomeClass** [[OBJ_PTR]])
 ; CHECK:   invoke void @"\01?may_throw@@YAXXZ"()
-; CHECK:           to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]+]]
+; CHECK:           to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
 
 ; Function Attrs: uwtable
 define void @"\01?test@@YAXXZ"() #0 {