blob: d9e87e017a6ae94d194761d05d5e374f7bff3630 [file] [log] [blame]
Dan Gohman10e730a2015-06-29 23:51:55 +00001// 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 Bastien5ca0bac2015-07-10 18:23:10 +00009///
10/// \file
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000011/// WebAssembly Instruction definitions.
JF Bastien5ca0bac2015-07-10 18:23:10 +000012///
Dan Gohman10e730a2015-06-29 23:51:55 +000013//===----------------------------------------------------------------------===//
14
15//===----------------------------------------------------------------------===//
16// WebAssembly Instruction Predicate Definitions.
17//===----------------------------------------------------------------------===//
18
JF Bastien03855df2015-07-01 23:41:25 +000019def HasAddr32 : Predicate<"!Subtarget->hasAddr64()">;
20def HasAddr64 : Predicate<"Subtarget->hasAddr64()">;
21def HasSIMD128 : Predicate<"Subtarget->hasSIMD128()">,
22 AssemblerPredicate<"FeatureSIMD128", "simd128">;
Derek Schuff18ba1922017-08-30 18:07:45 +000023def HasAtomics : Predicate<"Subtarget->hasAtomics()">,
24 AssemblerPredicate<"FeatureAtomics", "atomics">;
Dan Gohmancdd48b82017-11-28 01:13:40 +000025def HasNontrappingFPToInt :
26 Predicate<"Subtarget->hasNontrappingFPToInt()">,
27 AssemblerPredicate<"FeatureNontrappingFPToInt",
28 "nontrapping-fptoint">;
29def NotHasNontrappingFPToInt :
30 Predicate<"!Subtarget->hasNontrappingFPToInt()">,
31 AssemblerPredicate<"!FeatureNontrappingFPToInt",
32 "nontrapping-fptoint">;
Dan Gohman5d2b9352018-01-19 17:16:24 +000033def HasSignExt :
34 Predicate<"Subtarget->hasSignExt()">,
35 AssemblerPredicate<"FeatureSignExt",
36 "sign-ext">;
37def NotHasSignExt :
38 Predicate<"!Subtarget->hasSignExt()">,
39 AssemblerPredicate<"!FeatureSignExt",
40 "sign-ext">;
JF Bastien03855df2015-07-01 23:41:25 +000041
Heejin Ahn9386bde2018-02-24 00:40:50 +000042def HasExceptionHandling :
43 Predicate<"Subtarget->hasExceptionHandling()">,
44 AssemblerPredicate<"FeatureExceptionHandling",
45 "exception-handling">;
46
47def NotHasExceptionHandling :
48 Predicate<"!Subtarget->hasExceptionHandling()">,
49 AssemblerPredicate<"!FeatureExceptionHandling",
50 "exception-handling">;
51
Dan Gohman10e730a2015-06-29 23:51:55 +000052//===----------------------------------------------------------------------===//
53// WebAssembly-specific DAG Node Types.
54//===----------------------------------------------------------------------===//
55
Serge Pavlovd526b132017-05-09 13:35:13 +000056def SDT_WebAssemblyCallSeqStart : SDCallSeqStart<[SDTCisVT<0, iPTR>,
57 SDTCisVT<1, iPTR>]>;
JF Bastienaf111db2015-08-24 22:16:48 +000058def SDT_WebAssemblyCallSeqEnd :
59 SDCallSeqEnd<[SDTCisVT<0, iPTR>, SDTCisVT<1, iPTR>]>;
Dan Gohmanf71abef2015-09-09 16:13:47 +000060def SDT_WebAssemblyCall0 : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>;
61def SDT_WebAssemblyCall1 : SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>;
Dan Gohman14026062016-03-08 03:18:12 +000062def SDT_WebAssemblyBrTable : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>;
JF Bastien600aee92015-07-31 17:53:38 +000063def SDT_WebAssemblyArgument : SDTypeProfile<1, 1, [SDTCisVT<1, i32>]>;
JF Bastien4a2d5602015-07-31 21:04:18 +000064def SDT_WebAssemblyReturn : SDTypeProfile<0, -1, []>;
JF Bastienaf111db2015-08-24 22:16:48 +000065def SDT_WebAssemblyWrapper : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>,
66 SDTCisPtrTy<0>]>;
JF Bastien600aee92015-07-31 17:53:38 +000067
Dan Gohman10e730a2015-06-29 23:51:55 +000068//===----------------------------------------------------------------------===//
69// WebAssembly-specific DAG Nodes.
70//===----------------------------------------------------------------------===//
71
JF Bastienaf111db2015-08-24 22:16:48 +000072def WebAssemblycallseq_start :
73 SDNode<"ISD::CALLSEQ_START", SDT_WebAssemblyCallSeqStart,
74 [SDNPHasChain, SDNPOutGlue]>;
75def WebAssemblycallseq_end :
76 SDNode<"ISD::CALLSEQ_END", SDT_WebAssemblyCallSeqEnd,
77 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
Dan Gohmanf71abef2015-09-09 16:13:47 +000078def WebAssemblycall0 : SDNode<"WebAssemblyISD::CALL0",
79 SDT_WebAssemblyCall0,
80 [SDNPHasChain, SDNPVariadic]>;
81def WebAssemblycall1 : SDNode<"WebAssemblyISD::CALL1",
82 SDT_WebAssemblyCall1,
83 [SDNPHasChain, SDNPVariadic]>;
Dan Gohman14026062016-03-08 03:18:12 +000084def WebAssemblybr_table : SDNode<"WebAssemblyISD::BR_TABLE",
85 SDT_WebAssemblyBrTable,
86 [SDNPHasChain, SDNPVariadic]>;
JF Bastien600aee92015-07-31 17:53:38 +000087def WebAssemblyargument : SDNode<"WebAssemblyISD::ARGUMENT",
88 SDT_WebAssemblyArgument>;
89def WebAssemblyreturn : SDNode<"WebAssemblyISD::RETURN",
JF Bastienaf111db2015-08-24 22:16:48 +000090 SDT_WebAssemblyReturn, [SDNPHasChain]>;
91def WebAssemblywrapper : SDNode<"WebAssemblyISD::Wrapper",
92 SDT_WebAssemblyWrapper>;
JF Bastien600aee92015-07-31 17:53:38 +000093
Dan Gohman10e730a2015-06-29 23:51:55 +000094//===----------------------------------------------------------------------===//
95// WebAssembly-specific Operands.
96//===----------------------------------------------------------------------===//
97
Dan Gohmana11fb232016-01-12 03:09:16 +000098let OperandNamespace = "WebAssembly" in {
99
100let OperandType = "OPERAND_BASIC_BLOCK" in
Dan Gohman950a13c2015-09-16 16:51:30 +0000101def bb_op : Operand<OtherVT>;
JF Bastienaf111db2015-08-24 22:16:48 +0000102
Dan Gohman4fc4e422016-10-24 19:49:43 +0000103let OperandType = "OPERAND_LOCAL" in
104def local_op : Operand<i32>;
105
Dan Gohmanb89f2d32017-02-02 19:29:44 +0000106let OperandType = "OPERAND_GLOBAL" in
107def global_op : Operand<i32>;
108
Dan Gohman5a68ec72016-10-05 21:24:08 +0000109let OperandType = "OPERAND_I32IMM" in
110def i32imm_op : Operand<i32>;
111
112let OperandType = "OPERAND_I64IMM" in
113def i64imm_op : Operand<i64>;
114
Dan Gohman4b8e8be2016-10-03 21:31:31 +0000115let OperandType = "OPERAND_F32IMM" in
Dan Gohmana11fb232016-01-12 03:09:16 +0000116def f32imm_op : Operand<f32>;
Dan Gohmanaa742912016-02-16 15:14:23 +0000117
Dan Gohman4b8e8be2016-10-03 21:31:31 +0000118let OperandType = "OPERAND_F64IMM" in
Dan Gohmana11fb232016-01-12 03:09:16 +0000119def f64imm_op : Operand<f64>;
Dan Gohmana11fb232016-01-12 03:09:16 +0000120
Thomas Lively22442922018-08-21 21:03:18 +0000121let OperandType = "OPERAND_VEC_I8IMM" in
122def vec_i8imm_op : Operand<i32>;
123
124let OperandType = "OPERAND_VEC_I16IMM" in
125def vec_i16imm_op : Operand<i32>;
126
127let OperandType = "OPERAND_VEC_I32IMM" in
128def vec_i32imm_op : Operand<i32>;
129
130let OperandType = "OPERAND_VEC_I64IMM" in
131def vec_i64imm_op : Operand<i64>;
132
Dan Gohman00d734d2016-12-23 03:23:52 +0000133let OperandType = "OPERAND_FUNCTION32" in
134def function32_op : Operand<i32>;
135
136let OperandType = "OPERAND_OFFSET32" in
137def offset32_op : Operand<i32>;
138
Dan Gohmanbb372242016-01-26 03:39:31 +0000139let OperandType = "OPERAND_P2ALIGN" in {
140def P2Align : Operand<i32> {
141 let PrintMethod = "printWebAssemblyP2AlignOperand";
142}
143} // OperandType = "OPERAND_P2ALIGN"
144
Dan Gohman2726b882016-10-06 22:29:32 +0000145let OperandType = "OPERAND_SIGNATURE" in {
146def Signature : Operand<i32> {
147 let PrintMethod = "printWebAssemblySignatureOperand";
148}
149} // OperandType = "OPERAND_SIGNATURE"
150
Dan Gohmand934cb82017-02-24 23:18:00 +0000151let OperandType = "OPERAND_TYPEINDEX" in
152def TypeIndex : Operand<i32>;
153
Dan Gohmana11fb232016-01-12 03:09:16 +0000154} // OperandNamespace = "WebAssembly"
155
Dan Gohman10e730a2015-06-29 23:51:55 +0000156//===----------------------------------------------------------------------===//
157// WebAssembly Instruction Format Definitions.
158//===----------------------------------------------------------------------===//
159
160include "WebAssemblyInstrFormats.td"
161
Dan Gohman4ba48162015-11-18 16:12:01 +0000162//===----------------------------------------------------------------------===//
163// Additional instructions.
164//===----------------------------------------------------------------------===//
165
JF Bastien8f9aea02015-08-01 04:48:44 +0000166multiclass ARGUMENT<WebAssemblyRegClass vt> {
Dan Gohmana783f102015-12-21 16:53:29 +0000167 let hasSideEffects = 1, Uses = [ARGUMENTS], isCodeGenOnly = 1 in
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000168 defm ARGUMENT_#vt : I<(outs vt:$res), (ins i32imm:$argno),
169 (outs), (ins i32imm:$argno),
170 [(set vt:$res, (WebAssemblyargument timm:$argno))]>;
JF Bastien8f9aea02015-08-01 04:48:44 +0000171}
Derek Schuff39bf39f2016-08-02 23:16:09 +0000172multiclass SIMD_ARGUMENT<ValueType vt> {
173 let hasSideEffects = 1, Uses = [ARGUMENTS], isCodeGenOnly = 1 in
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000174 defm ARGUMENT_#vt : SIMD_I<(outs V128:$res), (ins i32imm:$argno),
175 (outs), (ins i32imm:$argno),
176 [(set (vt V128:$res),
Derek Schuff39bf39f2016-08-02 23:16:09 +0000177 (WebAssemblyargument timm:$argno))]>;
178}
Sam Clegg537afe62018-06-04 16:59:26 +0000179defm "": ARGUMENT<I32>;
180defm "": ARGUMENT<I64>;
181defm "": ARGUMENT<F32>;
182defm "": ARGUMENT<F64>;
183defm "": ARGUMENT<EXCEPT_REF>;
184defm "": SIMD_ARGUMENT<v16i8>;
185defm "": SIMD_ARGUMENT<v8i16>;
186defm "": SIMD_ARGUMENT<v4i32>;
Derek Schuff51ed1312018-08-07 21:24:01 +0000187defm "": SIMD_ARGUMENT<v2i64>;
Sam Clegg537afe62018-06-04 16:59:26 +0000188defm "": SIMD_ARGUMENT<v4f32>;
Derek Schuff51ed1312018-08-07 21:24:01 +0000189defm "": SIMD_ARGUMENT<v2f64>;
JF Bastien600aee92015-07-31 17:53:38 +0000190
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000191let Defs = [ARGUMENTS] in {
192
Dan Gohman4ba48162015-11-18 16:12:01 +0000193// get_local and set_local are not generated by instruction selection; they
Dan Gohmanadf28172016-01-28 01:22:44 +0000194// are implied by virtual register uses and defs.
Dan Gohman4ba48162015-11-18 16:12:01 +0000195multiclass LOCAL<WebAssemblyRegClass vt> {
Dan Gohman4817a752016-05-16 19:16:32 +0000196let hasSideEffects = 0 in {
Dan Gohman4fc4e422016-10-24 19:49:43 +0000197 // COPY is not an actual instruction in wasm, but since we allow get_local and
198 // set_local to be implicit during most of codegen, we can have a COPY which
199 // is actually a no-op because all the work is done in the implied get_local
200 // and set_local. COPYs are eliminated (and replaced with
201 // get_local/set_local) in the ExplicitLocals pass.
202 let isAsCheapAsAMove = 1, isCodeGenOnly = 1 in
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000203 defm COPY_#vt : I<(outs vt:$res), (ins vt:$src), (outs), (ins), [],
204 "copy_local\t$res, $src", "copy_local">;
Dan Gohmanadf28172016-01-28 01:22:44 +0000205
Dan Gohman4fc4e422016-10-24 19:49:43 +0000206 // TEE is similar to COPY, but writes two copies of its result. Typically
207 // this would be used to stackify one result and write the other result to a
208 // local.
209 let isAsCheapAsAMove = 1, isCodeGenOnly = 1 in
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000210 defm TEE_#vt : I<(outs vt:$res, vt:$also), (ins vt:$src), (outs), (ins), [],
211 "tee_local\t$res, $also, $src", "tee_local">;
Dan Gohman4fc4e422016-10-24 19:49:43 +0000212
213 // This is the actual get_local instruction in wasm. These are made explicit
214 // by the ExplicitLocals pass. It has mayLoad because it reads from a wasm
215 // local, which is a side effect not otherwise modeled in LLVM.
216 let mayLoad = 1, isAsCheapAsAMove = 1 in
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000217 defm GET_LOCAL_#vt : I<(outs vt:$res), (ins local_op:$local),
218 (outs), (ins local_op:$local), [],
219 "get_local\t$res, $local", "get_local\t$local", 0x20>;
Dan Gohman4fc4e422016-10-24 19:49:43 +0000220
221 // This is the actual set_local instruction in wasm. These are made explicit
222 // by the ExplicitLocals pass. It has mayStore because it writes to a wasm
223 // local, which is a side effect not otherwise modeled in LLVM.
224 let mayStore = 1, isAsCheapAsAMove = 1 in
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000225 defm SET_LOCAL_#vt : I<(outs), (ins local_op:$local, vt:$src),
226 (outs), (ins local_op:$local), [],
227 "set_local\t$local, $src", "set_local\t$local", 0x21>;
Dan Gohman4fc4e422016-10-24 19:49:43 +0000228
229 // This is the actual tee_local instruction in wasm. TEEs are turned into
230 // TEE_LOCALs by the ExplicitLocals pass. It has mayStore for the same reason
231 // as SET_LOCAL.
232 let mayStore = 1, isAsCheapAsAMove = 1 in
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000233 defm TEE_LOCAL_#vt : I<(outs vt:$res), (ins local_op:$local, vt:$src),
234 (outs), (ins local_op:$local), [],
235 "tee_local\t$res, $local, $src", "tee_local\t$local",
236 0x22>;
Dan Gohman4fc4e422016-10-24 19:49:43 +0000237
Dan Gohmanb89f2d32017-02-02 19:29:44 +0000238 // Unused values must be dropped in some contexts.
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000239 defm DROP_#vt : I<(outs), (ins vt:$src), (outs), (ins), [],
240 "drop\t$src", "drop", 0x1a>;
Dan Gohmanb89f2d32017-02-02 19:29:44 +0000241
242 let mayLoad = 1 in
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000243 defm GET_GLOBAL_#vt : I<(outs vt:$res), (ins global_op:$local),
244 (outs), (ins global_op:$local), [],
245 "get_global\t$res, $local", "get_global\t$local",
246 0x23>;
Dan Gohmanb89f2d32017-02-02 19:29:44 +0000247
248 let mayStore = 1 in
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000249 defm SET_GLOBAL_#vt : I<(outs), (ins global_op:$local, vt:$src),
250 (outs), (ins global_op:$local), [],
251 "set_global\t$local, $src", "set_global\t$local",
252 0x24>;
Dan Gohmanb89f2d32017-02-02 19:29:44 +0000253
Dan Gohman4817a752016-05-16 19:16:32 +0000254} // hasSideEffects = 0
Dan Gohman4ba48162015-11-18 16:12:01 +0000255}
Sam Clegg537afe62018-06-04 16:59:26 +0000256defm "" : LOCAL<I32>;
257defm "" : LOCAL<I64>;
258defm "" : LOCAL<F32>;
259defm "" : LOCAL<F64>;
260defm "" : LOCAL<V128>, Requires<[HasSIMD128]>;
261defm "" : LOCAL<EXCEPT_REF>, Requires<[HasExceptionHandling]>;
JF Bastien4a642252015-08-10 22:36:48 +0000262
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000263let isMoveImm = 1, isAsCheapAsAMove = 1, isReMaterializable = 1 in {
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000264defm CONST_I32 : I<(outs I32:$res), (ins i32imm_op:$imm),
265 (outs), (ins i32imm_op:$imm),
266 [(set I32:$res, imm:$imm)],
267 "i32.const\t$res, $imm", "i32.const\t$imm", 0x41>;
268defm CONST_I64 : I<(outs I64:$res), (ins i64imm_op:$imm),
269 (outs), (ins i64imm_op:$imm),
270 [(set I64:$res, imm:$imm)],
271 "i64.const\t$res, $imm", "i64.const\t$imm", 0x42>;
272defm CONST_F32 : I<(outs F32:$res), (ins f32imm_op:$imm),
273 (outs), (ins f32imm_op:$imm),
274 [(set F32:$res, fpimm:$imm)],
275 "f32.const\t$res, $imm", "f32.const\t$imm", 0x43>;
276defm CONST_F64 : I<(outs F64:$res), (ins f64imm_op:$imm),
277 (outs), (ins f64imm_op:$imm),
278 [(set F64:$res, fpimm:$imm)],
279 "f64.const\t$res, $imm", "f64.const\t$imm", 0x44>;
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000280} // isMoveImm = 1, isAsCheapAsAMove = 1, isReMaterializable = 1
JF Bastien4a642252015-08-10 22:36:48 +0000281
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000282} // Defs = [ARGUMENTS]
283
Dan Gohman8633eed2016-01-08 00:50:33 +0000284def : Pat<(i32 (WebAssemblywrapper tglobaladdr:$addr)),
285 (CONST_I32 tglobaladdr:$addr)>;
286def : Pat<(i32 (WebAssemblywrapper texternalsym:$addr)),
287 (CONST_I32 texternalsym:$addr)>;
Derek Schuff71e81692015-11-17 00:20:44 +0000288
Dan Gohman10e730a2015-06-29 23:51:55 +0000289//===----------------------------------------------------------------------===//
290// Additional sets of instructions.
291//===----------------------------------------------------------------------===//
292
JF Bastien5ca0bac2015-07-10 18:23:10 +0000293include "WebAssemblyInstrMemory.td"
294include "WebAssemblyInstrCall.td"
JF Bastien600aee92015-07-31 17:53:38 +0000295include "WebAssemblyInstrControl.td"
JF Bastien5ca0bac2015-07-10 18:23:10 +0000296include "WebAssemblyInstrInteger.td"
JF Bastien5ca0bac2015-07-10 18:23:10 +0000297include "WebAssemblyInstrConv.td"
Dan Gohmanf170ba02015-12-10 04:55:31 +0000298include "WebAssemblyInstrFloat.td"
Dan Gohman10e730a2015-06-29 23:51:55 +0000299include "WebAssemblyInstrAtomics.td"
300include "WebAssemblyInstrSIMD.td"
Heejin Ahn0de58722018-03-08 04:05:37 +0000301include "WebAssemblyInstrExceptRef.td"