R600/SI: Fix not encoding src2 for v_div_scale_{f32|f64}
[oota-llvm.git] / lib / Target / R600 / 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
10 class vop {
11   field bits<9> SI3;
12   field bits<10> VI3;
13 }
14
15 class vopc <bits<8> si, bits<8> vi = !add(0x40, si)> : vop {
16   field bits<8> SI = si;
17   field bits<8> VI = vi;
18
19   field bits<9>  SI3 = {0, si{7-0}};
20   field bits<10> VI3 = {0, 0, vi{7-0}};
21 }
22
23 class vop1 <bits<8> si, bits<8> vi = si> : vop {
24   field bits<8> SI = si;
25   field bits<8> VI = vi;
26
27   field bits<9>  SI3 = {1, 1, si{6-0}};
28   field bits<10> VI3 = !add(0x140, vi);
29 }
30
31 class vop2 <bits<6> si, bits<6> vi = si> : vop {
32   field bits<6> SI = si;
33   field bits<6> VI = vi;
34
35   field bits<9>  SI3 = {1, 0, 0, si{5-0}};
36   field bits<10> VI3 = {0, 1, 0, 0, vi{5-0}};
37 }
38
39 // Specify a VOP2 opcode for SI and VOP3 opcode for VI
40 // that doesn't have VOP2 encoding on VI
41 class vop23 <bits<6> si, bits<10> vi> : vop2 <si> {
42   let VI3 = vi;
43 }
44
45 class vop3 <bits<9> si, bits<10> vi = {0, si}> : vop {
46   let SI3 = si;
47   let VI3 = vi;
48 }
49
50 class sop1 <bits<8> si, bits<8> vi = si> {
51   field bits<8> SI = si;
52   field bits<8> VI = vi;
53 }
54
55 class sop2 <bits<7> si, bits<7> vi = si> {
56   field bits<7> SI = si;
57   field bits<7> VI = vi;
58 }
59
60 class sopk <bits<5> si, bits<5> vi = si> {
61   field bits<5> SI = si;
62   field bits<5> VI = vi;
63 }
64
65 // Execpt for the NONE field, this must be kept in sync with the SISubtarget enum
66 // in AMDGPUInstrInfo.cpp
67 def SISubtarget {
68   int NONE = -1;
69   int SI = 0;
70   int VI = 1;
71 }
72
73 //===----------------------------------------------------------------------===//
74 // SI DAG Nodes
75 //===----------------------------------------------------------------------===//
76
77 def SIload_constant : SDNode<"AMDGPUISD::LOAD_CONSTANT",
78   SDTypeProfile<1, 2, [SDTCisVT<0, f32>, SDTCisVT<1, v4i32>, SDTCisVT<2, i32>]>,
79                       [SDNPMayLoad, SDNPMemOperand]
80 >;
81
82 def SItbuffer_store : SDNode<"AMDGPUISD::TBUFFER_STORE_FORMAT",
83   SDTypeProfile<0, 13,
84     [SDTCisVT<0, v4i32>,   // rsrc(SGPR)
85      SDTCisVT<1, iAny>,   // vdata(VGPR)
86      SDTCisVT<2, i32>,    // num_channels(imm)
87      SDTCisVT<3, i32>,    // vaddr(VGPR)
88      SDTCisVT<4, i32>,    // soffset(SGPR)
89      SDTCisVT<5, i32>,    // inst_offset(imm)
90      SDTCisVT<6, i32>,    // dfmt(imm)
91      SDTCisVT<7, i32>,    // nfmt(imm)
92      SDTCisVT<8, i32>,    // offen(imm)
93      SDTCisVT<9, i32>,    // idxen(imm)
94      SDTCisVT<10, i32>,   // glc(imm)
95      SDTCisVT<11, i32>,   // slc(imm)
96      SDTCisVT<12, i32>    // tfe(imm)
97     ]>,
98   [SDNPMayStore, SDNPMemOperand, SDNPHasChain]
99 >;
100
101 def SIload_input : SDNode<"AMDGPUISD::LOAD_INPUT",
102   SDTypeProfile<1, 3, [SDTCisVT<0, v4f32>, SDTCisVT<1, v4i32>, SDTCisVT<2, i16>,
103                        SDTCisVT<3, i32>]>
104 >;
105
106 class SDSample<string opcode> : SDNode <opcode,
107   SDTypeProfile<1, 4, [SDTCisVT<0, v4f32>, SDTCisVT<2, v32i8>,
108                        SDTCisVT<3, v4i32>, SDTCisVT<4, i32>]>
109 >;
110
111 def SIsample : SDSample<"AMDGPUISD::SAMPLE">;
112 def SIsampleb : SDSample<"AMDGPUISD::SAMPLEB">;
113 def SIsampled : SDSample<"AMDGPUISD::SAMPLED">;
114 def SIsamplel : SDSample<"AMDGPUISD::SAMPLEL">;
115
116 def SIconstdata_ptr : SDNode<
117   "AMDGPUISD::CONST_DATA_PTR", SDTypeProfile <1, 0, [SDTCisVT<0, i64>]>
118 >;
119
120 // Transformation function, extract the lower 32bit of a 64bit immediate
121 def LO32 : SDNodeXForm<imm, [{
122   return CurDAG->getTargetConstant(N->getZExtValue() & 0xffffffff, MVT::i32);
123 }]>;
124
125 def LO32f : SDNodeXForm<fpimm, [{
126   APInt V = N->getValueAPF().bitcastToAPInt().trunc(32);
127   return CurDAG->getTargetConstantFP(APFloat(APFloat::IEEEsingle, V), MVT::f32);
128 }]>;
129
130 // Transformation function, extract the upper 32bit of a 64bit immediate
131 def HI32 : SDNodeXForm<imm, [{
132   return CurDAG->getTargetConstant(N->getZExtValue() >> 32, MVT::i32);
133 }]>;
134
135 def HI32f : SDNodeXForm<fpimm, [{
136   APInt V = N->getValueAPF().bitcastToAPInt().lshr(32).trunc(32);
137   return CurDAG->getTargetConstantFP(APFloat(APFloat::IEEEsingle, V), MVT::f32);
138 }]>;
139
140 def IMM8bitDWORD : PatLeaf <(imm),
141   [{return (N->getZExtValue() & ~0x3FC) == 0;}]
142 >;
143
144 def as_dword_i32imm : SDNodeXForm<imm, [{
145   return CurDAG->getTargetConstant(N->getZExtValue() >> 2, MVT::i32);
146 }]>;
147
148 def as_i1imm : SDNodeXForm<imm, [{
149   return CurDAG->getTargetConstant(N->getZExtValue(), MVT::i1);
150 }]>;
151
152 def as_i8imm : SDNodeXForm<imm, [{
153   return CurDAG->getTargetConstant(N->getZExtValue(), MVT::i8);
154 }]>;
155
156 def as_i16imm : SDNodeXForm<imm, [{
157   return CurDAG->getTargetConstant(N->getSExtValue(), MVT::i16);
158 }]>;
159
160 def as_i32imm: SDNodeXForm<imm, [{
161   return CurDAG->getTargetConstant(N->getSExtValue(), MVT::i32);
162 }]>;
163
164 def as_i64imm: SDNodeXForm<imm, [{
165   return CurDAG->getTargetConstant(N->getSExtValue(), MVT::i64);
166 }]>;
167
168 // Copied from the AArch64 backend:
169 def bitcast_fpimm_to_i32 : SDNodeXForm<fpimm, [{
170 return CurDAG->getTargetConstant(
171   N->getValueAPF().bitcastToAPInt().getZExtValue(), MVT::i32);
172 }]>;
173
174 // Copied from the AArch64 backend:
175 def bitcast_fpimm_to_i64 : SDNodeXForm<fpimm, [{
176 return CurDAG->getTargetConstant(
177   N->getValueAPF().bitcastToAPInt().getZExtValue(), MVT::i64);
178 }]>;
179
180 def IMM8bit : PatLeaf <(imm),
181   [{return isUInt<8>(N->getZExtValue());}]
182 >;
183
184 def IMM12bit : PatLeaf <(imm),
185   [{return isUInt<12>(N->getZExtValue());}]
186 >;
187
188 def IMM16bit : PatLeaf <(imm),
189   [{return isUInt<16>(N->getZExtValue());}]
190 >;
191
192 def IMM20bit : PatLeaf <(imm),
193   [{return isUInt<20>(N->getZExtValue());}]
194 >;
195
196 def IMM32bit : PatLeaf <(imm),
197   [{return isUInt<32>(N->getZExtValue());}]
198 >;
199
200 def mubuf_vaddr_offset : PatFrag<
201   (ops node:$ptr, node:$offset, node:$imm_offset),
202   (add (add node:$ptr, node:$offset), node:$imm_offset)
203 >;
204
205 class InlineImm <ValueType vt> : PatLeaf <(vt imm), [{
206   return isInlineImmediate(N);
207 }]>;
208
209 class InlineFPImm <ValueType vt> : PatLeaf <(vt fpimm), [{
210   return isInlineImmediate(N);
211 }]>;
212
213 class SGPRImm <dag frag> : PatLeaf<frag, [{
214   if (Subtarget->getGeneration() < AMDGPUSubtarget::SOUTHERN_ISLANDS) {
215     return false;
216   }
217   const SIRegisterInfo *SIRI =
218       static_cast<const SIRegisterInfo *>(Subtarget->getRegisterInfo());
219   for (SDNode::use_iterator U = N->use_begin(), E = SDNode::use_end();
220                                                 U != E; ++U) {
221     if (SIRI->isSGPRClass(getOperandRegClass(*U, U.getOperandNo()))) {
222       return true;
223     }
224   }
225   return false;
226 }]>;
227
228 //===----------------------------------------------------------------------===//
229 // Custom Operands
230 //===----------------------------------------------------------------------===//
231
232 def FRAMEri32 : Operand<iPTR> {
233   let MIOperandInfo = (ops i32:$ptr, i32imm:$index);
234 }
235
236 def sopp_brtarget : Operand<OtherVT> {
237   let EncoderMethod = "getSOPPBrEncoding";
238   let OperandType = "OPERAND_PCREL";
239 }
240
241 include "SIInstrFormats.td"
242 include "VIInstrFormats.td"
243
244 let OperandType = "OPERAND_IMMEDIATE" in {
245
246 def offen : Operand<i1> {
247   let PrintMethod = "printOffen";
248 }
249 def idxen : Operand<i1> {
250   let PrintMethod = "printIdxen";
251 }
252 def addr64 : Operand<i1> {
253   let PrintMethod = "printAddr64";
254 }
255 def mbuf_offset : Operand<i16> {
256   let PrintMethod = "printMBUFOffset";
257 }
258 def ds_offset : Operand<i16> {
259   let PrintMethod = "printDSOffset";
260 }
261 def ds_offset0 : Operand<i8> {
262   let PrintMethod = "printDSOffset0";
263 }
264 def ds_offset1 : Operand<i8> {
265   let PrintMethod = "printDSOffset1";
266 }
267 def glc : Operand <i1> {
268   let PrintMethod = "printGLC";
269 }
270 def slc : Operand <i1> {
271   let PrintMethod = "printSLC";
272 }
273 def tfe : Operand <i1> {
274   let PrintMethod = "printTFE";
275 }
276
277 def omod : Operand <i32> {
278   let PrintMethod = "printOModSI";
279 }
280
281 def ClampMod : Operand <i1> {
282   let PrintMethod = "printClampSI";
283 }
284
285 } // End OperandType = "OPERAND_IMMEDIATE"
286
287 //===----------------------------------------------------------------------===//
288 // Complex patterns
289 //===----------------------------------------------------------------------===//
290
291 def DS1Addr1Offset : ComplexPattern<i32, 2, "SelectDS1Addr1Offset">;
292 def DS64Bit4ByteAligned : ComplexPattern<i32, 3, "SelectDS64Bit4ByteAligned">;
293
294 def MUBUFAddr32 : ComplexPattern<i64, 9, "SelectMUBUFAddr32">;
295 def MUBUFAddr64 : ComplexPattern<i64, 4, "SelectMUBUFAddr64">;
296 def MUBUFAddr64Atomic : ComplexPattern<i64, 5, "SelectMUBUFAddr64">;
297 def MUBUFScratch : ComplexPattern<i64, 4, "SelectMUBUFScratch">;
298 def MUBUFOffset : ComplexPattern<i64, 6, "SelectMUBUFOffset">;
299 def MUBUFOffsetAtomic : ComplexPattern<i64, 4, "SelectMUBUFOffset">;
300
301 def VOP3Mods0 : ComplexPattern<untyped, 4, "SelectVOP3Mods0">;
302 def VOP3Mods0Clamp : ComplexPattern<untyped, 3, "SelectVOP3Mods0Clamp">;
303 def VOP3Mods0Clamp0OMod : ComplexPattern<untyped, 4, "SelectVOP3Mods0Clamp0OMod">;
304 def VOP3Mods  : ComplexPattern<untyped, 2, "SelectVOP3Mods">;
305
306 //===----------------------------------------------------------------------===//
307 // SI assembler operands
308 //===----------------------------------------------------------------------===//
309
310 def SIOperand {
311   int ZERO = 0x80;
312   int VCC = 0x6A;
313   int FLAT_SCR = 0x68;
314 }
315
316 def SRCMODS {
317   int NONE = 0;
318 }
319
320 def DSTCLAMP {
321   int NONE = 0;
322 }
323
324 def DSTOMOD {
325   int NONE = 0;
326 }
327
328 //===----------------------------------------------------------------------===//
329 //
330 // SI Instruction multiclass helpers.
331 //
332 // Instructions with _32 take 32-bit operands.
333 // Instructions with _64 take 64-bit operands.
334 //
335 // VOP_* instructions can use either a 32-bit or 64-bit encoding.  The 32-bit
336 // encoding is the standard encoding, but instruction that make use of
337 // any of the instruction modifiers must use the 64-bit encoding.
338 //
339 // Instructions with _e32 use the 32-bit encoding.
340 // Instructions with _e64 use the 64-bit encoding.
341 //
342 //===----------------------------------------------------------------------===//
343
344 class SIMCInstr <string pseudo, int subtarget> {
345   string PseudoInstr = pseudo;
346   int Subtarget = subtarget;
347 }
348
349 //===----------------------------------------------------------------------===//
350 // EXP classes
351 //===----------------------------------------------------------------------===//
352
353 class EXPCommon : InstSI<
354   (outs),
355   (ins i32imm:$en, i32imm:$tgt, i32imm:$compr, i32imm:$done, i32imm:$vm,
356        VGPR_32:$src0, VGPR_32:$src1, VGPR_32:$src2, VGPR_32:$src3),
357   "exp $en, $tgt, $compr, $done, $vm, $src0, $src1, $src2, $src3",
358   [] > {
359
360   let EXP_CNT = 1;
361   let Uses = [EXEC];
362 }
363
364 multiclass EXP_m {
365
366   let isPseudo = 1 in {
367     def "" : EXPCommon, SIMCInstr <"exp", SISubtarget.NONE> ;
368   }
369
370   def _si : EXPCommon, SIMCInstr <"exp", SISubtarget.SI>, EXPe;
371
372   def _vi : EXPCommon, SIMCInstr <"exp", SISubtarget.VI>, EXPe_vi;
373 }
374
375 //===----------------------------------------------------------------------===//
376 // Scalar classes
377 //===----------------------------------------------------------------------===//
378
379 class SOP1_Pseudo <string opName, dag outs, dag ins, list<dag> pattern> :
380   SOP1 <outs, ins, "", pattern>,
381   SIMCInstr<opName, SISubtarget.NONE> {
382   let isPseudo = 1;
383 }
384
385 class SOP1_Real_si <sop1 op, string opName, dag outs, dag ins, string asm> :
386   SOP1 <outs, ins, asm, []>,
387   SOP1e <op.SI>,
388   SIMCInstr<opName, SISubtarget.SI>;
389
390 class SOP1_Real_vi <sop1 op, string opName, dag outs, dag ins, string asm> :
391   SOP1 <outs, ins, asm, []>,
392   SOP1e <op.VI>,
393   SIMCInstr<opName, SISubtarget.VI>;
394
395 multiclass SOP1_m <sop1 op, string opName, dag outs, dag ins, string asm,
396                    list<dag> pattern> {
397
398   def "" : SOP1_Pseudo <opName, outs, ins, pattern>;
399
400   def _si : SOP1_Real_si <op, opName, outs, ins, asm>;
401
402   def _vi : SOP1_Real_vi <op, opName, outs, ins, asm>;
403
404 }
405
406 multiclass SOP1_32 <sop1 op, string opName, list<dag> pattern> : SOP1_m <
407     op, opName, (outs SReg_32:$dst), (ins SSrc_32:$src0),
408     opName#" $dst, $src0", pattern
409 >;
410
411 multiclass SOP1_64 <sop1 op, string opName, list<dag> pattern> : SOP1_m <
412     op, opName, (outs SReg_64:$dst), (ins SSrc_64:$src0),
413     opName#" $dst, $src0", pattern
414 >;
415
416 // no input, 64-bit output.
417 multiclass SOP1_64_0 <sop1 op, string opName, list<dag> pattern> {
418   def "" : SOP1_Pseudo <opName, (outs SReg_64:$dst), (ins), pattern>;
419
420   def _si : SOP1_Real_si <op, opName, (outs SReg_64:$dst), (ins),
421     opName#" $dst"> {
422     let SSRC0 = 0;
423   }
424
425   def _vi : SOP1_Real_vi <op, opName, (outs SReg_64:$dst), (ins),
426     opName#" $dst"> {
427     let SSRC0 = 0;
428   }
429 }
430
431 // 64-bit input, 32-bit output.
432 multiclass SOP1_32_64 <sop1 op, string opName, list<dag> pattern> : SOP1_m <
433     op, opName, (outs SReg_32:$dst), (ins SSrc_64:$src0),
434     opName#" $dst, $src0", pattern
435 >;
436
437 class SOP2_Pseudo<string opName, dag outs, dag ins, list<dag> pattern> :
438   SOP2<outs, ins, "", pattern>,
439   SIMCInstr<opName, SISubtarget.NONE> {
440   let isPseudo = 1;
441   let Size = 4;
442 }
443
444 class SOP2_Real_si<sop2 op, string opName, dag outs, dag ins, string asm> :
445   SOP2<outs, ins, asm, []>,
446   SOP2e<op.SI>,
447   SIMCInstr<opName, SISubtarget.SI>;
448
449 class SOP2_Real_vi<sop2 op, string opName, dag outs, dag ins, string asm> :
450   SOP2<outs, ins, asm, []>,
451   SOP2e<op.VI>,
452   SIMCInstr<opName, SISubtarget.VI>;
453
454 multiclass SOP2_SELECT_32 <sop2 op, string opName, list<dag> pattern> {
455   def "" : SOP2_Pseudo <opName, (outs SReg_32:$dst),
456     (ins SSrc_32:$src0, SSrc_32:$src1, SCCReg:$scc), pattern>;
457
458   def _si : SOP2_Real_si <op, opName, (outs SReg_32:$dst),
459     (ins SSrc_32:$src0, SSrc_32:$src1, SCCReg:$scc),
460     opName#" $dst, $src0, $src1 [$scc]">;
461
462   def _vi : SOP2_Real_vi <op, opName, (outs SReg_32:$dst),
463     (ins SSrc_32:$src0, SSrc_32:$src1, SCCReg:$scc),
464     opName#" $dst, $src0, $src1 [$scc]">;
465 }
466
467 multiclass SOP2_32 <sop2 op, string opName, list<dag> pattern> {
468   def "" : SOP2_Pseudo <opName, (outs SReg_32:$dst),
469     (ins SSrc_32:$src0, SSrc_32:$src1), pattern>;
470
471   def _si : SOP2_Real_si <op, opName, (outs SReg_32:$dst),
472     (ins SSrc_32:$src0, SSrc_32:$src1), opName#" $dst, $src0, $src1">;
473
474   def _vi : SOP2_Real_vi <op, opName, (outs SReg_32:$dst),
475     (ins SSrc_32:$src0, SSrc_32:$src1), opName#" $dst, $src0, $src1">;
476 }
477
478 multiclass SOP2_64 <sop2 op, string opName, list<dag> pattern> {
479   def "" : SOP2_Pseudo <opName, (outs SReg_64:$dst),
480     (ins SSrc_64:$src0, SSrc_64:$src1), pattern>;
481
482   def _si : SOP2_Real_si <op, opName, (outs SReg_64:$dst),
483     (ins SSrc_64:$src0, SSrc_64:$src1), opName#" $dst, $src0, $src1">;
484
485   def _vi : SOP2_Real_vi <op, opName, (outs SReg_64:$dst),
486     (ins SSrc_64:$src0, SSrc_64:$src1), opName#" $dst, $src0, $src1">;
487 }
488
489 multiclass SOP2_64_32 <sop2 op, string opName, list<dag> pattern> {
490   def "" : SOP2_Pseudo <opName, (outs SReg_64:$dst),
491     (ins SSrc_64:$src0, SSrc_32:$src1), pattern>;
492
493   def _si : SOP2_Real_si <op, opName, (outs SReg_64:$dst),
494     (ins SSrc_64:$src0, SSrc_32:$src1), opName#" $dst, $src0, $src1">;
495
496   def _vi : SOP2_Real_vi <op, opName, (outs SReg_64:$dst),
497     (ins SSrc_64:$src0, SSrc_32:$src1), opName#" $dst, $src0, $src1">;
498 }
499
500
501 class SOPC_Helper <bits<7> op, RegisterOperand rc, ValueType vt,
502                     string opName, PatLeaf cond> : SOPC <
503   op, (outs SCCReg:$dst), (ins rc:$src0, rc:$src1),
504   opName#" $dst, $src0, $src1", []>;
505
506 class SOPC_32<bits<7> op, string opName, PatLeaf cond = COND_NULL>
507   : SOPC_Helper<op, SSrc_32, i32, opName, cond>;
508
509 class SOPC_64<bits<7> op, string opName, PatLeaf cond = COND_NULL>
510   : SOPC_Helper<op, SSrc_64, i64, opName, cond>;
511
512 class SOPK_Pseudo <string opName, dag outs, dag ins, list<dag> pattern> :
513   SOPK <outs, ins, "", pattern>,
514   SIMCInstr<opName, SISubtarget.NONE> {
515   let isPseudo = 1;
516 }
517
518 class SOPK_Real_si <sopk op, string opName, dag outs, dag ins, string asm> :
519   SOPK <outs, ins, asm, []>,
520   SOPKe <op.SI>,
521   SIMCInstr<opName, SISubtarget.SI>;
522
523 class SOPK_Real_vi <sopk op, string opName, dag outs, dag ins, string asm> :
524   SOPK <outs, ins, asm, []>,
525   SOPKe <op.VI>,
526   SIMCInstr<opName, SISubtarget.VI>;
527
528 multiclass SOPK_32 <sopk op, string opName, list<dag> pattern> {
529   def "" : SOPK_Pseudo <opName, (outs SReg_32:$dst), (ins u16imm:$src0),
530     pattern>;
531
532   def _si : SOPK_Real_si <op, opName, (outs SReg_32:$dst), (ins u16imm:$src0),
533     opName#" $dst, $src0">;
534
535   def _vi : SOPK_Real_vi <op, opName, (outs SReg_32:$dst), (ins u16imm:$src0),
536     opName#" $dst, $src0">;
537 }
538
539 multiclass SOPK_SCC <sopk op, string opName, list<dag> pattern> {
540   def "" : SOPK_Pseudo <opName, (outs SCCReg:$dst),
541     (ins SReg_32:$src0, u16imm:$src1), pattern>;
542
543   def _si : SOPK_Real_si <op, opName, (outs SCCReg:$dst),
544     (ins SReg_32:$src0, u16imm:$src1), opName#" $dst, $src0">;
545
546   def _vi : SOPK_Real_vi <op, opName, (outs SCCReg:$dst),
547     (ins SReg_32:$src0, u16imm:$src1), opName#" $dst, $src0">;
548 }
549
550 //===----------------------------------------------------------------------===//
551 // SMRD classes
552 //===----------------------------------------------------------------------===//
553
554 class SMRD_Pseudo <string opName, dag outs, dag ins, list<dag> pattern> :
555   SMRD <outs, ins, "", pattern>,
556   SIMCInstr<opName, SISubtarget.NONE> {
557   let isPseudo = 1;
558 }
559
560 class SMRD_Real_si <bits<5> op, string opName, bit imm, dag outs, dag ins,
561                     string asm> :
562   SMRD <outs, ins, asm, []>,
563   SMRDe <op, imm>,
564   SIMCInstr<opName, SISubtarget.SI>;
565
566 class SMRD_Real_vi <bits<8> op, string opName, bit imm, dag outs, dag ins,
567                     string asm> :
568   SMRD <outs, ins, asm, []>,
569   SMEMe_vi <op, imm>,
570   SIMCInstr<opName, SISubtarget.VI>;
571
572 multiclass SMRD_m <bits<5> op, string opName, bit imm, dag outs, dag ins,
573                    string asm, list<dag> pattern> {
574
575   def "" : SMRD_Pseudo <opName, outs, ins, pattern>;
576
577   def _si : SMRD_Real_si <op, opName, imm, outs, ins, asm>;
578
579   def _vi : SMRD_Real_vi <{0, 0, 0, op}, opName, imm, outs, ins, asm>;
580 }
581
582 multiclass SMRD_Helper <bits<5> op, string opName, RegisterClass baseClass,
583                         RegisterClass dstClass> {
584   defm _IMM : SMRD_m <
585     op, opName#"_IMM", 1, (outs dstClass:$dst),
586     (ins baseClass:$sbase, u32imm:$offset),
587     opName#" $dst, $sbase, $offset", []
588   >;
589
590   defm _SGPR : SMRD_m <
591     op, opName#"_SGPR", 0, (outs dstClass:$dst),
592     (ins baseClass:$sbase, SReg_32:$soff),
593     opName#" $dst, $sbase, $soff", []
594   >;
595 }
596
597 //===----------------------------------------------------------------------===//
598 // Vector ALU classes
599 //===----------------------------------------------------------------------===//
600
601 // This must always be right before the operand being input modified.
602 def InputMods : OperandWithDefaultOps <i32, (ops (i32 0))> {
603   let PrintMethod = "printOperandAndMods";
604 }
605 def InputModsNoDefault : Operand <i32> {
606   let PrintMethod = "printOperandAndMods";
607 }
608
609 class getNumSrcArgs<ValueType Src1, ValueType Src2> {
610   int ret =
611     !if (!eq(Src1.Value, untyped.Value),      1,   // VOP1
612          !if (!eq(Src2.Value, untyped.Value), 2,   // VOP2
613                                               3)); // VOP3
614 }
615
616 // Returns the register class to use for the destination of VOP[123C]
617 // instructions for the given VT.
618 class getVALUDstForVT<ValueType VT> {
619   RegisterClass ret = !if(!eq(VT.Size, 32), VGPR_32,
620                           !if(!eq(VT.Size, 64), VReg_64,
621                             SReg_64)); // else VT == i1
622 }
623
624 // Returns the register class to use for source 0 of VOP[12C]
625 // instructions for the given VT.
626 class getVOPSrc0ForVT<ValueType VT> {
627   RegisterOperand ret = !if(!eq(VT.Size, 32), VSrc_32, VSrc_64);
628 }
629
630 // Returns the register class to use for source 1 of VOP[12C] for the
631 // given VT.
632 class getVOPSrc1ForVT<ValueType VT> {
633   RegisterClass ret = !if(!eq(VT.Size, 32), VGPR_32, VReg_64);
634 }
635
636 // Returns the register class to use for sources of VOP3 instructions for the
637 // given VT.
638 class getVOP3SrcForVT<ValueType VT> {
639   RegisterOperand ret = !if(!eq(VT.Size, 32), VCSrc_32, VCSrc_64);
640 }
641
642 // Returns 1 if the source arguments have modifiers, 0 if they do not.
643 class hasModifiers<ValueType SrcVT> {
644   bit ret = !if(!eq(SrcVT.Value, f32.Value), 1,
645             !if(!eq(SrcVT.Value, f64.Value), 1, 0));
646 }
647
648 // Returns the input arguments for VOP[12C] instructions for the given SrcVT.
649 class getIns32 <RegisterOperand Src0RC, RegisterClass Src1RC, int NumSrcArgs> {
650   dag ret = !if(!eq(NumSrcArgs, 1), (ins Src0RC:$src0),               // VOP1
651             !if(!eq(NumSrcArgs, 2), (ins Src0RC:$src0, Src1RC:$src1), // VOP2
652                                     (ins)));
653 }
654
655 // Returns the input arguments for VOP3 instructions for the given SrcVT.
656 class getIns64 <RegisterOperand Src0RC, RegisterOperand Src1RC,
657                 RegisterOperand Src2RC, int NumSrcArgs,
658                 bit HasModifiers> {
659
660   dag ret =
661     !if (!eq(NumSrcArgs, 1),
662       !if (!eq(HasModifiers, 1),
663         // VOP1 with modifiers
664         (ins InputModsNoDefault:$src0_modifiers, Src0RC:$src0,
665              ClampMod:$clamp, omod:$omod)
666       /* else */,
667         // VOP1 without modifiers
668         (ins Src0RC:$src0)
669       /* endif */ ),
670     !if (!eq(NumSrcArgs, 2),
671       !if (!eq(HasModifiers, 1),
672         // VOP 2 with modifiers
673         (ins InputModsNoDefault:$src0_modifiers, Src0RC:$src0,
674              InputModsNoDefault:$src1_modifiers, Src1RC:$src1,
675              ClampMod:$clamp, omod:$omod)
676       /* else */,
677         // VOP2 without modifiers
678         (ins Src0RC:$src0, Src1RC:$src1)
679       /* endif */ )
680     /* NumSrcArgs == 3 */,
681       !if (!eq(HasModifiers, 1),
682         // VOP3 with modifiers
683         (ins InputModsNoDefault:$src0_modifiers, Src0RC:$src0,
684              InputModsNoDefault:$src1_modifiers, Src1RC:$src1,
685              InputModsNoDefault:$src2_modifiers, Src2RC:$src2,
686              ClampMod:$clamp, omod:$omod)
687       /* else */,
688         // VOP3 without modifiers
689         (ins Src0RC:$src0, Src1RC:$src1, Src2RC:$src2)
690       /* endif */ )));
691 }
692
693 // Returns the assembly string for the inputs and outputs of a VOP[12C]
694 // instruction.  This does not add the _e32 suffix, so it can be reused
695 // by getAsm64.
696 class getAsm32 <int NumSrcArgs> {
697   string src1 = ", $src1";
698   string src2 = ", $src2";
699   string ret = " $dst, $src0"#
700                !if(!eq(NumSrcArgs, 1), "", src1)#
701                !if(!eq(NumSrcArgs, 3), src2, "");
702 }
703
704 // Returns the assembly string for the inputs and outputs of a VOP3
705 // instruction.
706 class getAsm64 <int NumSrcArgs, bit HasModifiers> {
707   string src0 = !if(!eq(NumSrcArgs, 1), "$src0_modifiers", "$src0_modifiers,");
708   string src1 = !if(!eq(NumSrcArgs, 1), "",
709                    !if(!eq(NumSrcArgs, 2), " $src1_modifiers",
710                                            " $src1_modifiers,"));
711   string src2 = !if(!eq(NumSrcArgs, 3), " $src2_modifiers", "");
712   string ret =
713   !if(!eq(HasModifiers, 0),
714       getAsm32<NumSrcArgs>.ret,
715       " $dst, "#src0#src1#src2#"$clamp"#"$omod");
716 }
717
718
719 class VOPProfile <list<ValueType> _ArgVT> {
720
721   field list<ValueType> ArgVT = _ArgVT;
722
723   field ValueType DstVT = ArgVT[0];
724   field ValueType Src0VT = ArgVT[1];
725   field ValueType Src1VT = ArgVT[2];
726   field ValueType Src2VT = ArgVT[3];
727   field RegisterClass DstRC = getVALUDstForVT<DstVT>.ret;
728   field RegisterOperand Src0RC32 = getVOPSrc0ForVT<Src0VT>.ret;
729   field RegisterClass Src1RC32 = getVOPSrc1ForVT<Src1VT>.ret;
730   field RegisterOperand Src0RC64 = getVOP3SrcForVT<Src0VT>.ret;
731   field RegisterOperand Src1RC64 = getVOP3SrcForVT<Src1VT>.ret;
732   field RegisterOperand Src2RC64 = getVOP3SrcForVT<Src2VT>.ret;
733
734   field int NumSrcArgs = getNumSrcArgs<Src1VT, Src2VT>.ret;
735   field bit HasModifiers = hasModifiers<Src0VT>.ret;
736
737   field dag Outs = (outs DstRC:$dst);
738
739   field dag Ins32 = getIns32<Src0RC32, Src1RC32, NumSrcArgs>.ret;
740   field dag Ins64 = getIns64<Src0RC64, Src1RC64, Src2RC64, NumSrcArgs,
741                              HasModifiers>.ret;
742
743   field string Asm32 = "_e32"#getAsm32<NumSrcArgs>.ret;
744   field string Asm64 = getAsm64<NumSrcArgs, HasModifiers>.ret;
745 }
746
747 def VOP_F32_F32 : VOPProfile <[f32, f32, untyped, untyped]>;
748 def VOP_F32_F64 : VOPProfile <[f32, f64, untyped, untyped]>;
749 def VOP_F32_I32 : VOPProfile <[f32, i32, untyped, untyped]>;
750 def VOP_F64_F32 : VOPProfile <[f64, f32, untyped, untyped]>;
751 def VOP_F64_F64 : VOPProfile <[f64, f64, untyped, untyped]>;
752 def VOP_F64_I32 : VOPProfile <[f64, i32, untyped, untyped]>;
753 def VOP_I32_F32 : VOPProfile <[i32, f32, untyped, untyped]>;
754 def VOP_I32_F64 : VOPProfile <[i32, f64, untyped, untyped]>;
755 def VOP_I32_I32 : VOPProfile <[i32, i32, untyped, untyped]>;
756
757 def VOP_F32_F32_F32 : VOPProfile <[f32, f32, f32, untyped]>;
758 def VOP_F32_F32_I32 : VOPProfile <[f32, f32, i32, untyped]>;
759 def VOP_F64_F64_F64 : VOPProfile <[f64, f64, f64, untyped]>;
760 def VOP_F64_F64_I32 : VOPProfile <[f64, f64, i32, untyped]>;
761 def VOP_I32_F32_F32 : VOPProfile <[i32, f32, f32, untyped]>;
762 def VOP_I32_F32_I32 : VOPProfile <[i32, f32, i32, untyped]>;
763 def VOP_I32_I32_I32 : VOPProfile <[i32, i32, i32, untyped]>;
764 def VOP_I32_I32_I32_VCC : VOPProfile <[i32, i32, i32, untyped]> {
765   let Src0RC32 = VCSrc_32;
766 }
767
768 def VOP_I1_F32_I32 : VOPProfile <[i1, f32, i32, untyped]> {
769   let Ins64 = (ins InputModsNoDefault:$src0_modifiers, Src0RC64:$src0, Src1RC64:$src1);
770   let Asm64 = " $dst, $src0_modifiers, $src1";
771 }
772
773 def VOP_I1_F64_I32 : VOPProfile <[i1, f64, i32, untyped]> {
774   let Ins64 = (ins InputModsNoDefault:$src0_modifiers, Src0RC64:$src0, Src1RC64:$src1);
775   let Asm64 = " $dst, $src0_modifiers, $src1";
776 }
777
778 def VOP_I64_I64_I32 : VOPProfile <[i64, i64, i32, untyped]>;
779 def VOP_I64_I32_I64 : VOPProfile <[i64, i32, i64, untyped]>;
780 def VOP_I64_I64_I64 : VOPProfile <[i64, i64, i64, untyped]>;
781
782 def VOP_F32_F32_F32_F32 : VOPProfile <[f32, f32, f32, f32]>;
783 def VOP_F64_F64_F64_F64 : VOPProfile <[f64, f64, f64, f64]>;
784 def VOP_I32_I32_I32_I32 : VOPProfile <[i32, i32, i32, i32]>;
785 def VOP_I64_I32_I32_I64 : VOPProfile <[i64, i32, i32, i64]>;
786
787
788 class VOP <string opName> {
789   string OpName = opName;
790 }
791
792 class VOP2_REV <string revOp, bit isOrig> {
793   string RevOp = revOp;
794   bit IsOrig = isOrig;
795 }
796
797 class AtomicNoRet <string noRetOp, bit isRet> {
798   string NoRetOp = noRetOp;
799   bit IsRet = isRet;
800 }
801
802 class VOP1_Pseudo <dag outs, dag ins, list<dag> pattern, string opName> :
803   VOP1Common <outs, ins, "", pattern>,
804   VOP <opName>,
805   SIMCInstr <opName#"_e32", SISubtarget.NONE> {
806   let isPseudo = 1;
807 }
808
809 multiclass VOP1_m <vop1 op, dag outs, dag ins, string asm, list<dag> pattern,
810                    string opName> {
811   def "" : VOP1_Pseudo <outs, ins, pattern, opName>;
812
813   def _si : VOP1<op.SI, outs, ins, asm, []>,
814             SIMCInstr <opName#"_e32", SISubtarget.SI>;
815   def _vi : VOP1<op.VI, outs, ins, asm, []>,
816             SIMCInstr <opName#"_e32", SISubtarget.VI>;
817 }
818
819 multiclass VOP1SI_m <vop1 op, dag outs, dag ins, string asm, list<dag> pattern,
820                    string opName> {
821   def "" : VOP1_Pseudo <outs, ins, pattern, opName>;
822
823   def _si : VOP1<op.SI, outs, ins, asm, []>,
824             SIMCInstr <opName#"_e32", SISubtarget.SI>;
825   // No VI instruction. This class is for SI only.
826 }
827
828 class VOP2_Pseudo <dag outs, dag ins, list<dag> pattern, string opName> :
829   VOP2Common <outs, ins, "", pattern>,
830   VOP <opName>,
831   SIMCInstr<opName#"_e32", SISubtarget.NONE> {
832   let isPseudo = 1;
833 }
834
835 multiclass VOP2SI_m <vop2 op, dag outs, dag ins, string asm, list<dag> pattern,
836                      string opName, string revOp> {
837   def "" : VOP2_Pseudo <outs, ins, pattern, opName>,
838            VOP2_REV<revOp#"_e32", !eq(revOp, opName)>;
839
840   def _si : VOP2 <op.SI, outs, ins, opName#asm, []>,
841             SIMCInstr <opName#"_e32", SISubtarget.SI>;
842 }
843
844 multiclass VOP2_m <vop2 op, dag outs, dag ins, string asm, list<dag> pattern,
845                    string opName, string revOp> {
846   def "" : VOP2_Pseudo <outs, ins, pattern, opName>,
847            VOP2_REV<revOp#"_e32", !eq(revOp, opName)>;
848
849   def _si : VOP2 <op.SI, outs, ins, opName#asm, []>,
850             SIMCInstr <opName#"_e32", SISubtarget.SI>;
851   def _vi : VOP2 <op.VI, outs, ins, opName#asm, []>,
852             SIMCInstr <opName#"_e32", SISubtarget.VI>;
853 }
854
855 class VOP3DisableFields <bit HasSrc1, bit HasSrc2, bit HasModifiers> {
856
857   bits<2> src0_modifiers = !if(HasModifiers, ?, 0);
858   bits<2> src1_modifiers = !if(HasModifiers, !if(HasSrc1, ?, 0), 0);
859   bits<2> src2_modifiers = !if(HasModifiers, !if(HasSrc2, ? ,0) ,0);
860   bits<2> omod = !if(HasModifiers, ?, 0);
861   bits<1> clamp = !if(HasModifiers, ?, 0);
862   bits<9> src1 = !if(HasSrc1, ?, 0);
863   bits<9> src2 = !if(HasSrc2, ?, 0);
864 }
865
866 class VOP3_Pseudo <dag outs, dag ins, list<dag> pattern, string opName> :
867   VOP3Common <outs, ins, "", pattern>,
868   VOP <opName>,
869   SIMCInstr<opName#"_e64", SISubtarget.NONE> {
870   let isPseudo = 1;
871 }
872
873 class VOP3_Real_si <bits<9> op, dag outs, dag ins, string asm, string opName> :
874   VOP3Common <outs, ins, asm, []>,
875   VOP3e <op>,
876   SIMCInstr<opName#"_e64", SISubtarget.SI>;
877
878 class VOP3_Real_vi <bits<10> op, dag outs, dag ins, string asm, string opName> :
879   VOP3Common <outs, ins, asm, []>,
880   VOP3e_vi <op>,
881   SIMCInstr <opName#"_e64", SISubtarget.VI>;
882
883 class VOP3b_Real_si <bits<9> op, dag outs, dag ins, string asm, string opName> :
884   VOP3Common <outs, ins, asm, []>,
885   VOP3be <op>,
886   SIMCInstr<opName#"_e64", SISubtarget.SI>;
887
888 class VOP3b_Real_vi <bits<10> op, dag outs, dag ins, string asm, string opName> :
889   VOP3Common <outs, ins, asm, []>,
890   VOP3be_vi <op>,
891   SIMCInstr <opName#"_e64", SISubtarget.VI>;
892
893 multiclass VOP3_m <vop op, dag outs, dag ins, string asm, list<dag> pattern,
894                    string opName, int NumSrcArgs, bit HasMods = 1> {
895
896   def "" : VOP3_Pseudo <outs, ins, pattern, opName>;
897
898   def _si : VOP3_Real_si <op.SI3, outs, ins, asm, opName>,
899             VOP3DisableFields<!if(!eq(NumSrcArgs, 1), 0, 1),
900                               !if(!eq(NumSrcArgs, 2), 0, 1),
901                               HasMods>;
902   def _vi : VOP3_Real_vi <op.VI3, outs, ins, asm, opName>,
903             VOP3DisableFields<!if(!eq(NumSrcArgs, 1), 0, 1),
904                               !if(!eq(NumSrcArgs, 2), 0, 1),
905                               HasMods>;
906 }
907
908 // VOP3_m without source modifiers
909 multiclass VOP3_m_nosrcmod <vop op, dag outs, dag ins, string asm, list<dag> pattern,
910                    string opName, int NumSrcArgs, bit HasMods = 1> {
911
912   def "" : VOP3_Pseudo <outs, ins, pattern, opName>;
913
914   let src0_modifiers = 0,
915       src1_modifiers = 0,
916       src2_modifiers = 0 in {
917     def _si : VOP3_Real_si <op.SI3, outs, ins, asm, opName>;
918     def _vi : VOP3_Real_vi <op.VI3, outs, ins, asm, opName>;
919   }
920 }
921
922 multiclass VOP3_1_m <vop op, dag outs, dag ins, string asm,
923                      list<dag> pattern, string opName, bit HasMods = 1> {
924
925   def "" : VOP3_Pseudo <outs, ins, pattern, opName>;
926
927   def _si : VOP3_Real_si <op.SI3, outs, ins, asm, opName>,
928             VOP3DisableFields<0, 0, HasMods>;
929
930   def _vi : VOP3_Real_vi <op.VI3, outs, ins, asm, opName>,
931             VOP3DisableFields<0, 0, HasMods>;
932 }
933
934 multiclass VOP3SI_1_m <vop op, dag outs, dag ins, string asm,
935                      list<dag> pattern, string opName, bit HasMods = 1> {
936
937   def "" : VOP3_Pseudo <outs, ins, pattern, opName>;
938
939   def _si : VOP3_Real_si <op.SI3, outs, ins, asm, opName>,
940             VOP3DisableFields<0, 0, HasMods>;
941   // No VI instruction. This class is for SI only.
942 }
943
944 multiclass VOP3_2_m <vop op, dag outs, dag ins, string asm,
945                      list<dag> pattern, string opName, string revOp,
946                      bit HasMods = 1, bit UseFullOp = 0> {
947
948   def "" : VOP3_Pseudo <outs, ins, pattern, opName>,
949            VOP2_REV<revOp#"_e64", !eq(revOp, opName)>;
950
951   def _si : VOP3_Real_si <op.SI3, outs, ins, asm, opName>,
952             VOP3DisableFields<1, 0, HasMods>;
953
954   def _vi : VOP3_Real_vi <op.VI3, outs, ins, asm, opName>,
955             VOP3DisableFields<1, 0, HasMods>;
956 }
957
958 multiclass VOP3SI_2_m <vop op, dag outs, dag ins, string asm,
959                      list<dag> pattern, string opName, string revOp,
960                      bit HasMods = 1, bit UseFullOp = 0> {
961
962   def "" : VOP3_Pseudo <outs, ins, pattern, opName>,
963            VOP2_REV<revOp#"_e64", !eq(revOp, opName)>;
964
965   def _si : VOP3_Real_si <op.SI3, outs, ins, asm, opName>,
966             VOP3DisableFields<1, 0, HasMods>;
967
968   // No VI instruction. This class is for SI only.
969 }
970
971 // XXX - Is v_div_scale_{f32|f64} only available in vop3b without
972 // option of implicit vcc use?
973 multiclass VOP3b_2_m <vop op, dag outs, dag ins, string asm,
974                       list<dag> pattern, string opName, string revOp,
975                       bit HasMods = 1, bit UseFullOp = 0> {
976   def "" : VOP3_Pseudo <outs, ins, pattern, opName>,
977            VOP2_REV<revOp#"_e64", !eq(revOp, opName)>;
978
979   // The VOP2 variant puts the carry out into VCC, the VOP3 variant
980   // can write it into any SGPR. We currently don't use the carry out,
981   // so for now hardcode it to VCC as well.
982   let sdst = SIOperand.VCC, Defs = [VCC] in {
983     def _si : VOP3b_Real_si <op.SI3, outs, ins, asm, opName>,
984               VOP3DisableFields<1, 0, HasMods>;
985
986     def _vi : VOP3b_Real_vi <op.VI3, outs, ins, asm, opName>,
987               VOP3DisableFields<1, 0, HasMods>;
988   } // End sdst = SIOperand.VCC, Defs = [VCC]
989 }
990
991 multiclass VOP3b_3_m <vop op, dag outs, dag ins, string asm,
992                       list<dag> pattern, string opName, string revOp,
993                       bit HasMods = 1, bit UseFullOp = 0> {
994   def "" : VOP3_Pseudo <outs, ins, pattern, opName>;
995
996
997   def _si : VOP3b_Real_si <op.SI3, outs, ins, asm, opName>,
998             VOP3DisableFields<1, 1, HasMods>;
999
1000   def _vi : VOP3b_Real_vi <op.VI3, outs, ins, asm, opName>,
1001             VOP3DisableFields<1, 1, HasMods>;
1002 }
1003
1004 multiclass VOP3_C_m <vop op, dag outs, dag ins, string asm,
1005                      list<dag> pattern, string opName,
1006                      bit HasMods, bit defExec> {
1007
1008   def "" : VOP3_Pseudo <outs, ins, pattern, opName>;
1009
1010   def _si : VOP3_Real_si <op.SI3, outs, ins, asm, opName>,
1011             VOP3DisableFields<1, 0, HasMods> {
1012     let Defs = !if(defExec, [EXEC], []);
1013   }
1014
1015   def _vi : VOP3_Real_vi <op.VI3, outs, ins, asm, opName>,
1016             VOP3DisableFields<1, 0, HasMods> {
1017     let Defs = !if(defExec, [EXEC], []);
1018   }
1019 }
1020
1021 // An instruction that is VOP2 on SI and VOP3 on VI, no modifiers.
1022 multiclass VOP2SI_3VI_m <vop3 op, string opName, dag outs, dag ins,
1023                          string asm, list<dag> pattern = []> {
1024   let isPseudo = 1 in {
1025     def "" : VOPAnyCommon <outs, ins, "", pattern>,
1026              SIMCInstr<opName, SISubtarget.NONE>;
1027   }
1028
1029   def _si : VOP2 <op.SI3{5-0}, outs, ins, asm, []>,
1030             SIMCInstr <opName, SISubtarget.SI>;
1031
1032   def _vi : VOP3Common <outs, ins, asm, []>,
1033             VOP3e_vi <op.VI3>,
1034             VOP3DisableFields <1, 0, 0>,
1035             SIMCInstr <opName, SISubtarget.VI>;
1036 }
1037
1038 multiclass VOP1_Helper <vop1 op, string opName, dag outs,
1039                         dag ins32, string asm32, list<dag> pat32,
1040                         dag ins64, string asm64, list<dag> pat64,
1041                         bit HasMods> {
1042
1043   defm _e32 : VOP1_m <op, outs, ins32, opName#asm32, pat32, opName>;
1044
1045   defm _e64 : VOP3_1_m <op, outs, ins64, opName#"_e64"#asm64, pat64, opName, HasMods>;
1046 }
1047
1048 multiclass VOP1Inst <vop1 op, string opName, VOPProfile P,
1049                      SDPatternOperator node = null_frag> : VOP1_Helper <
1050   op, opName, P.Outs,
1051   P.Ins32, P.Asm32, [],
1052   P.Ins64, P.Asm64,
1053   !if(P.HasModifiers,
1054       [(set P.DstVT:$dst, (node (P.Src0VT (VOP3Mods0 P.Src0VT:$src0,
1055                                 i32:$src0_modifiers, i1:$clamp, i32:$omod))))],
1056       [(set P.DstVT:$dst, (node P.Src0VT:$src0))]),
1057   P.HasModifiers
1058 >;
1059
1060 multiclass VOP1InstSI <vop1 op, string opName, VOPProfile P,
1061                        SDPatternOperator node = null_frag> {
1062
1063   defm _e32 : VOP1SI_m <op, P.Outs, P.Ins32, opName#P.Asm32, [], opName>;
1064
1065   defm _e64 : VOP3SI_1_m <op, P.Outs, P.Ins64, opName#P.Asm64,
1066     !if(P.HasModifiers,
1067       [(set P.DstVT:$dst, (node (P.Src0VT (VOP3Mods0 P.Src0VT:$src0,
1068                                 i32:$src0_modifiers, i1:$clamp, i32:$omod))))],
1069       [(set P.DstVT:$dst, (node P.Src0VT:$src0))]),
1070     opName, P.HasModifiers>;
1071 }
1072
1073 multiclass VOP2_Helper <vop2 op, string opName, dag outs,
1074                         dag ins32, string asm32, list<dag> pat32,
1075                         dag ins64, string asm64, list<dag> pat64,
1076                         string revOp, bit HasMods> {
1077   defm _e32 : VOP2_m <op, outs, ins32, asm32, pat32, opName, revOp>;
1078
1079   defm _e64 : VOP3_2_m <op,
1080     outs, ins64, opName#"_e64"#asm64, pat64, opName, revOp, HasMods
1081   >;
1082 }
1083
1084 multiclass VOP2Inst <vop2 op, string opName, VOPProfile P,
1085                      SDPatternOperator node = null_frag,
1086                      string revOp = opName> : VOP2_Helper <
1087   op, opName, P.Outs,
1088   P.Ins32, P.Asm32, [],
1089   P.Ins64, P.Asm64,
1090   !if(P.HasModifiers,
1091       [(set P.DstVT:$dst,
1092            (node (P.Src0VT (VOP3Mods0 P.Src0VT:$src0, i32:$src0_modifiers,
1093                                       i1:$clamp, i32:$omod)),
1094                  (P.Src1VT (VOP3Mods P.Src1VT:$src1, i32:$src1_modifiers))))],
1095       [(set P.DstVT:$dst, (node P.Src0VT:$src0, P.Src1VT:$src1))]),
1096   revOp, P.HasModifiers
1097 >;
1098
1099 multiclass VOP2InstSI <vop2 op, string opName, VOPProfile P,
1100                        SDPatternOperator node = null_frag,
1101                        string revOp = opName> {
1102   defm _e32 : VOP2SI_m <op, P.Outs, P.Ins32, P.Asm32, [], opName, revOp>;
1103
1104   defm _e64 : VOP3SI_2_m <op, P.Outs, P.Ins64, opName#"_e64"#P.Asm64,
1105     !if(P.HasModifiers,
1106         [(set P.DstVT:$dst,
1107              (node (P.Src0VT (VOP3Mods0 P.Src0VT:$src0, i32:$src0_modifiers,
1108                                         i1:$clamp, i32:$omod)),
1109                    (P.Src1VT (VOP3Mods P.Src1VT:$src1, i32:$src1_modifiers))))],
1110         [(set P.DstVT:$dst, (node P.Src0VT:$src0, P.Src1VT:$src1))]),
1111     opName, revOp, P.HasModifiers>;
1112 }
1113
1114 multiclass VOP2b_Helper <vop2 op, string opName, dag outs,
1115                          dag ins32, string asm32, list<dag> pat32,
1116                          dag ins64, string asm64, list<dag> pat64,
1117                          string revOp, bit HasMods> {
1118
1119   defm _e32 : VOP2_m <op, outs, ins32, asm32, pat32, opName, revOp>;
1120
1121   defm _e64 : VOP3b_2_m <op,
1122     outs, ins64, opName#"_e64"#asm64, pat64, opName, revOp, HasMods
1123   >;
1124 }
1125
1126 multiclass VOP2bInst <vop2 op, string opName, VOPProfile P,
1127                       SDPatternOperator node = null_frag,
1128                       string revOp = opName> : VOP2b_Helper <
1129   op, opName, P.Outs,
1130   P.Ins32, P.Asm32, [],
1131   P.Ins64, P.Asm64,
1132   !if(P.HasModifiers,
1133       [(set P.DstVT:$dst,
1134            (node (P.Src0VT (VOP3Mods0 P.Src0VT:$src0, i32:$src0_modifiers,
1135                                       i1:$clamp, i32:$omod)),
1136                  (P.Src1VT (VOP3Mods P.Src1VT:$src1, i32:$src1_modifiers))))],
1137       [(set P.DstVT:$dst, (node P.Src0VT:$src0, P.Src1VT:$src1))]),
1138   revOp, P.HasModifiers
1139 >;
1140
1141 // A VOP2 instruction that is VOP3-only on VI.
1142 multiclass VOP2_VI3_Helper <vop23 op, string opName, dag outs,
1143                             dag ins32, string asm32, list<dag> pat32,
1144                             dag ins64, string asm64, list<dag> pat64,
1145                             string revOp, bit HasMods> {
1146   defm _e32 : VOP2SI_m <op, outs, ins32, asm32, pat32, opName, revOp>;
1147
1148   defm _e64 : VOP3_2_m <op, outs, ins64, opName#"_e64"#asm64, pat64, opName,
1149                         revOp, HasMods>;
1150 }
1151
1152 multiclass VOP2_VI3_Inst <vop23 op, string opName, VOPProfile P,
1153                           SDPatternOperator node = null_frag,
1154                           string revOp = opName>
1155                           : VOP2_VI3_Helper <
1156   op, opName, P.Outs,
1157   P.Ins32, P.Asm32, [],
1158   P.Ins64, P.Asm64,
1159   !if(P.HasModifiers,
1160       [(set P.DstVT:$dst,
1161            (node (P.Src0VT (VOP3Mods0 P.Src0VT:$src0, i32:$src0_modifiers,
1162                                       i1:$clamp, i32:$omod)),
1163                  (P.Src1VT (VOP3Mods P.Src1VT:$src1, i32:$src1_modifiers))))],
1164       [(set P.DstVT:$dst, (node P.Src0VT:$src0, P.Src1VT:$src1))]),
1165   revOp, P.HasModifiers
1166 >;
1167
1168 class VOPC_Pseudo <dag outs, dag ins, list<dag> pattern, string opName> :
1169   VOPCCommon <ins, "", pattern>,
1170   VOP <opName>,
1171   SIMCInstr<opName#"_e32", SISubtarget.NONE> {
1172   let isPseudo = 1;
1173 }
1174
1175 multiclass VOPC_m <vopc op, dag outs, dag ins, string asm, list<dag> pattern,
1176                    string opName, bit DefExec> {
1177   def "" : VOPC_Pseudo <outs, ins, pattern, opName>;
1178
1179   def _si : VOPC<op.SI, ins, asm, []>,
1180             SIMCInstr <opName#"_e32", SISubtarget.SI> {
1181     let Defs = !if(DefExec, [EXEC], []);
1182   }
1183
1184   def _vi : VOPC<op.VI, ins, asm, []>,
1185             SIMCInstr <opName#"_e32", SISubtarget.VI> {
1186     let Defs = !if(DefExec, [EXEC], []);
1187   }
1188 }
1189
1190 multiclass VOPC_Helper <vopc op, string opName,
1191                         dag ins32, string asm32, list<dag> pat32,
1192                         dag out64, dag ins64, string asm64, list<dag> pat64,
1193                         bit HasMods, bit DefExec> {
1194   defm _e32 : VOPC_m <op, (outs), ins32, opName#asm32, pat32, opName, DefExec>;
1195
1196   defm _e64 : VOP3_C_m <op, out64, ins64, opName#"_e64"#asm64, pat64,
1197                         opName, HasMods, DefExec>;
1198 }
1199
1200 multiclass VOPCInst <vopc op, string opName,
1201                      VOPProfile P, PatLeaf cond = COND_NULL,
1202                      bit DefExec = 0> : VOPC_Helper <
1203   op, opName,
1204   P.Ins32, P.Asm32, [],
1205   (outs SReg_64:$dst), P.Ins64, P.Asm64,
1206   !if(P.HasModifiers,
1207       [(set i1:$dst,
1208           (setcc (P.Src0VT (VOP3Mods0 P.Src0VT:$src0, i32:$src0_modifiers,
1209                                       i1:$clamp, i32:$omod)),
1210                  (P.Src1VT (VOP3Mods P.Src1VT:$src1, i32:$src1_modifiers)),
1211                  cond))],
1212       [(set i1:$dst, (setcc P.Src0VT:$src0, P.Src1VT:$src1, cond))]),
1213   P.HasModifiers, DefExec
1214 >;
1215
1216 multiclass VOPCClassInst <vopc op, string opName, VOPProfile P,
1217                      bit DefExec = 0> : VOPC_Helper <
1218   op, opName,
1219   P.Ins32, P.Asm32, [],
1220   (outs SReg_64:$dst), P.Ins64, P.Asm64,
1221   !if(P.HasModifiers,
1222       [(set i1:$dst,
1223           (AMDGPUfp_class (P.Src0VT (VOP3Mods0Clamp0OMod P.Src0VT:$src0, i32:$src0_modifiers)), P.Src1VT:$src1))],
1224       [(set i1:$dst, (AMDGPUfp_class P.Src0VT:$src0, P.Src1VT:$src1))]),
1225   P.HasModifiers, DefExec
1226 >;
1227
1228
1229 multiclass VOPC_F32 <vopc op, string opName, PatLeaf cond = COND_NULL> :
1230   VOPCInst <op, opName, VOP_F32_F32_F32, cond>;
1231
1232 multiclass VOPC_F64 <vopc op, string opName, PatLeaf cond = COND_NULL> :
1233   VOPCInst <op, opName, VOP_F64_F64_F64, cond>;
1234
1235 multiclass VOPC_I32 <vopc op, string opName, PatLeaf cond = COND_NULL> :
1236   VOPCInst <op, opName, VOP_I32_I32_I32, cond>;
1237
1238 multiclass VOPC_I64 <vopc op, string opName, PatLeaf cond = COND_NULL> :
1239   VOPCInst <op, opName, VOP_I64_I64_I64, cond>;
1240
1241
1242 multiclass VOPCX <vopc op, string opName, VOPProfile P,
1243                   PatLeaf cond = COND_NULL>
1244   : VOPCInst <op, opName, P, cond, 1>;
1245
1246 multiclass VOPCX_F32 <vopc op, string opName, PatLeaf cond = COND_NULL> :
1247   VOPCX <op, opName, VOP_F32_F32_F32, cond>;
1248
1249 multiclass VOPCX_F64 <vopc op, string opName, PatLeaf cond = COND_NULL> :
1250   VOPCX <op, opName, VOP_F64_F64_F64, cond>;
1251
1252 multiclass VOPCX_I32 <vopc op, string opName, PatLeaf cond = COND_NULL> :
1253   VOPCX <op, opName, VOP_I32_I32_I32, cond>;
1254
1255 multiclass VOPCX_I64 <vopc op, string opName, PatLeaf cond = COND_NULL> :
1256   VOPCX <op, opName, VOP_I64_I64_I64, cond>;
1257
1258 multiclass VOP3_Helper <vop3 op, string opName, dag outs, dag ins, string asm,
1259                         list<dag> pat, int NumSrcArgs, bit HasMods> : VOP3_m <
1260     op, outs, ins, opName#asm, pat, opName, NumSrcArgs, HasMods
1261 >;
1262
1263 multiclass VOPC_CLASS_F32 <vopc op, string opName> :
1264   VOPCClassInst <op, opName, VOP_I1_F32_I32, 0>;
1265
1266 multiclass VOPCX_CLASS_F32 <vopc op, string opName> :
1267   VOPCClassInst <op, opName, VOP_I1_F32_I32, 1>;
1268
1269 multiclass VOPC_CLASS_F64 <vopc op, string opName> :
1270   VOPCClassInst <op, opName, VOP_I1_F64_I32, 0>;
1271
1272 multiclass VOPCX_CLASS_F64 <vopc op, string opName> :
1273   VOPCClassInst <op, opName, VOP_I1_F64_I32, 1>;
1274
1275 multiclass VOP3Inst <vop3 op, string opName, VOPProfile P,
1276                      SDPatternOperator node = null_frag> : VOP3_Helper <
1277   op, opName, P.Outs, P.Ins64, P.Asm64,
1278   !if(!eq(P.NumSrcArgs, 3),
1279     !if(P.HasModifiers,
1280         [(set P.DstVT:$dst,
1281             (node (P.Src0VT (VOP3Mods0 P.Src0VT:$src0, i32:$src0_modifiers,
1282                                        i1:$clamp, i32:$omod)),
1283                   (P.Src1VT (VOP3Mods P.Src1VT:$src1, i32:$src1_modifiers)),
1284                   (P.Src2VT (VOP3Mods P.Src2VT:$src2, i32:$src2_modifiers))))],
1285         [(set P.DstVT:$dst, (node P.Src0VT:$src0, P.Src1VT:$src1,
1286                                   P.Src2VT:$src2))]),
1287   !if(!eq(P.NumSrcArgs, 2),
1288     !if(P.HasModifiers,
1289         [(set P.DstVT:$dst,
1290             (node (P.Src0VT (VOP3Mods0 P.Src0VT:$src0, i32:$src0_modifiers,
1291                                        i1:$clamp, i32:$omod)),
1292                   (P.Src1VT (VOP3Mods P.Src1VT:$src1, i32:$src1_modifiers))))],
1293         [(set P.DstVT:$dst, (node P.Src0VT:$src0, P.Src1VT:$src1))])
1294   /* P.NumSrcArgs == 1 */,
1295     !if(P.HasModifiers,
1296         [(set P.DstVT:$dst,
1297             (node (P.Src0VT (VOP3Mods0 P.Src0VT:$src0, i32:$src0_modifiers,
1298                                        i1:$clamp, i32:$omod))))],
1299         [(set P.DstVT:$dst, (node P.Src0VT:$src0))]))),
1300   P.NumSrcArgs, P.HasModifiers
1301 >;
1302
1303 multiclass VOP3b_Helper <vop op, RegisterClass vrc, RegisterOperand arc,
1304                     string opName, list<dag> pattern> :
1305   VOP3b_3_m <
1306   op, (outs vrc:$vdst, SReg_64:$sdst),
1307       (ins InputModsNoDefault:$src0_modifiers, arc:$src0,
1308            InputModsNoDefault:$src1_modifiers, arc:$src1,
1309            InputModsNoDefault:$src2_modifiers, arc:$src2,
1310            ClampMod:$clamp, omod:$omod),
1311   opName#" $vdst, $sdst, $src0_modifiers, $src1_modifiers, $src2_modifiers"#"$clamp"#"$omod", pattern,
1312   opName, opName, 1, 1
1313 >;
1314
1315 multiclass VOP3b_64 <vop3 op, string opName, list<dag> pattern> :
1316   VOP3b_Helper <op, VReg_64, VSrc_64, opName, pattern>;
1317
1318 multiclass VOP3b_32 <vop3 op, string opName, list<dag> pattern> :
1319   VOP3b_Helper <op, VGPR_32, VSrc_32, opName, pattern>;
1320
1321
1322 class Vop3ModPat<Instruction Inst, VOPProfile P, SDPatternOperator node> : Pat<
1323   (node (P.Src0VT (VOP3Mods0 P.Src0VT:$src0, i32:$src0_modifiers, i1:$clamp, i32:$omod)),
1324         (P.Src1VT (VOP3Mods P.Src1VT:$src1, i32:$src1_modifiers)),
1325         (P.Src2VT (VOP3Mods P.Src2VT:$src2, i32:$src2_modifiers))),
1326   (Inst i32:$src0_modifiers, P.Src0VT:$src0,
1327         i32:$src1_modifiers, P.Src1VT:$src1,
1328         i32:$src2_modifiers, P.Src2VT:$src2,
1329         i1:$clamp,
1330         i32:$omod)>;
1331
1332 //===----------------------------------------------------------------------===//
1333 // Interpolation opcodes
1334 //===----------------------------------------------------------------------===//
1335
1336 class VINTRP_Pseudo <string opName, dag outs, dag ins, list<dag> pattern> :
1337   VINTRPCommon <outs, ins, "", pattern>,
1338   SIMCInstr<opName, SISubtarget.NONE> {
1339   let isPseudo = 1;
1340 }
1341
1342 class VINTRP_Real_si <bits <2> op, string opName, dag outs, dag ins,
1343                       string asm> :
1344   VINTRPCommon <outs, ins, asm, []>,
1345   VINTRPe <op>,
1346   SIMCInstr<opName, SISubtarget.SI>;
1347
1348 class VINTRP_Real_vi <bits <2> op, string opName, dag outs, dag ins,
1349                       string asm> :
1350   VINTRPCommon <outs, ins, asm, []>,
1351   VINTRPe_vi <op>,
1352   SIMCInstr<opName, SISubtarget.VI>;
1353
1354 multiclass VINTRP_m <bits <2> op, string opName, dag outs, dag ins, string asm,
1355                      string disableEncoding = "", string constraints = "",
1356                      list<dag> pattern = []> {
1357   let DisableEncoding = disableEncoding,
1358       Constraints = constraints in {
1359     def "" : VINTRP_Pseudo <opName, outs, ins, pattern>;
1360
1361     def _si : VINTRP_Real_si <op, opName, outs, ins, asm>;
1362
1363     def _vi : VINTRP_Real_vi <op, opName, outs, ins, asm>;
1364   }
1365 }
1366
1367 //===----------------------------------------------------------------------===//
1368 // Vector I/O classes
1369 //===----------------------------------------------------------------------===//
1370
1371 class DS_Pseudo <string opName, dag outs, dag ins, list<dag> pattern> :
1372   DS <outs, ins, "", pattern>,
1373   SIMCInstr <opName, SISubtarget.NONE> {
1374   let isPseudo = 1;
1375 }
1376
1377 class DS_Real_si <bits<8> op, string opName, dag outs, dag ins, string asm> :
1378   DS <outs, ins, asm, []>,
1379   DSe <op>,
1380   SIMCInstr <opName, SISubtarget.SI>;
1381
1382 class DS_Real_vi <bits<8> op, string opName, dag outs, dag ins, string asm> :
1383   DS <outs, ins, asm, []>,
1384   DSe_vi <op>,
1385   SIMCInstr <opName, SISubtarget.VI>;
1386
1387 class DS_1A_Real_si <bits<8> op, string opName, dag outs, dag ins, string asm> :
1388   DS <outs, ins, asm, []>,
1389   DSe <op>,
1390   SIMCInstr <opName, SISubtarget.SI> {
1391
1392   // Single load interpret the 2 i8imm operands as a single i16 offset.
1393   bits<16> offset;
1394   let offset0 = offset{7-0};
1395   let offset1 = offset{15-8};
1396 }
1397
1398 class DS_1A_Real_vi <bits<8> op, string opName, dag outs, dag ins, string asm> :
1399   DS <outs, ins, asm, []>,
1400   DSe_vi <op>,
1401   SIMCInstr <opName, SISubtarget.VI> {
1402
1403   // Single load interpret the 2 i8imm operands as a single i16 offset.
1404   bits<16> offset;
1405   let offset0 = offset{7-0};
1406   let offset1 = offset{15-8};
1407 }
1408
1409 multiclass DS_1A_Load_m <bits<8> op, string opName, dag outs, dag ins, string asm,
1410                          list<dag> pat> {
1411   let hasSideEffects = 0, mayLoad = 1, mayStore = 0 in {
1412     def "" : DS_Pseudo <opName, outs, ins, pat>;
1413
1414     let data0 = 0, data1 = 0 in {
1415       def _si : DS_1A_Real_si <op, opName, outs, ins, asm>;
1416       def _vi : DS_1A_Real_vi <op, opName, outs, ins, asm>;
1417     }
1418   }
1419 }
1420
1421 multiclass DS_Load_Helper <bits<8> op, string asm, RegisterClass regClass>
1422     : DS_1A_Load_m <
1423   op,
1424   asm,
1425   (outs regClass:$vdst),
1426   (ins i1imm:$gds, VGPR_32:$addr, ds_offset:$offset, M0Reg:$m0),
1427   asm#" $vdst, $addr"#"$offset"#" [M0]",
1428   []>;
1429
1430 multiclass DS_Load2_m <bits<8> op, string opName, dag outs, dag ins, string asm,
1431                        list<dag> pat> {
1432   let hasSideEffects = 0, mayLoad = 1, mayStore = 0 in {
1433     def "" : DS_Pseudo <opName, outs, ins, pat>;
1434
1435     let data0 = 0, data1 = 0 in {
1436       def _si : DS_Real_si <op, opName, outs, ins, asm>;
1437       def _vi : DS_Real_vi <op, opName, outs, ins, asm>;
1438     }
1439   }
1440 }
1441
1442 multiclass DS_Load2_Helper <bits<8> op, string asm, RegisterClass regClass>
1443     : DS_Load2_m <
1444   op,
1445   asm,
1446   (outs regClass:$vdst),
1447   (ins i1imm:$gds, VGPR_32:$addr, ds_offset0:$offset0, ds_offset1:$offset1,
1448         M0Reg:$m0),
1449   asm#" $vdst, $addr"#"$offset0"#"$offset1 [M0]",
1450   []>;
1451
1452 multiclass DS_1A_Store_m <bits<8> op, string opName, dag outs, dag ins,
1453                           string asm, list<dag> pat> {
1454   let hasSideEffects = 0, mayLoad = 0, mayStore = 1 in {
1455     def "" : DS_Pseudo <opName, outs, ins, pat>;
1456
1457     let data1 = 0, vdst = 0 in {
1458       def _si : DS_1A_Real_si <op, opName, outs, ins, asm>;
1459       def _vi : DS_1A_Real_vi <op, opName, outs, ins, asm>;
1460     }
1461   }
1462 }
1463
1464 multiclass DS_Store_Helper <bits<8> op, string asm, RegisterClass regClass>
1465     : DS_1A_Store_m <
1466   op,
1467   asm,
1468   (outs),
1469   (ins i1imm:$gds, VGPR_32:$addr, regClass:$data0, ds_offset:$offset, M0Reg:$m0),
1470   asm#" $addr, $data0"#"$offset"#" [M0]",
1471   []>;
1472
1473 multiclass DS_Store_m <bits<8> op, string opName, dag outs, dag ins,
1474                        string asm, list<dag> pat> {
1475   let hasSideEffects = 0, mayLoad = 0, mayStore = 1 in {
1476     def "" : DS_Pseudo <opName, outs, ins, pat>;
1477
1478     let vdst = 0 in {
1479       def _si : DS_Real_si <op, opName, outs, ins, asm>;
1480       def _vi : DS_Real_vi <op, opName, outs, ins, asm>;
1481     }
1482   }
1483 }
1484
1485 multiclass DS_Store2_Helper <bits<8> op, string asm, RegisterClass regClass>
1486     : DS_Store_m <
1487   op,
1488   asm,
1489   (outs),
1490   (ins i1imm:$gds, VGPR_32:$addr, regClass:$data0, regClass:$data1,
1491        ds_offset0:$offset0, ds_offset1:$offset1, M0Reg:$m0),
1492   asm#" $addr, $data0, $data1"#"$offset0"#"$offset1 [M0]",
1493   []>;
1494
1495 // 1 address, 1 data.
1496 multiclass DS_1A1D_RET_m <bits<8> op, string opName, dag outs, dag ins,
1497                           string asm, list<dag> pat, string noRetOp> {
1498   let mayLoad = 1, mayStore = 1,
1499       hasPostISelHook = 1 // Adjusted to no return version.
1500       in {
1501     def "" : DS_Pseudo <opName, outs, ins, pat>,
1502              AtomicNoRet<noRetOp, 1>;
1503
1504     let data1 = 0 in {
1505       def _si : DS_1A_Real_si <op, opName, outs, ins, asm>;
1506       def _vi : DS_1A_Real_vi <op, opName, outs, ins, asm>;
1507     }
1508   }
1509 }
1510
1511 multiclass DS_1A1D_RET <bits<8> op, string asm, RegisterClass rc,
1512                         string noRetOp = ""> : DS_1A1D_RET_m <
1513   op, asm,
1514   (outs rc:$vdst),
1515   (ins i1imm:$gds, VGPR_32:$addr, rc:$data0, ds_offset:$offset, M0Reg:$m0),
1516   asm#" $vdst, $addr, $data0"#"$offset"#" [M0]", [], noRetOp>;
1517
1518 // 1 address, 2 data.
1519 multiclass DS_1A2D_RET_m <bits<8> op, string opName, dag outs, dag ins,
1520                           string asm, list<dag> pat, string noRetOp> {
1521   let mayLoad = 1, mayStore = 1,
1522       hasPostISelHook = 1 // Adjusted to no return version.
1523       in {
1524     def "" : DS_Pseudo <opName, outs, ins, pat>,
1525              AtomicNoRet<noRetOp, 1>;
1526
1527     def _si : DS_1A_Real_si <op, opName, outs, ins, asm>;
1528     def _vi : DS_1A_Real_vi <op, opName, outs, ins, asm>;
1529   }
1530 }
1531
1532 multiclass DS_1A2D_RET <bits<8> op, string asm, RegisterClass rc,
1533                    string noRetOp = ""> : DS_1A2D_RET_m <
1534   op, asm,
1535   (outs rc:$vdst),
1536   (ins i1imm:$gds, VGPR_32:$addr, rc:$data0, rc:$data1, ds_offset:$offset, M0Reg:$m0),
1537   asm#" $vdst, $addr, $data0, $data1"#"$offset"#" [M0]",
1538   [], noRetOp>;
1539
1540 // 1 address, 2 data.
1541 multiclass DS_1A2D_NORET_m <bits<8> op, string opName, dag outs, dag ins,
1542                             string asm, list<dag> pat, string noRetOp> {
1543   let mayLoad = 1, mayStore = 1 in {
1544     def "" : DS_Pseudo <opName, outs, ins, pat>,
1545              AtomicNoRet<noRetOp, 0>;
1546
1547     def _si : DS_1A_Real_si <op, opName, outs, ins, asm>;
1548     def _vi : DS_1A_Real_vi <op, opName, outs, ins, asm>;
1549   }
1550 }
1551
1552 multiclass DS_1A2D_NORET <bits<8> op, string asm, RegisterClass rc,
1553                      string noRetOp = asm> : DS_1A2D_NORET_m <
1554   op, asm,
1555   (outs),
1556   (ins i1imm:$gds, VGPR_32:$addr, rc:$data0, rc:$data1, ds_offset:$offset, M0Reg:$m0),
1557   asm#" $addr, $data0, $data1"#"$offset"#" [M0]",
1558   [], noRetOp>;
1559
1560 // 1 address, 1 data.
1561 multiclass DS_1A1D_NORET_m <bits<8> op, string opName, dag outs, dag ins,
1562                             string asm, list<dag> pat, string noRetOp> {
1563   let mayLoad = 1, mayStore = 1 in {
1564     def "" : DS_Pseudo <opName, outs, ins, pat>,
1565              AtomicNoRet<noRetOp, 0>;
1566
1567     let data1 = 0 in {
1568       def _si : DS_1A_Real_si <op, opName, outs, ins, asm>;
1569       def _vi : DS_1A_Real_vi <op, opName, outs, ins, asm>;
1570     }
1571   }
1572 }
1573
1574 multiclass DS_1A1D_NORET <bits<8> op, string asm, RegisterClass rc,
1575                           string noRetOp = asm> : DS_1A1D_NORET_m <
1576   op, asm,
1577   (outs),
1578   (ins i1imm:$gds, VGPR_32:$addr, rc:$data0, ds_offset:$offset, M0Reg:$m0),
1579   asm#" $addr, $data0"#"$offset"#" [M0]",
1580   [], noRetOp>;
1581
1582 //===----------------------------------------------------------------------===//
1583 // MTBUF classes
1584 //===----------------------------------------------------------------------===//
1585
1586 class MTBUF_Pseudo <string opName, dag outs, dag ins, list<dag> pattern> :
1587   MTBUF <outs, ins, "", pattern>,
1588   SIMCInstr<opName, SISubtarget.NONE> {
1589   let isPseudo = 1;
1590 }
1591
1592 class MTBUF_Real_si <bits<3> op, string opName, dag outs, dag ins,
1593                     string asm> :
1594   MTBUF <outs, ins, asm, []>,
1595   MTBUFe <op>,
1596   SIMCInstr<opName, SISubtarget.SI>;
1597
1598 class MTBUF_Real_vi <bits<4> op, string opName, dag outs, dag ins, string asm> :
1599   MTBUF <outs, ins, asm, []>,
1600   MTBUFe_vi <op>,
1601   SIMCInstr <opName, SISubtarget.VI>;
1602
1603 multiclass MTBUF_m <bits<3> op, string opName, dag outs, dag ins, string asm,
1604                     list<dag> pattern> {
1605
1606   def "" : MTBUF_Pseudo <opName, outs, ins, pattern>;
1607
1608   def _si : MTBUF_Real_si <op, opName, outs, ins, asm>;
1609
1610   def _vi : MTBUF_Real_vi <{0, op{2}, op{1}, op{0}}, opName, outs, ins, asm>;
1611
1612 }
1613
1614 let mayStore = 1, mayLoad = 0 in {
1615
1616 multiclass MTBUF_Store_Helper <bits<3> op, string opName,
1617                                RegisterClass regClass> : MTBUF_m <
1618   op, opName, (outs),
1619   (ins regClass:$vdata, u16imm:$offset, i1imm:$offen, i1imm:$idxen, i1imm:$glc,
1620    i1imm:$addr64, i8imm:$dfmt, i8imm:$nfmt, VGPR_32:$vaddr,
1621    SReg_128:$srsrc, i1imm:$slc, i1imm:$tfe, SCSrc_32:$soffset),
1622   opName#" $vdata, $offset, $offen, $idxen, $glc, $addr64, $dfmt,"
1623         #" $nfmt, $vaddr, $srsrc, $slc, $tfe, $soffset", []
1624 >;
1625
1626 } // mayStore = 1, mayLoad = 0
1627
1628 let mayLoad = 1, mayStore = 0 in {
1629
1630 multiclass MTBUF_Load_Helper <bits<3> op, string opName,
1631                               RegisterClass regClass> : MTBUF_m <
1632   op, opName, (outs regClass:$dst),
1633   (ins u16imm:$offset, i1imm:$offen, i1imm:$idxen, i1imm:$glc, i1imm:$addr64,
1634        i8imm:$dfmt, i8imm:$nfmt, VGPR_32:$vaddr, SReg_128:$srsrc,
1635        i1imm:$slc, i1imm:$tfe, SCSrc_32:$soffset),
1636   opName#" $dst, $offset, $offen, $idxen, $glc, $addr64, $dfmt,"
1637         #" $nfmt, $vaddr, $srsrc, $slc, $tfe, $soffset", []
1638 >;
1639
1640 } // mayLoad = 1, mayStore = 0
1641
1642 //===----------------------------------------------------------------------===//
1643 // MUBUF classes
1644 //===----------------------------------------------------------------------===//
1645
1646 class mubuf <bits<7> si, bits<7> vi = si> {
1647   field bits<7> SI = si;
1648   field bits<7> VI = vi;
1649 }
1650
1651 class MUBUFAddr64Table <bit is_addr64, string suffix = ""> {
1652   bit IsAddr64 = is_addr64;
1653   string OpName = NAME # suffix;
1654 }
1655
1656 class MUBUF_Pseudo <string opName, dag outs, dag ins, list<dag> pattern> :
1657   MUBUF <outs, ins, "", pattern>,
1658   SIMCInstr<opName, SISubtarget.NONE> {
1659   let isPseudo = 1;
1660
1661   // dummy fields, so that we can use let statements around multiclasses
1662   bits<1> offen;
1663   bits<1> idxen;
1664   bits<8> vaddr;
1665   bits<1> glc;
1666   bits<1> slc;
1667   bits<1> tfe;
1668   bits<8> soffset;
1669 }
1670
1671 class MUBUF_Real_si <mubuf op, string opName, dag outs, dag ins,
1672                      string asm> :
1673   MUBUF <outs, ins, asm, []>,
1674   MUBUFe <op.SI>,
1675   SIMCInstr<opName, SISubtarget.SI> {
1676   let lds = 0;
1677 }
1678
1679 class MUBUF_Real_vi <mubuf op, string opName, dag outs, dag ins,
1680                      string asm> :
1681   MUBUF <outs, ins, asm, []>,
1682   MUBUFe_vi <op.VI>,
1683   SIMCInstr<opName, SISubtarget.VI> {
1684   let lds = 0;
1685 }
1686
1687 multiclass MUBUF_m <mubuf op, string opName, dag outs, dag ins, string asm,
1688                     list<dag> pattern> {
1689
1690   def "" : MUBUF_Pseudo <opName, outs, ins, pattern>,
1691            MUBUFAddr64Table <0>;
1692
1693   let addr64 = 0 in {
1694     def _si : MUBUF_Real_si <op, opName, outs, ins, asm>;
1695   }
1696
1697   def _vi : MUBUF_Real_vi <op, opName, outs, ins, asm>;
1698 }
1699
1700 multiclass MUBUFAddr64_m <mubuf op, string opName, dag outs,
1701                           dag ins, string asm, list<dag> pattern> {
1702
1703   def "" : MUBUF_Pseudo <opName, outs, ins, pattern>,
1704            MUBUFAddr64Table <1>;
1705
1706   let addr64 = 1 in {
1707     def _si : MUBUF_Real_si <op, opName, outs, ins, asm>;
1708   }
1709
1710   // There is no VI version. If the pseudo is selected, it should be lowered
1711   // for VI appropriately.
1712 }
1713
1714 class MUBUF_si <bits<7> op, dag outs, dag ins, string asm, list<dag> pattern> :
1715   MUBUF <outs, ins, asm, pattern>, MUBUFe <op> {
1716   let lds = 0;
1717 }
1718
1719 multiclass MUBUFAtomicOffset_m <mubuf op, string opName, dag outs, dag ins,
1720                                 string asm, list<dag> pattern, bit is_return> {
1721
1722   def "" : MUBUF_Pseudo <opName, outs, ins, pattern>,
1723            MUBUFAddr64Table <0, !if(is_return, "_RTN", "")>,
1724            AtomicNoRet<NAME#"_OFFSET", is_return>;
1725
1726   let offen = 0, idxen = 0, tfe = 0, vaddr = 0 in {
1727     let addr64 = 0 in {
1728       def _si : MUBUF_Real_si <op, opName, outs, ins, asm>;
1729     }
1730
1731     def _vi : MUBUF_Real_vi <op, opName, outs, ins, asm>;
1732   }
1733 }
1734
1735 multiclass MUBUFAtomicAddr64_m <mubuf op, string opName, dag outs, dag ins,
1736                                 string asm, list<dag> pattern, bit is_return> {
1737
1738   def "" : MUBUF_Pseudo <opName, outs, ins, pattern>,
1739            MUBUFAddr64Table <1, !if(is_return, "_RTN", "")>,
1740            AtomicNoRet<NAME#"_ADDR64", is_return>;
1741
1742   let offen = 0, idxen = 0, addr64 = 1, tfe = 0 in {
1743     def _si : MUBUF_Real_si <op, opName, outs, ins, asm>;
1744   }
1745
1746   // There is no VI version. If the pseudo is selected, it should be lowered
1747   // for VI appropriately.
1748 }
1749
1750 multiclass MUBUF_Atomic <mubuf op, string name, RegisterClass rc,
1751                          ValueType vt, SDPatternOperator atomic> {
1752
1753   let mayStore = 1, mayLoad = 1, hasPostISelHook = 1 in {
1754
1755     // No return variants
1756     let glc = 0 in {
1757
1758       defm _ADDR64 : MUBUFAtomicAddr64_m <
1759         op, name#"_addr64", (outs),
1760         (ins rc:$vdata, SReg_128:$srsrc, VReg_64:$vaddr,
1761              mbuf_offset:$offset, slc:$slc),
1762         name#" $vdata, $vaddr, $srsrc, 0 addr64"#"$offset"#"$slc", [], 0
1763       >;
1764
1765       defm _OFFSET : MUBUFAtomicOffset_m <
1766         op, name#"_offset", (outs),
1767         (ins rc:$vdata, SReg_128:$srsrc, mbuf_offset:$offset,
1768              SCSrc_32:$soffset, slc:$slc),
1769         name#" $vdata, $srsrc, $soffset"#"$offset"#"$slc", [], 0
1770       >;
1771     } // glc = 0
1772
1773     // Variant that return values
1774     let glc = 1, Constraints = "$vdata = $vdata_in",
1775         DisableEncoding = "$vdata_in"  in {
1776
1777       defm _RTN_ADDR64 : MUBUFAtomicAddr64_m <
1778         op, name#"_rtn_addr64", (outs rc:$vdata),
1779         (ins rc:$vdata_in, SReg_128:$srsrc, VReg_64:$vaddr,
1780              mbuf_offset:$offset, SSrc_32:$soffset, slc:$slc),
1781         name#" $vdata, $vaddr, $srsrc, $soffset addr64"#"$offset"#" glc"#"$slc",
1782         [(set vt:$vdata,
1783          (atomic (MUBUFAddr64Atomic v4i32:$srsrc, i64:$vaddr, i32:$soffset,
1784                                     i16:$offset, i1:$slc), vt:$vdata_in))], 1
1785       >;
1786
1787       defm _RTN_OFFSET : MUBUFAtomicOffset_m <
1788         op, name#"_rtn_offset", (outs rc:$vdata),
1789         (ins rc:$vdata_in, SReg_128:$srsrc, mbuf_offset:$offset,
1790              SCSrc_32:$soffset, slc:$slc),
1791         name#" $vdata, $srsrc, $soffset"#"$offset"#" glc $slc",
1792         [(set vt:$vdata,
1793          (atomic (MUBUFOffsetAtomic v4i32:$srsrc, i32:$soffset, i16:$offset,
1794                                     i1:$slc), vt:$vdata_in))], 1
1795       >;
1796
1797     } // glc = 1
1798
1799   } // mayStore = 1, mayLoad = 1, hasPostISelHook = 1
1800 }
1801
1802 multiclass MUBUF_Load_Helper <mubuf op, string name, RegisterClass regClass,
1803                               ValueType load_vt = i32,
1804                               SDPatternOperator ld = null_frag> {
1805
1806   let mayLoad = 1, mayStore = 0 in {
1807     let offen = 0, idxen = 0, vaddr = 0 in {
1808       defm _OFFSET : MUBUF_m <op, name#"_offset", (outs regClass:$vdata),
1809                            (ins SReg_128:$srsrc,
1810                            mbuf_offset:$offset, SCSrc_32:$soffset, glc:$glc,
1811                            slc:$slc, tfe:$tfe),
1812                            name#" $vdata, $srsrc, $soffset"#"$offset"#"$glc"#"$slc"#"$tfe",
1813                            [(set load_vt:$vdata, (ld (MUBUFOffset v4i32:$srsrc,
1814                                                      i32:$soffset, i16:$offset,
1815                                                      i1:$glc, i1:$slc, i1:$tfe)))]>;
1816     }
1817
1818     let offen = 1, idxen = 0  in {
1819       defm _OFFEN  : MUBUF_m <op, name#"_offen", (outs regClass:$vdata),
1820                            (ins SReg_128:$srsrc, VGPR_32:$vaddr,
1821                            SCSrc_32:$soffset, mbuf_offset:$offset, glc:$glc, slc:$slc,
1822                            tfe:$tfe),
1823                            name#" $vdata, $vaddr, $srsrc, $soffset offen"#"$offset"#"$glc"#"$slc"#"$tfe", []>;
1824     }
1825
1826     let offen = 0, idxen = 1 in {
1827       defm _IDXEN  : MUBUF_m <op, name#"_idxen", (outs regClass:$vdata),
1828                            (ins SReg_128:$srsrc, VGPR_32:$vaddr,
1829                            mbuf_offset:$offset, SCSrc_32:$soffset, glc:$glc,
1830                            slc:$slc, tfe:$tfe),
1831                            name#" $vdata, $vaddr, $srsrc, $soffset idxen"#"$offset"#"$glc"#"$slc"#"$tfe", []>;
1832     }
1833
1834     let offen = 1, idxen = 1 in {
1835       defm _BOTHEN : MUBUF_m <op, name#"_bothen", (outs regClass:$vdata),
1836                            (ins SReg_128:$srsrc, VReg_64:$vaddr,
1837                            SCSrc_32:$soffset, glc:$glc, slc:$slc, tfe:$tfe),
1838                            name#" $vdata, $vaddr, $srsrc, $soffset, idxen offen"#"$glc"#"$slc"#"$tfe", []>;
1839     }
1840
1841     let offen = 0, idxen = 0, glc = 0, slc = 0, tfe = 0 in {
1842       defm _ADDR64 : MUBUFAddr64_m <op, name#"_addr64", (outs regClass:$vdata),
1843                            (ins SReg_128:$srsrc, VReg_64:$vaddr,
1844                                 SCSrc_32:$soffset, mbuf_offset:$offset),
1845                            name#" $vdata, $vaddr, $srsrc, $soffset addr64"#"$offset",
1846                            [(set load_vt:$vdata, (ld (MUBUFAddr64 v4i32:$srsrc,
1847                                                   i64:$vaddr, i32:$soffset,
1848                                                   i16:$offset)))]>;
1849     }
1850   }
1851 }
1852
1853 multiclass MUBUF_Store_Helper <mubuf op, string name, RegisterClass vdataClass,
1854                           ValueType store_vt, SDPatternOperator st> {
1855   let mayLoad = 0, mayStore = 1 in {
1856     defm : MUBUF_m <op, name, (outs),
1857                     (ins vdataClass:$vdata, SReg_128:$srsrc, VGPR_32:$vaddr, SCSrc_32:$soffset,
1858                     mbuf_offset:$offset, offen:$offen, idxen:$idxen, glc:$glc, slc:$slc,
1859                     tfe:$tfe),
1860                     name#" $vdata, $vaddr, $srsrc, $soffset"#"$offen"#"$idxen"#"$offset"#
1861                     "$glc"#"$slc"#"$tfe", []>;
1862
1863     let offen = 0, idxen = 0, vaddr = 0 in {
1864       defm _OFFSET : MUBUF_m <op, name#"_offset",(outs),
1865                               (ins vdataClass:$vdata, SReg_128:$srsrc, mbuf_offset:$offset,
1866                               SCSrc_32:$soffset, glc:$glc, slc:$slc, tfe:$tfe),
1867                               name#" $vdata, $srsrc, $soffset"#"$offset"#"$glc"#"$slc"#"$tfe",
1868                               [(st store_vt:$vdata, (MUBUFOffset v4i32:$srsrc, i32:$soffset,
1869                                    i16:$offset, i1:$glc, i1:$slc, i1:$tfe))]>;
1870     } // offen = 0, idxen = 0, vaddr = 0
1871
1872     let offen = 1, idxen = 0  in {
1873       defm _OFFEN : MUBUF_m <op, name#"_offen", (outs),
1874                              (ins vdataClass:$vdata, SReg_128:$srsrc, VGPR_32:$vaddr, SCSrc_32:$soffset,
1875                              mbuf_offset:$offset, glc:$glc, slc:$slc, tfe:$tfe),
1876                              name#" $vdata, $vaddr, $srsrc, $soffset offen"#"$offset"#
1877                              "$glc"#"$slc"#"$tfe", []>;
1878     } // end offen = 1, idxen = 0
1879
1880     let offen = 0, idxen = 0, glc = 0, slc = 0, tfe = 0 in {
1881       defm _ADDR64 : MUBUFAddr64_m <op, name#"_addr64", (outs),
1882                                     (ins vdataClass:$vdata, SReg_128:$srsrc,
1883                                          VReg_64:$vaddr, SCSrc_32:$soffset,
1884                                          mbuf_offset:$offset),
1885                                     name#" $vdata, $vaddr, $srsrc, $soffset addr64"#"$offset",
1886                                     [(st store_vt:$vdata,
1887                                       (MUBUFAddr64 v4i32:$srsrc, i64:$vaddr,
1888                                                    i32:$soffset, i16:$offset))]>;
1889     }
1890   } // End mayLoad = 0, mayStore = 1
1891 }
1892
1893 class FLAT_Load_Helper <bits<7> op, string asm, RegisterClass regClass> :
1894       FLAT <op, (outs regClass:$data),
1895                 (ins VReg_64:$addr),
1896             asm#" $data, $addr, [M0, FLAT_SCRATCH]", []> {
1897   let glc = 0;
1898   let slc = 0;
1899   let tfe = 0;
1900   let mayLoad = 1;
1901 }
1902
1903 class FLAT_Store_Helper <bits<7> op, string name, RegisterClass vdataClass> :
1904       FLAT <op, (outs), (ins vdataClass:$data, VReg_64:$addr),
1905           name#" $data, $addr, [M0, FLAT_SCRATCH]",
1906          []> {
1907
1908   let mayLoad = 0;
1909   let mayStore = 1;
1910
1911   // Encoding
1912   let glc = 0;
1913   let slc = 0;
1914   let tfe = 0;
1915 }
1916
1917 class MIMG_Mask <string op, int channels> {
1918   string Op = op;
1919   int Channels = channels;
1920 }
1921
1922 class MIMG_NoSampler_Helper <bits<7> op, string asm,
1923                              RegisterClass dst_rc,
1924                              RegisterClass src_rc> : MIMG <
1925   op,
1926   (outs dst_rc:$vdata),
1927   (ins i32imm:$dmask, i1imm:$unorm, i1imm:$glc, i1imm:$da, i1imm:$r128,
1928        i1imm:$tfe, i1imm:$lwe, i1imm:$slc, src_rc:$vaddr,
1929        SReg_256:$srsrc),
1930   asm#" $vdata, $dmask, $unorm, $glc, $da, $r128,"
1931      #" $tfe, $lwe, $slc, $vaddr, $srsrc",
1932   []> {
1933   let SSAMP = 0;
1934   let mayLoad = 1;
1935   let mayStore = 0;
1936   let hasPostISelHook = 1;
1937 }
1938
1939 multiclass MIMG_NoSampler_Src_Helper <bits<7> op, string asm,
1940                                       RegisterClass dst_rc,
1941                                       int channels> {
1942   def _V1 : MIMG_NoSampler_Helper <op, asm, dst_rc, VGPR_32>,
1943             MIMG_Mask<asm#"_V1", channels>;
1944   def _V2 : MIMG_NoSampler_Helper <op, asm, dst_rc, VReg_64>,
1945             MIMG_Mask<asm#"_V2", channels>;
1946   def _V4 : MIMG_NoSampler_Helper <op, asm, dst_rc, VReg_128>,
1947             MIMG_Mask<asm#"_V4", channels>;
1948 }
1949
1950 multiclass MIMG_NoSampler <bits<7> op, string asm> {
1951   defm _V1 : MIMG_NoSampler_Src_Helper <op, asm, VGPR_32, 1>;
1952   defm _V2 : MIMG_NoSampler_Src_Helper <op, asm, VReg_64, 2>;
1953   defm _V3 : MIMG_NoSampler_Src_Helper <op, asm, VReg_96, 3>;
1954   defm _V4 : MIMG_NoSampler_Src_Helper <op, asm, VReg_128, 4>;
1955 }
1956
1957 class MIMG_Sampler_Helper <bits<7> op, string asm,
1958                            RegisterClass dst_rc,
1959                            RegisterClass src_rc, int wqm> : MIMG <
1960   op,
1961   (outs dst_rc:$vdata),
1962   (ins i32imm:$dmask, i1imm:$unorm, i1imm:$glc, i1imm:$da, i1imm:$r128,
1963        i1imm:$tfe, i1imm:$lwe, i1imm:$slc, src_rc:$vaddr,
1964        SReg_256:$srsrc, SReg_128:$ssamp),
1965   asm#" $vdata, $dmask, $unorm, $glc, $da, $r128,"
1966      #" $tfe, $lwe, $slc, $vaddr, $srsrc, $ssamp",
1967   []> {
1968   let mayLoad = 1;
1969   let mayStore = 0;
1970   let hasPostISelHook = 1;
1971   let WQM = wqm;
1972 }
1973
1974 multiclass MIMG_Sampler_Src_Helper <bits<7> op, string asm,
1975                                     RegisterClass dst_rc,
1976                                     int channels, int wqm> {
1977   def _V1 : MIMG_Sampler_Helper <op, asm, dst_rc, VGPR_32, wqm>,
1978             MIMG_Mask<asm#"_V1", channels>;
1979   def _V2 : MIMG_Sampler_Helper <op, asm, dst_rc, VReg_64, wqm>,
1980             MIMG_Mask<asm#"_V2", channels>;
1981   def _V4 : MIMG_Sampler_Helper <op, asm, dst_rc, VReg_128, wqm>,
1982             MIMG_Mask<asm#"_V4", channels>;
1983   def _V8 : MIMG_Sampler_Helper <op, asm, dst_rc, VReg_256, wqm>,
1984             MIMG_Mask<asm#"_V8", channels>;
1985   def _V16 : MIMG_Sampler_Helper <op, asm, dst_rc, VReg_512, wqm>,
1986             MIMG_Mask<asm#"_V16", channels>;
1987 }
1988
1989 multiclass MIMG_Sampler <bits<7> op, string asm> {
1990   defm _V1 : MIMG_Sampler_Src_Helper<op, asm, VGPR_32, 1, 0>;
1991   defm _V2 : MIMG_Sampler_Src_Helper<op, asm, VReg_64, 2, 0>;
1992   defm _V3 : MIMG_Sampler_Src_Helper<op, asm, VReg_96, 3, 0>;
1993   defm _V4 : MIMG_Sampler_Src_Helper<op, asm, VReg_128, 4, 0>;
1994 }
1995
1996 multiclass MIMG_Sampler_WQM <bits<7> op, string asm> {
1997   defm _V1 : MIMG_Sampler_Src_Helper<op, asm, VGPR_32, 1, 1>;
1998   defm _V2 : MIMG_Sampler_Src_Helper<op, asm, VReg_64, 2, 1>;
1999   defm _V3 : MIMG_Sampler_Src_Helper<op, asm, VReg_96, 3, 1>;
2000   defm _V4 : MIMG_Sampler_Src_Helper<op, asm, VReg_128, 4, 1>;
2001 }
2002
2003 class MIMG_Gather_Helper <bits<7> op, string asm,
2004                           RegisterClass dst_rc,
2005                           RegisterClass src_rc, int wqm> : MIMG <
2006   op,
2007   (outs dst_rc:$vdata),
2008   (ins i32imm:$dmask, i1imm:$unorm, i1imm:$glc, i1imm:$da, i1imm:$r128,
2009        i1imm:$tfe, i1imm:$lwe, i1imm:$slc, src_rc:$vaddr,
2010        SReg_256:$srsrc, SReg_128:$ssamp),
2011   asm#" $vdata, $dmask, $unorm, $glc, $da, $r128,"
2012      #" $tfe, $lwe, $slc, $vaddr, $srsrc, $ssamp",
2013   []> {
2014   let mayLoad = 1;
2015   let mayStore = 0;
2016
2017   // DMASK was repurposed for GATHER4. 4 components are always
2018   // returned and DMASK works like a swizzle - it selects
2019   // the component to fetch. The only useful DMASK values are
2020   // 1=red, 2=green, 4=blue, 8=alpha. (e.g. 1 returns
2021   // (red,red,red,red) etc.) The ISA document doesn't mention
2022   // this.
2023   // Therefore, disable all code which updates DMASK by setting these two:
2024   let MIMG = 0;
2025   let hasPostISelHook = 0;
2026   let WQM = wqm;
2027 }
2028
2029 multiclass MIMG_Gather_Src_Helper <bits<7> op, string asm,
2030                                     RegisterClass dst_rc,
2031                                     int channels, int wqm> {
2032   def _V1 : MIMG_Gather_Helper <op, asm, dst_rc, VGPR_32, wqm>,
2033             MIMG_Mask<asm#"_V1", channels>;
2034   def _V2 : MIMG_Gather_Helper <op, asm, dst_rc, VReg_64, wqm>,
2035             MIMG_Mask<asm#"_V2", channels>;
2036   def _V4 : MIMG_Gather_Helper <op, asm, dst_rc, VReg_128, wqm>,
2037             MIMG_Mask<asm#"_V4", channels>;
2038   def _V8 : MIMG_Gather_Helper <op, asm, dst_rc, VReg_256, wqm>,
2039             MIMG_Mask<asm#"_V8", channels>;
2040   def _V16 : MIMG_Gather_Helper <op, asm, dst_rc, VReg_512, wqm>,
2041             MIMG_Mask<asm#"_V16", channels>;
2042 }
2043
2044 multiclass MIMG_Gather <bits<7> op, string asm> {
2045   defm _V1 : MIMG_Gather_Src_Helper<op, asm, VGPR_32, 1, 0>;
2046   defm _V2 : MIMG_Gather_Src_Helper<op, asm, VReg_64, 2, 0>;
2047   defm _V3 : MIMG_Gather_Src_Helper<op, asm, VReg_96, 3, 0>;
2048   defm _V4 : MIMG_Gather_Src_Helper<op, asm, VReg_128, 4, 0>;
2049 }
2050
2051 multiclass MIMG_Gather_WQM <bits<7> op, string asm> {
2052   defm _V1 : MIMG_Gather_Src_Helper<op, asm, VGPR_32, 1, 1>;
2053   defm _V2 : MIMG_Gather_Src_Helper<op, asm, VReg_64, 2, 1>;
2054   defm _V3 : MIMG_Gather_Src_Helper<op, asm, VReg_96, 3, 1>;
2055   defm _V4 : MIMG_Gather_Src_Helper<op, asm, VReg_128, 4, 1>;
2056 }
2057
2058 //===----------------------------------------------------------------------===//
2059 // Vector instruction mappings
2060 //===----------------------------------------------------------------------===//
2061
2062 // Maps an opcode in e32 form to its e64 equivalent
2063 def getVOPe64 : InstrMapping {
2064   let FilterClass = "VOP";
2065   let RowFields = ["OpName"];
2066   let ColFields = ["Size"];
2067   let KeyCol = ["4"];
2068   let ValueCols = [["8"]];
2069 }
2070
2071 // Maps an opcode in e64 form to its e32 equivalent
2072 def getVOPe32 : InstrMapping {
2073   let FilterClass = "VOP";
2074   let RowFields = ["OpName"];
2075   let ColFields = ["Size"];
2076   let KeyCol = ["8"];
2077   let ValueCols = [["4"]];
2078 }
2079
2080 // Maps an original opcode to its commuted version
2081 def getCommuteRev : InstrMapping {
2082   let FilterClass = "VOP2_REV";
2083   let RowFields = ["RevOp"];
2084   let ColFields = ["IsOrig"];
2085   let KeyCol = ["1"];
2086   let ValueCols = [["0"]];
2087 }
2088
2089 def getMaskedMIMGOp : InstrMapping {
2090   let FilterClass = "MIMG_Mask";
2091   let RowFields = ["Op"];
2092   let ColFields = ["Channels"];
2093   let KeyCol = ["4"];
2094   let ValueCols = [["1"], ["2"], ["3"] ];
2095 }
2096
2097 // Maps an commuted opcode to its original version
2098 def getCommuteOrig : InstrMapping {
2099   let FilterClass = "VOP2_REV";
2100   let RowFields = ["RevOp"];
2101   let ColFields = ["IsOrig"];
2102   let KeyCol = ["0"];
2103   let ValueCols = [["1"]];
2104 }
2105
2106 def getMCOpcodeGen : InstrMapping {
2107   let FilterClass = "SIMCInstr";
2108   let RowFields = ["PseudoInstr"];
2109   let ColFields = ["Subtarget"];
2110   let KeyCol = [!cast<string>(SISubtarget.NONE)];
2111   let ValueCols = [[!cast<string>(SISubtarget.SI)],[!cast<string>(SISubtarget.VI)]];
2112 }
2113
2114 def getAddr64Inst : InstrMapping {
2115   let FilterClass = "MUBUFAddr64Table";
2116   let RowFields = ["OpName"];
2117   let ColFields = ["IsAddr64"];
2118   let KeyCol = ["0"];
2119   let ValueCols = [["1"]];
2120 }
2121
2122 // Maps an atomic opcode to its version with a return value.
2123 def getAtomicRetOp : InstrMapping {
2124   let FilterClass = "AtomicNoRet";
2125   let RowFields = ["NoRetOp"];
2126   let ColFields = ["IsRet"];
2127   let KeyCol = ["0"];
2128   let ValueCols = [["1"]];
2129 }
2130
2131 // Maps an atomic opcode to its returnless version.
2132 def getAtomicNoRetOp : InstrMapping {
2133   let FilterClass = "AtomicNoRet";
2134   let RowFields = ["NoRetOp"];
2135   let ColFields = ["IsRet"];
2136   let KeyCol = ["1"];
2137   let ValueCols = [["0"]];
2138 }
2139
2140 include "SIInstructions.td"
2141 include "CIInstructions.td"
2142 include "VIInstructions.td"