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 | |
Dan Gohman | 950a13c | 2015-09-16 16:51:30 +0000 | [diff] [blame] | 15 | let isBranch = 1, isTerminator = 1, hasCtrlDep = 1 in { |
Derek Schuff | 4ed4778 | 2015-11-16 21:04:51 +0000 | [diff] [blame] | 16 | def BR_IF : I<(outs), (ins I32:$a, bb_op:$dst), |
Dan Gohman | 231244c | 2015-11-13 00:46:31 +0000 | [diff] [blame] | 17 | [(brcond I32:$a, bb:$dst)], |
Dan Gohman | 94ef41f | 2015-11-18 17:05:35 +0000 | [diff] [blame] | 18 | "br_if \t$a, $dst">; |
Dan Gohman | 950a13c | 2015-09-16 16:51:30 +0000 | [diff] [blame] | 19 | let isBarrier = 1 in { |
| 20 | def BR : I<(outs), (ins bb_op:$dst), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 21 | [(br bb:$dst)], |
Dan Gohman | 94ef41f | 2015-11-18 17:05:35 +0000 | [diff] [blame] | 22 | "br \t$dst">; |
Dan Gohman | 950a13c | 2015-09-16 16:51:30 +0000 | [diff] [blame] | 23 | } // 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 Gohman | bb7ce8e | 2015-11-20 03:02:49 +0000 | [diff] [blame] | 27 | // jump tables, so in practice we don't ever use TABLESWITCH_I64 in wasm32 mode |
Dan Gohman | 950a13c | 2015-09-16 16:51:30 +0000 | [diff] [blame] | 28 | // currently. |
| 29 | let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in { |
Dan Gohman | bb7ce8e | 2015-11-20 03:02:49 +0000 | [diff] [blame] | 30 | def TABLESWITCH_I32 : I<(outs), (ins I32:$index, variable_ops), |
| 31 | [(WebAssemblytableswitch I32:$index)], |
| 32 | "tableswitch\t$index">; |
| 33 | def TABLESWITCH_I64 : I<(outs), (ins I64:$index, variable_ops), |
| 34 | [(WebAssemblytableswitch I64:$index)], |
| 35 | "tableswitch\t$index">; |
Dan Gohman | 950a13c | 2015-09-16 16:51:30 +0000 | [diff] [blame] | 36 | } // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 |
| 37 | |
| 38 | // Placemarkers to indicate the start of a block or loop scope. |
Dan Gohman | 94ef41f | 2015-11-18 17:05:35 +0000 | [diff] [blame] | 39 | def BLOCK : I<(outs), (ins bb_op:$dst), [], "block \t$dst">; |
| 40 | def LOOP : I<(outs), (ins bb_op:$dst), [], "loop \t$dst">; |
Dan Gohman | 950a13c | 2015-09-16 16:51:30 +0000 | [diff] [blame] | 41 | |
Dan Gohman | f685722 | 2015-11-23 19:12:37 +0000 | [diff] [blame] | 42 | // 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. |
| 44 | let isTerminator = 1, hasCtrlDep = 1 in |
| 45 | def LOOP_END : I<(outs), (ins), []>; |
| 46 | |
JF Bastien | 8f9aea0 | 2015-08-01 04:48:44 +0000 | [diff] [blame] | 47 | multiclass RETURN<WebAssemblyRegClass vt> { |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 48 | def RETURN_#vt : I<(outs), (ins vt:$val), [(WebAssemblyreturn vt:$val)], |
Dan Gohman | 94ef41f | 2015-11-18 17:05:35 +0000 | [diff] [blame] | 49 | "return \t$val">; |
JF Bastien | 8f9aea0 | 2015-08-01 04:48:44 +0000 | [diff] [blame] | 50 | } |
Derek Schuff | ffa143c | 2015-11-10 00:30:57 +0000 | [diff] [blame] | 51 | |
| 52 | let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in { |
| 53 | let isReturn = 1 in { |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 54 | defm : RETURN<I32>; |
| 55 | defm : RETURN<I64>; |
| 56 | defm : RETURN<F32>; |
| 57 | defm : RETURN<F64>; |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 58 | def RETURN_VOID : I<(outs), (ins), [(WebAssemblyreturn)], "return">; |
Derek Schuff | ffa143c | 2015-11-10 00:30:57 +0000 | [diff] [blame] | 59 | } // isReturn = 1 |
| 60 | def UNREACHABLE : I<(outs), (ins), [(trap)], "unreachable">; |
| 61 | } // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 |