1 //===-- SIInstrInfo.td - SI Instruction Infos -------------*- tablegen -*--===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
9 def isCI : Predicate<"Subtarget->getGeneration() "
10 ">= SISubtarget::SEA_ISLANDS">;
11 def isCIOnly : Predicate<"Subtarget->getGeneration() =="
12 "SISubtarget::SEA_ISLANDS">,
13 AssemblerPredicate <"FeatureSeaIslands">;
15 def DisableInst : Predicate <"false">, AssemblerPredicate<"FeatureDisable">;
17 // Execpt for the NONE field, this must be kept in sync with the
18 // SIEncodingFamily enum in AMDGPUInstrInfo.cpp
19 def SIEncodingFamily {
25 //===----------------------------------------------------------------------===//
27 //===----------------------------------------------------------------------===//
29 def SIload_constant : SDNode<"AMDGPUISD::LOAD_CONSTANT",
30 SDTypeProfile<1, 2, [SDTCisVT<0, f32>, SDTCisVT<1, v4i32>, SDTCisVT<2, i32>]>,
31 [SDNPMayLoad, SDNPMemOperand]
34 def SIatomic_inc : SDNode<"AMDGPUISD::ATOMIC_INC", SDTAtomic2,
35 [SDNPMayLoad, SDNPMayStore, SDNPMemOperand, SDNPHasChain]
38 def SIatomic_dec : SDNode<"AMDGPUISD::ATOMIC_DEC", SDTAtomic2,
39 [SDNPMayLoad, SDNPMayStore, SDNPMemOperand, SDNPHasChain]
42 def SItbuffer_store : SDNode<"AMDGPUISD::TBUFFER_STORE_FORMAT",
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)
58 [SDNPMayStore, SDNPMemOperand, SDNPHasChain]
61 def SDTBufferLoad : SDTypeProfile<1, 5,
63 SDTCisVT<1, v4i32>, // rsrc
64 SDTCisVT<2, i32>, // vindex
65 SDTCisVT<3, i32>, // offset
66 SDTCisVT<4, i1>, // glc
67 SDTCisVT<5, i1>]>; // slc
69 def SIbuffer_load : SDNode <"AMDGPUISD::BUFFER_LOAD", SDTBufferLoad,
70 [SDNPMemOperand, SDNPHasChain, SDNPMayLoad]>;
71 def SIbuffer_load_format : SDNode <"AMDGPUISD::BUFFER_LOAD_FORMAT", SDTBufferLoad,
72 [SDNPMemOperand, SDNPHasChain, SDNPMayLoad]>;
74 class SDSample<string opcode> : SDNode <opcode,
75 SDTypeProfile<1, 4, [SDTCisVT<0, v4f32>, SDTCisVT<2, v8i32>,
76 SDTCisVT<3, v4i32>, SDTCisVT<4, i32>]>
79 def SIsample : SDSample<"AMDGPUISD::SAMPLE">;
80 def SIsampleb : SDSample<"AMDGPUISD::SAMPLEB">;
81 def SIsampled : SDSample<"AMDGPUISD::SAMPLED">;
82 def SIsamplel : SDSample<"AMDGPUISD::SAMPLEL">;
84 def SIpc_add_rel_offset : SDNode<"AMDGPUISD::PC_ADD_REL_OFFSET",
85 SDTypeProfile<1, 2, [SDTCisVT<0, iPTR>, SDTCisSameAs<0,1>, SDTCisSameAs<0,2>]>
88 //===----------------------------------------------------------------------===//
89 // PatFrags for global memory operations
90 //===----------------------------------------------------------------------===//
92 defm atomic_inc_global : global_binary_atomic_op<SIatomic_inc>;
93 defm atomic_dec_global : global_binary_atomic_op<SIatomic_dec>;
95 //===----------------------------------------------------------------------===//
96 // SDNodes and PatFrag for local loads and stores to enable s_mov_b32 m0, -1
97 // to be glued to the memory instructions.
98 //===----------------------------------------------------------------------===//
100 def SIld_local : SDNode <"ISD::LOAD", SDTLoad,
101 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand, SDNPInGlue]
104 def si_ld_local : PatFrag <(ops node:$ptr), (SIld_local node:$ptr), [{
105 return cast<LoadSDNode>(N)->getAddressSpace() == AMDGPUASI.LOCAL_ADDRESS;
108 def si_load_local : PatFrag <(ops node:$ptr), (si_ld_local node:$ptr), [{
109 return cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED &&
110 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
113 def si_load_local_align8 : Aligned8Bytes <
114 (ops node:$ptr), (si_load_local node:$ptr)
117 def si_sextload_local : PatFrag <(ops node:$ptr), (si_ld_local node:$ptr), [{
118 return cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
120 def si_az_extload_local : AZExtLoadBase <si_ld_local>;
122 multiclass SIExtLoadLocal <PatFrag ld_node> {
124 def _i8 : PatFrag <(ops node:$ptr), (ld_node node:$ptr),
125 [{return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8;}]
128 def _i16 : PatFrag <(ops node:$ptr), (ld_node node:$ptr),
129 [{return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16;}]
133 defm si_sextload_local : SIExtLoadLocal <si_sextload_local>;
134 defm si_az_extload_local : SIExtLoadLocal <si_az_extload_local>;
136 def SIst_local : SDNode <"ISD::STORE", SDTStore,
137 [SDNPHasChain, SDNPMayStore, SDNPMemOperand, SDNPInGlue]
140 def si_st_local : PatFrag <
141 (ops node:$val, node:$ptr), (SIst_local node:$val, node:$ptr), [{
142 return cast<StoreSDNode>(N)->getAddressSpace() == AMDGPUASI.LOCAL_ADDRESS;
145 def si_store_local : PatFrag <
146 (ops node:$val, node:$ptr), (si_st_local node:$val, node:$ptr), [{
147 return cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED &&
148 !cast<StoreSDNode>(N)->isTruncatingStore();
151 def si_store_local_align8 : Aligned8Bytes <
152 (ops node:$val, node:$ptr), (si_store_local node:$val, node:$ptr)
155 def si_truncstore_local : PatFrag <
156 (ops node:$val, node:$ptr), (si_st_local node:$val, node:$ptr), [{
157 return cast<StoreSDNode>(N)->isTruncatingStore();
160 def si_truncstore_local_i8 : PatFrag <
161 (ops node:$val, node:$ptr), (si_truncstore_local node:$val, node:$ptr), [{
162 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i8;
165 def si_truncstore_local_i16 : PatFrag <
166 (ops node:$val, node:$ptr), (si_truncstore_local node:$val, node:$ptr), [{
167 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i16;
170 def si_setcc_uniform : PatFrag <
171 (ops node:$lhs, node:$rhs, node:$cond),
172 (setcc node:$lhs, node:$rhs, node:$cond), [{
173 for (SDNode *Use : N->uses()) {
174 if (Use->isMachineOpcode() || Use->getOpcode() != ISD::CopyToReg)
177 unsigned Reg = cast<RegisterSDNode>(Use->getOperand(1))->getReg();
178 if (Reg != AMDGPU::SCC)
184 def si_uniform_br : PatFrag <
185 (ops node:$cond, node:$bb), (brcond node:$cond, node:$bb), [{
186 return isUniformBr(N);
189 def si_uniform_br_scc : PatFrag <
190 (ops node:$cond, node:$bb), (si_uniform_br node:$cond, node:$bb), [{
191 return isCBranchSCC(N);
194 def lshr_rev : PatFrag <
195 (ops node:$src1, node:$src0),
199 def ashr_rev : PatFrag <
200 (ops node:$src1, node:$src0),
204 def lshl_rev : PatFrag <
205 (ops node:$src1, node:$src0),
209 multiclass SIAtomicM0Glue2 <string op_name, bit is_amdgpu = 0> {
212 !if(is_amdgpu, "AMDGPUISD", "ISD")#"::ATOMIC_"#op_name, SDTAtomic2,
213 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand, SDNPInGlue]
216 def _local : local_binary_atomic_op <!cast<SDNode>(NAME#"_glue")>;
219 defm si_atomic_load_add : SIAtomicM0Glue2 <"LOAD_ADD">;
220 defm si_atomic_load_sub : SIAtomicM0Glue2 <"LOAD_SUB">;
221 defm si_atomic_inc : SIAtomicM0Glue2 <"INC", 1>;
222 defm si_atomic_dec : SIAtomicM0Glue2 <"DEC", 1>;
223 defm si_atomic_load_and : SIAtomicM0Glue2 <"LOAD_AND">;
224 defm si_atomic_load_min : SIAtomicM0Glue2 <"LOAD_MIN">;
225 defm si_atomic_load_max : SIAtomicM0Glue2 <"LOAD_MAX">;
226 defm si_atomic_load_or : SIAtomicM0Glue2 <"LOAD_OR">;
227 defm si_atomic_load_xor : SIAtomicM0Glue2 <"LOAD_XOR">;
228 defm si_atomic_load_umin : SIAtomicM0Glue2 <"LOAD_UMIN">;
229 defm si_atomic_load_umax : SIAtomicM0Glue2 <"LOAD_UMAX">;
230 defm si_atomic_swap : SIAtomicM0Glue2 <"SWAP">;
232 def si_atomic_cmp_swap_glue : SDNode <"ISD::ATOMIC_CMP_SWAP", SDTAtomic3,
233 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand, SDNPInGlue]
236 defm si_atomic_cmp_swap : AtomicCmpSwapLocal <si_atomic_cmp_swap_glue>;
238 def as_i1imm : SDNodeXForm<imm, [{
239 return CurDAG->getTargetConstant(N->getZExtValue(), SDLoc(N), MVT::i1);
242 def as_i8imm : SDNodeXForm<imm, [{
243 return CurDAG->getTargetConstant(N->getZExtValue(), SDLoc(N), MVT::i8);
246 def as_i16imm : SDNodeXForm<imm, [{
247 return CurDAG->getTargetConstant(N->getSExtValue(), SDLoc(N), MVT::i16);
250 def as_i32imm: SDNodeXForm<imm, [{
251 return CurDAG->getTargetConstant(N->getSExtValue(), SDLoc(N), MVT::i32);
254 def as_i64imm: SDNodeXForm<imm, [{
255 return CurDAG->getTargetConstant(N->getSExtValue(), SDLoc(N), MVT::i64);
258 // Copied from the AArch64 backend:
259 def bitcast_fpimm_to_i32 : SDNodeXForm<fpimm, [{
260 return CurDAG->getTargetConstant(
261 N->getValueAPF().bitcastToAPInt().getZExtValue(), SDLoc(N), MVT::i32);
264 def frameindex_to_targetframeindex : SDNodeXForm<frameindex, [{
265 auto FI = cast<FrameIndexSDNode>(N);
266 return CurDAG->getTargetFrameIndex(FI->getIndex(), MVT::i32);
269 // Copied from the AArch64 backend:
270 def bitcast_fpimm_to_i64 : SDNodeXForm<fpimm, [{
271 return CurDAG->getTargetConstant(
272 N->getValueAPF().bitcastToAPInt().getZExtValue(), SDLoc(N), MVT::i64);
275 def SIMM16bit : PatLeaf <(imm),
276 [{return isInt<16>(N->getSExtValue());}]
279 class InlineImm <ValueType vt> : PatLeaf <(vt imm), [{
280 return isInlineImmediate(N);
283 class InlineFPImm <ValueType vt> : PatLeaf <(vt fpimm), [{
284 return isInlineImmediate(N);
287 class VGPRImm <dag frag> : PatLeaf<frag, [{
288 if (Subtarget->getGeneration() < SISubtarget::SOUTHERN_ISLANDS) {
291 const SIRegisterInfo *SIRI =
292 static_cast<const SIRegisterInfo *>(Subtarget->getRegisterInfo());
294 for (SDNode::use_iterator U = N->use_begin(), E = SDNode::use_end();
295 Limit < 10 && U != E; ++U, ++Limit) {
296 const TargetRegisterClass *RC = getOperandRegClass(*U, U.getOperandNo());
298 // If the register class is unknown, it could be an unknown
299 // register class that needs to be an SGPR, e.g. an inline asm
301 if (!RC || SIRI->isSGPRClass(RC))
308 def NegateImm : SDNodeXForm<imm, [{
309 return CurDAG->getConstant(-N->getSExtValue(), SDLoc(N), MVT::i32);
312 // TODO: When FP inline imm values work?
313 def NegSubInlineConst32 : ImmLeaf<i32, [{
314 return Imm < -16 && Imm >= -64;
317 def NegSubInlineConst16 : ImmLeaf<i16, [{
318 return Imm < -16 && Imm >= -64;
321 //===----------------------------------------------------------------------===//
323 //===----------------------------------------------------------------------===//
325 def SoppBrTarget : AsmOperandClass {
326 let Name = "SoppBrTarget";
327 let ParserMethod = "parseSOppBrTarget";
330 def sopp_brtarget : Operand<OtherVT> {
331 let EncoderMethod = "getSOPPBrEncoding";
332 let DecoderMethod = "decodeSoppBrTarget";
333 let OperandType = "OPERAND_PCREL";
334 let ParserMatchClass = SoppBrTarget;
337 def si_ga : Operand<iPTR>;
339 def InterpSlotMatchClass : AsmOperandClass {
340 let Name = "InterpSlot";
341 let PredicateMethod = "isInterpSlot";
342 let ParserMethod = "parseInterpSlot";
343 let RenderMethod = "addImmOperands";
346 def InterpSlot : Operand<i32> {
347 let PrintMethod = "printInterpSlot";
348 let ParserMatchClass = InterpSlotMatchClass;
349 let OperandType = "OPERAND_IMMEDIATE";
352 def AttrMatchClass : AsmOperandClass {
354 let PredicateMethod = "isInterpAttr";
355 let ParserMethod = "parseInterpAttr";
356 let RenderMethod = "addImmOperands";
359 // It appears to be necessary to create a separate operand for this to
360 // be able to parse attr<num> with no space.
361 def Attr : Operand<i32> {
362 let PrintMethod = "printInterpAttr";
363 let ParserMatchClass = AttrMatchClass;
364 let OperandType = "OPERAND_IMMEDIATE";
367 def AttrChanMatchClass : AsmOperandClass {
368 let Name = "AttrChan";
369 let PredicateMethod = "isAttrChan";
370 let RenderMethod = "addImmOperands";
373 def AttrChan : Operand<i32> {
374 let PrintMethod = "printInterpAttrChan";
375 let ParserMatchClass = AttrChanMatchClass;
376 let OperandType = "OPERAND_IMMEDIATE";
379 def SendMsgMatchClass : AsmOperandClass {
380 let Name = "SendMsg";
381 let PredicateMethod = "isSendMsg";
382 let ParserMethod = "parseSendMsgOp";
383 let RenderMethod = "addImmOperands";
386 def ExpTgtMatchClass : AsmOperandClass {
388 let PredicateMethod = "isExpTgt";
389 let ParserMethod = "parseExpTgt";
390 let RenderMethod = "printExpTgt";
393 def SendMsgImm : Operand<i32> {
394 let PrintMethod = "printSendMsg";
395 let ParserMatchClass = SendMsgMatchClass;
398 def SWaitMatchClass : AsmOperandClass {
399 let Name = "SWaitCnt";
400 let RenderMethod = "addImmOperands";
401 let ParserMethod = "parseSWaitCntOps";
404 def VReg32OrOffClass : AsmOperandClass {
405 let Name = "VReg32OrOff";
406 let ParserMethod = "parseVReg32OrOff";
409 def WAIT_FLAG : Operand <i32> {
410 let ParserMatchClass = SWaitMatchClass;
411 let PrintMethod = "printWaitFlag";
414 include "SIInstrFormats.td"
415 include "VIInstrFormats.td"
417 // ===----------------------------------------------------------------------===//
418 // ExpSrc* Special cases for exp src operands which are printed as
419 // "off" depending on en operand.
420 // ===----------------------------------------------------------------------===//
422 def ExpSrc0 : RegisterOperand<VGPR_32> {
423 let PrintMethod = "printExpSrc0";
424 let ParserMatchClass = VReg32OrOffClass;
427 def ExpSrc1 : RegisterOperand<VGPR_32> {
428 let PrintMethod = "printExpSrc1";
429 let ParserMatchClass = VReg32OrOffClass;
432 def ExpSrc2 : RegisterOperand<VGPR_32> {
433 let PrintMethod = "printExpSrc2";
434 let ParserMatchClass = VReg32OrOffClass;
437 def ExpSrc3 : RegisterOperand<VGPR_32> {
438 let PrintMethod = "printExpSrc3";
439 let ParserMatchClass = VReg32OrOffClass;
442 class NamedMatchClass<string CName, bit Optional = 1> : AsmOperandClass {
443 let Name = "Imm"#CName;
444 let PredicateMethod = "is"#CName;
445 let ParserMethod = !if(Optional, "parseOptionalOperand", "parse"#CName);
446 let RenderMethod = "addImmOperands";
447 let IsOptional = Optional;
448 let DefaultMethod = !if(Optional, "default"#CName, ?);
451 class NamedOperandBit<string Name, AsmOperandClass MatchClass> : Operand<i1> {
452 let PrintMethod = "print"#Name;
453 let ParserMatchClass = MatchClass;
456 class NamedOperandU8<string Name, AsmOperandClass MatchClass> : Operand<i8> {
457 let PrintMethod = "print"#Name;
458 let ParserMatchClass = MatchClass;
461 class NamedOperandU16<string Name, AsmOperandClass MatchClass> : Operand<i16> {
462 let PrintMethod = "print"#Name;
463 let ParserMatchClass = MatchClass;
466 class NamedOperandU32<string Name, AsmOperandClass MatchClass> : Operand<i32> {
467 let PrintMethod = "print"#Name;
468 let ParserMatchClass = MatchClass;
471 class NamedOperandU32Default0<string Name, AsmOperandClass MatchClass> :
472 OperandWithDefaultOps<i32, (ops (i32 0))> {
473 let PrintMethod = "print"#Name;
474 let ParserMatchClass = MatchClass;
477 let OperandType = "OPERAND_IMMEDIATE" in {
479 def offen : NamedOperandBit<"Offen", NamedMatchClass<"Offen">>;
480 def idxen : NamedOperandBit<"Idxen", NamedMatchClass<"Idxen">>;
481 def addr64 : NamedOperandBit<"Addr64", NamedMatchClass<"Addr64">>;
483 def offset : NamedOperandU16<"Offset", NamedMatchClass<"Offset">>;
484 def offset0 : NamedOperandU8<"Offset0", NamedMatchClass<"Offset0">>;
485 def offset1 : NamedOperandU8<"Offset1", NamedMatchClass<"Offset1">>;
487 def gds : NamedOperandBit<"GDS", NamedMatchClass<"GDS">>;
489 def omod : NamedOperandU32<"OModSI", NamedMatchClass<"OModSI">>;
490 def clampmod : NamedOperandBit<"ClampSI", NamedMatchClass<"ClampSI">>;
492 def GLC : NamedOperandBit<"GLC", NamedMatchClass<"GLC">>;
493 def slc : NamedOperandBit<"SLC", NamedMatchClass<"SLC">>;
494 def tfe : NamedOperandBit<"TFE", NamedMatchClass<"TFE">>;
495 def unorm : NamedOperandBit<"UNorm", NamedMatchClass<"UNorm">>;
496 def da : NamedOperandBit<"DA", NamedMatchClass<"DA">>;
497 def r128 : NamedOperandBit<"R128", NamedMatchClass<"R128">>;
498 def lwe : NamedOperandBit<"LWE", NamedMatchClass<"LWE">>;
499 def exp_compr : NamedOperandBit<"ExpCompr", NamedMatchClass<"ExpCompr">>;
500 def exp_vm : NamedOperandBit<"ExpVM", NamedMatchClass<"ExpVM">>;
502 def dmask : NamedOperandU16<"DMask", NamedMatchClass<"DMask">>;
504 def dpp_ctrl : NamedOperandU32<"DPPCtrl", NamedMatchClass<"DPPCtrl", 0>>;
505 def row_mask : NamedOperandU32<"RowMask", NamedMatchClass<"RowMask">>;
506 def bank_mask : NamedOperandU32<"BankMask", NamedMatchClass<"BankMask">>;
507 def bound_ctrl : NamedOperandBit<"BoundCtrl", NamedMatchClass<"BoundCtrl">>;
509 def dst_sel : NamedOperandU32<"SDWADstSel", NamedMatchClass<"SDWADstSel">>;
510 def src0_sel : NamedOperandU32<"SDWASrc0Sel", NamedMatchClass<"SDWASrc0Sel">>;
511 def src1_sel : NamedOperandU32<"SDWASrc1Sel", NamedMatchClass<"SDWASrc1Sel">>;
512 def dst_unused : NamedOperandU32<"SDWADstUnused", NamedMatchClass<"SDWADstUnused">>;
514 def op_sel : NamedOperandU32Default0<"OpSel", NamedMatchClass<"OpSel">>;
515 def op_sel_hi : NamedOperandU32Default0<"OpSelHi", NamedMatchClass<"OpSelHi">>;
516 def neg_lo : NamedOperandU32Default0<"NegLo", NamedMatchClass<"NegLo">>;
517 def neg_hi : NamedOperandU32Default0<"NegHi", NamedMatchClass<"NegHi">>;
519 def hwreg : NamedOperandU16<"Hwreg", NamedMatchClass<"Hwreg", 0>>;
521 def exp_tgt : NamedOperandU8<"ExpTgt", NamedMatchClass<"ExpTgt", 0>> {
525 } // End OperandType = "OPERAND_IMMEDIATE"
527 class KImmMatchClass<int size> : AsmOperandClass {
528 let Name = "KImmFP"#size;
529 let PredicateMethod = "isKImmFP"#size;
530 let ParserMethod = "parseImm";
531 let RenderMethod = "addKImmFP"#size#"Operands";
534 class kimmOperand<ValueType vt> : Operand<vt> {
535 let OperandNamespace = "AMDGPU";
536 let OperandType = "OPERAND_KIMM"#vt.Size;
537 let PrintMethod = "printU"#vt.Size#"ImmOperand";
538 let ParserMatchClass = !cast<AsmOperandClass>("KImmFP"#vt.Size#"MatchClass");
541 // 32-bit VALU immediate operand that uses the constant bus.
542 def KImmFP32MatchClass : KImmMatchClass<32>;
543 def f32kimm : kimmOperand<i32>;
545 // 32-bit VALU immediate operand with a 16-bit value that uses the
547 def KImmFP16MatchClass : KImmMatchClass<16>;
548 def f16kimm : kimmOperand<i16>;
551 def VOPDstS64 : VOPDstOperand <SReg_64>;
553 class FPInputModsMatchClass <int opSize> : AsmOperandClass {
554 let Name = "RegOrImmWithFP"#opSize#"InputMods";
555 let ParserMethod = "parseRegOrImmWithFPInputMods";
556 let PredicateMethod = "isRegOrImmWithFP"#opSize#"InputMods";
559 def FP16InputModsMatchClass : FPInputModsMatchClass<16>;
560 def FP32InputModsMatchClass : FPInputModsMatchClass<32>;
561 def FP64InputModsMatchClass : FPInputModsMatchClass<64>;
563 class InputMods <AsmOperandClass matchClass> : Operand <i32> {
564 let OperandNamespace = "AMDGPU";
565 let OperandType = "OPERAND_INPUT_MODS";
566 let ParserMatchClass = matchClass;
569 class FPInputMods <FPInputModsMatchClass matchClass> : InputMods <matchClass> {
570 let PrintMethod = "printOperandAndFPInputMods";
573 def FP16InputMods : FPInputMods<FP16InputModsMatchClass>;
574 def FP32InputMods : FPInputMods<FP32InputModsMatchClass>;
575 def FP64InputMods : FPInputMods<FP64InputModsMatchClass>;
577 class IntInputModsMatchClass <int opSize> : AsmOperandClass {
578 let Name = "RegOrImmWithInt"#opSize#"InputMods";
579 let ParserMethod = "parseRegOrImmWithIntInputMods";
580 let PredicateMethod = "isRegOrImmWithInt"#opSize#"InputMods";
582 def Int32InputModsMatchClass : IntInputModsMatchClass<32>;
583 def Int64InputModsMatchClass : IntInputModsMatchClass<64>;
585 class IntInputMods <IntInputModsMatchClass matchClass> : InputMods <matchClass> {
586 let PrintMethod = "printOperandAndIntInputMods";
588 def Int32InputMods : IntInputMods<Int32InputModsMatchClass>;
589 def Int64InputMods : IntInputMods<Int64InputModsMatchClass>;
591 def FPVRegInputModsMatchClass : AsmOperandClass {
592 let Name = "VRegWithFPInputMods";
593 let ParserMethod = "parseRegWithFPInputMods";
594 let PredicateMethod = "isVReg";
597 def FPVRegInputMods : InputMods <FPVRegInputModsMatchClass> {
598 let PrintMethod = "printOperandAndFPInputMods";
601 def IntVRegInputModsMatchClass : AsmOperandClass {
602 let Name = "VRegWithIntInputMods";
603 let ParserMethod = "parseRegWithIntInputMods";
604 let PredicateMethod = "isVReg";
607 def IntVRegInputMods : InputMods <IntVRegInputModsMatchClass> {
608 let PrintMethod = "printOperandAndIntInputMods";
611 class PackedFPInputModsMatchClass <int opSize> : AsmOperandClass {
612 let Name = "PackedFP"#opSize#"InputMods";
613 let ParserMethod = "parseRegOrImm";
614 let PredicateMethod = "isRegOrImm";
615 // let PredicateMethod = "isPackedFP"#opSize#"InputMods";
618 class PackedIntInputModsMatchClass <int opSize> : AsmOperandClass {
619 let Name = "PackedInt"#opSize#"InputMods";
620 let ParserMethod = "parseRegOrImm";
621 let PredicateMethod = "isRegOrImm";
622 // let PredicateMethod = "isPackedInt"#opSize#"InputMods";
625 def PackedF16InputModsMatchClass : PackedFPInputModsMatchClass<16>;
626 def PackedI16InputModsMatchClass : PackedIntInputModsMatchClass<16>;
628 class PackedFPInputMods <PackedFPInputModsMatchClass matchClass> : InputMods <matchClass> {
629 // let PrintMethod = "printPackedFPInputMods";
632 class PackedIntInputMods <PackedIntInputModsMatchClass matchClass> : InputMods <matchClass> {
633 //let PrintMethod = "printPackedIntInputMods";
636 def PackedF16InputMods : PackedFPInputMods<PackedF16InputModsMatchClass>;
637 def PackedI16InputMods : PackedIntInputMods<PackedI16InputModsMatchClass>;
639 //===----------------------------------------------------------------------===//
641 //===----------------------------------------------------------------------===//
643 def DS1Addr1Offset : ComplexPattern<i32, 2, "SelectDS1Addr1Offset">;
644 def DS64Bit4ByteAligned : ComplexPattern<i32, 3, "SelectDS64Bit4ByteAligned">;
646 def MOVRELOffset : ComplexPattern<i32, 2, "SelectMOVRELOffset">;
648 def VOP3Mods0 : ComplexPattern<untyped, 4, "SelectVOP3Mods0">;
649 def VOP3Mods0Clamp : ComplexPattern<untyped, 3, "SelectVOP3Mods0Clamp">;
650 def VOP3Mods0Clamp0OMod : ComplexPattern<untyped, 4, "SelectVOP3Mods0Clamp0OMod">;
651 def VOP3Mods : ComplexPattern<untyped, 2, "SelectVOP3Mods">;
652 def VOP3NoMods : ComplexPattern<untyped, 1, "SelectVOP3NoMods">;
653 // VOP3Mods, but the input source is known to never be NaN.
654 def VOP3Mods_nnan : ComplexPattern<fAny, 2, "SelectVOP3Mods_NNaN">;
656 def VOP3OMods : ComplexPattern<untyped, 3, "SelectVOP3OMods">;
658 def VOP3PMods : ComplexPattern<untyped, 2, "SelectVOP3PMods">;
659 def VOP3PMods0 : ComplexPattern<untyped, 3, "SelectVOP3PMods0">;
662 //===----------------------------------------------------------------------===//
663 // SI assembler operands
664 //===----------------------------------------------------------------------===//
672 // This should be kept in sync with SISrcMods enum
695 int LLVM_DEBUG_TRAP = 3;
698 //===----------------------------------------------------------------------===//
700 // SI Instruction multiclass helpers.
702 // Instructions with _32 take 32-bit operands.
703 // Instructions with _64 take 64-bit operands.
705 // VOP_* instructions can use either a 32-bit or 64-bit encoding. The 32-bit
706 // encoding is the standard encoding, but instruction that make use of
707 // any of the instruction modifiers must use the 64-bit encoding.
709 // Instructions with _e32 use the 32-bit encoding.
710 // Instructions with _e64 use the 64-bit encoding.
712 //===----------------------------------------------------------------------===//
714 class SIMCInstr <string pseudo, int subtarget> {
715 string PseudoInstr = pseudo;
716 int Subtarget = subtarget;
719 //===----------------------------------------------------------------------===//
721 //===----------------------------------------------------------------------===//
723 class EXP_Helper<bit done, SDPatternOperator node = null_frag> : EXPCommon<
726 ExpSrc0:$src0, ExpSrc1:$src1, ExpSrc2:$src2, ExpSrc3:$src3,
727 exp_vm:$vm, exp_compr:$compr, i8imm:$en),
728 "exp$tgt $src0, $src1, $src2, $src3"#!if(done, " done", "")#"$compr$vm",
729 [(node (i8 timm:$tgt), (i8 timm:$en),
730 f32:$src0, f32:$src1, f32:$src2, f32:$src3,
731 (i1 timm:$compr), (i1 timm:$vm))]> {
732 let AsmMatchConverter = "cvtExp";
735 // Split EXP instruction into EXP and EXP_DONE so we can set
736 // mayLoad for done=1.
737 multiclass EXP_m<bit done, SDPatternOperator node> {
738 let mayLoad = done in {
739 let isPseudo = 1, isCodeGenOnly = 1 in {
740 def "" : EXP_Helper<done, node>,
741 SIMCInstr <"exp"#!if(done, "_done", ""), SIEncodingFamily.NONE>;
745 def _si : EXP_Helper<done>,
746 SIMCInstr <"exp"#!if(done, "_done", ""), SIEncodingFamily.SI>,
748 let AssemblerPredicates = [isSICI];
749 let DecoderNamespace = "SICI";
750 let DisableDecoder = DisableSIDecoder;
753 def _vi : EXP_Helper<done>,
754 SIMCInstr <"exp"#!if(done, "_done", ""), SIEncodingFamily.VI>,
756 let AssemblerPredicates = [isVI];
757 let DecoderNamespace = "VI";
758 let DisableDecoder = DisableVIDecoder;
764 //===----------------------------------------------------------------------===//
765 // Vector ALU classes
766 //===----------------------------------------------------------------------===//
768 class getNumSrcArgs<ValueType Src0, ValueType Src1, ValueType Src2> {
770 !if (!eq(Src0.Value, untyped.Value), 0,
771 !if (!eq(Src1.Value, untyped.Value), 1, // VOP1
772 !if (!eq(Src2.Value, untyped.Value), 2, // VOP2
776 // Returns the register class to use for the destination of VOP[123C]
777 // instructions for the given VT.
778 class getVALUDstForVT<ValueType VT> {
779 RegisterOperand ret = !if(!eq(VT.Size, 32), VOPDstOperand<VGPR_32>,
780 !if(!eq(VT.Size, 128), VOPDstOperand<VReg_128>,
781 !if(!eq(VT.Size, 64), VOPDstOperand<VReg_64>,
782 !if(!eq(VT.Size, 16), VOPDstOperand<VGPR_32>,
783 VOPDstOperand<SReg_64>)))); // else VT == i1
786 // Returns the register class to use for source 0 of VOP[12C]
787 // instructions for the given VT.
788 class getVOPSrc0ForVT<ValueType VT> {
789 bit isFP = !if(!eq(VT.Value, f16.Value), 1,
790 !if(!eq(VT.Value, v2f16.Value), 1,
791 !if(!eq(VT.Value, f32.Value), 1,
792 !if(!eq(VT.Value, f64.Value), 1,
795 RegisterOperand ret =
797 !if(!eq(VT.Size, 64),
799 !if(!eq(VT.Value, f16.Value),
801 !if(!eq(VT.Value, v2f16.Value),
807 !if(!eq(VT.Size, 64),
809 !if(!eq(VT.Value, i16.Value),
811 !if(!eq(VT.Value, v2i16.Value),
820 // Returns the vreg register class to use for source operand given VT
821 class getVregSrcForVT<ValueType VT> {
822 RegisterClass ret = !if(!eq(VT.Size, 128), VReg_128,
823 !if(!eq(VT.Size, 64), VReg_64, VGPR_32));
827 // Returns the register class to use for sources of VOP3 instructions for the
829 class getVOP3SrcForVT<ValueType VT> {
830 bit isFP = !if(!eq(VT.Value, f16.Value), 1,
831 !if(!eq(VT.Value, v2f16.Value), 1,
832 !if(!eq(VT.Value, f32.Value), 1,
833 !if(!eq(VT.Value, f64.Value), 1,
835 RegisterOperand ret =
836 !if(!eq(VT.Size, 128),
838 !if(!eq(VT.Size, 64),
842 !if(!eq(VT.Value, i1.Value),
845 !if(!eq(VT.Value, f16.Value),
847 !if(!eq(VT.Value, v2f16.Value),
852 !if(!eq(VT.Value, i16.Value),
854 !if(!eq(VT.Value, v2i16.Value),
865 // Returns 1 if the source arguments have modifiers, 0 if they do not.
866 // XXX - do f16 instructions?
867 class isFloatType<ValueType SrcVT> {
869 !if(!eq(SrcVT.Value, f16.Value), 1,
870 !if(!eq(SrcVT.Value, f32.Value), 1,
871 !if(!eq(SrcVT.Value, f64.Value), 1,
872 !if(!eq(SrcVT.Value, v2f16.Value), 1,
876 class isIntType<ValueType SrcVT> {
878 !if(!eq(SrcVT.Value, i16.Value), 1,
879 !if(!eq(SrcVT.Value, i32.Value), 1,
880 !if(!eq(SrcVT.Value, i64.Value), 1,
884 class isPackedType<ValueType SrcVT> {
886 !if(!eq(SrcVT.Value, v2i16.Value), 1,
887 !if(!eq(SrcVT.Value, v2f16.Value), 1, 0)
891 // Float or packed int
892 class isModifierType<ValueType SrcVT> {
894 !if(!eq(SrcVT.Value, f16.Value), 1,
895 !if(!eq(SrcVT.Value, f32.Value), 1,
896 !if(!eq(SrcVT.Value, f64.Value), 1,
897 !if(!eq(SrcVT.Value, v2f16.Value), 1,
898 !if(!eq(SrcVT.Value, v2i16.Value), 1,
902 // Return type of input modifiers operand for specified input operand
903 class getSrcMod <ValueType VT> {
904 bit isFP = !if(!eq(VT.Value, f16.Value), 1,
905 !if(!eq(VT.Value, f32.Value), 1,
906 !if(!eq(VT.Value, f64.Value), 1,
908 bit isPacked = isPackedType<VT>.ret;
909 Operand ret = !if(!eq(VT.Size, 64),
910 !if(isFP, FP64InputMods, Int64InputMods),
912 !if(!eq(VT.Value, f16.Value),
920 // Return type of input modifiers operand specified input operand for SDWA/DPP
921 class getSrcModExt <ValueType VT> {
922 bit isFP = !if(!eq(VT.Value, f16.Value), 1,
923 !if(!eq(VT.Value, f32.Value), 1,
924 !if(!eq(VT.Value, f64.Value), 1,
926 Operand ret = !if(isFP, FPVRegInputMods, IntVRegInputMods);
929 // Returns the input arguments for VOP[12C] instructions for the given SrcVT.
930 class getIns32 <RegisterOperand Src0RC, RegisterClass Src1RC, int NumSrcArgs> {
931 dag ret = !if(!eq(NumSrcArgs, 1), (ins Src0RC:$src0), // VOP1
932 !if(!eq(NumSrcArgs, 2), (ins Src0RC:$src0, Src1RC:$src1), // VOP2
936 // Returns the input arguments for VOP3 instructions for the given SrcVT.
937 class getIns64 <RegisterOperand Src0RC, RegisterOperand Src1RC,
938 RegisterOperand Src2RC, int NumSrcArgs,
939 bit HasModifiers, bit HasOMod,
940 Operand Src0Mod, Operand Src1Mod, Operand Src2Mod> {
943 !if (!eq(NumSrcArgs, 0),
944 // VOP1 without input operands (V_NOP, V_CLREXCP)
947 !if (!eq(NumSrcArgs, 1),
948 !if (!eq(HasModifiers, 1),
949 // VOP1 with modifiers
950 (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
951 clampmod:$clamp, omod:$omod)
953 // VOP1 without modifiers
956 !if (!eq(NumSrcArgs, 2),
957 !if (!eq(HasModifiers, 1),
958 // VOP 2 with modifiers
959 !if( !eq(HasOMod, 1),
960 (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
961 Src1Mod:$src1_modifiers, Src1RC:$src1,
962 clampmod:$clamp, omod:$omod),
963 (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
964 Src1Mod:$src1_modifiers, Src1RC:$src1,
967 // VOP2 without modifiers
968 (ins Src0RC:$src0, Src1RC:$src1)
970 /* NumSrcArgs == 3 */,
971 !if (!eq(HasModifiers, 1),
972 // VOP3 with modifiers
973 !if (!eq(HasOMod, 1),
974 (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
975 Src1Mod:$src1_modifiers, Src1RC:$src1,
976 Src2Mod:$src2_modifiers, Src2RC:$src2,
977 clampmod:$clamp, omod:$omod),
978 (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
979 Src1Mod:$src1_modifiers, Src1RC:$src1,
980 Src2Mod:$src2_modifiers, Src2RC:$src2,
983 // VOP3 without modifiers
984 (ins Src0RC:$src0, Src1RC:$src1, Src2RC:$src2)
988 /// XXX - src1 may only allow VGPRs?
990 // The modifiers (except clamp) are dummy operands for the benefit of
991 // printing and parsing. They defer their values to looking at the
992 // srcN_modifiers for what to print.
993 class getInsVOP3P <RegisterOperand Src0RC, RegisterOperand Src1RC,
994 RegisterOperand Src2RC, int NumSrcArgs,
996 Operand Src0Mod, Operand Src1Mod, Operand Src2Mod> {
997 dag ret = !if (!eq(NumSrcArgs, 2),
999 (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1000 Src1Mod:$src1_modifiers, Src1RC:$src1,
1002 op_sel:$op_sel, op_sel_hi:$op_sel_hi,
1003 neg_lo:$neg_lo, neg_hi:$neg_hi),
1004 (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1005 Src1Mod:$src1_modifiers, Src1RC:$src1,
1006 op_sel:$op_sel, op_sel_hi:$op_sel_hi,
1007 neg_lo:$neg_lo, neg_hi:$neg_hi)),
1008 // else NumSrcArgs == 3
1010 (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1011 Src1Mod:$src1_modifiers, Src1RC:$src1,
1012 Src2Mod:$src2_modifiers, Src2RC:$src2,
1014 op_sel:$op_sel, op_sel_hi:$op_sel_hi,
1015 neg_lo:$neg_lo, neg_hi:$neg_hi),
1016 (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1017 Src1Mod:$src1_modifiers, Src1RC:$src1,
1018 Src2Mod:$src2_modifiers, Src2RC:$src2,
1019 op_sel:$op_sel, op_sel_hi:$op_sel_hi,
1020 neg_lo:$neg_lo, neg_hi:$neg_hi))
1024 class getInsDPP <RegisterClass Src0RC, RegisterClass Src1RC, int NumSrcArgs,
1025 bit HasModifiers, Operand Src0Mod, Operand Src1Mod> {
1027 dag ret = !if (!eq(NumSrcArgs, 0),
1028 // VOP1 without input operands (V_NOP)
1029 (ins dpp_ctrl:$dpp_ctrl, row_mask:$row_mask,
1030 bank_mask:$bank_mask, bound_ctrl:$bound_ctrl),
1031 !if (!eq(NumSrcArgs, 1),
1032 !if (!eq(HasModifiers, 1),
1033 // VOP1_DPP with modifiers
1034 (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1035 dpp_ctrl:$dpp_ctrl, row_mask:$row_mask,
1036 bank_mask:$bank_mask, bound_ctrl:$bound_ctrl)
1038 // VOP1_DPP without modifiers
1039 (ins Src0RC:$src0, dpp_ctrl:$dpp_ctrl, row_mask:$row_mask,
1040 bank_mask:$bank_mask, bound_ctrl:$bound_ctrl)
1042 /* NumSrcArgs == 2 */,
1043 !if (!eq(HasModifiers, 1),
1044 // VOP2_DPP with modifiers
1045 (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1046 Src1Mod:$src1_modifiers, Src1RC:$src1,
1047 dpp_ctrl:$dpp_ctrl, row_mask:$row_mask,
1048 bank_mask:$bank_mask, bound_ctrl:$bound_ctrl)
1050 // VOP2_DPP without modifiers
1051 (ins Src0RC:$src0, Src1RC:$src1, dpp_ctrl:$dpp_ctrl,
1052 row_mask:$row_mask, bank_mask:$bank_mask,
1053 bound_ctrl:$bound_ctrl)
1057 class getInsSDWA <RegisterClass Src0RC, RegisterClass Src1RC, int NumSrcArgs,
1058 bit HasFloatModifiers, Operand Src0Mod, Operand Src1Mod,
1061 dag ret = !if(!eq(NumSrcArgs, 0),
1062 // VOP1 without input operands (V_NOP)
1064 !if(!eq(NumSrcArgs, 1),
1065 (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1066 clampmod:$clamp, dst_sel:$dst_sel, dst_unused:$dst_unused,
1067 src0_sel:$src0_sel),
1068 !if(!eq(NumSrcArgs, 2),
1069 !if(!eq(DstVT.Size, 1),
1070 // VOPC_SDWA with modifiers
1071 (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1072 Src1Mod:$src1_modifiers, Src1RC:$src1,
1073 clampmod:$clamp, src0_sel:$src0_sel, src1_sel:$src1_sel),
1074 // VOP2_SDWA or VOPC_SDWA with modifiers
1075 (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1076 Src1Mod:$src1_modifiers, Src1RC:$src1,
1077 clampmod:$clamp, dst_sel:$dst_sel, dst_unused:$dst_unused,
1078 src0_sel:$src0_sel, src1_sel:$src1_sel)),
1079 (ins)/* endif */)));
1082 // Outs for DPP and SDWA
1083 class getOutsExt <bit HasDst, ValueType DstVT, RegisterOperand DstRCDPP> {
1084 dag ret = !if(HasDst,
1085 !if(!eq(DstVT.Size, 1),
1086 (outs), // no dst for VOPC, we use "vcc"-token as dst in SDWA VOPC instructions
1087 (outs DstRCDPP:$vdst)),
1091 // Returns the assembly string for the inputs and outputs of a VOP[12C]
1092 // instruction. This does not add the _e32 suffix, so it can be reused
1094 class getAsm32 <bit HasDst, int NumSrcArgs, ValueType DstVT = i32> {
1095 string dst = !if(!eq(DstVT.Size, 1), "$sdst", "$vdst"); // use $sdst for VOPC
1096 string src0 = ", $src0";
1097 string src1 = ", $src1";
1098 string src2 = ", $src2";
1099 string ret = !if(HasDst, dst, "") #
1100 !if(!eq(NumSrcArgs, 1), src0, "") #
1101 !if(!eq(NumSrcArgs, 2), src0#src1, "") #
1102 !if(!eq(NumSrcArgs, 3), src0#src1#src2, "");
1105 // Returns the assembly string for the inputs and outputs of a VOP3
1107 class getAsm64 <bit HasDst, int NumSrcArgs, bit HasModifiers,
1108 bit HasOMod, ValueType DstVT = i32> {
1109 string dst = !if(!eq(DstVT.Size, 1), "$sdst", "$vdst"); // use $sdst for VOPC
1110 string src0 = !if(!eq(NumSrcArgs, 1), "$src0_modifiers", "$src0_modifiers,");
1111 string src1 = !if(!eq(NumSrcArgs, 1), "",
1112 !if(!eq(NumSrcArgs, 2), " $src1_modifiers",
1113 " $src1_modifiers,"));
1114 string src2 = !if(!eq(NumSrcArgs, 3), " $src2_modifiers", "");
1116 !if(!eq(HasModifiers, 0),
1117 getAsm32<HasDst, NumSrcArgs, DstVT>.ret,
1118 dst#", "#src0#src1#src2#"$clamp"#!if(HasOMod, "$omod", ""));
1121 // Returns the assembly string for the inputs and outputs of a VOP3P
1123 class getAsmVOP3P <bit HasDst, int NumSrcArgs, bit HasModifiers,
1124 bit HasClamp, ValueType DstVT = i32> {
1125 string dst = " $vdst";
1126 string src0 = !if(!eq(NumSrcArgs, 1), "$src0", "$src0,");
1127 string src1 = !if(!eq(NumSrcArgs, 1), "",
1128 !if(!eq(NumSrcArgs, 2), " $src1",
1130 string src2 = !if(!eq(NumSrcArgs, 3), " $src2", "");
1132 string mods = !if(HasModifiers, "$neg_lo$neg_hi", "");
1133 string clamp = !if(HasClamp, "$clamp", "");
1135 // Each modifier is printed as an array of bits for each operand, so
1136 // all operands are printed as part of src0_modifiers.
1137 string ret = dst#", "#src0#src1#src2#"$op_sel$op_sel_hi"#mods#clamp;
1140 class getAsmDPP <bit HasDst, int NumSrcArgs, bit HasModifiers, ValueType DstVT = i32> {
1141 string dst = !if(HasDst,
1142 !if(!eq(DstVT.Size, 1),
1145 ""); // use $sdst for VOPC
1146 string src0 = !if(!eq(NumSrcArgs, 1), "$src0_modifiers", "$src0_modifiers,");
1147 string src1 = !if(!eq(NumSrcArgs, 1), "",
1148 !if(!eq(NumSrcArgs, 2), " $src1_modifiers",
1149 " $src1_modifiers,"));
1150 string args = !if(!eq(HasModifiers, 0),
1151 getAsm32<0, NumSrcArgs, DstVT>.ret,
1153 string ret = dst#args#" $dpp_ctrl$row_mask$bank_mask$bound_ctrl";
1156 class getAsmSDWA <bit HasDst, int NumSrcArgs, bit HasFloatModifiers,
1157 ValueType DstVT = i32> {
1158 string dst = !if(HasDst,
1159 !if(!eq(DstVT.Size, 1),
1160 " vcc", // use vcc token as dst for VOPC instructioins
1163 string src0 = "$src0_modifiers";
1164 string src1 = "$src1_modifiers";
1165 string args = !if(!eq(NumSrcArgs, 0),
1167 !if(!eq(NumSrcArgs, 1),
1169 ", "#src0#", "#src1#"$clamp"
1172 string sdwa = !if(!eq(NumSrcArgs, 0),
1174 !if(!eq(NumSrcArgs, 1),
1175 " $dst_sel $dst_unused $src0_sel",
1176 !if(!eq(DstVT.Size, 1),
1177 " $src0_sel $src1_sel", // No dst_sel and dst_unused for VOPC
1178 " $dst_sel $dst_unused $src0_sel $src1_sel"
1182 string ret = dst#args#sdwa;
1185 // Function that checks if instruction supports DPP and SDWA
1186 class getHasExt <int NumSrcArgs, ValueType DstVT = i32, ValueType Src0VT = i32,
1187 ValueType Src1VT = i32> {
1188 bit ret = !if(!eq(NumSrcArgs, 3),
1189 0, // NumSrcArgs == 3 - No DPP or SDWA for VOP3
1190 !if(!eq(DstVT.Size, 64),
1191 0, // 64-bit dst - No DPP or SDWA for 64-bit operands
1192 !if(!eq(Src0VT.Size, 64),
1194 !if(!eq(Src0VT.Size, 64),
1203 class BitOr<bit a, bit b> {
1204 bit ret = !if(a, 1, !if(b, 1, 0));
1207 class BitAnd<bit a, bit b> {
1208 bit ret = !if(a, !if(b, 1, 0), 0);
1211 class VOPProfile <list<ValueType> _ArgVT> {
1213 field list<ValueType> ArgVT = _ArgVT;
1215 field ValueType DstVT = ArgVT[0];
1216 field ValueType Src0VT = ArgVT[1];
1217 field ValueType Src1VT = ArgVT[2];
1218 field ValueType Src2VT = ArgVT[3];
1219 field RegisterOperand DstRC = getVALUDstForVT<DstVT>.ret;
1220 field RegisterOperand DstRCDPP = getVALUDstForVT<DstVT>.ret;
1221 field RegisterOperand DstRCSDWA = getVALUDstForVT<DstVT>.ret;
1222 field RegisterOperand Src0RC32 = getVOPSrc0ForVT<Src0VT>.ret;
1223 field RegisterClass Src1RC32 = getVregSrcForVT<Src1VT>.ret;
1224 field RegisterOperand Src0RC64 = getVOP3SrcForVT<Src0VT>.ret;
1225 field RegisterOperand Src1RC64 = getVOP3SrcForVT<Src1VT>.ret;
1226 field RegisterOperand Src2RC64 = getVOP3SrcForVT<Src2VT>.ret;
1227 field RegisterClass Src0DPP = getVregSrcForVT<Src0VT>.ret;
1228 field RegisterClass Src1DPP = getVregSrcForVT<Src1VT>.ret;
1229 field RegisterClass Src0SDWA = getVregSrcForVT<Src0VT>.ret;
1230 field RegisterClass Src1SDWA = getVregSrcForVT<Src1VT>.ret;
1231 field Operand Src0Mod = getSrcMod<Src0VT>.ret;
1232 field Operand Src1Mod = getSrcMod<Src1VT>.ret;
1233 field Operand Src2Mod = getSrcMod<Src2VT>.ret;
1234 field Operand Src0ModDPP = getSrcModExt<Src0VT>.ret;
1235 field Operand Src1ModDPP = getSrcModExt<Src1VT>.ret;
1236 field Operand Src0ModSDWA = getSrcModExt<Src0VT>.ret;
1237 field Operand Src1ModSDWA = getSrcModExt<Src1VT>.ret;
1240 field bit HasDst = !if(!eq(DstVT.Value, untyped.Value), 0, 1);
1241 field bit HasDst32 = HasDst;
1242 field bit EmitDst = HasDst; // force dst encoding, see v_movreld_b32 special case
1243 field int NumSrcArgs = getNumSrcArgs<Src0VT, Src1VT, Src2VT>.ret;
1244 field bit HasSrc0 = !if(!eq(Src0VT.Value, untyped.Value), 0, 1);
1245 field bit HasSrc1 = !if(!eq(Src1VT.Value, untyped.Value), 0, 1);
1246 field bit HasSrc2 = !if(!eq(Src2VT.Value, untyped.Value), 0, 1);
1248 // TODO: Modifiers logic is somewhat adhoc here, to be refined later
1249 field bit HasModifiers = isModifierType<Src0VT>.ret;
1251 field bit HasSrc0FloatMods = isFloatType<Src0VT>.ret;
1252 field bit HasSrc1FloatMods = isFloatType<Src1VT>.ret;
1253 field bit HasSrc2FloatMods = isFloatType<Src2VT>.ret;
1255 field bit HasSrc0IntMods = isIntType<Src0VT>.ret;
1256 field bit HasSrc1IntMods = isIntType<Src1VT>.ret;
1257 field bit HasSrc2IntMods = isIntType<Src2VT>.ret;
1259 field bit HasSrc0Mods = HasModifiers;
1260 field bit HasSrc1Mods = !if(HasModifiers, BitOr<HasSrc1FloatMods, HasSrc1IntMods>.ret, 0);
1261 field bit HasSrc2Mods = !if(HasModifiers, BitOr<HasSrc2FloatMods, HasSrc2IntMods>.ret, 0);
1263 field bit HasClamp = HasModifiers;
1264 field bit HasSDWAClamp = HasSrc0;
1265 field bit HasFPClamp = BitAnd<isFloatType<DstVT>.ret, HasClamp>.ret;
1267 field bit IsPacked = isPackedType<Src0VT>.ret;
1268 field bit HasOpSel = IsPacked;
1269 field bit HasOMod = !if(HasOpSel, 0, HasModifiers);
1271 field bit HasExt = getHasExt<NumSrcArgs, DstVT, Src0VT, Src1VT>.ret;
1273 field Operand Src0PackedMod = !if(HasSrc0FloatMods, PackedF16InputMods, PackedI16InputMods);
1274 field Operand Src1PackedMod = !if(HasSrc1FloatMods, PackedF16InputMods, PackedI16InputMods);
1275 field Operand Src2PackedMod = !if(HasSrc2FloatMods, PackedF16InputMods, PackedI16InputMods);
1277 field dag Outs = !if(HasDst,(outs DstRC:$vdst),(outs));
1279 // VOP3b instructions are a special case with a second explicit
1280 // output. This is manually overridden for them.
1281 field dag Outs32 = Outs;
1282 field dag Outs64 = Outs;
1283 field dag OutsDPP = getOutsExt<HasDst, DstVT, DstRCDPP>.ret;
1284 field dag OutsSDWA = getOutsExt<HasDst, DstVT, DstRCSDWA>.ret;
1286 field dag Ins32 = getIns32<Src0RC32, Src1RC32, NumSrcArgs>.ret;
1287 field dag Ins64 = getIns64<Src0RC64, Src1RC64, Src2RC64, NumSrcArgs,
1288 HasModifiers, HasOMod, Src0Mod, Src1Mod,
1290 field dag InsVOP3P = getInsVOP3P<Src0RC64, Src1RC64, Src2RC64,
1291 NumSrcArgs, HasClamp,
1292 Src0PackedMod, Src1PackedMod, Src2PackedMod>.ret;
1294 field dag InsDPP = getInsDPP<Src0DPP, Src1DPP, NumSrcArgs,
1295 HasModifiers, Src0ModDPP, Src1ModDPP>.ret;
1296 field dag InsSDWA = getInsSDWA<Src0SDWA, Src1SDWA, NumSrcArgs,
1297 HasModifiers, Src0ModSDWA, Src1ModSDWA,
1300 field string Asm32 = getAsm32<HasDst, NumSrcArgs, DstVT>.ret;
1301 field string Asm64 = getAsm64<HasDst, NumSrcArgs, HasModifiers, HasOMod, DstVT>.ret;
1302 field string AsmVOP3P = getAsmVOP3P<HasDst, NumSrcArgs, HasModifiers, HasClamp, DstVT>.ret;
1303 field string AsmDPP = getAsmDPP<HasDst, NumSrcArgs, HasModifiers, DstVT>.ret;
1304 field string AsmSDWA = getAsmSDWA<HasDst, NumSrcArgs, HasModifiers, DstVT>.ret;
1307 class VOP_NO_EXT <VOPProfile p> : VOPProfile <p.ArgVT> {
1311 def VOP_F16_F16 : VOPProfile <[f16, f16, untyped, untyped]>;
1312 def VOP_F16_I16 : VOPProfile <[f16, i16, untyped, untyped]>;
1313 def VOP_I16_F16 : VOPProfile <[i16, f16, untyped, untyped]>;
1315 def VOP_F16_F16_F16 : VOPProfile <[f16, f16, f16, untyped]>;
1316 def VOP_F16_F16_I16 : VOPProfile <[f16, f16, i16, untyped]>;
1317 def VOP_F16_F16_I32 : VOPProfile <[f16, f16, i32, untyped]>;
1318 def VOP_I16_I16_I16 : VOPProfile <[i16, i16, i16, untyped]>;
1320 def VOP_I16_I16_I16_I16 : VOPProfile <[i16, i16, i16, i16, untyped]>;
1321 def VOP_F16_F16_F16_F16 : VOPProfile <[f16, f16, f16, f16, untyped]>;
1323 def VOP_V2F16_V2F16_V2F16 : VOPProfile <[v2f16, v2f16, v2f16, untyped]>;
1324 def VOP_V2I16_V2I16_V2I16 : VOPProfile <[v2i16, v2i16, v2i16, untyped]>;
1325 def VOP_B32_F16_F16 : VOPProfile <[i32, f16, f16, untyped]>;
1327 def VOP_V2F16_V2F16_V2F16_V2F16 : VOPProfile <[v2f16, v2f16, v2f16, v2f16]>;
1328 def VOP_V2I16_V2I16_V2I16_V2I16 : VOPProfile <[v2i16, v2i16, v2i16, v2i16]>;
1330 def VOP_NONE : VOPProfile <[untyped, untyped, untyped, untyped]>;
1332 def VOP_F32_F32 : VOPProfile <[f32, f32, untyped, untyped]>;
1333 def VOP_F32_F64 : VOPProfile <[f32, f64, untyped, untyped]>;
1334 def VOP_F32_I32 : VOPProfile <[f32, i32, untyped, untyped]>;
1335 def VOP_F64_F32 : VOPProfile <[f64, f32, untyped, untyped]>;
1336 def VOP_F64_F64 : VOPProfile <[f64, f64, untyped, untyped]>;
1337 def VOP_F64_I32 : VOPProfile <[f64, i32, untyped, untyped]>;
1338 def VOP_I32_F32 : VOPProfile <[i32, f32, untyped, untyped]>;
1339 def VOP_I32_F64 : VOPProfile <[i32, f64, untyped, untyped]>;
1340 def VOP_I32_I32 : VOPProfile <[i32, i32, untyped, untyped]>;
1341 def VOP_F16_F32 : VOPProfile <[f16, f32, untyped, untyped]>;
1342 def VOP_F32_F16 : VOPProfile <[f32, f16, untyped, untyped]>;
1344 def VOP_F32_F32_F16 : VOPProfile <[f32, f32, f16, untyped]>;
1345 def VOP_F32_F32_F32 : VOPProfile <[f32, f32, f32, untyped]>;
1346 def VOP_F32_F32_I32 : VOPProfile <[f32, f32, i32, untyped]>;
1347 def VOP_F64_F64_F64 : VOPProfile <[f64, f64, f64, untyped]>;
1348 def VOP_F64_F64_I32 : VOPProfile <[f64, f64, i32, untyped]>;
1349 def VOP_I32_F32_F32 : VOPProfile <[i32, f32, f32, untyped]>;
1350 def VOP_I32_F32_I32 : VOPProfile <[i32, f32, i32, untyped]>;
1351 def VOP_I32_I32_I32 : VOPProfile <[i32, i32, i32, untyped]>;
1352 def VOP_V2F16_F32_F32 : VOPProfile <[v2f16, f32, f32, untyped]>;
1354 def VOP_I64_I64_I32 : VOPProfile <[i64, i64, i32, untyped]>;
1355 def VOP_I64_I32_I64 : VOPProfile <[i64, i32, i64, untyped]>;
1356 def VOP_I64_I64_I64 : VOPProfile <[i64, i64, i64, untyped]>;
1358 def VOP_F16_F32_F16_F32 : VOPProfile <[f16, f32, f16, f32]>;
1359 def VOP_F32_F32_F16_F16 : VOPProfile <[f32, f32, f16, f16]>;
1360 def VOP_F32_F32_F32_F32 : VOPProfile <[f32, f32, f32, f32]>;
1361 def VOP_F64_F64_F64_F64 : VOPProfile <[f64, f64, f64, f64]>;
1362 def VOP_I32_I32_I32_I32 : VOPProfile <[i32, i32, i32, i32]>;
1363 def VOP_I64_I32_I32_I64 : VOPProfile <[i64, i32, i32, i64]>;
1364 def VOP_I32_F32_I32_I32 : VOPProfile <[i32, f32, i32, i32]>;
1365 def VOP_I64_I64_I32_I64 : VOPProfile <[i64, i64, i32, i64]>;
1366 def VOP_V4I32_I64_I32_V4I32 : VOPProfile <[v4i32, i64, i32, v4i32]>;
1368 class Commutable_REV <string revOp, bit isOrig> {
1369 string RevOp = revOp;
1370 bit IsOrig = isOrig;
1373 class AtomicNoRet <string noRetOp, bit isRet> {
1374 string NoRetOp = noRetOp;
1378 //===----------------------------------------------------------------------===//
1379 // Interpolation opcodes
1380 //===----------------------------------------------------------------------===//
1382 class VINTRP_Pseudo <string opName, dag outs, dag ins, list<dag> pattern> :
1383 VINTRPCommon <outs, ins, "", pattern>,
1384 SIMCInstr<opName, SIEncodingFamily.NONE> {
1386 let isCodeGenOnly = 1;
1389 class VINTRP_Real_si <bits <2> op, string opName, dag outs, dag ins,
1391 VINTRPCommon <outs, ins, asm, []>,
1393 SIMCInstr<opName, SIEncodingFamily.SI> {
1394 let AssemblerPredicate = SIAssemblerPredicate;
1395 let DecoderNamespace = "SICI";
1396 let DisableDecoder = DisableSIDecoder;
1399 class VINTRP_Real_vi <bits <2> op, string opName, dag outs, dag ins,
1401 VINTRPCommon <outs, ins, asm, []>,
1403 SIMCInstr<opName, SIEncodingFamily.VI> {
1404 let AssemblerPredicate = VIAssemblerPredicate;
1405 let DecoderNamespace = "VI";
1406 let DisableDecoder = DisableVIDecoder;
1409 multiclass VINTRP_m <bits <2> op, dag outs, dag ins, string asm,
1410 list<dag> pattern = []> {
1411 def "" : VINTRP_Pseudo <NAME, outs, ins, pattern>;
1413 def _si : VINTRP_Real_si <op, NAME, outs, ins, asm>;
1415 def _vi : VINTRP_Real_vi <op, NAME, outs, ins, asm>;
1418 //===----------------------------------------------------------------------===//
1419 // Vector instruction mappings
1420 //===----------------------------------------------------------------------===//
1422 // Maps an opcode in e32 form to its e64 equivalent
1423 def getVOPe64 : InstrMapping {
1424 let FilterClass = "VOP";
1425 let RowFields = ["OpName"];
1426 let ColFields = ["Size", "VOP3"];
1427 let KeyCol = ["4", "0"];
1428 let ValueCols = [["8", "1"]];
1431 // Maps an opcode in e64 form to its e32 equivalent
1432 def getVOPe32 : InstrMapping {
1433 let FilterClass = "VOP";
1434 let RowFields = ["OpName"];
1435 let ColFields = ["Size", "VOP3"];
1436 let KeyCol = ["8", "1"];
1437 let ValueCols = [["4", "0"]];
1440 // Maps ordinary instructions to their SDWA counterparts
1441 def getSDWAOp : InstrMapping {
1442 let FilterClass = "VOP";
1443 let RowFields = ["OpName"];
1444 let ColFields = ["AsmVariantName"];
1445 let KeyCol = ["Default"];
1446 let ValueCols = [["SDWA"]];
1449 def getMaskedMIMGOp : InstrMapping {
1450 let FilterClass = "MIMG_Mask";
1451 let RowFields = ["Op"];
1452 let ColFields = ["Channels"];
1454 let ValueCols = [["1"], ["2"], ["3"] ];
1457 // Maps an commuted opcode to its original version
1458 def getCommuteOrig : InstrMapping {
1459 let FilterClass = "Commutable_REV";
1460 let RowFields = ["RevOp"];
1461 let ColFields = ["IsOrig"];
1463 let ValueCols = [["1"]];
1466 // Maps an original opcode to its commuted version
1467 def getCommuteRev : InstrMapping {
1468 let FilterClass = "Commutable_REV";
1469 let RowFields = ["RevOp"];
1470 let ColFields = ["IsOrig"];
1472 let ValueCols = [["0"]];
1475 def getMCOpcodeGen : InstrMapping {
1476 let FilterClass = "SIMCInstr";
1477 let RowFields = ["PseudoInstr"];
1478 let ColFields = ["Subtarget"];
1479 let KeyCol = [!cast<string>(SIEncodingFamily.NONE)];
1480 let ValueCols = [[!cast<string>(SIEncodingFamily.SI)],
1481 [!cast<string>(SIEncodingFamily.VI)]];
1484 // Get equivalent SOPK instruction.
1485 def getSOPKOp : InstrMapping {
1486 let FilterClass = "SOPKInstTable";
1487 let RowFields = ["BaseCmpOp"];
1488 let ColFields = ["IsSOPK"];
1490 let ValueCols = [["1"]];
1493 def getAddr64Inst : InstrMapping {
1494 let FilterClass = "MUBUFAddr64Table";
1495 let RowFields = ["OpName"];
1496 let ColFields = ["IsAddr64"];
1498 let ValueCols = [["1"]];
1501 // Maps an atomic opcode to its version with a return value.
1502 def getAtomicRetOp : InstrMapping {
1503 let FilterClass = "AtomicNoRet";
1504 let RowFields = ["NoRetOp"];
1505 let ColFields = ["IsRet"];
1507 let ValueCols = [["1"]];
1510 // Maps an atomic opcode to its returnless version.
1511 def getAtomicNoRetOp : InstrMapping {
1512 let FilterClass = "AtomicNoRet";
1513 let RowFields = ["NoRetOp"];
1514 let ColFields = ["IsRet"];
1516 let ValueCols = [["0"]];
1519 include "SIInstructions.td"
1520 include "CIInstructions.td"
1522 include "DSInstructions.td"
1523 include "MIMGInstructions.td"