blob: d1af73137debd0189d3110256775da5da55374bd [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.
Dan Gohman06b49582016-02-08 21:50:13 +000019def BR_IF : I<(outs), (ins bb_op:$dst, I32:$cond),
Dan Gohmanf0b165a2015-12-05 03:03:35 +000020 [(brcond I32:$cond, bb:$dst)],
Dan Gohman5a68ec72016-10-05 21:24:08 +000021 "br_if \t$dst, $cond", 0x07>;
Dan Gohmanf0b165a2015-12-05 03:03:35 +000022let isCodeGenOnly = 1 in
Dan Gohman5a68ec72016-10-05 21:24:08 +000023def BR_UNLESS : I<(outs), (ins bb_op:$dst, I32:$cond), []>;
Dan Gohman950a13c2015-09-16 16:51:30 +000024let isBarrier = 1 in {
25def BR : I<(outs), (ins bb_op:$dst),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000026 [(br bb:$dst)],
Dan Gohman5a68ec72016-10-05 21:24:08 +000027 "br \t$dst", 0x06>;
Dan Gohman950a13c2015-09-16 16:51:30 +000028} // isBarrier = 1
29} // isBranch = 1, isTerminator = 1, hasCtrlDep = 1
30
Dan Gohmanf0b165a2015-12-05 03:03:35 +000031} // Defs = [ARGUMENTS]
32
33def : Pat<(brcond (i32 (setne I32:$cond, 0)), bb:$dst),
Dan Gohman06b49582016-02-08 21:50:13 +000034 (BR_IF bb_op:$dst, I32:$cond)>;
Dan Gohmanf0b165a2015-12-05 03:03:35 +000035def : Pat<(brcond (i32 (seteq I32:$cond, 0)), bb:$dst),
Dan Gohman06b49582016-02-08 21:50:13 +000036 (BR_UNLESS bb_op:$dst, I32:$cond)>;
Dan Gohmanf0b165a2015-12-05 03:03:35 +000037
38let Defs = [ARGUMENTS] in {
39
Dan Gohman950a13c2015-09-16 16:51:30 +000040// TODO: SelectionDAG's lowering insists on using a pointer as the index for
Dan Gohman14026062016-03-08 03:18:12 +000041// jump tables, so in practice we don't ever use BR_TABLE_I64 in wasm32 mode
Dan Gohman950a13c2015-09-16 16:51:30 +000042// currently.
Dan Gohman85159ca2016-01-12 01:45:12 +000043// Set TSFlags{0} to 1 to indicate that the variable_ops are immediates.
Dan Gohman3469ee12016-01-12 20:30:51 +000044// Set TSFlags{1} to 1 to indicate that the immediates represent labels.
Dan Gohman950a13c2015-09-16 16:51:30 +000045let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
Dan Gohman14026062016-03-08 03:18:12 +000046def BR_TABLE_I32 : I<(outs), (ins I32:$index, variable_ops),
47 [(WebAssemblybr_table I32:$index)],
Dan Gohman5a68ec72016-10-05 21:24:08 +000048 "br_table \t$index", 0x08> {
Dan Gohman85159ca2016-01-12 01:45:12 +000049 let TSFlags{0} = 1;
Dan Gohman3469ee12016-01-12 20:30:51 +000050 let TSFlags{1} = 1;
Dan Gohman85159ca2016-01-12 01:45:12 +000051}
Dan Gohman14026062016-03-08 03:18:12 +000052def BR_TABLE_I64 : I<(outs), (ins I64:$index, variable_ops),
53 [(WebAssemblybr_table I64:$index)],
54 "br_table \t$index"> {
Dan Gohman85159ca2016-01-12 01:45:12 +000055 let TSFlags{0} = 1;
Dan Gohman3469ee12016-01-12 20:30:51 +000056 let TSFlags{1} = 1;
Dan Gohman85159ca2016-01-12 01:45:12 +000057}
Dan Gohman950a13c2015-09-16 16:51:30 +000058} // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1
59
Dan Gohman1d68e80f2016-01-12 19:14:46 +000060// Placemarkers to indicate the start or end of a block or loop scope. These
Dan Gohmane0405332016-10-03 22:43:53 +000061// use/clobber VALUE_STACK to prevent them from being moved into the middle of
Dan Gohman8887d1f2015-12-25 00:31:02 +000062// an expression tree.
Dan Gohmane0405332016-10-03 22:43:53 +000063let Uses = [VALUE_STACK], Defs = [VALUE_STACK] in {
Dan Gohman5a68ec72016-10-05 21:24:08 +000064def BLOCK : I<(outs), (ins), [], "block", 0x01>;
65def LOOP : I<(outs), (ins), [], "loop", 0x02>;
Dan Gohman1d68e80f2016-01-12 19:14:46 +000066def END_BLOCK : I<(outs), (ins), [], "end_block">;
67def END_LOOP : I<(outs), (ins), [], "end_loop">;
Dan Gohmane0405332016-10-03 22:43:53 +000068} // Uses = [VALUE_STACK], Defs = [VALUE_STACK]
Dan Gohman950a13c2015-09-16 16:51:30 +000069
JF Bastien8f9aea02015-08-01 04:48:44 +000070multiclass RETURN<WebAssemblyRegClass vt> {
Dan Gohmanaf29bd42015-11-05 20:42:30 +000071 def RETURN_#vt : I<(outs), (ins vt:$val), [(WebAssemblyreturn vt:$val)],
Dan Gohman94ef41f2015-11-18 17:05:35 +000072 "return \t$val">;
Dan Gohmanb7c24002016-05-21 00:21:56 +000073 // Equivalent to RETURN_#vt, for use at the end of a function when wasm
74 // semantics return by falling off the end of the block.
75 let isCodeGenOnly = 1 in
76 def FALLTHROUGH_RETURN_#vt : I<(outs), (ins vt:$val), []>;
JF Bastien8f9aea02015-08-01 04:48:44 +000077}
Derek Schuffffa143c2015-11-10 00:30:57 +000078
Derek Schuff39bf39f2016-08-02 23:16:09 +000079multiclass SIMD_RETURN<ValueType vt> {
80 def RETURN_#vt : SIMD_I<(outs), (ins V128:$val),
81 [(WebAssemblyreturn (vt V128:$val))],
82 "return \t$val">;
83 // Equivalent to RETURN_#vt, for use at the end of a function when wasm
84 // semantics return by falling off the end of the block.
85 let isCodeGenOnly = 1 in
86 def FALLTHROUGH_RETURN_#vt : SIMD_I<(outs), (ins V128:$val), []>;
87}
88
Derek Schuffffa143c2015-11-10 00:30:57 +000089let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
Dan Gohman9850e872016-10-03 21:33:09 +000090
Derek Schuffffa143c2015-11-10 00:30:57 +000091let isReturn = 1 in {
Dan Gohmand0bf9812015-09-26 01:09:44 +000092 defm : RETURN<I32>;
93 defm : RETURN<I64>;
94 defm : RETURN<F32>;
95 defm : RETURN<F64>;
Derek Schuff39bf39f2016-08-02 23:16:09 +000096 defm : SIMD_RETURN<v16i8>;
97 defm : SIMD_RETURN<v8i16>;
98 defm : SIMD_RETURN<v4i32>;
99 defm : SIMD_RETURN<v4f32>;
100
Dan Gohmanaf29bd42015-11-05 20:42:30 +0000101 def RETURN_VOID : I<(outs), (ins), [(WebAssemblyreturn)], "return">;
Dan Gohmanb7c24002016-05-21 00:21:56 +0000102
103 // This is to RETURN_VOID what FALLTHROUGH_RETURN_#vt is to RETURN_#vt.
104 let isCodeGenOnly = 1 in
105 def FALLTHROUGH_RETURN_VOID : I<(outs), (ins), []>;
Derek Schuffffa143c2015-11-10 00:30:57 +0000106} // isReturn = 1
Dan Gohman9850e872016-10-03 21:33:09 +0000107
108def UNREACHABLE : I<(outs), (ins), [(trap)], "unreachable">;
109
Derek Schuffffa143c2015-11-10 00:30:57 +0000110} // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000111
112} // Defs = [ARGUMENTS]