blob: f0b4ce7caf5199f55e42eac844f1ba6faa71a82f [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 Gohmanbb7ce8e2015-11-20 03:02:49 +000033def SDT_WebAssemblyTableswitch : 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 Gohmanbb7ce8e2015-11-20 03:02:49 +000055def WebAssemblytableswitch : SDNode<"WebAssemblyISD::TABLESWITCH",
56 SDT_WebAssemblyTableswitch,
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 Gohman950a13c2015-09-16 16:51:30 +000069def bb_op : Operand<OtherVT>;
JF Bastienaf111db2015-08-24 22:16:48 +000070
Dan Gohman10e730a2015-06-29 23:51:55 +000071//===----------------------------------------------------------------------===//
72// WebAssembly Instruction Format Definitions.
73//===----------------------------------------------------------------------===//
74
75include "WebAssemblyInstrFormats.td"
76
Dan Gohman4ba48162015-11-18 16:12:01 +000077//===----------------------------------------------------------------------===//
78// Additional instructions.
79//===----------------------------------------------------------------------===//
80
JF Bastien8f9aea02015-08-01 04:48:44 +000081multiclass ARGUMENT<WebAssemblyRegClass vt> {
Dan Gohmana783f102015-12-21 16:53:29 +000082 let hasSideEffects = 1, Uses = [ARGUMENTS], isCodeGenOnly = 1 in
JF Bastien8f9aea02015-08-01 04:48:44 +000083 def ARGUMENT_#vt : I<(outs vt:$res), (ins i32imm:$argno),
84 [(set vt:$res, (WebAssemblyargument timm:$argno))]>;
85}
Dan Gohmand0bf9812015-09-26 01:09:44 +000086defm : ARGUMENT<I32>;
87defm : ARGUMENT<I64>;
88defm : ARGUMENT<F32>;
89defm : ARGUMENT<F64>;
JF Bastien600aee92015-07-31 17:53:38 +000090
Dan Gohmanfb3e0592015-11-25 19:36:19 +000091let Defs = [ARGUMENTS] in {
92
Dan Gohman4ba48162015-11-18 16:12:01 +000093// get_local and set_local are not generated by instruction selection; they
94// are implied by virtual register uses and defs in most contexts. However,
95// they are explicitly emitted for special purposes.
96multiclass LOCAL<WebAssemblyRegClass vt> {
97 def GET_LOCAL_#vt : I<(outs vt:$res), (ins i32imm:$regno), [],
98 "get_local\t$res, $regno">;
99 // TODO: set_local returns its operand value
100 def SET_LOCAL_#vt : I<(outs), (ins i32imm:$regno, vt:$src), [],
101 "set_local\t$regno, $src">;
Dan Gohmanaa0a4bd2015-11-23 19:30:43 +0000102
103 // COPY_LOCAL is not an actual instruction in wasm, but since we allow
104 // get_local and set_local to be implicit, we can have a COPY_LOCAL which
105 // is actually a no-op because all the work is done in the implied
106 // get_local and set_local.
107 let isAsCheapAsAMove = 1 in
108 def COPY_LOCAL_#vt : I<(outs vt:$res), (ins vt:$src), [],
109 "copy_local\t$res, $src">;
Dan Gohman4ba48162015-11-18 16:12:01 +0000110}
111defm : LOCAL<I32>;
112defm : LOCAL<I64>;
113defm : LOCAL<F32>;
114defm : LOCAL<F64>;
JF Bastien4a642252015-08-10 22:36:48 +0000115
Dan Gohman174b2d82015-11-29 22:59:19 +0000116let isMoveImm = 1 in {
Dan Gohmandd0071f2015-11-13 20:27:45 +0000117def CONST_I32 : I<(outs I32:$res), (ins i32imm:$imm),
Dan Gohmanda7f4282015-11-05 20:44:29 +0000118 [(set I32:$res, imm:$imm)],
Dan Gohman1031d4a2015-11-15 15:34:19 +0000119 "i32.const\t$res, $imm">;
Dan Gohmandd0071f2015-11-13 20:27:45 +0000120def CONST_I64 : I<(outs I64:$res), (ins i64imm:$imm),
Dan Gohmanda7f4282015-11-05 20:44:29 +0000121 [(set I64:$res, imm:$imm)],
Dan Gohman1031d4a2015-11-15 15:34:19 +0000122 "i64.const\t$res, $imm">;
Dan Gohmandd0071f2015-11-13 20:27:45 +0000123def CONST_F32 : I<(outs F32:$res), (ins f32imm:$imm),
Dan Gohmanda7f4282015-11-05 20:44:29 +0000124 [(set F32:$res, fpimm:$imm)],
Dan Gohman1031d4a2015-11-15 15:34:19 +0000125 "f32.const\t$res, $imm">;
Dan Gohmandd0071f2015-11-13 20:27:45 +0000126def CONST_F64 : I<(outs F64:$res), (ins f64imm:$imm),
Dan Gohmanda7f4282015-11-05 20:44:29 +0000127 [(set F64:$res, fpimm:$imm)],
Dan Gohman1031d4a2015-11-15 15:34:19 +0000128 "f64.const\t$res, $imm">;
Dan Gohman174b2d82015-11-29 22:59:19 +0000129} // isMoveImm = 1
JF Bastien4a642252015-08-10 22:36:48 +0000130
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000131} // Defs = [ARGUMENTS]
132
Dan Gohman2c8fe6a2015-11-25 16:44:29 +0000133def : Pat<(i32 (WebAssemblywrapper tglobaladdr:$dst)),
134 (CONST_I32 tglobaladdr:$dst)>;
135def : Pat<(i32 (WebAssemblywrapper texternalsym:$dst)),
136 (CONST_I32 texternalsym:$dst)>;
Dan Gohman3bb55e92015-12-05 20:46:53 +0000137def : Pat<(i32 (WebAssemblywrapper tjumptable:$dst)),
138 (CONST_I32 tjumptable:$dst)>;
Derek Schuff71e81692015-11-17 00:20:44 +0000139
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000140let Defs = [ARGUMENTS] in {
141
Dan Gohman53828fd2015-11-23 16:50:18 +0000142// Function signature and local variable declaration "instructions".
143def PARAM : I<(outs), (ins variable_ops), [], ".param \t">;
144def RESULT : I<(outs), (ins variable_ops), [], ".result \t">;
145def LOCAL : I<(outs), (ins variable_ops), [], ".local \t">;
146
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000147} // Defs = [ARGUMENTS]
148
Dan Gohman10e730a2015-06-29 23:51:55 +0000149//===----------------------------------------------------------------------===//
150// Additional sets of instructions.
151//===----------------------------------------------------------------------===//
152
JF Bastien5ca0bac2015-07-10 18:23:10 +0000153include "WebAssemblyInstrMemory.td"
154include "WebAssemblyInstrCall.td"
JF Bastien600aee92015-07-31 17:53:38 +0000155include "WebAssemblyInstrControl.td"
JF Bastien5ca0bac2015-07-10 18:23:10 +0000156include "WebAssemblyInstrInteger.td"
JF Bastien5ca0bac2015-07-10 18:23:10 +0000157include "WebAssemblyInstrConv.td"
Dan Gohmanf170ba02015-12-10 04:55:31 +0000158include "WebAssemblyInstrFloat.td"
Dan Gohman10e730a2015-06-29 23:51:55 +0000159include "WebAssemblyInstrAtomics.td"
160include "WebAssemblyInstrSIMD.td"