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 | fb3e059 | 2015-11-25 19:36:19 +0000 | [diff] [blame] | 15 | let Defs = [ARGUMENTS] in { |
| 16 | |
Dan Gohman | 950a13c | 2015-09-16 16:51:30 +0000 | [diff] [blame] | 17 | let isBranch = 1, isTerminator = 1, hasCtrlDep = 1 in { |
Dan Gohman | f0b165a | 2015-12-05 03:03:35 +0000 | [diff] [blame^] | 18 | // The condition operand is a boolean value which WebAssembly represents as i32. |
| 19 | def BR_IF : I<(outs), (ins I32:$cond, bb_op:$dst), |
| 20 | [(brcond I32:$cond, bb:$dst)], |
| 21 | "br_if \t$cond, $dst">; |
| 22 | let isCodeGenOnly = 1 in |
| 23 | def BR_UNLESS : I<(outs), (ins I32:$cond, bb_op:$dst), [], |
| 24 | "br_unless\t$cond, $dst">; |
Dan Gohman | 950a13c | 2015-09-16 16:51:30 +0000 | [diff] [blame] | 25 | let isBarrier = 1 in { |
| 26 | def BR : I<(outs), (ins bb_op:$dst), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 27 | [(br bb:$dst)], |
Dan Gohman | 94ef41f | 2015-11-18 17:05:35 +0000 | [diff] [blame] | 28 | "br \t$dst">; |
Dan Gohman | 950a13c | 2015-09-16 16:51:30 +0000 | [diff] [blame] | 29 | } // isBarrier = 1 |
| 30 | } // isBranch = 1, isTerminator = 1, hasCtrlDep = 1 |
| 31 | |
Dan Gohman | f0b165a | 2015-12-05 03:03:35 +0000 | [diff] [blame^] | 32 | } // Defs = [ARGUMENTS] |
| 33 | |
| 34 | def : Pat<(brcond (i32 (setne I32:$cond, 0)), bb:$dst), |
| 35 | (BR_IF I32:$cond, bb_op:$dst)>; |
| 36 | def : Pat<(brcond (i32 (seteq I32:$cond, 0)), bb:$dst), |
| 37 | (BR_UNLESS I32:$cond, bb_op:$dst)>; |
| 38 | |
| 39 | let Defs = [ARGUMENTS] in { |
| 40 | |
Dan Gohman | 950a13c | 2015-09-16 16:51:30 +0000 | [diff] [blame] | 41 | // 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] | 42 | // 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] | 43 | // currently. |
| 44 | let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in { |
Dan Gohman | bb7ce8e | 2015-11-20 03:02:49 +0000 | [diff] [blame] | 45 | def TABLESWITCH_I32 : I<(outs), (ins I32:$index, variable_ops), |
| 46 | [(WebAssemblytableswitch I32:$index)], |
| 47 | "tableswitch\t$index">; |
| 48 | def TABLESWITCH_I64 : I<(outs), (ins I64:$index, variable_ops), |
| 49 | [(WebAssemblytableswitch I64:$index)], |
| 50 | "tableswitch\t$index">; |
Dan Gohman | 950a13c | 2015-09-16 16:51:30 +0000 | [diff] [blame] | 51 | } // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 |
| 52 | |
| 53 | // Placemarkers to indicate the start of a block or loop scope. |
Dan Gohman | 94ef41f | 2015-11-18 17:05:35 +0000 | [diff] [blame] | 54 | def BLOCK : I<(outs), (ins bb_op:$dst), [], "block \t$dst">; |
| 55 | def LOOP : I<(outs), (ins bb_op:$dst), [], "loop \t$dst">; |
Dan Gohman | 950a13c | 2015-09-16 16:51:30 +0000 | [diff] [blame] | 56 | |
Dan Gohman | f685722 | 2015-11-23 19:12:37 +0000 | [diff] [blame] | 57 | // No-op to indicate to the AsmPrinter that a loop ends here, so a |
| 58 | // basic block label is needed even if it wouldn't otherwise appear so. |
| 59 | let isTerminator = 1, hasCtrlDep = 1 in |
| 60 | def LOOP_END : I<(outs), (ins), []>; |
| 61 | |
JF Bastien | 8f9aea0 | 2015-08-01 04:48:44 +0000 | [diff] [blame] | 62 | multiclass RETURN<WebAssemblyRegClass vt> { |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 63 | def RETURN_#vt : I<(outs), (ins vt:$val), [(WebAssemblyreturn vt:$val)], |
Dan Gohman | 94ef41f | 2015-11-18 17:05:35 +0000 | [diff] [blame] | 64 | "return \t$val">; |
JF Bastien | 8f9aea0 | 2015-08-01 04:48:44 +0000 | [diff] [blame] | 65 | } |
Derek Schuff | ffa143c | 2015-11-10 00:30:57 +0000 | [diff] [blame] | 66 | |
| 67 | let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in { |
| 68 | let isReturn = 1 in { |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 69 | defm : RETURN<I32>; |
| 70 | defm : RETURN<I64>; |
| 71 | defm : RETURN<F32>; |
| 72 | defm : RETURN<F64>; |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 73 | def RETURN_VOID : I<(outs), (ins), [(WebAssemblyreturn)], "return">; |
Derek Schuff | ffa143c | 2015-11-10 00:30:57 +0000 | [diff] [blame] | 74 | } // isReturn = 1 |
| 75 | def UNREACHABLE : I<(outs), (ins), [(trap)], "unreachable">; |
| 76 | } // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 |
Dan Gohman | fb3e059 | 2015-11-25 19:36:19 +0000 | [diff] [blame] | 77 | |
| 78 | } // Defs = [ARGUMENTS] |