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 //===----------------------------------------------------------------------===//
15 let Defs = [ARGUMENTS] in {
17 let isBranch = 1, isTerminator = 1, hasCtrlDep = 1 in {
18 // The condition operand is a boolean value which WebAssembly represents as i32.
19 def BR_IF : I<(outs), (ins I32:$cond, bb_op:$dst),
20 [(brcond I32:$cond, bb:$dst)],
21 "br_if \t$cond, $dst">;
22 let isCodeGenOnly = 1 in
23 def BR_UNLESS : I<(outs), (ins I32:$cond, bb_op:$dst), [],
24 "br_unless\t$cond, $dst">;
25 let isBarrier = 1 in {
26 def BR : I<(outs), (ins bb_op:$dst),
30 } // isBranch = 1, isTerminator = 1, hasCtrlDep = 1
32 } // Defs = [ARGUMENTS]
34 def : Pat<(brcond (i32 (setne I32:$cond, 0)), bb:$dst),
35 (BR_IF I32:$cond, bb_op:$dst)>;
36 def : Pat<(brcond (i32 (seteq I32:$cond, 0)), bb:$dst),
37 (BR_UNLESS I32:$cond, bb_op:$dst)>;
39 let Defs = [ARGUMENTS] in {
41 // TODO: SelectionDAG's lowering insists on using a pointer as the index for
42 // jump tables, so in practice we don't ever use TABLESWITCH_I64 in wasm32 mode
44 // Set TSFlags{0} to 1 to indicate that the variable_ops are immediates.
45 let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
46 def TABLESWITCH_I32 : I<(outs), (ins I32:$index, bb_op:$default, variable_ops),
47 [(WebAssemblytableswitch I32:$index, bb:$default)],
48 "tableswitch\t$index, $default"> {
51 def TABLESWITCH_I64 : I<(outs), (ins I64:$index, bb_op:$default, variable_ops),
52 [(WebAssemblytableswitch I64:$index, bb:$default)],
53 "tableswitch\t$index, $default"> {
56 } // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1
58 // Placemarkers to indicate the start of a block or loop scope. These
59 // use/clobber EXPR_STACK to prevent them from being moved into the middle of
60 // an expression tree.
61 let Uses = [EXPR_STACK], Defs = [EXPR_STACK] in {
62 def BLOCK : I<(outs), (ins bb_op:$dst), [], "block \t$dst">;
63 def LOOP : I<(outs), (ins bb_op:$dst), [], "loop \t$dst">;
64 } // Uses = [EXPR_STACK], Defs = [EXPR_STACK]
66 // No-op to indicate to the AsmPrinter that a loop ends here, so a
67 // basic block label is needed even if it wouldn't otherwise appear so.
68 let isTerminator = 1, hasCtrlDep = 1 in
69 def LOOP_END : I<(outs), (ins), []>;
71 multiclass RETURN<WebAssemblyRegClass vt> {
72 def RETURN_#vt : I<(outs), (ins vt:$val), [(WebAssemblyreturn vt:$val)],
76 let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
82 def RETURN_VOID : I<(outs), (ins), [(WebAssemblyreturn)], "return">;
84 def UNREACHABLE : I<(outs), (ins), [(trap)], "unreachable">;
85 } // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1
87 } // Defs = [ARGUMENTS]