1 //===- WebAssemblyInstrControl.td-WebAssembly control-flow ------*- tablegen -*-
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief WebAssembly control-flow code-gen constructs.
13 //===----------------------------------------------------------------------===//
16 * TODO(jfb): Add the following.
18 * block: a fixed-length sequence of statements
20 * do_while: do while statement, basically a loop with a conditional branch
21 * forever: infinite loop statement (like while (1)), basically an unconditional
22 * branch (back to the top of the loop)
23 * continue: continue to start of nested loop
24 * break: break to end from nested loop or block
25 * switch: switch statement with fallthrough
28 let isBranch = 1, isTerminator = 1, hasCtrlDep = 1 in {
29 def BR_IF_ : I<(outs), (ins bb_op:$dst, I32:$a),
30 [(brcond I32:$a, bb:$dst)],
32 let isBarrier = 1 in {
33 def BR : I<(outs), (ins bb_op:$dst),
37 } // isBranch = 1, isTerminator = 1, hasCtrlDep = 1
39 // TODO: SelectionDAG's lowering insists on using a pointer as the index for
40 // jump tables, so in practice we don't ever use SWITCH_I64 in wasm32 mode
42 let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
43 def SWITCH_I32 : I<(outs), (ins I32:$index, variable_ops),
44 [(WebAssemblyswitch I32:$index)]>;
45 def SWITCH_I64 : I<(outs), (ins I64:$index, variable_ops),
46 [(WebAssemblyswitch I64:$index)]>;
47 } // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1
49 // Placemarkers to indicate the start of a block or loop scope.
50 def BLOCK : I<(outs), (ins bb_op:$dst), [], "block $dst">;
51 def LOOP : I<(outs), (ins bb_op:$dst), [], "loop $dst">;
53 multiclass RETURN<WebAssemblyRegClass vt> {
54 def RETURN_#vt : I<(outs), (ins vt:$val), [(WebAssemblyreturn vt:$val)],
58 let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
64 def RETURN_VOID : I<(outs), (ins), [(WebAssemblyreturn)], "return">;
66 def UNREACHABLE : I<(outs), (ins), [(trap)], "unreachable">;
67 } // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1