[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
2019-01-30 11:21:57 +08:00
|
|
|
# RUN: llvm-mc -triple=wasm32-unknown-unknown -mattr=+exception-handling < %s | FileCheck %s
|
|
|
|
|
|
|
|
# Tests if block/loop/try/catch/end/branch/rethrow instructions are correctly
|
|
|
|
# printed with their annotations.
|
|
|
|
|
|
|
|
.text
|
|
|
|
.section .text.test_annotation,"",@
|
|
|
|
.type test_annotation,@function
|
|
|
|
test_annotation:
|
|
|
|
.functype test_annotation () -> ()
|
|
|
|
.eventtype __cpp_exception i32
|
|
|
|
try
|
|
|
|
br 0
|
|
|
|
catch
|
|
|
|
block
|
|
|
|
br_if 0
|
|
|
|
loop
|
|
|
|
br_if 1
|
|
|
|
end_loop
|
|
|
|
end_block
|
|
|
|
try
|
|
|
|
rethrow
|
|
|
|
catch
|
|
|
|
block
|
|
|
|
try
|
|
|
|
br 0
|
|
|
|
catch
|
|
|
|
local.set 0
|
|
|
|
block i32
|
|
|
|
local.get 0
|
2019-02-23 06:29:34 +08:00
|
|
|
br_on_exn 0, __cpp_exception
|
[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
2019-01-30 11:21:57 +08:00
|
|
|
rethrow
|
|
|
|
end_block
|
|
|
|
end_try
|
|
|
|
end_block
|
|
|
|
rethrow
|
|
|
|
end_try
|
|
|
|
end_try
|
|
|
|
end_function
|
|
|
|
|
|
|
|
|
|
|
|
# CHECK: test_annotation:
|
|
|
|
# CHECK: try
|
|
|
|
# CHECK-NEXT: br 0 # 0: down to label0
|
|
|
|
# CHECK-NEXT: catch # catch0:
|
|
|
|
# CHECK-NEXT: block
|
|
|
|
# CHECK-NEXT: br_if 0 # 0: down to label1
|
|
|
|
# CHECK-NEXT: loop # label2:
|
|
|
|
# CHECK-NEXT: br_if 1 # 1: down to label1
|
|
|
|
# CHECK-NEXT: end_loop
|
|
|
|
# CHECK-NEXT: end_block # label1:
|
|
|
|
# CHECK-NEXT: try
|
|
|
|
# CHECK-NEXT: rethrow # down to catch1
|
|
|
|
# CHECK-NEXT: catch # catch1:
|
|
|
|
# CHECK-NEXT: block
|
|
|
|
# CHECK-NEXT: try
|
|
|
|
# CHECK-NEXT: br 0 # 0: down to label5
|
|
|
|
# CHECK-NEXT: catch # catch2:
|
|
|
|
# CHECK-NEXT: local.set 0
|
|
|
|
# CHECK-NEXT: block i32
|
|
|
|
# CHECK-NEXT: local.get 0
|
2019-02-23 06:29:34 +08:00
|
|
|
# CHECK-NEXT: br_on_exn 0, __cpp_exception # 0: down to label6
|
[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
2019-01-30 11:21:57 +08:00
|
|
|
# CHECK-NEXT: rethrow # to caller
|
|
|
|
# CHECK-NEXT: end_block # label6:
|
|
|
|
# CHECK-NEXT: end_try # label5:
|
|
|
|
# CHECK-NEXT: end_block # label4:
|
|
|
|
# CHECK-NEXT: rethrow # to caller
|
|
|
|
# CHECK-NEXT: end_try # label3:
|
|
|
|
# CHECK-NEXT: end_try # label0:
|
|
|
|
# CHECK-NEXT: end_function
|
|
|
|
|