blob: a601b575f5791474927c6fecdcf45c25b506448c [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">;
23
Dan Gohman10e730a2015-06-29 23:51:55 +000024//===----------------------------------------------------------------------===//
25// WebAssembly-specific DAG Node Types.
26//===----------------------------------------------------------------------===//
27
JF Bastienaf111db2015-08-24 22:16:48 +000028def SDT_WebAssemblyCallSeqStart : SDCallSeqStart<[SDTCisVT<0, iPTR>]>;
29def SDT_WebAssemblyCallSeqEnd :
30 SDCallSeqEnd<[SDTCisVT<0, iPTR>, SDTCisVT<1, iPTR>]>;
Dan Gohmanf71abef2015-09-09 16:13:47 +000031def SDT_WebAssemblyCall0 : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>;
32def SDT_WebAssemblyCall1 : SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>;
Dan Gohman14026062016-03-08 03:18:12 +000033def SDT_WebAssemblyBrTable : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>;
JF Bastien600aee92015-07-31 17:53:38 +000034def SDT_WebAssemblyArgument : SDTypeProfile<1, 1, [SDTCisVT<1, i32>]>;
JF Bastien4a2d5602015-07-31 21:04:18 +000035def SDT_WebAssemblyReturn : SDTypeProfile<0, -1, []>;
JF Bastienaf111db2015-08-24 22:16:48 +000036def SDT_WebAssemblyWrapper : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>,
37 SDTCisPtrTy<0>]>;
JF Bastien600aee92015-07-31 17:53:38 +000038
Dan Gohman10e730a2015-06-29 23:51:55 +000039//===----------------------------------------------------------------------===//
40// WebAssembly-specific DAG Nodes.
41//===----------------------------------------------------------------------===//
42
JF Bastienaf111db2015-08-24 22:16:48 +000043def WebAssemblycallseq_start :
44 SDNode<"ISD::CALLSEQ_START", SDT_WebAssemblyCallSeqStart,
45 [SDNPHasChain, SDNPOutGlue]>;
46def WebAssemblycallseq_end :
47 SDNode<"ISD::CALLSEQ_END", SDT_WebAssemblyCallSeqEnd,
48 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
Dan Gohmanf71abef2015-09-09 16:13:47 +000049def WebAssemblycall0 : SDNode<"WebAssemblyISD::CALL0",
50 SDT_WebAssemblyCall0,
51 [SDNPHasChain, SDNPVariadic]>;
52def WebAssemblycall1 : SDNode<"WebAssemblyISD::CALL1",
53 SDT_WebAssemblyCall1,
54 [SDNPHasChain, SDNPVariadic]>;
Dan Gohman14026062016-03-08 03:18:12 +000055def WebAssemblybr_table : SDNode<"WebAssemblyISD::BR_TABLE",
56 SDT_WebAssemblyBrTable,
57 [SDNPHasChain, SDNPVariadic]>;
JF Bastien600aee92015-07-31 17:53:38 +000058def WebAssemblyargument : SDNode<"WebAssemblyISD::ARGUMENT",
59 SDT_WebAssemblyArgument>;
60def WebAssemblyreturn : SDNode<"WebAssemblyISD::RETURN",
JF Bastienaf111db2015-08-24 22:16:48 +000061 SDT_WebAssemblyReturn, [SDNPHasChain]>;
62def WebAssemblywrapper : SDNode<"WebAssemblyISD::Wrapper",
63 SDT_WebAssemblyWrapper>;
JF Bastien600aee92015-07-31 17:53:38 +000064
Dan Gohman10e730a2015-06-29 23:51:55 +000065//===----------------------------------------------------------------------===//
66// WebAssembly-specific Operands.
67//===----------------------------------------------------------------------===//
68
Dan Gohmana11fb232016-01-12 03:09:16 +000069let OperandNamespace = "WebAssembly" in {
70
71let OperandType = "OPERAND_BASIC_BLOCK" in
Dan Gohman950a13c2015-09-16 16:51:30 +000072def bb_op : Operand<OtherVT>;
JF Bastienaf111db2015-08-24 22:16:48 +000073
Dan Gohman4fc4e422016-10-24 19:49:43 +000074let OperandType = "OPERAND_LOCAL" in
75def local_op : Operand<i32>;
76
Dan Gohmanb89f2d32017-02-02 19:29:44 +000077let OperandType = "OPERAND_GLOBAL" in
78def global_op : Operand<i32>;
79
Dan Gohman5a68ec72016-10-05 21:24:08 +000080let OperandType = "OPERAND_I32IMM" in
81def i32imm_op : Operand<i32>;
82
83let OperandType = "OPERAND_I64IMM" in
84def i64imm_op : Operand<i64>;
85
Dan Gohman4b8e8be2016-10-03 21:31:31 +000086let OperandType = "OPERAND_F32IMM" in
Dan Gohmana11fb232016-01-12 03:09:16 +000087def f32imm_op : Operand<f32>;
Dan Gohmanaa742912016-02-16 15:14:23 +000088
Dan Gohman4b8e8be2016-10-03 21:31:31 +000089let OperandType = "OPERAND_F64IMM" in
Dan Gohmana11fb232016-01-12 03:09:16 +000090def f64imm_op : Operand<f64>;
Dan Gohmana11fb232016-01-12 03:09:16 +000091
Dan Gohman00d734d2016-12-23 03:23:52 +000092let OperandType = "OPERAND_FUNCTION32" in
93def function32_op : Operand<i32>;
94
95let OperandType = "OPERAND_OFFSET32" in
96def offset32_op : Operand<i32>;
97
Dan Gohmanbb372242016-01-26 03:39:31 +000098let OperandType = "OPERAND_P2ALIGN" in {
99def P2Align : Operand<i32> {
100 let PrintMethod = "printWebAssemblyP2AlignOperand";
101}
102} // OperandType = "OPERAND_P2ALIGN"
103
Dan Gohman2726b882016-10-06 22:29:32 +0000104let OperandType = "OPERAND_SIGNATURE" in {
105def Signature : Operand<i32> {
106 let PrintMethod = "printWebAssemblySignatureOperand";
107}
108} // OperandType = "OPERAND_SIGNATURE"
109
Dan Gohmand934cb82017-02-24 23:18:00 +0000110let OperandType = "OPERAND_TYPEINDEX" in
111def TypeIndex : Operand<i32>;
112
Dan Gohmana11fb232016-01-12 03:09:16 +0000113} // OperandNamespace = "WebAssembly"
114
Dan Gohman10e730a2015-06-29 23:51:55 +0000115//===----------------------------------------------------------------------===//
116// WebAssembly Instruction Format Definitions.
117//===----------------------------------------------------------------------===//
118
119include "WebAssemblyInstrFormats.td"
120
Dan Gohman4ba48162015-11-18 16:12:01 +0000121//===----------------------------------------------------------------------===//
122// Additional instructions.
123//===----------------------------------------------------------------------===//
124
JF Bastien8f9aea02015-08-01 04:48:44 +0000125multiclass ARGUMENT<WebAssemblyRegClass vt> {
Dan Gohmana783f102015-12-21 16:53:29 +0000126 let hasSideEffects = 1, Uses = [ARGUMENTS], isCodeGenOnly = 1 in
JF Bastien8f9aea02015-08-01 04:48:44 +0000127 def ARGUMENT_#vt : I<(outs vt:$res), (ins i32imm:$argno),
128 [(set vt:$res, (WebAssemblyargument timm:$argno))]>;
129}
Derek Schuff39bf39f2016-08-02 23:16:09 +0000130multiclass SIMD_ARGUMENT<ValueType vt> {
131 let hasSideEffects = 1, Uses = [ARGUMENTS], isCodeGenOnly = 1 in
132 def ARGUMENT_#vt : SIMD_I<(outs V128:$res), (ins i32imm:$argno),
133 [(set (vt V128:$res),
134 (WebAssemblyargument timm:$argno))]>;
135}
Dan Gohmand0bf9812015-09-26 01:09:44 +0000136defm : ARGUMENT<I32>;
137defm : ARGUMENT<I64>;
138defm : ARGUMENT<F32>;
139defm : ARGUMENT<F64>;
Derek Schuff39bf39f2016-08-02 23:16:09 +0000140defm : SIMD_ARGUMENT<v16i8>;
141defm : SIMD_ARGUMENT<v8i16>;
142defm : SIMD_ARGUMENT<v4i32>;
143defm : SIMD_ARGUMENT<v4f32>;
JF Bastien600aee92015-07-31 17:53:38 +0000144
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000145let Defs = [ARGUMENTS] in {
146
Dan Gohman4ba48162015-11-18 16:12:01 +0000147// get_local and set_local are not generated by instruction selection; they
Dan Gohmanadf28172016-01-28 01:22:44 +0000148// are implied by virtual register uses and defs.
Dan Gohman4ba48162015-11-18 16:12:01 +0000149multiclass LOCAL<WebAssemblyRegClass vt> {
Dan Gohman4817a752016-05-16 19:16:32 +0000150let hasSideEffects = 0 in {
Dan Gohman4fc4e422016-10-24 19:49:43 +0000151 // COPY is not an actual instruction in wasm, but since we allow get_local and
152 // set_local to be implicit during most of codegen, we can have a COPY which
153 // is actually a no-op because all the work is done in the implied get_local
154 // and set_local. COPYs are eliminated (and replaced with
155 // get_local/set_local) in the ExplicitLocals pass.
156 let isAsCheapAsAMove = 1, isCodeGenOnly = 1 in
157 def COPY_#vt : I<(outs vt:$res), (ins vt:$src), [], "copy_local\t$res, $src">;
Dan Gohmanadf28172016-01-28 01:22:44 +0000158
Dan Gohman4fc4e422016-10-24 19:49:43 +0000159 // TEE is similar to COPY, but writes two copies of its result. Typically
160 // this would be used to stackify one result and write the other result to a
161 // local.
162 let isAsCheapAsAMove = 1, isCodeGenOnly = 1 in
163 def TEE_#vt : I<(outs vt:$res, vt:$also), (ins vt:$src), [],
164 "tee_local\t$res, $also, $src">;
165
166 // This is the actual get_local instruction in wasm. These are made explicit
167 // by the ExplicitLocals pass. It has mayLoad because it reads from a wasm
168 // local, which is a side effect not otherwise modeled in LLVM.
169 let mayLoad = 1, isAsCheapAsAMove = 1 in
170 def GET_LOCAL_#vt : I<(outs vt:$res), (ins local_op:$local), [],
Dan Gohmanc9682972016-10-24 20:21:49 +0000171 "get_local\t$res, $local", 0x20>;
Dan Gohman4fc4e422016-10-24 19:49:43 +0000172
173 // This is the actual set_local instruction in wasm. These are made explicit
174 // by the ExplicitLocals pass. It has mayStore because it writes to a wasm
175 // local, which is a side effect not otherwise modeled in LLVM.
176 let mayStore = 1, isAsCheapAsAMove = 1 in
177 def SET_LOCAL_#vt : I<(outs), (ins local_op:$local, vt:$src), [],
Dan Gohmanc9682972016-10-24 20:21:49 +0000178 "set_local\t$local, $src", 0x21>;
Dan Gohman4fc4e422016-10-24 19:49:43 +0000179
180 // This is the actual tee_local instruction in wasm. TEEs are turned into
181 // TEE_LOCALs by the ExplicitLocals pass. It has mayStore for the same reason
182 // as SET_LOCAL.
183 let mayStore = 1, isAsCheapAsAMove = 1 in
184 def TEE_LOCAL_#vt : I<(outs vt:$res), (ins local_op:$local, vt:$src), [],
Dan Gohmanc9682972016-10-24 20:21:49 +0000185 "tee_local\t$res, $local, $src", 0x22>;
Dan Gohman4fc4e422016-10-24 19:49:43 +0000186
Dan Gohmanb89f2d32017-02-02 19:29:44 +0000187 // Unused values must be dropped in some contexts.
188 def DROP_#vt : I<(outs), (ins vt:$src), [],
189 "drop\t$src", 0x1a>;
190
191 let mayLoad = 1 in
192 def GET_GLOBAL_#vt : I<(outs vt:$res), (ins global_op:$local), [],
193 "get_global\t$res, $local", 0x23>;
194
195 let mayStore = 1 in
196 def SET_GLOBAL_#vt : I<(outs), (ins global_op:$local, vt:$src), [],
197 "set_global\t$local, $src", 0x24>;
198
Dan Gohman4817a752016-05-16 19:16:32 +0000199} // hasSideEffects = 0
Dan Gohman4ba48162015-11-18 16:12:01 +0000200}
201defm : LOCAL<I32>;
202defm : LOCAL<I64>;
203defm : LOCAL<F32>;
204defm : LOCAL<F64>;
Derek Schuff39bf39f2016-08-02 23:16:09 +0000205defm : LOCAL<V128>, Requires<[HasSIMD128]>;
JF Bastien4a642252015-08-10 22:36:48 +0000206
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000207let isMoveImm = 1, isAsCheapAsAMove = 1, isReMaterializable = 1 in {
Dan Gohman5a68ec72016-10-05 21:24:08 +0000208def CONST_I32 : I<(outs I32:$res), (ins i32imm_op:$imm),
Dan Gohmanda7f4282015-11-05 20:44:29 +0000209 [(set I32:$res, imm:$imm)],
Dan Gohmanc9682972016-10-24 20:21:49 +0000210 "i32.const\t$res, $imm", 0x41>;
Dan Gohman5a68ec72016-10-05 21:24:08 +0000211def CONST_I64 : I<(outs I64:$res), (ins i64imm_op:$imm),
Dan Gohmanda7f4282015-11-05 20:44:29 +0000212 [(set I64:$res, imm:$imm)],
Dan Gohmanc9682972016-10-24 20:21:49 +0000213 "i64.const\t$res, $imm", 0x42>;
Dan Gohmana11fb232016-01-12 03:09:16 +0000214def CONST_F32 : I<(outs F32:$res), (ins f32imm_op:$imm),
Dan Gohmanda7f4282015-11-05 20:44:29 +0000215 [(set F32:$res, fpimm:$imm)],
Dan Gohmanc9682972016-10-24 20:21:49 +0000216 "f32.const\t$res, $imm", 0x43>;
Dan Gohmana11fb232016-01-12 03:09:16 +0000217def CONST_F64 : I<(outs F64:$res), (ins f64imm_op:$imm),
Dan Gohmanda7f4282015-11-05 20:44:29 +0000218 [(set F64:$res, fpimm:$imm)],
Dan Gohmanc9682972016-10-24 20:21:49 +0000219 "f64.const\t$res, $imm", 0x44>;
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000220} // isMoveImm = 1, isAsCheapAsAMove = 1, isReMaterializable = 1
JF Bastien4a642252015-08-10 22:36:48 +0000221
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000222} // Defs = [ARGUMENTS]
223
Dan Gohman8633eed2016-01-08 00:50:33 +0000224def : Pat<(i32 (WebAssemblywrapper tglobaladdr:$addr)),
225 (CONST_I32 tglobaladdr:$addr)>;
226def : Pat<(i32 (WebAssemblywrapper texternalsym:$addr)),
227 (CONST_I32 texternalsym:$addr)>;
Derek Schuff71e81692015-11-17 00:20:44 +0000228
Dan Gohman10e730a2015-06-29 23:51:55 +0000229//===----------------------------------------------------------------------===//
230// Additional sets of instructions.
231//===----------------------------------------------------------------------===//
232
JF Bastien5ca0bac2015-07-10 18:23:10 +0000233include "WebAssemblyInstrMemory.td"
234include "WebAssemblyInstrCall.td"
JF Bastien600aee92015-07-31 17:53:38 +0000235include "WebAssemblyInstrControl.td"
JF Bastien5ca0bac2015-07-10 18:23:10 +0000236include "WebAssemblyInstrInteger.td"
JF Bastien5ca0bac2015-07-10 18:23:10 +0000237include "WebAssemblyInstrConv.td"
Dan Gohmanf170ba02015-12-10 04:55:31 +0000238include "WebAssemblyInstrFloat.td"
Dan Gohman10e730a2015-06-29 23:51:55 +0000239include "WebAssemblyInstrAtomics.td"
240include "WebAssemblyInstrSIMD.td"