blob: 4fa567c98d72aee864abd55b20f6cbc8329d100b [file] [log] [blame]
JF Bastien600aee92015-07-31 17:53:38 +00001//===- 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/*
16 * TODO(jfb): Add the following.
17 *
18 * block: a fixed-length sequence of statements
19 * if: if statement
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
26 */
27
Dan Gohman950a13c2015-09-16 16:51:30 +000028let isBranch = 1, isTerminator = 1, hasCtrlDep = 1 in {
Dan Gohmand0bf9812015-09-26 01:09:44 +000029def BRIF : I<(outs), (ins bb_op:$dst, I32:$a),
30 [(brcond I32:$a, bb:$dst)]>;
Dan Gohman950a13c2015-09-16 16:51:30 +000031let isBarrier = 1 in {
32def BR : I<(outs), (ins bb_op:$dst),
33 [(br bb:$dst)]>;
34} // isBarrier = 1
35} // isBranch = 1, isTerminator = 1, hasCtrlDep = 1
36
37// TODO: SelectionDAG's lowering insists on using a pointer as the index for
38// jump tables, so in practice we don't ever use SWITCH_I64 in wasm32 mode
39// currently.
40let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
Dan Gohmand0bf9812015-09-26 01:09:44 +000041def SWITCH_I32 : I<(outs), (ins I32:$index, variable_ops),
42 [(WebAssemblyswitch I32:$index)]>;
43def SWITCH_I64 : I<(outs), (ins I64:$index, variable_ops),
44 [(WebAssemblyswitch I64:$index)]>;
Dan Gohman950a13c2015-09-16 16:51:30 +000045} // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1
46
47// Placemarkers to indicate the start of a block or loop scope.
48def BLOCK : I<(outs), (ins bb_op:$dst), []>;
49def LOOP : I<(outs), (ins bb_op:$dst), []>;
50
JF Bastien8f9aea02015-08-01 04:48:44 +000051multiclass RETURN<WebAssemblyRegClass vt> {
52 def RETURN_#vt : I<(outs), (ins vt:$val), [(WebAssemblyreturn vt:$val)]>;
53}
JF Bastienaf111db2015-08-24 22:16:48 +000054let isReturn = 1, isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
Dan Gohmand0bf9812015-09-26 01:09:44 +000055 defm : RETURN<I32>;
56 defm : RETURN<I64>;
57 defm : RETURN<F32>;
58 defm : RETURN<F64>;
JF Bastien8f9aea02015-08-01 04:48:44 +000059 def RETURN_VOID : I<(outs), (ins), [(WebAssemblyreturn)]>;
JF Bastienaf111db2015-08-24 22:16:48 +000060} // isReturn = 1, isTerminator = 1, hasCtrlDep = 1, isBarrier = 1