blob: 245d5abbf26351831fa9b1fa47ccdaa9773f211b [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
11/// \brief WebAssembly Instruction definitions.
12///
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
Dan Gohman10e730a2015-06-29 23:51:55 +000042//===----------------------------------------------------------------------===//
43// WebAssembly-specific DAG Node Types.
44//===----------------------------------------------------------------------===//
45
Serge Pavlovd526b132017-05-09 13:35:13 +000046def SDT_WebAssemblyCallSeqStart : SDCallSeqStart<[SDTCisVT<0, iPTR>,
47 SDTCisVT<1, iPTR>]>;
JF Bastienaf111db2015-08-24 22:16:48 +000048def SDT_WebAssemblyCallSeqEnd :
49 SDCallSeqEnd<[SDTCisVT<0, iPTR>, SDTCisVT<1, iPTR>]>;
Dan Gohmanf71abef2015-09-09 16:13:47 +000050def SDT_WebAssemblyCall0 : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>;
51def SDT_WebAssemblyCall1 : SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>;
Dan Gohman14026062016-03-08 03:18:12 +000052def SDT_WebAssemblyBrTable : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>;
JF Bastien600aee92015-07-31 17:53:38 +000053def SDT_WebAssemblyArgument : SDTypeProfile<1, 1, [SDTCisVT<1, i32>]>;
JF Bastien4a2d5602015-07-31 21:04:18 +000054def SDT_WebAssemblyReturn : SDTypeProfile<0, -1, []>;
JF Bastienaf111db2015-08-24 22:16:48 +000055def SDT_WebAssemblyWrapper : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>,
56 SDTCisPtrTy<0>]>;
JF Bastien600aee92015-07-31 17:53:38 +000057
Dan Gohman10e730a2015-06-29 23:51:55 +000058//===----------------------------------------------------------------------===//
59// WebAssembly-specific DAG Nodes.
60//===----------------------------------------------------------------------===//
61
JF Bastienaf111db2015-08-24 22:16:48 +000062def WebAssemblycallseq_start :
63 SDNode<"ISD::CALLSEQ_START", SDT_WebAssemblyCallSeqStart,
64 [SDNPHasChain, SDNPOutGlue]>;
65def WebAssemblycallseq_end :
66 SDNode<"ISD::CALLSEQ_END", SDT_WebAssemblyCallSeqEnd,
67 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
Dan Gohmanf71abef2015-09-09 16:13:47 +000068def WebAssemblycall0 : SDNode<"WebAssemblyISD::CALL0",
69 SDT_WebAssemblyCall0,
70 [SDNPHasChain, SDNPVariadic]>;
71def WebAssemblycall1 : SDNode<"WebAssemblyISD::CALL1",
72 SDT_WebAssemblyCall1,
73 [SDNPHasChain, SDNPVariadic]>;
Dan Gohman14026062016-03-08 03:18:12 +000074def WebAssemblybr_table : SDNode<"WebAssemblyISD::BR_TABLE",
75 SDT_WebAssemblyBrTable,
76 [SDNPHasChain, SDNPVariadic]>;
JF Bastien600aee92015-07-31 17:53:38 +000077def WebAssemblyargument : SDNode<"WebAssemblyISD::ARGUMENT",
78 SDT_WebAssemblyArgument>;
79def WebAssemblyreturn : SDNode<"WebAssemblyISD::RETURN",
JF Bastienaf111db2015-08-24 22:16:48 +000080 SDT_WebAssemblyReturn, [SDNPHasChain]>;
81def WebAssemblywrapper : SDNode<"WebAssemblyISD::Wrapper",
82 SDT_WebAssemblyWrapper>;
JF Bastien600aee92015-07-31 17:53:38 +000083
Dan Gohman10e730a2015-06-29 23:51:55 +000084//===----------------------------------------------------------------------===//
85// WebAssembly-specific Operands.
86//===----------------------------------------------------------------------===//
87
Dan Gohmana11fb232016-01-12 03:09:16 +000088let OperandNamespace = "WebAssembly" in {
89
90let OperandType = "OPERAND_BASIC_BLOCK" in
Dan Gohman950a13c2015-09-16 16:51:30 +000091def bb_op : Operand<OtherVT>;
JF Bastienaf111db2015-08-24 22:16:48 +000092
Dan Gohman4fc4e422016-10-24 19:49:43 +000093let OperandType = "OPERAND_LOCAL" in
94def local_op : Operand<i32>;
95
Dan Gohmanb89f2d32017-02-02 19:29:44 +000096let OperandType = "OPERAND_GLOBAL" in
97def global_op : Operand<i32>;
98
Dan Gohman5a68ec72016-10-05 21:24:08 +000099let OperandType = "OPERAND_I32IMM" in
100def i32imm_op : Operand<i32>;
101
102let OperandType = "OPERAND_I64IMM" in
103def i64imm_op : Operand<i64>;
104
Dan Gohman4b8e8be2016-10-03 21:31:31 +0000105let OperandType = "OPERAND_F32IMM" in
Dan Gohmana11fb232016-01-12 03:09:16 +0000106def f32imm_op : Operand<f32>;
Dan Gohmanaa742912016-02-16 15:14:23 +0000107
Dan Gohman4b8e8be2016-10-03 21:31:31 +0000108let OperandType = "OPERAND_F64IMM" in
Dan Gohmana11fb232016-01-12 03:09:16 +0000109def f64imm_op : Operand<f64>;
Dan Gohmana11fb232016-01-12 03:09:16 +0000110
Dan Gohman00d734d2016-12-23 03:23:52 +0000111let OperandType = "OPERAND_FUNCTION32" in
112def function32_op : Operand<i32>;
113
114let OperandType = "OPERAND_OFFSET32" in
115def offset32_op : Operand<i32>;
116
Dan Gohmanbb372242016-01-26 03:39:31 +0000117let OperandType = "OPERAND_P2ALIGN" in {
118def P2Align : Operand<i32> {
119 let PrintMethod = "printWebAssemblyP2AlignOperand";
120}
121} // OperandType = "OPERAND_P2ALIGN"
122
Dan Gohman2726b882016-10-06 22:29:32 +0000123let OperandType = "OPERAND_SIGNATURE" in {
124def Signature : Operand<i32> {
125 let PrintMethod = "printWebAssemblySignatureOperand";
126}
127} // OperandType = "OPERAND_SIGNATURE"
128
Dan Gohmand934cb82017-02-24 23:18:00 +0000129let OperandType = "OPERAND_TYPEINDEX" in
130def TypeIndex : Operand<i32>;
131
Dan Gohmana11fb232016-01-12 03:09:16 +0000132} // OperandNamespace = "WebAssembly"
133
Dan Gohman10e730a2015-06-29 23:51:55 +0000134//===----------------------------------------------------------------------===//
135// WebAssembly Instruction Format Definitions.
136//===----------------------------------------------------------------------===//
137
138include "WebAssemblyInstrFormats.td"
139
Dan Gohman4ba48162015-11-18 16:12:01 +0000140//===----------------------------------------------------------------------===//
141// Additional instructions.
142//===----------------------------------------------------------------------===//
143
JF Bastien8f9aea02015-08-01 04:48:44 +0000144multiclass ARGUMENT<WebAssemblyRegClass vt> {
Dan Gohmana783f102015-12-21 16:53:29 +0000145 let hasSideEffects = 1, Uses = [ARGUMENTS], isCodeGenOnly = 1 in
JF Bastien8f9aea02015-08-01 04:48:44 +0000146 def ARGUMENT_#vt : I<(outs vt:$res), (ins i32imm:$argno),
147 [(set vt:$res, (WebAssemblyargument timm:$argno))]>;
148}
Derek Schuff39bf39f2016-08-02 23:16:09 +0000149multiclass SIMD_ARGUMENT<ValueType vt> {
150 let hasSideEffects = 1, Uses = [ARGUMENTS], isCodeGenOnly = 1 in
151 def ARGUMENT_#vt : SIMD_I<(outs V128:$res), (ins i32imm:$argno),
152 [(set (vt V128:$res),
153 (WebAssemblyargument timm:$argno))]>;
154}
Dan Gohmand0bf9812015-09-26 01:09:44 +0000155defm : ARGUMENT<I32>;
156defm : ARGUMENT<I64>;
157defm : ARGUMENT<F32>;
158defm : ARGUMENT<F64>;
Derek Schuff39bf39f2016-08-02 23:16:09 +0000159defm : SIMD_ARGUMENT<v16i8>;
160defm : SIMD_ARGUMENT<v8i16>;
161defm : SIMD_ARGUMENT<v4i32>;
162defm : SIMD_ARGUMENT<v4f32>;
JF Bastien600aee92015-07-31 17:53:38 +0000163
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000164let Defs = [ARGUMENTS] in {
165
Dan Gohman4ba48162015-11-18 16:12:01 +0000166// get_local and set_local are not generated by instruction selection; they
Dan Gohmanadf28172016-01-28 01:22:44 +0000167// are implied by virtual register uses and defs.
Dan Gohman4ba48162015-11-18 16:12:01 +0000168multiclass LOCAL<WebAssemblyRegClass vt> {
Dan Gohman4817a752016-05-16 19:16:32 +0000169let hasSideEffects = 0 in {
Dan Gohman4fc4e422016-10-24 19:49:43 +0000170 // COPY is not an actual instruction in wasm, but since we allow get_local and
171 // set_local to be implicit during most of codegen, we can have a COPY which
172 // is actually a no-op because all the work is done in the implied get_local
173 // and set_local. COPYs are eliminated (and replaced with
174 // get_local/set_local) in the ExplicitLocals pass.
175 let isAsCheapAsAMove = 1, isCodeGenOnly = 1 in
176 def COPY_#vt : I<(outs vt:$res), (ins vt:$src), [], "copy_local\t$res, $src">;
Dan Gohmanadf28172016-01-28 01:22:44 +0000177
Dan Gohman4fc4e422016-10-24 19:49:43 +0000178 // TEE is similar to COPY, but writes two copies of its result. Typically
179 // this would be used to stackify one result and write the other result to a
180 // local.
181 let isAsCheapAsAMove = 1, isCodeGenOnly = 1 in
182 def TEE_#vt : I<(outs vt:$res, vt:$also), (ins vt:$src), [],
183 "tee_local\t$res, $also, $src">;
184
185 // This is the actual get_local instruction in wasm. These are made explicit
186 // by the ExplicitLocals pass. It has mayLoad because it reads from a wasm
187 // local, which is a side effect not otherwise modeled in LLVM.
188 let mayLoad = 1, isAsCheapAsAMove = 1 in
189 def GET_LOCAL_#vt : I<(outs vt:$res), (ins local_op:$local), [],
Dan Gohmanc9682972016-10-24 20:21:49 +0000190 "get_local\t$res, $local", 0x20>;
Dan Gohman4fc4e422016-10-24 19:49:43 +0000191
192 // This is the actual set_local instruction in wasm. These are made explicit
193 // by the ExplicitLocals pass. It has mayStore because it writes to a wasm
194 // local, which is a side effect not otherwise modeled in LLVM.
195 let mayStore = 1, isAsCheapAsAMove = 1 in
196 def SET_LOCAL_#vt : I<(outs), (ins local_op:$local, vt:$src), [],
Dan Gohmanc9682972016-10-24 20:21:49 +0000197 "set_local\t$local, $src", 0x21>;
Dan Gohman4fc4e422016-10-24 19:49:43 +0000198
199 // This is the actual tee_local instruction in wasm. TEEs are turned into
200 // TEE_LOCALs by the ExplicitLocals pass. It has mayStore for the same reason
201 // as SET_LOCAL.
202 let mayStore = 1, isAsCheapAsAMove = 1 in
203 def TEE_LOCAL_#vt : I<(outs vt:$res), (ins local_op:$local, vt:$src), [],
Dan Gohmanc9682972016-10-24 20:21:49 +0000204 "tee_local\t$res, $local, $src", 0x22>;
Dan Gohman4fc4e422016-10-24 19:49:43 +0000205
Dan Gohmanb89f2d32017-02-02 19:29:44 +0000206 // Unused values must be dropped in some contexts.
207 def DROP_#vt : I<(outs), (ins vt:$src), [],
208 "drop\t$src", 0x1a>;
209
210 let mayLoad = 1 in
211 def GET_GLOBAL_#vt : I<(outs vt:$res), (ins global_op:$local), [],
212 "get_global\t$res, $local", 0x23>;
213
214 let mayStore = 1 in
215 def SET_GLOBAL_#vt : I<(outs), (ins global_op:$local, vt:$src), [],
216 "set_global\t$local, $src", 0x24>;
217
Dan Gohman4817a752016-05-16 19:16:32 +0000218} // hasSideEffects = 0
Dan Gohman4ba48162015-11-18 16:12:01 +0000219}
220defm : LOCAL<I32>;
221defm : LOCAL<I64>;
222defm : LOCAL<F32>;
223defm : LOCAL<F64>;
Derek Schuff39bf39f2016-08-02 23:16:09 +0000224defm : LOCAL<V128>, Requires<[HasSIMD128]>;
JF Bastien4a642252015-08-10 22:36:48 +0000225
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000226let isMoveImm = 1, isAsCheapAsAMove = 1, isReMaterializable = 1 in {
Dan Gohman5a68ec72016-10-05 21:24:08 +0000227def CONST_I32 : I<(outs I32:$res), (ins i32imm_op:$imm),
Dan Gohmanda7f4282015-11-05 20:44:29 +0000228 [(set I32:$res, imm:$imm)],
Dan Gohmanc9682972016-10-24 20:21:49 +0000229 "i32.const\t$res, $imm", 0x41>;
Dan Gohman5a68ec72016-10-05 21:24:08 +0000230def CONST_I64 : I<(outs I64:$res), (ins i64imm_op:$imm),
Dan Gohmanda7f4282015-11-05 20:44:29 +0000231 [(set I64:$res, imm:$imm)],
Dan Gohmanc9682972016-10-24 20:21:49 +0000232 "i64.const\t$res, $imm", 0x42>;
Dan Gohmana11fb232016-01-12 03:09:16 +0000233def CONST_F32 : I<(outs F32:$res), (ins f32imm_op:$imm),
Dan Gohmanda7f4282015-11-05 20:44:29 +0000234 [(set F32:$res, fpimm:$imm)],
Dan Gohmanc9682972016-10-24 20:21:49 +0000235 "f32.const\t$res, $imm", 0x43>;
Dan Gohmana11fb232016-01-12 03:09:16 +0000236def CONST_F64 : I<(outs F64:$res), (ins f64imm_op:$imm),
Dan Gohmanda7f4282015-11-05 20:44:29 +0000237 [(set F64:$res, fpimm:$imm)],
Dan Gohmanc9682972016-10-24 20:21:49 +0000238 "f64.const\t$res, $imm", 0x44>;
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000239} // isMoveImm = 1, isAsCheapAsAMove = 1, isReMaterializable = 1
JF Bastien4a642252015-08-10 22:36:48 +0000240
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000241} // Defs = [ARGUMENTS]
242
Dan Gohman8633eed2016-01-08 00:50:33 +0000243def : Pat<(i32 (WebAssemblywrapper tglobaladdr:$addr)),
244 (CONST_I32 tglobaladdr:$addr)>;
245def : Pat<(i32 (WebAssemblywrapper texternalsym:$addr)),
246 (CONST_I32 texternalsym:$addr)>;
Derek Schuff71e81692015-11-17 00:20:44 +0000247
Dan Gohman10e730a2015-06-29 23:51:55 +0000248//===----------------------------------------------------------------------===//
249// Additional sets of instructions.
250//===----------------------------------------------------------------------===//
251
JF Bastien5ca0bac2015-07-10 18:23:10 +0000252include "WebAssemblyInstrMemory.td"
253include "WebAssemblyInstrCall.td"
JF Bastien600aee92015-07-31 17:53:38 +0000254include "WebAssemblyInstrControl.td"
JF Bastien5ca0bac2015-07-10 18:23:10 +0000255include "WebAssemblyInstrInteger.td"
JF Bastien5ca0bac2015-07-10 18:23:10 +0000256include "WebAssemblyInstrConv.td"
Dan Gohmanf170ba02015-12-10 04:55:31 +0000257include "WebAssemblyInstrFloat.td"
Dan Gohman10e730a2015-06-29 23:51:55 +0000258include "WebAssemblyInstrAtomics.td"
259include "WebAssemblyInstrSIMD.td"