summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Target/WebAssembly/WebAssemblyExceptionInfoTest.cpp
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2019-01-30 03:21:57 +0000
committerHeejin Ahn <aheejin@gmail.com>2019-01-30 03:21:57 +0000
commitd6f487863dc951d467b545b86b9ea62980569b5a (patch)
treef0e3f8ee6a6f6060ed36e9b63320fbd2499f93df /llvm/unittests/Target/WebAssembly/WebAssemblyExceptionInfoTest.cpp
parent6d8e1b456a23d6c75be160fc67b0889e2bfe2170 (diff)
downloadbcm5719-llvm-d6f487863dc951d467b545b86b9ea62980569b5a.tar.gz
bcm5719-llvm-d6f487863dc951d467b545b86b9ea62980569b5a.zip
[WebAssembly] Exception handling: Switch to the new proposal
Summary: This switches the EH implementation to the new proposal: https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md (The previous proposal was https://github.com/WebAssembly/exception-handling/blob/master/proposals/old/Exceptions.md) - Instruction changes - Now we have one single `catch` instruction that returns a except_ref value - `throw` now can take variable number of operations - `rethrow` does not have 'depth' argument anymore - `br_on_exn` queries an except_ref to see if it matches the tag and branches to the given label if true. - `extract_exception` is a pseudo instruction that simulates popping values from wasm stack. This is to make `br_on_exn`, a very special instruction, work: `br_on_exn` puts values onto the stack only if it is taken, and the # of values can vay depending on the tag. - Now there's only one `catch` per `try`, this patch removes all special handling for terminate pad with a call to `__clang_call_terminate`. Before it was the only case there are two catch clauses (a normal `catch` and `catch_all` per `try`). - Make `rethrow` act as a terminator like `throw`. This splits BB after `rethrow` in WasmEHPrepare, and deletes an unnecessary `unreachable` after `rethrow` in LateEHPrepare. - Now we stop at all catchpads (because we add wasm `catch` instruction that catches all exceptions), this creates new `findWasmUnwindDestinations` function in SelectionDAGBuilder. - Now we use `br_on_exn` instrution to figure out if an except_ref matches the current tag or not, LateEHPrepare generates this sequence for catch pads: ``` catch block i32 br_on_exn $__cpp_exception end_block extract_exception ``` - Branch analysis for `br_on_exn` in WebAssemblyInstrInfo - Other various misc. changes to switch to the new proposal. Reviewers: dschuff Subscribers: sbc100, jgravelle-google, sunfish, llvm-commits Differential Revision: https://reviews.llvm.org/D57134 llvm-svn: 352598
Diffstat (limited to 'llvm/unittests/Target/WebAssembly/WebAssemblyExceptionInfoTest.cpp')
-rw-r--r--llvm/unittests/Target/WebAssembly/WebAssemblyExceptionInfoTest.cpp152
1 files changed, 10 insertions, 142 deletions
diff --git a/llvm/unittests/Target/WebAssembly/WebAssemblyExceptionInfoTest.cpp b/llvm/unittests/Target/WebAssembly/WebAssemblyExceptionInfoTest.cpp
index 0ecfdad462a..ec946379b1e 100644
--- a/llvm/unittests/Target/WebAssembly/WebAssemblyExceptionInfoTest.cpp
+++ b/llvm/unittests/Target/WebAssembly/WebAssemblyExceptionInfoTest.cpp
@@ -74,7 +74,7 @@ TEST(WebAssemblyExceptionInfoTest, TEST0) {
declare i32 @__gxx_wasm_personality_v0(...)
- define hidden void @test0() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) {
+ define void @test0() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) {
unreachable
}
@@ -100,14 +100,14 @@ body: |
; predecessors: %bb.0
successors: %bb.3, %bb.9
liveins: $value_stack
- CATCH_ALL implicit-def $arguments
+ %0:except_ref = CATCH implicit-def $arguments
CLEANUPRET implicit-def dead $arguments
bb.3 (landing-pad):
; predecessors: %bb.2
successors: %bb.4, %bb.6
liveins: $value_stack
- CATCH_ALL implicit-def $arguments
+ %1:except_ref = CATCH implicit-def $arguments
BR_IF %bb.4, %58:i32, implicit-def $arguments, implicit-def $value_stack, implicit $value_stack
BR %bb.6, implicit-def $arguments
@@ -138,13 +138,13 @@ body: |
; predecessors: %bb.4
successors: %bb.9
liveins: $value_stack
- CATCH_ALL implicit-def $arguments
+ %2:except_ref = CATCH implicit-def $arguments
CLEANUPRET implicit-def dead $arguments
bb.9 (landing-pad):
; predecessors: %bb.2, %bb.6, %bb.8
liveins: $value_stack
- CATCH_ALL implicit-def $arguments
+ %3:except_ref = CATCH implicit-def $arguments
CLEANUPRET implicit-def dead $arguments
bb.10:
@@ -237,7 +237,7 @@ TEST(WebAssemblyExceptionInfoTest, TEST1) {
declare i32 @__gxx_wasm_personality_v0(...)
- define hidden void @test1() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) {
+ define void @test1() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) {
unreachable
}
@@ -257,7 +257,7 @@ body: |
; predecessors: %bb.0
successors: %bb.2, %bb.8
liveins: $value_stack
- %52:i32 = CATCH_I32 0, implicit-def dead $arguments
+ %0:except_ref = CATCH implicit-def $arguments
BR_IF %bb.2, %32:i32, implicit-def $arguments, implicit-def $value_stack, implicit $value_stack
BR %bb.8, implicit-def $arguments
@@ -271,7 +271,7 @@ body: |
; predecessors: %bb.2
successors: %bb.4, %bb.6
liveins: $value_stack
- CATCH_ALL implicit-def $arguments
+ %1:except_ref = CATCH implicit-def $arguments
BR_IF %bb.4, %43:i32, implicit-def $arguments, implicit-def $value_stack, implicit $value_stack
BR %bb.6, implicit-def $arguments
@@ -313,13 +313,13 @@ body: |
; predecessors: %bb.4
successors: %bb.11
liveins: $value_stack
- CATCH_ALL implicit-def $arguments
+ %2:except_ref = CATCH implicit-def $arguments
CLEANUPRET implicit-def dead $arguments
bb.11 (landing-pad):
; predecessors: %bb.2, %bb.6, %bb.10
liveins: $value_stack
- CATCH_ALL implicit-def $arguments
+ %3:except_ref = CATCH implicit-def $arguments
CLEANUPRET implicit-def dead $arguments
bb.12:
@@ -415,135 +415,3 @@ body: |
EXPECT_EQ(WE0_1->getParentException(), WE0);
EXPECT_EQ(WE0_1->getExceptionDepth(), (unsigned)2);
}
-
-// Terminate pad test
-TEST(WebAssemblyExceptionInfoTest, TEST2) {
- std::unique_ptr<LLVMTargetMachine> TM = createTargetMachine();
- ASSERT_TRUE(TM);
-
- StringRef MIRString = R"MIR(
---- |
- target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
- target triple = "wasm32-unknown-unknown"
-
- declare i32 @__gxx_wasm_personality_v0(...)
- declare void @_ZSt9terminatev()
- declare void @__clang_call_terminate(i8*)
-
- define hidden void @test2() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) {
- unreachable
- }
-
-...
----
-name: test2
-liveins:
- - { reg: '$arguments' }
- - { reg: '$value_stack' }
-body: |
- bb.0:
- successors: %bb.3, %bb.1
- BR %bb.3, implicit-def dead $arguments
-
- bb.1 (landing-pad):
- ; predecessors: %bb.0
- successors: %bb.2, %bb.4
- %3:i32 = CATCH_I32 0, implicit-def dead $arguments
- BR %bb.2, implicit-def dead $arguments
-
- bb.2:
- ; predecessors: %bb.1
- successors: %bb.3(0x80000000); %bb.3(200.00%)
- CATCHRET %bb.3, %bb.0, implicit-def dead $arguments
-
- bb.3:
- ; predecessors: %bb.0, %bb.2
- RETURN_VOID implicit-def $arguments
-
- bb.4 (landing-pad):
- ; predecessors: %bb.1
- successors: %bb.5, %bb.6
- CATCH_ALL implicit-def $arguments
- BR %bb.5, implicit-def dead $arguments
-
- bb.5:
- ; predecessors: %bb.4
- CLEANUPRET implicit-def dead $arguments
-
- bb.6 (landing-pad):
- ; predecessors: %bb.4
- successors: %bb.7(0x80000000); %bb.7(200.00%)
- %6:i32 = CATCH_I32 0, implicit-def dead $arguments
- CALL_VOID @__clang_call_terminate, %7:i32, implicit-def $arguments
- UNREACHABLE implicit-def $arguments
-
- bb.7 (landing-pad):
- ; predecessors: %bb.6
- CATCH_ALL implicit-def $arguments
- CALL_VOID @_ZSt9terminatev, implicit-def $arguments
- UNREACHABLE implicit-def $arguments
-)MIR";
-
- LLVMContext Context;
- std::unique_ptr<MIRParser> MIR;
- MachineModuleInfo MMI(TM.get());
- std::unique_ptr<Module> M =
- parseMIR(Context, MIR, *TM, MIRString, "test2", MMI);
- ASSERT_TRUE(M);
-
- Function *F = M->getFunction("test2");
- auto *MF = MMI.getMachineFunction(*F);
- ASSERT_TRUE(MF);
-
- WebAssemblyExceptionInfo WEI;
- MachineDominatorTree MDT;
- MachineDominanceFrontier MDF;
- MDT.runOnMachineFunction(*MF);
- MDF.getBase().analyze(MDT.getBase());
- WEI.recalculate(MDT, MDF);
-
- // Exception info structure:
- // |- bb1 (ehpad), bb2, bb4, bb5, bb6, bb7
- // |- bb4 (ehpad), bb5, bb6, bb7
- // |- bb6 (ehpad), bb7
- //
- // Here, bb6 is a terminate pad with a 'catch' instruction, and bb7 is a
- // terminate pad with a 'catch_all' instruction, In this case we put bb6 and
- // bb7 into one exception.
-
- auto *MBB1 = MF->getBlockNumbered(1);
- auto *WE0 = WEI.getExceptionFor(MBB1);
- ASSERT_TRUE(WE0);
- EXPECT_EQ(WE0->getEHPad(), MBB1);
- EXPECT_EQ(WE0->getParentException(), nullptr);
- EXPECT_EQ(WE0->getExceptionDepth(), (unsigned)1);
-
- auto *MBB2 = MF->getBlockNumbered(2);
- WE0 = WEI.getExceptionFor(MBB2);
- ASSERT_TRUE(WE0);
- EXPECT_EQ(WE0->getEHPad(), MBB1);
-
- auto *MBB4 = MF->getBlockNumbered(4);
- auto *WE0_0 = WEI.getExceptionFor(MBB4);
- ASSERT_TRUE(WE0_0);
- EXPECT_EQ(WE0_0->getEHPad(), MBB4);
- EXPECT_EQ(WE0_0->getParentException(), WE0);
- EXPECT_EQ(WE0_0->getExceptionDepth(), (unsigned)2);
-
- auto *MBB5 = MF->getBlockNumbered(5);
- WE0_0 = WEI.getExceptionFor(MBB5);
- ASSERT_TRUE(WE0_0);
- EXPECT_EQ(WE0_0->getEHPad(), MBB4);
-
- auto *MBB6 = MF->getBlockNumbered(6);
- auto *WE0_0_0 = WEI.getExceptionFor(MBB6);
- ASSERT_TRUE(WE0_0_0);
- EXPECT_EQ(WE0_0_0->getEHPad(), MBB6);
- EXPECT_EQ(WE0_0_0->getParentException(), WE0_0);
- EXPECT_EQ(WE0_0_0->getExceptionDepth(), (unsigned)3);
-
- auto *MBB7 = MF->getBlockNumbered(7);
- WE0_0_0 = WEI.getExceptionFor(MBB7);
- ASSERT_TRUE(WE0_0_0);
- EXPECT_EQ(WE0_0_0->getEHPad(), MBB6);
-}
OpenPOWER on IntegriCloud