blob: bc4e542c4fbb25173ded254506079afb5ca1b1fb [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">;
JF Bastien03855df2015-07-01 23:41:25 +000025
Dan Gohman10e730a2015-06-29 23:51:55 +000026//===----------------------------------------------------------------------===//
27// WebAssembly-specific DAG Node Types.
28//===----------------------------------------------------------------------===//
29
Serge Pavlovd526b132017-05-09 13:35:13 +000030def SDT_WebAssemblyCallSeqStart : SDCallSeqStart<[SDTCisVT<0, iPTR>,
31 SDTCisVT<1, iPTR>]>;
JF Bastienaf111db2015-08-24 22:16:48 +000032def SDT_WebAssemblyCallSeqEnd :
33 SDCallSeqEnd<[SDTCisVT<0, iPTR>, SDTCisVT<1, iPTR>]>;
Dan Gohmanf71abef2015-09-09 16:13:47 +000034def SDT_WebAssemblyCall0 : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>;
35def SDT_WebAssemblyCall1 : SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>;
Dan Gohman14026062016-03-08 03:18:12 +000036def SDT_WebAssemblyBrTable : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>;
JF Bastien600aee92015-07-31 17:53:38 +000037def SDT_WebAssemblyArgument : SDTypeProfile<1, 1, [SDTCisVT<1, i32>]>;
JF Bastien4a2d5602015-07-31 21:04:18 +000038def SDT_WebAssemblyReturn : SDTypeProfile<0, -1, []>;
JF Bastienaf111db2015-08-24 22:16:48 +000039def SDT_WebAssemblyWrapper : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>,
40 SDTCisPtrTy<0>]>;
JF Bastien600aee92015-07-31 17:53:38 +000041
Dan Gohman10e730a2015-06-29 23:51:55 +000042//===----------------------------------------------------------------------===//
43// WebAssembly-specific DAG Nodes.
44//===----------------------------------------------------------------------===//
45
JF Bastienaf111db2015-08-24 22:16:48 +000046def WebAssemblycallseq_start :
47 SDNode<"ISD::CALLSEQ_START", SDT_WebAssemblyCallSeqStart,
48 [SDNPHasChain, SDNPOutGlue]>;
49def WebAssemblycallseq_end :
50 SDNode<"ISD::CALLSEQ_END", SDT_WebAssemblyCallSeqEnd,
51 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
Dan Gohmanf71abef2015-09-09 16:13:47 +000052def WebAssemblycall0 : SDNode<"WebAssemblyISD::CALL0",
53 SDT_WebAssemblyCall0,
54 [SDNPHasChain, SDNPVariadic]>;
55def WebAssemblycall1 : SDNode<"WebAssemblyISD::CALL1",
56 SDT_WebAssemblyCall1,
57 [SDNPHasChain, SDNPVariadic]>;
Dan Gohman14026062016-03-08 03:18:12 +000058def WebAssemblybr_table : SDNode<"WebAssemblyISD::BR_TABLE",
59 SDT_WebAssemblyBrTable,
60 [SDNPHasChain, SDNPVariadic]>;
JF Bastien600aee92015-07-31 17:53:38 +000061def WebAssemblyargument : SDNode<"WebAssemblyISD::ARGUMENT",
62 SDT_WebAssemblyArgument>;
63def WebAssemblyreturn : SDNode<"WebAssemblyISD::RETURN",
JF Bastienaf111db2015-08-24 22:16:48 +000064 SDT_WebAssemblyReturn, [SDNPHasChain]>;
65def WebAssemblywrapper : SDNode<"WebAssemblyISD::Wrapper",
66 SDT_WebAssemblyWrapper>;
JF Bastien600aee92015-07-31 17:53:38 +000067
Dan Gohman10e730a2015-06-29 23:51:55 +000068//===----------------------------------------------------------------------===//
69// WebAssembly-specific Operands.
70//===----------------------------------------------------------------------===//
71
Dan Gohmana11fb232016-01-12 03:09:16 +000072let OperandNamespace = "WebAssembly" in {
73
74let OperandType = "OPERAND_BASIC_BLOCK" in
Dan Gohman950a13c2015-09-16 16:51:30 +000075def bb_op : Operand<OtherVT>;
JF Bastienaf111db2015-08-24 22:16:48 +000076
Dan Gohman4fc4e422016-10-24 19:49:43 +000077let OperandType = "OPERAND_LOCAL" in
78def local_op : Operand<i32>;
79
Dan Gohmanb89f2d32017-02-02 19:29:44 +000080let OperandType = "OPERAND_GLOBAL" in
81def global_op : Operand<i32>;
82
Dan Gohman5a68ec72016-10-05 21:24:08 +000083let OperandType = "OPERAND_I32IMM" in
84def i32imm_op : Operand<i32>;
85
86let OperandType = "OPERAND_I64IMM" in
87def i64imm_op : Operand<i64>;
88
Dan Gohman4b8e8be2016-10-03 21:31:31 +000089let OperandType = "OPERAND_F32IMM" in
Dan Gohmana11fb232016-01-12 03:09:16 +000090def f32imm_op : Operand<f32>;
Dan Gohmanaa742912016-02-16 15:14:23 +000091
Dan Gohman4b8e8be2016-10-03 21:31:31 +000092let OperandType = "OPERAND_F64IMM" in
Dan Gohmana11fb232016-01-12 03:09:16 +000093def f64imm_op : Operand<f64>;
Dan Gohmana11fb232016-01-12 03:09:16 +000094
Dan Gohman00d734d2016-12-23 03:23:52 +000095let OperandType = "OPERAND_FUNCTION32" in
96def function32_op : Operand<i32>;
97
98let OperandType = "OPERAND_OFFSET32" in
99def offset32_op : Operand<i32>;
100
Dan Gohmanbb372242016-01-26 03:39:31 +0000101let OperandType = "OPERAND_P2ALIGN" in {
102def P2Align : Operand<i32> {
103 let PrintMethod = "printWebAssemblyP2AlignOperand";
104}
105} // OperandType = "OPERAND_P2ALIGN"
106
Dan Gohman2726b882016-10-06 22:29:32 +0000107let OperandType = "OPERAND_SIGNATURE" in {
108def Signature : Operand<i32> {
109 let PrintMethod = "printWebAssemblySignatureOperand";
110}
111} // OperandType = "OPERAND_SIGNATURE"
112
Dan Gohmand934cb82017-02-24 23:18:00 +0000113let OperandType = "OPERAND_TYPEINDEX" in
114def TypeIndex : Operand<i32>;
115
Dan Gohmana11fb232016-01-12 03:09:16 +0000116} // OperandNamespace = "WebAssembly"
117
Dan Gohman10e730a2015-06-29 23:51:55 +0000118//===----------------------------------------------------------------------===//
119// WebAssembly Instruction Format Definitions.
120//===----------------------------------------------------------------------===//
121
122include "WebAssemblyInstrFormats.td"
123
Dan Gohman4ba48162015-11-18 16:12:01 +0000124//===----------------------------------------------------------------------===//
125// Additional instructions.
126//===----------------------------------------------------------------------===//
127
JF Bastien8f9aea02015-08-01 04:48:44 +0000128multiclass ARGUMENT<WebAssemblyRegClass vt> {
Dan Gohmana783f102015-12-21 16:53:29 +0000129 let hasSideEffects = 1, Uses = [ARGUMENTS], isCodeGenOnly = 1 in
JF Bastien8f9aea02015-08-01 04:48:44 +0000130 def ARGUMENT_#vt : I<(outs vt:$res), (ins i32imm:$argno),
131 [(set vt:$res, (WebAssemblyargument timm:$argno))]>;
132}
Derek Schuff39bf39f2016-08-02 23:16:09 +0000133multiclass SIMD_ARGUMENT<ValueType vt> {
134 let hasSideEffects = 1, Uses = [ARGUMENTS], isCodeGenOnly = 1 in
135 def ARGUMENT_#vt : SIMD_I<(outs V128:$res), (ins i32imm:$argno),
136 [(set (vt V128:$res),
137 (WebAssemblyargument timm:$argno))]>;
138}
Dan Gohmand0bf9812015-09-26 01:09:44 +0000139defm : ARGUMENT<I32>;
140defm : ARGUMENT<I64>;
141defm : ARGUMENT<F32>;
142defm : ARGUMENT<F64>;
Derek Schuff39bf39f2016-08-02 23:16:09 +0000143defm : SIMD_ARGUMENT<v16i8>;
144defm : SIMD_ARGUMENT<v8i16>;
145defm : SIMD_ARGUMENT<v4i32>;
146defm : SIMD_ARGUMENT<v4f32>;
JF Bastien600aee92015-07-31 17:53:38 +0000147
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000148let Defs = [ARGUMENTS] in {
149
Dan Gohman4ba48162015-11-18 16:12:01 +0000150// get_local and set_local are not generated by instruction selection; they
Dan Gohmanadf28172016-01-28 01:22:44 +0000151// are implied by virtual register uses and defs.
Dan Gohman4ba48162015-11-18 16:12:01 +0000152multiclass LOCAL<WebAssemblyRegClass vt> {
Dan Gohman4817a752016-05-16 19:16:32 +0000153let hasSideEffects = 0 in {
Dan Gohman4fc4e422016-10-24 19:49:43 +0000154 // COPY is not an actual instruction in wasm, but since we allow get_local and
155 // set_local to be implicit during most of codegen, we can have a COPY which
156 // is actually a no-op because all the work is done in the implied get_local
157 // and set_local. COPYs are eliminated (and replaced with
158 // get_local/set_local) in the ExplicitLocals pass.
159 let isAsCheapAsAMove = 1, isCodeGenOnly = 1 in
160 def COPY_#vt : I<(outs vt:$res), (ins vt:$src), [], "copy_local\t$res, $src">;
Dan Gohmanadf28172016-01-28 01:22:44 +0000161
Dan Gohman4fc4e422016-10-24 19:49:43 +0000162 // TEE is similar to COPY, but writes two copies of its result. Typically
163 // this would be used to stackify one result and write the other result to a
164 // local.
165 let isAsCheapAsAMove = 1, isCodeGenOnly = 1 in
166 def TEE_#vt : I<(outs vt:$res, vt:$also), (ins vt:$src), [],
167 "tee_local\t$res, $also, $src">;
168
169 // This is the actual get_local instruction in wasm. These are made explicit
170 // by the ExplicitLocals pass. It has mayLoad because it reads from a wasm
171 // local, which is a side effect not otherwise modeled in LLVM.
172 let mayLoad = 1, isAsCheapAsAMove = 1 in
173 def GET_LOCAL_#vt : I<(outs vt:$res), (ins local_op:$local), [],
Dan Gohmanc9682972016-10-24 20:21:49 +0000174 "get_local\t$res, $local", 0x20>;
Dan Gohman4fc4e422016-10-24 19:49:43 +0000175
176 // This is the actual set_local instruction in wasm. These are made explicit
177 // by the ExplicitLocals pass. It has mayStore because it writes to a wasm
178 // local, which is a side effect not otherwise modeled in LLVM.
179 let mayStore = 1, isAsCheapAsAMove = 1 in
180 def SET_LOCAL_#vt : I<(outs), (ins local_op:$local, vt:$src), [],
Dan Gohmanc9682972016-10-24 20:21:49 +0000181 "set_local\t$local, $src", 0x21>;
Dan Gohman4fc4e422016-10-24 19:49:43 +0000182
183 // This is the actual tee_local instruction in wasm. TEEs are turned into
184 // TEE_LOCALs by the ExplicitLocals pass. It has mayStore for the same reason
185 // as SET_LOCAL.
186 let mayStore = 1, isAsCheapAsAMove = 1 in
187 def TEE_LOCAL_#vt : I<(outs vt:$res), (ins local_op:$local, vt:$src), [],
Dan Gohmanc9682972016-10-24 20:21:49 +0000188 "tee_local\t$res, $local, $src", 0x22>;
Dan Gohman4fc4e422016-10-24 19:49:43 +0000189
Dan Gohmanb89f2d32017-02-02 19:29:44 +0000190 // Unused values must be dropped in some contexts.
191 def DROP_#vt : I<(outs), (ins vt:$src), [],
192 "drop\t$src", 0x1a>;
193
194 let mayLoad = 1 in
195 def GET_GLOBAL_#vt : I<(outs vt:$res), (ins global_op:$local), [],
196 "get_global\t$res, $local", 0x23>;
197
198 let mayStore = 1 in
199 def SET_GLOBAL_#vt : I<(outs), (ins global_op:$local, vt:$src), [],
200 "set_global\t$local, $src", 0x24>;
201
Dan Gohman4817a752016-05-16 19:16:32 +0000202} // hasSideEffects = 0
Dan Gohman4ba48162015-11-18 16:12:01 +0000203}
204defm : LOCAL<I32>;
205defm : LOCAL<I64>;
206defm : LOCAL<F32>;
207defm : LOCAL<F64>;
Derek Schuff39bf39f2016-08-02 23:16:09 +0000208defm : LOCAL<V128>, Requires<[HasSIMD128]>;
JF Bastien4a642252015-08-10 22:36:48 +0000209
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000210let isMoveImm = 1, isAsCheapAsAMove = 1, isReMaterializable = 1 in {
Dan Gohman5a68ec72016-10-05 21:24:08 +0000211def CONST_I32 : I<(outs I32:$res), (ins i32imm_op:$imm),
Dan Gohmanda7f4282015-11-05 20:44:29 +0000212 [(set I32:$res, imm:$imm)],
Dan Gohmanc9682972016-10-24 20:21:49 +0000213 "i32.const\t$res, $imm", 0x41>;
Dan Gohman5a68ec72016-10-05 21:24:08 +0000214def CONST_I64 : I<(outs I64:$res), (ins i64imm_op:$imm),
Dan Gohmanda7f4282015-11-05 20:44:29 +0000215 [(set I64:$res, imm:$imm)],
Dan Gohmanc9682972016-10-24 20:21:49 +0000216 "i64.const\t$res, $imm", 0x42>;
Dan Gohmana11fb232016-01-12 03:09:16 +0000217def CONST_F32 : I<(outs F32:$res), (ins f32imm_op:$imm),
Dan Gohmanda7f4282015-11-05 20:44:29 +0000218 [(set F32:$res, fpimm:$imm)],
Dan Gohmanc9682972016-10-24 20:21:49 +0000219 "f32.const\t$res, $imm", 0x43>;
Dan Gohmana11fb232016-01-12 03:09:16 +0000220def CONST_F64 : I<(outs F64:$res), (ins f64imm_op:$imm),
Dan Gohmanda7f4282015-11-05 20:44:29 +0000221 [(set F64:$res, fpimm:$imm)],
Dan Gohmanc9682972016-10-24 20:21:49 +0000222 "f64.const\t$res, $imm", 0x44>;
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000223} // isMoveImm = 1, isAsCheapAsAMove = 1, isReMaterializable = 1
JF Bastien4a642252015-08-10 22:36:48 +0000224
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000225} // Defs = [ARGUMENTS]
226
Dan Gohman8633eed2016-01-08 00:50:33 +0000227def : Pat<(i32 (WebAssemblywrapper tglobaladdr:$addr)),
228 (CONST_I32 tglobaladdr:$addr)>;
229def : Pat<(i32 (WebAssemblywrapper texternalsym:$addr)),
230 (CONST_I32 texternalsym:$addr)>;
Derek Schuff71e81692015-11-17 00:20:44 +0000231
Dan Gohman10e730a2015-06-29 23:51:55 +0000232//===----------------------------------------------------------------------===//
233// Additional sets of instructions.
234//===----------------------------------------------------------------------===//
235
JF Bastien5ca0bac2015-07-10 18:23:10 +0000236include "WebAssemblyInstrMemory.td"
237include "WebAssemblyInstrCall.td"
JF Bastien600aee92015-07-31 17:53:38 +0000238include "WebAssemblyInstrControl.td"
JF Bastien5ca0bac2015-07-10 18:23:10 +0000239include "WebAssemblyInstrInteger.td"
JF Bastien5ca0bac2015-07-10 18:23:10 +0000240include "WebAssemblyInstrConv.td"
Dan Gohmanf170ba02015-12-10 04:55:31 +0000241include "WebAssemblyInstrFloat.td"
Dan Gohman10e730a2015-06-29 23:51:55 +0000242include "WebAssemblyInstrAtomics.td"
243include "WebAssemblyInstrSIMD.td"