blob: 922279d77422014595aabc6d2bfa56689de4fdd4 [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}
Derek Schuff39bf39f2016-08-02 23:16:09 +0000103multiclass SIMD_ARGUMENT<ValueType vt> {
104 let hasSideEffects = 1, Uses = [ARGUMENTS], isCodeGenOnly = 1 in
105 def ARGUMENT_#vt : SIMD_I<(outs V128:$res), (ins i32imm:$argno),
106 [(set (vt V128:$res),
107 (WebAssemblyargument timm:$argno))]>;
108}
Dan Gohmand0bf9812015-09-26 01:09:44 +0000109defm : ARGUMENT<I32>;
110defm : ARGUMENT<I64>;
111defm : ARGUMENT<F32>;
112defm : ARGUMENT<F64>;
Derek Schuff39bf39f2016-08-02 23:16:09 +0000113defm : SIMD_ARGUMENT<v16i8>;
114defm : SIMD_ARGUMENT<v8i16>;
115defm : SIMD_ARGUMENT<v4i32>;
116defm : SIMD_ARGUMENT<v4f32>;
JF Bastien600aee92015-07-31 17:53:38 +0000117
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000118let Defs = [ARGUMENTS] in {
119
Dan Gohman4ba48162015-11-18 16:12:01 +0000120// get_local and set_local are not generated by instruction selection; they
Dan Gohmanadf28172016-01-28 01:22:44 +0000121// are implied by virtual register uses and defs.
Dan Gohman4ba48162015-11-18 16:12:01 +0000122multiclass LOCAL<WebAssemblyRegClass vt> {
Dan Gohman4817a752016-05-16 19:16:32 +0000123let hasSideEffects = 0 in {
Dan Gohmanaa0a4bd2015-11-23 19:30:43 +0000124 // COPY_LOCAL is not an actual instruction in wasm, but since we allow
125 // get_local and set_local to be implicit, we can have a COPY_LOCAL which
126 // is actually a no-op because all the work is done in the implied
127 // get_local and set_local.
128 let isAsCheapAsAMove = 1 in
129 def COPY_LOCAL_#vt : I<(outs vt:$res), (ins vt:$src), [],
130 "copy_local\t$res, $src">;
Dan Gohmanadf28172016-01-28 01:22:44 +0000131
132 // TEE_LOCAL is similar to COPY_LOCAL, but writes two copies of its result.
133 // Typically this would be used to stackify one result and write the other
134 // result to a local.
135 let isAsCheapAsAMove = 1 in
136 def TEE_LOCAL_#vt : I<(outs vt:$res, vt:$also), (ins vt:$src), [],
137 "tee_local\t$res, $also, $src">;
Dan Gohman4817a752016-05-16 19:16:32 +0000138} // hasSideEffects = 0
Dan Gohman4ba48162015-11-18 16:12:01 +0000139}
140defm : LOCAL<I32>;
141defm : LOCAL<I64>;
142defm : LOCAL<F32>;
143defm : LOCAL<F64>;
Derek Schuff39bf39f2016-08-02 23:16:09 +0000144defm : LOCAL<V128>, Requires<[HasSIMD128]>;
JF Bastien4a642252015-08-10 22:36:48 +0000145
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000146let isMoveImm = 1, isAsCheapAsAMove = 1, isReMaterializable = 1 in {
Dan Gohmandd0071f2015-11-13 20:27:45 +0000147def CONST_I32 : I<(outs I32:$res), (ins i32imm:$imm),
Dan Gohmanda7f4282015-11-05 20:44:29 +0000148 [(set I32:$res, imm:$imm)],
Dan Gohman1031d4a2015-11-15 15:34:19 +0000149 "i32.const\t$res, $imm">;
Dan Gohmandd0071f2015-11-13 20:27:45 +0000150def CONST_I64 : I<(outs I64:$res), (ins i64imm:$imm),
Dan Gohmanda7f4282015-11-05 20:44:29 +0000151 [(set I64:$res, imm:$imm)],
Dan Gohman1031d4a2015-11-15 15:34:19 +0000152 "i64.const\t$res, $imm">;
Dan Gohmana11fb232016-01-12 03:09:16 +0000153def CONST_F32 : I<(outs F32:$res), (ins f32imm_op:$imm),
Dan Gohmanda7f4282015-11-05 20:44:29 +0000154 [(set F32:$res, fpimm:$imm)],
Dan Gohman1031d4a2015-11-15 15:34:19 +0000155 "f32.const\t$res, $imm">;
Dan Gohmana11fb232016-01-12 03:09:16 +0000156def CONST_F64 : I<(outs F64:$res), (ins f64imm_op:$imm),
Dan Gohmanda7f4282015-11-05 20:44:29 +0000157 [(set F64:$res, fpimm:$imm)],
Dan Gohman1031d4a2015-11-15 15:34:19 +0000158 "f64.const\t$res, $imm">;
Dan Gohmanb6fd39a2016-01-19 16:59:23 +0000159} // isMoveImm = 1, isAsCheapAsAMove = 1, isReMaterializable = 1
JF Bastien4a642252015-08-10 22:36:48 +0000160
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000161} // Defs = [ARGUMENTS]
162
Dan Gohman8633eed2016-01-08 00:50:33 +0000163def : Pat<(i32 (WebAssemblywrapper tglobaladdr:$addr)),
164 (CONST_I32 tglobaladdr:$addr)>;
165def : Pat<(i32 (WebAssemblywrapper texternalsym:$addr)),
166 (CONST_I32 texternalsym:$addr)>;
Derek Schuff71e81692015-11-17 00:20:44 +0000167
Dan Gohman10e730a2015-06-29 23:51:55 +0000168//===----------------------------------------------------------------------===//
169// Additional sets of instructions.
170//===----------------------------------------------------------------------===//
171
JF Bastien5ca0bac2015-07-10 18:23:10 +0000172include "WebAssemblyInstrMemory.td"
173include "WebAssemblyInstrCall.td"
JF Bastien600aee92015-07-31 17:53:38 +0000174include "WebAssemblyInstrControl.td"
JF Bastien5ca0bac2015-07-10 18:23:10 +0000175include "WebAssemblyInstrInteger.td"
JF Bastien5ca0bac2015-07-10 18:23:10 +0000176include "WebAssemblyInstrConv.td"
Dan Gohmanf170ba02015-12-10 04:55:31 +0000177include "WebAssemblyInstrFloat.td"
Dan Gohman10e730a2015-06-29 23:51:55 +0000178include "WebAssemblyInstrAtomics.td"
179include "WebAssemblyInstrSIMD.td"