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