R600/SI: Fix src1_modifiers for class instructions
[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   // glc is only applicable to scalar stores, which are not yet
580   // implemented.
581   let glc = 0 in {
582     def _vi : SMRD_Real_vi <{0, 0, 0, op}, opName, imm, outs, ins, asm>;
583   }
584 }
585
586 multiclass SMRD_Helper <bits<5> op, string opName, RegisterClass baseClass,
587                         RegisterClass dstClass> {
588   defm _IMM : SMRD_m <
589     op, opName#"_IMM", 1, (outs dstClass:$dst),
590     (ins baseClass:$sbase, u32imm:$offset),
591     opName#" $dst, $sbase, $offset", []
592   >;
593
594   defm _SGPR : SMRD_m <
595     op, opName#"_SGPR", 0, (outs dstClass:$dst),
596     (ins baseClass:$sbase, SReg_32:$soff),
597     opName#" $dst, $sbase, $soff", []
598   >;
599 }
600
601 //===----------------------------------------------------------------------===//
602 // Vector ALU classes
603 //===----------------------------------------------------------------------===//
604
605 // This must always be right before the operand being input modified.
606 def InputMods : OperandWithDefaultOps <i32, (ops (i32 0))> {
607   let PrintMethod = "printOperandAndMods";
608 }
609 def InputModsNoDefault : Operand <i32> {
610   let PrintMethod = "printOperandAndMods";
611 }
612
613 class getNumSrcArgs<ValueType Src1, ValueType Src2> {
614   int ret =
615     !if (!eq(Src1.Value, untyped.Value),      1,   // VOP1
616          !if (!eq(Src2.Value, untyped.Value), 2,   // VOP2
617                                               3)); // VOP3
618 }
619
620 // Returns the register class to use for the destination of VOP[123C]
621 // instructions for the given VT.
622 class getVALUDstForVT<ValueType VT> {
623   RegisterClass ret = !if(!eq(VT.Size, 32), VGPR_32,
624                           !if(!eq(VT.Size, 64), VReg_64,
625                             SReg_64)); // else VT == i1
626 }
627
628 // Returns the register class to use for source 0 of VOP[12C]
629 // instructions for the given VT.
630 class getVOPSrc0ForVT<ValueType VT> {
631   RegisterOperand ret = !if(!eq(VT.Size, 32), VSrc_32, VSrc_64);
632 }
633
634 // Returns the register class to use for source 1 of VOP[12C] for the
635 // given VT.
636 class getVOPSrc1ForVT<ValueType VT> {
637   RegisterClass ret = !if(!eq(VT.Size, 32), VGPR_32, VReg_64);
638 }
639
640 // Returns the register class to use for sources of VOP3 instructions for the
641 // given VT.
642 class getVOP3SrcForVT<ValueType VT> {
643   RegisterOperand ret = !if(!eq(VT.Size, 32), VCSrc_32, VCSrc_64);
644 }
645
646 // Returns 1 if the source arguments have modifiers, 0 if they do not.
647 class hasModifiers<ValueType SrcVT> {
648   bit ret = !if(!eq(SrcVT.Value, f32.Value), 1,
649             !if(!eq(SrcVT.Value, f64.Value), 1, 0));
650 }
651
652 // Returns the input arguments for VOP[12C] instructions for the given SrcVT.
653 class getIns32 <RegisterOperand Src0RC, RegisterClass Src1RC, int NumSrcArgs> {
654   dag ret = !if(!eq(NumSrcArgs, 1), (ins Src0RC:$src0),               // VOP1
655             !if(!eq(NumSrcArgs, 2), (ins Src0RC:$src0, Src1RC:$src1), // VOP2
656                                     (ins)));
657 }
658
659 // Returns the input arguments for VOP3 instructions for the given SrcVT.
660 class getIns64 <RegisterOperand Src0RC, RegisterOperand Src1RC,
661                 RegisterOperand Src2RC, int NumSrcArgs,
662                 bit HasModifiers> {
663
664   dag ret =
665     !if (!eq(NumSrcArgs, 1),
666       !if (!eq(HasModifiers, 1),
667         // VOP1 with modifiers
668         (ins InputModsNoDefault:$src0_modifiers, Src0RC:$src0,
669              ClampMod:$clamp, omod:$omod)
670       /* else */,
671         // VOP1 without modifiers
672         (ins Src0RC:$src0)
673       /* endif */ ),
674     !if (!eq(NumSrcArgs, 2),
675       !if (!eq(HasModifiers, 1),
676         // VOP 2 with modifiers
677         (ins InputModsNoDefault:$src0_modifiers, Src0RC:$src0,
678              InputModsNoDefault:$src1_modifiers, Src1RC:$src1,
679              ClampMod:$clamp, omod:$omod)
680       /* else */,
681         // VOP2 without modifiers
682         (ins Src0RC:$src0, Src1RC:$src1)
683       /* endif */ )
684     /* NumSrcArgs == 3 */,
685       !if (!eq(HasModifiers, 1),
686         // VOP3 with modifiers
687         (ins InputModsNoDefault:$src0_modifiers, Src0RC:$src0,
688              InputModsNoDefault:$src1_modifiers, Src1RC:$src1,
689              InputModsNoDefault:$src2_modifiers, Src2RC:$src2,
690              ClampMod:$clamp, omod:$omod)
691       /* else */,
692         // VOP3 without modifiers
693         (ins Src0RC:$src0, Src1RC:$src1, Src2RC:$src2)
694       /* endif */ )));
695 }
696
697 // Returns the assembly string for the inputs and outputs of a VOP[12C]
698 // instruction.  This does not add the _e32 suffix, so it can be reused
699 // by getAsm64.
700 class getAsm32 <int NumSrcArgs> {
701   string src1 = ", $src1";
702   string src2 = ", $src2";
703   string ret = " $dst, $src0"#
704                !if(!eq(NumSrcArgs, 1), "", src1)#
705                !if(!eq(NumSrcArgs, 3), src2, "");
706 }
707
708 // Returns the assembly string for the inputs and outputs of a VOP3
709 // instruction.
710 class getAsm64 <int NumSrcArgs, bit HasModifiers> {
711   string src0 = !if(!eq(NumSrcArgs, 1), "$src0_modifiers", "$src0_modifiers,");
712   string src1 = !if(!eq(NumSrcArgs, 1), "",
713                    !if(!eq(NumSrcArgs, 2), " $src1_modifiers",
714                                            " $src1_modifiers,"));
715   string src2 = !if(!eq(NumSrcArgs, 3), " $src2_modifiers", "");
716   string ret =
717   !if(!eq(HasModifiers, 0),
718       getAsm32<NumSrcArgs>.ret,
719       " $dst, "#src0#src1#src2#"$clamp"#"$omod");
720 }
721
722
723 class VOPProfile <list<ValueType> _ArgVT> {
724
725   field list<ValueType> ArgVT = _ArgVT;
726
727   field ValueType DstVT = ArgVT[0];
728   field ValueType Src0VT = ArgVT[1];
729   field ValueType Src1VT = ArgVT[2];
730   field ValueType Src2VT = ArgVT[3];
731   field RegisterClass DstRC = getVALUDstForVT<DstVT>.ret;
732   field RegisterOperand Src0RC32 = getVOPSrc0ForVT<Src0VT>.ret;
733   field RegisterClass Src1RC32 = getVOPSrc1ForVT<Src1VT>.ret;
734   field RegisterOperand Src0RC64 = getVOP3SrcForVT<Src0VT>.ret;
735   field RegisterOperand Src1RC64 = getVOP3SrcForVT<Src1VT>.ret;
736   field RegisterOperand Src2RC64 = getVOP3SrcForVT<Src2VT>.ret;
737
738   field int NumSrcArgs = getNumSrcArgs<Src1VT, Src2VT>.ret;
739   field bit HasModifiers = hasModifiers<Src0VT>.ret;
740
741   field dag Outs = (outs DstRC:$dst);
742
743   field dag Ins32 = getIns32<Src0RC32, Src1RC32, NumSrcArgs>.ret;
744   field dag Ins64 = getIns64<Src0RC64, Src1RC64, Src2RC64, NumSrcArgs,
745                              HasModifiers>.ret;
746
747   field string Asm32 = "_e32"#getAsm32<NumSrcArgs>.ret;
748   field string Asm64 = getAsm64<NumSrcArgs, HasModifiers>.ret;
749 }
750
751 def VOP_F32_F32 : VOPProfile <[f32, f32, untyped, untyped]>;
752 def VOP_F32_F64 : VOPProfile <[f32, f64, untyped, untyped]>;
753 def VOP_F32_I32 : VOPProfile <[f32, i32, untyped, untyped]>;
754 def VOP_F64_F32 : VOPProfile <[f64, f32, untyped, untyped]>;
755 def VOP_F64_F64 : VOPProfile <[f64, f64, untyped, untyped]>;
756 def VOP_F64_I32 : VOPProfile <[f64, i32, untyped, untyped]>;
757 def VOP_I32_F32 : VOPProfile <[i32, f32, untyped, untyped]>;
758 def VOP_I32_F64 : VOPProfile <[i32, f64, untyped, untyped]>;
759 def VOP_I32_I32 : VOPProfile <[i32, i32, untyped, untyped]>;
760
761 def VOP_F32_F32_F32 : VOPProfile <[f32, f32, f32, untyped]>;
762 def VOP_F32_F32_I32 : VOPProfile <[f32, f32, i32, untyped]>;
763 def VOP_F64_F64_F64 : VOPProfile <[f64, f64, f64, untyped]>;
764 def VOP_F64_F64_I32 : VOPProfile <[f64, f64, i32, untyped]>;
765 def VOP_I32_F32_F32 : VOPProfile <[i32, f32, f32, untyped]>;
766 def VOP_I32_F32_I32 : VOPProfile <[i32, f32, i32, untyped]>;
767 def VOP_I32_I32_I32 : VOPProfile <[i32, i32, i32, untyped]>;
768 def VOP_I32_I32_I32_VCC : VOPProfile <[i32, i32, i32, untyped]> {
769   let Src0RC32 = VCSrc_32;
770 }
771
772 def VOP_I1_F32_I32 : VOPProfile <[i1, f32, i32, untyped]> {
773   let Ins64 = (ins InputModsNoDefault:$src0_modifiers, Src0RC64:$src0, Src1RC64:$src1);
774   let Asm64 = " $dst, $src0_modifiers, $src1";
775 }
776
777 def VOP_I1_F64_I32 : VOPProfile <[i1, f64, i32, untyped]> {
778   let Ins64 = (ins InputModsNoDefault:$src0_modifiers, Src0RC64:$src0, Src1RC64:$src1);
779   let Asm64 = " $dst, $src0_modifiers, $src1";
780 }
781
782 def VOP_I64_I64_I32 : VOPProfile <[i64, i64, i32, untyped]>;
783 def VOP_I64_I32_I64 : VOPProfile <[i64, i32, i64, untyped]>;
784 def VOP_I64_I64_I64 : VOPProfile <[i64, i64, i64, untyped]>;
785
786 def VOP_F32_F32_F32_F32 : VOPProfile <[f32, f32, f32, f32]>;
787 def VOP_F64_F64_F64_F64 : VOPProfile <[f64, f64, f64, f64]>;
788 def VOP_I32_I32_I32_I32 : VOPProfile <[i32, i32, i32, i32]>;
789 def VOP_I64_I32_I32_I64 : VOPProfile <[i64, i32, i32, i64]>;
790
791
792 class VOP <string opName> {
793   string OpName = opName;
794 }
795
796 class VOP2_REV <string revOp, bit isOrig> {
797   string RevOp = revOp;
798   bit IsOrig = isOrig;
799 }
800
801 class AtomicNoRet <string noRetOp, bit isRet> {
802   string NoRetOp = noRetOp;
803   bit IsRet = isRet;
804 }
805
806 class VOP1_Pseudo <dag outs, dag ins, list<dag> pattern, string opName> :
807   VOP1Common <outs, ins, "", pattern>,
808   VOP <opName>,
809   SIMCInstr <opName#"_e32", SISubtarget.NONE> {
810   let isPseudo = 1;
811 }
812
813 multiclass VOP1_m <vop1 op, dag outs, dag ins, string asm, list<dag> pattern,
814                    string opName> {
815   def "" : VOP1_Pseudo <outs, ins, pattern, opName>;
816
817   def _si : VOP1<op.SI, outs, ins, asm, []>,
818             SIMCInstr <opName#"_e32", SISubtarget.SI>;
819   def _vi : VOP1<op.VI, outs, ins, asm, []>,
820             SIMCInstr <opName#"_e32", SISubtarget.VI>;
821 }
822
823 multiclass VOP1SI_m <vop1 op, dag outs, dag ins, string asm, list<dag> pattern,
824                    string opName> {
825   def "" : VOP1_Pseudo <outs, ins, pattern, opName>;
826
827   def _si : VOP1<op.SI, outs, ins, asm, []>,
828             SIMCInstr <opName#"_e32", SISubtarget.SI>;
829   // No VI instruction. This class is for SI only.
830 }
831
832 class VOP2_Pseudo <dag outs, dag ins, list<dag> pattern, string opName> :
833   VOP2Common <outs, ins, "", pattern>,
834   VOP <opName>,
835   SIMCInstr<opName#"_e32", SISubtarget.NONE> {
836   let isPseudo = 1;
837 }
838
839 multiclass VOP2SI_m <vop2 op, dag outs, dag ins, string asm, list<dag> pattern,
840                      string opName, string revOp> {
841   def "" : VOP2_Pseudo <outs, ins, pattern, opName>,
842            VOP2_REV<revOp#"_e32", !eq(revOp, opName)>;
843
844   def _si : VOP2 <op.SI, outs, ins, opName#asm, []>,
845             SIMCInstr <opName#"_e32", SISubtarget.SI>;
846 }
847
848 multiclass VOP2_m <vop2 op, dag outs, dag ins, string asm, list<dag> pattern,
849                    string opName, string revOp> {
850   def "" : VOP2_Pseudo <outs, ins, pattern, opName>,
851            VOP2_REV<revOp#"_e32", !eq(revOp, opName)>;
852
853   def _si : VOP2 <op.SI, outs, ins, opName#asm, []>,
854             SIMCInstr <opName#"_e32", SISubtarget.SI>;
855   def _vi : VOP2 <op.VI, outs, ins, opName#asm, []>,
856             SIMCInstr <opName#"_e32", SISubtarget.VI>;
857 }
858
859 class VOP3DisableFields <bit HasSrc1, bit HasSrc2, bit HasModifiers> {
860
861   bits<2> src0_modifiers = !if(HasModifiers, ?, 0);
862   bits<2> src1_modifiers = !if(HasModifiers, !if(HasSrc1, ?, 0), 0);
863   bits<2> src2_modifiers = !if(HasModifiers, !if(HasSrc2, ?, 0), 0);
864   bits<2> omod = !if(HasModifiers, ?, 0);
865   bits<1> clamp = !if(HasModifiers, ?, 0);
866   bits<9> src1 = !if(HasSrc1, ?, 0);
867   bits<9> src2 = !if(HasSrc2, ?, 0);
868 }
869
870 class VOP3DisableModFields <bit HasSrc0Mods,
871                             bit HasSrc1Mods = 0,
872                             bit HasSrc2Mods = 0,
873                             bit HasOutputMods = 0> {
874   bits<2> src0_modifiers = !if(HasSrc0Mods, ?, 0);
875   bits<2> src1_modifiers = !if(HasSrc1Mods, ?, 0);
876   bits<2> src2_modifiers = !if(HasSrc2Mods, ?, 0);
877   bits<2> omod = !if(HasOutputMods, ?, 0);
878   bits<1> clamp = !if(HasOutputMods, ?, 0);
879 }
880
881 class VOP3_Pseudo <dag outs, dag ins, list<dag> pattern, string opName> :
882   VOP3Common <outs, ins, "", pattern>,
883   VOP <opName>,
884   SIMCInstr<opName#"_e64", SISubtarget.NONE> {
885   let isPseudo = 1;
886 }
887
888 class VOP3_Real_si <bits<9> op, dag outs, dag ins, string asm, string opName> :
889   VOP3Common <outs, ins, asm, []>,
890   VOP3e <op>,
891   SIMCInstr<opName#"_e64", SISubtarget.SI>;
892
893 class VOP3_Real_vi <bits<10> op, dag outs, dag ins, string asm, string opName> :
894   VOP3Common <outs, ins, asm, []>,
895   VOP3e_vi <op>,
896   SIMCInstr <opName#"_e64", SISubtarget.VI>;
897
898 class VOP3b_Real_si <bits<9> op, dag outs, dag ins, string asm, string opName> :
899   VOP3Common <outs, ins, asm, []>,
900   VOP3be <op>,
901   SIMCInstr<opName#"_e64", SISubtarget.SI>;
902
903 class VOP3b_Real_vi <bits<10> op, dag outs, dag ins, string asm, string opName> :
904   VOP3Common <outs, ins, asm, []>,
905   VOP3be_vi <op>,
906   SIMCInstr <opName#"_e64", SISubtarget.VI>;
907
908 multiclass VOP3_m <vop op, dag outs, dag ins, string asm, list<dag> pattern,
909                    string opName, int NumSrcArgs, bit HasMods = 1> {
910
911   def "" : VOP3_Pseudo <outs, ins, pattern, opName>;
912
913   def _si : VOP3_Real_si <op.SI3, outs, ins, asm, opName>,
914             VOP3DisableFields<!if(!eq(NumSrcArgs, 1), 0, 1),
915                               !if(!eq(NumSrcArgs, 2), 0, 1),
916                               HasMods>;
917   def _vi : VOP3_Real_vi <op.VI3, outs, ins, asm, opName>,
918             VOP3DisableFields<!if(!eq(NumSrcArgs, 1), 0, 1),
919                               !if(!eq(NumSrcArgs, 2), 0, 1),
920                               HasMods>;
921 }
922
923 // VOP3_m without source modifiers
924 multiclass VOP3_m_nomods <vop op, dag outs, dag ins, string asm, list<dag> pattern,
925                    string opName, int NumSrcArgs, bit HasMods = 1> {
926
927   def "" : VOP3_Pseudo <outs, ins, pattern, opName>;
928
929   let src0_modifiers = 0,
930       src1_modifiers = 0,
931       src2_modifiers = 0,
932       clamp = 0,
933       omod = 0 in {
934     def _si : VOP3_Real_si <op.SI3, outs, ins, asm, opName>;
935     def _vi : VOP3_Real_vi <op.VI3, outs, ins, asm, opName>;
936   }
937 }
938
939 multiclass VOP3_1_m <vop op, dag outs, dag ins, string asm,
940                      list<dag> pattern, string opName, bit HasMods = 1> {
941
942   def "" : VOP3_Pseudo <outs, ins, pattern, opName>;
943
944   def _si : VOP3_Real_si <op.SI3, outs, ins, asm, opName>,
945             VOP3DisableFields<0, 0, HasMods>;
946
947   def _vi : VOP3_Real_vi <op.VI3, outs, ins, asm, opName>,
948             VOP3DisableFields<0, 0, HasMods>;
949 }
950
951 multiclass VOP3SI_1_m <vop op, dag outs, dag ins, string asm,
952                      list<dag> pattern, string opName, bit HasMods = 1> {
953
954   def "" : VOP3_Pseudo <outs, ins, pattern, opName>;
955
956   def _si : VOP3_Real_si <op.SI3, outs, ins, asm, opName>,
957             VOP3DisableFields<0, 0, HasMods>;
958   // No VI instruction. This class is for SI only.
959 }
960
961 multiclass VOP3_2_m <vop op, dag outs, dag ins, string asm,
962                      list<dag> pattern, string opName, string revOp,
963                      bit HasMods = 1, bit UseFullOp = 0> {
964
965   def "" : VOP3_Pseudo <outs, ins, pattern, opName>,
966            VOP2_REV<revOp#"_e64", !eq(revOp, opName)>;
967
968   def _si : VOP3_Real_si <op.SI3, outs, ins, asm, opName>,
969             VOP3DisableFields<1, 0, HasMods>;
970
971   def _vi : VOP3_Real_vi <op.VI3, outs, ins, asm, opName>,
972             VOP3DisableFields<1, 0, HasMods>;
973 }
974
975 multiclass VOP3SI_2_m <vop op, dag outs, dag ins, string asm,
976                      list<dag> pattern, string opName, string revOp,
977                      bit HasMods = 1, bit UseFullOp = 0> {
978
979   def "" : VOP3_Pseudo <outs, ins, pattern, opName>,
980            VOP2_REV<revOp#"_e64", !eq(revOp, opName)>;
981
982   def _si : VOP3_Real_si <op.SI3, outs, ins, asm, opName>,
983             VOP3DisableFields<1, 0, HasMods>;
984
985   // No VI instruction. This class is for SI only.
986 }
987
988 // XXX - Is v_div_scale_{f32|f64} only available in vop3b without
989 // option of implicit vcc use?
990 multiclass VOP3b_2_m <vop op, dag outs, dag ins, string asm,
991                       list<dag> pattern, string opName, string revOp,
992                       bit HasMods = 1, bit UseFullOp = 0> {
993   def "" : VOP3_Pseudo <outs, ins, pattern, opName>,
994            VOP2_REV<revOp#"_e64", !eq(revOp, opName)>;
995
996   // The VOP2 variant puts the carry out into VCC, the VOP3 variant
997   // can write it into any SGPR. We currently don't use the carry out,
998   // so for now hardcode it to VCC as well.
999   let sdst = SIOperand.VCC, Defs = [VCC] in {
1000     def _si : VOP3b_Real_si <op.SI3, outs, ins, asm, opName>,
1001               VOP3DisableFields<1, 0, HasMods>;
1002
1003     def _vi : VOP3b_Real_vi <op.VI3, outs, ins, asm, opName>,
1004               VOP3DisableFields<1, 0, HasMods>;
1005   } // End sdst = SIOperand.VCC, Defs = [VCC]
1006 }
1007
1008 multiclass VOP3b_3_m <vop op, dag outs, dag ins, string asm,
1009                       list<dag> pattern, string opName, string revOp,
1010                       bit HasMods = 1, bit UseFullOp = 0> {
1011   def "" : VOP3_Pseudo <outs, ins, pattern, opName>;
1012
1013
1014   def _si : VOP3b_Real_si <op.SI3, outs, ins, asm, opName>,
1015             VOP3DisableFields<1, 1, HasMods>;
1016
1017   def _vi : VOP3b_Real_vi <op.VI3, outs, ins, asm, opName>,
1018             VOP3DisableFields<1, 1, HasMods>;
1019 }
1020
1021 multiclass VOP3_C_m <vop op, dag outs, dag ins, string asm,
1022                      list<dag> pattern, string opName,
1023                      bit HasMods, bit defExec> {
1024
1025   def "" : VOP3_Pseudo <outs, ins, pattern, opName>;
1026
1027   def _si : VOP3_Real_si <op.SI3, outs, ins, asm, opName>,
1028             VOP3DisableFields<1, 0, HasMods> {
1029     let Defs = !if(defExec, [EXEC], []);
1030   }
1031
1032   def _vi : VOP3_Real_vi <op.VI3, outs, ins, asm, opName>,
1033             VOP3DisableFields<1, 0, HasMods> {
1034     let Defs = !if(defExec, [EXEC], []);
1035   }
1036 }
1037
1038 // An instruction that is VOP2 on SI and VOP3 on VI, no modifiers.
1039 multiclass VOP2SI_3VI_m <vop3 op, string opName, dag outs, dag ins,
1040                          string asm, list<dag> pattern = []> {
1041   let isPseudo = 1 in {
1042     def "" : VOPAnyCommon <outs, ins, "", pattern>,
1043              SIMCInstr<opName, SISubtarget.NONE>;
1044   }
1045
1046   def _si : VOP2 <op.SI3{5-0}, outs, ins, asm, []>,
1047             SIMCInstr <opName, SISubtarget.SI>;
1048
1049   def _vi : VOP3Common <outs, ins, asm, []>,
1050             VOP3e_vi <op.VI3>,
1051             VOP3DisableFields <1, 0, 0>,
1052             SIMCInstr <opName, SISubtarget.VI>;
1053 }
1054
1055 multiclass VOP1_Helper <vop1 op, string opName, dag outs,
1056                         dag ins32, string asm32, list<dag> pat32,
1057                         dag ins64, string asm64, list<dag> pat64,
1058                         bit HasMods> {
1059
1060   defm _e32 : VOP1_m <op, outs, ins32, opName#asm32, pat32, opName>;
1061
1062   defm _e64 : VOP3_1_m <op, outs, ins64, opName#"_e64"#asm64, pat64, opName, HasMods>;
1063 }
1064
1065 multiclass VOP1Inst <vop1 op, string opName, VOPProfile P,
1066                      SDPatternOperator node = null_frag> : VOP1_Helper <
1067   op, opName, P.Outs,
1068   P.Ins32, P.Asm32, [],
1069   P.Ins64, P.Asm64,
1070   !if(P.HasModifiers,
1071       [(set P.DstVT:$dst, (node (P.Src0VT (VOP3Mods0 P.Src0VT:$src0,
1072                                 i32:$src0_modifiers, i1:$clamp, i32:$omod))))],
1073       [(set P.DstVT:$dst, (node P.Src0VT:$src0))]),
1074   P.HasModifiers
1075 >;
1076
1077 multiclass VOP1InstSI <vop1 op, string opName, VOPProfile P,
1078                        SDPatternOperator node = null_frag> {
1079
1080   defm _e32 : VOP1SI_m <op, P.Outs, P.Ins32, opName#P.Asm32, [], opName>;
1081
1082   defm _e64 : VOP3SI_1_m <op, P.Outs, P.Ins64, opName#P.Asm64,
1083     !if(P.HasModifiers,
1084       [(set P.DstVT:$dst, (node (P.Src0VT (VOP3Mods0 P.Src0VT:$src0,
1085                                 i32:$src0_modifiers, i1:$clamp, i32:$omod))))],
1086       [(set P.DstVT:$dst, (node P.Src0VT:$src0))]),
1087     opName, P.HasModifiers>;
1088 }
1089
1090 multiclass VOP2_Helper <vop2 op, string opName, dag outs,
1091                         dag ins32, string asm32, list<dag> pat32,
1092                         dag ins64, string asm64, list<dag> pat64,
1093                         string revOp, bit HasMods> {
1094   defm _e32 : VOP2_m <op, outs, ins32, asm32, pat32, opName, revOp>;
1095
1096   defm _e64 : VOP3_2_m <op,
1097     outs, ins64, opName#"_e64"#asm64, pat64, opName, revOp, HasMods
1098   >;
1099 }
1100
1101 multiclass VOP2Inst <vop2 op, string opName, VOPProfile P,
1102                      SDPatternOperator node = null_frag,
1103                      string revOp = opName> : VOP2_Helper <
1104   op, opName, P.Outs,
1105   P.Ins32, P.Asm32, [],
1106   P.Ins64, P.Asm64,
1107   !if(P.HasModifiers,
1108       [(set P.DstVT:$dst,
1109            (node (P.Src0VT (VOP3Mods0 P.Src0VT:$src0, i32:$src0_modifiers,
1110                                       i1:$clamp, i32:$omod)),
1111                  (P.Src1VT (VOP3Mods P.Src1VT:$src1, i32:$src1_modifiers))))],
1112       [(set P.DstVT:$dst, (node P.Src0VT:$src0, P.Src1VT:$src1))]),
1113   revOp, P.HasModifiers
1114 >;
1115
1116 multiclass VOP2InstSI <vop2 op, string opName, VOPProfile P,
1117                        SDPatternOperator node = null_frag,
1118                        string revOp = opName> {
1119   defm _e32 : VOP2SI_m <op, P.Outs, P.Ins32, P.Asm32, [], opName, revOp>;
1120
1121   defm _e64 : VOP3SI_2_m <op, P.Outs, P.Ins64, opName#"_e64"#P.Asm64,
1122     !if(P.HasModifiers,
1123         [(set P.DstVT:$dst,
1124              (node (P.Src0VT (VOP3Mods0 P.Src0VT:$src0, i32:$src0_modifiers,
1125                                         i1:$clamp, i32:$omod)),
1126                    (P.Src1VT (VOP3Mods P.Src1VT:$src1, i32:$src1_modifiers))))],
1127         [(set P.DstVT:$dst, (node P.Src0VT:$src0, P.Src1VT:$src1))]),
1128     opName, revOp, P.HasModifiers>;
1129 }
1130
1131 multiclass VOP2b_Helper <vop2 op, string opName, dag outs,
1132                          dag ins32, string asm32, list<dag> pat32,
1133                          dag ins64, string asm64, list<dag> pat64,
1134                          string revOp, bit HasMods> {
1135
1136   defm _e32 : VOP2_m <op, outs, ins32, asm32, pat32, opName, revOp>;
1137
1138   defm _e64 : VOP3b_2_m <op,
1139     outs, ins64, opName#"_e64"#asm64, pat64, opName, revOp, HasMods
1140   >;
1141 }
1142
1143 multiclass VOP2bInst <vop2 op, string opName, VOPProfile P,
1144                       SDPatternOperator node = null_frag,
1145                       string revOp = opName> : VOP2b_Helper <
1146   op, opName, P.Outs,
1147   P.Ins32, P.Asm32, [],
1148   P.Ins64, P.Asm64,
1149   !if(P.HasModifiers,
1150       [(set P.DstVT:$dst,
1151            (node (P.Src0VT (VOP3Mods0 P.Src0VT:$src0, i32:$src0_modifiers,
1152                                       i1:$clamp, i32:$omod)),
1153                  (P.Src1VT (VOP3Mods P.Src1VT:$src1, i32:$src1_modifiers))))],
1154       [(set P.DstVT:$dst, (node P.Src0VT:$src0, P.Src1VT:$src1))]),
1155   revOp, P.HasModifiers
1156 >;
1157
1158 // A VOP2 instruction that is VOP3-only on VI.
1159 multiclass VOP2_VI3_Helper <vop23 op, string opName, dag outs,
1160                             dag ins32, string asm32, list<dag> pat32,
1161                             dag ins64, string asm64, list<dag> pat64,
1162                             string revOp, bit HasMods> {
1163   defm _e32 : VOP2SI_m <op, outs, ins32, asm32, pat32, opName, revOp>;
1164
1165   defm _e64 : VOP3_2_m <op, outs, ins64, opName#"_e64"#asm64, pat64, opName,
1166                         revOp, HasMods>;
1167 }
1168
1169 multiclass VOP2_VI3_Inst <vop23 op, string opName, VOPProfile P,
1170                           SDPatternOperator node = null_frag,
1171                           string revOp = opName>
1172                           : VOP2_VI3_Helper <
1173   op, opName, P.Outs,
1174   P.Ins32, P.Asm32, [],
1175   P.Ins64, P.Asm64,
1176   !if(P.HasModifiers,
1177       [(set P.DstVT:$dst,
1178            (node (P.Src0VT (VOP3Mods0 P.Src0VT:$src0, i32:$src0_modifiers,
1179                                       i1:$clamp, i32:$omod)),
1180                  (P.Src1VT (VOP3Mods P.Src1VT:$src1, i32:$src1_modifiers))))],
1181       [(set P.DstVT:$dst, (node P.Src0VT:$src0, P.Src1VT:$src1))]),
1182   revOp, P.HasModifiers
1183 >;
1184
1185 class VOPC_Pseudo <dag outs, dag ins, list<dag> pattern, string opName> :
1186   VOPCCommon <ins, "", pattern>,
1187   VOP <opName>,
1188   SIMCInstr<opName#"_e32", SISubtarget.NONE> {
1189   let isPseudo = 1;
1190 }
1191
1192 multiclass VOPC_m <vopc op, dag outs, dag ins, string asm, list<dag> pattern,
1193                    string opName, bit DefExec> {
1194   def "" : VOPC_Pseudo <outs, ins, pattern, opName>;
1195
1196   def _si : VOPC<op.SI, ins, asm, []>,
1197             SIMCInstr <opName#"_e32", SISubtarget.SI> {
1198     let Defs = !if(DefExec, [EXEC], []);
1199   }
1200
1201   def _vi : VOPC<op.VI, ins, asm, []>,
1202             SIMCInstr <opName#"_e32", SISubtarget.VI> {
1203     let Defs = !if(DefExec, [EXEC], []);
1204   }
1205 }
1206
1207 multiclass VOPC_Helper <vopc op, string opName,
1208                         dag ins32, string asm32, list<dag> pat32,
1209                         dag out64, dag ins64, string asm64, list<dag> pat64,
1210                         bit HasMods, bit DefExec> {
1211   defm _e32 : VOPC_m <op, (outs), ins32, opName#asm32, pat32, opName, DefExec>;
1212
1213   defm _e64 : VOP3_C_m <op, out64, ins64, opName#"_e64"#asm64, pat64,
1214                         opName, HasMods, DefExec>;
1215 }
1216
1217 // Special case for class instructions which only have modifiers on
1218 // the 1st source operand.
1219 multiclass VOPC_Class_Helper <vopc op, string opName,
1220                              dag ins32, string asm32, list<dag> pat32,
1221                              dag out64, dag ins64, string asm64, list<dag> pat64,
1222                              bit HasMods, bit DefExec> {
1223   defm _e32 : VOPC_m <op, (outs), ins32, opName#asm32, pat32, opName, DefExec>;
1224
1225   defm _e64 : VOP3_C_m <op, out64, ins64, opName#"_e64"#asm64, pat64,
1226                         opName, HasMods, DefExec>,
1227                         VOP3DisableModFields<1, 0, 0>;
1228 }
1229
1230 multiclass VOPCInst <vopc op, string opName,
1231                      VOPProfile P, PatLeaf cond = COND_NULL,
1232                      bit DefExec = 0> : VOPC_Helper <
1233   op, opName,
1234   P.Ins32, P.Asm32, [],
1235   (outs SReg_64:$dst), P.Ins64, P.Asm64,
1236   !if(P.HasModifiers,
1237       [(set i1:$dst,
1238           (setcc (P.Src0VT (VOP3Mods0 P.Src0VT:$src0, i32:$src0_modifiers,
1239                                       i1:$clamp, i32:$omod)),
1240                  (P.Src1VT (VOP3Mods P.Src1VT:$src1, i32:$src1_modifiers)),
1241                  cond))],
1242       [(set i1:$dst, (setcc P.Src0VT:$src0, P.Src1VT:$src1, cond))]),
1243   P.HasModifiers, DefExec
1244 >;
1245
1246 multiclass VOPCClassInst <vopc op, string opName, VOPProfile P,
1247                      bit DefExec = 0> : VOPC_Class_Helper <
1248   op, opName,
1249   P.Ins32, P.Asm32, [],
1250   (outs SReg_64:$dst), P.Ins64, P.Asm64,
1251   !if(P.HasModifiers,
1252       [(set i1:$dst,
1253           (AMDGPUfp_class (P.Src0VT (VOP3Mods0Clamp0OMod P.Src0VT:$src0, i32:$src0_modifiers)), P.Src1VT:$src1))],
1254       [(set i1:$dst, (AMDGPUfp_class P.Src0VT:$src0, P.Src1VT:$src1))]),
1255   P.HasModifiers, DefExec
1256 >;
1257
1258
1259 multiclass VOPC_F32 <vopc op, string opName, PatLeaf cond = COND_NULL> :
1260   VOPCInst <op, opName, VOP_F32_F32_F32, cond>;
1261
1262 multiclass VOPC_F64 <vopc op, string opName, PatLeaf cond = COND_NULL> :
1263   VOPCInst <op, opName, VOP_F64_F64_F64, cond>;
1264
1265 multiclass VOPC_I32 <vopc op, string opName, PatLeaf cond = COND_NULL> :
1266   VOPCInst <op, opName, VOP_I32_I32_I32, cond>;
1267
1268 multiclass VOPC_I64 <vopc op, string opName, PatLeaf cond = COND_NULL> :
1269   VOPCInst <op, opName, VOP_I64_I64_I64, cond>;
1270
1271
1272 multiclass VOPCX <vopc op, string opName, VOPProfile P,
1273                   PatLeaf cond = COND_NULL>
1274   : VOPCInst <op, opName, P, cond, 1>;
1275
1276 multiclass VOPCX_F32 <vopc op, string opName, PatLeaf cond = COND_NULL> :
1277   VOPCX <op, opName, VOP_F32_F32_F32, cond>;
1278
1279 multiclass VOPCX_F64 <vopc op, string opName, PatLeaf cond = COND_NULL> :
1280   VOPCX <op, opName, VOP_F64_F64_F64, cond>;
1281
1282 multiclass VOPCX_I32 <vopc op, string opName, PatLeaf cond = COND_NULL> :
1283   VOPCX <op, opName, VOP_I32_I32_I32, cond>;
1284
1285 multiclass VOPCX_I64 <vopc op, string opName, PatLeaf cond = COND_NULL> :
1286   VOPCX <op, opName, VOP_I64_I64_I64, cond>;
1287
1288 multiclass VOP3_Helper <vop3 op, string opName, dag outs, dag ins, string asm,
1289                         list<dag> pat, int NumSrcArgs, bit HasMods> : VOP3_m <
1290     op, outs, ins, opName#asm, pat, opName, NumSrcArgs, HasMods
1291 >;
1292
1293 multiclass VOPC_CLASS_F32 <vopc op, string opName> :
1294   VOPCClassInst <op, opName, VOP_I1_F32_I32, 0>;
1295
1296 multiclass VOPCX_CLASS_F32 <vopc op, string opName> :
1297   VOPCClassInst <op, opName, VOP_I1_F32_I32, 1>;
1298
1299 multiclass VOPC_CLASS_F64 <vopc op, string opName> :
1300   VOPCClassInst <op, opName, VOP_I1_F64_I32, 0>;
1301
1302 multiclass VOPCX_CLASS_F64 <vopc op, string opName> :
1303   VOPCClassInst <op, opName, VOP_I1_F64_I32, 1>;
1304
1305 multiclass VOP3Inst <vop3 op, string opName, VOPProfile P,
1306                      SDPatternOperator node = null_frag> : VOP3_Helper <
1307   op, opName, P.Outs, P.Ins64, P.Asm64,
1308   !if(!eq(P.NumSrcArgs, 3),
1309     !if(P.HasModifiers,
1310         [(set P.DstVT:$dst,
1311             (node (P.Src0VT (VOP3Mods0 P.Src0VT:$src0, i32:$src0_modifiers,
1312                                        i1:$clamp, i32:$omod)),
1313                   (P.Src1VT (VOP3Mods P.Src1VT:$src1, i32:$src1_modifiers)),
1314                   (P.Src2VT (VOP3Mods P.Src2VT:$src2, i32:$src2_modifiers))))],
1315         [(set P.DstVT:$dst, (node P.Src0VT:$src0, P.Src1VT:$src1,
1316                                   P.Src2VT:$src2))]),
1317   !if(!eq(P.NumSrcArgs, 2),
1318     !if(P.HasModifiers,
1319         [(set P.DstVT:$dst,
1320             (node (P.Src0VT (VOP3Mods0 P.Src0VT:$src0, i32:$src0_modifiers,
1321                                        i1:$clamp, i32:$omod)),
1322                   (P.Src1VT (VOP3Mods P.Src1VT:$src1, i32:$src1_modifiers))))],
1323         [(set P.DstVT:$dst, (node P.Src0VT:$src0, P.Src1VT:$src1))])
1324   /* P.NumSrcArgs == 1 */,
1325     !if(P.HasModifiers,
1326         [(set P.DstVT:$dst,
1327             (node (P.Src0VT (VOP3Mods0 P.Src0VT:$src0, i32:$src0_modifiers,
1328                                        i1:$clamp, i32:$omod))))],
1329         [(set P.DstVT:$dst, (node P.Src0VT:$src0))]))),
1330   P.NumSrcArgs, P.HasModifiers
1331 >;
1332
1333 // Special case for v_div_fmas_{f32|f64}, since it seems to be the
1334 // only VOP instruction that implicitly reads VCC.
1335 multiclass VOP3_VCC_Inst <vop3 op, string opName,
1336                           VOPProfile P,
1337                           SDPatternOperator node = null_frag> : VOP3_Helper <
1338   op, opName,
1339   P.Outs,
1340   (ins InputModsNoDefault:$src0_modifiers, P.Src0RC64:$src0,
1341        InputModsNoDefault:$src1_modifiers, P.Src1RC64:$src1,
1342        InputModsNoDefault:$src2_modifiers, P.Src2RC64:$src2,
1343        ClampMod:$clamp,
1344        omod:$omod),
1345   " $dst, $src0_modifiers, $src1_modifiers, $src2_modifiers"#"$clamp"#"$omod",
1346   [(set P.DstVT:$dst,
1347             (node (P.Src0VT (VOP3Mods0 P.Src0VT:$src0, i32:$src0_modifiers,
1348                                        i1:$clamp, i32:$omod)),
1349                   (P.Src1VT (VOP3Mods P.Src1VT:$src1, i32:$src1_modifiers)),
1350                   (P.Src2VT (VOP3Mods P.Src2VT:$src2, i32:$src2_modifiers)),
1351                   (i1 VCC)))],
1352   3, 1
1353 >;
1354
1355 multiclass VOP3b_Helper <vop op, RegisterClass vrc, RegisterOperand arc,
1356                     string opName, list<dag> pattern> :
1357   VOP3b_3_m <
1358   op, (outs vrc:$vdst, SReg_64:$sdst),
1359       (ins InputModsNoDefault:$src0_modifiers, arc:$src0,
1360            InputModsNoDefault:$src1_modifiers, arc:$src1,
1361            InputModsNoDefault:$src2_modifiers, arc:$src2,
1362            ClampMod:$clamp, omod:$omod),
1363   opName#" $vdst, $sdst, $src0_modifiers, $src1_modifiers, $src2_modifiers"#"$clamp"#"$omod", pattern,
1364   opName, opName, 1, 1
1365 >;
1366
1367 multiclass VOP3b_64 <vop3 op, string opName, list<dag> pattern> :
1368   VOP3b_Helper <op, VReg_64, VSrc_64, opName, pattern>;
1369
1370 multiclass VOP3b_32 <vop3 op, string opName, list<dag> pattern> :
1371   VOP3b_Helper <op, VGPR_32, VSrc_32, opName, pattern>;
1372
1373
1374 class Vop3ModPat<Instruction Inst, VOPProfile P, SDPatternOperator node> : Pat<
1375   (node (P.Src0VT (VOP3Mods0 P.Src0VT:$src0, i32:$src0_modifiers, i1:$clamp, i32:$omod)),
1376         (P.Src1VT (VOP3Mods P.Src1VT:$src1, i32:$src1_modifiers)),
1377         (P.Src2VT (VOP3Mods P.Src2VT:$src2, i32:$src2_modifiers))),
1378   (Inst i32:$src0_modifiers, P.Src0VT:$src0,
1379         i32:$src1_modifiers, P.Src1VT:$src1,
1380         i32:$src2_modifiers, P.Src2VT:$src2,
1381         i1:$clamp,
1382         i32:$omod)>;
1383
1384 //===----------------------------------------------------------------------===//
1385 // Interpolation opcodes
1386 //===----------------------------------------------------------------------===//
1387
1388 class VINTRP_Pseudo <string opName, dag outs, dag ins, list<dag> pattern> :
1389   VINTRPCommon <outs, ins, "", pattern>,
1390   SIMCInstr<opName, SISubtarget.NONE> {
1391   let isPseudo = 1;
1392 }
1393
1394 class VINTRP_Real_si <bits <2> op, string opName, dag outs, dag ins,
1395                       string asm> :
1396   VINTRPCommon <outs, ins, asm, []>,
1397   VINTRPe <op>,
1398   SIMCInstr<opName, SISubtarget.SI>;
1399
1400 class VINTRP_Real_vi <bits <2> op, string opName, dag outs, dag ins,
1401                       string asm> :
1402   VINTRPCommon <outs, ins, asm, []>,
1403   VINTRPe_vi <op>,
1404   SIMCInstr<opName, SISubtarget.VI>;
1405
1406 multiclass VINTRP_m <bits <2> op, string opName, dag outs, dag ins, string asm,
1407                      string disableEncoding = "", string constraints = "",
1408                      list<dag> pattern = []> {
1409   let DisableEncoding = disableEncoding,
1410       Constraints = constraints in {
1411     def "" : VINTRP_Pseudo <opName, outs, ins, pattern>;
1412
1413     def _si : VINTRP_Real_si <op, opName, outs, ins, asm>;
1414
1415     def _vi : VINTRP_Real_vi <op, opName, outs, ins, asm>;
1416   }
1417 }
1418
1419 //===----------------------------------------------------------------------===//
1420 // Vector I/O classes
1421 //===----------------------------------------------------------------------===//
1422
1423 class DS_Pseudo <string opName, dag outs, dag ins, list<dag> pattern> :
1424   DS <outs, ins, "", pattern>,
1425   SIMCInstr <opName, SISubtarget.NONE> {
1426   let isPseudo = 1;
1427 }
1428
1429 class DS_Real_si <bits<8> op, string opName, dag outs, dag ins, string asm> :
1430   DS <outs, ins, asm, []>,
1431   DSe <op>,
1432   SIMCInstr <opName, SISubtarget.SI>;
1433
1434 class DS_Real_vi <bits<8> op, string opName, dag outs, dag ins, string asm> :
1435   DS <outs, ins, asm, []>,
1436   DSe_vi <op>,
1437   SIMCInstr <opName, SISubtarget.VI>;
1438
1439 class DS_1A_Real_si <bits<8> op, string opName, dag outs, dag ins, string asm> :
1440   DS <outs, ins, asm, []>,
1441   DSe <op>,
1442   SIMCInstr <opName, SISubtarget.SI> {
1443
1444   // Single load interpret the 2 i8imm operands as a single i16 offset.
1445   bits<16> offset;
1446   let offset0 = offset{7-0};
1447   let offset1 = offset{15-8};
1448 }
1449
1450 class DS_1A_Real_vi <bits<8> op, string opName, dag outs, dag ins, string asm> :
1451   DS <outs, ins, asm, []>,
1452   DSe_vi <op>,
1453   SIMCInstr <opName, SISubtarget.VI> {
1454
1455   // Single load interpret the 2 i8imm operands as a single i16 offset.
1456   bits<16> offset;
1457   let offset0 = offset{7-0};
1458   let offset1 = offset{15-8};
1459 }
1460
1461 multiclass DS_1A_Load_m <bits<8> op, string opName, dag outs, dag ins, string asm,
1462                          list<dag> pat> {
1463   let hasSideEffects = 0, mayLoad = 1, mayStore = 0 in {
1464     def "" : DS_Pseudo <opName, outs, ins, pat>;
1465
1466     let data0 = 0, data1 = 0 in {
1467       def _si : DS_1A_Real_si <op, opName, outs, ins, asm>;
1468       def _vi : DS_1A_Real_vi <op, opName, outs, ins, asm>;
1469     }
1470   }
1471 }
1472
1473 multiclass DS_Load_Helper <bits<8> op, string asm, RegisterClass regClass>
1474     : DS_1A_Load_m <
1475   op,
1476   asm,
1477   (outs regClass:$vdst),
1478   (ins i1imm:$gds, VGPR_32:$addr, ds_offset:$offset, M0Reg:$m0),
1479   asm#" $vdst, $addr"#"$offset"#" [M0]",
1480   []>;
1481
1482 multiclass DS_Load2_m <bits<8> op, string opName, dag outs, dag ins, string asm,
1483                        list<dag> pat> {
1484   let hasSideEffects = 0, mayLoad = 1, mayStore = 0 in {
1485     def "" : DS_Pseudo <opName, outs, ins, pat>;
1486
1487     let data0 = 0, data1 = 0 in {
1488       def _si : DS_Real_si <op, opName, outs, ins, asm>;
1489       def _vi : DS_Real_vi <op, opName, outs, ins, asm>;
1490     }
1491   }
1492 }
1493
1494 multiclass DS_Load2_Helper <bits<8> op, string asm, RegisterClass regClass>
1495     : DS_Load2_m <
1496   op,
1497   asm,
1498   (outs regClass:$vdst),
1499   (ins i1imm:$gds, VGPR_32:$addr, ds_offset0:$offset0, ds_offset1:$offset1,
1500         M0Reg:$m0),
1501   asm#" $vdst, $addr"#"$offset0"#"$offset1 [M0]",
1502   []>;
1503
1504 multiclass DS_1A_Store_m <bits<8> op, string opName, dag outs, dag ins,
1505                           string asm, list<dag> pat> {
1506   let hasSideEffects = 0, mayLoad = 0, mayStore = 1 in {
1507     def "" : DS_Pseudo <opName, outs, ins, pat>;
1508
1509     let data1 = 0, vdst = 0 in {
1510       def _si : DS_1A_Real_si <op, opName, outs, ins, asm>;
1511       def _vi : DS_1A_Real_vi <op, opName, outs, ins, asm>;
1512     }
1513   }
1514 }
1515
1516 multiclass DS_Store_Helper <bits<8> op, string asm, RegisterClass regClass>
1517     : DS_1A_Store_m <
1518   op,
1519   asm,
1520   (outs),
1521   (ins i1imm:$gds, VGPR_32:$addr, regClass:$data0, ds_offset:$offset, M0Reg:$m0),
1522   asm#" $addr, $data0"#"$offset"#" [M0]",
1523   []>;
1524
1525 multiclass DS_Store_m <bits<8> op, string opName, dag outs, dag ins,
1526                        string asm, list<dag> pat> {
1527   let hasSideEffects = 0, mayLoad = 0, mayStore = 1 in {
1528     def "" : DS_Pseudo <opName, outs, ins, pat>;
1529
1530     let vdst = 0 in {
1531       def _si : DS_Real_si <op, opName, outs, ins, asm>;
1532       def _vi : DS_Real_vi <op, opName, outs, ins, asm>;
1533     }
1534   }
1535 }
1536
1537 multiclass DS_Store2_Helper <bits<8> op, string asm, RegisterClass regClass>
1538     : DS_Store_m <
1539   op,
1540   asm,
1541   (outs),
1542   (ins i1imm:$gds, VGPR_32:$addr, regClass:$data0, regClass:$data1,
1543        ds_offset0:$offset0, ds_offset1:$offset1, M0Reg:$m0),
1544   asm#" $addr, $data0, $data1"#"$offset0"#"$offset1 [M0]",
1545   []>;
1546
1547 // 1 address, 1 data.
1548 multiclass DS_1A1D_RET_m <bits<8> op, string opName, dag outs, dag ins,
1549                           string asm, list<dag> pat, string noRetOp> {
1550   let mayLoad = 1, mayStore = 1,
1551       hasPostISelHook = 1 // Adjusted to no return version.
1552       in {
1553     def "" : DS_Pseudo <opName, outs, ins, pat>,
1554              AtomicNoRet<noRetOp, 1>;
1555
1556     let data1 = 0 in {
1557       def _si : DS_1A_Real_si <op, opName, outs, ins, asm>;
1558       def _vi : DS_1A_Real_vi <op, opName, outs, ins, asm>;
1559     }
1560   }
1561 }
1562
1563 multiclass DS_1A1D_RET <bits<8> op, string asm, RegisterClass rc,
1564                         string noRetOp = ""> : DS_1A1D_RET_m <
1565   op, asm,
1566   (outs rc:$vdst),
1567   (ins i1imm:$gds, VGPR_32:$addr, rc:$data0, ds_offset:$offset, M0Reg:$m0),
1568   asm#" $vdst, $addr, $data0"#"$offset"#" [M0]", [], noRetOp>;
1569
1570 // 1 address, 2 data.
1571 multiclass DS_1A2D_RET_m <bits<8> op, string opName, dag outs, dag ins,
1572                           string asm, list<dag> pat, string noRetOp> {
1573   let mayLoad = 1, mayStore = 1,
1574       hasPostISelHook = 1 // Adjusted to no return version.
1575       in {
1576     def "" : DS_Pseudo <opName, outs, ins, pat>,
1577              AtomicNoRet<noRetOp, 1>;
1578
1579     def _si : DS_1A_Real_si <op, opName, outs, ins, asm>;
1580     def _vi : DS_1A_Real_vi <op, opName, outs, ins, asm>;
1581   }
1582 }
1583
1584 multiclass DS_1A2D_RET <bits<8> op, string asm, RegisterClass rc,
1585                    string noRetOp = ""> : DS_1A2D_RET_m <
1586   op, asm,
1587   (outs rc:$vdst),
1588   (ins i1imm:$gds, VGPR_32:$addr, rc:$data0, rc:$data1, ds_offset:$offset, M0Reg:$m0),
1589   asm#" $vdst, $addr, $data0, $data1"#"$offset"#" [M0]",
1590   [], noRetOp>;
1591
1592 // 1 address, 2 data.
1593 multiclass DS_1A2D_NORET_m <bits<8> op, string opName, dag outs, dag ins,
1594                             string asm, list<dag> pat, string noRetOp> {
1595   let mayLoad = 1, mayStore = 1 in {
1596     def "" : DS_Pseudo <opName, outs, ins, pat>,
1597              AtomicNoRet<noRetOp, 0>;
1598
1599     let vdst = 0 in {
1600       def _si : DS_1A_Real_si <op, opName, outs, ins, asm>;
1601       def _vi : DS_1A_Real_vi <op, opName, outs, ins, asm>;
1602     }
1603   }
1604 }
1605
1606 multiclass DS_1A2D_NORET <bits<8> op, string asm, RegisterClass rc,
1607                      string noRetOp = asm> : DS_1A2D_NORET_m <
1608   op, asm,
1609   (outs),
1610   (ins i1imm:$gds, VGPR_32:$addr, rc:$data0, rc:$data1, ds_offset:$offset, M0Reg:$m0),
1611   asm#" $addr, $data0, $data1"#"$offset"#" [M0]",
1612   [], noRetOp>;
1613
1614 // 1 address, 1 data.
1615 multiclass DS_1A1D_NORET_m <bits<8> op, string opName, dag outs, dag ins,
1616                             string asm, list<dag> pat, string noRetOp> {
1617   let mayLoad = 1, mayStore = 1 in {
1618     def "" : DS_Pseudo <opName, outs, ins, pat>,
1619              AtomicNoRet<noRetOp, 0>;
1620
1621     let data1 = 0, vdst = 0 in {
1622       def _si : DS_1A_Real_si <op, opName, outs, ins, asm>;
1623       def _vi : DS_1A_Real_vi <op, opName, outs, ins, asm>;
1624     }
1625   }
1626 }
1627
1628 multiclass DS_1A1D_NORET <bits<8> op, string asm, RegisterClass rc,
1629                           string noRetOp = asm> : DS_1A1D_NORET_m <
1630   op, asm,
1631   (outs),
1632   (ins i1imm:$gds, VGPR_32:$addr, rc:$data0, ds_offset:$offset, M0Reg:$m0),
1633   asm#" $addr, $data0"#"$offset"#" [M0]",
1634   [], noRetOp>;
1635
1636 //===----------------------------------------------------------------------===//
1637 // MTBUF classes
1638 //===----------------------------------------------------------------------===//
1639
1640 class MTBUF_Pseudo <string opName, dag outs, dag ins, list<dag> pattern> :
1641   MTBUF <outs, ins, "", pattern>,
1642   SIMCInstr<opName, SISubtarget.NONE> {
1643   let isPseudo = 1;
1644 }
1645
1646 class MTBUF_Real_si <bits<3> op, string opName, dag outs, dag ins,
1647                     string asm> :
1648   MTBUF <outs, ins, asm, []>,
1649   MTBUFe <op>,
1650   SIMCInstr<opName, SISubtarget.SI>;
1651
1652 class MTBUF_Real_vi <bits<4> op, string opName, dag outs, dag ins, string asm> :
1653   MTBUF <outs, ins, asm, []>,
1654   MTBUFe_vi <op>,
1655   SIMCInstr <opName, SISubtarget.VI>;
1656
1657 multiclass MTBUF_m <bits<3> op, string opName, dag outs, dag ins, string asm,
1658                     list<dag> pattern> {
1659
1660   def "" : MTBUF_Pseudo <opName, outs, ins, pattern>;
1661
1662   def _si : MTBUF_Real_si <op, opName, outs, ins, asm>;
1663
1664   def _vi : MTBUF_Real_vi <{0, op{2}, op{1}, op{0}}, opName, outs, ins, asm>;
1665
1666 }
1667
1668 let mayStore = 1, mayLoad = 0 in {
1669
1670 multiclass MTBUF_Store_Helper <bits<3> op, string opName,
1671                                RegisterClass regClass> : MTBUF_m <
1672   op, opName, (outs),
1673   (ins regClass:$vdata, u16imm:$offset, i1imm:$offen, i1imm:$idxen, i1imm:$glc,
1674    i1imm:$addr64, i8imm:$dfmt, i8imm:$nfmt, VGPR_32:$vaddr,
1675    SReg_128:$srsrc, i1imm:$slc, i1imm:$tfe, SCSrc_32:$soffset),
1676   opName#" $vdata, $offset, $offen, $idxen, $glc, $addr64, $dfmt,"
1677         #" $nfmt, $vaddr, $srsrc, $slc, $tfe, $soffset", []
1678 >;
1679
1680 } // mayStore = 1, mayLoad = 0
1681
1682 let mayLoad = 1, mayStore = 0 in {
1683
1684 multiclass MTBUF_Load_Helper <bits<3> op, string opName,
1685                               RegisterClass regClass> : MTBUF_m <
1686   op, opName, (outs regClass:$dst),
1687   (ins u16imm:$offset, i1imm:$offen, i1imm:$idxen, i1imm:$glc, i1imm:$addr64,
1688        i8imm:$dfmt, i8imm:$nfmt, VGPR_32:$vaddr, SReg_128:$srsrc,
1689        i1imm:$slc, i1imm:$tfe, SCSrc_32:$soffset),
1690   opName#" $dst, $offset, $offen, $idxen, $glc, $addr64, $dfmt,"
1691         #" $nfmt, $vaddr, $srsrc, $slc, $tfe, $soffset", []
1692 >;
1693
1694 } // mayLoad = 1, mayStore = 0
1695
1696 //===----------------------------------------------------------------------===//
1697 // MUBUF classes
1698 //===----------------------------------------------------------------------===//
1699
1700 class mubuf <bits<7> si, bits<7> vi = si> {
1701   field bits<7> SI = si;
1702   field bits<7> VI = vi;
1703 }
1704
1705 class MUBUFAddr64Table <bit is_addr64, string suffix = ""> {
1706   bit IsAddr64 = is_addr64;
1707   string OpName = NAME # suffix;
1708 }
1709
1710 class MUBUF_Pseudo <string opName, dag outs, dag ins, list<dag> pattern> :
1711   MUBUF <outs, ins, "", pattern>,
1712   SIMCInstr<opName, SISubtarget.NONE> {
1713   let isPseudo = 1;
1714
1715   // dummy fields, so that we can use let statements around multiclasses
1716   bits<1> offen;
1717   bits<1> idxen;
1718   bits<8> vaddr;
1719   bits<1> glc;
1720   bits<1> slc;
1721   bits<1> tfe;
1722   bits<8> soffset;
1723 }
1724
1725 class MUBUF_Real_si <mubuf op, string opName, dag outs, dag ins,
1726                      string asm> :
1727   MUBUF <outs, ins, asm, []>,
1728   MUBUFe <op.SI>,
1729   SIMCInstr<opName, SISubtarget.SI> {
1730   let lds = 0;
1731 }
1732
1733 class MUBUF_Real_vi <mubuf op, string opName, dag outs, dag ins,
1734                      string asm> :
1735   MUBUF <outs, ins, asm, []>,
1736   MUBUFe_vi <op.VI>,
1737   SIMCInstr<opName, SISubtarget.VI> {
1738   let lds = 0;
1739 }
1740
1741 multiclass MUBUF_m <mubuf op, string opName, dag outs, dag ins, string asm,
1742                     list<dag> pattern> {
1743
1744   def "" : MUBUF_Pseudo <opName, outs, ins, pattern>,
1745            MUBUFAddr64Table <0>;
1746
1747   let addr64 = 0 in {
1748     def _si : MUBUF_Real_si <op, opName, outs, ins, asm>;
1749   }
1750
1751   def _vi : MUBUF_Real_vi <op, opName, outs, ins, asm>;
1752 }
1753
1754 multiclass MUBUFAddr64_m <mubuf op, string opName, dag outs,
1755                           dag ins, string asm, list<dag> pattern> {
1756
1757   def "" : MUBUF_Pseudo <opName, outs, ins, pattern>,
1758            MUBUFAddr64Table <1>;
1759
1760   let addr64 = 1 in {
1761     def _si : MUBUF_Real_si <op, opName, outs, ins, asm>;
1762   }
1763
1764   // There is no VI version. If the pseudo is selected, it should be lowered
1765   // for VI appropriately.
1766 }
1767
1768 class MUBUF_si <bits<7> op, dag outs, dag ins, string asm, list<dag> pattern> :
1769   MUBUF <outs, ins, asm, pattern>, MUBUFe <op> {
1770   let lds = 0;
1771 }
1772
1773 multiclass MUBUFAtomicOffset_m <mubuf op, string opName, dag outs, dag ins,
1774                                 string asm, list<dag> pattern, bit is_return> {
1775
1776   def "" : MUBUF_Pseudo <opName, outs, ins, pattern>,
1777            MUBUFAddr64Table <0, !if(is_return, "_RTN", "")>,
1778            AtomicNoRet<NAME#"_OFFSET", is_return>;
1779
1780   let offen = 0, idxen = 0, tfe = 0, vaddr = 0 in {
1781     let addr64 = 0 in {
1782       def _si : MUBUF_Real_si <op, opName, outs, ins, asm>;
1783     }
1784
1785     def _vi : MUBUF_Real_vi <op, opName, outs, ins, asm>;
1786   }
1787 }
1788
1789 multiclass MUBUFAtomicAddr64_m <mubuf op, string opName, dag outs, dag ins,
1790                                 string asm, list<dag> pattern, bit is_return> {
1791
1792   def "" : MUBUF_Pseudo <opName, outs, ins, pattern>,
1793            MUBUFAddr64Table <1, !if(is_return, "_RTN", "")>,
1794            AtomicNoRet<NAME#"_ADDR64", is_return>;
1795
1796   let offen = 0, idxen = 0, addr64 = 1, tfe = 0 in {
1797     def _si : MUBUF_Real_si <op, opName, outs, ins, asm>;
1798   }
1799
1800   // There is no VI version. If the pseudo is selected, it should be lowered
1801   // for VI appropriately.
1802 }
1803
1804 multiclass MUBUF_Atomic <mubuf op, string name, RegisterClass rc,
1805                          ValueType vt, SDPatternOperator atomic> {
1806
1807   let mayStore = 1, mayLoad = 1, hasPostISelHook = 1 in {
1808
1809     // No return variants
1810     let glc = 0 in {
1811
1812       defm _ADDR64 : MUBUFAtomicAddr64_m <
1813         op, name#"_addr64", (outs),
1814         (ins rc:$vdata, SReg_128:$srsrc, VReg_64:$vaddr,
1815              mbuf_offset:$offset, SCSrc_32:$soffset, slc:$slc),
1816         name#" $vdata, $vaddr, $srsrc, $soffset addr64"#"$offset"#"$slc", [], 0
1817       >;
1818
1819       defm _OFFSET : MUBUFAtomicOffset_m <
1820         op, name#"_offset", (outs),
1821         (ins rc:$vdata, SReg_128:$srsrc, mbuf_offset:$offset,
1822              SCSrc_32:$soffset, slc:$slc),
1823         name#" $vdata, $srsrc, $soffset"#"$offset"#"$slc", [], 0
1824       >;
1825     } // glc = 0
1826
1827     // Variant that return values
1828     let glc = 1, Constraints = "$vdata = $vdata_in",
1829         DisableEncoding = "$vdata_in"  in {
1830
1831       defm _RTN_ADDR64 : MUBUFAtomicAddr64_m <
1832         op, name#"_rtn_addr64", (outs rc:$vdata),
1833         (ins rc:$vdata_in, SReg_128:$srsrc, VReg_64:$vaddr,
1834              mbuf_offset:$offset, SSrc_32:$soffset, slc:$slc),
1835         name#" $vdata, $vaddr, $srsrc, $soffset addr64"#"$offset"#" glc"#"$slc",
1836         [(set vt:$vdata,
1837          (atomic (MUBUFAddr64Atomic v4i32:$srsrc, i64:$vaddr, i32:$soffset,
1838                                     i16:$offset, i1:$slc), vt:$vdata_in))], 1
1839       >;
1840
1841       defm _RTN_OFFSET : MUBUFAtomicOffset_m <
1842         op, name#"_rtn_offset", (outs rc:$vdata),
1843         (ins rc:$vdata_in, SReg_128:$srsrc, mbuf_offset:$offset,
1844              SCSrc_32:$soffset, slc:$slc),
1845         name#" $vdata, $srsrc, $soffset"#"$offset"#" glc $slc",
1846         [(set vt:$vdata,
1847          (atomic (MUBUFOffsetAtomic v4i32:$srsrc, i32:$soffset, i16:$offset,
1848                                     i1:$slc), vt:$vdata_in))], 1
1849       >;
1850
1851     } // glc = 1
1852
1853   } // mayStore = 1, mayLoad = 1, hasPostISelHook = 1
1854 }
1855
1856 multiclass MUBUF_Load_Helper <mubuf op, string name, RegisterClass regClass,
1857                               ValueType load_vt = i32,
1858                               SDPatternOperator ld = null_frag> {
1859
1860   let mayLoad = 1, mayStore = 0 in {
1861     let offen = 0, idxen = 0, vaddr = 0 in {
1862       defm _OFFSET : MUBUF_m <op, name#"_offset", (outs regClass:$vdata),
1863                            (ins SReg_128:$srsrc,
1864                            mbuf_offset:$offset, SCSrc_32:$soffset, glc:$glc,
1865                            slc:$slc, tfe:$tfe),
1866                            name#" $vdata, $srsrc, $soffset"#"$offset"#"$glc"#"$slc"#"$tfe",
1867                            [(set load_vt:$vdata, (ld (MUBUFOffset v4i32:$srsrc,
1868                                                      i32:$soffset, i16:$offset,
1869                                                      i1:$glc, i1:$slc, i1:$tfe)))]>;
1870     }
1871
1872     let offen = 1, idxen = 0  in {
1873       defm _OFFEN  : MUBUF_m <op, name#"_offen", (outs regClass:$vdata),
1874                            (ins SReg_128:$srsrc, VGPR_32:$vaddr,
1875                            SCSrc_32:$soffset, mbuf_offset:$offset, glc:$glc, slc:$slc,
1876                            tfe:$tfe),
1877                            name#" $vdata, $vaddr, $srsrc, $soffset offen"#"$offset"#"$glc"#"$slc"#"$tfe", []>;
1878     }
1879
1880     let offen = 0, idxen = 1 in {
1881       defm _IDXEN  : MUBUF_m <op, name#"_idxen", (outs regClass:$vdata),
1882                            (ins SReg_128:$srsrc, VGPR_32:$vaddr,
1883                            mbuf_offset:$offset, SCSrc_32:$soffset, glc:$glc,
1884                            slc:$slc, tfe:$tfe),
1885                            name#" $vdata, $vaddr, $srsrc, $soffset idxen"#"$offset"#"$glc"#"$slc"#"$tfe", []>;
1886     }
1887
1888     let offen = 1, idxen = 1 in {
1889       defm _BOTHEN : MUBUF_m <op, name#"_bothen", (outs regClass:$vdata),
1890                            (ins SReg_128:$srsrc, VReg_64:$vaddr,
1891                            SCSrc_32:$soffset, mbuf_offset:$offset, glc:$glc, slc:$slc, tfe:$tfe),
1892                            name#" $vdata, $vaddr, $srsrc, $soffset idxen offen"#"$offset"#"$glc"#"$slc"#"$tfe", []>;
1893     }
1894
1895     let offen = 0, idxen = 0, glc = 0, slc = 0, tfe = 0 in {
1896       defm _ADDR64 : MUBUFAddr64_m <op, name#"_addr64", (outs regClass:$vdata),
1897                            (ins SReg_128:$srsrc, VReg_64:$vaddr,
1898                                 SCSrc_32:$soffset, mbuf_offset:$offset),
1899                            name#" $vdata, $vaddr, $srsrc, $soffset addr64"#"$offset",
1900                            [(set load_vt:$vdata, (ld (MUBUFAddr64 v4i32:$srsrc,
1901                                                   i64:$vaddr, i32:$soffset,
1902                                                   i16:$offset)))]>;
1903     }
1904   }
1905 }
1906
1907 multiclass MUBUF_Store_Helper <mubuf op, string name, RegisterClass vdataClass,
1908                           ValueType store_vt, SDPatternOperator st> {
1909   let mayLoad = 0, mayStore = 1 in {
1910     defm : MUBUF_m <op, name, (outs),
1911                     (ins vdataClass:$vdata, SReg_128:$srsrc, VGPR_32:$vaddr, SCSrc_32:$soffset,
1912                     mbuf_offset:$offset, offen:$offen, idxen:$idxen, glc:$glc, slc:$slc,
1913                     tfe:$tfe),
1914                     name#" $vdata, $vaddr, $srsrc, $soffset"#"$offen"#"$idxen"#"$offset"#
1915                     "$glc"#"$slc"#"$tfe", []>;
1916
1917     let offen = 0, idxen = 0, vaddr = 0 in {
1918       defm _OFFSET : MUBUF_m <op, name#"_offset",(outs),
1919                               (ins vdataClass:$vdata, SReg_128:$srsrc, mbuf_offset:$offset,
1920                               SCSrc_32:$soffset, glc:$glc, slc:$slc, tfe:$tfe),
1921                               name#" $vdata, $srsrc, $soffset"#"$offset"#"$glc"#"$slc"#"$tfe",
1922                               [(st store_vt:$vdata, (MUBUFOffset v4i32:$srsrc, i32:$soffset,
1923                                    i16:$offset, i1:$glc, i1:$slc, i1:$tfe))]>;
1924     } // offen = 0, idxen = 0, vaddr = 0
1925
1926     let offen = 1, idxen = 0  in {
1927       defm _OFFEN : MUBUF_m <op, name#"_offen", (outs),
1928                              (ins vdataClass:$vdata, SReg_128:$srsrc, VGPR_32:$vaddr, SCSrc_32:$soffset,
1929                              mbuf_offset:$offset, glc:$glc, slc:$slc, tfe:$tfe),
1930                              name#" $vdata, $vaddr, $srsrc, $soffset offen"#"$offset"#
1931                              "$glc"#"$slc"#"$tfe", []>;
1932     } // end offen = 1, idxen = 0
1933
1934     let offen = 0, idxen = 0, glc = 0, slc = 0, tfe = 0 in {
1935       defm _ADDR64 : MUBUFAddr64_m <op, name#"_addr64", (outs),
1936                                     (ins vdataClass:$vdata, SReg_128:$srsrc,
1937                                          VReg_64:$vaddr, SCSrc_32:$soffset,
1938                                          mbuf_offset:$offset),
1939                                     name#" $vdata, $vaddr, $srsrc, $soffset addr64"#"$offset",
1940                                     [(st store_vt:$vdata,
1941                                       (MUBUFAddr64 v4i32:$srsrc, i64:$vaddr,
1942                                                    i32:$soffset, i16:$offset))]>;
1943     }
1944   } // End mayLoad = 0, mayStore = 1
1945 }
1946
1947 class FLAT_Load_Helper <bits<7> op, string asm, RegisterClass regClass> :
1948       FLAT <op, (outs regClass:$vdst),
1949                 (ins VReg_64:$addr),
1950             asm#" $vdst, $addr, [M0, FLAT_SCRATCH]", []> {
1951   let glc = 0;
1952   let slc = 0;
1953   let tfe = 0;
1954   let data = 0;
1955   let mayLoad = 1;
1956 }
1957
1958 class FLAT_Store_Helper <bits<7> op, string name, RegisterClass vdataClass> :
1959       FLAT <op, (outs), (ins vdataClass:$data, VReg_64:$addr),
1960           name#" $data, $addr, [M0, FLAT_SCRATCH]",
1961          []> {
1962
1963   let mayLoad = 0;
1964   let mayStore = 1;
1965
1966   // Encoding
1967   let glc = 0;
1968   let slc = 0;
1969   let tfe = 0;
1970   let vdst = 0;
1971 }
1972
1973 class MIMG_Mask <string op, int channels> {
1974   string Op = op;
1975   int Channels = channels;
1976 }
1977
1978 class MIMG_NoSampler_Helper <bits<7> op, string asm,
1979                              RegisterClass dst_rc,
1980                              RegisterClass src_rc> : MIMG <
1981   op,
1982   (outs dst_rc:$vdata),
1983   (ins i32imm:$dmask, i1imm:$unorm, i1imm:$glc, i1imm:$da, i1imm:$r128,
1984        i1imm:$tfe, i1imm:$lwe, i1imm:$slc, src_rc:$vaddr,
1985        SReg_256:$srsrc),
1986   asm#" $vdata, $dmask, $unorm, $glc, $da, $r128,"
1987      #" $tfe, $lwe, $slc, $vaddr, $srsrc",
1988   []> {
1989   let SSAMP = 0;
1990   let mayLoad = 1;
1991   let mayStore = 0;
1992   let hasPostISelHook = 1;
1993 }
1994
1995 multiclass MIMG_NoSampler_Src_Helper <bits<7> op, string asm,
1996                                       RegisterClass dst_rc,
1997                                       int channels> {
1998   def _V1 : MIMG_NoSampler_Helper <op, asm, dst_rc, VGPR_32>,
1999             MIMG_Mask<asm#"_V1", channels>;
2000   def _V2 : MIMG_NoSampler_Helper <op, asm, dst_rc, VReg_64>,
2001             MIMG_Mask<asm#"_V2", channels>;
2002   def _V4 : MIMG_NoSampler_Helper <op, asm, dst_rc, VReg_128>,
2003             MIMG_Mask<asm#"_V4", channels>;
2004 }
2005
2006 multiclass MIMG_NoSampler <bits<7> op, string asm> {
2007   defm _V1 : MIMG_NoSampler_Src_Helper <op, asm, VGPR_32, 1>;
2008   defm _V2 : MIMG_NoSampler_Src_Helper <op, asm, VReg_64, 2>;
2009   defm _V3 : MIMG_NoSampler_Src_Helper <op, asm, VReg_96, 3>;
2010   defm _V4 : MIMG_NoSampler_Src_Helper <op, asm, VReg_128, 4>;
2011 }
2012
2013 class MIMG_Sampler_Helper <bits<7> op, string asm,
2014                            RegisterClass dst_rc,
2015                            RegisterClass src_rc, int wqm> : MIMG <
2016   op,
2017   (outs dst_rc:$vdata),
2018   (ins i32imm:$dmask, i1imm:$unorm, i1imm:$glc, i1imm:$da, i1imm:$r128,
2019        i1imm:$tfe, i1imm:$lwe, i1imm:$slc, src_rc:$vaddr,
2020        SReg_256:$srsrc, SReg_128:$ssamp),
2021   asm#" $vdata, $dmask, $unorm, $glc, $da, $r128,"
2022      #" $tfe, $lwe, $slc, $vaddr, $srsrc, $ssamp",
2023   []> {
2024   let mayLoad = 1;
2025   let mayStore = 0;
2026   let hasPostISelHook = 1;
2027   let WQM = wqm;
2028 }
2029
2030 multiclass MIMG_Sampler_Src_Helper <bits<7> op, string asm,
2031                                     RegisterClass dst_rc,
2032                                     int channels, int wqm> {
2033   def _V1 : MIMG_Sampler_Helper <op, asm, dst_rc, VGPR_32, wqm>,
2034             MIMG_Mask<asm#"_V1", channels>;
2035   def _V2 : MIMG_Sampler_Helper <op, asm, dst_rc, VReg_64, wqm>,
2036             MIMG_Mask<asm#"_V2", channels>;
2037   def _V4 : MIMG_Sampler_Helper <op, asm, dst_rc, VReg_128, wqm>,
2038             MIMG_Mask<asm#"_V4", channels>;
2039   def _V8 : MIMG_Sampler_Helper <op, asm, dst_rc, VReg_256, wqm>,
2040             MIMG_Mask<asm#"_V8", channels>;
2041   def _V16 : MIMG_Sampler_Helper <op, asm, dst_rc, VReg_512, wqm>,
2042             MIMG_Mask<asm#"_V16", channels>;
2043 }
2044
2045 multiclass MIMG_Sampler <bits<7> op, string asm> {
2046   defm _V1 : MIMG_Sampler_Src_Helper<op, asm, VGPR_32, 1, 0>;
2047   defm _V2 : MIMG_Sampler_Src_Helper<op, asm, VReg_64, 2, 0>;
2048   defm _V3 : MIMG_Sampler_Src_Helper<op, asm, VReg_96, 3, 0>;
2049   defm _V4 : MIMG_Sampler_Src_Helper<op, asm, VReg_128, 4, 0>;
2050 }
2051
2052 multiclass MIMG_Sampler_WQM <bits<7> op, string asm> {
2053   defm _V1 : MIMG_Sampler_Src_Helper<op, asm, VGPR_32, 1, 1>;
2054   defm _V2 : MIMG_Sampler_Src_Helper<op, asm, VReg_64, 2, 1>;
2055   defm _V3 : MIMG_Sampler_Src_Helper<op, asm, VReg_96, 3, 1>;
2056   defm _V4 : MIMG_Sampler_Src_Helper<op, asm, VReg_128, 4, 1>;
2057 }
2058
2059 class MIMG_Gather_Helper <bits<7> op, string asm,
2060                           RegisterClass dst_rc,
2061                           RegisterClass src_rc, int wqm> : MIMG <
2062   op,
2063   (outs dst_rc:$vdata),
2064   (ins i32imm:$dmask, i1imm:$unorm, i1imm:$glc, i1imm:$da, i1imm:$r128,
2065        i1imm:$tfe, i1imm:$lwe, i1imm:$slc, src_rc:$vaddr,
2066        SReg_256:$srsrc, SReg_128:$ssamp),
2067   asm#" $vdata, $dmask, $unorm, $glc, $da, $r128,"
2068      #" $tfe, $lwe, $slc, $vaddr, $srsrc, $ssamp",
2069   []> {
2070   let mayLoad = 1;
2071   let mayStore = 0;
2072
2073   // DMASK was repurposed for GATHER4. 4 components are always
2074   // returned and DMASK works like a swizzle - it selects
2075   // the component to fetch. The only useful DMASK values are
2076   // 1=red, 2=green, 4=blue, 8=alpha. (e.g. 1 returns
2077   // (red,red,red,red) etc.) The ISA document doesn't mention
2078   // this.
2079   // Therefore, disable all code which updates DMASK by setting these two:
2080   let MIMG = 0;
2081   let hasPostISelHook = 0;
2082   let WQM = wqm;
2083 }
2084
2085 multiclass MIMG_Gather_Src_Helper <bits<7> op, string asm,
2086                                     RegisterClass dst_rc,
2087                                     int channels, int wqm> {
2088   def _V1 : MIMG_Gather_Helper <op, asm, dst_rc, VGPR_32, wqm>,
2089             MIMG_Mask<asm#"_V1", channels>;
2090   def _V2 : MIMG_Gather_Helper <op, asm, dst_rc, VReg_64, wqm>,
2091             MIMG_Mask<asm#"_V2", channels>;
2092   def _V4 : MIMG_Gather_Helper <op, asm, dst_rc, VReg_128, wqm>,
2093             MIMG_Mask<asm#"_V4", channels>;
2094   def _V8 : MIMG_Gather_Helper <op, asm, dst_rc, VReg_256, wqm>,
2095             MIMG_Mask<asm#"_V8", channels>;
2096   def _V16 : MIMG_Gather_Helper <op, asm, dst_rc, VReg_512, wqm>,
2097             MIMG_Mask<asm#"_V16", channels>;
2098 }
2099
2100 multiclass MIMG_Gather <bits<7> op, string asm> {
2101   defm _V1 : MIMG_Gather_Src_Helper<op, asm, VGPR_32, 1, 0>;
2102   defm _V2 : MIMG_Gather_Src_Helper<op, asm, VReg_64, 2, 0>;
2103   defm _V3 : MIMG_Gather_Src_Helper<op, asm, VReg_96, 3, 0>;
2104   defm _V4 : MIMG_Gather_Src_Helper<op, asm, VReg_128, 4, 0>;
2105 }
2106
2107 multiclass MIMG_Gather_WQM <bits<7> op, string asm> {
2108   defm _V1 : MIMG_Gather_Src_Helper<op, asm, VGPR_32, 1, 1>;
2109   defm _V2 : MIMG_Gather_Src_Helper<op, asm, VReg_64, 2, 1>;
2110   defm _V3 : MIMG_Gather_Src_Helper<op, asm, VReg_96, 3, 1>;
2111   defm _V4 : MIMG_Gather_Src_Helper<op, asm, VReg_128, 4, 1>;
2112 }
2113
2114 //===----------------------------------------------------------------------===//
2115 // Vector instruction mappings
2116 //===----------------------------------------------------------------------===//
2117
2118 // Maps an opcode in e32 form to its e64 equivalent
2119 def getVOPe64 : InstrMapping {
2120   let FilterClass = "VOP";
2121   let RowFields = ["OpName"];
2122   let ColFields = ["Size"];
2123   let KeyCol = ["4"];
2124   let ValueCols = [["8"]];
2125 }
2126
2127 // Maps an opcode in e64 form to its e32 equivalent
2128 def getVOPe32 : InstrMapping {
2129   let FilterClass = "VOP";
2130   let RowFields = ["OpName"];
2131   let ColFields = ["Size"];
2132   let KeyCol = ["8"];
2133   let ValueCols = [["4"]];
2134 }
2135
2136 // Maps an original opcode to its commuted version
2137 def getCommuteRev : InstrMapping {
2138   let FilterClass = "VOP2_REV";
2139   let RowFields = ["RevOp"];
2140   let ColFields = ["IsOrig"];
2141   let KeyCol = ["1"];
2142   let ValueCols = [["0"]];
2143 }
2144
2145 def getMaskedMIMGOp : InstrMapping {
2146   let FilterClass = "MIMG_Mask";
2147   let RowFields = ["Op"];
2148   let ColFields = ["Channels"];
2149   let KeyCol = ["4"];
2150   let ValueCols = [["1"], ["2"], ["3"] ];
2151 }
2152
2153 // Maps an commuted opcode to its original version
2154 def getCommuteOrig : InstrMapping {
2155   let FilterClass = "VOP2_REV";
2156   let RowFields = ["RevOp"];
2157   let ColFields = ["IsOrig"];
2158   let KeyCol = ["0"];
2159   let ValueCols = [["1"]];
2160 }
2161
2162 def getMCOpcodeGen : InstrMapping {
2163   let FilterClass = "SIMCInstr";
2164   let RowFields = ["PseudoInstr"];
2165   let ColFields = ["Subtarget"];
2166   let KeyCol = [!cast<string>(SISubtarget.NONE)];
2167   let ValueCols = [[!cast<string>(SISubtarget.SI)],[!cast<string>(SISubtarget.VI)]];
2168 }
2169
2170 def getAddr64Inst : InstrMapping {
2171   let FilterClass = "MUBUFAddr64Table";
2172   let RowFields = ["OpName"];
2173   let ColFields = ["IsAddr64"];
2174   let KeyCol = ["0"];
2175   let ValueCols = [["1"]];
2176 }
2177
2178 // Maps an atomic opcode to its version with a return value.
2179 def getAtomicRetOp : InstrMapping {
2180   let FilterClass = "AtomicNoRet";
2181   let RowFields = ["NoRetOp"];
2182   let ColFields = ["IsRet"];
2183   let KeyCol = ["0"];
2184   let ValueCols = [["1"]];
2185 }
2186
2187 // Maps an atomic opcode to its returnless version.
2188 def getAtomicNoRetOp : InstrMapping {
2189   let FilterClass = "AtomicNoRet";
2190   let RowFields = ["NoRetOp"];
2191   let ColFields = ["IsRet"];
2192   let KeyCol = ["1"];
2193   let ValueCols = [["0"]];
2194 }
2195
2196 include "SIInstructions.td"
2197 include "CIInstructions.td"
2198 include "VIInstructions.td"