• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1//===- 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
15let Defs = [ARGUMENTS] in {
16
17let isBranch = 1, isTerminator = 1, hasCtrlDep = 1 in {
18// The condition operand is a boolean value which WebAssembly represents as i32.
19def BR_IF : I<(outs), (ins bb_op:$dst, I32:$cond),
20              [(brcond I32:$cond, bb:$dst)],
21               "br_if   \t$dst, $cond">;
22let isCodeGenOnly = 1 in
23def BR_UNLESS : I<(outs), (ins bb_op:$dst, I32:$cond), [],
24                   "br_unless\t$dst, $cond">;
25let isBarrier = 1 in {
26def BR   : I<(outs), (ins bb_op:$dst),
27             [(br bb:$dst)],
28             "br      \t$dst">;
29} // isBarrier = 1
30} // isBranch = 1, isTerminator = 1, hasCtrlDep = 1
31
32} // Defs = [ARGUMENTS]
33
34def : Pat<(brcond (i32 (setne I32:$cond, 0)), bb:$dst),
35          (BR_IF bb_op:$dst, I32:$cond)>;
36def : Pat<(brcond (i32 (seteq I32:$cond, 0)), bb:$dst),
37          (BR_UNLESS bb_op:$dst, I32:$cond)>;
38
39let Defs = [ARGUMENTS] in {
40
41// TODO: SelectionDAG's lowering insists on using a pointer as the index for
42// jump tables, so in practice we don't ever use BR_TABLE_I64 in wasm32 mode
43// currently.
44// Set TSFlags{0} to 1 to indicate that the variable_ops are immediates.
45// Set TSFlags{1} to 1 to indicate that the immediates represent labels.
46let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
47def BR_TABLE_I32 : I<(outs), (ins I32:$index, variable_ops),
48                     [(WebAssemblybr_table I32:$index)],
49                     "br_table \t$index"> {
50  let TSFlags{0} = 1;
51  let TSFlags{1} = 1;
52}
53def BR_TABLE_I64 : I<(outs), (ins I64:$index, variable_ops),
54                     [(WebAssemblybr_table I64:$index)],
55                     "br_table \t$index"> {
56  let TSFlags{0} = 1;
57  let TSFlags{1} = 1;
58}
59} // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1
60
61// Placemarkers to indicate the start or end of a block or loop scope. These
62// use/clobber EXPR_STACK to prevent them from being moved into the middle of
63// an expression tree.
64let Uses = [EXPR_STACK], Defs = [EXPR_STACK] in {
65def BLOCK     : I<(outs), (ins), [], "block">;
66def LOOP      : I<(outs), (ins), [], "loop">;
67def END_BLOCK : I<(outs), (ins), [], "end_block">;
68def END_LOOP  : I<(outs), (ins), [], "end_loop">;
69} // Uses = [EXPR_STACK], Defs = [EXPR_STACK]
70
71multiclass RETURN<WebAssemblyRegClass vt> {
72  def RETURN_#vt : I<(outs), (ins vt:$val), [(WebAssemblyreturn vt:$val)],
73                     "return  \t$val">;
74  // Equivalent to RETURN_#vt, for use at the end of a function when wasm
75  // semantics return by falling off the end of the block.
76  let isCodeGenOnly = 1 in
77  def FALLTHROUGH_RETURN_#vt : I<(outs), (ins vt:$val), []>;
78}
79
80let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
81let isReturn = 1 in {
82  defm : RETURN<I32>;
83  defm : RETURN<I64>;
84  defm : RETURN<F32>;
85  defm : RETURN<F64>;
86  def RETURN_VOID : I<(outs), (ins), [(WebAssemblyreturn)], "return">;
87
88  // This is to RETURN_VOID what FALLTHROUGH_RETURN_#vt is to RETURN_#vt.
89  let isCodeGenOnly = 1 in
90  def FALLTHROUGH_RETURN_VOID : I<(outs), (ins), []>;
91} // isReturn = 1
92  def UNREACHABLE : I<(outs), (ins), [(trap)], "unreachable">;
93} // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1
94
95} // Defs = [ARGUMENTS]
96