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 VOP3NoMods0 : ComplexPattern<untyped, 4, "SelectVOP3NoMods0">;
650 def VOP3Mods0Clamp : ComplexPattern<untyped, 3, "SelectVOP3Mods0Clamp">;
651 def VOP3Mods0Clamp0OMod : ComplexPattern<untyped, 4, "SelectVOP3Mods0Clamp0OMod">;
652 def VOP3Mods : ComplexPattern<untyped, 2, "SelectVOP3Mods">;
653 def VOP3NoMods : ComplexPattern<untyped, 2, "SelectVOP3NoMods">;
654 // VOP3Mods, but the input source is known to never be NaN.
655 def VOP3Mods_nnan : ComplexPattern<fAny, 2, "SelectVOP3Mods_NNaN">;
657 def VOP3OMods : ComplexPattern<untyped, 3, "SelectVOP3OMods">;
659 def VOP3PMods : ComplexPattern<untyped, 2, "SelectVOP3PMods">;
660 def VOP3PMods0 : ComplexPattern<untyped, 3, "SelectVOP3PMods0">;
663 //===----------------------------------------------------------------------===//
664 // SI assembler operands
665 //===----------------------------------------------------------------------===//
673 // This should be kept in sync with SISrcMods enum
696 int LLVM_DEBUG_TRAP = 3;
699 //===----------------------------------------------------------------------===//
701 // SI Instruction multiclass helpers.
703 // Instructions with _32 take 32-bit operands.
704 // Instructions with _64 take 64-bit operands.
706 // VOP_* instructions can use either a 32-bit or 64-bit encoding. The 32-bit
707 // encoding is the standard encoding, but instruction that make use of
708 // any of the instruction modifiers must use the 64-bit encoding.
710 // Instructions with _e32 use the 32-bit encoding.
711 // Instructions with _e64 use the 64-bit encoding.
713 //===----------------------------------------------------------------------===//
715 class SIMCInstr <string pseudo, int subtarget> {
716 string PseudoInstr = pseudo;
717 int Subtarget = subtarget;
720 //===----------------------------------------------------------------------===//
722 //===----------------------------------------------------------------------===//
724 class EXP_Helper<bit done, SDPatternOperator node = null_frag> : EXPCommon<
727 ExpSrc0:$src0, ExpSrc1:$src1, ExpSrc2:$src2, ExpSrc3:$src3,
728 exp_vm:$vm, exp_compr:$compr, i8imm:$en),
729 "exp$tgt $src0, $src1, $src2, $src3"#!if(done, " done", "")#"$compr$vm",
730 [(node (i8 timm:$tgt), (i8 timm:$en),
731 f32:$src0, f32:$src1, f32:$src2, f32:$src3,
732 (i1 timm:$compr), (i1 timm:$vm))]> {
733 let AsmMatchConverter = "cvtExp";
736 // Split EXP instruction into EXP and EXP_DONE so we can set
737 // mayLoad for done=1.
738 multiclass EXP_m<bit done, SDPatternOperator node> {
739 let mayLoad = done in {
740 let isPseudo = 1, isCodeGenOnly = 1 in {
741 def "" : EXP_Helper<done, node>,
742 SIMCInstr <"exp"#!if(done, "_done", ""), SIEncodingFamily.NONE>;
746 def _si : EXP_Helper<done>,
747 SIMCInstr <"exp"#!if(done, "_done", ""), SIEncodingFamily.SI>,
749 let AssemblerPredicates = [isSICI];
750 let DecoderNamespace = "SICI";
751 let DisableDecoder = DisableSIDecoder;
754 def _vi : EXP_Helper<done>,
755 SIMCInstr <"exp"#!if(done, "_done", ""), SIEncodingFamily.VI>,
757 let AssemblerPredicates = [isVI];
758 let DecoderNamespace = "VI";
759 let DisableDecoder = DisableVIDecoder;
765 //===----------------------------------------------------------------------===//
766 // Vector ALU classes
767 //===----------------------------------------------------------------------===//
769 class getNumSrcArgs<ValueType Src0, ValueType Src1, ValueType Src2> {
771 !if (!eq(Src0.Value, untyped.Value), 0,
772 !if (!eq(Src1.Value, untyped.Value), 1, // VOP1
773 !if (!eq(Src2.Value, untyped.Value), 2, // VOP2
777 // Returns the register class to use for the destination of VOP[123C]
778 // instructions for the given VT.
779 class getVALUDstForVT<ValueType VT> {
780 RegisterOperand ret = !if(!eq(VT.Size, 32), VOPDstOperand<VGPR_32>,
781 !if(!eq(VT.Size, 128), VOPDstOperand<VReg_128>,
782 !if(!eq(VT.Size, 64), VOPDstOperand<VReg_64>,
783 !if(!eq(VT.Size, 16), VOPDstOperand<VGPR_32>,
784 VOPDstOperand<SReg_64>)))); // else VT == i1
787 // Returns the register class to use for source 0 of VOP[12C]
788 // instructions for the given VT.
789 class getVOPSrc0ForVT<ValueType VT> {
790 bit isFP = !if(!eq(VT.Value, f16.Value), 1,
791 !if(!eq(VT.Value, v2f16.Value), 1,
792 !if(!eq(VT.Value, f32.Value), 1,
793 !if(!eq(VT.Value, f64.Value), 1,
796 RegisterOperand ret =
798 !if(!eq(VT.Size, 64),
800 !if(!eq(VT.Value, f16.Value),
802 !if(!eq(VT.Value, v2f16.Value),
808 !if(!eq(VT.Size, 64),
810 !if(!eq(VT.Value, i16.Value),
812 !if(!eq(VT.Value, v2i16.Value),
821 // Returns the vreg register class to use for source operand given VT
822 class getVregSrcForVT<ValueType VT> {
823 RegisterClass ret = !if(!eq(VT.Size, 128), VReg_128,
824 !if(!eq(VT.Size, 64), VReg_64, VGPR_32));
828 // Returns the register class to use for sources of VOP3 instructions for the
830 class getVOP3SrcForVT<ValueType VT> {
831 bit isFP = !if(!eq(VT.Value, f16.Value), 1,
832 !if(!eq(VT.Value, v2f16.Value), 1,
833 !if(!eq(VT.Value, f32.Value), 1,
834 !if(!eq(VT.Value, f64.Value), 1,
836 RegisterOperand ret =
837 !if(!eq(VT.Size, 128),
839 !if(!eq(VT.Size, 64),
843 !if(!eq(VT.Value, i1.Value),
846 !if(!eq(VT.Value, f16.Value),
848 !if(!eq(VT.Value, v2f16.Value),
853 !if(!eq(VT.Value, i16.Value),
855 !if(!eq(VT.Value, v2i16.Value),
866 // Returns 1 if the source arguments have modifiers, 0 if they do not.
867 // XXX - do f16 instructions?
868 class isFloatType<ValueType SrcVT> {
870 !if(!eq(SrcVT.Value, f16.Value), 1,
871 !if(!eq(SrcVT.Value, f32.Value), 1,
872 !if(!eq(SrcVT.Value, f64.Value), 1,
873 !if(!eq(SrcVT.Value, v2f16.Value), 1,
877 class isIntType<ValueType SrcVT> {
879 !if(!eq(SrcVT.Value, i16.Value), 1,
880 !if(!eq(SrcVT.Value, i32.Value), 1,
881 !if(!eq(SrcVT.Value, i64.Value), 1,
885 class isPackedType<ValueType SrcVT> {
887 !if(!eq(SrcVT.Value, v2i16.Value), 1,
888 !if(!eq(SrcVT.Value, v2f16.Value), 1, 0)
892 // Float or packed int
893 class isModifierType<ValueType SrcVT> {
895 !if(!eq(SrcVT.Value, f16.Value), 1,
896 !if(!eq(SrcVT.Value, f32.Value), 1,
897 !if(!eq(SrcVT.Value, f64.Value), 1,
898 !if(!eq(SrcVT.Value, v2f16.Value), 1,
899 !if(!eq(SrcVT.Value, v2i16.Value), 1,
903 // Return type of input modifiers operand for specified input operand
904 class getSrcMod <ValueType VT> {
905 bit isFP = !if(!eq(VT.Value, f16.Value), 1,
906 !if(!eq(VT.Value, f32.Value), 1,
907 !if(!eq(VT.Value, f64.Value), 1,
909 bit isPacked = isPackedType<VT>.ret;
910 Operand ret = !if(!eq(VT.Size, 64),
911 !if(isFP, FP64InputMods, Int64InputMods),
913 !if(!eq(VT.Value, f16.Value),
921 // Return type of input modifiers operand specified input operand for SDWA/DPP
922 class getSrcModExt <ValueType VT> {
923 bit isFP = !if(!eq(VT.Value, f16.Value), 1,
924 !if(!eq(VT.Value, f32.Value), 1,
925 !if(!eq(VT.Value, f64.Value), 1,
927 Operand ret = !if(isFP, FPVRegInputMods, IntVRegInputMods);
930 // Returns the input arguments for VOP[12C] instructions for the given SrcVT.
931 class getIns32 <RegisterOperand Src0RC, RegisterClass Src1RC, int NumSrcArgs> {
932 dag ret = !if(!eq(NumSrcArgs, 1), (ins Src0RC:$src0), // VOP1
933 !if(!eq(NumSrcArgs, 2), (ins Src0RC:$src0, Src1RC:$src1), // VOP2
937 // Returns the input arguments for VOP3 instructions for the given SrcVT.
938 class getIns64 <RegisterOperand Src0RC, RegisterOperand Src1RC,
939 RegisterOperand Src2RC, int NumSrcArgs,
940 bit HasModifiers, bit HasOMod,
941 Operand Src0Mod, Operand Src1Mod, Operand Src2Mod> {
944 !if (!eq(NumSrcArgs, 0),
945 // VOP1 without input operands (V_NOP, V_CLREXCP)
948 !if (!eq(NumSrcArgs, 1),
949 !if (!eq(HasModifiers, 1),
950 // VOP1 with modifiers
951 (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
952 clampmod:$clamp, omod:$omod)
954 // VOP1 without modifiers
957 !if (!eq(NumSrcArgs, 2),
958 !if (!eq(HasModifiers, 1),
959 // VOP 2 with modifiers
960 !if( !eq(HasOMod, 1),
961 (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
962 Src1Mod:$src1_modifiers, Src1RC:$src1,
963 clampmod:$clamp, omod:$omod),
964 (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
965 Src1Mod:$src1_modifiers, Src1RC:$src1,
968 // VOP2 without modifiers
969 (ins Src0RC:$src0, Src1RC:$src1)
971 /* NumSrcArgs == 3 */,
972 !if (!eq(HasModifiers, 1),
973 // VOP3 with modifiers
974 !if (!eq(HasOMod, 1),
975 (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
976 Src1Mod:$src1_modifiers, Src1RC:$src1,
977 Src2Mod:$src2_modifiers, Src2RC:$src2,
978 clampmod:$clamp, omod:$omod),
979 (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
980 Src1Mod:$src1_modifiers, Src1RC:$src1,
981 Src2Mod:$src2_modifiers, Src2RC:$src2,
984 // VOP3 without modifiers
985 (ins Src0RC:$src0, Src1RC:$src1, Src2RC:$src2)
989 /// XXX - src1 may only allow VGPRs?
991 // The modifiers (except clamp) are dummy operands for the benefit of
992 // printing and parsing. They defer their values to looking at the
993 // srcN_modifiers for what to print.
994 class getInsVOP3P <RegisterOperand Src0RC, RegisterOperand Src1RC,
995 RegisterOperand Src2RC, int NumSrcArgs,
997 Operand Src0Mod, Operand Src1Mod, Operand Src2Mod> {
998 dag ret = !if (!eq(NumSrcArgs, 2),
1000 (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1001 Src1Mod:$src1_modifiers, Src1RC:$src1,
1003 op_sel:$op_sel, op_sel_hi:$op_sel_hi,
1004 neg_lo:$neg_lo, neg_hi:$neg_hi),
1005 (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1006 Src1Mod:$src1_modifiers, Src1RC:$src1,
1007 op_sel:$op_sel, op_sel_hi:$op_sel_hi,
1008 neg_lo:$neg_lo, neg_hi:$neg_hi)),
1009 // else NumSrcArgs == 3
1011 (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1012 Src1Mod:$src1_modifiers, Src1RC:$src1,
1013 Src2Mod:$src2_modifiers, Src2RC:$src2,
1015 op_sel:$op_sel, op_sel_hi:$op_sel_hi,
1016 neg_lo:$neg_lo, neg_hi:$neg_hi),
1017 (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1018 Src1Mod:$src1_modifiers, Src1RC:$src1,
1019 Src2Mod:$src2_modifiers, Src2RC:$src2,
1020 op_sel:$op_sel, op_sel_hi:$op_sel_hi,
1021 neg_lo:$neg_lo, neg_hi:$neg_hi))
1025 class getInsDPP <RegisterClass Src0RC, RegisterClass Src1RC, int NumSrcArgs,
1026 bit HasModifiers, Operand Src0Mod, Operand Src1Mod> {
1028 dag ret = !if (!eq(NumSrcArgs, 0),
1029 // VOP1 without input operands (V_NOP)
1030 (ins dpp_ctrl:$dpp_ctrl, row_mask:$row_mask,
1031 bank_mask:$bank_mask, bound_ctrl:$bound_ctrl),
1032 !if (!eq(NumSrcArgs, 1),
1033 !if (!eq(HasModifiers, 1),
1034 // VOP1_DPP with modifiers
1035 (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1036 dpp_ctrl:$dpp_ctrl, row_mask:$row_mask,
1037 bank_mask:$bank_mask, bound_ctrl:$bound_ctrl)
1039 // VOP1_DPP without modifiers
1040 (ins Src0RC:$src0, dpp_ctrl:$dpp_ctrl, row_mask:$row_mask,
1041 bank_mask:$bank_mask, bound_ctrl:$bound_ctrl)
1043 /* NumSrcArgs == 2 */,
1044 !if (!eq(HasModifiers, 1),
1045 // VOP2_DPP with modifiers
1046 (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1047 Src1Mod:$src1_modifiers, Src1RC:$src1,
1048 dpp_ctrl:$dpp_ctrl, row_mask:$row_mask,
1049 bank_mask:$bank_mask, bound_ctrl:$bound_ctrl)
1051 // VOP2_DPP without modifiers
1052 (ins Src0RC:$src0, Src1RC:$src1, dpp_ctrl:$dpp_ctrl,
1053 row_mask:$row_mask, bank_mask:$bank_mask,
1054 bound_ctrl:$bound_ctrl)
1058 class getInsSDWA <RegisterClass Src0RC, RegisterClass Src1RC, int NumSrcArgs,
1059 bit HasFloatModifiers, Operand Src0Mod, Operand Src1Mod,
1062 dag ret = !if(!eq(NumSrcArgs, 0),
1063 // VOP1 without input operands (V_NOP)
1065 !if(!eq(NumSrcArgs, 1),
1066 (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1067 clampmod:$clamp, dst_sel:$dst_sel, dst_unused:$dst_unused,
1068 src0_sel:$src0_sel),
1069 !if(!eq(NumSrcArgs, 2),
1070 !if(!eq(DstVT.Size, 1),
1071 // VOPC_SDWA with modifiers
1072 (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1073 Src1Mod:$src1_modifiers, Src1RC:$src1,
1074 clampmod:$clamp, src0_sel:$src0_sel, src1_sel:$src1_sel),
1075 // VOP2_SDWA or VOPC_SDWA with modifiers
1076 (ins Src0Mod:$src0_modifiers, Src0RC:$src0,
1077 Src1Mod:$src1_modifiers, Src1RC:$src1,
1078 clampmod:$clamp, dst_sel:$dst_sel, dst_unused:$dst_unused,
1079 src0_sel:$src0_sel, src1_sel:$src1_sel)),
1080 (ins)/* endif */)));
1083 // Outs for DPP and SDWA
1084 class getOutsExt <bit HasDst, ValueType DstVT, RegisterOperand DstRCDPP> {
1085 dag ret = !if(HasDst,
1086 !if(!eq(DstVT.Size, 1),
1087 (outs), // no dst for VOPC, we use "vcc"-token as dst in SDWA VOPC instructions
1088 (outs DstRCDPP:$vdst)),
1092 // Returns the assembly string for the inputs and outputs of a VOP[12C]
1093 // instruction. This does not add the _e32 suffix, so it can be reused
1095 class getAsm32 <bit HasDst, int NumSrcArgs, ValueType DstVT = i32> {
1096 string dst = !if(!eq(DstVT.Size, 1), "$sdst", "$vdst"); // use $sdst for VOPC
1097 string src0 = ", $src0";
1098 string src1 = ", $src1";
1099 string src2 = ", $src2";
1100 string ret = !if(HasDst, dst, "") #
1101 !if(!eq(NumSrcArgs, 1), src0, "") #
1102 !if(!eq(NumSrcArgs, 2), src0#src1, "") #
1103 !if(!eq(NumSrcArgs, 3), src0#src1#src2, "");
1106 // Returns the assembly string for the inputs and outputs of a VOP3
1108 class getAsm64 <bit HasDst, int NumSrcArgs, bit HasModifiers,
1109 bit HasOMod, ValueType DstVT = i32> {
1110 string dst = !if(!eq(DstVT.Size, 1), "$sdst", "$vdst"); // use $sdst for VOPC
1111 string src0 = !if(!eq(NumSrcArgs, 1), "$src0_modifiers", "$src0_modifiers,");
1112 string src1 = !if(!eq(NumSrcArgs, 1), "",
1113 !if(!eq(NumSrcArgs, 2), " $src1_modifiers",
1114 " $src1_modifiers,"));
1115 string src2 = !if(!eq(NumSrcArgs, 3), " $src2_modifiers", "");
1117 !if(!eq(HasModifiers, 0),
1118 getAsm32<HasDst, NumSrcArgs, DstVT>.ret,
1119 dst#", "#src0#src1#src2#"$clamp"#!if(HasOMod, "$omod", ""));
1122 // Returns the assembly string for the inputs and outputs of a VOP3P
1124 class getAsmVOP3P <bit HasDst, int NumSrcArgs, bit HasModifiers,
1125 bit HasClamp, ValueType DstVT = i32> {
1126 string dst = " $vdst";
1127 string src0 = !if(!eq(NumSrcArgs, 1), "$src0", "$src0,");
1128 string src1 = !if(!eq(NumSrcArgs, 1), "",
1129 !if(!eq(NumSrcArgs, 2), " $src1",
1131 string src2 = !if(!eq(NumSrcArgs, 3), " $src2", "");
1133 string mods = !if(HasModifiers, "$neg_lo$neg_hi", "");
1134 string clamp = !if(HasClamp, "$clamp", "");
1136 // Each modifier is printed as an array of bits for each operand, so
1137 // all operands are printed as part of src0_modifiers.
1138 string ret = dst#", "#src0#src1#src2#"$op_sel$op_sel_hi"#mods#clamp;
1141 class getAsmDPP <bit HasDst, int NumSrcArgs, bit HasModifiers, ValueType DstVT = i32> {
1142 string dst = !if(HasDst,
1143 !if(!eq(DstVT.Size, 1),
1146 ""); // use $sdst for VOPC
1147 string src0 = !if(!eq(NumSrcArgs, 1), "$src0_modifiers", "$src0_modifiers,");
1148 string src1 = !if(!eq(NumSrcArgs, 1), "",
1149 !if(!eq(NumSrcArgs, 2), " $src1_modifiers",
1150 " $src1_modifiers,"));
1151 string args = !if(!eq(HasModifiers, 0),
1152 getAsm32<0, NumSrcArgs, DstVT>.ret,
1154 string ret = dst#args#" $dpp_ctrl$row_mask$bank_mask$bound_ctrl";
1157 class getAsmSDWA <bit HasDst, int NumSrcArgs, bit HasFloatModifiers,
1158 ValueType DstVT = i32> {
1159 string dst = !if(HasDst,
1160 !if(!eq(DstVT.Size, 1),
1161 " vcc", // use vcc token as dst for VOPC instructioins
1164 string src0 = "$src0_modifiers";
1165 string src1 = "$src1_modifiers";
1166 string args = !if(!eq(NumSrcArgs, 0),
1168 !if(!eq(NumSrcArgs, 1),
1170 ", "#src0#", "#src1#"$clamp"
1173 string sdwa = !if(!eq(NumSrcArgs, 0),
1175 !if(!eq(NumSrcArgs, 1),
1176 " $dst_sel $dst_unused $src0_sel",
1177 !if(!eq(DstVT.Size, 1),
1178 " $src0_sel $src1_sel", // No dst_sel and dst_unused for VOPC
1179 " $dst_sel $dst_unused $src0_sel $src1_sel"
1183 string ret = dst#args#sdwa;
1186 // Function that checks if instruction supports DPP and SDWA
1187 class getHasExt <int NumSrcArgs, ValueType DstVT = i32, ValueType Src0VT = i32,
1188 ValueType Src1VT = i32> {
1189 bit ret = !if(!eq(NumSrcArgs, 3),
1190 0, // NumSrcArgs == 3 - No DPP or SDWA for VOP3
1191 !if(!eq(DstVT.Size, 64),
1192 0, // 64-bit dst - No DPP or SDWA for 64-bit operands
1193 !if(!eq(Src0VT.Size, 64),
1195 !if(!eq(Src0VT.Size, 64),
1204 class BitOr<bit a, bit b> {
1205 bit ret = !if(a, 1, !if(b, 1, 0));
1208 class BitAnd<bit a, bit b> {
1209 bit ret = !if(a, !if(b, 1, 0), 0);
1212 class VOPProfile <list<ValueType> _ArgVT> {
1214 field list<ValueType> ArgVT = _ArgVT;
1216 field ValueType DstVT = ArgVT[0];
1217 field ValueType Src0VT = ArgVT[1];
1218 field ValueType Src1VT = ArgVT[2];
1219 field ValueType Src2VT = ArgVT[3];
1220 field RegisterOperand DstRC = getVALUDstForVT<DstVT>.ret;
1221 field RegisterOperand DstRCDPP = getVALUDstForVT<DstVT>.ret;
1222 field RegisterOperand DstRCSDWA = getVALUDstForVT<DstVT>.ret;
1223 field RegisterOperand Src0RC32 = getVOPSrc0ForVT<Src0VT>.ret;
1224 field RegisterClass Src1RC32 = getVregSrcForVT<Src1VT>.ret;
1225 field RegisterOperand Src0RC64 = getVOP3SrcForVT<Src0VT>.ret;
1226 field RegisterOperand Src1RC64 = getVOP3SrcForVT<Src1VT>.ret;
1227 field RegisterOperand Src2RC64 = getVOP3SrcForVT<Src2VT>.ret;
1228 field RegisterClass Src0DPP = getVregSrcForVT<Src0VT>.ret;
1229 field RegisterClass Src1DPP = getVregSrcForVT<Src1VT>.ret;
1230 field RegisterClass Src0SDWA = getVregSrcForVT<Src0VT>.ret;
1231 field RegisterClass Src1SDWA = getVregSrcForVT<Src1VT>.ret;
1232 field Operand Src0Mod = getSrcMod<Src0VT>.ret;
1233 field Operand Src1Mod = getSrcMod<Src1VT>.ret;
1234 field Operand Src2Mod = getSrcMod<Src2VT>.ret;
1235 field Operand Src0ModDPP = getSrcModExt<Src0VT>.ret;
1236 field Operand Src1ModDPP = getSrcModExt<Src1VT>.ret;
1237 field Operand Src0ModSDWA = getSrcModExt<Src0VT>.ret;
1238 field Operand Src1ModSDWA = getSrcModExt<Src1VT>.ret;
1241 field bit HasDst = !if(!eq(DstVT.Value, untyped.Value), 0, 1);
1242 field bit HasDst32 = HasDst;
1243 field bit EmitDst = HasDst; // force dst encoding, see v_movreld_b32 special case
1244 field int NumSrcArgs = getNumSrcArgs<Src0VT, Src1VT, Src2VT>.ret;
1245 field bit HasSrc0 = !if(!eq(Src0VT.Value, untyped.Value), 0, 1);
1246 field bit HasSrc1 = !if(!eq(Src1VT.Value, untyped.Value), 0, 1);
1247 field bit HasSrc2 = !if(!eq(Src2VT.Value, untyped.Value), 0, 1);
1249 // TODO: Modifiers logic is somewhat adhoc here, to be refined later
1250 field bit HasModifiers = isModifierType<Src0VT>.ret;
1252 field bit HasSrc0FloatMods = isFloatType<Src0VT>.ret;
1253 field bit HasSrc1FloatMods = isFloatType<Src1VT>.ret;
1254 field bit HasSrc2FloatMods = isFloatType<Src2VT>.ret;
1256 field bit HasSrc0IntMods = isIntType<Src0VT>.ret;
1257 field bit HasSrc1IntMods = isIntType<Src1VT>.ret;
1258 field bit HasSrc2IntMods = isIntType<Src2VT>.ret;
1260 field bit HasSrc0Mods = HasModifiers;
1261 field bit HasSrc1Mods = !if(HasModifiers, BitOr<HasSrc1FloatMods, HasSrc1IntMods>.ret, 0);
1262 field bit HasSrc2Mods = !if(HasModifiers, BitOr<HasSrc2FloatMods, HasSrc2IntMods>.ret, 0);
1264 field bit HasClamp = HasModifiers;
1265 field bit HasSDWAClamp = HasSrc0;
1266 field bit HasFPClamp = BitAnd<isFloatType<DstVT>.ret, HasClamp>.ret;
1268 field bit IsPacked = isPackedType<Src0VT>.ret;
1269 field bit HasOpSel = IsPacked;
1270 field bit HasOMod = !if(HasOpSel, 0, HasModifiers);
1272 field bit HasExt = getHasExt<NumSrcArgs, DstVT, Src0VT, Src1VT>.ret;
1274 field Operand Src0PackedMod = !if(HasSrc0FloatMods, PackedF16InputMods, PackedI16InputMods);
1275 field Operand Src1PackedMod = !if(HasSrc1FloatMods, PackedF16InputMods, PackedI16InputMods);
1276 field Operand Src2PackedMod = !if(HasSrc2FloatMods, PackedF16InputMods, PackedI16InputMods);
1278 field dag Outs = !if(HasDst,(outs DstRC:$vdst),(outs));
1280 // VOP3b instructions are a special case with a second explicit
1281 // output. This is manually overridden for them.
1282 field dag Outs32 = Outs;
1283 field dag Outs64 = Outs;
1284 field dag OutsDPP = getOutsExt<HasDst, DstVT, DstRCDPP>.ret;
1285 field dag OutsSDWA = getOutsExt<HasDst, DstVT, DstRCSDWA>.ret;
1287 field dag Ins32 = getIns32<Src0RC32, Src1RC32, NumSrcArgs>.ret;
1288 field dag Ins64 = getIns64<Src0RC64, Src1RC64, Src2RC64, NumSrcArgs,
1289 HasModifiers, HasOMod, Src0Mod, Src1Mod,
1291 field dag InsVOP3P = getInsVOP3P<Src0RC64, Src1RC64, Src2RC64,
1292 NumSrcArgs, HasClamp,
1293 Src0PackedMod, Src1PackedMod, Src2PackedMod>.ret;
1295 field dag InsDPP = getInsDPP<Src0DPP, Src1DPP, NumSrcArgs,
1296 HasModifiers, Src0ModDPP, Src1ModDPP>.ret;
1297 field dag InsSDWA = getInsSDWA<Src0SDWA, Src1SDWA, NumSrcArgs,
1298 HasModifiers, Src0ModSDWA, Src1ModSDWA,
1301 field string Asm32 = getAsm32<HasDst, NumSrcArgs, DstVT>.ret;
1302 field string Asm64 = getAsm64<HasDst, NumSrcArgs, HasModifiers, HasOMod, DstVT>.ret;
1303 field string AsmVOP3P = getAsmVOP3P<HasDst, NumSrcArgs, HasModifiers, HasClamp, DstVT>.ret;
1304 field string AsmDPP = getAsmDPP<HasDst, NumSrcArgs, HasModifiers, DstVT>.ret;
1305 field string AsmSDWA = getAsmSDWA<HasDst, NumSrcArgs, HasModifiers, DstVT>.ret;
1308 class VOP_NO_EXT <VOPProfile p> : VOPProfile <p.ArgVT> {
1312 def VOP_F16_F16 : VOPProfile <[f16, f16, untyped, untyped]>;
1313 def VOP_F16_I16 : VOPProfile <[f16, i16, untyped, untyped]>;
1314 def VOP_I16_F16 : VOPProfile <[i16, f16, untyped, untyped]>;
1316 def VOP_F16_F16_F16 : VOPProfile <[f16, f16, f16, untyped]>;
1317 def VOP_F16_F16_I16 : VOPProfile <[f16, f16, i16, untyped]>;
1318 def VOP_F16_F16_I32 : VOPProfile <[f16, f16, i32, untyped]>;
1319 def VOP_I16_I16_I16 : VOPProfile <[i16, i16, i16, untyped]>;
1321 def VOP_I16_I16_I16_I16 : VOPProfile <[i16, i16, i16, i16, untyped]>;
1322 def VOP_F16_F16_F16_F16 : VOPProfile <[f16, f16, f16, f16, untyped]>;
1324 def VOP_V2F16_V2F16_V2F16 : VOPProfile <[v2f16, v2f16, v2f16, untyped]>;
1325 def VOP_V2I16_V2I16_V2I16 : VOPProfile <[v2i16, v2i16, v2i16, untyped]>;
1326 def VOP_B32_F16_F16 : VOPProfile <[i32, f16, f16, untyped]>;
1328 def VOP_V2F16_V2F16_V2F16_V2F16 : VOPProfile <[v2f16, v2f16, v2f16, v2f16]>;
1329 def VOP_V2I16_V2I16_V2I16_V2I16 : VOPProfile <[v2i16, v2i16, v2i16, v2i16]>;
1331 def VOP_NONE : VOPProfile <[untyped, untyped, untyped, untyped]>;
1333 def VOP_F32_F32 : VOPProfile <[f32, f32, untyped, untyped]>;
1334 def VOP_F32_F64 : VOPProfile <[f32, f64, untyped, untyped]>;
1335 def VOP_F32_I32 : VOPProfile <[f32, i32, untyped, untyped]>;
1336 def VOP_F64_F32 : VOPProfile <[f64, f32, untyped, untyped]>;
1337 def VOP_F64_F64 : VOPProfile <[f64, f64, untyped, untyped]>;
1338 def VOP_F64_I32 : VOPProfile <[f64, i32, untyped, untyped]>;
1339 def VOP_I32_F32 : VOPProfile <[i32, f32, untyped, untyped]>;
1340 def VOP_I32_F64 : VOPProfile <[i32, f64, untyped, untyped]>;
1341 def VOP_I32_I32 : VOPProfile <[i32, i32, untyped, untyped]>;
1342 def VOP_F16_F32 : VOPProfile <[f16, f32, untyped, untyped]>;
1343 def VOP_F32_F16 : VOPProfile <[f32, f16, untyped, untyped]>;
1345 def VOP_F32_F32_F16 : VOPProfile <[f32, f32, f16, untyped]>;
1346 def VOP_F32_F32_F32 : VOPProfile <[f32, f32, f32, untyped]>;
1347 def VOP_F32_F32_I32 : VOPProfile <[f32, f32, i32, untyped]>;
1348 def VOP_F64_F64_F64 : VOPProfile <[f64, f64, f64, untyped]>;
1349 def VOP_F64_F64_I32 : VOPProfile <[f64, f64, i32, untyped]>;
1350 def VOP_I32_F32_F32 : VOPProfile <[i32, f32, f32, untyped]>;
1351 def VOP_I32_F32_I32 : VOPProfile <[i32, f32, i32, untyped]>;
1352 def VOP_I32_I32_I32 : VOPProfile <[i32, i32, i32, untyped]>;
1353 def VOP_V2F16_F32_F32 : VOPProfile <[v2f16, f32, f32, untyped]>;
1355 def VOP_I64_I64_I32 : VOPProfile <[i64, i64, i32, untyped]>;
1356 def VOP_I64_I32_I64 : VOPProfile <[i64, i32, i64, untyped]>;
1357 def VOP_I64_I64_I64 : VOPProfile <[i64, i64, i64, untyped]>;
1359 def VOP_F16_F32_F16_F32 : VOPProfile <[f16, f32, f16, f32]>;
1360 def VOP_F32_F32_F16_F16 : VOPProfile <[f32, f32, f16, f16]>;
1361 def VOP_F32_F32_F32_F32 : VOPProfile <[f32, f32, f32, f32]>;
1362 def VOP_F64_F64_F64_F64 : VOPProfile <[f64, f64, f64, f64]>;
1363 def VOP_I32_I32_I32_I32 : VOPProfile <[i32, i32, i32, i32]>;
1364 def VOP_I64_I32_I32_I64 : VOPProfile <[i64, i32, i32, i64]>;
1365 def VOP_I32_F32_I32_I32 : VOPProfile <[i32, f32, i32, i32]>;
1366 def VOP_I64_I64_I32_I64 : VOPProfile <[i64, i64, i32, i64]>;
1367 def VOP_V4I32_I64_I32_V4I32 : VOPProfile <[v4i32, i64, i32, v4i32]>;
1369 class Commutable_REV <string revOp, bit isOrig> {
1370 string RevOp = revOp;
1371 bit IsOrig = isOrig;
1374 class AtomicNoRet <string noRetOp, bit isRet> {
1375 string NoRetOp = noRetOp;
1379 //===----------------------------------------------------------------------===//
1380 // Interpolation opcodes
1381 //===----------------------------------------------------------------------===//
1383 class VINTRP_Pseudo <string opName, dag outs, dag ins, list<dag> pattern> :
1384 VINTRPCommon <outs, ins, "", pattern>,
1385 SIMCInstr<opName, SIEncodingFamily.NONE> {
1387 let isCodeGenOnly = 1;
1390 class VINTRP_Real_si <bits <2> op, string opName, dag outs, dag ins,
1392 VINTRPCommon <outs, ins, asm, []>,
1394 SIMCInstr<opName, SIEncodingFamily.SI> {
1395 let AssemblerPredicate = SIAssemblerPredicate;
1396 let DecoderNamespace = "SICI";
1397 let DisableDecoder = DisableSIDecoder;
1400 class VINTRP_Real_vi <bits <2> op, string opName, dag outs, dag ins,
1402 VINTRPCommon <outs, ins, asm, []>,
1404 SIMCInstr<opName, SIEncodingFamily.VI> {
1405 let AssemblerPredicate = VIAssemblerPredicate;
1406 let DecoderNamespace = "VI";
1407 let DisableDecoder = DisableVIDecoder;
1410 multiclass VINTRP_m <bits <2> op, dag outs, dag ins, string asm,
1411 list<dag> pattern = []> {
1412 def "" : VINTRP_Pseudo <NAME, outs, ins, pattern>;
1414 def _si : VINTRP_Real_si <op, NAME, outs, ins, asm>;
1416 def _vi : VINTRP_Real_vi <op, NAME, outs, ins, asm>;
1419 //===----------------------------------------------------------------------===//
1420 // Vector instruction mappings
1421 //===----------------------------------------------------------------------===//
1423 // Maps an opcode in e32 form to its e64 equivalent
1424 def getVOPe64 : InstrMapping {
1425 let FilterClass = "VOP";
1426 let RowFields = ["OpName"];
1427 let ColFields = ["Size", "VOP3"];
1428 let KeyCol = ["4", "0"];
1429 let ValueCols = [["8", "1"]];
1432 // Maps an opcode in e64 form to its e32 equivalent
1433 def getVOPe32 : InstrMapping {
1434 let FilterClass = "VOP";
1435 let RowFields = ["OpName"];
1436 let ColFields = ["Size", "VOP3"];
1437 let KeyCol = ["8", "1"];
1438 let ValueCols = [["4", "0"]];
1441 // Maps ordinary instructions to their SDWA counterparts
1442 def getSDWAOp : InstrMapping {
1443 let FilterClass = "VOP";
1444 let RowFields = ["OpName"];
1445 let ColFields = ["AsmVariantName"];
1446 let KeyCol = ["Default"];
1447 let ValueCols = [["SDWA"]];
1450 def getMaskedMIMGOp : InstrMapping {
1451 let FilterClass = "MIMG_Mask";
1452 let RowFields = ["Op"];
1453 let ColFields = ["Channels"];
1455 let ValueCols = [["1"], ["2"], ["3"] ];
1458 // Maps an commuted opcode to its original version
1459 def getCommuteOrig : InstrMapping {
1460 let FilterClass = "Commutable_REV";
1461 let RowFields = ["RevOp"];
1462 let ColFields = ["IsOrig"];
1464 let ValueCols = [["1"]];
1467 // Maps an original opcode to its commuted version
1468 def getCommuteRev : InstrMapping {
1469 let FilterClass = "Commutable_REV";
1470 let RowFields = ["RevOp"];
1471 let ColFields = ["IsOrig"];
1473 let ValueCols = [["0"]];
1476 def getMCOpcodeGen : InstrMapping {
1477 let FilterClass = "SIMCInstr";
1478 let RowFields = ["PseudoInstr"];
1479 let ColFields = ["Subtarget"];
1480 let KeyCol = [!cast<string>(SIEncodingFamily.NONE)];
1481 let ValueCols = [[!cast<string>(SIEncodingFamily.SI)],
1482 [!cast<string>(SIEncodingFamily.VI)]];
1485 // Get equivalent SOPK instruction.
1486 def getSOPKOp : InstrMapping {
1487 let FilterClass = "SOPKInstTable";
1488 let RowFields = ["BaseCmpOp"];
1489 let ColFields = ["IsSOPK"];
1491 let ValueCols = [["1"]];
1494 def getAddr64Inst : InstrMapping {
1495 let FilterClass = "MUBUFAddr64Table";
1496 let RowFields = ["OpName"];
1497 let ColFields = ["IsAddr64"];
1499 let ValueCols = [["1"]];
1502 // Maps an atomic opcode to its version with a return value.
1503 def getAtomicRetOp : InstrMapping {
1504 let FilterClass = "AtomicNoRet";
1505 let RowFields = ["NoRetOp"];
1506 let ColFields = ["IsRet"];
1508 let ValueCols = [["1"]];
1511 // Maps an atomic opcode to its returnless version.
1512 def getAtomicNoRetOp : InstrMapping {
1513 let FilterClass = "AtomicNoRet";
1514 let RowFields = ["NoRetOp"];
1515 let ColFields = ["IsRet"];
1517 let ValueCols = [["0"]];
1520 include "SIInstructions.td"
1521 include "CIInstructions.td"
1523 include "DSInstructions.td"
1524 include "MIMGInstructions.td"