blob: 3f97ef5f7b7ae66778821a79f5a0e151804b6190 [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
Dan Gohman00d734d2016-12-23 03:23:52 +0000121let OperandType = "OPERAND_FUNCTION32" in
122def function32_op : Operand<i32>;
123
124let OperandType = "OPERAND_OFFSET32" in
125def offset32_op : Operand<i32>;
126
Dan Gohmanbb372242016-01-26 03:39:31 +0000127let OperandType = "OPERAND_P2ALIGN" in {
128def P2Align : Operand<i32> {
129 let PrintMethod = "printWebAssemblyP2AlignOperand";
130}
131} // OperandType = "OPERAND_P2ALIGN"
132
Dan Gohman2726b882016-10-06 22:29:32 +0000133let OperandType = "OPERAND_SIGNATURE" in {
134def Signature : Operand<i32> {
135 let PrintMethod = "printWebAssemblySignatureOperand";
136}
137} // OperandType = "OPERAND_SIGNATURE"
138
Dan Gohmand934cb82017-02-24 23:18:00 +0000139let OperandType = "OPERAND_TYPEINDEX" in
140def TypeIndex : Operand<i32>;
141
Dan Gohmana11fb232016-01-12 03:09:16 +0000142} // OperandNamespace = "WebAssembly"
143
Dan Gohman10e730a2015-06-29 23:51:55 +0000144//===----------------------------------------------------------------------===//
145// WebAssembly Instruction Format Definitions.
146//===----------------------------------------------------------------------===//
147
148include "WebAssemblyInstrFormats.td"
149
Dan Gohman4ba48162015-11-18 16:12:01 +0000150//===----------------------------------------------------------------------===//
151// Additional instructions.
152//===----------------------------------------------------------------------===//
153
JF Bastien8f9aea02015-08-01 04:48:44 +0000154multiclass ARGUMENT<WebAssemblyRegClass vt> {
Dan Gohmana783f102015-12-21 16:53:29 +0000155 let hasSideEffects = 1, Uses = [ARGUMENTS], isCodeGenOnly = 1 in
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000156 defm ARGUMENT_#vt : I<(outs vt:$res), (ins i32imm:$argno),
157 (outs), (ins i32imm:$argno),
158 [(set vt:$res, (WebAssemblyargument timm:$argno))]>;
JF Bastien8f9aea02015-08-01 04:48:44 +0000159}
Derek Schuff39bf39f2016-08-02 23:16:09 +0000160multiclass SIMD_ARGUMENT<ValueType vt> {
161 let hasSideEffects = 1, Uses = [ARGUMENTS], isCodeGenOnly = 1 in
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000162 defm ARGUMENT_#vt : SIMD_I<(outs V128:$res), (ins i32imm:$argno),
163 (outs), (ins i32imm:$argno),
164 [(set (vt V128:$res),
Derek Schuff39bf39f2016-08-02 23:16:09 +0000165 (WebAssemblyargument timm:$argno))]>;
166}
Sam Clegg537afe62018-06-04 16:59:26 +0000167defm "": ARGUMENT<I32>;
168defm "": ARGUMENT<I64>;
169defm "": ARGUMENT<F32>;
170defm "": ARGUMENT<F64>;
171defm "": ARGUMENT<EXCEPT_REF>;
172defm "": SIMD_ARGUMENT<v16i8>;
173defm "": SIMD_ARGUMENT<v8i16>;
174defm "": SIMD_ARGUMENT<v4i32>;
Derek Schuff51ed1312018-08-07 21:24:01 +0000175defm "": SIMD_ARGUMENT<v2i64>;
Sam Clegg537afe62018-06-04 16:59:26 +0000176defm "": SIMD_ARGUMENT<v4f32>;
Derek Schuff51ed1312018-08-07 21:24:01 +0000177defm "": SIMD_ARGUMENT<v2f64>;
JF Bastien600aee92015-07-31 17:53:38 +0000178
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000179let Defs = [ARGUMENTS] in {
180
Dan Gohman4ba48162015-11-18 16:12:01 +0000181// get_local and set_local are not generated by instruction selection; they
Dan Gohmanadf28172016-01-28 01:22:44 +0000182// are implied by virtual register uses and defs.
Dan Gohman4ba48162015-11-18 16:12:01 +0000183multiclass LOCAL<WebAssemblyRegClass vt> {
Dan Gohman4817a752016-05-16 19:16:32 +0000184let hasSideEffects = 0 in {
Dan Gohman4fc4e422016-10-24 19:49:43 +0000185 // COPY is not an actual instruction in wasm, but since we allow get_local and
186 // set_local to be implicit during most of codegen, we can have a COPY which
187 // is actually a no-op because all the work is done in the implied get_local
188 // and set_local. COPYs are eliminated (and replaced with
189 // get_local/set_local) in the ExplicitLocals pass.
190 let isAsCheapAsAMove = 1, isCodeGenOnly = 1 in
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000191 defm COPY_#vt : I<(outs vt:$res), (ins vt:$src), (outs), (ins), [],
192 "copy_local\t$res, $src", "copy_local">;
Dan Gohmanadf28172016-01-28 01:22:44 +0000193
Dan Gohman4fc4e422016-10-24 19:49:43 +0000194 // TEE is similar to COPY, but writes two copies of its result. Typically
195 // this would be used to stackify one result and write the other result to a
196 // local.
197 let isAsCheapAsAMove = 1, isCodeGenOnly = 1 in
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000198 defm TEE_#vt : I<(outs vt:$res, vt:$also), (ins vt:$src), (outs), (ins), [],
199 "tee_local\t$res, $also, $src", "tee_local">;
Dan Gohman4fc4e422016-10-24 19:49:43 +0000200
201 // This is the actual get_local instruction in wasm. These are made explicit
202 // by the ExplicitLocals pass. It has mayLoad because it reads from a wasm
203 // local, which is a side effect not otherwise modeled in LLVM.
204 let mayLoad = 1, isAsCheapAsAMove = 1 in
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000205 defm GET_LOCAL_#vt : I<(outs vt:$res), (ins local_op:$local),
206 (outs), (ins local_op:$local), [],
207 "get_local\t$res, $local", "get_local\t$local", 0x20>;
Dan Gohman4fc4e422016-10-24 19:49:43 +0000208
209 // This is the actual set_local instruction in wasm. These are made explicit
210 // by the ExplicitLocals pass. It has mayStore because it writes to a wasm
211 // local, which is a side effect not otherwise modeled in LLVM.
212 let mayStore = 1, isAsCheapAsAMove = 1 in
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000213 defm SET_LOCAL_#vt : I<(outs), (ins local_op:$local, vt:$src),
214 (outs), (ins local_op:$local), [],
215 "set_local\t$local, $src", "set_local\t$local", 0x21>;
Dan Gohman4fc4e422016-10-24 19:49:43 +0000216
217 // This is the actual tee_local instruction in wasm. TEEs are turned into
218 // TEE_LOCALs by the ExplicitLocals pass. It has mayStore for the same reason
219 // as SET_LOCAL.
220 let mayStore = 1, isAsCheapAsAMove = 1 in
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000221 defm TEE_LOCAL_#vt : I<(outs vt:$res), (ins local_op:$local, vt:$src),
222 (outs), (ins local_op:$local), [],
223 "tee_local\t$res, $local, $src", "tee_local\t$local",
224 0x22>;
Dan Gohman4fc4e422016-10-24 19:49:43 +0000225
Dan Gohmanb89f2d32017-02-02 19:29:44 +0000226 // Unused values must be dropped in some contexts.
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000227 defm DROP_#vt : I<(outs), (ins vt:$src), (outs), (ins), [],
228 "drop\t$src", "drop", 0x1a>;
Dan Gohmanb89f2d32017-02-02 19:29:44 +0000229
230 let mayLoad = 1 in
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000231 defm GET_GLOBAL_#vt : I<(outs vt:$res), (ins global_op:$local),
232 (outs), (ins global_op:$local), [],
233 "get_global\t$res, $local", "get_global\t$local",
234 0x23>;
Dan Gohmanb89f2d32017-02-02 19:29:44 +0000235
236 let mayStore = 1 in
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000237 defm SET_GLOBAL_#vt : I<(outs), (ins global_op:$local, vt:$src),
238 (outs), (ins global_op:$local), [],
239 "set_global\t$local, $src", "set_global\t$local",
240 0x24>;
Dan Gohmanb89f2d32017-02-02 19:29:44 +0000241
Dan Gohman4817a752016-05-16 19:16:32 +0000242} // hasSideEffects = 0
Dan Gohman4ba48162015-11-18 16:12:01 +0000243}
Sam Clegg537afe62018-06-04 16:59:26 +0000244defm "" : LOCAL<I32>;
245defm "" : LOCAL<I64>;
246defm "" : LOCAL<F32>;
247defm "" : LOCAL<F64>;
248defm "" : LOCAL<V128>, Requires<[HasSIMD128]>;
249defm "" : LOCAL<EXCEPT_REF>, Requires<[HasExceptionHandling]>;
JF Bastien4a642252015-08-10 22:36:48 +0000250
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000251let isMoveImm = 1, isAsCheapAsAMove = 1, isReMaterializable = 1 in {
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000252defm CONST_I32 : I<(outs I32:$res), (ins i32imm_op:$imm),
253 (outs), (ins i32imm_op:$imm),
254 [(set I32:$res, imm:$imm)],
255 "i32.const\t$res, $imm", "i32.const\t$imm", 0x41>;
256defm CONST_I64 : I<(outs I64:$res), (ins i64imm_op:$imm),
257 (outs), (ins i64imm_op:$imm),
258 [(set I64:$res, imm:$imm)],
259 "i64.const\t$res, $imm", "i64.const\t$imm", 0x42>;
260defm CONST_F32 : I<(outs F32:$res), (ins f32imm_op:$imm),
261 (outs), (ins f32imm_op:$imm),
262 [(set F32:$res, fpimm:$imm)],
263 "f32.const\t$res, $imm", "f32.const\t$imm", 0x43>;
264defm CONST_F64 : I<(outs F64:$res), (ins f64imm_op:$imm),
265 (outs), (ins f64imm_op:$imm),
266 [(set F64:$res, fpimm:$imm)],
267 "f64.const\t$res, $imm", "f64.const\t$imm", 0x44>;
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000268} // isMoveImm = 1, isAsCheapAsAMove = 1, isReMaterializable = 1
JF Bastien4a642252015-08-10 22:36:48 +0000269
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000270} // Defs = [ARGUMENTS]
271
Dan Gohman8633eed2016-01-08 00:50:33 +0000272def : Pat<(i32 (WebAssemblywrapper tglobaladdr:$addr)),
273 (CONST_I32 tglobaladdr:$addr)>;
274def : Pat<(i32 (WebAssemblywrapper texternalsym:$addr)),
275 (CONST_I32 texternalsym:$addr)>;
Derek Schuff71e81692015-11-17 00:20:44 +0000276
Dan Gohman10e730a2015-06-29 23:51:55 +0000277//===----------------------------------------------------------------------===//
278// Additional sets of instructions.
279//===----------------------------------------------------------------------===//
280
JF Bastien5ca0bac2015-07-10 18:23:10 +0000281include "WebAssemblyInstrMemory.td"
282include "WebAssemblyInstrCall.td"
JF Bastien600aee92015-07-31 17:53:38 +0000283include "WebAssemblyInstrControl.td"
JF Bastien5ca0bac2015-07-10 18:23:10 +0000284include "WebAssemblyInstrInteger.td"
JF Bastien5ca0bac2015-07-10 18:23:10 +0000285include "WebAssemblyInstrConv.td"
Dan Gohmanf170ba02015-12-10 04:55:31 +0000286include "WebAssemblyInstrFloat.td"
Dan Gohman10e730a2015-06-29 23:51:55 +0000287include "WebAssemblyInstrAtomics.td"
288include "WebAssemblyInstrSIMD.td"
Heejin Ahn0de58722018-03-08 04:05:37 +0000289include "WebAssemblyInstrExceptRef.td"