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