blob: dd63e98efe993814d897886d9cd2c9471ac38fcc [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
Dan Gohman950a13c2015-09-16 16:51:30 +000015let isBranch = 1, isTerminator = 1, hasCtrlDep = 1 in {
Derek Schuff4ed47782015-11-16 21:04:51 +000016def BR_IF : I<(outs), (ins I32:$a, bb_op:$dst),
Dan Gohman231244c2015-11-13 00:46:31 +000017 [(brcond I32:$a, bb:$dst)],
Derek Schuff4ed47782015-11-16 21:04:51 +000018 "br_if\t$a, $dst">;
Dan Gohman950a13c2015-09-16 16:51:30 +000019let isBarrier = 1 in {
20def BR : I<(outs), (ins bb_op:$dst),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000021 [(br bb:$dst)],
Dan Gohman1031d4a2015-11-15 15:34:19 +000022 "br\t$dst">;
Dan Gohman950a13c2015-09-16 16:51:30 +000023} // 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.
29let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
Dan Gohmand0bf9812015-09-26 01:09:44 +000030def SWITCH_I32 : I<(outs), (ins I32:$index, variable_ops),
Dan Gohmancf4748f2015-11-12 17:04:33 +000031 [(WebAssemblyswitch I32:$index)],
Dan Gohman1031d4a2015-11-15 15:34:19 +000032 "switch\t$index">;
Dan Gohmand0bf9812015-09-26 01:09:44 +000033def SWITCH_I64 : I<(outs), (ins I64:$index, variable_ops),
Dan Gohmancf4748f2015-11-12 17:04:33 +000034 [(WebAssemblyswitch I64:$index)],
Dan Gohman1031d4a2015-11-15 15:34:19 +000035 "switch\t$index">;
Dan Gohman950a13c2015-09-16 16:51:30 +000036} // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1
37
38// Placemarkers to indicate the start of a block or loop scope.
Dan Gohman1031d4a2015-11-15 15:34:19 +000039def BLOCK : I<(outs), (ins bb_op:$dst), [], "block\t$dst">;
40def LOOP : I<(outs), (ins bb_op:$dst), [], "loop\t$dst">;
Dan Gohman950a13c2015-09-16 16:51:30 +000041
JF Bastien8f9aea02015-08-01 04:48:44 +000042multiclass RETURN<WebAssemblyRegClass vt> {
Dan Gohmanaf29bd42015-11-05 20:42:30 +000043 def RETURN_#vt : I<(outs), (ins vt:$val), [(WebAssemblyreturn vt:$val)],
Dan Gohman1031d4a2015-11-15 15:34:19 +000044 "return\t$val">;
JF Bastien8f9aea02015-08-01 04:48:44 +000045}
Derek Schuffffa143c2015-11-10 00:30:57 +000046
47let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
48let isReturn = 1 in {
Dan Gohmand0bf9812015-09-26 01:09:44 +000049 defm : RETURN<I32>;
50 defm : RETURN<I64>;
51 defm : RETURN<F32>;
52 defm : RETURN<F64>;
Dan Gohmanaf29bd42015-11-05 20:42:30 +000053 def RETURN_VOID : I<(outs), (ins), [(WebAssemblyreturn)], "return">;
Derek Schuffffa143c2015-11-10 00:30:57 +000054} // isReturn = 1
55 def UNREACHABLE : I<(outs), (ins), [(trap)], "unreachable">;
56} // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1