]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td
MFV r325609: 7531 Assign correct flags to prefetched buffers
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / WebAssembly / WebAssemblyInstrInfo.td
1 // 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 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// \brief WebAssembly Instruction definitions.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 //===----------------------------------------------------------------------===//
16 // WebAssembly Instruction Predicate Definitions.
17 //===----------------------------------------------------------------------===//
18
19 def HasAddr32 : Predicate<"!Subtarget->hasAddr64()">;
20 def HasAddr64 : Predicate<"Subtarget->hasAddr64()">;
21 def HasSIMD128 : Predicate<"Subtarget->hasSIMD128()">,
22                            AssemblerPredicate<"FeatureSIMD128", "simd128">;
23
24 //===----------------------------------------------------------------------===//
25 // WebAssembly-specific DAG Node Types.
26 //===----------------------------------------------------------------------===//
27
28 def SDT_WebAssemblyCallSeqStart : SDCallSeqStart<[SDTCisVT<0, iPTR>,
29                                                   SDTCisVT<1, iPTR>]>;
30 def SDT_WebAssemblyCallSeqEnd :
31     SDCallSeqEnd<[SDTCisVT<0, iPTR>, SDTCisVT<1, iPTR>]>;
32 def SDT_WebAssemblyCall0    : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>;
33 def SDT_WebAssemblyCall1    : SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>;
34 def SDT_WebAssemblyBrTable  : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>;
35 def SDT_WebAssemblyArgument : SDTypeProfile<1, 1, [SDTCisVT<1, i32>]>;
36 def SDT_WebAssemblyReturn   : SDTypeProfile<0, -1, []>;
37 def SDT_WebAssemblyWrapper  : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>,
38                                                    SDTCisPtrTy<0>]>;
39
40 //===----------------------------------------------------------------------===//
41 // WebAssembly-specific DAG Nodes.
42 //===----------------------------------------------------------------------===//
43
44 def WebAssemblycallseq_start :
45     SDNode<"ISD::CALLSEQ_START", SDT_WebAssemblyCallSeqStart,
46            [SDNPHasChain, SDNPOutGlue]>;
47 def WebAssemblycallseq_end :
48     SDNode<"ISD::CALLSEQ_END", SDT_WebAssemblyCallSeqEnd,
49            [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
50 def WebAssemblycall0 : SDNode<"WebAssemblyISD::CALL0",
51                               SDT_WebAssemblyCall0,
52                               [SDNPHasChain, SDNPVariadic]>;
53 def WebAssemblycall1 : SDNode<"WebAssemblyISD::CALL1",
54                               SDT_WebAssemblyCall1,
55                               [SDNPHasChain, SDNPVariadic]>;
56 def WebAssemblybr_table : SDNode<"WebAssemblyISD::BR_TABLE",
57                                  SDT_WebAssemblyBrTable,
58                                  [SDNPHasChain, SDNPVariadic]>;
59 def WebAssemblyargument : SDNode<"WebAssemblyISD::ARGUMENT",
60                                  SDT_WebAssemblyArgument>;
61 def WebAssemblyreturn   : SDNode<"WebAssemblyISD::RETURN",
62                                  SDT_WebAssemblyReturn, [SDNPHasChain]>;
63 def WebAssemblywrapper  : SDNode<"WebAssemblyISD::Wrapper",
64                                  SDT_WebAssemblyWrapper>;
65
66 //===----------------------------------------------------------------------===//
67 // WebAssembly-specific Operands.
68 //===----------------------------------------------------------------------===//
69
70 let OperandNamespace = "WebAssembly" in {
71
72 let OperandType = "OPERAND_BASIC_BLOCK" in
73 def bb_op : Operand<OtherVT>;
74
75 let OperandType = "OPERAND_LOCAL" in
76 def local_op : Operand<i32>;
77
78 let OperandType = "OPERAND_GLOBAL" in
79 def global_op : Operand<i32>;
80
81 let OperandType = "OPERAND_I32IMM" in
82 def i32imm_op : Operand<i32>;
83
84 let OperandType = "OPERAND_I64IMM" in
85 def i64imm_op : Operand<i64>;
86
87 let OperandType = "OPERAND_F32IMM" in
88 def f32imm_op : Operand<f32>;
89
90 let OperandType = "OPERAND_F64IMM" in
91 def f64imm_op : Operand<f64>;
92
93 let OperandType = "OPERAND_FUNCTION32" in
94 def function32_op : Operand<i32>;
95
96 let OperandType = "OPERAND_OFFSET32" in
97 def offset32_op : Operand<i32>;
98
99 let OperandType = "OPERAND_P2ALIGN" in {
100 def P2Align : Operand<i32> {
101   let PrintMethod = "printWebAssemblyP2AlignOperand";
102 }
103 } // OperandType = "OPERAND_P2ALIGN"
104
105 let OperandType = "OPERAND_SIGNATURE" in {
106 def Signature : Operand<i32> {
107   let PrintMethod = "printWebAssemblySignatureOperand";
108 }
109 } // OperandType = "OPERAND_SIGNATURE"
110
111 let OperandType = "OPERAND_TYPEINDEX" in
112 def TypeIndex : Operand<i32>;
113
114 } // OperandNamespace = "WebAssembly"
115
116 //===----------------------------------------------------------------------===//
117 // WebAssembly Instruction Format Definitions.
118 //===----------------------------------------------------------------------===//
119
120 include "WebAssemblyInstrFormats.td"
121
122 //===----------------------------------------------------------------------===//
123 // Additional instructions.
124 //===----------------------------------------------------------------------===//
125
126 multiclass ARGUMENT<WebAssemblyRegClass vt> {
127   let hasSideEffects = 1, Uses = [ARGUMENTS], isCodeGenOnly = 1 in
128   def ARGUMENT_#vt : I<(outs vt:$res), (ins i32imm:$argno),
129                        [(set vt:$res, (WebAssemblyargument timm:$argno))]>;
130 }
131 multiclass SIMD_ARGUMENT<ValueType vt> {
132   let hasSideEffects = 1, Uses = [ARGUMENTS], isCodeGenOnly = 1 in
133   def ARGUMENT_#vt : SIMD_I<(outs V128:$res), (ins i32imm:$argno),
134                             [(set (vt V128:$res),
135                                   (WebAssemblyargument timm:$argno))]>;
136 }
137 defm : ARGUMENT<I32>;
138 defm : ARGUMENT<I64>;
139 defm : ARGUMENT<F32>;
140 defm : ARGUMENT<F64>;
141 defm : SIMD_ARGUMENT<v16i8>;
142 defm : SIMD_ARGUMENT<v8i16>;
143 defm : SIMD_ARGUMENT<v4i32>;
144 defm : SIMD_ARGUMENT<v4f32>;
145
146 let Defs = [ARGUMENTS] in {
147
148 // get_local and set_local are not generated by instruction selection; they
149 // are implied by virtual register uses and defs.
150 multiclass LOCAL<WebAssemblyRegClass vt> {
151 let hasSideEffects = 0 in {
152   // COPY is not an actual instruction in wasm, but since we allow get_local and
153   // set_local to be implicit during most of codegen, we can have a COPY which
154   // is actually a no-op because all the work is done in the implied get_local
155   // and set_local. COPYs are eliminated (and replaced with
156   // get_local/set_local) in the ExplicitLocals pass.
157   let isAsCheapAsAMove = 1, isCodeGenOnly = 1 in
158   def COPY_#vt : I<(outs vt:$res), (ins vt:$src), [], "copy_local\t$res, $src">;
159
160   // TEE is similar to COPY, but writes two copies of its result. Typically
161   // this would be used to stackify one result and write the other result to a
162   // local.
163   let isAsCheapAsAMove = 1, isCodeGenOnly = 1 in
164   def TEE_#vt : I<(outs vt:$res, vt:$also), (ins vt:$src), [],
165                   "tee_local\t$res, $also, $src">;
166
167   // This is the actual get_local instruction in wasm. These are made explicit
168   // by the ExplicitLocals pass. It has mayLoad because it reads from a wasm
169   // local, which is a side effect not otherwise modeled in LLVM.
170   let mayLoad = 1, isAsCheapAsAMove = 1 in
171   def GET_LOCAL_#vt : I<(outs vt:$res), (ins local_op:$local), [],
172                         "get_local\t$res, $local", 0x20>;
173
174   // This is the actual set_local instruction in wasm. These are made explicit
175   // by the ExplicitLocals pass. It has mayStore because it writes to a wasm
176   // local, which is a side effect not otherwise modeled in LLVM.
177   let mayStore = 1, isAsCheapAsAMove = 1 in
178   def SET_LOCAL_#vt : I<(outs), (ins local_op:$local, vt:$src), [],
179                         "set_local\t$local, $src", 0x21>;
180
181   // This is the actual tee_local instruction in wasm. TEEs are turned into
182   // TEE_LOCALs by the ExplicitLocals pass. It has mayStore for the same reason
183   // as SET_LOCAL.
184   let mayStore = 1, isAsCheapAsAMove = 1 in
185   def TEE_LOCAL_#vt : I<(outs vt:$res), (ins local_op:$local, vt:$src), [],
186                          "tee_local\t$res, $local, $src", 0x22>;
187
188   // Unused values must be dropped in some contexts.
189   def DROP_#vt : I<(outs), (ins vt:$src), [],
190                    "drop\t$src", 0x1a>;
191
192   let mayLoad = 1 in
193   def GET_GLOBAL_#vt : I<(outs vt:$res), (ins global_op:$local), [],
194                          "get_global\t$res, $local", 0x23>;
195
196   let mayStore = 1 in
197   def SET_GLOBAL_#vt : I<(outs), (ins global_op:$local, vt:$src), [],
198                          "set_global\t$local, $src", 0x24>;
199
200 } // hasSideEffects = 0
201 }
202 defm : LOCAL<I32>;
203 defm : LOCAL<I64>;
204 defm : LOCAL<F32>;
205 defm : LOCAL<F64>;
206 defm : LOCAL<V128>, Requires<[HasSIMD128]>;
207
208 let isMoveImm = 1, isAsCheapAsAMove = 1, isReMaterializable = 1 in {
209 def CONST_I32 : I<(outs I32:$res), (ins i32imm_op:$imm),
210                   [(set I32:$res, imm:$imm)],
211                   "i32.const\t$res, $imm", 0x41>;
212 def CONST_I64 : I<(outs I64:$res), (ins i64imm_op:$imm),
213                   [(set I64:$res, imm:$imm)],
214                   "i64.const\t$res, $imm", 0x42>;
215 def CONST_F32 : I<(outs F32:$res), (ins f32imm_op:$imm),
216                   [(set F32:$res, fpimm:$imm)],
217                   "f32.const\t$res, $imm", 0x43>;
218 def CONST_F64 : I<(outs F64:$res), (ins f64imm_op:$imm),
219                   [(set F64:$res, fpimm:$imm)],
220                   "f64.const\t$res, $imm", 0x44>;
221 } // isMoveImm = 1, isAsCheapAsAMove = 1, isReMaterializable = 1
222
223 } // Defs = [ARGUMENTS]
224
225 def : Pat<(i32 (WebAssemblywrapper tglobaladdr:$addr)),
226           (CONST_I32 tglobaladdr:$addr)>;
227 def : Pat<(i32 (WebAssemblywrapper texternalsym:$addr)),
228           (CONST_I32 texternalsym:$addr)>;
229
230 //===----------------------------------------------------------------------===//
231 // Additional sets of instructions.
232 //===----------------------------------------------------------------------===//
233
234 include "WebAssemblyInstrMemory.td"
235 include "WebAssemblyInstrCall.td"
236 include "WebAssemblyInstrControl.td"
237 include "WebAssemblyInstrInteger.td"
238 include "WebAssemblyInstrConv.td"
239 include "WebAssemblyInstrFloat.td"
240 include "WebAssemblyInstrAtomics.td"
241 include "WebAssemblyInstrSIMD.td"