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