blob: 840f7d669314ac7d9101e66ba9bf0dee43607620 [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 {
Derek Schuff4ed47782015-11-16 21:04:51 +000018def BR_IF : I<(outs), (ins I32:$a, bb_op:$dst),
Dan Gohman231244c2015-11-13 00:46:31 +000019 [(brcond I32:$a, bb:$dst)],
Dan Gohman94ef41f2015-11-18 17:05:35 +000020 "br_if \t$a, $dst">;
Dan Gohman950a13c2015-09-16 16:51:30 +000021let isBarrier = 1 in {
22def BR : I<(outs), (ins bb_op:$dst),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000023 [(br bb:$dst)],
Dan Gohman94ef41f2015-11-18 17:05:35 +000024 "br \t$dst">;
Dan Gohman950a13c2015-09-16 16:51:30 +000025} // isBarrier = 1
26} // isBranch = 1, isTerminator = 1, hasCtrlDep = 1
27
28// TODO: SelectionDAG's lowering insists on using a pointer as the index for
Dan Gohmanbb7ce8e2015-11-20 03:02:49 +000029// jump tables, so in practice we don't ever use TABLESWITCH_I64 in wasm32 mode
Dan Gohman950a13c2015-09-16 16:51:30 +000030// currently.
31let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
Dan Gohmanbb7ce8e2015-11-20 03:02:49 +000032def TABLESWITCH_I32 : I<(outs), (ins I32:$index, variable_ops),
33 [(WebAssemblytableswitch I32:$index)],
34 "tableswitch\t$index">;
35def TABLESWITCH_I64 : I<(outs), (ins I64:$index, variable_ops),
36 [(WebAssemblytableswitch I64:$index)],
37 "tableswitch\t$index">;
Dan Gohman950a13c2015-09-16 16:51:30 +000038} // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1
39
40// Placemarkers to indicate the start of a block or loop scope.
Dan Gohman94ef41f2015-11-18 17:05:35 +000041def BLOCK : I<(outs), (ins bb_op:$dst), [], "block \t$dst">;
42def LOOP : I<(outs), (ins bb_op:$dst), [], "loop \t$dst">;
Dan Gohman950a13c2015-09-16 16:51:30 +000043
Dan Gohmanf6857222015-11-23 19:12:37 +000044// No-op to indicate to the AsmPrinter that a loop ends here, so a
45// basic block label is needed even if it wouldn't otherwise appear so.
46let isTerminator = 1, hasCtrlDep = 1 in
47def LOOP_END : I<(outs), (ins), []>;
48
JF Bastien8f9aea02015-08-01 04:48:44 +000049multiclass RETURN<WebAssemblyRegClass vt> {
Dan Gohmanaf29bd42015-11-05 20:42:30 +000050 def RETURN_#vt : I<(outs), (ins vt:$val), [(WebAssemblyreturn vt:$val)],
Dan Gohman94ef41f2015-11-18 17:05:35 +000051 "return \t$val">;
JF Bastien8f9aea02015-08-01 04:48:44 +000052}
Derek Schuffffa143c2015-11-10 00:30:57 +000053
54let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
55let isReturn = 1 in {
Dan Gohmand0bf9812015-09-26 01:09:44 +000056 defm : RETURN<I32>;
57 defm : RETURN<I64>;
58 defm : RETURN<F32>;
59 defm : RETURN<F64>;
Dan Gohmanaf29bd42015-11-05 20:42:30 +000060 def RETURN_VOID : I<(outs), (ins), [(WebAssemblyreturn)], "return">;
Derek Schuffffa143c2015-11-10 00:30:57 +000061} // isReturn = 1
62 def UNREACHABLE : I<(outs), (ins), [(trap)], "unreachable">;
63} // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1
Dan Gohmanfb3e0592015-11-25 19:36:19 +000064
65} // Defs = [ARGUMENTS]