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//===----------------------------------------------------------------------===//
9def isCI : Predicate<"Subtarget->getGeneration() "
10                      ">= SISubtarget::SEA_ISLANDS">;
11def isCIOnly : Predicate<"Subtarget->getGeneration() =="
12                         "SISubtarget::SEA_ISLANDS">,
13  AssemblerPredicate <"FeatureSeaIslands">;
14
15def DisableInst : Predicate <"false">, AssemblerPredicate<"FeatureDisable">;
16
17// Execpt for the NONE field, this must be kept in sync with the
18// SIEncodingFamily enum in AMDGPUInstrInfo.cpp
19def SIEncodingFamily {
20  int NONE = -1;
21  int SI = 0;
22  int VI = 1;
23}
24
25//===----------------------------------------------------------------------===//
26// SI DAG Nodes
27//===----------------------------------------------------------------------===//
28
29def SIload_constant : SDNode<"AMDGPUISD::LOAD_CONSTANT",
30  SDTypeProfile<1, 2, [SDTCisVT<0, f32>, SDTCisVT<1, v4i32>, SDTCisVT<2, i32>]>,
31                      [SDNPMayLoad, SDNPMemOperand]
32>;
33
34def SIatomic_inc : SDNode<"AMDGPUISD::ATOMIC_INC", SDTAtomic2,
35  [SDNPMayLoad, SDNPMayStore, SDNPMemOperand, SDNPHasChain]
36>;
37
38def SIatomic_dec : SDNode<"AMDGPUISD::ATOMIC_DEC", SDTAtomic2,
39  [SDNPMayLoad, SDNPMayStore, SDNPMemOperand, SDNPHasChain]
40>;
41
42def SItbuffer_store : SDNode<"AMDGPUISD::TBUFFER_STORE_FORMAT",
43  SDTypeProfile<0, 13,
44    [SDTCisVT<0, v4i32>,   // rsrc(SGPR)
45     SDTCisVT<1, iAny>,   // vdata(VGPR)
46     SDTCisVT<2, i32>,    // num_channels(imm)
47     SDTCisVT<3, i32>,    // vaddr(VGPR)
48     SDTCisVT<4, i32>,    // soffset(SGPR)
49     SDTCisVT<5, i32>,    // inst_offset(imm)
50     SDTCisVT<6, i32>,    // dfmt(imm)
51     SDTCisVT<7, i32>,    // nfmt(imm)
52     SDTCisVT<8, i32>,    // offen(imm)
53     SDTCisVT<9, i32>,    // idxen(imm)
54     SDTCisVT<10, i32>,   // glc(imm)
55     SDTCisVT<11, i32>,   // slc(imm)
56     SDTCisVT<12, i32>    // tfe(imm)
57    ]>,
58  [SDNPMayStore, SDNPMemOperand, SDNPHasChain]
59>;
60
61def SIload_input : SDNode<"AMDGPUISD::LOAD_INPUT",
62  SDTypeProfile<1, 3, [SDTCisVT<0, v4f32>, SDTCisVT<1, v4i32>, SDTCisVT<2, i16>,
63                       SDTCisVT<3, i32>]>
64>;
65
66class SDSample<string opcode> : SDNode <opcode,
67  SDTypeProfile<1, 4, [SDTCisVT<0, v4f32>, SDTCisVT<2, v8i32>,
68                       SDTCisVT<3, v4i32>, SDTCisVT<4, i32>]>
69>;
70
71def SIsample : SDSample<"AMDGPUISD::SAMPLE">;
72def SIsampleb : SDSample<"AMDGPUISD::SAMPLEB">;
73def SIsampled : SDSample<"AMDGPUISD::SAMPLED">;
74def SIsamplel : SDSample<"AMDGPUISD::SAMPLEL">;
75
76def SIpc_add_rel_offset : SDNode<"AMDGPUISD::PC_ADD_REL_OFFSET",
77  SDTypeProfile<1, 2, [SDTCisVT<0, iPTR>, SDTCisSameAs<0,1>, SDTCisSameAs<0,2>]>
78>;
79
80//===----------------------------------------------------------------------===//
81// PatFrags for global memory operations
82//===----------------------------------------------------------------------===//
83
84def atomic_inc_global : global_binary_atomic_op<SIatomic_inc>;
85def atomic_dec_global : global_binary_atomic_op<SIatomic_dec>;
86
87//===----------------------------------------------------------------------===//
88// SDNodes and PatFrag for local loads and stores to enable s_mov_b32 m0, -1
89// to be glued to the memory instructions.
90//===----------------------------------------------------------------------===//
91
92def SIld_local : SDNode <"ISD::LOAD", SDTLoad,
93  [SDNPHasChain, SDNPMayLoad, SDNPMemOperand, SDNPInGlue]
94>;
95
96def si_ld_local : PatFrag <(ops node:$ptr), (SIld_local node:$ptr), [{
97  return cast<LoadSDNode>(N)->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
98}]>;
99
100def si_load_local : PatFrag <(ops node:$ptr), (si_ld_local node:$ptr), [{
101  return cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED &&
102         cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
103}]>;
104
105def si_load_local_align8 : Aligned8Bytes <
106  (ops node:$ptr), (si_load_local node:$ptr)
107>;
108
109def si_sextload_local : PatFrag <(ops node:$ptr), (si_ld_local node:$ptr), [{
110  return cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
111}]>;
112def si_az_extload_local : AZExtLoadBase <si_ld_local>;
113
114multiclass SIExtLoadLocal <PatFrag ld_node> {
115
116  def _i8 : PatFrag <(ops node:$ptr), (ld_node node:$ptr),
117                     [{return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8;}]
118  >;
119
120  def _i16 : PatFrag <(ops node:$ptr), (ld_node node:$ptr),
121                     [{return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16;}]
122  >;
123}
124
125defm si_sextload_local : SIExtLoadLocal <si_sextload_local>;
126defm si_az_extload_local : SIExtLoadLocal <si_az_extload_local>;
127
128def SIst_local : SDNode <"ISD::STORE", SDTStore,
129  [SDNPHasChain, SDNPMayStore, SDNPMemOperand, SDNPInGlue]
130>;
131
132def si_st_local : PatFrag <
133  (ops node:$val, node:$ptr), (SIst_local node:$val, node:$ptr), [{
134  return cast<StoreSDNode>(N)->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
135}]>;
136
137def si_store_local : PatFrag <
138  (ops node:$val, node:$ptr), (si_st_local node:$val, node:$ptr), [{
139  return cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED &&
140         !cast<StoreSDNode>(N)->isTruncatingStore();
141}]>;
142
143def si_store_local_align8 : Aligned8Bytes <
144  (ops node:$val, node:$ptr), (si_store_local node:$val, node:$ptr)
145>;
146
147def si_truncstore_local : PatFrag <
148  (ops node:$val, node:$ptr), (si_st_local node:$val, node:$ptr), [{
149  return cast<StoreSDNode>(N)->isTruncatingStore();
150}]>;
151
152def si_truncstore_local_i8 : PatFrag <
153  (ops node:$val, node:$ptr), (si_truncstore_local node:$val, node:$ptr), [{
154  return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i8;
155}]>;
156
157def si_truncstore_local_i16 : PatFrag <
158  (ops node:$val, node:$ptr), (si_truncstore_local node:$val, node:$ptr), [{
159  return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i16;
160}]>;
161
162def si_setcc_uniform : PatFrag <
163  (ops node:$lhs, node:$rhs, node:$cond),
164  (setcc node:$lhs, node:$rhs, node:$cond), [{
165  for (SDNode *Use : N->uses()) {
166    if (Use->isMachineOpcode() || Use->getOpcode() != ISD::CopyToReg)
167      return false;
168
169    unsigned Reg = cast<RegisterSDNode>(Use->getOperand(1))->getReg();
170    if (Reg != AMDGPU::SCC)
171      return false;
172  }
173  return true;
174}]>;
175
176def si_uniform_br : PatFrag <
177  (ops node:$cond, node:$bb), (brcond node:$cond, node:$bb), [{
178  return isUniformBr(N);
179}]>;
180
181def si_uniform_br_scc : PatFrag <
182  (ops node:$cond, node:$bb), (si_uniform_br node:$cond, node:$bb), [{
183  return isCBranchSCC(N);
184}]>;
185
186multiclass SIAtomicM0Glue2 <string op_name, bit is_amdgpu = 0> {
187
188  def _glue : SDNode <
189    !if(is_amdgpu, "AMDGPUISD", "ISD")#"::ATOMIC_"#op_name, SDTAtomic2,
190    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand, SDNPInGlue]
191  >;
192
193  def _local : local_binary_atomic_op <!cast<SDNode>(NAME#"_glue")>;
194}
195
196defm si_atomic_load_add : SIAtomicM0Glue2 <"LOAD_ADD">;
197defm si_atomic_load_sub : SIAtomicM0Glue2 <"LOAD_SUB">;
198defm si_atomic_inc : SIAtomicM0Glue2 <"INC", 1>;
199defm si_atomic_dec : SIAtomicM0Glue2 <"DEC", 1>;
200defm si_atomic_load_and : SIAtomicM0Glue2 <"LOAD_AND">;
201defm si_atomic_load_min : SIAtomicM0Glue2 <"LOAD_MIN">;
202defm si_atomic_load_max : SIAtomicM0Glue2 <"LOAD_MAX">;
203defm si_atomic_load_or : SIAtomicM0Glue2 <"LOAD_OR">;
204defm si_atomic_load_xor : SIAtomicM0Glue2 <"LOAD_XOR">;
205defm si_atomic_load_umin : SIAtomicM0Glue2 <"LOAD_UMIN">;
206defm si_atomic_load_umax : SIAtomicM0Glue2 <"LOAD_UMAX">;
207defm si_atomic_swap : SIAtomicM0Glue2 <"SWAP">;
208
209def si_atomic_cmp_swap_glue : SDNode <"ISD::ATOMIC_CMP_SWAP", SDTAtomic3,
210  [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand, SDNPInGlue]
211>;
212
213defm si_atomic_cmp_swap : AtomicCmpSwapLocal <si_atomic_cmp_swap_glue>;
214
215def as_i1imm : SDNodeXForm<imm, [{
216  return CurDAG->getTargetConstant(N->getZExtValue(), SDLoc(N), MVT::i1);
217}]>;
218
219def as_i8imm : SDNodeXForm<imm, [{
220  return CurDAG->getTargetConstant(N->getZExtValue(), SDLoc(N), MVT::i8);
221}]>;
222
223def as_i16imm : SDNodeXForm<imm, [{
224  return CurDAG->getTargetConstant(N->getSExtValue(), SDLoc(N), MVT::i16);
225}]>;
226
227def as_i32imm: SDNodeXForm<imm, [{
228  return CurDAG->getTargetConstant(N->getSExtValue(), SDLoc(N), MVT::i32);
229}]>;
230
231def as_i64imm: SDNodeXForm<imm, [{
232  return CurDAG->getTargetConstant(N->getSExtValue(), SDLoc(N), MVT::i64);
233}]>;
234
235// Copied from the AArch64 backend:
236def bitcast_fpimm_to_i32 : SDNodeXForm<fpimm, [{
237return CurDAG->getTargetConstant(
238  N->getValueAPF().bitcastToAPInt().getZExtValue(), SDLoc(N), MVT::i32);
239}]>;
240
241def frameindex_to_targetframeindex : SDNodeXForm<frameindex, [{
242  auto FI = cast<FrameIndexSDNode>(N);
243  return CurDAG->getTargetFrameIndex(FI->getIndex(), MVT::i32);
244}]>;
245
246// Copied from the AArch64 backend:
247def bitcast_fpimm_to_i64 : SDNodeXForm<fpimm, [{
248return CurDAG->getTargetConstant(
249  N->getValueAPF().bitcastToAPInt().getZExtValue(), SDLoc(N), MVT::i64);
250}]>;
251
252def SIMM16bit : PatLeaf <(imm),
253  [{return isInt<16>(N->getSExtValue());}]
254>;
255
256def IMM20bit : PatLeaf <(imm),
257  [{return isUInt<20>(N->getZExtValue());}]
258>;
259
260class InlineImm <ValueType vt> : PatLeaf <(vt imm), [{
261  return isInlineImmediate(N);
262}]>;
263
264class InlineFPImm <ValueType vt> : PatLeaf <(vt fpimm), [{
265  return isInlineImmediate(N);
266}]>;
267
268class VGPRImm <dag frag> : PatLeaf<frag, [{
269  if (Subtarget->getGeneration() < SISubtarget::SOUTHERN_ISLANDS) {
270    return false;
271  }
272  const SIRegisterInfo *SIRI =
273      static_cast<const SIRegisterInfo *>(Subtarget->getRegisterInfo());
274  unsigned Limit = 0;
275  for (SDNode::use_iterator U = N->use_begin(), E = SDNode::use_end();
276         Limit < 10 && U != E; ++U, ++Limit) {
277    const TargetRegisterClass *RC = getOperandRegClass(*U, U.getOperandNo());
278
279    // If the register class is unknown, it could be an unknown
280    // register class that needs to be an SGPR, e.g. an inline asm
281    // constraint
282    if (!RC || SIRI->isSGPRClass(RC))
283      return false;
284  }
285
286  return Limit < 10;
287}]>;
288
289//===----------------------------------------------------------------------===//
290// Custom Operands
291//===----------------------------------------------------------------------===//
292
293def SoppBrTarget : AsmOperandClass {
294  let Name = "SoppBrTarget";
295  let ParserMethod = "parseSOppBrTarget";
296}
297
298def sopp_brtarget : Operand<OtherVT> {
299  let EncoderMethod = "getSOPPBrEncoding";
300  let DecoderMethod = "decodeSoppBrTarget";
301  let OperandType = "OPERAND_PCREL";
302  let ParserMatchClass = SoppBrTarget;
303}
304
305def si_ga : Operand<iPTR>;
306
307def InterpSlot : Operand<i32> {
308  let PrintMethod = "printInterpSlot";
309}
310
311def SendMsgMatchClass : AsmOperandClass {
312  let Name = "SendMsg";
313  let PredicateMethod = "isSendMsg";
314  let ParserMethod = "parseSendMsgOp";
315  let RenderMethod = "addImmOperands";
316}
317
318def ExpTgtMatchClass : AsmOperandClass {
319  let Name = "ExpTgt";
320  let PredicateMethod = "isExpTgt";
321  let ParserMethod = "parseExpTgt";
322  let RenderMethod = "printExpTgt";
323}
324
325def SendMsgImm : Operand<i32> {
326  let PrintMethod = "printSendMsg";
327  let ParserMatchClass = SendMsgMatchClass;
328}
329
330def SWaitMatchClass : AsmOperandClass {
331  let Name = "SWaitCnt";
332  let RenderMethod = "addImmOperands";
333  let ParserMethod = "parseSWaitCntOps";
334}
335
336def VReg32OrOffClass : AsmOperandClass {
337  let Name = "VReg32OrOff";
338  let ParserMethod = "parseVReg32OrOff";
339}
340
341def WAIT_FLAG : Operand <i32> {
342  let ParserMatchClass = SWaitMatchClass;
343  let PrintMethod = "printWaitFlag";
344}
345
346include "SIInstrFormats.td"
347include "VIInstrFormats.td"
348
349// ===----------------------------------------------------------------------===//
350// ExpSrc* Special cases for exp src operands which are printed as
351// "off" depending on en operand.
352// ===----------------------------------------------------------------------===//
353
354def ExpSrc0 : RegisterOperand<VGPR_32> {
355  let PrintMethod = "printExpSrc0";
356  let ParserMatchClass = VReg32OrOffClass;
357}
358
359def ExpSrc1 : RegisterOperand<VGPR_32> {
360  let PrintMethod = "printExpSrc1";
361  let ParserMatchClass = VReg32OrOffClass;
362}
363
364def ExpSrc2 : RegisterOperand<VGPR_32> {
365  let PrintMethod = "printExpSrc2";
366  let ParserMatchClass = VReg32OrOffClass;
367}
368
369def ExpSrc3 : RegisterOperand<VGPR_32> {
370  let PrintMethod = "printExpSrc3";
371  let ParserMatchClass = VReg32OrOffClass;
372}
373
374class NamedMatchClass<string CName, bit Optional = 1> : AsmOperandClass {
375  let Name = "Imm"#CName;
376  let PredicateMethod = "is"#CName;
377  let ParserMethod = !if(Optional, "parseOptionalOperand", "parse"#CName);
378  let RenderMethod = "addImmOperands";
379  let IsOptional = Optional;
380  let DefaultMethod = !if(Optional, "default"#CName, ?);
381}
382
383class NamedOperandBit<string Name, AsmOperandClass MatchClass> : Operand<i1> {
384  let PrintMethod = "print"#Name;
385  let ParserMatchClass = MatchClass;
386}
387
388class NamedOperandU8<string Name, AsmOperandClass MatchClass> : Operand<i8> {
389  let PrintMethod = "print"#Name;
390  let ParserMatchClass = MatchClass;
391}
392
393class NamedOperandU16<string Name, AsmOperandClass MatchClass> : Operand<i16> {
394  let PrintMethod = "print"#Name;
395  let ParserMatchClass = MatchClass;
396}
397
398class NamedOperandU32<string Name, AsmOperandClass MatchClass> : Operand<i32> {
399  let PrintMethod = "print"#Name;
400  let ParserMatchClass = MatchClass;
401}
402
403let OperandType = "OPERAND_IMMEDIATE" in {
404
405def offen : NamedOperandBit<"Offen", NamedMatchClass<"Offen">>;
406def idxen : NamedOperandBit<"Idxen", NamedMatchClass<"Idxen">>;
407def addr64 : NamedOperandBit<"Addr64", NamedMatchClass<"Addr64">>;
408
409def offset : NamedOperandU16<"Offset", NamedMatchClass<"Offset">>;
410def offset0 : NamedOperandU8<"Offset0", NamedMatchClass<"Offset0">>;
411def offset1 : NamedOperandU8<"Offset1", NamedMatchClass<"Offset1">>;
412
413def gds : NamedOperandBit<"GDS", NamedMatchClass<"GDS">>;
414
415def omod : NamedOperandU32<"OModSI", NamedMatchClass<"OModSI">>;
416def clampmod : NamedOperandBit<"ClampSI", NamedMatchClass<"ClampSI">>;
417
418def GLC : NamedOperandBit<"GLC", NamedMatchClass<"GLC">>;
419def slc : NamedOperandBit<"SLC", NamedMatchClass<"SLC">>;
420def tfe : NamedOperandBit<"TFE", NamedMatchClass<"TFE">>;
421def unorm : NamedOperandBit<"UNorm", NamedMatchClass<"UNorm">>;
422def da : NamedOperandBit<"DA", NamedMatchClass<"DA">>;
423def r128 : NamedOperandBit<"R128", NamedMatchClass<"R128">>;
424def lwe : NamedOperandBit<"LWE", NamedMatchClass<"LWE">>;
425def exp_compr : NamedOperandBit<"ExpCompr", NamedMatchClass<"ExpCompr">>;
426def exp_vm : NamedOperandBit<"ExpVM", NamedMatchClass<"ExpVM">>;
427
428def dmask : NamedOperandU16<"DMask", NamedMatchClass<"DMask">>;
429
430def dpp_ctrl : NamedOperandU32<"DPPCtrl", NamedMatchClass<"DPPCtrl", 0>>;
431def row_mask : NamedOperandU32<"RowMask", NamedMatchClass<"RowMask">>;
432def bank_mask : NamedOperandU32<"BankMask", NamedMatchClass<"BankMask">>;
433def bound_ctrl : NamedOperandBit<"BoundCtrl", NamedMatchClass<"BoundCtrl">>;
434
435def dst_sel : NamedOperandU32<"SDWADstSel", NamedMatchClass<"SDWADstSel">>;
436def src0_sel : NamedOperandU32<"SDWASrc0Sel", NamedMatchClass<"SDWASrc0Sel">>;
437def src1_sel : NamedOperandU32<"SDWASrc1Sel", NamedMatchClass<"SDWASrc1Sel">>;
438def dst_unused : NamedOperandU32<"SDWADstUnused", NamedMatchClass<"SDWADstUnused">>;
439
440def hwreg : NamedOperandU16<"Hwreg", NamedMatchClass<"Hwreg", 0>>;
441
442def exp_tgt : NamedOperandU8<"ExpTgt", NamedMatchClass<"ExpTgt", 0>> {
443
444}
445
446} // End OperandType = "OPERAND_IMMEDIATE"
447
448class KImmMatchClass<int size> : AsmOperandClass {
449  let Name = "KImmFP"#size;
450  let PredicateMethod = "isKImmFP"#size;
451  let ParserMethod = "parseImm";
452  let RenderMethod = "addKImmFP"#size#"Operands";
453}
454
455class kimmOperand<ValueType vt> : Operand<vt> {
456  let OperandNamespace = "AMDGPU";
457  let OperandType = "OPERAND_KIMM"#vt.Size;
458  let PrintMethod = "printU"#vt.Size#"ImmOperand";
459  let ParserMatchClass = !cast<AsmOperandClass>("KImmFP"#vt.Size#"MatchClass");
460}
461
462// 32-bit VALU immediate operand that uses the constant bus.
463def KImmFP32MatchClass : KImmMatchClass<32>;
464def f32kimm : kimmOperand<i32>;
465
466// 32-bit VALU immediate operand with a 16-bit value that uses the
467// constant bus.
468def KImmFP16MatchClass : KImmMatchClass<16>;
469def f16kimm : kimmOperand<i16>;
470
471
472def VOPDstS64 : VOPDstOperand <SReg_64>;
473
474class FPInputModsMatchClass <int opSize> : AsmOperandClass {
475  let Name = "RegOrImmWithFP"#opSize#"InputMods";
476  let ParserMethod = "parseRegOrImmWithFPInputMods";
477  let PredicateMethod = "isRegOrImmWithFP"#opSize#"InputMods";
478}
479def FP16InputModsMatchClass : FPInputModsMatchClass<16>;
480def FP32InputModsMatchClass : FPInputModsMatchClass<32>;
481def FP64InputModsMatchClass : FPInputModsMatchClass<64>;
482
483class InputMods <AsmOperandClass matchClass> : Operand <i32> {
484  let OperandNamespace = "AMDGPU";
485  let OperandType = "OPERAND_INPUT_MODS";
486  let ParserMatchClass = matchClass;
487}
488
489class FPInputMods <FPInputModsMatchClass matchClass> : InputMods <matchClass> {
490  let PrintMethod = "printOperandAndFPInputMods";
491}
492
493def FP16InputMods : FPInputMods<FP16InputModsMatchClass>;
494def FP32InputMods : FPInputMods<FP32InputModsMatchClass>;
495def FP64InputMods : FPInputMods<FP64InputModsMatchClass>;
496
497class IntInputModsMatchClass <int opSize> : AsmOperandClass {
498  let Name = "RegOrImmWithInt"#opSize#"InputMods";
499  let ParserMethod = "parseRegOrImmWithIntInputMods";
500  let PredicateMethod = "isRegOrImmWithInt"#opSize#"InputMods";
501}
502def Int32InputModsMatchClass : IntInputModsMatchClass<32>;
503def Int64InputModsMatchClass : IntInputModsMatchClass<64>;
504
505class IntInputMods <IntInputModsMatchClass matchClass> : InputMods <matchClass> {
506  let PrintMethod = "printOperandAndIntInputMods";
507}
508def Int32InputMods : IntInputMods<Int32InputModsMatchClass>;
509def Int64InputMods : IntInputMods<Int64InputModsMatchClass>;
510
511//===----------------------------------------------------------------------===//
512// Complex patterns
513//===----------------------------------------------------------------------===//
514
515def DS1Addr1Offset : ComplexPattern<i32, 2, "SelectDS1Addr1Offset">;
516def DS64Bit4ByteAligned : ComplexPattern<i32, 3, "SelectDS64Bit4ByteAligned">;
517
518def MOVRELOffset : ComplexPattern<i32, 2, "SelectMOVRELOffset">;
519
520def VOP3Mods0 : ComplexPattern<untyped, 4, "SelectVOP3Mods0">;
521def VOP3NoMods0 : ComplexPattern<untyped, 4, "SelectVOP3NoMods0">;
522def VOP3Mods0Clamp : ComplexPattern<untyped, 3, "SelectVOP3Mods0Clamp">;
523def VOP3Mods0Clamp0OMod : ComplexPattern<untyped, 4, "SelectVOP3Mods0Clamp0OMod">;
524def VOP3Mods  : ComplexPattern<untyped, 2, "SelectVOP3Mods">;
525def VOP3NoMods : ComplexPattern<untyped, 2, "SelectVOP3NoMods">;
526
527//===----------------------------------------------------------------------===//
528// SI assembler operands
529//===----------------------------------------------------------------------===//
530
531def SIOperand {
532  int ZERO = 0x80;
533  int VCC = 0x6A;
534  int FLAT_SCR = 0x68;
535}
536
537def SRCMODS {
538  int NONE = 0;
539  int NEG = 1;
540}
541
542def DSTCLAMP {
543  int NONE = 0;
544}
545
546def DSTOMOD {
547  int NONE = 0;
548}
549
550//===----------------------------------------------------------------------===//
551//
552// SI Instruction multiclass helpers.
553//
554// Instructions with _32 take 32-bit operands.
555// Instructions with _64 take 64-bit operands.
556//
557// VOP_* instructions can use either a 32-bit or 64-bit encoding.  The 32-bit
558// encoding is the standard encoding, but instruction that make use of
559// any of the instruction modifiers must use the 64-bit encoding.
560//
561// Instructions with _e32 use the 32-bit encoding.
562// Instructions with _e64 use the 64-bit encoding.
563//
564//===----------------------------------------------------------------------===//
565
566class SIMCInstr <string pseudo, int subtarget> {
567  string PseudoInstr = pseudo;
568  int Subtarget = subtarget;
569}
570
571//===----------------------------------------------------------------------===//
572// EXP classes
573//===----------------------------------------------------------------------===//
574
575class EXP_Helper<bit done, SDPatternOperator node = null_frag> : EXPCommon<
576  (outs),
577  (ins exp_tgt:$tgt,
578       ExpSrc0:$src0, ExpSrc1:$src1, ExpSrc2:$src2, ExpSrc3:$src3,
579       exp_vm:$vm, exp_compr:$compr, i8imm:$en),
580  "exp$tgt $src0, $src1, $src2, $src3"#!if(done, " done", "")#"$compr$vm",
581  [(node (i8 timm:$en), (i1 timm:$vm), (i8 timm:$tgt), (i1 timm:$compr),
582         f32:$src0, f32:$src1, f32:$src2, f32:$src3)]> {
583  let AsmMatchConverter = "cvtExp";
584}
585
586// Split EXP instruction into EXP and EXP_DONE so we can set
587// mayLoad for done=1.
588multiclass EXP_m<bit done, SDPatternOperator node> {
589  let mayLoad = done in {
590    let isPseudo = 1, isCodeGenOnly = 1 in {
591      def "" : EXP_Helper<done, node>,
592               SIMCInstr <"exp"#!if(done, "_done", ""), SIEncodingFamily.NONE>;
593    }
594
595    let done = done in {
596      def _si : EXP_Helper<done>,
597                SIMCInstr <"exp"#!if(done, "_done", ""), SIEncodingFamily.SI>,
598                EXPe {
599        let DecoderNamespace = "SICI";
600        let DisableDecoder = DisableSIDecoder;
601      }
602
603      def _vi : EXP_Helper<done>,
604                SIMCInstr <"exp"#!if(done, "_done", ""), SIEncodingFamily.VI>,
605                EXPe_vi {
606        let DecoderNamespace = "VI";
607        let DisableDecoder = DisableVIDecoder;
608      }
609    }
610  }
611}
612
613//===----------------------------------------------------------------------===//
614// Vector ALU classes
615//===----------------------------------------------------------------------===//
616
617class getNumSrcArgs<ValueType Src0, ValueType Src1, ValueType Src2> {
618  int ret =
619    !if (!eq(Src0.Value, untyped.Value),      0,
620      !if (!eq(Src1.Value, untyped.Value),    1,   // VOP1
621         !if (!eq(Src2.Value, untyped.Value), 2,   // VOP2
622                                              3))); // VOP3
623}
624
625// Returns the register class to use for the destination of VOP[123C]
626// instructions for the given VT.
627class getVALUDstForVT<ValueType VT> {
628  RegisterOperand ret = !if(!eq(VT.Size, 32), VOPDstOperand<VGPR_32>,
629                          !if(!eq(VT.Size, 128), VOPDstOperand<VReg_128>,
630                            !if(!eq(VT.Size, 64), VOPDstOperand<VReg_64>,
631                              !if(!eq(VT.Size, 16), VOPDstOperand<VGPR_32>,
632                              VOPDstOperand<SReg_64>)))); // else VT == i1
633}
634
635// Returns the register class to use for source 0 of VOP[12C]
636// instructions for the given VT.
637class getVOPSrc0ForVT<ValueType VT> {
638  bit isFP = !if(!eq(VT.Value, f16.Value), 1,
639             !if(!eq(VT.Value, f32.Value), 1,
640             !if(!eq(VT.Value, f64.Value), 1,
641             0)));
642  RegisterOperand ret = !if(isFP,
643                            !if(!eq(VT.Size, 64), VSrc_f64, !if(!eq(VT.Size, 16), VSrc_f16, VSrc_f32)),
644                            !if(!eq(VT.Size, 64), VSrc_b64, !if(!eq(VT.Size, 16), VSrc_b16, VSrc_b32)));
645}
646
647// Returns the vreg register class to use for source operand given VT
648class getVregSrcForVT<ValueType VT> {
649  RegisterClass ret = !if(!eq(VT.Size, 128), VReg_128,
650                        !if(!eq(VT.Size, 64), VReg_64, VGPR_32));
651}
652
653
654// Returns the register class to use for sources of VOP3 instructions for the
655// given VT.
656class getVOP3SrcForVT<ValueType VT> {
657  bit isFP = !if(!eq(VT.Value, f16.Value), 1,
658             !if(!eq(VT.Value, f32.Value), 1,
659             !if(!eq(VT.Value, f64.Value), 1,
660             0)));
661  RegisterOperand ret =
662  !if(!eq(VT.Size, 128),
663      VSrc_128,
664    !if(!eq(VT.Size, 64),
665        !if(isFP,
666            VCSrc_f64,
667            VCSrc_b64),
668        !if(!eq(VT.Value, i1.Value),
669            SCSrc_b64,
670            !if(isFP,
671                !if(!eq(VT.Size, 16), VCSrc_f16, VCSrc_f32),
672                !if(!eq(VT.Size, 16), VCSrc_b16, VCSrc_b32)
673            )
674         )
675	   )
676     );
677}
678
679// Returns 1 if the source arguments have modifiers, 0 if they do not.
680// XXX - do f16 instructions?
681class isFloatType<ValueType SrcVT> {
682  bit ret =
683    !if(!eq(SrcVT.Value, f16.Value), 1,
684    !if(!eq(SrcVT.Value, f32.Value), 1,
685    !if(!eq(SrcVT.Value, f64.Value), 1,
686    0)));
687}
688
689class isIntType<ValueType SrcVT> {
690  bit ret =
691    !if(!eq(SrcVT.Value, i16.Value), 1,
692    !if(!eq(SrcVT.Value, i32.Value), 1,
693    !if(!eq(SrcVT.Value, i64.Value), 1,
694    0)));
695}
696
697
698// Return type of input modifiers operand for specified input operand
699class getSrcMod <ValueType VT> {
700  bit isFP = !if(!eq(VT.Value, f16.Value), 1,
701               !if(!eq(VT.Value, f32.Value), 1,
702               !if(!eq(VT.Value, f64.Value), 1,
703               0)));
704  Operand ret =  !if(!eq(VT.Size, 64),
705                     !if(isFP, FP64InputMods, Int64InputMods),
706                       !if(isFP,
707                         !if(!eq(VT.Value, f16.Value),
708                            FP16InputMods,
709                            FP32InputMods
710                          ),
711                         Int32InputMods)
712                     );
713}
714
715// Returns the input arguments for VOP[12C] instructions for the given SrcVT.
716class getIns32 <RegisterOperand Src0RC, RegisterClass Src1RC, int NumSrcArgs> {
717  dag ret = !if(!eq(NumSrcArgs, 1), (ins Src0RC:$src0),               // VOP1
718            !if(!eq(NumSrcArgs, 2), (ins Src0RC:$src0, Src1RC:$src1), // VOP2
719                                    (ins)));
720}
721
722// Returns the input arguments for VOP3 instructions for the given SrcVT.
723class getIns64 <RegisterOperand Src0RC, RegisterOperand Src1RC,
724                RegisterOperand Src2RC, int NumSrcArgs,
725                bit HasModifiers, Operand Src0Mod, Operand Src1Mod,
726                Operand Src2Mod> {
727
728  dag ret =
729    !if (!eq(NumSrcArgs, 0),
730      // VOP1 without input operands (V_NOP, V_CLREXCP)
731      (ins),
732      /* else */
733    !if (!eq(NumSrcArgs, 1),
734      !if (!eq(HasModifiers, 1),
735        // VOP1 with modifiers
736        (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
737             clampmod:$clamp, omod:$omod)
738      /* else */,
739        // VOP1 without modifiers
740        (ins Src0RC:$src0)
741      /* endif */ ),
742    !if (!eq(NumSrcArgs, 2),
743      !if (!eq(HasModifiers, 1),
744        // VOP 2 with modifiers
745        (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
746             Src1Mod:$src1_modifiers, Src1RC:$src1,
747             clampmod:$clamp, omod:$omod)
748      /* else */,
749        // VOP2 without modifiers
750        (ins Src0RC:$src0, Src1RC:$src1)
751      /* endif */ )
752    /* NumSrcArgs == 3 */,
753      !if (!eq(HasModifiers, 1),
754        // VOP3 with modifiers
755        (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
756             Src1Mod:$src1_modifiers, Src1RC:$src1,
757             Src2Mod:$src2_modifiers, Src2RC:$src2,
758             clampmod:$clamp, omod:$omod)
759      /* else */,
760        // VOP3 without modifiers
761        (ins Src0RC:$src0, Src1RC:$src1, Src2RC:$src2)
762      /* endif */ ))));
763}
764
765class getInsDPP <RegisterClass Src0RC, RegisterClass Src1RC, int NumSrcArgs,
766                 bit HasModifiers, Operand Src0Mod, Operand Src1Mod> {
767
768  dag ret = !if (!eq(NumSrcArgs, 0),
769                // VOP1 without input operands (V_NOP)
770                (ins dpp_ctrl:$dpp_ctrl, row_mask:$row_mask,
771                     bank_mask:$bank_mask, bound_ctrl:$bound_ctrl),
772            !if (!eq(NumSrcArgs, 1),
773              !if (!eq(HasModifiers, 1),
774                // VOP1_DPP with modifiers
775                (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
776                     dpp_ctrl:$dpp_ctrl, row_mask:$row_mask,
777                     bank_mask:$bank_mask, bound_ctrl:$bound_ctrl)
778              /* else */,
779                // VOP1_DPP without modifiers
780                (ins Src0RC:$src0, dpp_ctrl:$dpp_ctrl, row_mask:$row_mask,
781                bank_mask:$bank_mask, bound_ctrl:$bound_ctrl)
782              /* endif */)
783              /* NumSrcArgs == 2 */,
784              !if (!eq(HasModifiers, 1),
785                // VOP2_DPP with modifiers
786                (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
787                     Src1Mod:$src1_modifiers, Src1RC:$src1,
788                     dpp_ctrl:$dpp_ctrl, row_mask:$row_mask,
789                     bank_mask:$bank_mask, bound_ctrl:$bound_ctrl)
790              /* else */,
791                // VOP2_DPP without modifiers
792                (ins Src0RC:$src0, Src1RC:$src1, dpp_ctrl:$dpp_ctrl,
793                row_mask:$row_mask, bank_mask:$bank_mask,
794                bound_ctrl:$bound_ctrl)
795             /* endif */)));
796}
797
798class getInsSDWA <RegisterClass Src0RC, RegisterClass Src1RC, int NumSrcArgs,
799                  bit HasFloatModifiers, Operand Src0Mod, Operand Src1Mod,
800                  ValueType DstVT> {
801
802  dag ret = !if(!eq(NumSrcArgs, 0),
803               // VOP1 without input operands (V_NOP)
804               (ins),
805            !if(!eq(NumSrcArgs, 1),
806               (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
807                    clampmod:$clamp, dst_sel:$dst_sel, dst_unused:$dst_unused,
808                    src0_sel:$src0_sel),
809            !if(!eq(NumSrcArgs, 2),
810               !if(!eq(DstVT.Size, 1),
811                  // VOPC_SDWA with float modifiers
812                  (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
813                       Src1Mod:$src1_modifiers, Src1RC:$src1,
814                       clampmod:$clamp, src0_sel:$src0_sel, src1_sel:$src1_sel),
815                  // VOP2_SDWA or VOPC_SDWA with float modifiers
816                  (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
817                       Src1Mod:$src1_modifiers, Src1RC:$src1,
818                       clampmod:$clamp, dst_sel:$dst_sel, dst_unused:$dst_unused,
819                       src0_sel:$src0_sel, src1_sel:$src1_sel)),
820            (ins)/* endif */)));
821}
822
823// Outs for DPP and SDWA
824class getOutsExt <bit HasDst, ValueType DstVT, RegisterOperand DstRCDPP> {
825  dag ret = !if(HasDst,
826                !if(!eq(DstVT.Size, 1),
827                    (outs), // no dst for VOPC, we use "vcc"-token as dst in SDWA VOPC instructions
828                    (outs DstRCDPP:$vdst)),
829                (outs)); // V_NOP
830}
831
832// Returns the assembly string for the inputs and outputs of a VOP[12C]
833// instruction.  This does not add the _e32 suffix, so it can be reused
834// by getAsm64.
835class getAsm32 <bit HasDst, int NumSrcArgs, ValueType DstVT = i32> {
836  string dst = !if(!eq(DstVT.Size, 1), "$sdst", "$vdst"); // use $sdst for VOPC
837  string src0 = ", $src0";
838  string src1 = ", $src1";
839  string src2 = ", $src2";
840  string ret = !if(HasDst, dst, "") #
841               !if(!eq(NumSrcArgs, 1), src0, "") #
842               !if(!eq(NumSrcArgs, 2), src0#src1, "") #
843               !if(!eq(NumSrcArgs, 3), src0#src1#src2, "");
844}
845
846// Returns the assembly string for the inputs and outputs of a VOP3
847// instruction.
848class getAsm64 <bit HasDst, int NumSrcArgs, bit HasModifiers, ValueType DstVT = i32> {
849  string dst = !if(!eq(DstVT.Size, 1), "$sdst", "$vdst"); // use $sdst for VOPC
850  string src0 = !if(!eq(NumSrcArgs, 1), "$src0_modifiers", "$src0_modifiers,");
851  string src1 = !if(!eq(NumSrcArgs, 1), "",
852                   !if(!eq(NumSrcArgs, 2), " $src1_modifiers",
853                                           " $src1_modifiers,"));
854  string src2 = !if(!eq(NumSrcArgs, 3), " $src2_modifiers", "");
855  string ret =
856  !if(!eq(HasModifiers, 0),
857      getAsm32<HasDst, NumSrcArgs, DstVT>.ret,
858      dst#", "#src0#src1#src2#"$clamp"#"$omod");
859}
860
861class getAsmDPP <bit HasDst, int NumSrcArgs, bit HasModifiers, ValueType DstVT = i32> {
862  string dst = !if(HasDst,
863                   !if(!eq(DstVT.Size, 1),
864                       "$sdst",
865                       "$vdst"),
866                    ""); // use $sdst for VOPC
867  string src0 = !if(!eq(NumSrcArgs, 1), "$src0_modifiers", "$src0_modifiers,");
868  string src1 = !if(!eq(NumSrcArgs, 1), "",
869                   !if(!eq(NumSrcArgs, 2), " $src1_modifiers",
870                                           " $src1_modifiers,"));
871  string args = !if(!eq(HasModifiers, 0),
872                     getAsm32<0, NumSrcArgs, DstVT>.ret,
873                     ", "#src0#src1);
874  string ret = dst#args#" $dpp_ctrl$row_mask$bank_mask$bound_ctrl";
875}
876
877class getAsmSDWA <bit HasDst, int NumSrcArgs, bit HasFloatModifiers,
878                  ValueType DstVT = i32> {
879  string dst = !if(HasDst,
880                   !if(!eq(DstVT.Size, 1),
881                       " vcc", // use vcc token as dst for VOPC instructioins
882                       "$vdst"),
883                    "");
884  string src0 = "$src0_modifiers";
885  string src1 = "$src1_modifiers";
886  string args = !if(!eq(NumSrcArgs, 0),
887                    "",
888                    !if(!eq(NumSrcArgs, 1),
889                        ", "#src0#"$clamp",
890                        ", "#src0#", "#src1#"$clamp"
891                     )
892                );
893  string sdwa = !if(!eq(NumSrcArgs, 0),
894                    "",
895                    !if(!eq(NumSrcArgs, 1),
896                        " $dst_sel $dst_unused $src0_sel",
897                        !if(!eq(DstVT.Size, 1),
898                            " $src0_sel $src1_sel", // No dst_sel and dst_unused for VOPC
899                            " $dst_sel $dst_unused $src0_sel $src1_sel"
900                        )
901                    )
902                );
903  string ret = dst#args#sdwa;
904}
905
906// Function that checks if instruction supports DPP and SDWA
907class getHasExt <int NumSrcArgs, ValueType DstVT = i32, ValueType Src0VT = i32,
908                 ValueType Src1VT = i32> {
909  bit ret = !if(!eq(NumSrcArgs, 3),
910                0, // NumSrcArgs == 3 - No DPP or SDWA for VOP3
911                !if(!eq(DstVT.Size, 64),
912                    0, // 64-bit dst - No DPP or SDWA for 64-bit operands
913                    !if(!eq(Src0VT.Size, 64),
914                        0, // 64-bit src0
915                        !if(!eq(Src0VT.Size, 64),
916                            0, // 64-bit src2
917                            1
918                        )
919                    )
920                )
921            );
922}
923
924class BitOr<bit a, bit b> {
925  bit ret = !if(a, 1, !if(b, 1, 0));
926}
927
928class BitAnd<bit a, bit b> {
929  bit ret = !if(a, !if(b, 1, 0), 0);
930}
931
932class VOPProfile <list<ValueType> _ArgVT> {
933
934  field list<ValueType> ArgVT = _ArgVT;
935
936  field ValueType DstVT = ArgVT[0];
937  field ValueType Src0VT = ArgVT[1];
938  field ValueType Src1VT = ArgVT[2];
939  field ValueType Src2VT = ArgVT[3];
940  field RegisterOperand DstRC = getVALUDstForVT<DstVT>.ret;
941  field RegisterOperand DstRCDPP = getVALUDstForVT<DstVT>.ret;
942  field RegisterOperand DstRCSDWA = getVALUDstForVT<DstVT>.ret;
943  field RegisterOperand Src0RC32 = getVOPSrc0ForVT<Src0VT>.ret;
944  field RegisterClass Src1RC32 = getVregSrcForVT<Src1VT>.ret;
945  field RegisterOperand Src0RC64 = getVOP3SrcForVT<Src0VT>.ret;
946  field RegisterOperand Src1RC64 = getVOP3SrcForVT<Src1VT>.ret;
947  field RegisterOperand Src2RC64 = getVOP3SrcForVT<Src2VT>.ret;
948  field RegisterClass Src0DPP = getVregSrcForVT<Src0VT>.ret;
949  field RegisterClass Src1DPP = getVregSrcForVT<Src1VT>.ret;
950  field RegisterClass Src0SDWA = getVregSrcForVT<Src0VT>.ret;
951  field RegisterClass Src1SDWA = getVregSrcForVT<Src1VT>.ret;
952  field Operand Src0Mod = getSrcMod<Src0VT>.ret;
953  field Operand Src1Mod = getSrcMod<Src1VT>.ret;
954  field Operand Src2Mod = getSrcMod<Src2VT>.ret;
955
956  field bit HasDst = !if(!eq(DstVT.Value, untyped.Value), 0, 1);
957  field bit HasDst32 = HasDst;
958  field bit EmitDst = HasDst; // force dst encoding, see v_movreld_b32 special case
959  field int NumSrcArgs = getNumSrcArgs<Src0VT, Src1VT, Src2VT>.ret;
960  field bit HasSrc0 = !if(!eq(Src0VT.Value, untyped.Value), 0, 1);
961  field bit HasSrc1 = !if(!eq(Src1VT.Value, untyped.Value), 0, 1);
962  field bit HasSrc2 = !if(!eq(Src2VT.Value, untyped.Value), 0, 1);
963
964  // TODO: Modifiers logic is somewhat adhoc here, to be refined later
965  field bit HasModifiers = isFloatType<Src0VT>.ret;
966
967  field bit HasSrc0FloatMods = isFloatType<Src0VT>.ret;
968  field bit HasSrc1FloatMods = isFloatType<Src1VT>.ret;
969  field bit HasSrc2FloatMods = isFloatType<Src2VT>.ret;
970
971  field bit HasSrc0IntMods = isIntType<Src0VT>.ret;
972  field bit HasSrc1IntMods = isIntType<Src1VT>.ret;
973  field bit HasSrc2IntMods = isIntType<Src2VT>.ret;
974
975  field bit HasSrc0Mods = HasModifiers;
976  field bit HasSrc1Mods = !if(HasModifiers, BitOr<HasSrc1FloatMods, HasSrc1IntMods>.ret, 0);
977  field bit HasSrc2Mods = !if(HasModifiers, BitOr<HasSrc2FloatMods, HasSrc2IntMods>.ret, 0);
978
979  field bit HasOMod = HasModifiers;
980  field bit HasClamp = HasModifiers;
981  field bit HasSDWAClamp = HasSrc0;
982
983  field bit HasExt = getHasExt<NumSrcArgs, DstVT, Src0VT, Src1VT>.ret;
984
985  field dag Outs = !if(HasDst,(outs DstRC:$vdst),(outs));
986
987  // VOP3b instructions are a special case with a second explicit
988  // output. This is manually overridden for them.
989  field dag Outs32 = Outs;
990  field dag Outs64 = Outs;
991  field dag OutsDPP = getOutsExt<HasDst, DstVT, DstRCDPP>.ret;
992  field dag OutsSDWA = getOutsExt<HasDst, DstVT, DstRCDPP>.ret;
993
994  field dag Ins32 = getIns32<Src0RC32, Src1RC32, NumSrcArgs>.ret;
995  field dag Ins64 = getIns64<Src0RC64, Src1RC64, Src2RC64, NumSrcArgs,
996                             HasModifiers, Src0Mod, Src1Mod, Src2Mod>.ret;
997  field dag InsDPP = getInsDPP<Src0DPP, Src1DPP, NumSrcArgs,
998                               HasModifiers, Src0Mod, Src1Mod>.ret;
999  field dag InsSDWA = getInsSDWA<Src0SDWA, Src1SDWA, NumSrcArgs,
1000                                 HasModifiers, Src0Mod, Src1Mod, DstVT>.ret;
1001
1002  field string Asm32 = getAsm32<HasDst, NumSrcArgs, DstVT>.ret;
1003  field string Asm64 = getAsm64<HasDst, NumSrcArgs, HasModifiers, DstVT>.ret;
1004  field string AsmDPP = getAsmDPP<HasDst, NumSrcArgs, HasModifiers, DstVT>.ret;
1005  field string AsmSDWA = getAsmSDWA<HasDst, NumSrcArgs, HasModifiers, DstVT>.ret;
1006}
1007
1008class VOP_NO_EXT <VOPProfile p> : VOPProfile <p.ArgVT> {
1009  let HasExt = 0;
1010}
1011
1012def VOP_F16_F16 : VOPProfile <[f16, f16, untyped, untyped]>;
1013def VOP_F16_I16 : VOPProfile <[f16, i16, untyped, untyped]>;
1014def VOP_I16_F16 : VOPProfile <[i16, f16, untyped, untyped]>;
1015
1016def VOP_F16_F16_F16 : VOPProfile <[f16, f16, f16, untyped]>;
1017def VOP_F16_F16_I16 : VOPProfile <[f16, f16, i16, untyped]>;
1018def VOP_F16_F16_I32 : VOPProfile <[f16, f16, i32, untyped]>;
1019def VOP_I16_I16_I16 : VOPProfile <[i32, i32, i32, untyped]>;
1020
1021def VOP_I16_I16_I16_I16 : VOPProfile <[i32, i32, i32, i32, untyped]>;
1022def VOP_F16_F16_F16_F16 : VOPProfile <[f16, f16, f16, f16, untyped]>;
1023
1024def VOP_NONE : VOPProfile <[untyped, untyped, untyped, untyped]>;
1025
1026def VOP_F32_F32 : VOPProfile <[f32, f32, untyped, untyped]>;
1027def VOP_F32_F64 : VOPProfile <[f32, f64, untyped, untyped]>;
1028def VOP_F32_I32 : VOPProfile <[f32, i32, untyped, untyped]>;
1029def VOP_F64_F32 : VOPProfile <[f64, f32, untyped, untyped]>;
1030def VOP_F64_F64 : VOPProfile <[f64, f64, untyped, untyped]>;
1031def VOP_F64_I32 : VOPProfile <[f64, i32, untyped, untyped]>;
1032def VOP_I32_F32 : VOPProfile <[i32, f32, untyped, untyped]>;
1033def VOP_I32_F64 : VOPProfile <[i32, f64, untyped, untyped]>;
1034def VOP_I32_I32 : VOPProfile <[i32, i32, untyped, untyped]>;
1035
1036def VOP_F32_F32_F16 : VOPProfile <[f32, f32, f16, untyped]>;
1037def VOP_F32_F32_F32 : VOPProfile <[f32, f32, f32, untyped]>;
1038def VOP_F32_F32_I32 : VOPProfile <[f32, f32, i32, untyped]>;
1039def VOP_F64_F64_F64 : VOPProfile <[f64, f64, f64, untyped]>;
1040def VOP_F64_F64_I32 : VOPProfile <[f64, f64, i32, untyped]>;
1041def VOP_I32_F32_F32 : VOPProfile <[i32, f32, f32, untyped]>;
1042def VOP_I32_F32_I32 : VOPProfile <[i32, f32, i32, untyped]>;
1043def VOP_I32_I32_I32 : VOPProfile <[i32, i32, i32, untyped]>;
1044
1045def VOP_I64_I64_I32 : VOPProfile <[i64, i64, i32, untyped]>;
1046def VOP_I64_I32_I64 : VOPProfile <[i64, i32, i64, untyped]>;
1047def VOP_I64_I64_I64 : VOPProfile <[i64, i64, i64, untyped]>;
1048
1049def VOP_F16_F32_F16_F32 : VOPProfile <[f16, f32, f16, f32]>;
1050def VOP_F32_F32_F16_F16 : VOPProfile <[f32, f32, f16, f16]>;
1051def VOP_F32_F32_F32_F32 : VOPProfile <[f32, f32, f32, f32]>;
1052def VOP_F64_F64_F64_F64 : VOPProfile <[f64, f64, f64, f64]>;
1053def VOP_I32_I32_I32_I32 : VOPProfile <[i32, i32, i32, i32]>;
1054def VOP_I64_I32_I32_I64 : VOPProfile <[i64, i32, i32, i64]>;
1055def VOP_I32_F32_I32_I32 : VOPProfile <[i32, f32, i32, i32]>;
1056def VOP_I64_I64_I32_I64 : VOPProfile <[i64, i64, i32, i64]>;
1057def VOP_V4I32_I64_I32_V4I32 : VOPProfile <[v4i32, i64, i32, v4i32]>;
1058
1059class Commutable_REV <string revOp, bit isOrig> {
1060  string RevOp = revOp;
1061  bit IsOrig = isOrig;
1062}
1063
1064class AtomicNoRet <string noRetOp, bit isRet> {
1065  string NoRetOp = noRetOp;
1066  bit IsRet = isRet;
1067}
1068
1069//===----------------------------------------------------------------------===//
1070// Interpolation opcodes
1071//===----------------------------------------------------------------------===//
1072
1073class VINTRP_Pseudo <string opName, dag outs, dag ins, list<dag> pattern> :
1074  VINTRPCommon <outs, ins, "", pattern>,
1075  SIMCInstr<opName, SIEncodingFamily.NONE> {
1076  let isPseudo = 1;
1077  let isCodeGenOnly = 1;
1078}
1079
1080class VINTRP_Real_si <bits <2> op, string opName, dag outs, dag ins,
1081                      string asm> :
1082  VINTRPCommon <outs, ins, asm, []>,
1083  VINTRPe <op>,
1084  SIMCInstr<opName, SIEncodingFamily.SI> {
1085  let AssemblerPredicate = SIAssemblerPredicate;
1086  let DecoderNamespace = "SICI";
1087  let DisableDecoder = DisableSIDecoder;
1088}
1089
1090class VINTRP_Real_vi <bits <2> op, string opName, dag outs, dag ins,
1091                      string asm> :
1092  VINTRPCommon <outs, ins, asm, []>,
1093  VINTRPe_vi <op>,
1094  SIMCInstr<opName, SIEncodingFamily.VI> {
1095  let AssemblerPredicate = VIAssemblerPredicate;
1096  let DecoderNamespace = "VI";
1097  let DisableDecoder = DisableVIDecoder;
1098}
1099
1100multiclass VINTRP_m <bits <2> op, dag outs, dag ins, string asm,
1101                     list<dag> pattern = []> {
1102  def "" : VINTRP_Pseudo <NAME, outs, ins, pattern>;
1103
1104  def _si : VINTRP_Real_si <op, NAME, outs, ins, asm>;
1105
1106  def _vi : VINTRP_Real_vi <op, NAME, outs, ins, asm>;
1107}
1108
1109//===----------------------------------------------------------------------===//
1110// Vector instruction mappings
1111//===----------------------------------------------------------------------===//
1112
1113// Maps an opcode in e32 form to its e64 equivalent
1114def getVOPe64 : InstrMapping {
1115  let FilterClass = "VOP";
1116  let RowFields = ["OpName"];
1117  let ColFields = ["Size", "VOP3"];
1118  let KeyCol = ["4", "0"];
1119  let ValueCols = [["8", "1"]];
1120}
1121
1122// Maps an opcode in e64 form to its e32 equivalent
1123def getVOPe32 : InstrMapping {
1124  let FilterClass = "VOP";
1125  let RowFields = ["OpName"];
1126  let ColFields = ["Size", "VOP3"];
1127  let KeyCol = ["8", "1"];
1128  let ValueCols = [["4", "0"]];
1129}
1130
1131def getMaskedMIMGOp : InstrMapping {
1132  let FilterClass = "MIMG_Mask";
1133  let RowFields = ["Op"];
1134  let ColFields = ["Channels"];
1135  let KeyCol = ["4"];
1136  let ValueCols = [["1"], ["2"], ["3"] ];
1137}
1138
1139// Maps an commuted opcode to its original version
1140def getCommuteOrig : InstrMapping {
1141  let FilterClass = "Commutable_REV";
1142  let RowFields = ["RevOp"];
1143  let ColFields = ["IsOrig"];
1144  let KeyCol = ["0"];
1145  let ValueCols = [["1"]];
1146}
1147
1148// Maps an original opcode to its commuted version
1149def getCommuteRev : InstrMapping {
1150  let FilterClass = "Commutable_REV";
1151  let RowFields = ["RevOp"];
1152  let ColFields = ["IsOrig"];
1153  let KeyCol = ["1"];
1154  let ValueCols = [["0"]];
1155}
1156
1157def getMCOpcodeGen : InstrMapping {
1158  let FilterClass = "SIMCInstr";
1159  let RowFields = ["PseudoInstr"];
1160  let ColFields = ["Subtarget"];
1161  let KeyCol = [!cast<string>(SIEncodingFamily.NONE)];
1162  let ValueCols = [[!cast<string>(SIEncodingFamily.SI)],
1163                   [!cast<string>(SIEncodingFamily.VI)]];
1164}
1165
1166// Get equivalent SOPK instruction.
1167def getSOPKOp : InstrMapping {
1168  let FilterClass = "SOPKInstTable";
1169  let RowFields = ["BaseCmpOp"];
1170  let ColFields = ["IsSOPK"];
1171  let KeyCol = ["0"];
1172  let ValueCols = [["1"]];
1173}
1174
1175def getAddr64Inst : InstrMapping {
1176  let FilterClass = "MUBUFAddr64Table";
1177  let RowFields = ["OpName"];
1178  let ColFields = ["IsAddr64"];
1179  let KeyCol = ["0"];
1180  let ValueCols = [["1"]];
1181}
1182
1183// Maps an atomic opcode to its version with a return value.
1184def getAtomicRetOp : InstrMapping {
1185  let FilterClass = "AtomicNoRet";
1186  let RowFields = ["NoRetOp"];
1187  let ColFields = ["IsRet"];
1188  let KeyCol = ["0"];
1189  let ValueCols = [["1"]];
1190}
1191
1192// Maps an atomic opcode to its returnless version.
1193def getAtomicNoRetOp : InstrMapping {
1194  let FilterClass = "AtomicNoRet";
1195  let RowFields = ["NoRetOp"];
1196  let ColFields = ["IsRet"];
1197  let KeyCol = ["1"];
1198  let ValueCols = [["0"]];
1199}
1200
1201include "SIInstructions.td"
1202include "CIInstructions.td"
1203
1204include "DSInstructions.td"
1205include "MIMGInstructions.td"
1206