llvm.org GIT mirror llvm / f21a6b7
[WebAssembly] Add support for exception handling instructions Summary: This adds backend support for throw, rethrow, try, and try_end instructions. This needs the corresponding clang builtin support: https://reviews.llvm.org/D34783 This follows the Wasm exception handling proposal in https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md Reviewers: sunfish, dschuff Reviewed By: dschuff Subscribers: jfb, sbc100, jgravelle-google Differential Revision: https://reviews.llvm.org/D34826 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306774 91177308-0d34-0410-b5e6-96231b3b80d8 Heejin Ahn 2 years ago
3 changed file(s) with 47 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
1818 def int_wasm_current_memory : Intrinsic<[llvm_anyint_ty], [], [IntrReadMem]>;
1919 def int_wasm_grow_memory : Intrinsic<[llvm_anyint_ty], [LLVMMatchType<0>], []>;
2020
21 // Exception handling intrinsics
22 def int_wasm_throw: Intrinsic<[], [llvm_i32_ty, llvm_ptr_ty], [Throws]>;
23 def int_wasm_rethrow: Intrinsic<[], [], [Throws]>;
24
2125 }
5656 }
5757 } // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1
5858
59 // Placemarkers to indicate the start or end of a block or loop scope. These
60 // use/clobber VALUE_STACK to prevent them from being moved into the middle of
61 // an expression tree.
59 // Placemarkers to indicate the start or end of a block, loop, or try scope.
60 // These use/clobber VALUE_STACK to prevent them from being moved into the
61 // middle of an expression tree.
6262 let Uses = [VALUE_STACK], Defs = [VALUE_STACK] in {
6363 def BLOCK : I<(outs), (ins Signature:$sig), [], "block \t$sig", 0x02>;
6464 def LOOP : I<(outs), (ins Signature:$sig), [], "loop \t$sig", 0x03>;
65 def TRY : I<(outs), (ins Signature:$sig), [], "try \t$sig", 0x06>;
6566
66 // END_BLOCK, END_LOOP, and END_FUNCTION are represented with the same opcode
67 // in wasm.
67 // END_BLOCK, END_LOOP, END_TRY, and END_FUNCTION are represented with the same
68 // opcode in wasm.
6869 def END_BLOCK : I<(outs), (ins), [], "end_block", 0x0b>;
6970 def END_LOOP : I<(outs), (ins), [], "end_loop", 0x0b>;
71 def END_TRY : I<(outs), (ins), [], "end_try", 0x0b>;
7072 let isTerminator = 1, isBarrier = 1 in
7173 def END_FUNCTION : I<(outs), (ins), [], "end_function", 0x0b>;
7274 } // Uses = [VALUE_STACK], Defs = [VALUE_STACK]
111113
112114 def UNREACHABLE : I<(outs), (ins), [(trap)], "unreachable", 0x00>;
113115
116 def THROW_I32 : I<(outs), (ins i32imm:$tag, I32:$obj),
117 [(int_wasm_throw imm:$tag, I32:$obj)], "throw \t$tag, $obj",
118 0x08>;
119 def THROW_I64 : I<(outs), (ins i32imm:$tag, I64:$obj),
120 [(int_wasm_throw imm:$tag, I64:$obj)], "throw \t$tag, $obj",
121 0x08>;
122 def RETHROW : I<(outs), (ins i32imm:$rel_depth), [], "rethrow \t$rel_depth",
123 0x09>;
124
114125 } // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1
115126
116127 } // Defs = [ARGUMENTS]
128
129 // rethrow takes a relative depth as an argument, for which currently only 0 is
130 // possible for C++. Once other languages need depths other than 0, depths will
131 // be computed in CFGStackify.
132 def : Pat<(int_wasm_rethrow), (RETHROW 0)>;
0 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -disable-wasm-explicit-locals | FileCheck %s
1
2 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
3 target triple = "wasm32-unknown-unknown-wasm"
4
5 declare void @llvm.wasm.throw(i32, i8*)
6 declare void @llvm.wasm.rethrow()
7
8 ; CHECK-LABEL: throw:
9 ; CHECK-NEXT: i32.const $push0=, 0
10 ; CHECK-NEXT: throw 0, $pop0
11 define void @throw() {
12 call void @llvm.wasm.throw(i32 0, i8* null)
13 ret void
14 }
15
16 ; CHECK-LABEL: rethrow:
17 ; CHECK-NEXT: rethrow 0
18 define void @rethrow() {
19 call void @llvm.wasm.rethrow()
20 ret void
21 }