dd63e98efe993814d897886d9cd2c9471ac38fcc
[oota-llvm.git] / lib / Target / WebAssembly / WebAssemblyInstrControl.td
1 //===- WebAssemblyInstrControl.td-WebAssembly control-flow ------*- tablegen -*-
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// \brief WebAssembly control-flow code-gen constructs.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 let isBranch = 1, isTerminator = 1, hasCtrlDep = 1 in {
16 def BR_IF : I<(outs), (ins I32:$a, bb_op:$dst),
17               [(brcond I32:$a, bb:$dst)],
18                "br_if\t$a, $dst">;
19 let isBarrier = 1 in {
20 def BR   : I<(outs), (ins bb_op:$dst),
21              [(br bb:$dst)],
22              "br\t$dst">;
23 } // isBarrier = 1
24 } // isBranch = 1, isTerminator = 1, hasCtrlDep = 1
25
26 // TODO: SelectionDAG's lowering insists on using a pointer as the index for
27 // jump tables, so in practice we don't ever use SWITCH_I64 in wasm32 mode
28 // currently.
29 let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
30 def SWITCH_I32 : I<(outs), (ins I32:$index, variable_ops),
31                    [(WebAssemblyswitch I32:$index)],
32                    "switch\t$index">;
33 def SWITCH_I64 : I<(outs), (ins I64:$index, variable_ops),
34                    [(WebAssemblyswitch I64:$index)],
35                    "switch\t$index">;
36 } // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1
37
38 // Placemarkers to indicate the start of a block or loop scope.
39 def BLOCK     : I<(outs), (ins bb_op:$dst), [], "block\t$dst">;
40 def LOOP      : I<(outs), (ins bb_op:$dst), [], "loop\t$dst">;
41
42 multiclass RETURN<WebAssemblyRegClass vt> {
43   def RETURN_#vt : I<(outs), (ins vt:$val), [(WebAssemblyreturn vt:$val)],
44                      "return\t$val">;
45 }
46
47 let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
48 let isReturn = 1 in {
49   defm : RETURN<I32>;
50   defm : RETURN<I64>;
51   defm : RETURN<F32>;
52   defm : RETURN<F64>;
53   def RETURN_VOID : I<(outs), (ins), [(WebAssemblyreturn)], "return">;
54 } // isReturn = 1
55   def UNREACHABLE : I<(outs), (ins), [(trap)], "unreachable">;
56 } // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1