]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/AMDGPU/SIInstrInfo.td
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / AMDGPU / SIInstrInfo.td
1 //===-- SIInstrInfo.td - SI Instruction Infos -------------*- 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 def isCI : Predicate<"Subtarget->getGeneration() "
10                       ">= AMDGPUSubtarget::SEA_ISLANDS">;
11 def isCIOnly : Predicate<"Subtarget->getGeneration() =="
12                          "AMDGPUSubtarget::SEA_ISLANDS">,
13   AssemblerPredicate <"FeatureSeaIslands">;
14 def isVIOnly : Predicate<"Subtarget->getGeneration() =="
15                          "AMDGPUSubtarget::VOLCANIC_ISLANDS">,
16   AssemblerPredicate <"FeatureVolcanicIslands">;
17
18 def DisableInst : Predicate <"false">, AssemblerPredicate<"FeatureDisable">;
19
20 class GCNPredicateControl : PredicateControl {
21   Predicate SIAssemblerPredicate = isSICI;
22   Predicate VIAssemblerPredicate = isVI;
23 }
24
25 // Execpt for the NONE field, this must be kept in sync with the
26 // SIEncodingFamily enum in AMDGPUInstrInfo.cpp
27 def SIEncodingFamily {
28   int NONE = -1;
29   int SI = 0;
30   int VI = 1;
31   int SDWA = 2;
32   int SDWA9 = 3;
33   int GFX80 = 4;
34   int GFX9 = 5;
35 }
36
37 //===----------------------------------------------------------------------===//
38 // SI DAG Nodes
39 //===----------------------------------------------------------------------===//
40
41 def AMDGPUclamp : SDNode<"AMDGPUISD::CLAMP", SDTFPUnaryOp>;
42
43 def SIload_constant : SDNode<"AMDGPUISD::LOAD_CONSTANT",
44   SDTypeProfile<1, 2, [SDTCisVT<0, f32>, SDTCisVT<1, v4i32>, SDTCisVT<2, i32>]>,
45                       [SDNPMayLoad, SDNPMemOperand]
46 >;
47
48 def SIatomic_inc : SDNode<"AMDGPUISD::ATOMIC_INC", SDTAtomic2,
49   [SDNPMayLoad, SDNPMayStore, SDNPMemOperand, SDNPHasChain]
50 >;
51
52 def SIatomic_dec : SDNode<"AMDGPUISD::ATOMIC_DEC", SDTAtomic2,
53   [SDNPMayLoad, SDNPMayStore, SDNPMemOperand, SDNPHasChain]
54 >;
55
56 def SDTAtomic2_f32 : SDTypeProfile<1, 2, [
57   SDTCisSameAs<0,2>, SDTCisFP<0>, SDTCisPtrTy<1>
58 ]>;
59
60 def SIatomic_fadd : SDNode<"AMDGPUISD::ATOMIC_LOAD_FADD", SDTAtomic2_f32,
61   [SDNPMayLoad, SDNPMayStore, SDNPMemOperand, SDNPHasChain]
62 >;
63
64 def SIatomic_fmin : SDNode<"AMDGPUISD::ATOMIC_LOAD_FMIN", SDTAtomic2_f32,
65   [SDNPMayLoad, SDNPMayStore, SDNPMemOperand, SDNPHasChain]
66 >;
67
68 def SIatomic_fmax : SDNode<"AMDGPUISD::ATOMIC_LOAD_FMAX", SDTAtomic2_f32,
69   [SDNPMayLoad, SDNPMayStore, SDNPMemOperand, SDNPHasChain]
70 >;
71
72 def SDTbuffer_load : SDTypeProfile<1, 9,
73   [                     // vdata
74    SDTCisVT<1, v4i32>,  // rsrc
75    SDTCisVT<2, i32>,    // vindex(VGPR)
76    SDTCisVT<3, i32>,    // voffset(VGPR)
77    SDTCisVT<4, i32>,    // soffset(SGPR)
78    SDTCisVT<5, i32>,    // offset(imm)
79    SDTCisVT<6, i32>,    // dfmt(imm)
80    SDTCisVT<7, i32>,    // nfmt(imm)
81    SDTCisVT<8, i32>,    // glc(imm)
82    SDTCisVT<9, i32>     // slc(imm)
83   ]>;
84
85 def SItbuffer_load :   SDNode<"AMDGPUISD::TBUFFER_LOAD_FORMAT", SDTbuffer_load,
86                               [SDNPMayLoad, SDNPMemOperand, SDNPHasChain]>;
87 def SItbuffer_load_d16 : SDNode<"AMDGPUISD::TBUFFER_LOAD_FORMAT_D16",
88                                 SDTbuffer_load,
89                                 [SDNPMayLoad, SDNPMemOperand, SDNPHasChain]>;
90
91 def SDTtbuffer_store : SDTypeProfile<0, 10,
92     [                     // vdata
93      SDTCisVT<1, v4i32>,  // rsrc
94      SDTCisVT<2, i32>,    // vindex(VGPR)
95      SDTCisVT<3, i32>,    // voffset(VGPR)
96      SDTCisVT<4, i32>,    // soffset(SGPR)
97      SDTCisVT<5, i32>,    // offset(imm)
98      SDTCisVT<6, i32>,    // dfmt(imm)
99      SDTCisVT<7, i32>,    // nfmt(imm)
100      SDTCisVT<8, i32>,    // glc(imm)
101      SDTCisVT<9, i32>     // slc(imm)
102     ]>;
103
104 def SItbuffer_store : SDNode<"AMDGPUISD::TBUFFER_STORE_FORMAT", SDTtbuffer_store,
105                              [SDNPMayStore, SDNPMemOperand, SDNPHasChain]>;
106 def SItbuffer_store_x3 : SDNode<"AMDGPUISD::TBUFFER_STORE_FORMAT_X3",
107                                 SDTtbuffer_store,
108                                 [SDNPMayStore, SDNPMemOperand, SDNPHasChain]>;
109 def SItbuffer_store_d16 : SDNode<"AMDGPUISD::TBUFFER_STORE_FORMAT_D16",
110                                 SDTtbuffer_store,
111                                 [SDNPMayStore, SDNPMemOperand, SDNPHasChain]>;
112
113 def SDTBufferLoad : SDTypeProfile<1, 5,
114     [                    // vdata
115      SDTCisVT<1, v4i32>, // rsrc
116      SDTCisVT<2, i32>,   // vindex
117      SDTCisVT<3, i32>,   // offset
118      SDTCisVT<4, i1>,    // glc
119      SDTCisVT<5, i1>]>;  // slc
120
121 def SIbuffer_load : SDNode <"AMDGPUISD::BUFFER_LOAD", SDTBufferLoad,
122                             [SDNPMemOperand, SDNPHasChain, SDNPMayLoad]>;
123 def SIbuffer_load_format : SDNode <"AMDGPUISD::BUFFER_LOAD_FORMAT", SDTBufferLoad,
124                             [SDNPMemOperand, SDNPHasChain, SDNPMayLoad]>;
125 def SIbuffer_load_format_d16 : SDNode <"AMDGPUISD::BUFFER_LOAD_FORMAT_D16",
126                                 SDTBufferLoad,
127                                 [SDNPMemOperand, SDNPHasChain, SDNPMayLoad]>;
128
129 def SDTBufferStore : SDTypeProfile<0, 6,
130     [                    // vdata
131      SDTCisVT<1, v4i32>, // rsrc
132      SDTCisVT<2, i32>,   // vindex
133      SDTCisVT<3, i32>,   // offset
134      SDTCisVT<4, i1>,    // glc
135      SDTCisVT<5, i1>]>;  // slc
136
137 def SIbuffer_store : SDNode <"AMDGPUISD::BUFFER_STORE", SDTBufferStore,
138                              [SDNPMayStore, SDNPMemOperand, SDNPHasChain]>;
139 def SIbuffer_store_format : SDNode <"AMDGPUISD::BUFFER_STORE_FORMAT",
140                             SDTBufferStore,
141                             [SDNPMayStore, SDNPMemOperand, SDNPHasChain]>;
142 def SIbuffer_store_format_d16 : SDNode <"AMDGPUISD::BUFFER_STORE_FORMAT_D16",
143                             SDTBufferStore,
144                             [SDNPMayStore, SDNPMemOperand, SDNPHasChain]>;
145
146 class SDBufferAtomic<string opcode> : SDNode <opcode,
147   SDTypeProfile<1, 5,
148       [SDTCisVT<0, i32>,   // dst
149        SDTCisVT<1, i32>,   // vdata
150        SDTCisVT<2, v4i32>, // rsrc
151        SDTCisVT<3, i32>,   // vindex
152        SDTCisVT<4, i32>,   // offset
153        SDTCisVT<5, i1>]>,  // slc
154   [SDNPMemOperand, SDNPHasChain, SDNPMayLoad, SDNPMayStore]
155 >;
156
157 def SIbuffer_atomic_swap : SDBufferAtomic <"AMDGPUISD::BUFFER_ATOMIC_SWAP">;
158 def SIbuffer_atomic_add : SDBufferAtomic <"AMDGPUISD::BUFFER_ATOMIC_ADD">;
159 def SIbuffer_atomic_sub : SDBufferAtomic <"AMDGPUISD::BUFFER_ATOMIC_SUB">;
160 def SIbuffer_atomic_smin : SDBufferAtomic <"AMDGPUISD::BUFFER_ATOMIC_SMIN">;
161 def SIbuffer_atomic_umin : SDBufferAtomic <"AMDGPUISD::BUFFER_ATOMIC_UMIN">;
162 def SIbuffer_atomic_smax : SDBufferAtomic <"AMDGPUISD::BUFFER_ATOMIC_SMAX">;
163 def SIbuffer_atomic_umax : SDBufferAtomic <"AMDGPUISD::BUFFER_ATOMIC_UMAX">;
164 def SIbuffer_atomic_and : SDBufferAtomic <"AMDGPUISD::BUFFER_ATOMIC_AND">;
165 def SIbuffer_atomic_or : SDBufferAtomic <"AMDGPUISD::BUFFER_ATOMIC_OR">;
166 def SIbuffer_atomic_xor : SDBufferAtomic <"AMDGPUISD::BUFFER_ATOMIC_XOR">;
167
168 def SIbuffer_atomic_cmpswap : SDNode <"AMDGPUISD::BUFFER_ATOMIC_CMPSWAP",
169   SDTypeProfile<1, 6,
170     [SDTCisVT<0, i32>,   // dst
171      SDTCisVT<1, i32>,   // src
172      SDTCisVT<2, i32>,   // cmp
173      SDTCisVT<3, v4i32>, // rsrc
174      SDTCisVT<4, i32>,   // vindex
175      SDTCisVT<5, i32>,   // offset
176      SDTCisVT<6, i1>]>,  // slc
177   [SDNPMemOperand, SDNPHasChain, SDNPMayLoad, SDNPMayStore]
178 >;
179
180 def SIpc_add_rel_offset : SDNode<"AMDGPUISD::PC_ADD_REL_OFFSET",
181   SDTypeProfile<1, 2, [SDTCisVT<0, iPTR>, SDTCisSameAs<0,1>, SDTCisSameAs<0,2>]>
182 >;
183
184 //===----------------------------------------------------------------------===//
185 // ValueType helpers
186 //===----------------------------------------------------------------------===//
187
188 // Returns 1 if the source arguments have modifiers, 0 if they do not.
189 // XXX - do f16 instructions?
190 class isFloatType<ValueType SrcVT> {
191   bit ret =
192     !if(!eq(SrcVT.Value, f16.Value), 1,
193     !if(!eq(SrcVT.Value, f32.Value), 1,
194     !if(!eq(SrcVT.Value, f64.Value), 1,
195     !if(!eq(SrcVT.Value, v2f16.Value), 1,
196     0))));
197 }
198
199 class isIntType<ValueType SrcVT> {
200   bit ret =
201     !if(!eq(SrcVT.Value, i16.Value), 1,
202     !if(!eq(SrcVT.Value, i32.Value), 1,
203     !if(!eq(SrcVT.Value, i64.Value), 1,
204     0)));
205 }
206
207 class isPackedType<ValueType SrcVT> {
208   bit ret =
209     !if(!eq(SrcVT.Value, v2i16.Value), 1,
210       !if(!eq(SrcVT.Value, v2f16.Value), 1, 0)
211     );
212 }
213
214 //===----------------------------------------------------------------------===//
215 // PatFrags for global memory operations
216 //===----------------------------------------------------------------------===//
217
218 defm atomic_inc_global : global_binary_atomic_op<SIatomic_inc>;
219 defm atomic_dec_global : global_binary_atomic_op<SIatomic_dec>;
220
221 def atomic_inc_local : local_binary_atomic_op<SIatomic_inc>;
222 def atomic_dec_local : local_binary_atomic_op<SIatomic_dec>;
223 def atomic_load_fadd_local : local_binary_atomic_op<SIatomic_fadd>;
224 def atomic_load_fmin_local : local_binary_atomic_op<SIatomic_fmin>;
225 def atomic_load_fmax_local : local_binary_atomic_op<SIatomic_fmax>;
226
227 //===----------------------------------------------------------------------===//
228 // SDNodes PatFrags for loads/stores with a glue input.
229 // This is for SDNodes and PatFrag for local loads and stores to
230 // enable s_mov_b32 m0, -1 to be glued to the memory instructions.
231 //
232 // These mirror the regular load/store PatFrags and rely on special
233 // processing during Select() to add the glued copy.
234 //
235 //===----------------------------------------------------------------------===//
236
237 def AMDGPUld_glue : SDNode <"ISD::LOAD", SDTLoad,
238   [SDNPHasChain, SDNPMayLoad, SDNPMemOperand, SDNPInGlue]
239 >;
240
241 def AMDGPUatomic_ld_glue : SDNode <"ISD::ATOMIC_LOAD", SDTAtomicLoad,
242   [SDNPHasChain, SDNPMayLoad, SDNPMemOperand, SDNPInGlue]
243 >;
244
245 def unindexedload_glue : PatFrag <(ops node:$ptr), (AMDGPUld_glue node:$ptr), [{
246   return cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
247 }]>;
248
249 def load_glue : PatFrag <(ops node:$ptr), (unindexedload_glue node:$ptr), [{
250   return cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
251 }]>;
252
253 def atomic_load_32_glue : PatFrag<(ops node:$ptr),
254   (AMDGPUatomic_ld_glue node:$ptr)> {
255   let IsAtomic = 1;
256   let MemoryVT = i32;
257 }
258
259 def atomic_load_64_glue : PatFrag<(ops node:$ptr),
260   (AMDGPUatomic_ld_glue node:$ptr)> {
261   let IsAtomic = 1;
262   let MemoryVT = i64;
263 }
264
265 def extload_glue : PatFrag<(ops node:$ptr), (load_glue node:$ptr), [{
266   return cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
267 }]>;
268
269 def sextload_glue : PatFrag<(ops node:$ptr), (unindexedload_glue node:$ptr), [{
270   return cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
271 }]>;
272
273 def zextload_glue : PatFrag<(ops node:$ptr), (unindexedload_glue node:$ptr), [{
274   return cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
275 }]>;
276
277 def az_extload_glue : AZExtLoadBase <unindexedload_glue>;
278
279 def az_extloadi8_glue : PatFrag<(ops node:$ptr), (az_extload_glue node:$ptr), [{
280   return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8;
281 }]>;
282
283 def az_extloadi16_glue : PatFrag<(ops node:$ptr), (az_extload_glue node:$ptr), [{
284   return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16;
285 }]>;
286
287 def sextloadi8_glue : PatFrag<(ops node:$ptr), (sextload_glue node:$ptr), [{
288   return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8;
289 }]>;
290
291 def sextloadi16_glue : PatFrag<(ops node:$ptr), (sextload_glue node:$ptr), [{
292   return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16;
293 }]>;
294
295 def load_glue_align8 : Aligned8Bytes <
296   (ops node:$ptr), (load_glue node:$ptr)
297 >;
298 def load_glue_align16 : Aligned16Bytes <
299   (ops node:$ptr), (load_glue node:$ptr)
300 >;
301
302
303 def load_local_m0 : LoadFrag<load_glue>, LocalAddress;
304 def sextloadi8_local_m0 : LoadFrag<sextloadi8_glue>, LocalAddress;
305 def sextloadi16_local_m0 : LoadFrag<sextloadi16_glue>, LocalAddress;
306 def az_extloadi8_local_m0 : LoadFrag<az_extloadi8_glue>, LocalAddress;
307 def az_extloadi16_local_m0 : LoadFrag<az_extloadi16_glue>, LocalAddress;
308 def load_align8_local_m0 : LoadFrag <load_glue_align8>, LocalAddress;
309 def load_align16_local_m0 : LoadFrag <load_glue_align16>, LocalAddress;
310 def atomic_load_32_local_m0 : LoadFrag<atomic_load_32_glue>, LocalAddress;
311 def atomic_load_64_local_m0 : LoadFrag<atomic_load_64_glue>, LocalAddress;
312
313
314 def AMDGPUst_glue : SDNode <"ISD::STORE", SDTStore,
315   [SDNPHasChain, SDNPMayStore, SDNPMemOperand, SDNPInGlue]
316 >;
317
318 def AMDGPUatomic_st_glue : SDNode <"ISD::ATOMIC_STORE", SDTAtomicStore,
319   [SDNPHasChain, SDNPMayStore, SDNPMemOperand, SDNPInGlue]
320 >;
321
322 def atomic_store_glue : PatFrag<(ops node:$ptr, node:$val),
323   (AMDGPUatomic_st_glue node:$ptr, node:$val)> {
324 }
325
326 def unindexedstore_glue : PatFrag<(ops node:$val, node:$ptr),
327                                    (AMDGPUst_glue node:$val, node:$ptr), [{
328   return cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
329 }]>;
330
331 def store_glue : PatFrag<(ops node:$val, node:$ptr),
332                       (unindexedstore_glue node:$val, node:$ptr), [{
333   return !cast<StoreSDNode>(N)->isTruncatingStore();
334 }]>;
335
336 def truncstore_glue : PatFrag<(ops node:$val, node:$ptr),
337   (unindexedstore_glue node:$val, node:$ptr), [{
338   return cast<StoreSDNode>(N)->isTruncatingStore();
339 }]>;
340
341 def truncstorei8_glue : PatFrag<(ops node:$val, node:$ptr),
342                            (truncstore_glue node:$val, node:$ptr), [{
343   return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i8;
344 }]>;
345
346 def truncstorei16_glue : PatFrag<(ops node:$val, node:$ptr),
347                            (truncstore_glue node:$val, node:$ptr), [{
348   return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i16;
349 }]>;
350
351 def store_glue_align8 : Aligned8Bytes <
352   (ops node:$value, node:$ptr), (store_glue node:$value, node:$ptr)
353 >;
354
355 def store_glue_align16 : Aligned16Bytes <
356   (ops node:$value, node:$ptr), (store_glue node:$value, node:$ptr)
357 >;
358
359 def store_local_m0 : StoreFrag<store_glue>, LocalAddress;
360 def truncstorei8_local_m0 : StoreFrag<truncstorei8_glue>, LocalAddress;
361 def truncstorei16_local_m0 : StoreFrag<truncstorei16_glue>, LocalAddress;
362 def atomic_store_local_m0 : StoreFrag<AMDGPUatomic_st_glue>, LocalAddress;
363
364 def store_align8_local_m0 : StoreFrag<store_glue_align8>, LocalAddress;
365 def store_align16_local_m0 : StoreFrag<store_glue_align16>, LocalAddress;
366
367 def si_setcc_uniform : PatFrag <
368   (ops node:$lhs, node:$rhs, node:$cond),
369   (setcc node:$lhs, node:$rhs, node:$cond), [{
370   for (SDNode *Use : N->uses()) {
371     if (Use->isMachineOpcode() || Use->getOpcode() != ISD::CopyToReg)
372       return false;
373
374     unsigned Reg = cast<RegisterSDNode>(Use->getOperand(1))->getReg();
375     if (Reg != AMDGPU::SCC)
376       return false;
377   }
378   return true;
379 }]>;
380
381 def lshr_rev : PatFrag <
382   (ops node:$src1, node:$src0),
383   (srl $src0, $src1)
384 >;
385
386 def ashr_rev : PatFrag <
387   (ops node:$src1, node:$src0),
388   (sra $src0, $src1)
389 >;
390
391 def lshl_rev : PatFrag <
392   (ops node:$src1, node:$src0),
393   (shl $src0, $src1)
394 >;
395
396 multiclass SIAtomicM0Glue2 <string op_name, bit is_amdgpu = 0,
397                             SDTypeProfile tc = SDTAtomic2> {
398
399   def _glue : SDNode <
400     !if(is_amdgpu, "AMDGPUISD", "ISD")#"::ATOMIC_"#op_name, tc,
401     [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand, SDNPInGlue]
402   >;
403
404   def _local_m0 : local_binary_atomic_op <!cast<SDNode>(NAME#"_glue")>;
405 }
406
407 defm atomic_load_add : SIAtomicM0Glue2 <"LOAD_ADD">;
408 defm atomic_load_sub : SIAtomicM0Glue2 <"LOAD_SUB">;
409 defm atomic_inc : SIAtomicM0Glue2 <"INC", 1>;
410 defm atomic_dec : SIAtomicM0Glue2 <"DEC", 1>;
411 defm atomic_load_and : SIAtomicM0Glue2 <"LOAD_AND">;
412 defm atomic_load_min : SIAtomicM0Glue2 <"LOAD_MIN">;
413 defm atomic_load_max : SIAtomicM0Glue2 <"LOAD_MAX">;
414 defm atomic_load_or : SIAtomicM0Glue2 <"LOAD_OR">;
415 defm atomic_load_xor : SIAtomicM0Glue2 <"LOAD_XOR">;
416 defm atomic_load_umin : SIAtomicM0Glue2 <"LOAD_UMIN">;
417 defm atomic_load_umax : SIAtomicM0Glue2 <"LOAD_UMAX">;
418 defm atomic_swap : SIAtomicM0Glue2 <"SWAP">;
419 defm atomic_load_fadd : SIAtomicM0Glue2 <"LOAD_FADD", 1, SDTAtomic2_f32>;
420 defm atomic_load_fmin : SIAtomicM0Glue2 <"LOAD_FMIN", 1, SDTAtomic2_f32>;
421 defm atomic_load_fmax : SIAtomicM0Glue2 <"LOAD_FMAX", 1, SDTAtomic2_f32>;
422
423 def atomic_cmp_swap_glue : SDNode <"ISD::ATOMIC_CMP_SWAP", SDTAtomic3,
424   [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand, SDNPInGlue]
425 >;
426
427 def atomic_cmp_swap_local_m0 : AtomicCmpSwapLocal<atomic_cmp_swap_glue>;
428
429
430 def as_i1imm : SDNodeXForm<imm, [{
431   return CurDAG->getTargetConstant(N->getZExtValue(), SDLoc(N), MVT::i1);
432 }]>;
433
434 def as_i8imm : SDNodeXForm<imm, [{
435   return CurDAG->getTargetConstant(N->getZExtValue(), SDLoc(N), MVT::i8);
436 }]>;
437
438 def as_i16imm : SDNodeXForm<imm, [{
439   return CurDAG->getTargetConstant(N->getSExtValue(), SDLoc(N), MVT::i16);
440 }]>;
441
442 def as_i32imm: SDNodeXForm<imm, [{
443   return CurDAG->getTargetConstant(N->getSExtValue(), SDLoc(N), MVT::i32);
444 }]>;
445
446 def as_i64imm: SDNodeXForm<imm, [{
447   return CurDAG->getTargetConstant(N->getSExtValue(), SDLoc(N), MVT::i64);
448 }]>;
449
450 def cond_as_i32imm: SDNodeXForm<cond, [{
451   return CurDAG->getTargetConstant(N->get(), SDLoc(N), MVT::i32);
452 }]>;
453
454 // Copied from the AArch64 backend:
455 def bitcast_fpimm_to_i32 : SDNodeXForm<fpimm, [{
456 return CurDAG->getTargetConstant(
457   N->getValueAPF().bitcastToAPInt().getZExtValue(), SDLoc(N), MVT::i32);
458 }]>;
459
460 def frameindex_to_targetframeindex : SDNodeXForm<frameindex, [{
461   auto FI = cast<FrameIndexSDNode>(N);
462   return CurDAG->getTargetFrameIndex(FI->getIndex(), MVT::i32);
463 }]>;
464
465 // Copied from the AArch64 backend:
466 def bitcast_fpimm_to_i64 : SDNodeXForm<fpimm, [{
467 return CurDAG->getTargetConstant(
468   N->getValueAPF().bitcastToAPInt().getZExtValue(), SDLoc(N), MVT::i64);
469 }]>;
470
471 class bitextract_imm<int bitnum> : SDNodeXForm<imm, [{
472   uint64_t Imm = N->getZExtValue();
473   unsigned Bit = (Imm >> }] # bitnum # [{ ) & 1;
474   return CurDAG->getTargetConstant(Bit, SDLoc(N), MVT::i1);
475 }]>;
476
477 def SIMM16bit : PatLeaf <(imm),
478   [{return isInt<16>(N->getSExtValue());}]
479 >;
480
481 class InlineImm <ValueType vt> : PatLeaf <(vt imm), [{
482   return isInlineImmediate(N);
483 }]>;
484
485 class InlineFPImm <ValueType vt> : PatLeaf <(vt fpimm), [{
486   return isInlineImmediate(N);
487 }]>;
488
489 class VGPRImm <dag frag> : PatLeaf<frag, [{
490   if (Subtarget->getGeneration() < AMDGPUSubtarget::SOUTHERN_ISLANDS) {
491     return false;
492   }
493   const SIRegisterInfo *SIRI =
494       static_cast<const SIRegisterInfo *>(Subtarget->getRegisterInfo());
495   unsigned Limit = 0;
496   for (SDNode::use_iterator U = N->use_begin(), E = SDNode::use_end();
497          Limit < 10 && U != E; ++U, ++Limit) {
498     const TargetRegisterClass *RC = getOperandRegClass(*U, U.getOperandNo());
499
500     // If the register class is unknown, it could be an unknown
501     // register class that needs to be an SGPR, e.g. an inline asm
502     // constraint
503     if (!RC || SIRI->isSGPRClass(RC))
504       return false;
505   }
506
507   return Limit < 10;
508 }]>;
509
510 def NegateImm : SDNodeXForm<imm, [{
511   return CurDAG->getConstant(-N->getSExtValue(), SDLoc(N), MVT::i32);
512 }]>;
513
514 // TODO: When FP inline imm values work?
515 def NegSubInlineConst32 : ImmLeaf<i32, [{
516   return Imm < -16 && Imm >= -64;
517 }], NegateImm>;
518
519 def NegSubInlineConst16 : ImmLeaf<i16, [{
520   return Imm < -16 && Imm >= -64;
521 }], NegateImm>;
522
523 def ShiftAmt32Imm : PatLeaf <(imm), [{
524   return N->getZExtValue() < 32;
525 }]>;
526
527 //===----------------------------------------------------------------------===//
528 // Custom Operands
529 //===----------------------------------------------------------------------===//
530
531 def SoppBrTarget : AsmOperandClass {
532   let Name = "SoppBrTarget";
533   let ParserMethod = "parseSOppBrTarget";
534 }
535
536 def sopp_brtarget : Operand<OtherVT> {
537   let EncoderMethod = "getSOPPBrEncoding";
538   let DecoderMethod = "decodeSoppBrTarget";
539   let OperandType = "OPERAND_PCREL";
540   let ParserMatchClass = SoppBrTarget;
541 }
542
543 def si_ga : Operand<iPTR>;
544
545 def InterpSlotMatchClass : AsmOperandClass {
546   let Name = "InterpSlot";
547   let PredicateMethod = "isInterpSlot";
548   let ParserMethod = "parseInterpSlot";
549   let RenderMethod = "addImmOperands";
550 }
551
552 def InterpSlot : Operand<i32> {
553   let PrintMethod = "printInterpSlot";
554   let ParserMatchClass = InterpSlotMatchClass;
555   let OperandType = "OPERAND_IMMEDIATE";
556 }
557
558 def AttrMatchClass : AsmOperandClass {
559   let Name = "Attr";
560   let PredicateMethod = "isInterpAttr";
561   let ParserMethod = "parseInterpAttr";
562   let RenderMethod = "addImmOperands";
563 }
564
565 // It appears to be necessary to create a separate operand for this to
566 // be able to parse attr<num> with no space.
567 def Attr : Operand<i32> {
568   let PrintMethod = "printInterpAttr";
569   let ParserMatchClass = AttrMatchClass;
570   let OperandType = "OPERAND_IMMEDIATE";
571 }
572
573 def AttrChanMatchClass : AsmOperandClass {
574   let Name = "AttrChan";
575   let PredicateMethod = "isAttrChan";
576   let RenderMethod = "addImmOperands";
577 }
578
579 def AttrChan : Operand<i32> {
580   let PrintMethod = "printInterpAttrChan";
581   let ParserMatchClass = AttrChanMatchClass;
582   let OperandType = "OPERAND_IMMEDIATE";
583 }
584
585 def SendMsgMatchClass : AsmOperandClass {
586   let Name = "SendMsg";
587   let PredicateMethod = "isSendMsg";
588   let ParserMethod = "parseSendMsgOp";
589   let RenderMethod = "addImmOperands";
590 }
591
592 def SwizzleMatchClass : AsmOperandClass {
593   let Name = "Swizzle";
594   let PredicateMethod = "isSwizzle";
595   let ParserMethod = "parseSwizzleOp";
596   let RenderMethod = "addImmOperands";
597   let IsOptional = 1;
598 }
599
600 def ExpTgtMatchClass : AsmOperandClass {
601   let Name = "ExpTgt";
602   let PredicateMethod = "isExpTgt";
603   let ParserMethod = "parseExpTgt";
604   let RenderMethod = "printExpTgt";
605 }
606
607 def SendMsgImm : Operand<i32> {
608   let PrintMethod = "printSendMsg";
609   let ParserMatchClass = SendMsgMatchClass;
610 }
611
612 def SwizzleImm : Operand<i16> {
613   let PrintMethod = "printSwizzle";
614   let ParserMatchClass = SwizzleMatchClass;
615 }
616
617 def SWaitMatchClass : AsmOperandClass {
618   let Name = "SWaitCnt";
619   let RenderMethod = "addImmOperands";
620   let ParserMethod = "parseSWaitCntOps";
621 }
622
623 def VReg32OrOffClass : AsmOperandClass {
624   let Name = "VReg32OrOff";
625   let ParserMethod = "parseVReg32OrOff";
626 }
627
628 def WAIT_FLAG : Operand <i32> {
629   let ParserMatchClass = SWaitMatchClass;
630   let PrintMethod = "printWaitFlag";
631 }
632
633 include "SIInstrFormats.td"
634 include "VIInstrFormats.td"
635
636 // ===----------------------------------------------------------------------===//
637 // ExpSrc* Special cases for exp src operands which are printed as
638 // "off" depending on en operand.
639 // ===----------------------------------------------------------------------===//
640
641 def ExpSrc0 : RegisterOperand<VGPR_32> {
642   let PrintMethod = "printExpSrc0";
643   let ParserMatchClass = VReg32OrOffClass;
644 }
645
646 def ExpSrc1 : RegisterOperand<VGPR_32> {
647   let PrintMethod = "printExpSrc1";
648   let ParserMatchClass = VReg32OrOffClass;
649 }
650
651 def ExpSrc2 : RegisterOperand<VGPR_32> {
652   let PrintMethod = "printExpSrc2";
653   let ParserMatchClass = VReg32OrOffClass;
654 }
655
656 def ExpSrc3 : RegisterOperand<VGPR_32> {
657   let PrintMethod = "printExpSrc3";
658   let ParserMatchClass = VReg32OrOffClass;
659 }
660
661 class SDWASrc<ValueType vt> : RegisterOperand<VS_32> {
662   let OperandNamespace = "AMDGPU";
663   string Type = !if(isFloatType<vt>.ret, "FP", "INT");
664   let OperandType = "OPERAND_REG_INLINE_C_"#Type#vt.Size;
665   let DecoderMethod = "decodeSDWASrc"#vt.Size;
666   let EncoderMethod = "getSDWASrcEncoding";
667 }
668
669 def SDWASrc_i32 : SDWASrc<i32>;
670 def SDWASrc_i16 : SDWASrc<i16>;
671 def SDWASrc_f32 : SDWASrc<f32>;
672 def SDWASrc_f16 : SDWASrc<f16>;
673
674 def SDWAVopcDst : VOPDstOperand<SReg_64> {
675   let OperandNamespace = "AMDGPU";
676   let OperandType = "OPERAND_SDWA_VOPC_DST";
677   let EncoderMethod = "getSDWAVopcDstEncoding";
678   let DecoderMethod = "decodeSDWAVopcDst";
679 }
680
681 class NamedMatchClass<string CName, bit Optional = 1> : AsmOperandClass {
682   let Name = "Imm"#CName;
683   let PredicateMethod = "is"#CName;
684   let ParserMethod = !if(Optional, "parseOptionalOperand", "parse"#CName);
685   let RenderMethod = "addImmOperands";
686   let IsOptional = Optional;
687   let DefaultMethod = !if(Optional, "default"#CName, ?);
688 }
689
690 class NamedOperandBit<string Name, AsmOperandClass MatchClass> : Operand<i1> {
691   let PrintMethod = "print"#Name;
692   let ParserMatchClass = MatchClass;
693 }
694
695 class NamedOperandU8<string Name, AsmOperandClass MatchClass> : Operand<i8> {
696   let PrintMethod = "print"#Name;
697   let ParserMatchClass = MatchClass;
698 }
699
700 class NamedOperandU12<string Name, AsmOperandClass MatchClass> : Operand<i16> {
701   let PrintMethod = "print"#Name;
702   let ParserMatchClass = MatchClass;
703 }
704
705 class NamedOperandU16<string Name, AsmOperandClass MatchClass> : Operand<i16> {
706   let PrintMethod = "print"#Name;
707   let ParserMatchClass = MatchClass;
708 }
709
710 class NamedOperandS13<string Name, AsmOperandClass MatchClass> : Operand<i16> {
711   let PrintMethod = "print"#Name;
712   let ParserMatchClass = MatchClass;
713 }
714
715 class NamedOperandU32<string Name, AsmOperandClass MatchClass> : Operand<i32> {
716   let PrintMethod = "print"#Name;
717   let ParserMatchClass = MatchClass;
718 }
719
720 class NamedOperandU32Default0<string Name, AsmOperandClass MatchClass> :
721   OperandWithDefaultOps<i32, (ops (i32 0))> {
722   let PrintMethod = "print"#Name;
723   let ParserMatchClass = MatchClass;
724 }
725
726 let OperandType = "OPERAND_IMMEDIATE" in {
727
728 def offen : NamedOperandBit<"Offen", NamedMatchClass<"Offen">>;
729 def idxen : NamedOperandBit<"Idxen", NamedMatchClass<"Idxen">>;
730 def addr64 : NamedOperandBit<"Addr64", NamedMatchClass<"Addr64">>;
731
732 def offset_u12 : NamedOperandU12<"Offset", NamedMatchClass<"OffsetU12">>;
733 def offset_s13 : NamedOperandS13<"OffsetS13", NamedMatchClass<"OffsetS13">>;
734 def offset : NamedOperandU16<"Offset", NamedMatchClass<"Offset">>;
735 def offset0 : NamedOperandU8<"Offset0", NamedMatchClass<"Offset0">>;
736 def offset1 : NamedOperandU8<"Offset1", NamedMatchClass<"Offset1">>;
737
738 def gds : NamedOperandBit<"GDS", NamedMatchClass<"GDS">>;
739
740 def omod : NamedOperandU32<"OModSI", NamedMatchClass<"OModSI">>;
741 def clampmod : NamedOperandBit<"ClampSI", NamedMatchClass<"ClampSI">>;
742 def highmod : NamedOperandBit<"High", NamedMatchClass<"High">>;
743
744 def GLC : NamedOperandBit<"GLC", NamedMatchClass<"GLC">>;
745 def SLC : NamedOperandBit<"SLC", NamedMatchClass<"SLC">>;
746 def TFE : NamedOperandBit<"TFE", NamedMatchClass<"TFE">>;
747 def UNorm : NamedOperandBit<"UNorm", NamedMatchClass<"UNorm">>;
748 def DA : NamedOperandBit<"DA", NamedMatchClass<"DA">>;
749 def R128 : NamedOperandBit<"R128", NamedMatchClass<"R128">>;
750 def D16 : NamedOperandBit<"D16", NamedMatchClass<"D16">>;
751 def LWE : NamedOperandBit<"LWE", NamedMatchClass<"LWE">>;
752 def exp_compr : NamedOperandBit<"ExpCompr", NamedMatchClass<"ExpCompr">>;
753 def exp_vm : NamedOperandBit<"ExpVM", NamedMatchClass<"ExpVM">>;
754
755 def DFMT : NamedOperandU8<"DFMT", NamedMatchClass<"DFMT">>;
756 def NFMT : NamedOperandU8<"NFMT", NamedMatchClass<"NFMT">>;
757
758 def DMask : NamedOperandU16<"DMask", NamedMatchClass<"DMask">>;
759
760 def dpp_ctrl : NamedOperandU32<"DPPCtrl", NamedMatchClass<"DPPCtrl", 0>>;
761 def row_mask : NamedOperandU32<"RowMask", NamedMatchClass<"RowMask">>;
762 def bank_mask : NamedOperandU32<"BankMask", NamedMatchClass<"BankMask">>;
763 def bound_ctrl : NamedOperandBit<"BoundCtrl", NamedMatchClass<"BoundCtrl">>;
764
765 def dst_sel : NamedOperandU32<"SDWADstSel", NamedMatchClass<"SDWADstSel">>;
766 def src0_sel : NamedOperandU32<"SDWASrc0Sel", NamedMatchClass<"SDWASrc0Sel">>;
767 def src1_sel : NamedOperandU32<"SDWASrc1Sel", NamedMatchClass<"SDWASrc1Sel">>;
768 def dst_unused : NamedOperandU32<"SDWADstUnused", NamedMatchClass<"SDWADstUnused">>;
769
770 def op_sel : NamedOperandU32Default0<"OpSel", NamedMatchClass<"OpSel">>;
771 def op_sel_hi : NamedOperandU32Default0<"OpSelHi", NamedMatchClass<"OpSelHi">>;
772 def neg_lo : NamedOperandU32Default0<"NegLo", NamedMatchClass<"NegLo">>;
773 def neg_hi : NamedOperandU32Default0<"NegHi", NamedMatchClass<"NegHi">>;
774
775 def hwreg : NamedOperandU16<"Hwreg", NamedMatchClass<"Hwreg", 0>>;
776
777 def exp_tgt : NamedOperandU8<"ExpTgt", NamedMatchClass<"ExpTgt", 0>> {
778
779 }
780
781 } // End OperandType = "OPERAND_IMMEDIATE"
782
783 class KImmMatchClass<int size> : AsmOperandClass {
784   let Name = "KImmFP"#size;
785   let PredicateMethod = "isKImmFP"#size;
786   let ParserMethod = "parseImm";
787   let RenderMethod = "addKImmFP"#size#"Operands";
788 }
789
790 class kimmOperand<ValueType vt> : Operand<vt> {
791   let OperandNamespace = "AMDGPU";
792   let OperandType = "OPERAND_KIMM"#vt.Size;
793   let PrintMethod = "printU"#vt.Size#"ImmOperand";
794   let ParserMatchClass = !cast<AsmOperandClass>("KImmFP"#vt.Size#"MatchClass");
795 }
796
797 // 32-bit VALU immediate operand that uses the constant bus.
798 def KImmFP32MatchClass : KImmMatchClass<32>;
799 def f32kimm : kimmOperand<i32>;
800
801 // 32-bit VALU immediate operand with a 16-bit value that uses the
802 // constant bus.
803 def KImmFP16MatchClass : KImmMatchClass<16>;
804 def f16kimm : kimmOperand<i16>;
805
806
807 def VOPDstS64 : VOPDstOperand <SReg_64>;
808
809 class FPInputModsMatchClass <int opSize> : AsmOperandClass {
810   let Name = "RegOrImmWithFP"#opSize#"InputMods";
811   let ParserMethod = "parseRegOrImmWithFPInputMods";
812   let PredicateMethod = "isRegOrImmWithFP"#opSize#"InputMods";
813 }
814
815 def FP16InputModsMatchClass : FPInputModsMatchClass<16>;
816 def FP32InputModsMatchClass : FPInputModsMatchClass<32>;
817 def FP64InputModsMatchClass : FPInputModsMatchClass<64>;
818
819 class InputMods <AsmOperandClass matchClass> : Operand <i32> {
820   let OperandNamespace = "AMDGPU";
821   let OperandType = "OPERAND_INPUT_MODS";
822   let ParserMatchClass = matchClass;
823 }
824
825 class FPInputMods <FPInputModsMatchClass matchClass> : InputMods <matchClass> {
826   let PrintMethod = "printOperandAndFPInputMods";
827 }
828
829 def FP16InputMods : FPInputMods<FP16InputModsMatchClass>;
830 def FP32InputMods : FPInputMods<FP32InputModsMatchClass>;
831 def FP64InputMods : FPInputMods<FP64InputModsMatchClass>;
832
833 class IntInputModsMatchClass <int opSize> : AsmOperandClass {
834   let Name = "RegOrImmWithInt"#opSize#"InputMods";
835   let ParserMethod = "parseRegOrImmWithIntInputMods";
836   let PredicateMethod = "isRegOrImmWithInt"#opSize#"InputMods";
837 }
838 def Int32InputModsMatchClass : IntInputModsMatchClass<32>;
839 def Int64InputModsMatchClass : IntInputModsMatchClass<64>;
840
841 class IntInputMods <IntInputModsMatchClass matchClass> : InputMods <matchClass> {
842   let PrintMethod = "printOperandAndIntInputMods";
843 }
844 def Int32InputMods : IntInputMods<Int32InputModsMatchClass>;
845 def Int64InputMods : IntInputMods<Int64InputModsMatchClass>;
846
847 class OpSelModsMatchClass : AsmOperandClass {
848   let Name = "OpSelMods";
849   let ParserMethod = "parseRegOrImm";
850   let PredicateMethod = "isRegOrImm";
851 }
852
853 def IntOpSelModsMatchClass : OpSelModsMatchClass;
854 def IntOpSelMods : InputMods<IntOpSelModsMatchClass>;
855
856 class FPSDWAInputModsMatchClass <int opSize> : AsmOperandClass {
857   let Name = "SDWAWithFP"#opSize#"InputMods";
858   let ParserMethod = "parseRegOrImmWithFPInputMods";
859   let PredicateMethod = "isSDWAFP"#opSize#"Operand";
860 }
861
862 def FP16SDWAInputModsMatchClass : FPSDWAInputModsMatchClass<16>;
863 def FP32SDWAInputModsMatchClass : FPSDWAInputModsMatchClass<32>;
864
865 class FPSDWAInputMods <FPSDWAInputModsMatchClass matchClass> :
866   InputMods <matchClass> {
867   let PrintMethod = "printOperandAndFPInputMods";
868 }
869
870 def FP16SDWAInputMods : FPSDWAInputMods<FP16SDWAInputModsMatchClass>;
871 def FP32SDWAInputMods : FPSDWAInputMods<FP32SDWAInputModsMatchClass>;
872
873 def FPVRegInputModsMatchClass : AsmOperandClass {
874   let Name = "VRegWithFPInputMods";
875   let ParserMethod = "parseRegWithFPInputMods";
876   let PredicateMethod = "isVReg";
877 }
878
879 def FPVRegInputMods : InputMods <FPVRegInputModsMatchClass> {
880   let PrintMethod = "printOperandAndFPInputMods";
881 }
882
883 class IntSDWAInputModsMatchClass <int opSize> : AsmOperandClass {
884   let Name = "SDWAWithInt"#opSize#"InputMods";
885   let ParserMethod = "parseRegOrImmWithIntInputMods";
886   let PredicateMethod = "isSDWAInt"#opSize#"Operand";
887 }
888
889 def Int16SDWAInputModsMatchClass : IntSDWAInputModsMatchClass<16>;
890 def Int32SDWAInputModsMatchClass : IntSDWAInputModsMatchClass<32>;
891
892 class IntSDWAInputMods <IntSDWAInputModsMatchClass matchClass> :
893   InputMods <matchClass> {
894   let PrintMethod = "printOperandAndIntInputMods";
895 }
896
897 def Int16SDWAInputMods : IntSDWAInputMods<Int16SDWAInputModsMatchClass>;
898 def Int32SDWAInputMods : IntSDWAInputMods<Int32SDWAInputModsMatchClass>;
899
900 def IntVRegInputModsMatchClass : AsmOperandClass {
901   let Name = "VRegWithIntInputMods";
902   let ParserMethod = "parseRegWithIntInputMods";
903   let PredicateMethod = "isVReg";
904 }
905
906 def IntVRegInputMods : InputMods <IntVRegInputModsMatchClass> {
907   let PrintMethod = "printOperandAndIntInputMods";
908 }
909
910 class PackedFPInputModsMatchClass <int opSize> : AsmOperandClass {
911   let Name = "PackedFP"#opSize#"InputMods";
912   let ParserMethod = "parseRegOrImm";
913   let PredicateMethod = "isRegOrImm";
914 //  let PredicateMethod = "isPackedFP"#opSize#"InputMods";
915 }
916
917 class PackedIntInputModsMatchClass <int opSize> : AsmOperandClass {
918   let Name = "PackedInt"#opSize#"InputMods";
919   let ParserMethod = "parseRegOrImm";
920   let PredicateMethod = "isRegOrImm";
921 //  let PredicateMethod = "isPackedInt"#opSize#"InputMods";
922 }
923
924 def PackedF16InputModsMatchClass : PackedFPInputModsMatchClass<16>;
925 def PackedI16InputModsMatchClass : PackedIntInputModsMatchClass<16>;
926
927 class PackedFPInputMods <PackedFPInputModsMatchClass matchClass> : InputMods <matchClass> {
928 //  let PrintMethod = "printPackedFPInputMods";
929 }
930
931 class PackedIntInputMods <PackedIntInputModsMatchClass matchClass> : InputMods <matchClass> {
932   //let PrintMethod = "printPackedIntInputMods";
933 }
934
935 def PackedF16InputMods : PackedFPInputMods<PackedF16InputModsMatchClass>;
936 def PackedI16InputMods : PackedIntInputMods<PackedI16InputModsMatchClass>;
937
938 //===----------------------------------------------------------------------===//
939 // Complex patterns
940 //===----------------------------------------------------------------------===//
941
942 def DS1Addr1Offset : ComplexPattern<i32, 2, "SelectDS1Addr1Offset">;
943 def DS64Bit4ByteAligned : ComplexPattern<i32, 3, "SelectDS64Bit4ByteAligned">;
944
945 def MOVRELOffset : ComplexPattern<i32, 2, "SelectMOVRELOffset">;
946
947 def VOP3Mods0 : ComplexPattern<untyped, 4, "SelectVOP3Mods0">;
948 def VOP3Mods0Clamp : ComplexPattern<untyped, 3, "SelectVOP3Mods0Clamp">;
949 def VOP3Mods0Clamp0OMod : ComplexPattern<untyped, 4, "SelectVOP3Mods0Clamp0OMod">;
950 def VOP3Mods  : ComplexPattern<untyped, 2, "SelectVOP3Mods">;
951 def VOP3NoMods : ComplexPattern<untyped, 1, "SelectVOP3NoMods">;
952 // VOP3Mods, but the input source is known to never be NaN.
953 def VOP3Mods_nnan : ComplexPattern<fAny, 2, "SelectVOP3Mods_NNaN">;
954
955 def VOP3OMods : ComplexPattern<untyped, 3, "SelectVOP3OMods">;
956
957 def VOP3PMods  : ComplexPattern<untyped, 2, "SelectVOP3PMods">;
958 def VOP3PMods0 : ComplexPattern<untyped, 3, "SelectVOP3PMods0">;
959
960 def VOP3OpSel  : ComplexPattern<untyped, 2, "SelectVOP3OpSel">;
961 def VOP3OpSel0 : ComplexPattern<untyped, 3, "SelectVOP3OpSel0">;
962
963 def VOP3OpSelMods  : ComplexPattern<untyped, 2, "SelectVOP3OpSelMods">;
964 def VOP3OpSelMods0 : ComplexPattern<untyped, 3, "SelectVOP3OpSelMods0">;
965
966 def VOP3PMadMixMods  : ComplexPattern<untyped, 2, "SelectVOP3PMadMixMods">;
967
968
969 def Hi16Elt  : ComplexPattern<untyped, 1, "SelectHi16Elt">;
970
971 //===----------------------------------------------------------------------===//
972 // SI assembler operands
973 //===----------------------------------------------------------------------===//
974
975 def SIOperand {
976   int ZERO = 0x80;
977   int VCC = 0x6A;
978   int FLAT_SCR = 0x68;
979 }
980
981 // This should be kept in sync with SISrcMods enum
982 def SRCMODS {
983   int NONE = 0;
984   int NEG = 1;
985   int ABS = 2;
986   int NEG_ABS = 3;
987
988   int NEG_HI = ABS;
989   int OP_SEL_0 = 4;
990   int OP_SEL_1 = 8;
991   int DST_OP_SEL = 8;
992 }
993
994 def DSTCLAMP {
995   int NONE = 0;
996   int ENABLE = 1;
997 }
998
999 def DSTOMOD {
1000   int NONE = 0;
1001 }
1002
1003 def TRAPID{
1004   int LLVM_TRAP = 2;
1005   int LLVM_DEBUG_TRAP = 3;
1006 }
1007
1008 //===----------------------------------------------------------------------===//
1009 //
1010 // SI Instruction multiclass helpers.
1011 //
1012 // Instructions with _32 take 32-bit operands.
1013 // Instructions with _64 take 64-bit operands.
1014 //
1015 // VOP_* instructions can use either a 32-bit or 64-bit encoding.  The 32-bit
1016 // encoding is the standard encoding, but instruction that make use of
1017 // any of the instruction modifiers must use the 64-bit encoding.
1018 //
1019 // Instructions with _e32 use the 32-bit encoding.
1020 // Instructions with _e64 use the 64-bit encoding.
1021 //
1022 //===----------------------------------------------------------------------===//
1023
1024 class SIMCInstr <string pseudo, int subtarget> {
1025   string PseudoInstr = pseudo;
1026   int Subtarget = subtarget;
1027 }
1028
1029 //===----------------------------------------------------------------------===//
1030 // EXP classes
1031 //===----------------------------------------------------------------------===//
1032
1033 class EXP_Helper<bit done, SDPatternOperator node = null_frag> : EXPCommon<
1034   (outs),
1035   (ins exp_tgt:$tgt,
1036        ExpSrc0:$src0, ExpSrc1:$src1, ExpSrc2:$src2, ExpSrc3:$src3,
1037        exp_vm:$vm, exp_compr:$compr, i8imm:$en),
1038   "exp$tgt $src0, $src1, $src2, $src3"#!if(done, " done", "")#"$compr$vm",
1039   [(node (i8 timm:$tgt), (i8 timm:$en),
1040          f32:$src0, f32:$src1, f32:$src2, f32:$src3,
1041          (i1 timm:$compr), (i1 timm:$vm))]> {
1042   let AsmMatchConverter = "cvtExp";
1043 }
1044
1045 // Split EXP instruction into EXP and EXP_DONE so we can set
1046 // mayLoad for done=1.
1047 multiclass EXP_m<bit done, SDPatternOperator node> {
1048   let mayLoad = done, DisableWQM = 1 in {
1049     let isPseudo = 1, isCodeGenOnly = 1 in {
1050       def "" : EXP_Helper<done, node>,
1051                SIMCInstr <"exp"#!if(done, "_done", ""), SIEncodingFamily.NONE>;
1052     }
1053
1054     let done = done in {
1055       def _si : EXP_Helper<done>,
1056                 SIMCInstr <"exp"#!if(done, "_done", ""), SIEncodingFamily.SI>,
1057                 EXPe {
1058         let AssemblerPredicates = [isSICI];
1059         let DecoderNamespace = "SICI";
1060         let DisableDecoder = DisableSIDecoder;
1061       }
1062
1063       def _vi : EXP_Helper<done>,
1064                 SIMCInstr <"exp"#!if(done, "_done", ""), SIEncodingFamily.VI>,
1065                 EXPe_vi {
1066         let AssemblerPredicates = [isVI];
1067         let DecoderNamespace = "VI";
1068         let DisableDecoder = DisableVIDecoder;
1069       }
1070     }
1071   }
1072 }
1073
1074 //===----------------------------------------------------------------------===//
1075 // Vector ALU classes
1076 //===----------------------------------------------------------------------===//
1077
1078 class getNumSrcArgs<ValueType Src0, ValueType Src1, ValueType Src2> {
1079   int ret =
1080     !if (!eq(Src0.Value, untyped.Value),      0,
1081       !if (!eq(Src1.Value, untyped.Value),    1,   // VOP1
1082          !if (!eq(Src2.Value, untyped.Value), 2,   // VOP2
1083                                               3))); // VOP3
1084 }
1085
1086 // Returns the register class to use for the destination of VOP[123C]
1087 // instructions for the given VT.
1088 class getVALUDstForVT<ValueType VT> {
1089   RegisterOperand ret = !if(!eq(VT.Size, 32), VOPDstOperand<VGPR_32>,
1090                           !if(!eq(VT.Size, 128), VOPDstOperand<VReg_128>,
1091                             !if(!eq(VT.Size, 64), VOPDstOperand<VReg_64>,
1092                               !if(!eq(VT.Size, 16), VOPDstOperand<VGPR_32>,
1093                               VOPDstOperand<SReg_64>)))); // else VT == i1
1094 }
1095
1096 // Returns the register class to use for the destination of VOP[12C]
1097 // instructions with SDWA extension
1098 class getSDWADstForVT<ValueType VT> {
1099   RegisterOperand ret = !if(!eq(VT.Size, 1),
1100                             SDWAVopcDst, // VOPC
1101                             VOPDstOperand<VGPR_32>); // VOP1/2 32-bit dst
1102 }
1103
1104 // Returns the register class to use for source 0 of VOP[12C]
1105 // instructions for the given VT.
1106 class getVOPSrc0ForVT<ValueType VT> {
1107   bit isFP = !if(!eq(VT.Value, f16.Value), 1,
1108              !if(!eq(VT.Value, v2f16.Value), 1,
1109              !if(!eq(VT.Value, f32.Value), 1,
1110              !if(!eq(VT.Value, f64.Value), 1,
1111              0))));
1112
1113   RegisterOperand ret =
1114     !if(isFP,
1115       !if(!eq(VT.Size, 64),
1116          VSrc_f64,
1117          !if(!eq(VT.Value, f16.Value),
1118             VSrc_f16,
1119             !if(!eq(VT.Value, v2f16.Value),
1120                VCSrc_v2f16,
1121                VSrc_f32
1122             )
1123          )
1124        ),
1125        !if(!eq(VT.Size, 64),
1126           VSrc_b64,
1127           !if(!eq(VT.Value, i16.Value),
1128              VSrc_b16,
1129              !if(!eq(VT.Value, v2i16.Value),
1130                 VCSrc_v2b16,
1131                 VSrc_b32
1132              )
1133           )
1134        )
1135     );
1136 }
1137
1138 // Returns the vreg register class to use for source operand given VT
1139 class getVregSrcForVT<ValueType VT> {
1140   RegisterClass ret = !if(!eq(VT.Size, 128), VReg_128,
1141                         !if(!eq(VT.Size, 64), VReg_64, VGPR_32));
1142 }
1143
1144 class getSDWASrcForVT <ValueType VT> {
1145   bit isFP = !if(!eq(VT.Value, f16.Value), 1,
1146              !if(!eq(VT.Value, f32.Value), 1,
1147              0));
1148   RegisterOperand retFlt = !if(!eq(VT.Size, 16), SDWASrc_f16, SDWASrc_f32);
1149   RegisterOperand retInt = !if(!eq(VT.Size, 16), SDWASrc_i16, SDWASrc_i32);
1150   RegisterOperand ret = !if(isFP, retFlt, retInt);
1151 }
1152
1153 // Returns the register class to use for sources of VOP3 instructions for the
1154 // given VT.
1155 class getVOP3SrcForVT<ValueType VT> {
1156   bit isFP = !if(!eq(VT.Value, f16.Value), 1,
1157              !if(!eq(VT.Value, v2f16.Value), 1,
1158              !if(!eq(VT.Value, f32.Value), 1,
1159              !if(!eq(VT.Value, f64.Value), 1,
1160              0))));
1161   RegisterOperand ret =
1162   !if(!eq(VT.Size, 128),
1163      VSrc_128,
1164      !if(!eq(VT.Size, 64),
1165         !if(isFP,
1166            VCSrc_f64,
1167            VCSrc_b64),
1168         !if(!eq(VT.Value, i1.Value),
1169            SCSrc_i1,
1170            !if(isFP,
1171               !if(!eq(VT.Value, f16.Value),
1172                  VCSrc_f16,
1173                  !if(!eq(VT.Value, v2f16.Value),
1174                     VCSrc_v2f16,
1175                     VCSrc_f32
1176                  )
1177               ),
1178               !if(!eq(VT.Value, i16.Value),
1179                  VCSrc_b16,
1180                  !if(!eq(VT.Value, v2i16.Value),
1181                     VCSrc_v2b16,
1182                     VCSrc_b32
1183                  )
1184               )
1185            )
1186         )
1187      )
1188   );
1189 }
1190
1191 // Float or packed int
1192 class isModifierType<ValueType SrcVT> {
1193   bit ret =
1194     !if(!eq(SrcVT.Value, f16.Value), 1,
1195     !if(!eq(SrcVT.Value, f32.Value), 1,
1196     !if(!eq(SrcVT.Value, f64.Value), 1,
1197     !if(!eq(SrcVT.Value, v2f16.Value), 1,
1198     !if(!eq(SrcVT.Value, v2i16.Value), 1,
1199     0)))));
1200 }
1201
1202 // Return type of input modifiers operand for specified input operand
1203 class getSrcMod <ValueType VT> {
1204   bit isFP = !if(!eq(VT.Value, f16.Value), 1,
1205                !if(!eq(VT.Value, f32.Value), 1,
1206                !if(!eq(VT.Value, f64.Value), 1,
1207                0)));
1208   bit isPacked = isPackedType<VT>.ret;
1209   Operand ret =  !if(!eq(VT.Size, 64),
1210                      !if(isFP, FP64InputMods, Int64InputMods),
1211                        !if(isFP,
1212                          !if(!eq(VT.Value, f16.Value),
1213                             FP16InputMods,
1214                             FP32InputMods
1215                           ),
1216                          Int32InputMods)
1217                      );
1218 }
1219
1220 class getOpSelMod <ValueType VT> {
1221   Operand ret = !if(!eq(VT.Value, f16.Value), FP16InputMods, IntOpSelMods);
1222 }
1223
1224 // Return type of input modifiers operand specified input operand for DPP
1225 class getSrcModExt <ValueType VT> {
1226     bit isFP = !if(!eq(VT.Value, f16.Value), 1,
1227                !if(!eq(VT.Value, f32.Value), 1,
1228                !if(!eq(VT.Value, f64.Value), 1,
1229                0)));
1230   Operand ret = !if(isFP, FPVRegInputMods, IntVRegInputMods);
1231 }
1232
1233 // Return type of input modifiers operand specified input operand for SDWA
1234 class getSrcModSDWA <ValueType VT> {
1235   Operand ret = !if(!eq(VT.Value, f16.Value), FP16SDWAInputMods,
1236                 !if(!eq(VT.Value, f32.Value), FP32SDWAInputMods,
1237                 !if(!eq(VT.Value, i16.Value), Int16SDWAInputMods,
1238                 Int32SDWAInputMods)));
1239 }
1240
1241 // Returns the input arguments for VOP[12C] instructions for the given SrcVT.
1242 class getIns32 <RegisterOperand Src0RC, RegisterClass Src1RC, int NumSrcArgs> {
1243   dag ret = !if(!eq(NumSrcArgs, 1), (ins Src0RC:$src0),               // VOP1
1244             !if(!eq(NumSrcArgs, 2), (ins Src0RC:$src0, Src1RC:$src1), // VOP2
1245                                     (ins)));
1246 }
1247
1248 // Returns the input arguments for VOP3 instructions for the given SrcVT.
1249 class getIns64 <RegisterOperand Src0RC, RegisterOperand Src1RC,
1250                 RegisterOperand Src2RC, int NumSrcArgs,
1251                 bit HasIntClamp, bit HasModifiers, bit HasOMod,
1252                 Operand Src0Mod, Operand Src1Mod, Operand Src2Mod> {
1253
1254   dag ret =
1255     !if (!eq(NumSrcArgs, 0),
1256       // VOP1 without input operands (V_NOP, V_CLREXCP)
1257       (ins),
1258       /* else */
1259     !if (!eq(NumSrcArgs, 1),
1260       !if (!eq(HasModifiers, 1),
1261         // VOP1 with modifiers
1262         (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1263              clampmod:$clamp, omod:$omod)
1264       /* else */,
1265         // VOP1 without modifiers
1266         !if (!eq(HasIntClamp, 1),
1267           (ins Src0RC:$src0, clampmod:$clamp),
1268           (ins Src0RC:$src0))
1269       /* endif */ ),
1270     !if (!eq(NumSrcArgs, 2),
1271       !if (!eq(HasModifiers, 1),
1272         // VOP 2 with modifiers
1273         !if( !eq(HasOMod, 1),
1274           (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1275                Src1Mod:$src1_modifiers, Src1RC:$src1,
1276                clampmod:$clamp, omod:$omod),
1277            (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1278                Src1Mod:$src1_modifiers, Src1RC:$src1,
1279                clampmod:$clamp))
1280       /* else */,
1281         // VOP2 without modifiers
1282         !if (!eq(HasIntClamp, 1),
1283           (ins Src0RC:$src0, Src1RC:$src1, clampmod:$clamp),
1284           (ins Src0RC:$src0, Src1RC:$src1))
1285
1286       /* endif */ )
1287     /* NumSrcArgs == 3 */,
1288       !if (!eq(HasModifiers, 1),
1289         // VOP3 with modifiers
1290         !if (!eq(HasOMod, 1),
1291           (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1292                Src1Mod:$src1_modifiers, Src1RC:$src1,
1293                Src2Mod:$src2_modifiers, Src2RC:$src2,
1294                clampmod:$clamp, omod:$omod),
1295           (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1296                Src1Mod:$src1_modifiers, Src1RC:$src1,
1297                Src2Mod:$src2_modifiers, Src2RC:$src2,
1298                clampmod:$clamp))
1299       /* else */,
1300         // VOP3 without modifiers
1301         !if (!eq(HasIntClamp, 1),
1302           (ins Src0RC:$src0, Src1RC:$src1, Src2RC:$src2, clampmod:$clamp),
1303           (ins Src0RC:$src0, Src1RC:$src1, Src2RC:$src2))
1304       /* endif */ ))));
1305 }
1306
1307 /// XXX - src1 may only allow VGPRs?
1308
1309 // The modifiers (except clamp) are dummy operands for the benefit of
1310 // printing and parsing. They defer their values to looking at the
1311 // srcN_modifiers for what to print.
1312 class getInsVOP3P <RegisterOperand Src0RC, RegisterOperand Src1RC,
1313                    RegisterOperand Src2RC, int NumSrcArgs,
1314                    bit HasClamp,
1315                    Operand Src0Mod, Operand Src1Mod, Operand Src2Mod> {
1316   dag ret = !if (!eq(NumSrcArgs, 2),
1317     !if (HasClamp,
1318       (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1319            Src1Mod:$src1_modifiers, Src1RC:$src1,
1320            clampmod:$clamp,
1321            op_sel:$op_sel, op_sel_hi:$op_sel_hi,
1322            neg_lo:$neg_lo, neg_hi:$neg_hi),
1323       (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1324            Src1Mod:$src1_modifiers, Src1RC:$src1,
1325            op_sel:$op_sel, op_sel_hi:$op_sel_hi,
1326            neg_lo:$neg_lo, neg_hi:$neg_hi)),
1327     // else NumSrcArgs == 3
1328     !if (HasClamp,
1329       (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1330            Src1Mod:$src1_modifiers, Src1RC:$src1,
1331            Src2Mod:$src2_modifiers, Src2RC:$src2,
1332            clampmod:$clamp,
1333            op_sel:$op_sel, op_sel_hi:$op_sel_hi,
1334            neg_lo:$neg_lo, neg_hi:$neg_hi),
1335       (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1336            Src1Mod:$src1_modifiers, Src1RC:$src1,
1337            Src2Mod:$src2_modifiers, Src2RC:$src2,
1338            op_sel:$op_sel, op_sel_hi:$op_sel_hi,
1339            neg_lo:$neg_lo, neg_hi:$neg_hi))
1340   );
1341 }
1342
1343 class getInsVOP3OpSel <RegisterOperand Src0RC,
1344                        RegisterOperand Src1RC,
1345                        RegisterOperand Src2RC,
1346                        int NumSrcArgs,
1347                        bit HasClamp,
1348                        Operand Src0Mod,
1349                        Operand Src1Mod,
1350                        Operand Src2Mod> {
1351   dag ret = !if (!eq(NumSrcArgs, 2),
1352     !if (HasClamp,
1353       (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1354            Src1Mod:$src1_modifiers, Src1RC:$src1,
1355            clampmod:$clamp,
1356            op_sel:$op_sel),
1357       (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1358            Src1Mod:$src1_modifiers, Src1RC:$src1,
1359            op_sel:$op_sel)),
1360     // else NumSrcArgs == 3
1361     !if (HasClamp,
1362       (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1363            Src1Mod:$src1_modifiers, Src1RC:$src1,
1364            Src2Mod:$src2_modifiers, Src2RC:$src2,
1365            clampmod:$clamp,
1366            op_sel:$op_sel),
1367       (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1368            Src1Mod:$src1_modifiers, Src1RC:$src1,
1369            Src2Mod:$src2_modifiers, Src2RC:$src2,
1370            op_sel:$op_sel))
1371   );
1372 }
1373
1374 class getInsDPP <RegisterOperand DstRC, RegisterClass Src0RC, RegisterClass Src1RC,
1375                  int NumSrcArgs, bit HasModifiers,
1376                  Operand Src0Mod, Operand Src1Mod> {
1377
1378   dag ret = !if (!eq(NumSrcArgs, 0),
1379                 // VOP1 without input operands (V_NOP)
1380                 (ins dpp_ctrl:$dpp_ctrl, row_mask:$row_mask,
1381                      bank_mask:$bank_mask, bound_ctrl:$bound_ctrl),
1382             !if (!eq(NumSrcArgs, 1),
1383               !if (!eq(HasModifiers, 1),
1384                 // VOP1_DPP with modifiers
1385                 (ins DstRC:$old, Src0Mod:$src0_modifiers,
1386                      Src0RC:$src0, dpp_ctrl:$dpp_ctrl, row_mask:$row_mask,
1387                      bank_mask:$bank_mask, bound_ctrl:$bound_ctrl)
1388               /* else */,
1389                 // VOP1_DPP without modifiers
1390                 (ins DstRC:$old, Src0RC:$src0,
1391                      dpp_ctrl:$dpp_ctrl, row_mask:$row_mask,
1392                      bank_mask:$bank_mask, bound_ctrl:$bound_ctrl)
1393               /* endif */)
1394               /* NumSrcArgs == 2 */,
1395               !if (!eq(HasModifiers, 1),
1396                 // VOP2_DPP with modifiers
1397                 (ins DstRC:$old,
1398                      Src0Mod:$src0_modifiers, Src0RC:$src0,
1399                      Src1Mod:$src1_modifiers, Src1RC:$src1,
1400                      dpp_ctrl:$dpp_ctrl, row_mask:$row_mask,
1401                      bank_mask:$bank_mask, bound_ctrl:$bound_ctrl)
1402               /* else */,
1403                 // VOP2_DPP without modifiers
1404                 (ins DstRC:$old,
1405                      Src0RC:$src0, Src1RC:$src1, dpp_ctrl:$dpp_ctrl,
1406                      row_mask:$row_mask, bank_mask:$bank_mask,
1407                      bound_ctrl:$bound_ctrl)
1408              /* endif */)));
1409 }
1410
1411
1412
1413 // Ins for SDWA
1414 class getInsSDWA <RegisterOperand Src0RC, RegisterOperand Src1RC, int NumSrcArgs,
1415                   bit HasSDWAOMod, Operand Src0Mod, Operand Src1Mod,
1416                   ValueType DstVT> {
1417
1418   dag ret = !if(!eq(NumSrcArgs, 0),
1419                // VOP1 without input operands (V_NOP)
1420                (ins),
1421             !if(!eq(NumSrcArgs, 1),
1422                // VOP1
1423                !if(!eq(HasSDWAOMod, 0),
1424                   // VOP1_SDWA without omod
1425                   (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1426                        clampmod:$clamp,
1427                        dst_sel:$dst_sel, dst_unused:$dst_unused,
1428                        src0_sel:$src0_sel),
1429                   // VOP1_SDWA with omod
1430                   (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1431                        clampmod:$clamp, omod:$omod,
1432                        dst_sel:$dst_sel, dst_unused:$dst_unused,
1433                        src0_sel:$src0_sel)),
1434             !if(!eq(NumSrcArgs, 2),
1435                !if(!eq(DstVT.Size, 1),
1436                   // VOPC_SDWA
1437                   (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1438                        Src1Mod:$src1_modifiers, Src1RC:$src1,
1439                        clampmod:$clamp, src0_sel:$src0_sel, src1_sel:$src1_sel),
1440                   // VOP2_SDWA
1441                   !if(!eq(HasSDWAOMod, 0),
1442                      // VOP2_SDWA without omod
1443                      (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1444                           Src1Mod:$src1_modifiers, Src1RC:$src1,
1445                           clampmod:$clamp,
1446                           dst_sel:$dst_sel, dst_unused:$dst_unused,
1447                           src0_sel:$src0_sel, src1_sel:$src1_sel),
1448                      // VOP2_SDWA with omod
1449                      (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1450                           Src1Mod:$src1_modifiers, Src1RC:$src1,
1451                           clampmod:$clamp, omod:$omod,
1452                           dst_sel:$dst_sel, dst_unused:$dst_unused,
1453                           src0_sel:$src0_sel, src1_sel:$src1_sel))),
1454             (ins)/* endif */)));
1455 }
1456
1457 // Outs for DPP and SDWA
1458 class getOutsExt <bit HasDst, ValueType DstVT, RegisterOperand DstRCExt> {
1459   dag ret = !if(HasDst,
1460                 !if(!eq(DstVT.Size, 1),
1461                     (outs), // no dst for VOPC, we use "vcc"-token as dst in SDWA VOPC instructions
1462                     (outs DstRCExt:$vdst)),
1463                 (outs)); // V_NOP
1464 }
1465
1466 // Outs for SDWA
1467 class getOutsSDWA <bit HasDst, ValueType DstVT, RegisterOperand DstRCSDWA> {
1468   dag ret = !if(HasDst,
1469                 !if(!eq(DstVT.Size, 1),
1470                     (outs DstRCSDWA:$sdst),
1471                     (outs DstRCSDWA:$vdst)),
1472                 (outs)); // V_NOP
1473 }
1474
1475 // Returns the assembly string for the inputs and outputs of a VOP[12C]
1476 // instruction.  This does not add the _e32 suffix, so it can be reused
1477 // by getAsm64.
1478 class getAsm32 <bit HasDst, int NumSrcArgs, ValueType DstVT = i32> {
1479   string dst = !if(!eq(DstVT.Size, 1), "$sdst", "$vdst"); // use $sdst for VOPC
1480   string src0 = ", $src0";
1481   string src1 = ", $src1";
1482   string src2 = ", $src2";
1483   string ret = !if(HasDst, dst, "") #
1484                !if(!eq(NumSrcArgs, 1), src0, "") #
1485                !if(!eq(NumSrcArgs, 2), src0#src1, "") #
1486                !if(!eq(NumSrcArgs, 3), src0#src1#src2, "");
1487 }
1488
1489 // Returns the assembly string for the inputs and outputs of a VOP3
1490 // instruction.
1491 class getAsm64 <bit HasDst, int NumSrcArgs, bit HasIntClamp, bit HasModifiers,
1492                 bit HasOMod, ValueType DstVT = i32> {
1493   string dst = !if(!eq(DstVT.Size, 1), "$sdst", "$vdst"); // use $sdst for VOPC
1494   string src0 = !if(!eq(NumSrcArgs, 1), "$src0_modifiers", "$src0_modifiers,");
1495   string src1 = !if(!eq(NumSrcArgs, 1), "",
1496                    !if(!eq(NumSrcArgs, 2), " $src1_modifiers",
1497                                            " $src1_modifiers,"));
1498   string src2 = !if(!eq(NumSrcArgs, 3), " $src2_modifiers", "");
1499   string iclamp = !if(HasIntClamp, "$clamp", "");
1500   string ret =
1501   !if(!eq(HasModifiers, 0),
1502       getAsm32<HasDst, NumSrcArgs, DstVT>.ret # iclamp,
1503       dst#", "#src0#src1#src2#"$clamp"#!if(HasOMod, "$omod", ""));
1504 }
1505
1506 // Returns the assembly string for the inputs and outputs of a VOP3P
1507 // instruction.
1508 class getAsmVOP3P <bit HasDst, int NumSrcArgs, bit HasModifiers,
1509                    bit HasClamp, ValueType DstVT = i32> {
1510   string dst = " $vdst";
1511   string src0 = !if(!eq(NumSrcArgs, 1), "$src0", "$src0,");
1512   string src1 = !if(!eq(NumSrcArgs, 1), "",
1513                    !if(!eq(NumSrcArgs, 2), " $src1",
1514                                            " $src1,"));
1515   string src2 = !if(!eq(NumSrcArgs, 3), " $src2", "");
1516
1517   string mods = !if(HasModifiers, "$neg_lo$neg_hi", "");
1518   string clamp = !if(HasClamp, "$clamp", "");
1519
1520   // Each modifier is printed as an array of bits for each operand, so
1521   // all operands are printed as part of src0_modifiers.
1522   string ret = dst#", "#src0#src1#src2#"$op_sel$op_sel_hi"#mods#clamp;
1523 }
1524
1525 class getAsmVOP3OpSel <int NumSrcArgs,
1526                        bit HasClamp,
1527                        bit Src0HasMods,
1528                        bit Src1HasMods,
1529                        bit Src2HasMods> {
1530   string dst = " $vdst";
1531
1532   string isrc0 = !if(!eq(NumSrcArgs, 1), "$src0", "$src0,");
1533   string isrc1 = !if(!eq(NumSrcArgs, 1), "",
1534                      !if(!eq(NumSrcArgs, 2), " $src1",
1535                                              " $src1,"));
1536   string isrc2 = !if(!eq(NumSrcArgs, 3), " $src2", "");
1537
1538   string fsrc0 = !if(!eq(NumSrcArgs, 1), "$src0_modifiers", "$src0_modifiers,");
1539   string fsrc1 = !if(!eq(NumSrcArgs, 1), "",
1540                      !if(!eq(NumSrcArgs, 2), " $src1_modifiers",
1541                                              " $src1_modifiers,"));
1542   string fsrc2 = !if(!eq(NumSrcArgs, 3), " $src2_modifiers", "");
1543
1544   string src0 = !if(Src0HasMods, fsrc0, isrc0);
1545   string src1 = !if(Src1HasMods, fsrc1, isrc1);
1546   string src2 = !if(Src2HasMods, fsrc2, isrc2);
1547
1548   string clamp = !if(HasClamp, "$clamp", "");
1549
1550   string ret = dst#", "#src0#src1#src2#"$op_sel"#clamp;
1551 }
1552
1553 class getAsmDPP <bit HasDst, int NumSrcArgs, bit HasModifiers, ValueType DstVT = i32> {
1554   string dst = !if(HasDst,
1555                    !if(!eq(DstVT.Size, 1),
1556                        "$sdst",
1557                        "$vdst"),
1558                     ""); // use $sdst for VOPC
1559   string src0 = !if(!eq(NumSrcArgs, 1), "$src0_modifiers", "$src0_modifiers,");
1560   string src1 = !if(!eq(NumSrcArgs, 1), "",
1561                    !if(!eq(NumSrcArgs, 2), " $src1_modifiers",
1562                                            " $src1_modifiers,"));
1563   string args = !if(!eq(HasModifiers, 0),
1564                      getAsm32<0, NumSrcArgs, DstVT>.ret,
1565                      ", "#src0#src1);
1566   string ret = dst#args#" $dpp_ctrl$row_mask$bank_mask$bound_ctrl";
1567 }
1568
1569 class getAsmSDWA <bit HasDst, int NumSrcArgs, ValueType DstVT = i32> {
1570   string dst = !if(HasDst,
1571                    !if(!eq(DstVT.Size, 1),
1572                        " vcc", // use vcc token as dst for VOPC instructioins
1573                        "$vdst"),
1574                     "");
1575   string src0 = "$src0_modifiers";
1576   string src1 = "$src1_modifiers";
1577   string args = !if(!eq(NumSrcArgs, 0),
1578                     "",
1579                     !if(!eq(NumSrcArgs, 1),
1580                         ", "#src0#"$clamp",
1581                         ", "#src0#", "#src1#"$clamp"
1582                      )
1583                 );
1584   string sdwa = !if(!eq(NumSrcArgs, 0),
1585                     "",
1586                     !if(!eq(NumSrcArgs, 1),
1587                         " $dst_sel $dst_unused $src0_sel",
1588                         !if(!eq(DstVT.Size, 1),
1589                             " $src0_sel $src1_sel", // No dst_sel and dst_unused for VOPC
1590                             " $dst_sel $dst_unused $src0_sel $src1_sel"
1591                         )
1592                     )
1593                 );
1594   string ret = dst#args#sdwa;
1595 }
1596
1597 class getAsmSDWA9 <bit HasDst, bit HasOMod, int NumSrcArgs,
1598                    ValueType DstVT = i32> {
1599   string dst = !if(HasDst,
1600                    !if(!eq(DstVT.Size, 1),
1601                        "$sdst", // VOPC
1602                        "$vdst"), // VOP1/2
1603                     "");
1604   string src0 = "$src0_modifiers";
1605   string src1 = "$src1_modifiers";
1606   string out_mods = !if(!eq(HasOMod, 0), "$clamp", "$clamp$omod");
1607   string args = !if(!eq(NumSrcArgs, 0), "",
1608                     !if(!eq(NumSrcArgs, 1),
1609                         ", "#src0,
1610                         ", "#src0#", "#src1
1611                      )
1612                 );
1613   string sdwa = !if(!eq(NumSrcArgs, 0), "",
1614                     !if(!eq(NumSrcArgs, 1),
1615                         out_mods#" $dst_sel $dst_unused $src0_sel",
1616                         !if(!eq(DstVT.Size, 1),
1617                             " $src0_sel $src1_sel", // No dst_sel, dst_unused and output modifiers for VOPC
1618                             out_mods#" $dst_sel $dst_unused $src0_sel $src1_sel"
1619                         )
1620                     )
1621                 );
1622   string ret = dst#args#sdwa;
1623 }
1624
1625
1626 // Function that checks if instruction supports DPP and SDWA
1627 class getHasExt <int NumSrcArgs, ValueType DstVT = i32, ValueType Src0VT = i32,
1628                  ValueType Src1VT = i32> {
1629   bit ret = !if(!eq(NumSrcArgs, 3),
1630                 0, // NumSrcArgs == 3 - No DPP or SDWA for VOP3
1631                 !if(!eq(DstVT.Size, 64),
1632                     0, // 64-bit dst - No DPP or SDWA for 64-bit operands
1633                     !if(!eq(Src0VT.Size, 64),
1634                         0, // 64-bit src0
1635                         !if(!eq(Src0VT.Size, 64),
1636                             0, // 64-bit src2
1637                             1
1638                         )
1639                     )
1640                 )
1641             );
1642 }
1643
1644 class BitOr<bit a, bit b> {
1645   bit ret = !if(a, 1, !if(b, 1, 0));
1646 }
1647
1648 class BitAnd<bit a, bit b> {
1649   bit ret = !if(a, !if(b, 1, 0), 0);
1650 }
1651
1652 class VOPProfile <list<ValueType> _ArgVT> {
1653
1654   field list<ValueType> ArgVT = _ArgVT;
1655
1656   field ValueType DstVT = ArgVT[0];
1657   field ValueType Src0VT = ArgVT[1];
1658   field ValueType Src1VT = ArgVT[2];
1659   field ValueType Src2VT = ArgVT[3];
1660   field RegisterOperand DstRC = getVALUDstForVT<DstVT>.ret;
1661   field RegisterOperand DstRCDPP = getVALUDstForVT<DstVT>.ret;
1662   field RegisterOperand DstRCSDWA = getSDWADstForVT<DstVT>.ret;
1663   field RegisterOperand Src0RC32 = getVOPSrc0ForVT<Src0VT>.ret;
1664   field RegisterClass Src1RC32 = getVregSrcForVT<Src1VT>.ret;
1665   field RegisterOperand Src0RC64 = getVOP3SrcForVT<Src0VT>.ret;
1666   field RegisterOperand Src1RC64 = getVOP3SrcForVT<Src1VT>.ret;
1667   field RegisterOperand Src2RC64 = getVOP3SrcForVT<Src2VT>.ret;
1668   field RegisterClass Src0DPP = getVregSrcForVT<Src0VT>.ret;
1669   field RegisterClass Src1DPP = getVregSrcForVT<Src1VT>.ret;
1670   field RegisterOperand Src0SDWA = getSDWASrcForVT<Src0VT>.ret;
1671   field RegisterOperand Src1SDWA = getSDWASrcForVT<Src0VT>.ret;
1672   field Operand Src0Mod = getSrcMod<Src0VT>.ret;
1673   field Operand Src1Mod = getSrcMod<Src1VT>.ret;
1674   field Operand Src2Mod = getSrcMod<Src2VT>.ret;
1675   field Operand Src0ModDPP = getSrcModExt<Src0VT>.ret;
1676   field Operand Src1ModDPP = getSrcModExt<Src1VT>.ret;
1677   field Operand Src0ModSDWA = getSrcModSDWA<Src0VT>.ret;
1678   field Operand Src1ModSDWA = getSrcModSDWA<Src1VT>.ret;
1679
1680
1681   field bit HasDst = !if(!eq(DstVT.Value, untyped.Value), 0, 1);
1682   field bit HasDst32 = HasDst;
1683   field bit EmitDst = HasDst; // force dst encoding, see v_movreld_b32 special case
1684   field int NumSrcArgs = getNumSrcArgs<Src0VT, Src1VT, Src2VT>.ret;
1685   field bit HasSrc0 = !if(!eq(Src0VT.Value, untyped.Value), 0, 1);
1686   field bit HasSrc1 = !if(!eq(Src1VT.Value, untyped.Value), 0, 1);
1687   field bit HasSrc2 = !if(!eq(Src2VT.Value, untyped.Value), 0, 1);
1688
1689   // TODO: Modifiers logic is somewhat adhoc here, to be refined later
1690   field bit HasModifiers = isModifierType<Src0VT>.ret;
1691
1692   field bit HasSrc0FloatMods = isFloatType<Src0VT>.ret;
1693   field bit HasSrc1FloatMods = isFloatType<Src1VT>.ret;
1694   field bit HasSrc2FloatMods = isFloatType<Src2VT>.ret;
1695
1696   field bit HasSrc0IntMods = isIntType<Src0VT>.ret;
1697   field bit HasSrc1IntMods = isIntType<Src1VT>.ret;
1698   field bit HasSrc2IntMods = isIntType<Src2VT>.ret;
1699
1700   field bit HasSrc0Mods = HasModifiers;
1701   field bit HasSrc1Mods = !if(HasModifiers, BitOr<HasSrc1FloatMods, HasSrc1IntMods>.ret, 0);
1702   field bit HasSrc2Mods = !if(HasModifiers, BitOr<HasSrc2FloatMods, HasSrc2IntMods>.ret, 0);
1703
1704   field bit HasClamp = HasModifiers;
1705   field bit HasSDWAClamp = EmitDst;
1706   field bit HasFPClamp = BitAnd<isFloatType<DstVT>.ret, HasClamp>.ret;
1707   field bit HasIntClamp = !if(isFloatType<DstVT>.ret, 0, HasClamp);
1708   field bit HasClampLo = HasClamp;
1709   field bit HasClampHi = BitAnd<isPackedType<DstVT>.ret, HasClamp>.ret;
1710   field bit HasHigh = 0;
1711
1712   field bit IsPacked = isPackedType<Src0VT>.ret;
1713   field bit HasOpSel = IsPacked;
1714   field bit HasOMod = !if(HasOpSel, 0, isFloatType<DstVT>.ret);
1715   field bit HasSDWAOMod = isFloatType<DstVT>.ret;
1716
1717   field bit HasExt = getHasExt<NumSrcArgs, DstVT, Src0VT, Src1VT>.ret;
1718   field bit HasSDWA9 = HasExt;
1719
1720   field Operand Src0PackedMod = !if(HasSrc0FloatMods, PackedF16InputMods, PackedI16InputMods);
1721   field Operand Src1PackedMod = !if(HasSrc1FloatMods, PackedF16InputMods, PackedI16InputMods);
1722   field Operand Src2PackedMod = !if(HasSrc2FloatMods, PackedF16InputMods, PackedI16InputMods);
1723
1724   field dag Outs = !if(HasDst,(outs DstRC:$vdst),(outs));
1725
1726   // VOP3b instructions are a special case with a second explicit
1727   // output. This is manually overridden for them.
1728   field dag Outs32 = Outs;
1729   field dag Outs64 = Outs;
1730   field dag OutsDPP = getOutsExt<HasDst, DstVT, DstRCDPP>.ret;
1731   field dag OutsSDWA = getOutsSDWA<HasDst, DstVT, DstRCSDWA>.ret;
1732
1733   field dag Ins32 = getIns32<Src0RC32, Src1RC32, NumSrcArgs>.ret;
1734   field dag Ins64 = getIns64<Src0RC64, Src1RC64, Src2RC64, NumSrcArgs,
1735                              HasIntClamp, HasModifiers, HasOMod, Src0Mod, Src1Mod,
1736                              Src2Mod>.ret;
1737   field dag InsVOP3P = getInsVOP3P<Src0RC64, Src1RC64, Src2RC64,
1738                                    NumSrcArgs, HasClamp,
1739                                    Src0PackedMod, Src1PackedMod, Src2PackedMod>.ret;
1740   field dag InsVOP3OpSel = getInsVOP3OpSel<Src0RC64, Src1RC64, Src2RC64,
1741                                            NumSrcArgs,
1742                                            HasClamp,
1743                                            getOpSelMod<Src0VT>.ret,
1744                                            getOpSelMod<Src1VT>.ret,
1745                                            getOpSelMod<Src2VT>.ret>.ret;
1746   field dag InsDPP = getInsDPP<DstRCDPP, Src0DPP, Src1DPP, NumSrcArgs,
1747                                HasModifiers, Src0ModDPP, Src1ModDPP>.ret;
1748   field dag InsSDWA = getInsSDWA<Src0SDWA, Src1SDWA, NumSrcArgs,
1749                                  HasSDWAOMod, Src0ModSDWA, Src1ModSDWA,
1750                                  DstVT>.ret;
1751
1752
1753   field string Asm32 = getAsm32<HasDst, NumSrcArgs, DstVT>.ret;
1754   field string Asm64 = getAsm64<HasDst, NumSrcArgs, HasIntClamp, HasModifiers, HasOMod, DstVT>.ret;
1755   field string AsmVOP3P = getAsmVOP3P<HasDst, NumSrcArgs, HasModifiers, HasClamp, DstVT>.ret;
1756   field string AsmVOP3OpSel = getAsmVOP3OpSel<NumSrcArgs,
1757                                               HasClamp,
1758                                               HasSrc0FloatMods,
1759                                               HasSrc1FloatMods,
1760                                               HasSrc2FloatMods>.ret;
1761   field string AsmDPP = getAsmDPP<HasDst, NumSrcArgs, HasModifiers, DstVT>.ret;
1762   field string AsmSDWA = getAsmSDWA<HasDst, NumSrcArgs, DstVT>.ret;
1763   field string AsmSDWA9 = getAsmSDWA9<HasDst, HasSDWAOMod, NumSrcArgs, DstVT>.ret;
1764 }
1765
1766 class VOP_NO_EXT <VOPProfile p> : VOPProfile <p.ArgVT> {
1767   let HasExt = 0;
1768   let HasSDWA9 = 0;
1769 }
1770
1771 def VOP_F16_F16 : VOPProfile <[f16, f16, untyped, untyped]>;
1772 def VOP_F16_I16 : VOPProfile <[f16, i16, untyped, untyped]>;
1773 def VOP_I16_F16 : VOPProfile <[i16, f16, untyped, untyped]>;
1774
1775 def VOP_F16_F16_F16 : VOPProfile <[f16, f16, f16, untyped]>;
1776 def VOP_F16_F16_I16 : VOPProfile <[f16, f16, i16, untyped]>;
1777 def VOP_F16_F16_I32 : VOPProfile <[f16, f16, i32, untyped]>;
1778 def VOP_I16_I16_I16 : VOPProfile <[i16, i16, i16, untyped]>;
1779
1780 def VOP_I16_I16_I16_I16 : VOPProfile <[i16, i16, i16, i16, untyped]>;
1781 def VOP_F16_F16_F16_F16 : VOPProfile <[f16, f16, f16, f16, untyped]>;
1782
1783 def VOP_I32_I16_I16_I32 : VOPProfile <[i32, i16, i16, i32, untyped]>;
1784
1785 def VOP_V2F16_V2F16_V2F16 : VOPProfile <[v2f16, v2f16, v2f16, untyped]>;
1786 def VOP_V2I16_V2I16_V2I16 : VOPProfile <[v2i16, v2i16, v2i16, untyped]>;
1787 def VOP_B32_F16_F16 : VOPProfile <[i32, f16, f16, untyped]>;
1788
1789 def VOP_V2F16_V2F16_V2F16_V2F16 : VOPProfile <[v2f16, v2f16, v2f16, v2f16]>;
1790 def VOP_V2I16_V2I16_V2I16_V2I16 : VOPProfile <[v2i16, v2i16, v2i16, v2i16]>;
1791
1792 def VOP_F32_V2F16_V2F16_V2F16 : VOPProfile <[f32, v2f16, v2f16, v2f16]>;
1793
1794 def VOP_NONE : VOPProfile <[untyped, untyped, untyped, untyped]>;
1795
1796 def VOP_F32_F32 : VOPProfile <[f32, f32, untyped, untyped]>;
1797 def VOP_F32_F64 : VOPProfile <[f32, f64, untyped, untyped]>;
1798 def VOP_F32_I32 : VOPProfile <[f32, i32, untyped, untyped]>;
1799 def VOP_F64_F32 : VOPProfile <[f64, f32, untyped, untyped]>;
1800 def VOP_F64_F64 : VOPProfile <[f64, f64, untyped, untyped]>;
1801 def VOP_F64_I32 : VOPProfile <[f64, i32, untyped, untyped]>;
1802 def VOP_I32_F32 : VOPProfile <[i32, f32, untyped, untyped]>;
1803 def VOP_I32_F64 : VOPProfile <[i32, f64, untyped, untyped]>;
1804 def VOP_I32_I32 : VOPProfile <[i32, i32, untyped, untyped]>;
1805 def VOP_F16_F32 : VOPProfile <[f16, f32, untyped, untyped]>;
1806 def VOP_F32_F16 : VOPProfile <[f32, f16, untyped, untyped]>;
1807
1808 def VOP_F32_F32_F16 : VOPProfile <[f32, f32, f16, untyped]>;
1809 def VOP_F32_F32_F32 : VOPProfile <[f32, f32, f32, untyped]>;
1810 def VOP_F32_F32_I32 : VOPProfile <[f32, f32, i32, untyped]>;
1811 def VOP_F64_F64_F64 : VOPProfile <[f64, f64, f64, untyped]>;
1812 def VOP_F64_F64_I32 : VOPProfile <[f64, f64, i32, untyped]>;
1813 def VOP_I32_F32_F32 : VOPProfile <[i32, f32, f32, untyped]>;
1814 def VOP_I32_F32_I32 : VOPProfile <[i32, f32, i32, untyped]>;
1815 def VOP_I32_I32_I32 : VOPProfile <[i32, i32, i32, untyped]>;
1816 def VOP_V2F16_F32_F32 : VOPProfile <[v2f16, f32, f32, untyped]>;
1817 def VOP_F32_F16_F16_F16 : VOPProfile <[f32, f16, f16, f16]>;
1818
1819 def VOP_I64_I64_I32 : VOPProfile <[i64, i64, i32, untyped]>;
1820 def VOP_I64_I32_I64 : VOPProfile <[i64, i32, i64, untyped]>;
1821 def VOP_I64_I64_I64 : VOPProfile <[i64, i64, i64, untyped]>;
1822
1823 def VOP_F16_F32_F16_F32 : VOPProfile <[f16, f32, f16, f32]>;
1824 def VOP_F32_F32_F16_F16 : VOPProfile <[f32, f32, f16, f16]>;
1825 def VOP_F32_F32_F32_F32 : VOPProfile <[f32, f32, f32, f32]>;
1826 def VOP_F64_F64_F64_F64 : VOPProfile <[f64, f64, f64, f64]>;
1827 def VOP_I32_I32_I32_I32 : VOPProfile <[i32, i32, i32, i32]>;
1828 def VOP_I64_I32_I32_I64 : VOPProfile <[i64, i32, i32, i64]>;
1829 def VOP_I32_F32_I32_I32 : VOPProfile <[i32, f32, i32, i32]>;
1830 def VOP_I64_I64_I32_I64 : VOPProfile <[i64, i64, i32, i64]>;
1831 def VOP_V4I32_I64_I32_V4I32 : VOPProfile <[v4i32, i64, i32, v4i32]>;
1832
1833 def VOP_F32_V2F16_V2F16_F32 : VOPProfile <[f32, v2f16, v2f16, f32]>;
1834 def VOP_I32_V2I16_V2I16_I32 : VOPProfile <[i32, v2i16, v2i16, i32]>;
1835
1836 class Commutable_REV <string revOp, bit isOrig> {
1837   string RevOp = revOp;
1838   bit IsOrig = isOrig;
1839 }
1840
1841 class AtomicNoRet <string noRetOp, bit isRet> {
1842   string NoRetOp = noRetOp;
1843   bit IsRet = isRet;
1844 }
1845
1846 //===----------------------------------------------------------------------===//
1847 // Interpolation opcodes
1848 //===----------------------------------------------------------------------===//
1849
1850 class VINTRPDstOperand <RegisterClass rc> : RegisterOperand <rc, "printVINTRPDst">;
1851
1852 class VINTRP_Pseudo <string opName, dag outs, dag ins, list<dag> pattern> :
1853   VINTRPCommon <outs, ins, "", pattern>,
1854   SIMCInstr<opName, SIEncodingFamily.NONE> {
1855   let isPseudo = 1;
1856   let isCodeGenOnly = 1;
1857 }
1858
1859 class VINTRP_Real_si <bits <2> op, string opName, dag outs, dag ins,
1860                       string asm> :
1861   VINTRPCommon <outs, ins, asm, []>,
1862   VINTRPe <op>,
1863   SIMCInstr<opName, SIEncodingFamily.SI> {
1864   let AssemblerPredicate = SIAssemblerPredicate;
1865   let DecoderNamespace = "SICI";
1866   let DisableDecoder = DisableSIDecoder;
1867 }
1868
1869 class VINTRP_Real_vi <bits <2> op, string opName, dag outs, dag ins,
1870                       string asm> :
1871   VINTRPCommon <outs, ins, asm, []>,
1872   VINTRPe_vi <op>,
1873   SIMCInstr<opName, SIEncodingFamily.VI> {
1874   let AssemblerPredicate = VIAssemblerPredicate;
1875   let DecoderNamespace = "VI";
1876   let DisableDecoder = DisableVIDecoder;
1877 }
1878
1879 multiclass VINTRP_m <bits <2> op, dag outs, dag ins, string asm,
1880                      list<dag> pattern = []> {
1881   def "" : VINTRP_Pseudo <NAME, outs, ins, pattern>;
1882
1883   def _si : VINTRP_Real_si <op, NAME, outs, ins, asm>;
1884
1885   def _vi : VINTRP_Real_vi <op, NAME, outs, ins, asm>;
1886 }
1887
1888 //===----------------------------------------------------------------------===//
1889 // Vector instruction mappings
1890 //===----------------------------------------------------------------------===//
1891
1892 // Maps an opcode in e32 form to its e64 equivalent
1893 def getVOPe64 : InstrMapping {
1894   let FilterClass = "VOP";
1895   let RowFields = ["OpName"];
1896   let ColFields = ["Size", "VOP3"];
1897   let KeyCol = ["4", "0"];
1898   let ValueCols = [["8", "1"]];
1899 }
1900
1901 // Maps an opcode in e64 form to its e32 equivalent
1902 def getVOPe32 : InstrMapping {
1903   let FilterClass = "VOP";
1904   let RowFields = ["OpName"];
1905   let ColFields = ["Size", "VOP3"];
1906   let KeyCol = ["8", "1"];
1907   let ValueCols = [["4", "0"]];
1908 }
1909
1910 // Maps ordinary instructions to their SDWA counterparts
1911 def getSDWAOp : InstrMapping {
1912   let FilterClass = "VOP";
1913   let RowFields = ["OpName"];
1914   let ColFields = ["AsmVariantName"];
1915   let KeyCol = ["Default"];
1916   let ValueCols = [["SDWA"]];
1917 }
1918
1919 // Maps SDWA instructions to their ordinary counterparts
1920 def getBasicFromSDWAOp : InstrMapping {
1921   let FilterClass = "VOP";
1922   let RowFields = ["OpName"];
1923   let ColFields = ["AsmVariantName"];
1924   let KeyCol = ["SDWA"];
1925   let ValueCols = [["Default"]];
1926 }
1927
1928 // Maps an commuted opcode to its original version
1929 def getCommuteOrig : InstrMapping {
1930   let FilterClass = "Commutable_REV";
1931   let RowFields = ["RevOp"];
1932   let ColFields = ["IsOrig"];
1933   let KeyCol = ["0"];
1934   let ValueCols = [["1"]];
1935 }
1936
1937 // Maps an original opcode to its commuted version
1938 def getCommuteRev : InstrMapping {
1939   let FilterClass = "Commutable_REV";
1940   let RowFields = ["RevOp"];
1941   let ColFields = ["IsOrig"];
1942   let KeyCol = ["1"];
1943   let ValueCols = [["0"]];
1944 }
1945
1946 def getMCOpcodeGen : InstrMapping {
1947   let FilterClass = "SIMCInstr";
1948   let RowFields = ["PseudoInstr"];
1949   let ColFields = ["Subtarget"];
1950   let KeyCol = [!cast<string>(SIEncodingFamily.NONE)];
1951   let ValueCols = [[!cast<string>(SIEncodingFamily.SI)],
1952                    [!cast<string>(SIEncodingFamily.VI)],
1953                    [!cast<string>(SIEncodingFamily.SDWA)],
1954                    [!cast<string>(SIEncodingFamily.SDWA9)],
1955                    // GFX80 encoding is added to work around a multiple matching
1956                    // issue for buffer instructions with unpacked d16 data. This
1957                    // does not actually change the encoding, and thus may be
1958                    // removed later.
1959                    [!cast<string>(SIEncodingFamily.GFX80)],
1960                    [!cast<string>(SIEncodingFamily.GFX9)]];
1961 }
1962
1963 // Get equivalent SOPK instruction.
1964 def getSOPKOp : InstrMapping {
1965   let FilterClass = "SOPKInstTable";
1966   let RowFields = ["BaseCmpOp"];
1967   let ColFields = ["IsSOPK"];
1968   let KeyCol = ["0"];
1969   let ValueCols = [["1"]];
1970 }
1971
1972 def getAddr64Inst : InstrMapping {
1973   let FilterClass = "MUBUFAddr64Table";
1974   let RowFields = ["OpName"];
1975   let ColFields = ["IsAddr64"];
1976   let KeyCol = ["0"];
1977   let ValueCols = [["1"]];
1978 }
1979
1980 def getMUBUFNoLdsInst : InstrMapping {
1981   let FilterClass = "MUBUFLdsTable";
1982   let RowFields = ["OpName"];
1983   let ColFields = ["IsLds"];
1984   let KeyCol = ["1"];
1985   let ValueCols = [["0"]];
1986 }
1987
1988 // Maps an atomic opcode to its version with a return value.
1989 def getAtomicRetOp : InstrMapping {
1990   let FilterClass = "AtomicNoRet";
1991   let RowFields = ["NoRetOp"];
1992   let ColFields = ["IsRet"];
1993   let KeyCol = ["0"];
1994   let ValueCols = [["1"]];
1995 }
1996
1997 // Maps an atomic opcode to its returnless version.
1998 def getAtomicNoRetOp : InstrMapping {
1999   let FilterClass = "AtomicNoRet";
2000   let RowFields = ["NoRetOp"];
2001   let ColFields = ["IsRet"];
2002   let KeyCol = ["1"];
2003   let ValueCols = [["0"]];
2004 }
2005
2006 include "SIInstructions.td"
2007
2008 include "DSInstructions.td"
2009 include "MIMGInstructions.td"