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