Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 1 | // WebAssemblyInstrInfo.td-Describe the WebAssembly Instructions-*- 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 | //===----------------------------------------------------------------------===// |
JF Bastien | 5ca0bac | 2015-07-10 18:23:10 +0000 | [diff] [blame] | 9 | /// |
| 10 | /// \file |
| 11 | /// \brief WebAssembly Instruction definitions. |
| 12 | /// |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | // WebAssembly Instruction Predicate Definitions. |
| 17 | //===----------------------------------------------------------------------===// |
| 18 | |
JF Bastien | 03855df | 2015-07-01 23:41:25 +0000 | [diff] [blame] | 19 | def HasAddr32 : Predicate<"!Subtarget->hasAddr64()">; |
| 20 | def HasAddr64 : Predicate<"Subtarget->hasAddr64()">; |
| 21 | def HasSIMD128 : Predicate<"Subtarget->hasSIMD128()">, |
| 22 | AssemblerPredicate<"FeatureSIMD128", "simd128">; |
| 23 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 24 | //===----------------------------------------------------------------------===// |
| 25 | // WebAssembly-specific DAG Node Types. |
| 26 | //===----------------------------------------------------------------------===// |
| 27 | |
JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 28 | def SDT_WebAssemblyCallSeqStart : SDCallSeqStart<[SDTCisVT<0, iPTR>]>; |
| 29 | def SDT_WebAssemblyCallSeqEnd : |
| 30 | SDCallSeqEnd<[SDTCisVT<0, iPTR>, SDTCisVT<1, iPTR>]>; |
Dan Gohman | f71abef | 2015-09-09 16:13:47 +0000 | [diff] [blame] | 31 | def SDT_WebAssemblyCall0 : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>; |
| 32 | def SDT_WebAssemblyCall1 : SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>; |
Dan Gohman | 1402606 | 2016-03-08 03:18:12 +0000 | [diff] [blame] | 33 | def SDT_WebAssemblyBrTable : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>; |
JF Bastien | 600aee9 | 2015-07-31 17:53:38 +0000 | [diff] [blame] | 34 | def SDT_WebAssemblyArgument : SDTypeProfile<1, 1, [SDTCisVT<1, i32>]>; |
JF Bastien | 4a2d560 | 2015-07-31 21:04:18 +0000 | [diff] [blame] | 35 | def SDT_WebAssemblyReturn : SDTypeProfile<0, -1, []>; |
JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 36 | def SDT_WebAssemblyWrapper : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>, |
| 37 | SDTCisPtrTy<0>]>; |
JF Bastien | 600aee9 | 2015-07-31 17:53:38 +0000 | [diff] [blame] | 38 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 39 | //===----------------------------------------------------------------------===// |
| 40 | // WebAssembly-specific DAG Nodes. |
| 41 | //===----------------------------------------------------------------------===// |
| 42 | |
JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 43 | def WebAssemblycallseq_start : |
| 44 | SDNode<"ISD::CALLSEQ_START", SDT_WebAssemblyCallSeqStart, |
| 45 | [SDNPHasChain, SDNPOutGlue]>; |
| 46 | def WebAssemblycallseq_end : |
| 47 | SDNode<"ISD::CALLSEQ_END", SDT_WebAssemblyCallSeqEnd, |
| 48 | [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>; |
Dan Gohman | f71abef | 2015-09-09 16:13:47 +0000 | [diff] [blame] | 49 | def WebAssemblycall0 : SDNode<"WebAssemblyISD::CALL0", |
| 50 | SDT_WebAssemblyCall0, |
| 51 | [SDNPHasChain, SDNPVariadic]>; |
| 52 | def WebAssemblycall1 : SDNode<"WebAssemblyISD::CALL1", |
| 53 | SDT_WebAssemblyCall1, |
| 54 | [SDNPHasChain, SDNPVariadic]>; |
Dan Gohman | 1402606 | 2016-03-08 03:18:12 +0000 | [diff] [blame] | 55 | def WebAssemblybr_table : SDNode<"WebAssemblyISD::BR_TABLE", |
| 56 | SDT_WebAssemblyBrTable, |
| 57 | [SDNPHasChain, SDNPVariadic]>; |
JF Bastien | 600aee9 | 2015-07-31 17:53:38 +0000 | [diff] [blame] | 58 | def WebAssemblyargument : SDNode<"WebAssemblyISD::ARGUMENT", |
| 59 | SDT_WebAssemblyArgument>; |
| 60 | def WebAssemblyreturn : SDNode<"WebAssemblyISD::RETURN", |
JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 61 | SDT_WebAssemblyReturn, [SDNPHasChain]>; |
| 62 | def WebAssemblywrapper : SDNode<"WebAssemblyISD::Wrapper", |
| 63 | SDT_WebAssemblyWrapper>; |
JF Bastien | 600aee9 | 2015-07-31 17:53:38 +0000 | [diff] [blame] | 64 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 65 | //===----------------------------------------------------------------------===// |
| 66 | // WebAssembly-specific Operands. |
| 67 | //===----------------------------------------------------------------------===// |
| 68 | |
Dan Gohman | a11fb23 | 2016-01-12 03:09:16 +0000 | [diff] [blame] | 69 | let OperandNamespace = "WebAssembly" in { |
| 70 | |
| 71 | let OperandType = "OPERAND_BASIC_BLOCK" in |
Dan Gohman | 950a13c | 2015-09-16 16:51:30 +0000 | [diff] [blame] | 72 | def bb_op : Operand<OtherVT>; |
JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 73 | |
Dan Gohman | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 74 | let OperandType = "OPERAND_LOCAL" in |
| 75 | def local_op : Operand<i32>; |
| 76 | |
Dan Gohman | 5a68ec7 | 2016-10-05 21:24:08 +0000 | [diff] [blame] | 77 | let OperandType = "OPERAND_I32IMM" in |
| 78 | def i32imm_op : Operand<i32>; |
| 79 | |
| 80 | let OperandType = "OPERAND_I64IMM" in |
| 81 | def i64imm_op : Operand<i64>; |
| 82 | |
Dan Gohman | 4b8e8be | 2016-10-03 21:31:31 +0000 | [diff] [blame] | 83 | let OperandType = "OPERAND_F32IMM" in |
Dan Gohman | a11fb23 | 2016-01-12 03:09:16 +0000 | [diff] [blame] | 84 | def f32imm_op : Operand<f32>; |
Dan Gohman | aa74291 | 2016-02-16 15:14:23 +0000 | [diff] [blame] | 85 | |
Dan Gohman | 4b8e8be | 2016-10-03 21:31:31 +0000 | [diff] [blame] | 86 | let OperandType = "OPERAND_F64IMM" in |
Dan Gohman | a11fb23 | 2016-01-12 03:09:16 +0000 | [diff] [blame] | 87 | def f64imm_op : Operand<f64>; |
Dan Gohman | a11fb23 | 2016-01-12 03:09:16 +0000 | [diff] [blame] | 88 | |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 89 | let OperandType = "OPERAND_P2ALIGN" in { |
| 90 | def P2Align : Operand<i32> { |
| 91 | let PrintMethod = "printWebAssemblyP2AlignOperand"; |
| 92 | } |
| 93 | } // OperandType = "OPERAND_P2ALIGN" |
| 94 | |
Dan Gohman | 2726b88 | 2016-10-06 22:29:32 +0000 | [diff] [blame] | 95 | let OperandType = "OPERAND_SIGNATURE" in { |
| 96 | def Signature : Operand<i32> { |
| 97 | let PrintMethod = "printWebAssemblySignatureOperand"; |
| 98 | } |
| 99 | } // OperandType = "OPERAND_SIGNATURE" |
| 100 | |
Dan Gohman | a11fb23 | 2016-01-12 03:09:16 +0000 | [diff] [blame] | 101 | } // OperandNamespace = "WebAssembly" |
| 102 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 103 | //===----------------------------------------------------------------------===// |
| 104 | // WebAssembly Instruction Format Definitions. |
| 105 | //===----------------------------------------------------------------------===// |
| 106 | |
| 107 | include "WebAssemblyInstrFormats.td" |
| 108 | |
Dan Gohman | 4ba4816 | 2015-11-18 16:12:01 +0000 | [diff] [blame] | 109 | //===----------------------------------------------------------------------===// |
| 110 | // Additional instructions. |
| 111 | //===----------------------------------------------------------------------===// |
| 112 | |
JF Bastien | 8f9aea0 | 2015-08-01 04:48:44 +0000 | [diff] [blame] | 113 | multiclass ARGUMENT<WebAssemblyRegClass vt> { |
Dan Gohman | a783f10 | 2015-12-21 16:53:29 +0000 | [diff] [blame] | 114 | let hasSideEffects = 1, Uses = [ARGUMENTS], isCodeGenOnly = 1 in |
JF Bastien | 8f9aea0 | 2015-08-01 04:48:44 +0000 | [diff] [blame] | 115 | def ARGUMENT_#vt : I<(outs vt:$res), (ins i32imm:$argno), |
| 116 | [(set vt:$res, (WebAssemblyargument timm:$argno))]>; |
| 117 | } |
Derek Schuff | 39bf39f | 2016-08-02 23:16:09 +0000 | [diff] [blame] | 118 | multiclass SIMD_ARGUMENT<ValueType vt> { |
| 119 | let hasSideEffects = 1, Uses = [ARGUMENTS], isCodeGenOnly = 1 in |
| 120 | def ARGUMENT_#vt : SIMD_I<(outs V128:$res), (ins i32imm:$argno), |
| 121 | [(set (vt V128:$res), |
| 122 | (WebAssemblyargument timm:$argno))]>; |
| 123 | } |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 124 | defm : ARGUMENT<I32>; |
| 125 | defm : ARGUMENT<I64>; |
| 126 | defm : ARGUMENT<F32>; |
| 127 | defm : ARGUMENT<F64>; |
Derek Schuff | 39bf39f | 2016-08-02 23:16:09 +0000 | [diff] [blame] | 128 | defm : SIMD_ARGUMENT<v16i8>; |
| 129 | defm : SIMD_ARGUMENT<v8i16>; |
| 130 | defm : SIMD_ARGUMENT<v4i32>; |
| 131 | defm : SIMD_ARGUMENT<v4f32>; |
JF Bastien | 600aee9 | 2015-07-31 17:53:38 +0000 | [diff] [blame] | 132 | |
Dan Gohman | fb3e059 | 2015-11-25 19:36:19 +0000 | [diff] [blame] | 133 | let Defs = [ARGUMENTS] in { |
| 134 | |
Dan Gohman | 4ba4816 | 2015-11-18 16:12:01 +0000 | [diff] [blame] | 135 | // get_local and set_local are not generated by instruction selection; they |
Dan Gohman | adf2817 | 2016-01-28 01:22:44 +0000 | [diff] [blame] | 136 | // are implied by virtual register uses and defs. |
Dan Gohman | 4ba4816 | 2015-11-18 16:12:01 +0000 | [diff] [blame] | 137 | multiclass LOCAL<WebAssemblyRegClass vt> { |
Dan Gohman | 4817a75 | 2016-05-16 19:16:32 +0000 | [diff] [blame] | 138 | let hasSideEffects = 0 in { |
Dan Gohman | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 139 | // COPY is not an actual instruction in wasm, but since we allow get_local and |
| 140 | // set_local to be implicit during most of codegen, we can have a COPY which |
| 141 | // is actually a no-op because all the work is done in the implied get_local |
| 142 | // and set_local. COPYs are eliminated (and replaced with |
| 143 | // get_local/set_local) in the ExplicitLocals pass. |
| 144 | let isAsCheapAsAMove = 1, isCodeGenOnly = 1 in |
| 145 | def COPY_#vt : I<(outs vt:$res), (ins vt:$src), [], "copy_local\t$res, $src">; |
Dan Gohman | adf2817 | 2016-01-28 01:22:44 +0000 | [diff] [blame] | 146 | |
Dan Gohman | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 147 | // TEE is similar to COPY, but writes two copies of its result. Typically |
| 148 | // this would be used to stackify one result and write the other result to a |
| 149 | // local. |
| 150 | let isAsCheapAsAMove = 1, isCodeGenOnly = 1 in |
| 151 | def TEE_#vt : I<(outs vt:$res, vt:$also), (ins vt:$src), [], |
| 152 | "tee_local\t$res, $also, $src">; |
| 153 | |
| 154 | // This is the actual get_local instruction in wasm. These are made explicit |
| 155 | // by the ExplicitLocals pass. It has mayLoad because it reads from a wasm |
| 156 | // local, which is a side effect not otherwise modeled in LLVM. |
| 157 | let mayLoad = 1, isAsCheapAsAMove = 1 in |
| 158 | def GET_LOCAL_#vt : I<(outs vt:$res), (ins local_op:$local), [], |
Dan Gohman | c968297 | 2016-10-24 20:21:49 +0000 | [diff] [blame^] | 159 | "get_local\t$res, $local", 0x20>; |
Dan Gohman | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 160 | |
| 161 | // This is the actual set_local instruction in wasm. These are made explicit |
| 162 | // by the ExplicitLocals pass. It has mayStore because it writes to a wasm |
| 163 | // local, which is a side effect not otherwise modeled in LLVM. |
| 164 | let mayStore = 1, isAsCheapAsAMove = 1 in |
| 165 | def SET_LOCAL_#vt : I<(outs), (ins local_op:$local, vt:$src), [], |
Dan Gohman | c968297 | 2016-10-24 20:21:49 +0000 | [diff] [blame^] | 166 | "set_local\t$local, $src", 0x21>; |
Dan Gohman | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 167 | |
| 168 | // This is the actual tee_local instruction in wasm. TEEs are turned into |
| 169 | // TEE_LOCALs by the ExplicitLocals pass. It has mayStore for the same reason |
| 170 | // as SET_LOCAL. |
| 171 | let mayStore = 1, isAsCheapAsAMove = 1 in |
| 172 | def TEE_LOCAL_#vt : I<(outs vt:$res), (ins local_op:$local, vt:$src), [], |
Dan Gohman | c968297 | 2016-10-24 20:21:49 +0000 | [diff] [blame^] | 173 | "tee_local\t$res, $local, $src", 0x22>; |
Dan Gohman | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 174 | |
Dan Gohman | 4817a75 | 2016-05-16 19:16:32 +0000 | [diff] [blame] | 175 | } // hasSideEffects = 0 |
Dan Gohman | 4ba4816 | 2015-11-18 16:12:01 +0000 | [diff] [blame] | 176 | } |
| 177 | defm : LOCAL<I32>; |
| 178 | defm : LOCAL<I64>; |
| 179 | defm : LOCAL<F32>; |
| 180 | defm : LOCAL<F64>; |
Derek Schuff | 39bf39f | 2016-08-02 23:16:09 +0000 | [diff] [blame] | 181 | defm : LOCAL<V128>, Requires<[HasSIMD128]>; |
JF Bastien | 4a64225 | 2015-08-10 22:36:48 +0000 | [diff] [blame] | 182 | |
Dan Gohman | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 183 | // Set TSFlags{0} to 1 to indicate that the variable_ops are immediates. |
| 184 | // Set TSFlags{2} to 1 to indicate that the immediates are ValTypes. |
| 185 | def DECLARE_LOCALS : I<(outs), (ins variable_ops), [], ".local \t"> { |
| 186 | let TSFlags{0} = 1; |
| 187 | let TSFlags{2} = 1; |
| 188 | } |
| 189 | |
Dan Gohman | b6fd39a | 2016-01-19 16:59:23 +0000 | [diff] [blame] | 190 | let isMoveImm = 1, isAsCheapAsAMove = 1, isReMaterializable = 1 in { |
Dan Gohman | 5a68ec7 | 2016-10-05 21:24:08 +0000 | [diff] [blame] | 191 | def CONST_I32 : I<(outs I32:$res), (ins i32imm_op:$imm), |
Dan Gohman | da7f428 | 2015-11-05 20:44:29 +0000 | [diff] [blame] | 192 | [(set I32:$res, imm:$imm)], |
Dan Gohman | c968297 | 2016-10-24 20:21:49 +0000 | [diff] [blame^] | 193 | "i32.const\t$res, $imm", 0x41>; |
Dan Gohman | 5a68ec7 | 2016-10-05 21:24:08 +0000 | [diff] [blame] | 194 | def CONST_I64 : I<(outs I64:$res), (ins i64imm_op:$imm), |
Dan Gohman | da7f428 | 2015-11-05 20:44:29 +0000 | [diff] [blame] | 195 | [(set I64:$res, imm:$imm)], |
Dan Gohman | c968297 | 2016-10-24 20:21:49 +0000 | [diff] [blame^] | 196 | "i64.const\t$res, $imm", 0x42>; |
Dan Gohman | a11fb23 | 2016-01-12 03:09:16 +0000 | [diff] [blame] | 197 | def CONST_F32 : I<(outs F32:$res), (ins f32imm_op:$imm), |
Dan Gohman | da7f428 | 2015-11-05 20:44:29 +0000 | [diff] [blame] | 198 | [(set F32:$res, fpimm:$imm)], |
Dan Gohman | c968297 | 2016-10-24 20:21:49 +0000 | [diff] [blame^] | 199 | "f32.const\t$res, $imm", 0x43>; |
Dan Gohman | a11fb23 | 2016-01-12 03:09:16 +0000 | [diff] [blame] | 200 | def CONST_F64 : I<(outs F64:$res), (ins f64imm_op:$imm), |
Dan Gohman | da7f428 | 2015-11-05 20:44:29 +0000 | [diff] [blame] | 201 | [(set F64:$res, fpimm:$imm)], |
Dan Gohman | c968297 | 2016-10-24 20:21:49 +0000 | [diff] [blame^] | 202 | "f64.const\t$res, $imm", 0x44>; |
Dan Gohman | b6fd39a | 2016-01-19 16:59:23 +0000 | [diff] [blame] | 203 | } // isMoveImm = 1, isAsCheapAsAMove = 1, isReMaterializable = 1 |
JF Bastien | 4a64225 | 2015-08-10 22:36:48 +0000 | [diff] [blame] | 204 | |
Dan Gohman | fb3e059 | 2015-11-25 19:36:19 +0000 | [diff] [blame] | 205 | } // Defs = [ARGUMENTS] |
| 206 | |
Dan Gohman | 8633eed | 2016-01-08 00:50:33 +0000 | [diff] [blame] | 207 | def : Pat<(i32 (WebAssemblywrapper tglobaladdr:$addr)), |
| 208 | (CONST_I32 tglobaladdr:$addr)>; |
| 209 | def : Pat<(i32 (WebAssemblywrapper texternalsym:$addr)), |
| 210 | (CONST_I32 texternalsym:$addr)>; |
Derek Schuff | 71e8169 | 2015-11-17 00:20:44 +0000 | [diff] [blame] | 211 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 212 | //===----------------------------------------------------------------------===// |
| 213 | // Additional sets of instructions. |
| 214 | //===----------------------------------------------------------------------===// |
| 215 | |
JF Bastien | 5ca0bac | 2015-07-10 18:23:10 +0000 | [diff] [blame] | 216 | include "WebAssemblyInstrMemory.td" |
| 217 | include "WebAssemblyInstrCall.td" |
JF Bastien | 600aee9 | 2015-07-31 17:53:38 +0000 | [diff] [blame] | 218 | include "WebAssemblyInstrControl.td" |
JF Bastien | 5ca0bac | 2015-07-10 18:23:10 +0000 | [diff] [blame] | 219 | include "WebAssemblyInstrInteger.td" |
JF Bastien | 5ca0bac | 2015-07-10 18:23:10 +0000 | [diff] [blame] | 220 | include "WebAssemblyInstrConv.td" |
Dan Gohman | f170ba0 | 2015-12-10 04:55:31 +0000 | [diff] [blame] | 221 | include "WebAssemblyInstrFloat.td" |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 222 | include "WebAssemblyInstrAtomics.td" |
| 223 | include "WebAssemblyInstrSIMD.td" |