blob: 1c06b08597a014adea9f531dffa7dd1deb66acf5 [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 Gohmanfb3e0592015-11-25 19:36:19 +000015let Defs = [ARGUMENTS] in {
16
Dan Gohman950a13c2015-09-16 16:51:30 +000017let isBranch = 1, isTerminator = 1, hasCtrlDep = 1 in {
Dan Gohmanf0b165a2015-12-05 03:03:35 +000018// The condition operand is a boolean value which WebAssembly represents as i32.
19def BR_IF : I<(outs), (ins I32:$cond, bb_op:$dst),
20 [(brcond I32:$cond, bb:$dst)],
21 "br_if \t$cond, $dst">;
22let isCodeGenOnly = 1 in
23def BR_UNLESS : I<(outs), (ins I32:$cond, bb_op:$dst), [],
24 "br_unless\t$cond, $dst">;
Dan Gohman950a13c2015-09-16 16:51:30 +000025let isBarrier = 1 in {
26def BR : I<(outs), (ins bb_op:$dst),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000027 [(br bb:$dst)],
Dan Gohman94ef41f2015-11-18 17:05:35 +000028 "br \t$dst">;
Dan Gohman950a13c2015-09-16 16:51:30 +000029} // isBarrier = 1
30} // isBranch = 1, isTerminator = 1, hasCtrlDep = 1
31
Dan Gohmanf0b165a2015-12-05 03:03:35 +000032} // Defs = [ARGUMENTS]
33
34def : Pat<(brcond (i32 (setne I32:$cond, 0)), bb:$dst),
35 (BR_IF I32:$cond, bb_op:$dst)>;
36def : Pat<(brcond (i32 (seteq I32:$cond, 0)), bb:$dst),
37 (BR_UNLESS I32:$cond, bb_op:$dst)>;
38
39let Defs = [ARGUMENTS] in {
40
Dan Gohman950a13c2015-09-16 16:51:30 +000041// TODO: SelectionDAG's lowering insists on using a pointer as the index for
Dan Gohmanbb7ce8e2015-11-20 03:02:49 +000042// jump tables, so in practice we don't ever use TABLESWITCH_I64 in wasm32 mode
Dan Gohman950a13c2015-09-16 16:51:30 +000043// currently.
Dan Gohman85159ca2016-01-12 01:45:12 +000044// Set TSFlags{0} to 1 to indicate that the variable_ops are immediates.
Dan Gohman950a13c2015-09-16 16:51:30 +000045let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
Dan Gohman770f0d02015-12-06 19:34:57 +000046def TABLESWITCH_I32 : I<(outs), (ins I32:$index, bb_op:$default, variable_ops),
47 [(WebAssemblytableswitch I32:$index, bb:$default)],
Dan Gohman85159ca2016-01-12 01:45:12 +000048 "tableswitch\t$index, $default"> {
49 let TSFlags{0} = 1;
50}
Dan Gohman770f0d02015-12-06 19:34:57 +000051def TABLESWITCH_I64 : I<(outs), (ins I64:$index, bb_op:$default, variable_ops),
52 [(WebAssemblytableswitch I64:$index, bb:$default)],
Dan Gohman85159ca2016-01-12 01:45:12 +000053 "tableswitch\t$index, $default"> {
54 let TSFlags{0} = 1;
55}
Dan Gohman950a13c2015-09-16 16:51:30 +000056} // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1
57
Dan Gohman8887d1f2015-12-25 00:31:02 +000058// 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.
61let Uses = [EXPR_STACK], Defs = [EXPR_STACK] in {
Dan Gohman94ef41f2015-11-18 17:05:35 +000062def BLOCK : I<(outs), (ins bb_op:$dst), [], "block \t$dst">;
63def LOOP : I<(outs), (ins bb_op:$dst), [], "loop \t$dst">;
Dan Gohman8887d1f2015-12-25 00:31:02 +000064} // Uses = [EXPR_STACK], Defs = [EXPR_STACK]
Dan Gohman950a13c2015-09-16 16:51:30 +000065
Dan Gohmanf6857222015-11-23 19:12:37 +000066// 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.
68let isTerminator = 1, hasCtrlDep = 1 in
69def LOOP_END : I<(outs), (ins), []>;
70
JF Bastien8f9aea02015-08-01 04:48:44 +000071multiclass RETURN<WebAssemblyRegClass vt> {
Dan Gohmanaf29bd42015-11-05 20:42:30 +000072 def RETURN_#vt : I<(outs), (ins vt:$val), [(WebAssemblyreturn vt:$val)],
Dan Gohman94ef41f2015-11-18 17:05:35 +000073 "return \t$val">;
JF Bastien8f9aea02015-08-01 04:48:44 +000074}
Derek Schuffffa143c2015-11-10 00:30:57 +000075
76let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
77let isReturn = 1 in {
Dan Gohmand0bf9812015-09-26 01:09:44 +000078 defm : RETURN<I32>;
79 defm : RETURN<I64>;
80 defm : RETURN<F32>;
81 defm : RETURN<F64>;
Dan Gohmanaf29bd42015-11-05 20:42:30 +000082 def RETURN_VOID : I<(outs), (ins), [(WebAssemblyreturn)], "return">;
Derek Schuffffa143c2015-11-10 00:30:57 +000083} // isReturn = 1
84 def UNREACHABLE : I<(outs), (ins), [(trap)], "unreachable">;
85} // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1
Dan Gohmanfb3e0592015-11-25 19:36:19 +000086
87} // Defs = [ARGUMENTS]