JF Bastien | 600aee9 | 2015-07-31 17:53:38 +0000 | [diff] [blame] | 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 | |
| 15 | /* |
| 16 | * TODO(jfb): Add the following. |
| 17 | * |
| 18 | * block: a fixed-length sequence of statements |
| 19 | * if: if statement |
| 20 | * do_while: do while statement, basically a loop with a conditional branch |
| 21 | * forever: infinite loop statement (like while (1)), basically an unconditional |
| 22 | * branch (back to the top of the loop) |
| 23 | * continue: continue to start of nested loop |
| 24 | * break: break to end from nested loop or block |
| 25 | * switch: switch statement with fallthrough |
| 26 | */ |
| 27 | |
Dan Gohman | 950a13c | 2015-09-16 16:51:30 +0000 | [diff] [blame] | 28 | let isBranch = 1, isTerminator = 1, hasCtrlDep = 1 in { |
JF Bastien | 3b0177c | 2015-10-20 00:37:42 +0000 | [diff] [blame] | 29 | def BR_IF_ : I<(outs), (ins bb_op:$dst, I32:$a), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 30 | [(brcond I32:$a, bb:$dst)], |
| 31 | "br_if $dst, $a">; |
Dan Gohman | 950a13c | 2015-09-16 16:51:30 +0000 | [diff] [blame] | 32 | let isBarrier = 1 in { |
| 33 | def BR : I<(outs), (ins bb_op:$dst), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 34 | [(br bb:$dst)], |
| 35 | "br $dst">; |
Dan Gohman | 950a13c | 2015-09-16 16:51:30 +0000 | [diff] [blame] | 36 | } // isBarrier = 1 |
| 37 | } // isBranch = 1, isTerminator = 1, hasCtrlDep = 1 |
| 38 | |
| 39 | // TODO: SelectionDAG's lowering insists on using a pointer as the index for |
| 40 | // jump tables, so in practice we don't ever use SWITCH_I64 in wasm32 mode |
| 41 | // currently. |
| 42 | let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in { |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 43 | def SWITCH_I32 : I<(outs), (ins I32:$index, variable_ops), |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame^] | 44 | [(WebAssemblyswitch I32:$index)], |
| 45 | "switch $index">; |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 46 | def SWITCH_I64 : I<(outs), (ins I64:$index, variable_ops), |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame^] | 47 | [(WebAssemblyswitch I64:$index)], |
| 48 | "switch $index">; |
Dan Gohman | 950a13c | 2015-09-16 16:51:30 +0000 | [diff] [blame] | 49 | } // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 |
| 50 | |
| 51 | // Placemarkers to indicate the start of a block or loop scope. |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 52 | def BLOCK : I<(outs), (ins bb_op:$dst), [], "block $dst">; |
| 53 | def LOOP : I<(outs), (ins bb_op:$dst), [], "loop $dst">; |
Dan Gohman | 950a13c | 2015-09-16 16:51:30 +0000 | [diff] [blame] | 54 | |
JF Bastien | 8f9aea0 | 2015-08-01 04:48:44 +0000 | [diff] [blame] | 55 | multiclass RETURN<WebAssemblyRegClass vt> { |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 56 | def RETURN_#vt : I<(outs), (ins vt:$val), [(WebAssemblyreturn vt:$val)], |
| 57 | "return $val">; |
JF Bastien | 8f9aea0 | 2015-08-01 04:48:44 +0000 | [diff] [blame] | 58 | } |
Derek Schuff | ffa143c | 2015-11-10 00:30:57 +0000 | [diff] [blame] | 59 | |
| 60 | let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in { |
| 61 | let isReturn = 1 in { |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 62 | defm : RETURN<I32>; |
| 63 | defm : RETURN<I64>; |
| 64 | defm : RETURN<F32>; |
| 65 | defm : RETURN<F64>; |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 66 | def RETURN_VOID : I<(outs), (ins), [(WebAssemblyreturn)], "return">; |
Derek Schuff | ffa143c | 2015-11-10 00:30:57 +0000 | [diff] [blame] | 67 | } // isReturn = 1 |
| 68 | def UNREACHABLE : I<(outs), (ins), [(trap)], "unreachable">; |
| 69 | } // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 |