blob: 4b319871cf16c3909d841a25446cda759994825a [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 Gohmanaa742912016-02-16 15:14:23 +000074let OperandType = "OPERAND_FP32IMM" in
Dan Gohmana11fb232016-01-12 03:09:16 +000075def f32imm_op : Operand<f32>;
Dan Gohmanaa742912016-02-16 15:14:23 +000076
77let OperandType = "OPERAND_FP64IMM" in
Dan Gohmana11fb232016-01-12 03:09:16 +000078def f64imm_op : Operand<f64>;
Dan Gohmana11fb232016-01-12 03:09:16 +000079
Dan Gohmanbb372242016-01-26 03:39:31 +000080let OperandType = "OPERAND_P2ALIGN" in {
81def P2Align : Operand<i32> {
82 let PrintMethod = "printWebAssemblyP2AlignOperand";
83}
84} // OperandType = "OPERAND_P2ALIGN"
85
Dan Gohmana11fb232016-01-12 03:09:16 +000086} // OperandNamespace = "WebAssembly"
87
Dan Gohman10e730a2015-06-29 23:51:55 +000088//===----------------------------------------------------------------------===//
89// WebAssembly Instruction Format Definitions.
90//===----------------------------------------------------------------------===//
91
92include "WebAssemblyInstrFormats.td"
93
Dan Gohman4ba48162015-11-18 16:12:01 +000094//===----------------------------------------------------------------------===//
95// Additional instructions.
96//===----------------------------------------------------------------------===//
97
JF Bastien8f9aea02015-08-01 04:48:44 +000098multiclass ARGUMENT<WebAssemblyRegClass vt> {
Dan Gohmana783f102015-12-21 16:53:29 +000099 let hasSideEffects = 1, Uses = [ARGUMENTS], isCodeGenOnly = 1 in
JF Bastien8f9aea02015-08-01 04:48:44 +0000100 def ARGUMENT_#vt : I<(outs vt:$res), (ins i32imm:$argno),
101 [(set vt:$res, (WebAssemblyargument timm:$argno))]>;
102}
Dan Gohmand0bf9812015-09-26 01:09:44 +0000103defm : ARGUMENT<I32>;
104defm : ARGUMENT<I64>;
105defm : ARGUMENT<F32>;
106defm : ARGUMENT<F64>;
JF Bastien600aee92015-07-31 17:53:38 +0000107
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000108let Defs = [ARGUMENTS] in {
109
Dan Gohman4ba48162015-11-18 16:12:01 +0000110// get_local and set_local are not generated by instruction selection; they
Dan Gohmanadf28172016-01-28 01:22:44 +0000111// are implied by virtual register uses and defs.
Dan Gohman4ba48162015-11-18 16:12:01 +0000112multiclass LOCAL<WebAssemblyRegClass vt> {
Dan Gohman4817a752016-05-16 19:16:32 +0000113let hasSideEffects = 0 in {
Dan Gohmanaa0a4bd2015-11-23 19:30:43 +0000114 // COPY_LOCAL is not an actual instruction in wasm, but since we allow
115 // get_local and set_local to be implicit, we can have a COPY_LOCAL which
116 // is actually a no-op because all the work is done in the implied
117 // get_local and set_local.
118 let isAsCheapAsAMove = 1 in
119 def COPY_LOCAL_#vt : I<(outs vt:$res), (ins vt:$src), [],
120 "copy_local\t$res, $src">;
Dan Gohmanadf28172016-01-28 01:22:44 +0000121
122 // TEE_LOCAL is similar to COPY_LOCAL, but writes two copies of its result.
123 // Typically this would be used to stackify one result and write the other
124 // result to a local.
125 let isAsCheapAsAMove = 1 in
126 def TEE_LOCAL_#vt : I<(outs vt:$res, vt:$also), (ins vt:$src), [],
127 "tee_local\t$res, $also, $src">;
Dan Gohman4817a752016-05-16 19:16:32 +0000128} // hasSideEffects = 0
Dan Gohman4ba48162015-11-18 16:12:01 +0000129}
130defm : LOCAL<I32>;
131defm : LOCAL<I64>;
132defm : LOCAL<F32>;
133defm : LOCAL<F64>;
JF Bastien4a642252015-08-10 22:36:48 +0000134
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000135let isMoveImm = 1, isAsCheapAsAMove = 1, isReMaterializable = 1 in {
Dan Gohmandd0071f2015-11-13 20:27:45 +0000136def CONST_I32 : I<(outs I32:$res), (ins i32imm:$imm),
Dan Gohmanda7f4282015-11-05 20:44:29 +0000137 [(set I32:$res, imm:$imm)],
Dan Gohman1031d4a2015-11-15 15:34:19 +0000138 "i32.const\t$res, $imm">;
Dan Gohmandd0071f2015-11-13 20:27:45 +0000139def CONST_I64 : I<(outs I64:$res), (ins i64imm:$imm),
Dan Gohmanda7f4282015-11-05 20:44:29 +0000140 [(set I64:$res, imm:$imm)],
Dan Gohman1031d4a2015-11-15 15:34:19 +0000141 "i64.const\t$res, $imm">;
Dan Gohmana11fb232016-01-12 03:09:16 +0000142def CONST_F32 : I<(outs F32:$res), (ins f32imm_op:$imm),
Dan Gohmanda7f4282015-11-05 20:44:29 +0000143 [(set F32:$res, fpimm:$imm)],
Dan Gohman1031d4a2015-11-15 15:34:19 +0000144 "f32.const\t$res, $imm">;
Dan Gohmana11fb232016-01-12 03:09:16 +0000145def CONST_F64 : I<(outs F64:$res), (ins f64imm_op:$imm),
Dan Gohmanda7f4282015-11-05 20:44:29 +0000146 [(set F64:$res, fpimm:$imm)],
Dan Gohman1031d4a2015-11-15 15:34:19 +0000147 "f64.const\t$res, $imm">;
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000148} // isMoveImm = 1, isAsCheapAsAMove = 1, isReMaterializable = 1
JF Bastien4a642252015-08-10 22:36:48 +0000149
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000150} // Defs = [ARGUMENTS]
151
Dan Gohman8633eed2016-01-08 00:50:33 +0000152def : Pat<(i32 (WebAssemblywrapper tglobaladdr:$addr)),
153 (CONST_I32 tglobaladdr:$addr)>;
154def : Pat<(i32 (WebAssemblywrapper texternalsym:$addr)),
155 (CONST_I32 texternalsym:$addr)>;
Derek Schuff71e81692015-11-17 00:20:44 +0000156
Dan Gohman10e730a2015-06-29 23:51:55 +0000157//===----------------------------------------------------------------------===//
158// Additional sets of instructions.
159//===----------------------------------------------------------------------===//
160
JF Bastien5ca0bac2015-07-10 18:23:10 +0000161include "WebAssemblyInstrMemory.td"
162include "WebAssemblyInstrCall.td"
JF Bastien600aee92015-07-31 17:53:38 +0000163include "WebAssemblyInstrControl.td"
JF Bastien5ca0bac2015-07-10 18:23:10 +0000164include "WebAssemblyInstrInteger.td"
JF Bastien5ca0bac2015-07-10 18:23:10 +0000165include "WebAssemblyInstrConv.td"
Dan Gohmanf170ba02015-12-10 04:55:31 +0000166include "WebAssemblyInstrFloat.td"
Dan Gohman10e730a2015-06-29 23:51:55 +0000167include "WebAssemblyInstrAtomics.td"
168include "WebAssemblyInstrSIMD.td"