blob: 7fa4c5613e96f24778da191f92d347c14d8e79f9 [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)],
Dan Gohman94ef41f2015-11-18 17:05:35 +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 Gohman94ef41f2015-11-18 17:05:35 +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
Dan Gohmanbb7ce8e2015-11-20 03:02:49 +000027// jump tables, so in practice we don't ever use TABLESWITCH_I64 in wasm32 mode
Dan Gohman950a13c2015-09-16 16:51:30 +000028// currently.
29let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
Dan Gohmanbb7ce8e2015-11-20 03:02:49 +000030def TABLESWITCH_I32 : I<(outs), (ins I32:$index, variable_ops),
31 [(WebAssemblytableswitch I32:$index)],
32 "tableswitch\t$index">;
33def TABLESWITCH_I64 : I<(outs), (ins I64:$index, variable_ops),
34 [(WebAssemblytableswitch I64:$index)],
35 "tableswitch\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 Gohman94ef41f2015-11-18 17:05:35 +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
Dan Gohmanf6857222015-11-23 19:12:37 +000042// No-op to indicate to the AsmPrinter that a loop ends here, so a
43// basic block label is needed even if it wouldn't otherwise appear so.
44let isTerminator = 1, hasCtrlDep = 1 in
45def LOOP_END : I<(outs), (ins), []>;
46
JF Bastien8f9aea02015-08-01 04:48:44 +000047multiclass RETURN<WebAssemblyRegClass vt> {
Dan Gohmanaf29bd42015-11-05 20:42:30 +000048 def RETURN_#vt : I<(outs), (ins vt:$val), [(WebAssemblyreturn vt:$val)],
Dan Gohman94ef41f2015-11-18 17:05:35 +000049 "return \t$val">;
JF Bastien8f9aea02015-08-01 04:48:44 +000050}
Derek Schuffffa143c2015-11-10 00:30:57 +000051
52let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
53let isReturn = 1 in {
Dan Gohmand0bf9812015-09-26 01:09:44 +000054 defm : RETURN<I32>;
55 defm : RETURN<I64>;
56 defm : RETURN<F32>;
57 defm : RETURN<F64>;
Dan Gohmanaf29bd42015-11-05 20:42:30 +000058 def RETURN_VOID : I<(outs), (ins), [(WebAssemblyreturn)], "return">;
Derek Schuffffa143c2015-11-10 00:30:57 +000059} // isReturn = 1
60 def UNREACHABLE : I<(outs), (ins), [(trap)], "unreachable">;
61} // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1