Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 1 | // WebAssemblyInstrInfo.td-Describe the WebAssembly Instructions-*- tablegen -*- |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
JF Bastien | 5ca0bac | 2015-07-10 18:23:10 +0000 | [diff] [blame] | 8 | /// |
| 9 | /// \file |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 10 | /// WebAssembly Instruction definitions. |
JF Bastien | 5ca0bac | 2015-07-10 18:23:10 +0000 | [diff] [blame] | 11 | /// |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | // WebAssembly Instruction Predicate Definitions. |
| 16 | //===----------------------------------------------------------------------===// |
| 17 | |
Sam Clegg | 492f752 | 2019-03-26 19:46:15 +0000 | [diff] [blame] | 18 | def IsPIC : Predicate<"TM.isPositionIndependent()">; |
| 19 | def IsNotPIC : Predicate<"!TM.isPositionIndependent()">; |
| 20 | |
JF Bastien | 03855df | 2015-07-01 23:41:25 +0000 | [diff] [blame] | 21 | def HasAddr32 : Predicate<"!Subtarget->hasAddr64()">; |
Thomas Lively | 88058d4 | 2019-01-31 21:02:19 +0000 | [diff] [blame] | 22 | |
JF Bastien | 03855df | 2015-07-01 23:41:25 +0000 | [diff] [blame] | 23 | def HasAddr64 : Predicate<"Subtarget->hasAddr64()">; |
Thomas Lively | 88058d4 | 2019-01-31 21:02:19 +0000 | [diff] [blame] | 24 | |
| 25 | def HasSIMD128 : |
| 26 | Predicate<"Subtarget->hasSIMD128()">, |
| 27 | AssemblerPredicate<"FeatureSIMD128", "simd128">; |
| 28 | |
Thomas Lively | 64a39a1 | 2019-01-10 22:32:11 +0000 | [diff] [blame] | 29 | def HasUnimplementedSIMD128 : |
| 30 | Predicate<"Subtarget->hasUnimplementedSIMD128()">, |
| 31 | AssemblerPredicate<"FeatureUnimplementedSIMD128", "unimplemented-simd128">; |
Thomas Lively | 88058d4 | 2019-01-31 21:02:19 +0000 | [diff] [blame] | 32 | |
| 33 | def HasAtomics : |
| 34 | Predicate<"Subtarget->hasAtomics()">, |
| 35 | AssemblerPredicate<"FeatureAtomics", "atomics">; |
| 36 | |
Dan Gohman | cdd48b8 | 2017-11-28 01:13:40 +0000 | [diff] [blame] | 37 | def HasNontrappingFPToInt : |
| 38 | Predicate<"Subtarget->hasNontrappingFPToInt()">, |
Thomas Lively | 88058d4 | 2019-01-31 21:02:19 +0000 | [diff] [blame] | 39 | AssemblerPredicate<"FeatureNontrappingFPToInt", "nontrapping-fptoint">; |
| 40 | |
Dan Gohman | cdd48b8 | 2017-11-28 01:13:40 +0000 | [diff] [blame] | 41 | def NotHasNontrappingFPToInt : |
| 42 | Predicate<"!Subtarget->hasNontrappingFPToInt()">, |
Thomas Lively | 88058d4 | 2019-01-31 21:02:19 +0000 | [diff] [blame] | 43 | AssemblerPredicate<"!FeatureNontrappingFPToInt", "nontrapping-fptoint">; |
| 44 | |
Dan Gohman | 5d2b935 | 2018-01-19 17:16:24 +0000 | [diff] [blame] | 45 | def HasSignExt : |
| 46 | Predicate<"Subtarget->hasSignExt()">, |
Thomas Lively | 88058d4 | 2019-01-31 21:02:19 +0000 | [diff] [blame] | 47 | AssemblerPredicate<"FeatureSignExt", "sign-ext">; |
| 48 | |
Dan Gohman | 5d2b935 | 2018-01-19 17:16:24 +0000 | [diff] [blame] | 49 | def NotHasSignExt : |
| 50 | Predicate<"!Subtarget->hasSignExt()">, |
Thomas Lively | 88058d4 | 2019-01-31 21:02:19 +0000 | [diff] [blame] | 51 | AssemblerPredicate<"!FeatureSignExt", "sign-ext">; |
JF Bastien | 03855df | 2015-07-01 23:41:25 +0000 | [diff] [blame] | 52 | |
Heejin Ahn | 9386bde | 2018-02-24 00:40:50 +0000 | [diff] [blame] | 53 | def HasExceptionHandling : |
| 54 | Predicate<"Subtarget->hasExceptionHandling()">, |
Thomas Lively | 88058d4 | 2019-01-31 21:02:19 +0000 | [diff] [blame] | 55 | AssemblerPredicate<"FeatureExceptionHandling", "exception-handling">; |
Heejin Ahn | 9386bde | 2018-02-24 00:40:50 +0000 | [diff] [blame] | 56 | |
| 57 | def NotHasExceptionHandling : |
| 58 | Predicate<"!Subtarget->hasExceptionHandling()">, |
Thomas Lively | 88058d4 | 2019-01-31 21:02:19 +0000 | [diff] [blame] | 59 | AssemblerPredicate<"!FeatureExceptionHandling", "exception-handling">; |
| 60 | |
| 61 | def HasBulkMemory : |
| 62 | Predicate<"Subtarget->hasBulkMemory()">, |
| 63 | AssemblerPredicate<"FeatureBulkMemory", "bulk-memory">; |
Heejin Ahn | 9386bde | 2018-02-24 00:40:50 +0000 | [diff] [blame] | 64 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 65 | //===----------------------------------------------------------------------===// |
| 66 | // WebAssembly-specific DAG Node Types. |
| 67 | //===----------------------------------------------------------------------===// |
| 68 | |
Serge Pavlov | d526b13 | 2017-05-09 13:35:13 +0000 | [diff] [blame] | 69 | def SDT_WebAssemblyCallSeqStart : SDCallSeqStart<[SDTCisVT<0, iPTR>, |
| 70 | SDTCisVT<1, iPTR>]>; |
JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 71 | def SDT_WebAssemblyCallSeqEnd : |
| 72 | SDCallSeqEnd<[SDTCisVT<0, iPTR>, SDTCisVT<1, iPTR>]>; |
Sam Clegg | 492f752 | 2019-03-26 19:46:15 +0000 | [diff] [blame] | 73 | def SDT_WebAssemblyCall0 : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>; |
| 74 | def SDT_WebAssemblyCall1 : SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>; |
| 75 | def SDT_WebAssemblyBrTable : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>; |
| 76 | def SDT_WebAssemblyArgument : SDTypeProfile<1, 1, [SDTCisVT<1, i32>]>; |
| 77 | def SDT_WebAssemblyReturn : SDTypeProfile<0, -1, []>; |
| 78 | def SDT_WebAssemblyWrapper : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>, |
| 79 | SDTCisPtrTy<0>]>; |
| 80 | def SDT_WebAssemblyWrapperPIC : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>, |
| 81 | SDTCisPtrTy<0>]>; |
| 82 | def SDT_WebAssemblyThrow : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>; |
JF Bastien | 600aee9 | 2015-07-31 17:53:38 +0000 | [diff] [blame] | 83 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 84 | //===----------------------------------------------------------------------===// |
| 85 | // WebAssembly-specific DAG Nodes. |
| 86 | //===----------------------------------------------------------------------===// |
| 87 | |
JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 88 | def WebAssemblycallseq_start : |
| 89 | SDNode<"ISD::CALLSEQ_START", SDT_WebAssemblyCallSeqStart, |
| 90 | [SDNPHasChain, SDNPOutGlue]>; |
| 91 | def WebAssemblycallseq_end : |
| 92 | SDNode<"ISD::CALLSEQ_END", SDT_WebAssemblyCallSeqEnd, |
| 93 | [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>; |
Dan Gohman | f71abef | 2015-09-09 16:13:47 +0000 | [diff] [blame] | 94 | def WebAssemblycall0 : SDNode<"WebAssemblyISD::CALL0", |
| 95 | SDT_WebAssemblyCall0, |
| 96 | [SDNPHasChain, SDNPVariadic]>; |
| 97 | def WebAssemblycall1 : SDNode<"WebAssemblyISD::CALL1", |
| 98 | SDT_WebAssemblyCall1, |
| 99 | [SDNPHasChain, SDNPVariadic]>; |
Dan Gohman | 1402606 | 2016-03-08 03:18:12 +0000 | [diff] [blame] | 100 | def WebAssemblybr_table : SDNode<"WebAssemblyISD::BR_TABLE", |
| 101 | SDT_WebAssemblyBrTable, |
| 102 | [SDNPHasChain, SDNPVariadic]>; |
JF Bastien | 600aee9 | 2015-07-31 17:53:38 +0000 | [diff] [blame] | 103 | def WebAssemblyargument : SDNode<"WebAssemblyISD::ARGUMENT", |
| 104 | SDT_WebAssemblyArgument>; |
| 105 | def WebAssemblyreturn : SDNode<"WebAssemblyISD::RETURN", |
JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 106 | SDT_WebAssemblyReturn, [SDNPHasChain]>; |
| 107 | def WebAssemblywrapper : SDNode<"WebAssemblyISD::Wrapper", |
| 108 | SDT_WebAssemblyWrapper>; |
Sam Clegg | 492f752 | 2019-03-26 19:46:15 +0000 | [diff] [blame] | 109 | def WebAssemblywrapperPIC : SDNode<"WebAssemblyISD::WrapperPIC", |
| 110 | SDT_WebAssemblyWrapperPIC>; |
Heejin Ahn | da419bd | 2018-11-14 02:46:21 +0000 | [diff] [blame] | 111 | def WebAssemblythrow : SDNode<"WebAssemblyISD::THROW", SDT_WebAssemblyThrow, |
Heejin Ahn | d6f4878 | 2019-01-30 03:21:57 +0000 | [diff] [blame] | 112 | [SDNPHasChain, SDNPVariadic]>; |
JF Bastien | 600aee9 | 2015-07-31 17:53:38 +0000 | [diff] [blame] | 113 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 114 | //===----------------------------------------------------------------------===// |
| 115 | // WebAssembly-specific Operands. |
| 116 | //===----------------------------------------------------------------------===// |
| 117 | |
Dan Gohman | a11fb23 | 2016-01-12 03:09:16 +0000 | [diff] [blame] | 118 | let OperandNamespace = "WebAssembly" in { |
| 119 | |
| 120 | let OperandType = "OPERAND_BASIC_BLOCK" in |
Dan Gohman | 950a13c | 2015-09-16 16:51:30 +0000 | [diff] [blame] | 121 | def bb_op : Operand<OtherVT>; |
JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 122 | |
Dan Gohman | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 123 | let OperandType = "OPERAND_LOCAL" in |
| 124 | def local_op : Operand<i32>; |
| 125 | |
Dan Gohman | b89f2d3 | 2017-02-02 19:29:44 +0000 | [diff] [blame] | 126 | let OperandType = "OPERAND_GLOBAL" in |
| 127 | def global_op : Operand<i32>; |
| 128 | |
Dan Gohman | 5a68ec7 | 2016-10-05 21:24:08 +0000 | [diff] [blame] | 129 | let OperandType = "OPERAND_I32IMM" in |
| 130 | def i32imm_op : Operand<i32>; |
| 131 | |
| 132 | let OperandType = "OPERAND_I64IMM" in |
| 133 | def i64imm_op : Operand<i64>; |
| 134 | |
Dan Gohman | 4b8e8be | 2016-10-03 21:31:31 +0000 | [diff] [blame] | 135 | let OperandType = "OPERAND_F32IMM" in |
Dan Gohman | a11fb23 | 2016-01-12 03:09:16 +0000 | [diff] [blame] | 136 | def f32imm_op : Operand<f32>; |
Dan Gohman | aa74291 | 2016-02-16 15:14:23 +0000 | [diff] [blame] | 137 | |
Dan Gohman | 4b8e8be | 2016-10-03 21:31:31 +0000 | [diff] [blame] | 138 | let OperandType = "OPERAND_F64IMM" in |
Dan Gohman | a11fb23 | 2016-01-12 03:09:16 +0000 | [diff] [blame] | 139 | def f64imm_op : Operand<f64>; |
Dan Gohman | a11fb23 | 2016-01-12 03:09:16 +0000 | [diff] [blame] | 140 | |
Thomas Lively | 2244292 | 2018-08-21 21:03:18 +0000 | [diff] [blame] | 141 | let OperandType = "OPERAND_VEC_I8IMM" in |
| 142 | def vec_i8imm_op : Operand<i32>; |
| 143 | |
| 144 | let OperandType = "OPERAND_VEC_I16IMM" in |
| 145 | def vec_i16imm_op : Operand<i32>; |
| 146 | |
| 147 | let OperandType = "OPERAND_VEC_I32IMM" in |
| 148 | def vec_i32imm_op : Operand<i32>; |
| 149 | |
| 150 | let OperandType = "OPERAND_VEC_I64IMM" in |
| 151 | def vec_i64imm_op : Operand<i64>; |
| 152 | |
Dan Gohman | 00d734d | 2016-12-23 03:23:52 +0000 | [diff] [blame] | 153 | let OperandType = "OPERAND_FUNCTION32" in |
| 154 | def function32_op : Operand<i32>; |
| 155 | |
| 156 | let OperandType = "OPERAND_OFFSET32" in |
| 157 | def offset32_op : Operand<i32>; |
| 158 | |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 159 | let OperandType = "OPERAND_P2ALIGN" in { |
| 160 | def P2Align : Operand<i32> { |
| 161 | let PrintMethod = "printWebAssemblyP2AlignOperand"; |
| 162 | } |
Heejin Ahn | da419bd | 2018-11-14 02:46:21 +0000 | [diff] [blame] | 163 | |
| 164 | let OperandType = "OPERAND_EVENT" in |
| 165 | def event_op : Operand<i32>; |
| 166 | |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 167 | } // OperandType = "OPERAND_P2ALIGN" |
| 168 | |
Heejin Ahn | 4367587 | 2019-02-06 00:17:03 +0000 | [diff] [blame] | 169 | let OperandType = "OPERAND_SIGNATURE" in |
Dan Gohman | 2726b88 | 2016-10-06 22:29:32 +0000 | [diff] [blame] | 170 | def Signature : Operand<i32> { |
| 171 | let PrintMethod = "printWebAssemblySignatureOperand"; |
| 172 | } |
Dan Gohman | 2726b88 | 2016-10-06 22:29:32 +0000 | [diff] [blame] | 173 | |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 174 | let OperandType = "OPERAND_TYPEINDEX" in |
| 175 | def TypeIndex : Operand<i32>; |
| 176 | |
Dan Gohman | a11fb23 | 2016-01-12 03:09:16 +0000 | [diff] [blame] | 177 | } // OperandNamespace = "WebAssembly" |
| 178 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 179 | //===----------------------------------------------------------------------===// |
Thomas Lively | c63b5fc | 2018-10-22 21:55:26 +0000 | [diff] [blame] | 180 | // WebAssembly Register to Stack instruction mapping |
| 181 | //===----------------------------------------------------------------------===// |
| 182 | |
| 183 | class StackRel; |
| 184 | def getStackOpcode : InstrMapping { |
| 185 | let FilterClass = "StackRel"; |
| 186 | let RowFields = ["BaseName"]; |
| 187 | let ColFields = ["StackBased"]; |
| 188 | let KeyCol = ["false"]; |
| 189 | let ValueCols = [["true"]]; |
| 190 | } |
| 191 | |
| 192 | //===----------------------------------------------------------------------===// |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 193 | // WebAssembly Instruction Format Definitions. |
| 194 | //===----------------------------------------------------------------------===// |
| 195 | |
| 196 | include "WebAssemblyInstrFormats.td" |
| 197 | |
Dan Gohman | 4ba4816 | 2015-11-18 16:12:01 +0000 | [diff] [blame] | 198 | //===----------------------------------------------------------------------===// |
| 199 | // Additional instructions. |
| 200 | //===----------------------------------------------------------------------===// |
| 201 | |
Thomas Lively | 0ff82ac | 2018-10-13 07:09:10 +0000 | [diff] [blame] | 202 | multiclass ARGUMENT<WebAssemblyRegClass reg, ValueType vt> { |
Heejin Ahn | 4367587 | 2019-02-06 00:17:03 +0000 | [diff] [blame] | 203 | let hasSideEffects = 1, isCodeGenOnly = 1, Defs = []<Register>, |
| 204 | Uses = [ARGUMENTS] in |
Thomas Lively | 0ff82ac | 2018-10-13 07:09:10 +0000 | [diff] [blame] | 205 | defm ARGUMENT_#vt : |
| 206 | I<(outs reg:$res), (ins i32imm:$argno), (outs), (ins i32imm:$argno), |
| 207 | [(set (vt reg:$res), (WebAssemblyargument timm:$argno))]>; |
JF Bastien | 8f9aea0 | 2015-08-01 04:48:44 +0000 | [diff] [blame] | 208 | } |
Thomas Lively | 0ff82ac | 2018-10-13 07:09:10 +0000 | [diff] [blame] | 209 | defm "": ARGUMENT<I32, i32>; |
| 210 | defm "": ARGUMENT<I64, i64>; |
| 211 | defm "": ARGUMENT<F32, f32>; |
| 212 | defm "": ARGUMENT<F64, f64>; |
| 213 | defm "": ARGUMENT<EXCEPT_REF, ExceptRef>; |
JF Bastien | 600aee9 | 2015-07-31 17:53:38 +0000 | [diff] [blame] | 214 | |
Thomas Lively | 6a87dda | 2019-01-08 06:25:55 +0000 | [diff] [blame] | 215 | // local.get and local.set are not generated by instruction selection; they |
Dan Gohman | adf2817 | 2016-01-28 01:22:44 +0000 | [diff] [blame] | 216 | // are implied by virtual register uses and defs. |
Dan Gohman | 4ba4816 | 2015-11-18 16:12:01 +0000 | [diff] [blame] | 217 | multiclass LOCAL<WebAssemblyRegClass vt> { |
Heejin Ahn | 4367587 | 2019-02-06 00:17:03 +0000 | [diff] [blame] | 218 | let hasSideEffects = 0 in { |
Thomas Lively | 6a87dda | 2019-01-08 06:25:55 +0000 | [diff] [blame] | 219 | // COPY is not an actual instruction in wasm, but since we allow local.get and |
| 220 | // local.set to be implicit during most of codegen, we can have a COPY which |
| 221 | // is actually a no-op because all the work is done in the implied local.get |
| 222 | // and local.set. COPYs are eliminated (and replaced with |
| 223 | // local.get/local.set) in the ExplicitLocals pass. |
Dan Gohman | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 224 | let isAsCheapAsAMove = 1, isCodeGenOnly = 1 in |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 225 | defm COPY_#vt : I<(outs vt:$res), (ins vt:$src), (outs), (ins), [], |
Thomas Lively | 6a87dda | 2019-01-08 06:25:55 +0000 | [diff] [blame] | 226 | "local.copy\t$res, $src", "local.copy">; |
Dan Gohman | adf2817 | 2016-01-28 01:22:44 +0000 | [diff] [blame] | 227 | |
Dan Gohman | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 228 | // TEE is similar to COPY, but writes two copies of its result. Typically |
| 229 | // this would be used to stackify one result and write the other result to a |
| 230 | // local. |
| 231 | let isAsCheapAsAMove = 1, isCodeGenOnly = 1 in |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 232 | defm TEE_#vt : I<(outs vt:$res, vt:$also), (ins vt:$src), (outs), (ins), [], |
Thomas Lively | 6a87dda | 2019-01-08 06:25:55 +0000 | [diff] [blame] | 233 | "local.tee\t$res, $also, $src", "local.tee">; |
Dan Gohman | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 234 | |
Thomas Lively | 6a87dda | 2019-01-08 06:25:55 +0000 | [diff] [blame] | 235 | // This is the actual local.get instruction in wasm. These are made explicit |
Dan Gohman | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 236 | // by the ExplicitLocals pass. It has mayLoad because it reads from a wasm |
| 237 | // local, which is a side effect not otherwise modeled in LLVM. |
| 238 | let mayLoad = 1, isAsCheapAsAMove = 1 in |
Thomas Lively | 6a87dda | 2019-01-08 06:25:55 +0000 | [diff] [blame] | 239 | defm LOCAL_GET_#vt : I<(outs vt:$res), (ins local_op:$local), |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 240 | (outs), (ins local_op:$local), [], |
Thomas Lively | 6a87dda | 2019-01-08 06:25:55 +0000 | [diff] [blame] | 241 | "local.get\t$res, $local", "local.get\t$local", 0x20>; |
Dan Gohman | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 242 | |
Thomas Lively | 6a87dda | 2019-01-08 06:25:55 +0000 | [diff] [blame] | 243 | // This is the actual local.set instruction in wasm. These are made explicit |
Dan Gohman | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 244 | // by the ExplicitLocals pass. It has mayStore because it writes to a wasm |
| 245 | // local, which is a side effect not otherwise modeled in LLVM. |
| 246 | let mayStore = 1, isAsCheapAsAMove = 1 in |
Thomas Lively | 6a87dda | 2019-01-08 06:25:55 +0000 | [diff] [blame] | 247 | defm LOCAL_SET_#vt : I<(outs), (ins local_op:$local, vt:$src), |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 248 | (outs), (ins local_op:$local), [], |
Thomas Lively | 6a87dda | 2019-01-08 06:25:55 +0000 | [diff] [blame] | 249 | "local.set\t$local, $src", "local.set\t$local", 0x21>; |
Dan Gohman | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 250 | |
Thomas Lively | 6a87dda | 2019-01-08 06:25:55 +0000 | [diff] [blame] | 251 | // This is the actual local.tee instruction in wasm. TEEs are turned into |
| 252 | // LOCAL_TEEs by the ExplicitLocals pass. It has mayStore for the same reason |
| 253 | // as LOCAL_SET. |
Dan Gohman | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 254 | let mayStore = 1, isAsCheapAsAMove = 1 in |
Thomas Lively | 6a87dda | 2019-01-08 06:25:55 +0000 | [diff] [blame] | 255 | defm LOCAL_TEE_#vt : I<(outs vt:$res), (ins local_op:$local, vt:$src), |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 256 | (outs), (ins local_op:$local), [], |
Thomas Lively | 6a87dda | 2019-01-08 06:25:55 +0000 | [diff] [blame] | 257 | "local.tee\t$res, $local, $src", "local.tee\t$local", |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 258 | 0x22>; |
Dan Gohman | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 259 | |
Dan Gohman | b89f2d3 | 2017-02-02 19:29:44 +0000 | [diff] [blame] | 260 | // Unused values must be dropped in some contexts. |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 261 | defm DROP_#vt : I<(outs), (ins vt:$src), (outs), (ins), [], |
| 262 | "drop\t$src", "drop", 0x1a>; |
Dan Gohman | b89f2d3 | 2017-02-02 19:29:44 +0000 | [diff] [blame] | 263 | |
| 264 | let mayLoad = 1 in |
Thomas Lively | 6a87dda | 2019-01-08 06:25:55 +0000 | [diff] [blame] | 265 | defm GLOBAL_GET_#vt : I<(outs vt:$res), (ins global_op:$local), |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 266 | (outs), (ins global_op:$local), [], |
Thomas Lively | 6a87dda | 2019-01-08 06:25:55 +0000 | [diff] [blame] | 267 | "global.get\t$res, $local", "global.get\t$local", |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 268 | 0x23>; |
Dan Gohman | b89f2d3 | 2017-02-02 19:29:44 +0000 | [diff] [blame] | 269 | |
| 270 | let mayStore = 1 in |
Thomas Lively | 6a87dda | 2019-01-08 06:25:55 +0000 | [diff] [blame] | 271 | defm GLOBAL_SET_#vt : I<(outs), (ins global_op:$local, vt:$src), |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 272 | (outs), (ins global_op:$local), [], |
Thomas Lively | 6a87dda | 2019-01-08 06:25:55 +0000 | [diff] [blame] | 273 | "global.set\t$local, $src", "global.set\t$local", |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 274 | 0x24>; |
Dan Gohman | b89f2d3 | 2017-02-02 19:29:44 +0000 | [diff] [blame] | 275 | |
Dan Gohman | 4817a75 | 2016-05-16 19:16:32 +0000 | [diff] [blame] | 276 | } // hasSideEffects = 0 |
Dan Gohman | 4ba4816 | 2015-11-18 16:12:01 +0000 | [diff] [blame] | 277 | } |
Sam Clegg | 537afe6 | 2018-06-04 16:59:26 +0000 | [diff] [blame] | 278 | defm "" : LOCAL<I32>; |
| 279 | defm "" : LOCAL<I64>; |
| 280 | defm "" : LOCAL<F32>; |
| 281 | defm "" : LOCAL<F64>; |
| 282 | defm "" : LOCAL<V128>, Requires<[HasSIMD128]>; |
| 283 | defm "" : LOCAL<EXCEPT_REF>, Requires<[HasExceptionHandling]>; |
JF Bastien | 4a64225 | 2015-08-10 22:36:48 +0000 | [diff] [blame] | 284 | |
Dan Gohman | b6fd39a | 2016-01-19 16:59:23 +0000 | [diff] [blame] | 285 | let isMoveImm = 1, isAsCheapAsAMove = 1, isReMaterializable = 1 in { |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 286 | defm CONST_I32 : I<(outs I32:$res), (ins i32imm_op:$imm), |
| 287 | (outs), (ins i32imm_op:$imm), |
| 288 | [(set I32:$res, imm:$imm)], |
| 289 | "i32.const\t$res, $imm", "i32.const\t$imm", 0x41>; |
| 290 | defm CONST_I64 : I<(outs I64:$res), (ins i64imm_op:$imm), |
| 291 | (outs), (ins i64imm_op:$imm), |
| 292 | [(set I64:$res, imm:$imm)], |
| 293 | "i64.const\t$res, $imm", "i64.const\t$imm", 0x42>; |
| 294 | defm CONST_F32 : I<(outs F32:$res), (ins f32imm_op:$imm), |
| 295 | (outs), (ins f32imm_op:$imm), |
| 296 | [(set F32:$res, fpimm:$imm)], |
| 297 | "f32.const\t$res, $imm", "f32.const\t$imm", 0x43>; |
| 298 | defm CONST_F64 : I<(outs F64:$res), (ins f64imm_op:$imm), |
| 299 | (outs), (ins f64imm_op:$imm), |
| 300 | [(set F64:$res, fpimm:$imm)], |
| 301 | "f64.const\t$res, $imm", "f64.const\t$imm", 0x44>; |
Dan Gohman | b6fd39a | 2016-01-19 16:59:23 +0000 | [diff] [blame] | 302 | } // isMoveImm = 1, isAsCheapAsAMove = 1, isReMaterializable = 1 |
JF Bastien | 4a64225 | 2015-08-10 22:36:48 +0000 | [diff] [blame] | 303 | |
Dan Gohman | 8633eed | 2016-01-08 00:50:33 +0000 | [diff] [blame] | 304 | def : Pat<(i32 (WebAssemblywrapper tglobaladdr:$addr)), |
Sam Clegg | 492f752 | 2019-03-26 19:46:15 +0000 | [diff] [blame] | 305 | (CONST_I32 tglobaladdr:$addr)>, Requires<[IsNotPIC]>; |
| 306 | |
| 307 | def : Pat<(i32 (WebAssemblywrapper tglobaladdr:$addr)), |
| 308 | (GLOBAL_GET_I32 tglobaladdr:$addr)>, Requires<[IsPIC]>; |
| 309 | |
| 310 | def : Pat<(i32 (WebAssemblywrapperPIC tglobaladdr:$addr)), |
| 311 | (CONST_I32 tglobaladdr:$addr)>, Requires<[IsPIC]>; |
| 312 | |
Dan Gohman | 8633eed | 2016-01-08 00:50:33 +0000 | [diff] [blame] | 313 | def : Pat<(i32 (WebAssemblywrapper texternalsym:$addr)), |
Sam Clegg | 492f752 | 2019-03-26 19:46:15 +0000 | [diff] [blame] | 314 | (GLOBAL_GET_I32 texternalsym:$addr)>, Requires<[IsPIC]>; |
| 315 | |
| 316 | def : Pat<(i32 (WebAssemblywrapper texternalsym:$addr)), |
| 317 | (CONST_I32 texternalsym:$addr)>, Requires<[IsNotPIC]>; |
| 318 | |
Heejin Ahn | 24faf85 | 2018-10-25 23:55:10 +0000 | [diff] [blame] | 319 | def : Pat<(i32 (WebAssemblywrapper mcsym:$sym)), (CONST_I32 mcsym:$sym)>; |
| 320 | def : Pat<(i64 (WebAssemblywrapper mcsym:$sym)), (CONST_I64 mcsym:$sym)>; |
Derek Schuff | 71e8169 | 2015-11-17 00:20:44 +0000 | [diff] [blame] | 321 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 322 | //===----------------------------------------------------------------------===// |
| 323 | // Additional sets of instructions. |
| 324 | //===----------------------------------------------------------------------===// |
| 325 | |
JF Bastien | 5ca0bac | 2015-07-10 18:23:10 +0000 | [diff] [blame] | 326 | include "WebAssemblyInstrMemory.td" |
| 327 | include "WebAssemblyInstrCall.td" |
JF Bastien | 600aee9 | 2015-07-31 17:53:38 +0000 | [diff] [blame] | 328 | include "WebAssemblyInstrControl.td" |
JF Bastien | 5ca0bac | 2015-07-10 18:23:10 +0000 | [diff] [blame] | 329 | include "WebAssemblyInstrInteger.td" |
JF Bastien | 5ca0bac | 2015-07-10 18:23:10 +0000 | [diff] [blame] | 330 | include "WebAssemblyInstrConv.td" |
Dan Gohman | f170ba0 | 2015-12-10 04:55:31 +0000 | [diff] [blame] | 331 | include "WebAssemblyInstrFloat.td" |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 332 | include "WebAssemblyInstrAtomics.td" |
| 333 | include "WebAssemblyInstrSIMD.td" |
Heejin Ahn | 0de5872 | 2018-03-08 04:05:37 +0000 | [diff] [blame] | 334 | include "WebAssemblyInstrExceptRef.td" |
Thomas Lively | d99af23 | 2019-02-05 00:49:55 +0000 | [diff] [blame] | 335 | include "WebAssemblyInstrBulkMemory.td" |