70 enum KindTy { Token, Immediate, Register, Expression } Kind;
72 SMLoc StartLoc, EndLoc;
73 const AMDGPUAsmParser *AsmParser;
76 AMDGPUOperand(KindTy Kind_,
const AMDGPUAsmParser *AsmParser_)
77 : Kind(Kind_), AsmParser(AsmParser_) {}
79 using Ptr = std::unique_ptr<AMDGPUOperand>;
87 bool hasFPModifiers()
const {
return Abs || Neg; }
88 bool hasIntModifiers()
const {
return Sext; }
89 bool hasModifiers()
const {
return hasFPModifiers() || hasIntModifiers(); }
90 bool isForcedLit()
const {
return Lit == LitModifier::Lit; }
91 bool isForcedLit64()
const {
return Lit == LitModifier::Lit64; }
93 int64_t getFPModifiersOperand()
const {
100 int64_t getIntModifiersOperand()
const {
106 int64_t getModifiersOperand()
const {
107 assert(!(hasFPModifiers() && hasIntModifiers()) &&
108 "fp and int modifiers should not be used simultaneously");
109 if (hasFPModifiers())
110 return getFPModifiersOperand();
111 if (hasIntModifiers())
112 return getIntModifiersOperand();
116 friend raw_ostream &
operator<<(raw_ostream &OS,
117 AMDGPUOperand::Modifiers Mods);
192 ImmTyMatrixAScaleFmt,
193 ImmTyMatrixBScaleFmt,
226 mutable int MCOpIdx = -1;
229 bool isToken()
const override {
return Kind == Token; }
231 bool isSymbolRefExpr()
const {
235 bool hasSymbolSpecifier()
const {
236 return isSymbolRefExpr() &&
241 bool isImm()
const override {
return Kind == Immediate; }
243 bool isInlinableImm(MVT type)
const;
244 bool isLiteralImm(MVT type)
const;
246 bool isRegKind()
const {
return Kind == Register; }
248 bool isReg()
const override {
return isRegKind() && !hasModifiers(); }
250 bool isRegOrInline(
unsigned RCID, MVT type)
const {
251 return isRegClass(RCID) || isInlinableImm(type);
254 bool isRegOrInlineTarget(
unsigned TargetRCIdx, MVT type)
const {
255 return isRegClassTarget(TargetRCIdx) || isInlinableImm(type);
259 return isRegOrInline(RCID, type) || isLiteralImm(type);
262 bool isRegOrImmWithInputModsTarget(
unsigned TargetRCIdx, MVT type)
const {
263 return isRegOrInlineTarget(TargetRCIdx, type) || isLiteralImm(type);
266 template <
bool IsFake16>
bool isRegOrImmWithIntT16InputMods()
const {
268 IsFake16 ? AMDGPU::VS_32RegClassID : AMDGPU::VS_16RegClassID, MVT::i16);
271 bool isRegOrImmWithInt32InputMods()
const {
275 template <
bool IsFake16>
bool isRegOrInlineImmWithIntT16InputMods()
const {
276 return isRegOrInline(
277 IsFake16 ? AMDGPU::VS_32RegClassID : AMDGPU::VS_16RegClassID, MVT::i16);
280 bool isRegOrInlineImmWithInt32InputMods()
const {
281 return isRegOrInline(AMDGPU::VS_32RegClassID, MVT::i32);
284 bool isRegOrImmWithInt64InputMods()
const {
285 return isRegOrImmWithInputModsTarget(AMDGPU::VS_64_AlignTarget, MVT::i64);
288 bool isRegOrImmWithFP16InputMods()
const {
292 template <
bool IsFake16>
bool isRegOrImmWithFPT16InputMods()
const {
294 IsFake16 ? AMDGPU::VS_32RegClassID : AMDGPU::VS_16RegClassID, MVT::f16);
297 bool isRegOrImmWithFPT16_LO16InputMods()
const {
301 bool isRegOrImmWithFP32InputMods()
const {
305 bool isRegOrImmWithFP64InputMods()
const {
306 return isRegOrImmWithInputModsTarget(AMDGPU::VS_64_AlignTarget, MVT::f64);
309 template <
bool IsFake16>
bool isRegOrInlineImmWithFP16InputMods()
const {
310 return isRegOrInline(
311 IsFake16 ? AMDGPU::VS_32RegClassID : AMDGPU::VS_16RegClassID, MVT::f16);
314 bool isRegOrInlineImmWithFP32InputMods()
const {
315 return isRegOrInline(AMDGPU::VS_32RegClassID, MVT::f32);
318 bool isRegOrInlineImmWithFP64InputMods()
const {
319 return isRegOrInlineTarget(AMDGPU::VS_64_AlignTarget, MVT::f64);
322 bool isVRegWithInputMods(
unsigned RCID)
const {
return isRegClass(RCID); }
324 bool isVRegWithFP32InputMods()
const {
325 return isVRegWithInputMods(AMDGPU::VGPR_32RegClassID);
328 bool isVRegWithFP64InputMods()
const {
329 return isRegClassTarget(AMDGPU::VReg_64_AlignTarget);
332 bool isPackedFP16InputMods()
const {
336 bool isPackedVGPRFP32InputMods()
const {
340 bool isVReg32()
const {
return isRegClass(AMDGPU::VGPR_32RegClassID); }
342 bool isVReg32OrOff()
const {
return isOff() || isVReg32(); }
344 bool isRsrcReg32()
const {
return isRegClass(AMDGPU::RsrcReg32RegClassID); }
346 bool isNull()
const {
return isRegKind() &&
getReg() == AMDGPU::SGPR_NULL; }
348 bool isAV_LdSt_32_Align2_RegOp()
const {
349 return isRegClass(AMDGPU::VGPR_32RegClassID) ||
350 isRegClass(AMDGPU::AGPR_32RegClassID);
353 bool isVRegWithInputMods()
const;
354 template <
bool IsFake16>
bool isT16_Lo128VRegWithInputMods()
const;
355 template <
bool IsFake16>
bool isT16VRegWithInputMods()
const;
356 bool isT16_LO16VRegWithInputMods()
const;
358 bool isSDWAOperand(MVT type)
const;
359 bool isSDWAFP16Operand()
const;
360 bool isSDWAFP32Operand()
const;
361 bool isSDWAInt16Operand()
const;
362 bool isSDWAInt32Operand()
const;
364 bool isImmTy(ImmTy ImmT)
const {
return isImm() &&
Imm.Type == ImmT; }
366 template <ImmTy Ty>
bool isImmTy()
const {
return isImmTy(Ty); }
368 bool isImmLiteral()
const {
return isImmTy(ImmTyNone); }
370 bool isImmModifier()
const {
return isImm() &&
Imm.Type != ImmTyNone; }
372 bool isOModSI()
const {
return isImmTy(ImmTyOModSI); }
373 bool isDim()
const {
return isImmTy(ImmTyDim); }
374 bool isR128A16()
const {
return isImmTy(ImmTyR128A16); }
375 bool isOff()
const {
return isImmTy(ImmTyOff); }
376 bool isExpTgt()
const {
return isImmTy(ImmTyExpTgt); }
377 bool isOffen()
const {
return isImmTy(ImmTyOffen); }
378 bool isIdxen()
const {
return isImmTy(ImmTyIdxen); }
379 bool isAddr64()
const {
return isImmTy(ImmTyAddr64); }
380 bool isSMEMOffsetMod()
const {
return isImmTy(ImmTySMEMOffsetMod); }
381 bool isFlatOffset()
const {
382 return isImmTy(ImmTyOffset) || isImmTy(ImmTyInstOffset);
384 bool isGDS()
const {
return isImmTy(ImmTyGDS); }
385 bool isLDS()
const {
return isImmTy(ImmTyLDS); }
386 bool isCPol()
const {
return isImmTy(ImmTyCPol); }
387 bool isIndexKey8bit()
const {
return isImmTy(ImmTyIndexKey8bit); }
388 bool isIndexKey16bit()
const {
return isImmTy(ImmTyIndexKey16bit); }
389 bool isIndexKey32bit()
const {
return isImmTy(ImmTyIndexKey32bit); }
390 bool isMatrixAFMT()
const {
return isImmTy(ImmTyMatrixAFMT); }
391 bool isMatrixBFMT()
const {
return isImmTy(ImmTyMatrixBFMT); }
392 bool isMatrixAScale()
const {
return isImmTy(ImmTyMatrixAScale); }
393 bool isMatrixBScale()
const {
return isImmTy(ImmTyMatrixBScale); }
394 bool isMatrixAScaleFmt()
const {
return isImmTy(ImmTyMatrixAScaleFmt); }
395 bool isMatrixBScaleFmt()
const {
return isImmTy(ImmTyMatrixBScaleFmt); }
396 bool isTFE()
const {
return isImmTy(ImmTyTFE); }
397 bool isFormat()
const {
return isImmTy(ImmTyFormat) &&
isUInt<7>(
getImm()); }
398 bool isFormatOp()
const {
401 bool isDppFI()
const {
return isImmTy(ImmTyDppFI); }
402 bool isSDWADstSel()
const {
return isImmTy(ImmTySDWADstSel); }
403 bool isSDWASrc0Sel()
const {
return isImmTy(ImmTySDWASrc0Sel); }
404 bool isSDWASrc1Sel()
const {
return isImmTy(ImmTySDWASrc1Sel); }
405 bool isSDWADstUnused()
const {
return isImmTy(ImmTySDWADstUnused); }
406 bool isInterpSlot()
const {
return isImmTy(ImmTyInterpSlot); }
407 bool isInterpAttr()
const {
return isImmTy(ImmTyInterpAttr); }
408 bool isInterpAttrChan()
const {
return isImmTy(ImmTyInterpAttrChan); }
409 bool isOpSel()
const {
return isImmTy(ImmTyOpSel); }
410 bool isOpSelHi()
const {
return isImmTy(ImmTyOpSelHi); }
411 bool isNegLo()
const {
return isImmTy(ImmTyNegLo); }
412 bool isNegHi()
const {
return isImmTy(ImmTyNegHi); }
414 bool isRegOrImm()
const {
return isReg() || isImm(); }
416 bool isRegClass(
unsigned RCID)
const;
419 bool isRegClassTarget(
unsigned TargetRCIdx)
const;
423 bool isRegOrInlineNoMods(
unsigned RCID, MVT type)
const {
424 return isRegOrInline(RCID, type) && !hasModifiers();
427 bool isRegOrInlineNoModsTarget(
unsigned TargetRCIdx, MVT type)
const {
428 return isRegOrInlineTarget(TargetRCIdx, type) && !hasModifiers();
431 bool isSCSrcB16()
const {
432 return isRegOrInlineNoMods(AMDGPU::SReg_32RegClassID, MVT::i16);
435 bool isSCSrc_b32()
const {
436 return isRegOrInlineNoMods(AMDGPU::SReg_32RegClassID, MVT::i32);
439 bool isSCSrc_b64()
const {
440 return isRegOrInlineNoMods(AMDGPU::SReg_64RegClassID, MVT::i64);
443 bool isBoolReg()
const;
445 bool isSSrc_b32()
const {
446 return isSCSrc_b32() || isLiteralImm(MVT::i32) || isExpr();
449 bool isSSrc_b16()
const {
return isSCSrcB16() || isLiteralImm(MVT::i16); }
451 bool isSSrc_b64()
const {
454 return isSCSrc_b64() || isLiteralImm(MVT::i64) ||
455 (((
const MCTargetAsmParser *)AsmParser)
456 ->getAvailableFeatures()[AMDGPU::Feature64BitLiterals] &&
460 bool isSSrc_f32()
const {
461 return isSCSrc_b32() || isLiteralImm(MVT::f32) || isExpr();
464 bool isSSrc_bf16()
const {
return isSCSrcB16() || isLiteralImm(MVT::bf16); }
466 bool isSSrc_f16()
const {
return isSCSrcB16() || isLiteralImm(MVT::f16); }
468 bool isSSrc_NoInline_f16()
const {
return isSSrc_f16(); }
470 bool isSSrcOrLds_b32()
const {
471 return isRegOrInlineNoMods(AMDGPU::SRegOrLds_32RegClassID, MVT::i32) ||
472 isLiteralImm(MVT::i32) || isExpr();
475 bool isVCSrc_b32()
const {
476 return isRegOrInlineNoMods(AMDGPU::VS_32RegClassID, MVT::i32);
479 bool isVCSrc_b32_Lo256()
const {
480 return isRegOrInlineNoMods(AMDGPU::VS_32_Lo256RegClassID, MVT::i32);
483 bool isVCSrc_b64_Lo256()
const {
484 return isRegOrInlineNoMods(AMDGPU::VS_64_Lo256RegClassID, MVT::i64);
487 bool isVCSrc_b64()
const {
488 return isRegOrInlineNoModsTarget(AMDGPU::VS_64_AlignTarget, MVT::i64);
491 bool isVCSrcT_b16()
const {
492 return isRegOrInlineNoMods(AMDGPU::VS_16RegClassID, MVT::i16);
495 bool isVCSrcTB16_Lo128()
const {
496 return isRegOrInlineNoMods(AMDGPU::VS_16_Lo128RegClassID, MVT::i16);
499 bool isVCSrcFake16B16_Lo128()
const {
500 return isRegOrInlineNoMods(AMDGPU::VS_32_Lo128RegClassID, MVT::i16);
503 bool isVCSrc_b16()
const {
504 return isRegOrInlineNoMods(AMDGPU::VS_32RegClassID, MVT::i16);
507 bool isVCSrc_v2b16()
const {
return isVCSrc_b16(); }
509 bool isVCSrc_f32()
const {
510 return isRegOrInlineNoMods(AMDGPU::VS_32RegClassID, MVT::f32);
513 bool isVCSrc_f64()
const {
514 return isRegOrInlineNoModsTarget(AMDGPU::VS_64_AlignTarget, MVT::f64);
517 bool isVCSrcTBF16()
const {
518 return isRegOrInlineNoMods(AMDGPU::VS_16RegClassID, MVT::bf16);
521 bool isVCSrcT_f16()
const {
522 return isRegOrInlineNoMods(AMDGPU::VS_16RegClassID, MVT::f16);
525 bool isVCSrcT_bf16()
const {
526 return isRegOrInlineNoMods(AMDGPU::VS_16RegClassID, MVT::f16);
529 bool isVCSrcTF16_LO16()
const {
530 return isRegOrInlineNoMods(AMDGPU::VS_16_LO16RegClassID, MVT::f16);
533 bool isVCSrcTBF16_Lo128()
const {
534 return isRegOrInlineNoMods(AMDGPU::VS_16_Lo128RegClassID, MVT::bf16);
537 bool isVCSrcTF16_Lo128()
const {
538 return isRegOrInlineNoMods(AMDGPU::VS_16_Lo128RegClassID, MVT::f16);
541 bool isVCSrcFake16BF16_Lo128()
const {
542 return isRegOrInlineNoMods(AMDGPU::VS_32_Lo128RegClassID, MVT::bf16);
545 bool isVCSrcFake16F16_Lo128()
const {
546 return isRegOrInlineNoMods(AMDGPU::VS_32_Lo128RegClassID, MVT::f16);
549 bool isVCSrc_bf16()
const {
550 return isRegOrInlineNoMods(AMDGPU::VS_32RegClassID, MVT::bf16);
553 bool isVCSrc_f16()
const {
554 return isRegOrInlineNoMods(AMDGPU::VS_32RegClassID, MVT::f16);
557 bool isVCSrc_v2bf16()
const {
return isVCSrc_bf16(); }
559 bool isVCSrc_v2f16()
const {
return isVCSrc_f16(); }
561 bool isVSrc_b32()
const {
562 return isVCSrc_f32() || isLiteralImm(MVT::i32) || isExpr();
565 bool isVSrc_b64()
const {
return isVCSrc_f64() || isLiteralImm(MVT::i64); }
567 bool isVSrc_v2b64()
const {
568 return isRegOrInlineNoModsTarget(AMDGPU::VS_128_AlignTarget, MVT::i64) ||
569 isLiteralImm(MVT::i64);
572 bool isVSrc_v2f64()
const {
573 return isRegOrInlineNoModsTarget(AMDGPU::VS_128_AlignTarget, MVT::f64) ||
574 isLiteralImm(MVT::f64);
577 bool isVSrcT_b16()
const {
return isVCSrcT_b16() || isLiteralImm(MVT::i16); }
579 bool isVSrcT_b16_Lo128()
const {
580 return isVCSrcTB16_Lo128() || isLiteralImm(MVT::i16);
583 bool isVSrcFake16_b16_Lo128()
const {
584 return isVCSrcFake16B16_Lo128() || isLiteralImm(MVT::i16);
587 bool isVSrc_b16()
const {
return isVCSrc_b16() || isLiteralImm(MVT::i16); }
589 bool isVSrc_v2b16()
const {
return isVSrc_b16() || isLiteralImm(MVT::v2i16); }
591 bool isVSrc_v2f32()
const {
return isVSrc_f64() || isLiteralImm(MVT::v2f32); }
593 bool isVCSrc_v2b32()
const {
return isVCSrc_b64(); }
595 bool isVSrc_v2b32()
const {
return isVSrc_b64() || isLiteralImm(MVT::v2i32); }
597 bool isVSrc_f32()
const {
598 return isVCSrc_f32() || isLiteralImm(MVT::f32) || isExpr();
601 bool isVSrc_f64()
const {
602 return isRegOrInlineNoModsTarget(AMDGPU::VS_64_AlignTarget, MVT::f64) ||
603 isLiteralImm(MVT::f64);
606 bool isVSrcT_bf16()
const {
607 return isVCSrcTBF16() || isLiteralImm(MVT::bf16);
610 bool isVSrcT_f16()
const {
return isVCSrcT_f16() || isLiteralImm(MVT::f16); }
612 bool isVSrcT_f16_LO16()
const {
613 return isVCSrcTF16_LO16() || isLiteralImm(MVT::f16);
616 bool isVSrcT_bf16_Lo128()
const {
617 return isVCSrcTBF16_Lo128() || isLiteralImm(MVT::bf16);
620 bool isVSrcT_f16_Lo128()
const {
621 return isVCSrcTF16_Lo128() || isLiteralImm(MVT::f16);
624 bool isVSrcFake16_bf16_Lo128()
const {
625 return isVCSrcFake16BF16_Lo128() || isLiteralImm(MVT::bf16);
628 bool isVSrcFake16_f16_Lo128()
const {
629 return isVCSrcFake16F16_Lo128() || isLiteralImm(MVT::f16);
632 bool isVSrc_bf16()
const {
return isVCSrc_bf16() || isLiteralImm(MVT::bf16); }
634 bool isVSrc_f16()
const {
return isVCSrc_f16() || isLiteralImm(MVT::f16); }
636 bool isVSrc_v2bf16()
const {
637 return isVSrc_bf16() || isLiteralImm(MVT::v2bf16);
640 bool isVSrc_v2f16()
const {
return isVSrc_f16() || isLiteralImm(MVT::v2f16); }
642 bool isVSrc_v2f16_splat()
const {
return isVSrc_v2f16(); }
644 bool isVSrc_NoInline_v2f16()
const {
return isVSrc_v2f16(); }
646 bool isVISrc_64_bf16()
const {
647 return isRegOrInlineNoModsTarget(AMDGPU::VReg_64_AlignTarget, MVT::bf16);
650 bool isVISrc_64_f16()
const {
651 return isRegOrInlineNoModsTarget(AMDGPU::VReg_64_AlignTarget, MVT::f16);
654 bool isVISrc_64_b32()
const {
655 return isRegOrInlineNoModsTarget(AMDGPU::VReg_64_AlignTarget, MVT::i32);
658 bool isVISrc_64_f64()
const {
659 return isRegOrInlineNoModsTarget(AMDGPU::VReg_64_AlignTarget, MVT::f64);
662 bool isVISrc_256_b32()
const {
663 return isRegOrInlineNoModsTarget(AMDGPU::VReg_256_AlignTarget, MVT::i32);
666 bool isVISrc_256_f32()
const {
667 return isRegOrInlineNoModsTarget(AMDGPU::VReg_256_AlignTarget, MVT::f32);
670 bool isVISrc_256_f64()
const {
671 return isRegOrInlineNoModsTarget(AMDGPU::VReg_256_AlignTarget, MVT::f64);
674 bool isVISrc_512_f64()
const {
675 return isRegOrInlineNoModsTarget(AMDGPU::VReg_512_AlignTarget, MVT::f64);
678 bool isVISrc_128_b32()
const {
679 return isRegOrInlineNoModsTarget(AMDGPU::VReg_128_AlignTarget, MVT::i32);
682 bool isVISrc_128_f32()
const {
683 return isRegOrInlineNoModsTarget(AMDGPU::VReg_128_AlignTarget, MVT::f32);
686 bool isVISrc_512_b32()
const {
687 return isRegOrInlineNoModsTarget(AMDGPU::VReg_512_AlignTarget, MVT::i32);
690 bool isVISrc_512_f32()
const {
691 return isRegOrInlineNoModsTarget(AMDGPU::VReg_512_AlignTarget, MVT::f32);
694 bool isVISrc_1024_b32()
const {
695 return isRegOrInlineNoModsTarget(AMDGPU::VReg_1024_AlignTarget, MVT::i32);
698 bool isVISrc_1024_f32()
const {
699 return isRegOrInlineNoModsTarget(AMDGPU::VReg_1024_AlignTarget, MVT::f32);
702 bool isAISrc_64_f64()
const {
703 return isRegOrInlineNoModsTarget(AMDGPU::AReg_64_AlignTarget, MVT::f64);
706 bool isAISrc_128_b32()
const {
707 return isRegOrInlineNoModsTarget(AMDGPU::AReg_128_AlignTarget, MVT::i32);
710 bool isAISrc_128_f32()
const {
711 return isRegOrInlineNoModsTarget(AMDGPU::AReg_128_AlignTarget, MVT::f32);
714 bool isVISrc_128_bf16()
const {
715 return isRegOrInlineNoModsTarget(AMDGPU::VReg_128_AlignTarget, MVT::bf16);
718 bool isVISrc_128_f16()
const {
719 return isRegOrInlineNoModsTarget(AMDGPU::VReg_128_AlignTarget, MVT::f16);
722 bool isAISrc_256_f64()
const {
723 return isRegOrInlineNoModsTarget(AMDGPU::AReg_256_AlignTarget, MVT::f64);
726 bool isAISrc_512_b32()
const {
727 return isRegOrInlineNoModsTarget(AMDGPU::AReg_512_AlignTarget, MVT::i32);
730 bool isAISrc_512_f32()
const {
731 return isRegOrInlineNoModsTarget(AMDGPU::AReg_512_AlignTarget, MVT::f32);
734 bool isAISrc_1024_b32()
const {
735 return isRegOrInlineNoModsTarget(AMDGPU::AReg_1024_AlignTarget, MVT::i32);
738 bool isAISrc_1024_f32()
const {
739 return isRegOrInlineNoModsTarget(AMDGPU::AReg_1024_AlignTarget, MVT::f32);
742 bool isKImmFP32()
const {
return isLiteralImm(MVT::f32); }
744 bool isKImmFP16()
const {
return isLiteralImm(MVT::f16); }
746 bool isKImmFP64()
const {
return isLiteralImm(MVT::f64); }
748 bool isMem()
const override {
return false; }
750 bool isExpr()
const {
return Kind == Expression; }
752 bool isSOPPBrTarget()
const {
return isExpr() || isImm(); }
754 bool isSMEMOffsetPCRel()
const {
return isExpr() || isImm(); }
756 bool isSWaitCnt()
const;
757 bool isDepCtr()
const;
758 bool isSDelayALU()
const;
759 bool isHwreg()
const;
760 bool isSendMsg()
const;
761 bool isWaitEvent()
const;
762 bool isSplitBarrier()
const;
763 bool isSwizzle()
const;
764 bool isSMRDOffset8()
const;
765 bool isSMEMOffset()
const;
766 bool isSMRDLiteralOffset()
const;
768 bool isDPPCtrl()
const;
770 bool isGPRIdxMode()
const;
771 bool isS16Imm()
const;
772 bool isU16Imm()
const;
773 bool isEndpgm()
const;
775 auto getPredicate(std::function<
bool(
const AMDGPUOperand &
Op)>
P)
const {
776 return [
this,
P]() {
return P(*
this); };
781 return StringRef(Tok.Data, Tok.Length);
789 ImmTy getImmTy()
const {
794 MCRegister
getReg()
const override {
799 SMLoc getStartLoc()
const override {
return StartLoc; }
801 SMLoc getEndLoc()
const override {
return EndLoc; }
803 int getMCOpIdx()
const {
return MCOpIdx; }
805 Modifiers getModifiers()
const {
806 assert(isRegKind() || isImmTy(ImmTyNone));
807 return isRegKind() ?
Reg.Mods :
Imm.Mods;
810 void setModifiers(Modifiers Mods) {
811 assert(isRegKind() || isImmTy(ImmTyNone));
818 bool hasModifiers()
const {
return getModifiers().hasModifiers(); }
820 bool hasFPModifiers()
const {
return getModifiers().hasFPModifiers(); }
822 bool hasIntModifiers()
const {
return getModifiers().hasIntModifiers(); }
824 bool isForcedLit()
const {
825 return isImmLiteral() && getModifiers().isForcedLit();
828 bool isForcedLit64()
const {
829 return isImmLiteral() && getModifiers().isForcedLit64();
834 void addImmOperands(MCInst &Inst,
unsigned N,
835 bool ApplyModifiers =
true)
const;
837 void addLiteralImmOperand(MCInst &Inst, int64_t Val,
838 bool ApplyModifiers)
const;
840 void addRegOperands(MCInst &Inst,
unsigned N)
const;
842 void addRegOrImmOperands(MCInst &Inst,
unsigned N)
const {
844 addRegOperands(Inst,
N);
846 addImmOperands(Inst,
N);
849 void addRegOrImmWithInputModsOperands(MCInst &Inst,
unsigned N)
const {
850 Modifiers Mods = getModifiers();
853 addRegOperands(Inst,
N);
855 addImmOperands(Inst,
N,
false);
859 void addRegOrImmWithFPInputModsOperands(MCInst &Inst,
unsigned N)
const {
860 assert(!hasIntModifiers());
861 addRegOrImmWithInputModsOperands(Inst,
N);
864 void addRegWithInputModsOperands(MCInst &Inst,
unsigned N)
const {
865 Modifiers Mods = getModifiers();
868 addRegOperands(Inst,
N);
871 void addRegWithFPInputModsOperands(MCInst &Inst,
unsigned N)
const {
872 assert(!hasIntModifiers());
873 addRegWithInputModsOperands(Inst,
N);
876 static void printImmTy(raw_ostream &OS, ImmTy
Type) {
879 case ImmTyNone: OS <<
"None";
break;
880 case ImmTyGDS: OS <<
"GDS";
break;
881 case ImmTyLDS: OS <<
"LDS";
break;
882 case ImmTyOffen: OS <<
"Offen";
break;
883 case ImmTyIdxen: OS <<
"Idxen";
break;
884 case ImmTyAddr64: OS <<
"Addr64";
break;
885 case ImmTyOffset: OS <<
"Offset";
break;
886 case ImmTyInstOffset: OS <<
"InstOffset";
break;
887 case ImmTyOffset0: OS <<
"Offset0";
break;
888 case ImmTyOffset1: OS <<
"Offset1";
break;
889 case ImmTySMEMOffsetMod: OS <<
"SMEMOffsetMod";
break;
890 case ImmTyCPol: OS <<
"CPol";
break;
891 case ImmTyIndexKey8bit: OS <<
"index_key";
break;
892 case ImmTyIndexKey16bit: OS <<
"index_key";
break;
893 case ImmTyIndexKey32bit: OS <<
"index_key";
break;
894 case ImmTyTFE: OS <<
"TFE";
break;
895 case ImmTyIsAsync: OS <<
"IsAsync";
break;
896 case ImmTyD16: OS <<
"D16";
break;
897 case ImmTyFormat: OS <<
"Format";
break;
898 case ImmTyFormatOp: OS <<
"FormatOp";
break;
899 case ImmTyClamp: OS <<
"Clamp";
break;
900 case ImmTyOModSI: OS <<
"OModSI";
break;
901 case ImmTyDPP8: OS <<
"DPP8";
break;
902 case ImmTyDppCtrl: OS <<
"DppCtrl";
break;
903 case ImmTyDppRowMask: OS <<
"DppRowMask";
break;
904 case ImmTyDppBankMask: OS <<
"DppBankMask";
break;
905 case ImmTyDppBoundCtrl: OS <<
"DppBoundCtrl";
break;
906 case ImmTyDppFI: OS <<
"DppFI";
break;
907 case ImmTySDWADstSel: OS <<
"SDWADstSel";
break;
908 case ImmTySDWASrc0Sel: OS <<
"SDWASrc0Sel";
break;
909 case ImmTySDWASrc1Sel: OS <<
"SDWASrc1Sel";
break;
910 case ImmTySDWADstUnused: OS <<
"SDWADstUnused";
break;
911 case ImmTyDMask: OS <<
"DMask";
break;
912 case ImmTyDim: OS <<
"Dim";
break;
913 case ImmTyUNorm: OS <<
"UNorm";
break;
914 case ImmTyDA: OS <<
"DA";
break;
915 case ImmTyR128A16: OS <<
"R128A16";
break;
916 case ImmTyA16: OS <<
"A16";
break;
917 case ImmTyLWE: OS <<
"LWE";
break;
918 case ImmTyOff: OS <<
"Off";
break;
919 case ImmTyExpTgt: OS <<
"ExpTgt";
break;
920 case ImmTyExpCompr: OS <<
"ExpCompr";
break;
921 case ImmTyExpVM: OS <<
"ExpVM";
break;
922 case ImmTyDone: OS <<
"Done";
break;
923 case ImmTyRowEn: OS <<
"RowEn";
break;
924 case ImmTyHwreg: OS <<
"Hwreg";
break;
925 case ImmTySendMsg: OS <<
"SendMsg";
break;
926 case ImmTyWaitEvent: OS <<
"WaitEvent";
break;
927 case ImmTyInterpSlot: OS <<
"InterpSlot";
break;
928 case ImmTyInterpAttr: OS <<
"InterpAttr";
break;
929 case ImmTyInterpAttrChan: OS <<
"InterpAttrChan";
break;
930 case ImmTyOpSel: OS <<
"OpSel";
break;
931 case ImmTyOpSelHi: OS <<
"OpSelHi";
break;
932 case ImmTyNegLo: OS <<
"NegLo";
break;
933 case ImmTyNegHi: OS <<
"NegHi";
break;
934 case ImmTySwizzle: OS <<
"Swizzle";
break;
935 case ImmTyGprIdxMode: OS <<
"GprIdxMode";
break;
936 case ImmTyHigh: OS <<
"High";
break;
937 case ImmTyBLGP: OS <<
"BLGP";
break;
938 case ImmTyCBSZ: OS <<
"CBSZ";
break;
939 case ImmTyABID: OS <<
"ABID";
break;
940 case ImmTyEndpgm: OS <<
"Endpgm";
break;
941 case ImmTyWaitVDST: OS <<
"WaitVDST";
break;
942 case ImmTyWaitEXP: OS <<
"WaitEXP";
break;
943 case ImmTyWaitVAVDst: OS <<
"WaitVAVDst";
break;
944 case ImmTyWaitVMVSrc: OS <<
"WaitVMVSrc";
break;
945 case ImmTyBitOp3: OS <<
"BitOp3";
break;
946 case ImmTyMatrixAFMT: OS <<
"ImmTyMatrixAFMT";
break;
947 case ImmTyMatrixBFMT: OS <<
"ImmTyMatrixBFMT";
break;
948 case ImmTyMatrixAScale: OS <<
"ImmTyMatrixAScale";
break;
949 case ImmTyMatrixBScale: OS <<
"ImmTyMatrixBScale";
break;
950 case ImmTyMatrixAScaleFmt: OS <<
"ImmTyMatrixAScaleFmt";
break;
951 case ImmTyMatrixBScaleFmt: OS <<
"ImmTyMatrixBScaleFmt";
break;
952 case ImmTyMatrixAReuse: OS <<
"ImmTyMatrixAReuse";
break;
953 case ImmTyMatrixBReuse: OS <<
"ImmTyMatrixBReuse";
break;
954 case ImmTyScaleSel: OS <<
"ScaleSel" ;
break;
955 case ImmTyByteSel: OS <<
"ByteSel" ;
break;
960 void print(raw_ostream &OS,
const MCAsmInfo &MAI)
const override {
964 <<
" mods: " <<
Reg.Mods <<
'>';
968 if (getImmTy() != ImmTyNone) {
970 printImmTy(OS, getImmTy());
972 OS <<
" mods: " <<
Imm.Mods <<
'>';
985 static AMDGPUOperand::Ptr CreateImm(
const AMDGPUAsmParser *AsmParser,
986 int64_t Val, SMLoc Loc,
987 ImmTy
Type = ImmTyNone,
988 bool IsFPImm =
false) {
989 auto Op = std::make_unique<AMDGPUOperand>(Immediate, AsmParser);
991 Op->Imm.IsFPImm = IsFPImm;
993 Op->Imm.Mods = Modifiers();
999 static AMDGPUOperand::Ptr CreateToken(
const AMDGPUAsmParser *AsmParser,
1000 StringRef Str, SMLoc Loc,
1001 bool HasExplicitEncodingSize =
true) {
1002 auto Res = std::make_unique<AMDGPUOperand>(Token, AsmParser);
1003 Res->Tok.Data = Str.data();
1004 Res->Tok.Length = Str.size();
1005 Res->StartLoc = Loc;
1010 static AMDGPUOperand::Ptr CreateReg(
const AMDGPUAsmParser *AsmParser,
1011 MCRegister
Reg, SMLoc S, SMLoc
E) {
1012 auto Op = std::make_unique<AMDGPUOperand>(Register, AsmParser);
1013 Op->Reg.RegNo =
Reg;
1014 Op->Reg.Mods = Modifiers();
1020 static AMDGPUOperand::Ptr CreateExpr(
const AMDGPUAsmParser *AsmParser,
1021 const class MCExpr *Expr, SMLoc S) {
1022 auto Op = std::make_unique<AMDGPUOperand>(Expression, AsmParser);
1031 OS <<
"abs:" << Mods.Abs <<
" neg: " << Mods.Neg <<
" sext:" << Mods.Sext;
1040#define GET_REGISTER_MATCHER
1041#include "AMDGPUGenAsmMatcher.inc"
1042#undef GET_REGISTER_MATCHER
1043#undef GET_SUBTARGET_FEATURE_NAME
1048class KernelScopeInfo {
1049 int SgprIndexUnusedMin = -1;
1050 int VgprIndexUnusedMin = -1;
1051 int AgprIndexUnusedMin = -1;
1055 void usesSgprAt(
int i) {
1056 if (i >= SgprIndexUnusedMin) {
1057 SgprIndexUnusedMin = ++i;
1060 Ctx->getOrCreateSymbol(
Twine(
".kernel.sgpr_count"));
1066 void usesVgprAt(
int i) {
1067 if (i >= VgprIndexUnusedMin) {
1068 VgprIndexUnusedMin = ++i;
1071 Ctx->getOrCreateSymbol(
Twine(
".kernel.vgpr_count"));
1074 VgprIndexUnusedMin);
1080 void usesAgprAt(
int i) {
1085 if (i >= AgprIndexUnusedMin) {
1086 AgprIndexUnusedMin = ++i;
1089 Ctx->getOrCreateSymbol(
Twine(
".kernel.agpr_count"));
1094 Ctx->getOrCreateSymbol(
Twine(
".kernel.vgpr_count"));
1097 VgprIndexUnusedMin);
1104 KernelScopeInfo() =
default;
1108 MSTI = Ctx->getSubtargetInfo();
1110 usesSgprAt(SgprIndexUnusedMin = -1);
1111 usesVgprAt(VgprIndexUnusedMin = -1);
1113 usesAgprAt(AgprIndexUnusedMin = -1);
1117 void usesRegister(RegisterKind RegKind,
unsigned DwordRegIndex,
1118 unsigned RegWidth) {
1121 usesSgprAt(DwordRegIndex +
divideCeil(RegWidth, 32) - 1);
1124 usesAgprAt(DwordRegIndex +
divideCeil(RegWidth, 32) - 1);
1127 usesVgprAt(DwordRegIndex +
divideCeil(RegWidth, 32) - 1);
1136 MCAsmParser &Parser;
1138 unsigned ForcedEncodingSize = 0;
1139 bool ForcedDPP =
false;
1140 bool ForcedSDWA =
false;
1141 KernelScopeInfo KernelScope;
1142 const unsigned HwMode;
1144 const AMDGPU::IsaVersion ISA;
1149#define GET_ASSEMBLER_HEADER
1150#include "AMDGPUGenAsmMatcher.inc"
1155 unsigned getRegOperandSize(
const MCInstrDesc &
Desc,
unsigned OpNo)
const {
1157 int16_t RCID = MII.getOpRegClassID(
Desc.operands()[OpNo], HwMode);
1161 std::optional<AMDGPU::InfoSectionData> InfoData;
1170 SmallVector<unsigned> OpcodeStream;
1172 OpcodeStreamSymbols;
1173 SmallPtrSet<const MCSymbol *, 8> AMDHSAKernelSymbols;
1176 void checkKernelPrologues();
1179 void createConstantSymbol(StringRef Id, int64_t Val);
1181 bool ParseAsAbsoluteExpression(uint32_t &Ret);
1182 bool OutOfRangeError(SMRange
Range);
1198 bool calculateGPRBlocks(
const FeatureBitset &Features,
const MCExpr *VCCUsed,
1199 const MCExpr *FlatScrUsed,
bool XNACKUsed,
1200 std::optional<bool> EnableWavefrontSize32,
1201 const MCExpr *NextFreeVGPR, SMRange VGPRRange,
1202 const MCExpr *NextFreeSGPR, SMRange SGPRRange,
1203 const MCExpr *&VGPRBlocks,
const MCExpr *&SGPRBlocks);
1204 bool ParseDirectiveAMDGCNTarget();
1205 bool ParseDirectiveAMDHSACodeObjectVersion();
1206 bool ParseDirectiveAMDHSAKernel();
1207 bool ParseAMDKernelCodeTValue(StringRef ID, AMDGPUMCKernelCodeT &Header);
1208 bool ParseDirectiveAMDKernelCodeT();
1210 bool subtargetHasRegister(
const MCRegisterInfo &
MRI, MCRegister
Reg);
1211 bool ParseDirectiveAMDGPUHsaKernel();
1213 bool ParseDirectiveISAVersion();
1214 bool ParseDirectiveHSAMetadata();
1215 bool ParseDirectivePALMetadataBegin();
1216 bool ParseDirectivePALMetadata();
1217 bool ParseDirectiveAMDGPULDS();
1218 bool ParseDirectiveAMDGPUInfo();
1222 bool ParseToEndDirective(
const char *AssemblerDirectiveBegin,
1223 const char *AssemblerDirectiveEnd,
1224 std::string &CollectString);
1226 bool AddNextRegisterToList(MCRegister &
Reg,
unsigned &RegWidth,
1227 RegisterKind RegKind, MCRegister Reg1,
1228 RegisterKind RegKind1, SMLoc Loc);
1229 bool ParseAMDGPURegister(RegisterKind &RegKind, MCRegister &
Reg,
1230 unsigned &RegNum,
unsigned &RegWidth,
1231 bool RestoreOnFailure =
false);
1232 bool ParseAMDGPURegister(RegisterKind &RegKind, MCRegister &
Reg,
1233 unsigned &RegNum,
unsigned &RegWidth,
1234 SmallVectorImpl<AsmToken> &Tokens);
1235 MCRegister ParseRegularReg(RegisterKind &RegKind,
unsigned &RegNum,
1237 SmallVectorImpl<AsmToken> &Tokens);
1238 MCRegister ParseSpecialReg(RegisterKind &RegKind,
unsigned &RegNum,
1240 SmallVectorImpl<AsmToken> &Tokens);
1241 MCRegister ParseRegList(RegisterKind &RegKind,
unsigned &RegNum,
1243 SmallVectorImpl<AsmToken> &Tokens);
1244 bool ParseRegRange(
unsigned &Num,
unsigned &Width,
unsigned &SubReg);
1245 MCRegister getRegularReg(RegisterKind RegKind,
unsigned RegNum,
1246 unsigned SubReg,
unsigned RegWidth, SMLoc Loc);
1249 bool isRegister(
const AsmToken &Token,
const AsmToken &NextToken)
const;
1250 std::optional<StringRef> getGprCountSymbolName(RegisterKind RegKind);
1251 void initializeGprCountSymbol(RegisterKind RegKind);
1252 bool updateGprCountSymbols(RegisterKind RegKind,
unsigned DwordRegIndex,
1258 OperandMode_Default,
1262 using OptionalImmIndexMap = std::map<AMDGPUOperand::ImmTy, unsigned>;
1264 AMDGPUAsmParser(
const MCSubtargetInfo &STI, MCAsmParser &_Parser,
1265 const MCInstrInfo &MII)
1266 : MCTargetAsmParser(STI, MII), Parser(_Parser),
1267 HwMode(STI.getHwMode(MCSubtargetInfo::HwMode_RegInfo)),
1272 setAvailableFeatures(ComputeAvailableFeatures(getFeatureBits()));
1274 if (ISA.Major >= 6 &&
isHsaAbi(getSTI())) {
1275 createConstantSymbol(
".amdgcn.gfx_generation_number", ISA.Major);
1276 createConstantSymbol(
".amdgcn.gfx_generation_minor", ISA.Minor);
1277 createConstantSymbol(
".amdgcn.gfx_generation_stepping", ISA.Stepping);
1279 createConstantSymbol(
".option.machine_version_major", ISA.Major);
1280 createConstantSymbol(
".option.machine_version_minor", ISA.Minor);
1281 createConstantSymbol(
".option.machine_version_stepping", ISA.Stepping);
1283 if (ISA.Major >= 6 &&
isHsaAbi(getSTI())) {
1284 initializeGprCountSymbol(IS_VGPR);
1285 initializeGprCountSymbol(IS_SGPR);
1290 createConstantSymbol(Symbol, Code);
1292 createConstantSymbol(
"UC_VERSION_W64_BIT", 0x2000);
1293 createConstantSymbol(
"UC_VERSION_W32_BIT", 0x4000);
1294 createConstantSymbol(
"UC_VERSION_MDP_BIT", 0x8000);
1334 bool hasBVHRayTracingInsts()
const {
1335 return getFeatureBits()[AMDGPU::FeatureBVHRayTracingInsts];
1338 bool isWave32()
const {
return getAvailableFeatures()[Feature_isWave32Bit]; }
1340 bool isWave64()
const {
return getAvailableFeatures()[Feature_isWave64Bit]; }
1342 bool hasInv2PiInlineImm()
const {
1343 return getFeatureBits()[AMDGPU::FeatureInv2PiInlineImm];
1346 bool has64BitLiterals()
const {
1347 return getFeatureBits()[AMDGPU::Feature64BitLiterals];
1350 bool hasFlatOffsets()
const {
1351 return getFeatureBits()[AMDGPU::FeatureFlatInstOffsets];
1354 bool hasTrue16Insts()
const {
1355 return getFeatureBits()[AMDGPU::FeatureTrue16BitInsts];
1359 return getFeatureBits()[AMDGPU::FeatureArchitectedFlatScratch];
1362 bool hasSGPR102_SGPR103()
const {
return !
isVI() && !
isGFX9(); }
1364 bool hasSGPR104_SGPR105()
const {
return isGFX10Plus(); }
1366 bool hasIntClamp()
const {
return getFeatureBits()[AMDGPU::FeatureIntClamp]; }
1368 bool hasPartialNSAEncoding()
const {
1369 return getFeatureBits()[AMDGPU::FeaturePartialNSAEncoding];
1372 bool hasGloballyAddressableScratch()
const {
1373 return getFeatureBits()[AMDGPU::FeatureGloballyAddressableScratch];
1376 bool hasScaleOffset()
const {
1377 return getFeatureBits()[AMDGPU::FeatureScaleOffset];
1380 bool hasCacheFillSize()
const {
1381 return getFeatureBits()[AMDGPU::FeatureCacheFillSize];
1394 AMDGPUTargetStreamer &getTargetStreamer() {
1395 MCTargetStreamer &TS = *getParser().getStreamer().getTargetStreamer();
1396 return static_cast<AMDGPUTargetStreamer &
>(TS);
1402 return const_cast<AMDGPUAsmParser *
>(
this)->MCTargetAsmParser::getContext();
1405 const MCRegisterInfo *getMRI()
const {
1409 const MCInstrInfo *getMII()
const {
return &MII; }
1413 int16_t getTargetRegClass(
unsigned TargetRCIdx)
const {
1419 const FeatureBitset &getFeatureBits()
const {
1420 return getSTI().getFeatureBits();
1423 void setForcedEncodingSize(
unsigned Size) { ForcedEncodingSize =
Size; }
1424 void setForcedDPP(
bool ForceDPP_) { ForcedDPP = ForceDPP_; }
1425 void setForcedSDWA(
bool ForceSDWA_) { ForcedSDWA = ForceSDWA_; }
1427 unsigned getForcedEncodingSize()
const {
return ForcedEncodingSize; }
1428 bool isForcedVOP3()
const {
return ForcedEncodingSize == 64; }
1429 bool isForcedDPP()
const {
return ForcedDPP; }
1430 bool isForcedSDWA()
const {
return ForcedSDWA; }
1431 ArrayRef<unsigned> getMatchedVariants()
const;
1432 StringRef getMatchedVariantName()
const;
1434 std::unique_ptr<AMDGPUOperand> parseRegister(
bool RestoreOnFailure =
false);
1435 bool ParseRegister(MCRegister &RegNo, SMLoc &StartLoc, SMLoc &EndLoc,
1436 bool RestoreOnFailure);
1437 bool parseRegister(MCRegister &
Reg, SMLoc &StartLoc, SMLoc &EndLoc)
override;
1438 ParseStatus tryParseRegister(MCRegister &
Reg, SMLoc &StartLoc,
1439 SMLoc &EndLoc)
override;
1440 unsigned checkTargetMatchPredicate(MCInst &Inst)
override;
1441 unsigned validateTargetOperandClass(
const MCParsedAsmOperand &
Op,
1442 unsigned Kind)
override;
1443 bool matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
1446 bool MatchingInlineAsm)
override;
1447 bool ParseDirective(AsmToken DirectiveID)
override;
1448 void doBeforeLabelEmit(MCSymbol *Symbol, SMLoc IDLoc)
override;
1449 void onEndOfFile()
override;
1451 OperandMode
Mode = OperandMode_Default);
1452 StringRef parseMnemonicSuffix(StringRef Name);
1453 bool parseInstruction(ParseInstructionInfo &Info, StringRef Name,
1459 ParseStatus parseIntWithPrefix(
const char *Prefix, int64_t &
Int);
1463 AMDGPUOperand::ImmTy ImmTy = AMDGPUOperand::ImmTyNone,
1464 std::function<
bool(int64_t &)> ConvertResult =
nullptr);
1466 ParseStatus parseOperandArrayWithPrefix(
1468 AMDGPUOperand::ImmTy ImmTy = AMDGPUOperand::ImmTyNone,
1469 bool (*ConvertResult)(int64_t &) =
nullptr);
1473 AMDGPUOperand::ImmTy ImmTy = AMDGPUOperand::ImmTyNone,
1474 bool IgnoreNegative =
false);
1475 unsigned getCPolKind(StringRef Id, StringRef Mnemo,
bool &Disabling)
const;
1480 ParseStatus parseStringWithPrefix(StringRef Prefix, StringRef &
Value,
1484 ArrayRef<const char *> Ids,
1488 ArrayRef<const char *> Ids,
1489 AMDGPUOperand::ImmTy
Type);
1492 bool isOperandModifier(
const AsmToken &Token,
1493 const AsmToken &NextToken)
const;
1494 bool isRegOrOperandModifier(
const AsmToken &Token,
1495 const AsmToken &NextToken)
const;
1496 bool isNamedOperandModifier(
const AsmToken &Token,
1497 const AsmToken &NextToken)
const;
1498 bool isOpcodeModifierWithVal(
const AsmToken &Token,
1499 const AsmToken &NextToken)
const;
1500 bool parseSP3NegModifier();
1507 bool AllowImm =
true);
1509 bool AllowImm =
true);
1515 AMDGPUOperand::ImmTy ImmTy);
1520 AMDGPUOperand::ImmTy
Type);
1524 AMDGPUOperand::ImmTy
Type);
1528 AMDGPUOperand::ImmTy
Type);
1532 ParseStatus parseDfmtNfmt(int64_t &
Format);
1533 ParseStatus parseUfmt(int64_t &
Format);
1534 ParseStatus parseSymbolicSplitFormat(StringRef FormatStr, SMLoc Loc,
1536 ParseStatus parseSymbolicUnifiedFormat(StringRef FormatStr, SMLoc Loc,
1540 ParseStatus parseSymbolicOrNumericFormat(int64_t &
Format);
1541 ParseStatus parseNumericFormat(int64_t &
Format);
1545 ParseStatus tryParseFmt(
const char *Pref, int64_t MaxVal, int64_t &Fmt);
1546 bool matchDfmtNfmt(int64_t &Dfmt, int64_t &Nfmt, StringRef FormatStr,
1551 bool parseCnt(int64_t &IntVal);
1554 bool parseDepCtr(int64_t &IntVal,
unsigned &Mask);
1555 void depCtrError(SMLoc Loc,
int ErrorId, StringRef DepCtrName);
1558 bool parseDelay(int64_t &Delay);
1564 struct OperandInfoTy {
1567 bool IsSymbolic =
false;
1568 bool IsDefined =
false;
1570 constexpr OperandInfoTy(int64_t Val) : Val(Val) {}
1573 struct StructuredOpField : OperandInfoTy {
1577 bool IsDefined =
false;
1579 constexpr StructuredOpField(StringLiteral Id, StringLiteral Desc,
1580 unsigned Width, int64_t
Default)
1581 : OperandInfoTy(
Default), Id(Id), Desc(Desc), Width(Width) {}
1582 virtual ~StructuredOpField() =
default;
1584 bool Error(AMDGPUAsmParser &Parser,
const Twine &Err)
const {
1585 Parser.Error(Loc,
"invalid " + Desc +
": " + Err);
1589 virtual bool validate(AMDGPUAsmParser &Parser)
const {
1591 return Error(Parser,
"not supported on this GPU");
1593 return Error(Parser,
"only " + Twine(Width) +
"-bit values are legal");
1601 bool parseSendMsgBody(OperandInfoTy &
Msg, OperandInfoTy &
Op,
1602 OperandInfoTy &Stream);
1603 bool validateSendMsg(
const OperandInfoTy &
Msg,
const OperandInfoTy &
Op,
1604 const OperandInfoTy &Stream);
1606 ParseStatus parseHwregFunc(OperandInfoTy &HwReg, OperandInfoTy &
Offset,
1607 OperandInfoTy &Width);
1612 static SMLoc getLaterLoc(SMLoc a, SMLoc b);
1619 SMLoc getOperandLoc(std::function<
bool(
const AMDGPUOperand &)>
Test,
1621 SMLoc getImmLoc(AMDGPUOperand::ImmTy
Type,
1625 bool validateInstruction(
const MCInst &Inst, SMLoc IDLoc,
1631 bool validateBF16InlineConst(
const MCInst &Inst,
1634 bool validateConstantBusLimitations(
const MCInst &Inst,
1636 std::optional<unsigned> checkVOPDRegBankConstraints(
const MCInst &Inst,
1639 bool tryVOPD(
const MCInst &Inst);
1640 bool tryVOPD3(
const MCInst &Inst);
1641 bool tryAnotherVOPDEncoding(
const MCInst &Inst);
1643 bool validateIntClampSupported(
const MCInst &Inst);
1644 bool validateMIMGAtomicDMask(
const MCInst &Inst);
1645 bool validateMIMGGatherDMask(
const MCInst &Inst);
1647 bool validateMIMGDataSize(
const MCInst &Inst, SMLoc IDLoc);
1648 bool validateMIMGAddrSize(
const MCInst &Inst, SMLoc IDLoc);
1649 bool validateMIMGD16(
const MCInst &Inst);
1651 bool validateTensorR128(
const MCInst &Inst);
1652 bool validateMIMGMSAA(
const MCInst &Inst);
1653 bool validateOpSel(
const MCInst &Inst);
1654 bool validateTrue16OpSel(
const MCInst &Inst);
1655 bool validateNeg(
const MCInst &Inst, AMDGPU::OpName OpName);
1657 bool validateVccOperand(MCRegister
Reg)
const;
1662 bool validateAGPRLdSt(
const MCInst &Inst)
const;
1663 bool validateVGPRAlign(
const MCInst &Inst)
const;
1667 bool validateDivScale(
const MCInst &Inst);
1672 const unsigned CPol);
1678 bool validateClusterBarrierIsFirst(
const MCInst &Inst,
1681 unsigned getConstantBusLimit(
unsigned Opcode)
const;
1682 bool usesConstantBus(
const MCInst &Inst,
unsigned OpIdx);
1683 bool isInlineConstant(
const MCInst &Inst,
unsigned OpIdx)
const;
1684 MCRegister findImplicitSGPRReadInVOP(
const MCInst &Inst)
const;
1686 bool isSupportedMnemo(StringRef Mnemo,
const FeatureBitset &FBS);
1687 bool isSupportedMnemo(StringRef Mnemo,
const FeatureBitset &FBS,
1688 ArrayRef<unsigned> Variants);
1689 bool checkUnsupportedInstruction(StringRef Name, SMLoc IDLoc);
1691 bool isId(
const StringRef Id)
const;
1692 bool isId(
const AsmToken &Token,
const StringRef Id)
const;
1694 StringRef getId()
const;
1695 bool trySkipId(
const StringRef Id);
1696 bool trySkipId(
const StringRef Pref,
const StringRef Id);
1700 bool parseString(StringRef &Val,
1701 const StringRef ErrMsg =
"expected a string");
1702 bool parseId(StringRef &Val,
const StringRef ErrMsg =
"");
1708 StringRef getTokenStr()
const;
1709 AsmToken peekToken(
bool ShouldSkipSpace =
true);
1711 SMLoc getLoc()
const;
1715 void onBeginOfFile()
override;
1720 void emitTargetDirective();
1721 bool parsePrimaryExpr(
const MCExpr *&Res, SMLoc &EndLoc)
override;
1734 bool parseSwizzleOperand(int64_t &
Op,
const unsigned MinVal,
1735 const unsigned MaxVal,
const Twine &ErrMsg,
1737 bool parseSwizzleOperands(
const unsigned OpNum, int64_t *
Op,
1738 const unsigned MinVal,
const unsigned MaxVal,
1739 const StringRef ErrMsg);
1741 bool parseSwizzleOffset(int64_t &
Imm);
1742 bool parseSwizzleMacro(int64_t &
Imm);
1743 bool parseSwizzleQuadPerm(int64_t &
Imm);
1744 bool parseSwizzleBitmaskPerm(int64_t &
Imm);
1745 bool parseSwizzleBroadcast(int64_t &
Imm);
1746 bool parseSwizzleSwap(int64_t &
Imm);
1747 bool parseSwizzleReverse(int64_t &
Imm);
1748 bool parseSwizzleFFT(int64_t &
Imm);
1749 bool parseSwizzleRotate(int64_t &
Imm);
1752 int64_t parseGPRIdxMacro();
1755 cvtMubufImpl(Inst,
Operands,
false);
1758 cvtMubufImpl(Inst,
Operands,
true);
1764 OptionalImmIndexMap &OptionalIdx);
1773 OptionalImmIndexMap &OptionalIdx);
1775 OptionalImmIndexMap &OptionalIdx);
1779 void cvtOpSelHelper(MCInst &Inst,
unsigned OpSel);
1781 bool parseDimId(
unsigned &Encoding);
1783 bool convertDppBoundCtrl(int64_t &BoundCtrl);
1787 int64_t parseDPPCtrlSel(StringRef Ctrl);
1788 int64_t parseDPPCtrlPerm();
1794 bool IsDPP8 =
false);
1800 AMDGPUOperand::ImmTy
Type);
1808 enum class SDWAInstType :
unsigned {
VOP1 = 0,
VOP2 = 1,
VOPC = 2 };
1811 SDWAInstType BasicInstType,
bool SkipDstVcc =
false,
1812 bool SkipSrcVcc =
false);
1922bool AMDGPUOperand::isInlinableImm(
MVT type)
const {
1932 if (!isImmTy(ImmTyNone)) {
1937 if (getModifiers().
Lit != LitModifier::None)
1947 if (type == MVT::f64 || type == MVT::i64) {
1949 AsmParser->hasInv2PiInlineImm());
1952 APFloat FPLiteral(APFloat::IEEEdouble(), APInt(64,
Imm.Val));
1971 APFloat::rmNearestTiesToEven, &Lost);
1978 uint32_t ImmVal = FPLiteral.bitcastToAPInt().getZExtValue();
1980 AsmParser->hasInv2PiInlineImm());
1985 static_cast<int32_t
>(FPLiteral.bitcastToAPInt().getZExtValue()),
1986 AsmParser->hasInv2PiInlineImm());
1990 if (type == MVT::f64 || type == MVT::i64) {
1992 AsmParser->hasInv2PiInlineImm());
2001 static_cast<int16_t
>(
Literal.getLoBits(16).getSExtValue()), type,
2002 AsmParser->hasInv2PiInlineImm());
2006 static_cast<int32_t
>(
Literal.getLoBits(32).getZExtValue()),
2007 AsmParser->hasInv2PiInlineImm());
2010bool AMDGPUOperand::isLiteralImm(MVT type)
const {
2012 if (!isImmTy(ImmTyNone)) {
2017 (type == MVT::i64 || type == MVT::f64) && AsmParser->has64BitLiterals();
2022 if (type == MVT::f64 && hasFPModifiers()) {
2042 if (type == MVT::f64) {
2047 if (type == MVT::i64) {
2060 MVT ExpectedType = (type == MVT::v2f16) ? MVT::f16
2061 : (type == MVT::v2i16) ? MVT::f32
2062 : (type == MVT::v2f32) ? MVT::f32
2065 APFloat FPLiteral(APFloat::IEEEdouble(), APInt(64,
Imm.Val));
2069bool AMDGPUOperand::isRegClassTarget(
unsigned TargetRCIdx)
const {
2072 int16_t RCID = AsmParser->getTargetRegClass(TargetRCIdx);
2073 return RCID >= 0 && isRegClass(RCID);
2076bool AMDGPUOperand::isRegClass(
unsigned RCID)
const {
2077 return isRegKind() &&
2078 AsmParser->getMRI()->getRegClass(RCID).contains(
getReg());
2081bool AMDGPUOperand::isVRegWithInputMods()
const {
2082 return isRegClass(AMDGPU::VGPR_32RegClassID) ||
2084 (AsmParser->getFeatureBits()[AMDGPU::FeatureDPALU_DPP] &&
2085 isRegClassTarget(AMDGPU::VReg_64_AlignTarget));
2088template <
bool IsFake16>
2089bool AMDGPUOperand::isT16_Lo128VRegWithInputMods()
const {
2090 return isRegClass(IsFake16 ? AMDGPU::VGPR_32_Lo128RegClassID
2091 : AMDGPU::VGPR_16_Lo128RegClassID);
2094template <
bool IsFake16>
bool AMDGPUOperand::isT16VRegWithInputMods()
const {
2095 return isRegClass(IsFake16 ? AMDGPU::VGPR_32RegClassID
2096 : AMDGPU::VGPR_16RegClassID);
2099bool AMDGPUOperand::isT16_LO16VRegWithInputMods()
const {
2100 return isRegClass(AMDGPU::VGPR_16_LO16RegClassID);
2103bool AMDGPUOperand::isSDWAOperand(MVT type)
const {
2104 if (AsmParser->isVI())
2106 if (AsmParser->isGFX9Plus())
2107 return isRegClass(AMDGPU::VS_32RegClassID) || isInlinableImm(type);
2111bool AMDGPUOperand::isSDWAFP16Operand()
const {
2112 return isSDWAOperand(MVT::f16);
2115bool AMDGPUOperand::isSDWAFP32Operand()
const {
2116 return isSDWAOperand(MVT::f32);
2119bool AMDGPUOperand::isSDWAInt16Operand()
const {
2120 return isSDWAOperand(MVT::i16);
2123bool AMDGPUOperand::isSDWAInt32Operand()
const {
2124 return isSDWAOperand(MVT::i32);
2127bool AMDGPUOperand::isBoolReg()
const {
2128 return isReg() && ((AsmParser->isWave64() && isSCSrc_b64()) ||
2129 (AsmParser->isWave32() && isSCSrc_b32()));
2133 unsigned Size)
const {
2134 assert(isImmTy(ImmTyNone) &&
Imm.Mods.hasFPModifiers());
2149void AMDGPUOperand::addImmOperands(MCInst &Inst,
unsigned N,
2150 bool ApplyModifiers)
const {
2160 addLiteralImmOperand(Inst,
Imm.Val,
2161 ApplyModifiers & isImmTy(ImmTyNone) &&
2162 Imm.Mods.hasFPModifiers());
2164 assert(!isImmTy(ImmTyNone) || !hasModifiers());
2169void AMDGPUOperand::addLiteralImmOperand(MCInst &Inst, int64_t Val,
2170 bool ApplyModifiers)
const {
2171 const auto &InstDesc = AsmParser->getMII()->get(Inst.
getOpcode());
2176 if (ApplyModifiers) {
2178 const unsigned Size =
2180 Val = applyInputFPModifiers(Val,
Size);
2184 uint8_t OpTy = InstDesc.operands()[OpNum].OperandType;
2186 bool CanUse64BitLiterals =
2189 MCContext &Ctx = AsmParser->getContext();
2200 if (
Lit == LitModifier::None &&
2202 AsmParser->hasInv2PiInlineImm())) {
2210 bool HasMandatoryLiteral =
2213 if (
Literal.getLoBits(32) != 0 &&
2214 (InstDesc.getSize() != 4 || !AsmParser->has64BitLiterals()) &&
2215 !HasMandatoryLiteral) {
2216 const_cast<AMDGPUAsmParser *
>(AsmParser)->
Warning(
2218 "Can't encode literal as exact 64-bit floating-point operand. "
2219 "Low 32-bits will be set to zero");
2220 Val &= 0xffffffff00000000u;
2226 if (CanUse64BitLiterals &&
Lit == LitModifier::None &&
2232 Lit = LitModifier::Lit64;
2233 }
else if (
Lit == LitModifier::Lit) {
2247 if (CanUse64BitLiterals &&
Lit == LitModifier::None &&
2249 Lit = LitModifier::Lit64;
2256 if (
Lit == LitModifier::None && AsmParser->hasInv2PiInlineImm() &&
2257 Literal == 0x3fc45f306725feed) {
2297 Val = FPLiteral.bitcastToAPInt().getZExtValue();
2302 Lit == LitModifier::None && AsmParser->isGFX11Plus() &&
2304 AsmParser->hasInv2PiInlineImm()))
2305 Val = (Val << 16) | Val;
2312 if (
Lit != LitModifier::None) {
2343 if (
Lit == LitModifier::None &&
2353 if (!AsmParser->has64BitLiterals() ||
Lit == LitModifier::Lit)
2361 if (
Lit == LitModifier::None &&
2369 if (!AsmParser->has64BitLiterals()) {
2370 Val =
static_cast<uint64_t>(Val) << 32;
2377 if (
Lit == LitModifier::Lit ||
2379 Val =
static_cast<uint64_t>(Val) << 32;
2383 if (
Lit == LitModifier::Lit)
2410 if (
Lit != LitModifier::None) {
2418void AMDGPUOperand::addRegOperands(MCInst &Inst,
unsigned N)
const {
2424bool AMDGPUOperand::isInlineValue()
const {
2432void AMDGPUAsmParser::createConstantSymbol(StringRef Id, int64_t Val) {
2443 if (Is == IS_VGPR) {
2448 return AMDGPU::VGPR_32RegClassID;
2450 return AMDGPU::VReg_64RegClassID;
2452 return AMDGPU::VReg_96RegClassID;
2454 return AMDGPU::VReg_128RegClassID;
2456 return AMDGPU::VReg_160RegClassID;
2458 return AMDGPU::VReg_192RegClassID;
2460 return AMDGPU::VReg_224RegClassID;
2462 return AMDGPU::VReg_256RegClassID;
2464 return AMDGPU::VReg_288RegClassID;
2466 return AMDGPU::VReg_320RegClassID;
2468 return AMDGPU::VReg_352RegClassID;
2470 return AMDGPU::VReg_384RegClassID;
2472 return AMDGPU::VReg_512RegClassID;
2474 return AMDGPU::VReg_1024RegClassID;
2476 }
else if (Is == IS_TTMP) {
2481 return AMDGPU::TTMP_32RegClassID;
2483 return AMDGPU::TTMP_64RegClassID;
2485 return AMDGPU::TTMP_128RegClassID;
2487 return AMDGPU::TTMP_256RegClassID;
2489 return AMDGPU::TTMP_512RegClassID;
2491 }
else if (Is == IS_SGPR) {
2496 return AMDGPU::SGPR_32RegClassID;
2498 return AMDGPU::SGPR_64RegClassID;
2500 return AMDGPU::SGPR_96RegClassID;
2502 return AMDGPU::SGPR_128RegClassID;
2504 return AMDGPU::SGPR_160RegClassID;
2506 return AMDGPU::SGPR_192RegClassID;
2508 return AMDGPU::SGPR_224RegClassID;
2510 return AMDGPU::SGPR_256RegClassID;
2512 return AMDGPU::SGPR_288RegClassID;
2514 return AMDGPU::SGPR_320RegClassID;
2516 return AMDGPU::SGPR_352RegClassID;
2518 return AMDGPU::SGPR_384RegClassID;
2520 return AMDGPU::SGPR_512RegClassID;
2522 }
else if (Is == IS_AGPR) {
2527 return AMDGPU::AGPR_32RegClassID;
2529 return AMDGPU::AReg_64RegClassID;
2531 return AMDGPU::AReg_96RegClassID;
2533 return AMDGPU::AReg_128RegClassID;
2535 return AMDGPU::AReg_160RegClassID;
2537 return AMDGPU::AReg_192RegClassID;
2539 return AMDGPU::AReg_224RegClassID;
2541 return AMDGPU::AReg_256RegClassID;
2543 return AMDGPU::AReg_288RegClassID;
2545 return AMDGPU::AReg_320RegClassID;
2547 return AMDGPU::AReg_352RegClassID;
2549 return AMDGPU::AReg_384RegClassID;
2551 return AMDGPU::AReg_512RegClassID;
2553 return AMDGPU::AReg_1024RegClassID;
2561 .
Case(
"exec", AMDGPU::EXEC)
2562 .
Case(
"vcc", AMDGPU::VCC)
2563 .
Case(
"flat_scratch", AMDGPU::FLAT_SCR)
2564 .
Case(
"xnack_mask", AMDGPU::XNACK_MASK)
2565 .
Case(
"shared_base", AMDGPU::SRC_SHARED_BASE)
2566 .
Case(
"src_shared_base", AMDGPU::SRC_SHARED_BASE)
2567 .
Case(
"shared_limit", AMDGPU::SRC_SHARED_LIMIT)
2568 .
Case(
"src_shared_limit", AMDGPU::SRC_SHARED_LIMIT)
2569 .
Case(
"private_base", AMDGPU::SRC_PRIVATE_BASE)
2570 .
Case(
"src_private_base", AMDGPU::SRC_PRIVATE_BASE)
2571 .
Case(
"private_limit", AMDGPU::SRC_PRIVATE_LIMIT)
2572 .
Case(
"src_private_limit", AMDGPU::SRC_PRIVATE_LIMIT)
2573 .
Case(
"src_flat_scratch_base_lo", AMDGPU::SRC_FLAT_SCRATCH_BASE_LO)
2574 .
Case(
"src_flat_scratch_base_hi", AMDGPU::SRC_FLAT_SCRATCH_BASE_HI)
2575 .
Case(
"pops_exiting_wave_id", AMDGPU::SRC_POPS_EXITING_WAVE_ID)
2576 .
Case(
"src_pops_exiting_wave_id", AMDGPU::SRC_POPS_EXITING_WAVE_ID)
2577 .
Case(
"lds_direct", AMDGPU::LDS_DIRECT)
2578 .
Case(
"src_lds_direct", AMDGPU::LDS_DIRECT)
2579 .
Case(
"m0", AMDGPU::M0)
2580 .
Case(
"vccz", AMDGPU::SRC_VCCZ)
2581 .
Case(
"src_vccz", AMDGPU::SRC_VCCZ)
2582 .
Case(
"execz", AMDGPU::SRC_EXECZ)
2583 .
Case(
"src_execz", AMDGPU::SRC_EXECZ)
2584 .
Case(
"scc", AMDGPU::SRC_SCC)
2585 .
Case(
"src_scc", AMDGPU::SRC_SCC)
2586 .
Case(
"tba", AMDGPU::TBA)
2587 .
Case(
"tma", AMDGPU::TMA)
2588 .
Case(
"flat_scratch_lo", AMDGPU::FLAT_SCR_LO)
2589 .
Case(
"flat_scratch_hi", AMDGPU::FLAT_SCR_HI)
2590 .
Case(
"xnack_mask_lo", AMDGPU::XNACK_MASK_LO)
2591 .
Case(
"xnack_mask_hi", AMDGPU::XNACK_MASK_HI)
2592 .
Case(
"vcc_lo", AMDGPU::VCC_LO)
2593 .
Case(
"vcc_hi", AMDGPU::VCC_HI)
2594 .
Case(
"exec_lo", AMDGPU::EXEC_LO)
2595 .
Case(
"exec_hi", AMDGPU::EXEC_HI)
2596 .
Case(
"tma_lo", AMDGPU::TMA_LO)
2597 .
Case(
"tma_hi", AMDGPU::TMA_HI)
2598 .
Case(
"tba_lo", AMDGPU::TBA_LO)
2599 .
Case(
"tba_hi", AMDGPU::TBA_HI)
2600 .
Case(
"pc", AMDGPU::PC_REG)
2601 .
Case(
"null", AMDGPU::SGPR_NULL)
2605bool AMDGPUAsmParser::ParseRegister(MCRegister &RegNo, SMLoc &StartLoc,
2606 SMLoc &EndLoc,
bool RestoreOnFailure) {
2607 auto R = parseRegister();
2611 RegNo =
R->getReg();
2612 StartLoc =
R->getStartLoc();
2613 EndLoc =
R->getEndLoc();
2617bool AMDGPUAsmParser::parseRegister(MCRegister &
Reg, SMLoc &StartLoc,
2619 return ParseRegister(
Reg, StartLoc, EndLoc,
false);
2622ParseStatus AMDGPUAsmParser::tryParseRegister(MCRegister &
Reg, SMLoc &StartLoc,
2624 bool Result = ParseRegister(
Reg, StartLoc, EndLoc,
true);
2625 bool PendingErrors = getParser().hasPendingError();
2626 getParser().clearPendingErrors();
2634bool AMDGPUAsmParser::AddNextRegisterToList(MCRegister &
Reg,
unsigned &RegWidth,
2635 RegisterKind RegKind,
2637 RegisterKind RegKind1, SMLoc Loc) {
2639 if (RegKind == IS_SGPR) {
2640 unsigned RegIdx = (
Reg - AMDGPU::SGPR0) + RegWidth / 32;
2641 if ((RegIdx == 106 && Reg1 == AMDGPU::VCC_LO) ||
2642 (RegIdx == 107 && Reg1 == AMDGPU::VCC_HI)) {
2648 if (RegKind != RegKind1) {
2649 Error(Loc,
"registers in a list must be of the same kind");
2655 if (
Reg == AMDGPU::EXEC_LO && Reg1 == AMDGPU::EXEC_HI) {
2660 if (
Reg == AMDGPU::FLAT_SCR_LO && Reg1 == AMDGPU::FLAT_SCR_HI) {
2661 Reg = AMDGPU::FLAT_SCR;
2665 if (
Reg == AMDGPU::XNACK_MASK_LO && Reg1 == AMDGPU::XNACK_MASK_HI) {
2666 Reg = AMDGPU::XNACK_MASK;
2670 if (
Reg == AMDGPU::VCC_LO && Reg1 == AMDGPU::VCC_HI) {
2675 if (
Reg == AMDGPU::TBA_LO && Reg1 == AMDGPU::TBA_HI) {
2680 if (
Reg == AMDGPU::TMA_LO && Reg1 == AMDGPU::TMA_HI) {
2685 Error(Loc,
"register does not fit in the list");
2691 if (Reg1 !=
Reg + RegWidth / 32) {
2692 Error(Loc,
"registers in a list must have consecutive indices");
2708 {{
"v"}, IS_VGPR}, {{
"s"}, IS_SGPR}, {{
"ttmp"}, IS_TTMP},
2709 {{
"acc"}, IS_AGPR}, {{
"a"}, IS_AGPR},
2713 return Kind == IS_VGPR || Kind == IS_SGPR || Kind == IS_TTMP ||
2719 if (Str.starts_with(
Reg.Name))
2725 return !Str.getAsInteger(10, Num);
2728bool AMDGPUAsmParser::isRegister(
const AsmToken &Token,
2729 const AsmToken &NextToken)
const {
2744 StringRef RegSuffix = Str.substr(
RegName.size());
2745 if (!RegSuffix.
empty()) {
2762bool AMDGPUAsmParser::isRegister() {
2763 return isRegister(
getToken(), peekToken());
2766MCRegister AMDGPUAsmParser::getRegularReg(RegisterKind RegKind,
unsigned RegNum,
2767 unsigned SubReg,
unsigned RegWidth,
2771 unsigned AlignSize = 1;
2772 if (RegKind == IS_SGPR || RegKind == IS_TTMP) {
2778 if (RegNum % AlignSize != 0) {
2779 Error(Loc,
"invalid register alignment");
2780 return MCRegister();
2783 unsigned RegIdx = RegNum / AlignSize;
2786 Error(Loc,
"invalid or unsupported register size");
2787 return MCRegister();
2791 const MCRegisterClass &RC =
TRI->getRegClass(RCID);
2792 if (RegIdx >= RC.
getNumRegs() || (RegKind == IS_VGPR && RegIdx > 255)) {
2793 Error(Loc,
"register index is out of range");
2794 return AMDGPU::NoRegister;
2797 if (RegKind == IS_VGPR && !
isGFX1250Plus() && RegIdx + RegWidth / 32 > 256) {
2798 Error(Loc,
"register index is out of range");
2799 return MCRegister();
2808 Error(Loc,
"invalid subregister");
2814bool AMDGPUAsmParser::ParseRegRange(
unsigned &Num,
unsigned &RegWidth,
2816 int64_t RegLo, RegHi;
2820 SMLoc FirstIdxLoc = getLoc();
2827 SecondIdxLoc = getLoc();
2838 Error(FirstIdxLoc,
"invalid register index");
2843 Error(SecondIdxLoc,
"invalid register index");
2847 if (RegLo > RegHi) {
2848 Error(FirstIdxLoc,
"first register index should not exceed second index");
2852 if (RegHi == RegLo) {
2853 StringRef RegSuffix = getTokenStr();
2854 if (RegSuffix ==
".l") {
2855 SubReg = AMDGPU::lo16;
2857 }
else if (RegSuffix ==
".h") {
2858 SubReg = AMDGPU::hi16;
2863 Num =
static_cast<unsigned>(RegLo);
2864 RegWidth = 32 * ((RegHi - RegLo) + 1);
2869MCRegister AMDGPUAsmParser::ParseSpecialReg(RegisterKind &RegKind,
2872 SmallVectorImpl<AsmToken> &Tokens) {
2878 RegKind = IS_SPECIAL;
2885MCRegister AMDGPUAsmParser::ParseRegularReg(RegisterKind &RegKind,
2888 SmallVectorImpl<AsmToken> &Tokens) {
2890 StringRef
RegName = getTokenStr();
2891 auto Loc = getLoc();
2895 Error(Loc,
"invalid register name");
2896 return MCRegister();
2904 unsigned SubReg = NoSubRegister;
2905 bool IsRange =
false;
2906 if (!RegSuffix.
empty()) {
2908 SubReg = AMDGPU::lo16;
2910 SubReg = AMDGPU::hi16;
2914 Error(Loc,
"invalid register index");
2915 return MCRegister();
2921 if (!ParseRegRange(RegNum, RegWidth, SubReg))
2922 return MCRegister();
2926 MCRegister
Reg = getRegularReg(RegKind, RegNum, SubReg, RegWidth, Loc);
2927 const MCRegisterInfo &
TRI = *
getContext().getRegisterInfo();
2928 if (RegKind == IS_SGPR && IsRange
2929 ? (
TRI.isSubRegister(
Reg, VCC_LO) ||
TRI.isSubRegister(
Reg, VCC_HI))
2930 : (
Reg == VCC_LO ||
Reg == VCC_HI)) {
2931 Error(Loc,
"register index is out of range");
2932 return MCRegister();
2938MCRegister AMDGPUAsmParser::ParseRegList(RegisterKind &RegKind,
2939 unsigned &RegNum,
unsigned &RegWidth,
2940 SmallVectorImpl<AsmToken> &Tokens) {
2942 auto ListLoc = getLoc();
2945 "expected a register or a list of registers")) {
2946 return MCRegister();
2951 auto Loc = getLoc();
2952 if (!ParseAMDGPURegister(RegKind,
Reg, RegNum, RegWidth))
2953 return MCRegister();
2954 if (RegWidth != 32) {
2955 Error(Loc,
"expected a single 32-bit register");
2956 return MCRegister();
2960 RegisterKind NextRegKind;
2962 unsigned NextRegNum, NextRegWidth;
2965 if (!ParseAMDGPURegister(NextRegKind, NextReg, NextRegNum, NextRegWidth,
2967 return MCRegister();
2969 if (NextRegWidth != 32) {
2970 Error(Loc,
"expected a single 32-bit register");
2971 return MCRegister();
2973 if (!AddNextRegisterToList(
Reg, RegWidth, RegKind, NextReg, NextRegKind,
2975 return MCRegister();
2979 "expected a comma or a closing square bracket")) {
2980 return MCRegister();
2984 Reg = getRegularReg(RegKind, RegNum, NoSubRegister, RegWidth, ListLoc);
2989bool AMDGPUAsmParser::ParseAMDGPURegister(RegisterKind &RegKind,
2990 MCRegister &
Reg,
unsigned &RegNum,
2992 SmallVectorImpl<AsmToken> &Tokens) {
2993 auto Loc = getLoc();
2997 Reg = ParseSpecialReg(RegKind, RegNum, RegWidth, Tokens);
2999 Reg = ParseRegularReg(RegKind, RegNum, RegWidth, Tokens);
3001 Reg = ParseRegList(RegKind, RegNum, RegWidth, Tokens);
3006 assert(Parser.hasPendingError());
3010 if (!subtargetHasRegister(*
TRI,
Reg)) {
3011 if (
Reg == AMDGPU::SGPR_NULL) {
3012 Error(Loc,
"'null' operand is not supported on this GPU");
3015 " register not available on this GPU");
3023bool AMDGPUAsmParser::ParseAMDGPURegister(RegisterKind &RegKind,
3024 MCRegister &
Reg,
unsigned &RegNum,
3026 bool RestoreOnFailure ) {
3030 if (ParseAMDGPURegister(RegKind,
Reg, RegNum, RegWidth, Tokens)) {
3031 if (RestoreOnFailure) {
3032 while (!Tokens.
empty()) {
3041std::optional<StringRef>
3042AMDGPUAsmParser::getGprCountSymbolName(RegisterKind RegKind) {
3045 return StringRef(
".amdgcn.next_free_vgpr");
3047 return StringRef(
".amdgcn.next_free_sgpr");
3049 return std::nullopt;
3053void AMDGPUAsmParser::initializeGprCountSymbol(RegisterKind RegKind) {
3054 auto SymbolName = getGprCountSymbolName(RegKind);
3055 assert(SymbolName &&
"initializing invalid register kind");
3061bool AMDGPUAsmParser::updateGprCountSymbols(RegisterKind RegKind,
3062 unsigned DwordRegIndex,
3063 unsigned RegWidth) {
3068 auto SymbolName = getGprCountSymbolName(RegKind);
3073 int64_t NewMax = DwordRegIndex +
divideCeil(RegWidth, 32) - 1;
3077 return !
Error(getLoc(),
3078 ".amdgcn.next_free_{v,s}gpr symbols must be variable");
3082 ".amdgcn.next_free_{v,s}gpr symbols must be absolute expressions");
3084 if (OldCount <= NewMax)
3090std::unique_ptr<AMDGPUOperand>
3091AMDGPUAsmParser::parseRegister(
bool RestoreOnFailure) {
3093 SMLoc StartLoc = Tok.getLoc();
3094 SMLoc EndLoc = Tok.getEndLoc();
3095 RegisterKind RegKind;
3097 unsigned RegNum, RegWidth;
3099 if (!ParseAMDGPURegister(RegKind,
Reg, RegNum, RegWidth)) {
3103 if (!updateGprCountSymbols(RegKind, RegNum, RegWidth))
3106 KernelScope.usesRegister(RegKind, RegNum, RegWidth);
3107 return AMDGPUOperand::CreateReg(
this,
Reg, StartLoc, EndLoc);
3114 if (isRegister() || isModifier())
3117 if (
Lit == LitModifier::None) {
3118 if (trySkipId(
"lit"))
3119 Lit = LitModifier::Lit;
3120 else if (trySkipId(
"lit64"))
3121 Lit = LitModifier::Lit64;
3123 if (
Lit != LitModifier::None) {
3126 ParseStatus S = parseImm(
Operands, HasSP3AbsModifier,
Lit);
3135 const auto &NextTok = peekToken();
3138 bool Negate =
false;
3146 AMDGPUOperand::Modifiers Mods;
3154 StringRef Num = getTokenStr();
3157 APFloat RealVal(APFloat::IEEEdouble());
3158 auto roundMode = APFloat::rmNearestTiesToEven;
3159 if (
errorToBool(RealVal.convertFromString(Num, roundMode).takeError()))
3162 RealVal.changeSign();
3165 AMDGPUOperand::CreateImm(
this, RealVal.bitcastToAPInt().getZExtValue(),
3166 S, AMDGPUOperand::ImmTyNone,
true));
3167 AMDGPUOperand &
Op =
static_cast<AMDGPUOperand &
>(*
Operands.back());
3168 Op.setModifiers(Mods);
3177 if (HasSP3AbsModifier) {
3186 if (getParser().parsePrimaryExpr(Expr, EndLoc,
nullptr))
3189 if (Parser.parseExpression(Expr))
3193 if (Expr->evaluateAsAbsolute(IntVal)) {
3195 return Error(S,
"literal value out of range");
3196 Operands.push_back(AMDGPUOperand::CreateImm(
this, IntVal, S));
3197 AMDGPUOperand &
Op =
static_cast<AMDGPUOperand &
>(*
Operands.back());
3198 Op.setModifiers(Mods);
3200 if (
Lit != LitModifier::None)
3202 Operands.push_back(AMDGPUOperand::CreateExpr(
this, Expr, S));
3215 if (
auto R = parseRegister()) {
3225 ParseStatus Res = parseReg(
Operands);
3233bool AMDGPUAsmParser::isNamedOperandModifier(
const AsmToken &Token,
3234 const AsmToken &NextToken)
const {
3237 return str ==
"abs" || str ==
"neg" || str ==
"sext";
3242bool AMDGPUAsmParser::isOpcodeModifierWithVal(
const AsmToken &Token,
3243 const AsmToken &NextToken)
const {
3247bool AMDGPUAsmParser::isOperandModifier(
const AsmToken &Token,
3248 const AsmToken &NextToken)
const {
3249 return isNamedOperandModifier(Token, NextToken) || Token.
is(
AsmToken::Pipe);
3252bool AMDGPUAsmParser::isRegOrOperandModifier(
const AsmToken &Token,
3253 const AsmToken &NextToken)
const {
3254 return isRegister(Token, NextToken) || isOperandModifier(Token, NextToken);
3271bool AMDGPUAsmParser::isModifier() {
3274 AsmToken NextToken[2];
3275 peekTokens(NextToken);
3279 bool IsOpcodeModifier = isOpcodeModifierWithVal(Tok, NextToken[0]) &&
3282 return isOperandModifier(Tok, NextToken[0]) ||
3284 isRegOrOperandModifier(NextToken[0], NextToken[1])) ||
3310bool AMDGPUAsmParser::parseSP3NegModifier() {
3312 AsmToken NextToken[2];
3313 peekTokens(NextToken);
3316 (isRegister(NextToken[0], NextToken[1]) ||
3334 return Error(getLoc(),
"invalid syntax, expected 'neg' modifier");
3336 SP3Neg = parseSP3NegModifier();
3339 Neg = trySkipId(
"neg");
3341 return Error(Loc,
"expected register or immediate");
3345 Abs = trySkipId(
"abs");
3350 if (trySkipId(
"lit")) {
3351 Lit = LitModifier::Lit;
3354 }
else if (trySkipId(
"lit64")) {
3355 Lit = LitModifier::Lit64;
3358 if (!has64BitLiterals())
3359 return Error(Loc,
"lit64 is not supported on this GPU");
3365 return Error(Loc,
"expected register or immediate");
3374 return (SP3Neg || Neg || SP3Abs || Abs ||
Lit != LitModifier::None)
3378 if (
Lit != LitModifier::None && !
Operands.back()->isImm())
3379 Error(Loc,
"expected immediate with lit modifier");
3381 if (SP3Abs && !skipToken(
AsmToken::Pipe,
"expected vertical bar"))
3387 if (
Lit != LitModifier::None &&
3391 AMDGPUOperand::Modifiers Mods;
3392 Mods.Abs = Abs || SP3Abs;
3393 Mods.Neg = Neg || SP3Neg;
3396 if (Mods.hasFPModifiers() ||
Lit != LitModifier::None) {
3397 AMDGPUOperand &
Op =
static_cast<AMDGPUOperand &
>(*
Operands.back());
3399 return Error(
Op.getStartLoc(),
"expected an absolute expression");
3400 Op.setModifiers(Mods);
3408 bool Sext = trySkipId(
"sext");
3409 if (Sext && !skipToken(
AsmToken::LParen,
"expected left paren after sext"))
3424 AMDGPUOperand::Modifiers Mods;
3427 if (Mods.hasIntModifiers()) {
3428 AMDGPUOperand &
Op =
static_cast<AMDGPUOperand &
>(*
Operands.back());
3430 return Error(
Op.getStartLoc(),
"expected an absolute expression");
3431 Op.setModifiers(Mods);
3438 return parseRegOrImmWithFPInputMods(
Operands,
false);
3442 return parseRegOrImmWithIntInputMods(
Operands,
false);
3449 if (!trySkipId(
"rsrcidx"))
3455 SMLoc RegLoc = getLoc();
3456 std::unique_ptr<AMDGPUOperand>
Reg = parseRegister();
3464 if (!
Reg->isRsrcReg32())
3465 return Error(RegLoc,
"rsrcidx operand must be a 32-bit SGPR or VGPR");
3475 auto Loc = getLoc();
3476 if (trySkipId(
"off")) {
3478 AMDGPUOperand::CreateImm(
this, 0, Loc, AMDGPUOperand::ImmTyOff,
false));
3485 std::unique_ptr<AMDGPUOperand>
Reg = parseRegister();
3494unsigned AMDGPUAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
3499 return Match_InvalidOperand;
3501 if (Inst.
getOpcode() == AMDGPU::V_MAC_F32_sdwa_vi ||
3502 Inst.
getOpcode() == AMDGPU::V_MAC_F16_sdwa_vi) {
3505 AMDGPU::getNamedOperandIdx(Inst.
getOpcode(), AMDGPU::OpName::dst_sel);
3507 if (!
Op.isImm() ||
Op.getImm() != AMDGPU::SDWA::SdwaSel::DWORD) {
3508 return Match_InvalidOperand;
3516 if (tryAnotherVOPDEncoding(Inst))
3517 return Match_InvalidOperand;
3519 return Match_Success;
3523 static const unsigned Variants[] = {
3532ArrayRef<unsigned> AMDGPUAsmParser::getMatchedVariants()
const {
3533 if (isForcedDPP() && isForcedVOP3()) {
3537 if (getForcedEncodingSize() == 32) {
3542 if (isForcedVOP3()) {
3547 if (isForcedSDWA()) {
3553 if (isForcedDPP()) {
3561StringRef AMDGPUAsmParser::getMatchedVariantName()
const {
3562 if (isForcedDPP() && isForcedVOP3())
3565 if (getForcedEncodingSize() == 32)
3581AMDGPUAsmParser::findImplicitSGPRReadInVOP(
const MCInst &Inst)
const {
3585 case AMDGPU::FLAT_SCR:
3587 case AMDGPU::VCC_LO:
3588 case AMDGPU::VCC_HI:
3595 return MCRegister();
3602bool AMDGPUAsmParser::isInlineConstant(
const MCInst &Inst,
3603 unsigned OpIdx)
const {
3611 const MCOperand &MO = Inst.
getOperand(OpIdx);
3661unsigned AMDGPUAsmParser::getConstantBusLimit(
unsigned Opcode)
const {
3667 case AMDGPU::V_LSHLREV_B64_e64:
3668 case AMDGPU::V_LSHLREV_B64_gfx10:
3669 case AMDGPU::V_LSHLREV_B64_e64_gfx11:
3670 case AMDGPU::V_LSHLREV_B64_e32_gfx12:
3671 case AMDGPU::V_LSHLREV_B64_e64_gfx12:
3672 case AMDGPU::V_LSHRREV_B64_e64:
3673 case AMDGPU::V_LSHRREV_B64_gfx10:
3674 case AMDGPU::V_LSHRREV_B64_e64_gfx11:
3675 case AMDGPU::V_LSHRREV_B64_e64_gfx12:
3676 case AMDGPU::V_ASHRREV_I64_e64:
3677 case AMDGPU::V_ASHRREV_I64_gfx10:
3678 case AMDGPU::V_ASHRREV_I64_e64_gfx11:
3679 case AMDGPU::V_ASHRREV_I64_e64_gfx12:
3680 case AMDGPU::V_LSHL_B64_e64:
3681 case AMDGPU::V_LSHR_B64_e64:
3682 case AMDGPU::V_ASHR_I64_e64:
3695 bool AddMandatoryLiterals =
false) {
3698 AddMandatoryLiterals ? getNamedOperandIdx(Opcode, OpName::imm) : -1;
3702 AddMandatoryLiterals ? getNamedOperandIdx(Opcode, OpName::immX) : -1;
3704 return {getNamedOperandIdx(Opcode, OpName::src0X),
3705 getNamedOperandIdx(Opcode, OpName::vsrc1X),
3706 getNamedOperandIdx(Opcode, OpName::vsrc2X),
3707 getNamedOperandIdx(Opcode, OpName::src0Y),
3708 getNamedOperandIdx(Opcode, OpName::vsrc1Y),
3709 getNamedOperandIdx(Opcode, OpName::vsrc2Y),
3714 return {getNamedOperandIdx(Opcode, OpName::src0),
3715 getNamedOperandIdx(Opcode, OpName::src1),
3716 getNamedOperandIdx(Opcode, OpName::src2), ImmIdx};
3719bool AMDGPUAsmParser::usesConstantBus(
const MCInst &Inst,
unsigned OpIdx) {
3720 const MCOperand &MO = Inst.
getOperand(OpIdx);
3722 return !isInlineConstant(Inst, OpIdx);
3729 return isSGPR(PReg,
TRI) && PReg != SGPR_NULL;
3740 const unsigned Opcode = Inst.
getOpcode();
3741 if (Opcode != V_WRITELANE_B32_gfx6_gfx7 && Opcode != V_WRITELANE_B32_vi)
3744 if (!LaneSelOp.
isReg())
3747 return LaneSelReg ==
M0 || LaneSelReg == M0_gfxpre11;
3750bool AMDGPUAsmParser::validateConstantBusLimitations(
3752 const unsigned Opcode = Inst.
getOpcode();
3753 const MCInstrDesc &
Desc = MII.
get(Opcode);
3754 MCRegister LastSGPR;
3755 unsigned ConstantBusUseCount = 0;
3756 unsigned NumLiterals = 0;
3757 unsigned LiteralSize;
3773 SmallDenseSet<MCRegister> SGPRsUsed;
3774 MCRegister SGPRUsed = findImplicitSGPRReadInVOP(Inst);
3776 SGPRsUsed.
insert(SGPRUsed);
3777 ++ConstantBusUseCount;
3782 unsigned ConstantBusLimit = getConstantBusLimit(Opcode);
3784 for (
int OpIdx : OpIndices) {
3788 const MCOperand &MO = Inst.
getOperand(OpIdx);
3789 if (usesConstantBus(Inst, OpIdx)) {
3798 if (SGPRsUsed.
insert(LastSGPR).second) {
3799 ++ConstantBusUseCount;
3819 if (NumLiterals == 0) {
3822 }
else if (LiteralSize !=
Size) {
3828 if (ConstantBusUseCount + NumLiterals > ConstantBusLimit) {
3830 "invalid operand (violates constant bus restrictions)");
3837std::optional<unsigned>
3838AMDGPUAsmParser::checkVOPDRegBankConstraints(
const MCInst &Inst,
bool AsVOPD3) {
3840 const unsigned Opcode = Inst.
getOpcode();
3846 auto getVRegIdx = [&](unsigned,
unsigned OperandIdx) {
3847 const MCOperand &Opr = Inst.
getOperand(OperandIdx);
3856 Opcode == AMDGPU::V_DUAL_MOV_B32_e32_X_MOV_B32_e32_gfx1170 ||
3857 Opcode == AMDGPU::V_DUAL_MOV_B32_e32_X_MOV_B32_e32_gfx12 ||
3858 Opcode == AMDGPU::V_DUAL_MOV_B32_e32_X_MOV_B32_e32_gfx1250 ||
3859 Opcode == AMDGPU::V_DUAL_MOV_B32_e32_X_MOV_B32_e32_gfx13 ||
3860 Opcode == AMDGPU::V_DUAL_MOV_B32_e32_X_MOV_B32_e32_e96_gfx1250 ||
3861 Opcode == AMDGPU::V_DUAL_MOV_B32_e32_X_MOV_B32_e32_e96_gfx13;
3865 for (
auto OpName : {OpName::src0X, OpName::src0Y}) {
3866 int I = getNamedOperandIdx(Opcode, OpName);
3870 int64_t
Imm =
Op.getImm();
3876 for (
auto OpName : {OpName::vsrc1X, OpName::vsrc1Y, OpName::vsrc2X,
3877 OpName::vsrc2Y, OpName::imm}) {
3878 int I = getNamedOperandIdx(Opcode, OpName);
3888 auto InvalidCompOprIdx = InstInfo.getInvalidCompOperandIndex(
3889 getVRegIdx, *
TRI, SkipSrc, AllowSameVGPR, AsVOPD3);
3891 return InvalidCompOprIdx;
3894bool AMDGPUAsmParser::validateVOPD(
const MCInst &Inst,
3901 for (
const std::unique_ptr<MCParsedAsmOperand> &Operand :
Operands) {
3902 AMDGPUOperand &
Op = (AMDGPUOperand &)*Operand;
3903 if ((
Op.isRegKind() ||
Op.isImmTy(AMDGPUOperand::ImmTyNone)) &&
3905 Error(
Op.getStartLoc(),
"ABS not allowed in VOPD3 instructions");
3909 auto InvalidCompOprIdx = checkVOPDRegBankConstraints(Inst, AsVOPD3);
3910 if (!InvalidCompOprIdx.has_value())
3913 auto CompOprIdx = *InvalidCompOprIdx;
3916 std::max(InstInfo[
VOPD::X].getIndexInParsedOperands(CompOprIdx),
3917 InstInfo[
VOPD::Y].getIndexInParsedOperands(CompOprIdx));
3920 auto Loc = ((AMDGPUOperand &)*
Operands[ParsedIdx]).getStartLoc();
3921 if (CompOprIdx == VOPD::Component::DST) {
3923 Error(Loc,
"dst registers must be distinct");
3925 Error(Loc,
"one dst register must be even and the other odd");
3927 auto CompSrcIdx = CompOprIdx - VOPD::Component::DST_NUM;
3928 Error(Loc, Twine(
"src") + Twine(CompSrcIdx) +
3929 " operands must use different VGPR banks");
3937bool AMDGPUAsmParser::tryVOPD3(
const MCInst &Inst) {
3939 auto InvalidCompOprIdx = checkVOPDRegBankConstraints(Inst,
false);
3940 if (!InvalidCompOprIdx.has_value())
3944 InvalidCompOprIdx = checkVOPDRegBankConstraints(Inst,
true);
3945 if (InvalidCompOprIdx.has_value()) {
3950 if (*InvalidCompOprIdx == VOPD::Component::DST)
3963bool AMDGPUAsmParser::tryVOPD(
const MCInst &Inst) {
3964 const unsigned Opcode = Inst.
getOpcode();
3979 for (
auto OpName : {OpName::src0X_modifiers, OpName::src0Y_modifiers,
3980 OpName::vsrc1X_modifiers, OpName::vsrc1Y_modifiers,
3981 OpName::vsrc2X_modifiers, OpName::vsrc2Y_modifiers}) {
3982 int I = getNamedOperandIdx(Opcode, OpName);
3989 return !tryVOPD3(Inst);
3994bool AMDGPUAsmParser::tryAnotherVOPDEncoding(
const MCInst &Inst) {
3999 return tryVOPD(Inst);
4000 return tryVOPD3(Inst);
4003bool AMDGPUAsmParser::validateIntClampSupported(
const MCInst &Inst) {
4008 int ClampIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::clamp);
4016bool AMDGPUAsmParser::validateMIMGDataSize(
const MCInst &Inst, SMLoc IDLoc) {
4024 int VDataIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::vdata);
4025 int DMaskIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::dmask);
4026 int TFEIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::tfe);
4031 if ((DMaskIdx == -1 || TFEIdx == -1) &&
4032 hasBVHRayTracingInsts())
4035 unsigned VDataSize = getRegOperandSize(
Desc, VDataIdx);
4036 unsigned TFESize = (TFEIdx != -1 && Inst.
getOperand(TFEIdx).
getImm()) ? 1 : 0;
4041 bool IsPackedD16 =
false;
4044 int D16Idx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::d16);
4045 IsPackedD16 = D16Idx >= 0;
4047 DataSize = (DataSize + 1) / 2;
4050 if ((VDataSize / 4) == DataSize + TFESize)
4055 Modifiers = IsPackedD16 ?
"dmask and d16" :
"dmask";
4057 Modifiers = IsPackedD16 ?
"dmask, d16 and tfe" :
"dmask and tfe";
4059 Error(IDLoc, Twine(
"image data size does not match ") + Modifiers);
4063bool AMDGPUAsmParser::validateMIMGAddrSize(
const MCInst &Inst, SMLoc IDLoc) {
4072 const AMDGPU::MIMGBaseOpcodeInfo *BaseOpcode =
4074 int VAddr0Idx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::vaddr0);
4075 AMDGPU::OpName RSrcOpName =
4077 int SrsrcIdx = AMDGPU::getNamedOperandIdx(
Opc, RSrcOpName);
4078 int DimIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::dim);
4079 int A16Idx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::a16);
4083 assert(SrsrcIdx > VAddr0Idx);
4086 if (BaseOpcode->
BVH) {
4087 if (IsA16 == BaseOpcode->
A16)
4089 Error(IDLoc,
"image address size does not match a16");
4095 bool IsNSA = SrsrcIdx - VAddr0Idx > 1;
4096 unsigned ActualAddrSize =
4097 IsNSA ? SrsrcIdx - VAddr0Idx : getRegOperandSize(
Desc, VAddr0Idx) / 4;
4099 unsigned ExpectedAddrSize =
4103 if (hasPartialNSAEncoding() &&
4105 int VAddrLastIdx = SrsrcIdx - 1;
4106 unsigned VAddrLastSize = getRegOperandSize(
Desc, VAddrLastIdx) / 4;
4108 ActualAddrSize = VAddrLastIdx - VAddr0Idx + VAddrLastSize;
4111 if (ExpectedAddrSize > 12)
4112 ExpectedAddrSize = 16;
4117 if (ActualAddrSize == 8 && (ExpectedAddrSize >= 5 && ExpectedAddrSize <= 7))
4121 if (ActualAddrSize == ExpectedAddrSize)
4124 Error(IDLoc,
"image address size does not match dim and a16");
4128bool AMDGPUAsmParser::validateMIMGAtomicDMask(
const MCInst &Inst) {
4135 if (!
Desc.mayLoad() || !
Desc.mayStore())
4138 int DMaskIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::dmask);
4145 return DMask == 0x1 || DMask == 0x3 || DMask == 0xf;
4148bool AMDGPUAsmParser::validateMIMGGatherDMask(
const MCInst &Inst) {
4155 int DMaskIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::dmask);
4163 return DMask == 0x1 || DMask == 0x2 || DMask == 0x4 || DMask == 0x8;
4166bool AMDGPUAsmParser::validateMIMGDim(
const MCInst &Inst,
4180 for (
unsigned i = 1, e =
Operands.size(); i != e; ++i) {
4181 AMDGPUOperand &
Op = ((AMDGPUOperand &)*
Operands[i]);
4188bool AMDGPUAsmParser::validateMIMGMSAA(
const MCInst &Inst) {
4195 const AMDGPU::MIMGBaseOpcodeInfo *BaseOpcode =
4198 if (!BaseOpcode->
MSAA)
4201 int DimIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::dim);
4207 return DimInfo->
MSAA;
4212 case AMDGPU::V_MOVRELS_B32_sdwa_gfx10:
4213 case AMDGPU::V_MOVRELSD_B32_sdwa_gfx10:
4214 case AMDGPU::V_MOVRELSD_2_B32_sdwa_gfx10:
4224bool AMDGPUAsmParser::validateMovrels(
const MCInst &Inst,
4232 const int Src0Idx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::src0);
4243 Error(getOperandLoc(
Operands, Src0Idx),
"source operand must be a VGPR");
4247bool AMDGPUAsmParser::validateMAIAccWrite(
const MCInst &Inst,
4252 if (
Opc != AMDGPU::V_ACCVGPR_WRITE_B32_vi)
4255 const int Src0Idx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::src0);
4266 "source operand must be either a VGPR or an inline constant");
4273bool AMDGPUAsmParser::validateMAISrc2(
const MCInst &Inst,
4278 !getFeatureBits()[FeatureMFMAInlineLiteralBug])
4281 const int Src2Idx = getNamedOperandIdx(Opcode, OpName::src2);
4285 if (Inst.
getOperand(Src2Idx).
isImm() && isInlineConstant(Inst, Src2Idx)) {
4287 "inline constants are not allowed for this operand");
4294bool AMDGPUAsmParser::validateMFMA(
const MCInst &Inst,
4302 int BlgpIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::blgp);
4303 if (BlgpIdx != -1) {
4304 if (
const MFMA_F8F6F4_Info *Info = AMDGPU::isMFMA_F8F6F4(
Opc)) {
4305 int CbszIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::cbsz);
4315 int Src0Idx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::src0);
4317 "wrong register tuple size for cbsz value " + Twine(CBSZ));
4322 int Src1Idx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::src1);
4324 "wrong register tuple size for blgp value " + Twine(BLGP));
4332 const int Src2Idx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::src2);
4342 if (Src2Reg == DstReg)
4347 .getSizeInBits() <= 128)
4350 if (
TRI->regsOverlap(Src2Reg, DstReg)) {
4352 "source 2 operand must not partially overlap with dst");
4359bool AMDGPUAsmParser::validateDivScale(
const MCInst &Inst) {
4363 case V_DIV_SCALE_F32_gfx6_gfx7:
4364 case V_DIV_SCALE_F32_vi:
4365 case V_DIV_SCALE_F32_gfx10:
4366 case V_DIV_SCALE_F64_gfx6_gfx7:
4367 case V_DIV_SCALE_F64_vi:
4368 case V_DIV_SCALE_F64_gfx10:
4375 {AMDGPU::OpName::src0_modifiers, AMDGPU::OpName::src2_modifiers,
4376 AMDGPU::OpName::src2_modifiers}) {
4387bool AMDGPUAsmParser::validateMIMGD16(
const MCInst &Inst) {
4394 int D16Idx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::d16);
4403bool AMDGPUAsmParser::validateTensorR128(
const MCInst &Inst) {
4409 int R128Idx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::r128);
4416 case AMDGPU::V_SUBREV_F32_e32:
4417 case AMDGPU::V_SUBREV_F32_e64:
4418 case AMDGPU::V_SUBREV_F32_e32_gfx10:
4419 case AMDGPU::V_SUBREV_F32_e32_gfx6_gfx7:
4420 case AMDGPU::V_SUBREV_F32_e32_vi:
4421 case AMDGPU::V_SUBREV_F32_e64_gfx10:
4422 case AMDGPU::V_SUBREV_F32_e64_gfx6_gfx7:
4423 case AMDGPU::V_SUBREV_F32_e64_vi:
4425 case AMDGPU::V_SUBREV_CO_U32_e32:
4426 case AMDGPU::V_SUBREV_CO_U32_e64:
4427 case AMDGPU::V_SUBREV_I32_e32_gfx6_gfx7:
4428 case AMDGPU::V_SUBREV_I32_e64_gfx6_gfx7:
4430 case AMDGPU::V_SUBBREV_U32_e32:
4431 case AMDGPU::V_SUBBREV_U32_e64:
4432 case AMDGPU::V_SUBBREV_U32_e32_gfx6_gfx7:
4433 case AMDGPU::V_SUBBREV_U32_e32_vi:
4434 case AMDGPU::V_SUBBREV_U32_e64_gfx6_gfx7:
4435 case AMDGPU::V_SUBBREV_U32_e64_vi:
4437 case AMDGPU::V_SUBREV_U32_e32:
4438 case AMDGPU::V_SUBREV_U32_e64:
4439 case AMDGPU::V_SUBREV_U32_e32_gfx9:
4440 case AMDGPU::V_SUBREV_U32_e32_vi:
4441 case AMDGPU::V_SUBREV_U32_e64_gfx9:
4442 case AMDGPU::V_SUBREV_U32_e64_vi:
4444 case AMDGPU::V_SUBREV_F16_e32:
4445 case AMDGPU::V_SUBREV_F16_e64:
4446 case AMDGPU::V_SUBREV_F16_e32_gfx10:
4447 case AMDGPU::V_SUBREV_F16_e32_vi:
4448 case AMDGPU::V_SUBREV_F16_e64_gfx10:
4449 case AMDGPU::V_SUBREV_F16_e64_vi:
4451 case AMDGPU::V_SUBREV_U16_e32:
4452 case AMDGPU::V_SUBREV_U16_e64:
4453 case AMDGPU::V_SUBREV_U16_e32_vi:
4454 case AMDGPU::V_SUBREV_U16_e64_vi:
4456 case AMDGPU::V_SUBREV_CO_U32_e32_gfx9:
4457 case AMDGPU::V_SUBREV_CO_U32_e64_gfx10:
4458 case AMDGPU::V_SUBREV_CO_U32_e64_gfx9:
4460 case AMDGPU::V_SUBBREV_CO_U32_e32_gfx9:
4461 case AMDGPU::V_SUBBREV_CO_U32_e64_gfx9:
4463 case AMDGPU::V_SUBREV_NC_U32_e32_gfx10:
4464 case AMDGPU::V_SUBREV_NC_U32_e64_gfx10:
4466 case AMDGPU::V_SUBREV_CO_CI_U32_e32_gfx10:
4467 case AMDGPU::V_SUBREV_CO_CI_U32_e64_gfx10:
4469 case AMDGPU::V_LSHRREV_B32_e32:
4470 case AMDGPU::V_LSHRREV_B32_e64:
4471 case AMDGPU::V_LSHRREV_B32_e32_gfx6_gfx7:
4472 case AMDGPU::V_LSHRREV_B32_e64_gfx6_gfx7:
4473 case AMDGPU::V_LSHRREV_B32_e32_vi:
4474 case AMDGPU::V_LSHRREV_B32_e64_vi:
4475 case AMDGPU::V_LSHRREV_B32_e32_gfx10:
4476 case AMDGPU::V_LSHRREV_B32_e64_gfx10:
4478 case AMDGPU::V_ASHRREV_I32_e32:
4479 case AMDGPU::V_ASHRREV_I32_e64:
4480 case AMDGPU::V_ASHRREV_I32_e32_gfx10:
4481 case AMDGPU::V_ASHRREV_I32_e32_gfx6_gfx7:
4482 case AMDGPU::V_ASHRREV_I32_e32_vi:
4483 case AMDGPU::V_ASHRREV_I32_e64_gfx10:
4484 case AMDGPU::V_ASHRREV_I32_e64_gfx6_gfx7:
4485 case AMDGPU::V_ASHRREV_I32_e64_vi:
4487 case AMDGPU::V_LSHLREV_B32_e32:
4488 case AMDGPU::V_LSHLREV_B32_e64:
4489 case AMDGPU::V_LSHLREV_B32_e32_gfx10:
4490 case AMDGPU::V_LSHLREV_B32_e32_gfx6_gfx7:
4491 case AMDGPU::V_LSHLREV_B32_e32_vi:
4492 case AMDGPU::V_LSHLREV_B32_e64_gfx10:
4493 case AMDGPU::V_LSHLREV_B32_e64_gfx6_gfx7:
4494 case AMDGPU::V_LSHLREV_B32_e64_vi:
4496 case AMDGPU::V_LSHLREV_B16_e32:
4497 case AMDGPU::V_LSHLREV_B16_e64:
4498 case AMDGPU::V_LSHLREV_B16_e32_vi:
4499 case AMDGPU::V_LSHLREV_B16_e64_vi:
4500 case AMDGPU::V_LSHLREV_B16_gfx10:
4502 case AMDGPU::V_LSHRREV_B16_e32:
4503 case AMDGPU::V_LSHRREV_B16_e64:
4504 case AMDGPU::V_LSHRREV_B16_e32_vi:
4505 case AMDGPU::V_LSHRREV_B16_e64_vi:
4506 case AMDGPU::V_LSHRREV_B16_gfx10:
4508 case AMDGPU::V_ASHRREV_I16_e32:
4509 case AMDGPU::V_ASHRREV_I16_e64:
4510 case AMDGPU::V_ASHRREV_I16_e32_vi:
4511 case AMDGPU::V_ASHRREV_I16_e64_vi:
4512 case AMDGPU::V_ASHRREV_I16_gfx10:
4514 case AMDGPU::V_LSHLREV_B64_e64:
4515 case AMDGPU::V_LSHLREV_B64_gfx10:
4516 case AMDGPU::V_LSHLREV_B64_vi:
4518 case AMDGPU::V_LSHRREV_B64_e64:
4519 case AMDGPU::V_LSHRREV_B64_gfx10:
4520 case AMDGPU::V_LSHRREV_B64_vi:
4522 case AMDGPU::V_ASHRREV_I64_e64:
4523 case AMDGPU::V_ASHRREV_I64_gfx10:
4524 case AMDGPU::V_ASHRREV_I64_vi:
4526 case AMDGPU::V_PK_LSHLREV_B16:
4527 case AMDGPU::V_PK_LSHLREV_B16_gfx10:
4528 case AMDGPU::V_PK_LSHLREV_B16_vi:
4530 case AMDGPU::V_PK_LSHRREV_B16:
4531 case AMDGPU::V_PK_LSHRREV_B16_gfx10:
4532 case AMDGPU::V_PK_LSHRREV_B16_vi:
4533 case AMDGPU::V_PK_ASHRREV_I16:
4534 case AMDGPU::V_PK_ASHRREV_I16_gfx10:
4535 case AMDGPU::V_PK_ASHRREV_I16_vi:
4542bool AMDGPUAsmParser::validateLdsDirect(
const MCInst &Inst,
4544 const unsigned Opcode = Inst.
getOpcode();
4553 for (
auto SrcName : {OpName::src0, OpName::src1, OpName::src2}) {
4554 auto SrcIdx = getNamedOperandIdx(Opcode, SrcName);
4558 if (Src.isReg() && Src.getReg() == LDS_DIRECT) {
4562 "lds_direct is not supported on this GPU");
4568 "lds_direct cannot be used with this instruction");
4572 if (SrcName != OpName::src0) {
4574 "lds_direct may be used as src0 only");
4584 for (
unsigned i = 1, e =
Operands.size(); i != e; ++i) {
4585 AMDGPUOperand &
Op = ((AMDGPUOperand &)*
Operands[i]);
4586 if (
Op.isFlatOffset())
4587 return Op.getStartLoc();
4592bool AMDGPUAsmParser::validateOffset(
const MCInst &Inst,
4595 auto OpNum = AMDGPU::getNamedOperandIdx(Opcode, AMDGPU::OpName::offset);
4600 return validateFlatOffset(Inst,
Operands);
4603 return validateSMEMOffset(Inst,
Operands);
4608 const unsigned OffsetSize = 24;
4609 if (!
isUIntN(OffsetSize - 1,
Op.getImm())) {
4611 Twine(
"expected a ") + Twine(OffsetSize - 1) +
4612 "-bit unsigned offset for buffer ops");
4616 const unsigned OffsetSize = 16;
4617 if (!
isUIntN(OffsetSize,
Op.getImm())) {
4619 Twine(
"expected a ") + Twine(OffsetSize) +
"-bit unsigned offset");
4626bool AMDGPUAsmParser::validateFlatOffset(
const MCInst &Inst,
4632 auto OpNum = AMDGPU::getNamedOperandIdx(Opcode, AMDGPU::OpName::offset);
4636 if (!hasFlatOffsets() &&
Op.getImm() != 0) {
4638 "flat offset modifier is not supported on this GPU");
4645 bool AllowNegative =
4647 if (!
isIntN(OffsetSize,
Op.getImm()) || (!AllowNegative &&
Op.getImm() < 0)) {
4649 Twine(
"expected a ") +
4650 (AllowNegative ? Twine(OffsetSize) +
"-bit signed offset"
4651 : Twine(OffsetSize - 1) +
"-bit unsigned offset"));
4660 for (
unsigned i = 2, e =
Operands.size(); i != e; ++i) {
4661 AMDGPUOperand &
Op = ((AMDGPUOperand &)*
Operands[i]);
4662 if (
Op.isSMEMOffset() ||
Op.isSMEMOffsetMod())
4663 return Op.getStartLoc();
4668bool AMDGPUAsmParser::validateSMEMOffset(
const MCInst &Inst,
4677 auto OpNum = AMDGPU::getNamedOperandIdx(Opcode, AMDGPU::OpName::offset);
4693 ?
"expected a 23-bit unsigned offset for buffer ops"
4694 :
isGFX12Plus() ?
"expected a 24-bit signed offset"
4695 : (
isVI() || IsBuffer) ?
"expected a 20-bit unsigned offset"
4696 :
"expected a 21-bit signed offset");
4702bool AMDGPUAsmParser::validateSMEMSData(
const MCInst &Inst,
4708 AMDGPU::getNamedOperandIdx(Inst.
getOpcode(), AMDGPU::OpName::sdata);
4713 Error(getOperandLoc(
Operands, OpNum),
"expected a 5-bit unsigned immediate");
4722bool AMDGPUAsmParser::validateBF16InlineConst(
const MCInst &Inst,
4724 if (!getFeatureBits()[AMDGPU::FeatureBF16InlineConstFromUpperFP32])
4739 const int Src0Idx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::src0);
4743 const MCOperandInfo &Src0Info =
Desc.operands()[Src0Idx];
4748 if (!
Src0.isImm() ||
4750 hasInv2PiInlineImm()))
4755 AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::src0_modifiers);
4756 if (ModsIdx != -1 &&
4762 "bf16 inline constant is read from the high half of the fp32 inline "
4763 "constant on this GPU; use the e64 encoding with op_sel:[1,0]");
4767bool AMDGPUAsmParser::validateSOPLiteral(
const MCInst &Inst,
4770 const MCInstrDesc &
Desc = MII.
get(Opcode);
4774 const int Src0Idx = AMDGPU::getNamedOperandIdx(Opcode, AMDGPU::OpName::src0);
4775 const int Src1Idx = AMDGPU::getNamedOperandIdx(Opcode, AMDGPU::OpName::src1);
4777 const int OpIndices[] = {Src0Idx, Src1Idx};
4779 unsigned NumExprs = 0;
4780 unsigned NumLiterals = 0;
4783 for (
int OpIdx : OpIndices) {
4787 const MCOperand &MO = Inst.
getOperand(OpIdx);
4791 std::optional<int64_t>
Imm;
4794 }
else if (MO.
isExpr()) {
4803 if (!
Imm.has_value()) {
4805 }
else if (!isInlineConstant(Inst, OpIdx)) {
4809 if (NumLiterals == 0 || LiteralValue !=
Value) {
4817 if (NumLiterals + NumExprs <= 1)
4821 "only one unique literal operand is allowed");
4825bool AMDGPUAsmParser::validateOpSel(
const MCInst &Inst) {
4828 int OpSelIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::op_sel);
4836 int OpSelIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::op_sel);
4837 if (OpSelIdx != -1) {
4841 int OpSelHiIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::op_sel_hi);
4842 if (OpSelHiIdx != -1) {
4851 int OpSelIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::op_sel);
4858 if (getFeatureBits()[AMDGPU::FeatureGFX950Insts] &&
4859 (
Opc == AMDGPU::V_PK_ADD_F32_vi ||
Opc == AMDGPU::V_PK_MUL_F32_vi ||
4860 Opc == AMDGPU::V_PK_FMA_F32_vi)) {
4861 int OpSelIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::op_sel);
4865 if (
Opc == AMDGPU::V_PK_FMA_F32_vi &&
4866 (((OpSel >> 1) & 1) || ((OpSel >> 2) & 1)))
4869 else if ((OpSel & 3) == 2)
4877 int Src0Idx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::src0);
4878 int Src1Idx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::src1);
4879 int OpSelIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::op_sel);
4880 int OpSelHiIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::op_sel_hi);
4889 auto VerifyOneSGPR = [
OpSel, OpSelHi](
unsigned Index) ->
bool {
4891 return ((OpSel & Mask) == 0) && ((OpSelHi &
Mask) == 0);
4901 int Src2Idx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::src2);
4902 if (Src2Idx != -1) {
4913bool AMDGPUAsmParser::validateTrue16OpSel(
const MCInst &Inst) {
4914 if (!hasTrue16Insts())
4916 const MCRegisterInfo *
MRI = getMRI();
4918 int OpSelIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::op_sel);
4924 if (OpSelOpValue == 0)
4926 unsigned OpCount = 0;
4927 for (AMDGPU::OpName OpName : {AMDGPU::OpName::src0, AMDGPU::OpName::src1,
4928 AMDGPU::OpName::src2, AMDGPU::OpName::vdst}) {
4929 int OpIdx = AMDGPU::getNamedOperandIdx(Inst.
getOpcode(), OpName);
4936 bool OpSelOpIsHi = ((OpSelOpValue & (1 << OpCount)) != 0);
4937 if (OpSelOpIsHi != VGPRSuffixIsHi)
4946bool AMDGPUAsmParser::validateNeg(
const MCInst &Inst, AMDGPU::OpName OpName) {
4947 assert(OpName == AMDGPU::OpName::neg_lo || OpName == AMDGPU::OpName::neg_hi);
4959 int NegIdx = AMDGPU::getNamedOperandIdx(
Opc, OpName);
4970 const AMDGPU::OpName SrcMods[3] = {AMDGPU::OpName::src0_modifiers,
4971 AMDGPU::OpName::src1_modifiers,
4972 AMDGPU::OpName::src2_modifiers};
4974 for (
unsigned i = 0; i < 3; ++i) {
4984bool AMDGPUAsmParser::validateDPP(
const MCInst &Inst,
4987 int DppCtrlIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::dpp_ctrl);
4988 if (DppCtrlIdx >= 0) {
4992 getSTI().
hasFeature(AMDGPU::FeatureDPALU_DPP) &&
4996 SMLoc S = getImmLoc(AMDGPUOperand::ImmTyDppCtrl,
Operands);
4997 Error(S,
isGFX12() ?
"DP ALU dpp only supports row_share"
4998 :
"DP ALU dpp only supports row_newbcast");
5003 int Dpp8Idx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::dpp8);
5004 bool IsDPP = DppCtrlIdx >= 0 || Dpp8Idx >= 0;
5008 int Src1Idx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::src1);
5014 "invalid operand for instruction");
5019 "src1 immediate operand invalid for instruction");
5029bool AMDGPUAsmParser::validateVccOperand(MCRegister
Reg)
const {
5030 return (
Reg == AMDGPU::VCC && isWave64()) ||
5031 (
Reg == AMDGPU::VCC_LO && isWave32());
5035bool AMDGPUAsmParser::validateVOPLiteral(
const MCInst &Inst,
5038 const MCInstrDesc &
Desc = MII.
get(Opcode);
5039 bool HasMandatoryLiteral = getNamedOperandIdx(Opcode, OpName::imm) != -1;
5046 std::optional<unsigned> LiteralOpIdx;
5049 for (
int OpIdx : OpIndices) {
5053 const MCOperand &MO = Inst.
getOperand(OpIdx);
5059 std::optional<int64_t>
Imm;
5065 bool IsAnotherLiteral =
false;
5066 bool IsForcedLit = findMCOperand(
Operands, OpIdx).isForcedLit();
5067 bool IsForcedLit64 = findMCOperand(
Operands, OpIdx).isForcedLit64();
5068 if (!
Imm.has_value()) {
5070 IsAnotherLiteral =
true;
5071 }
else if (IsForcedLit || IsForcedLit64 || !isInlineConstant(Inst, OpIdx)) {
5076 HasMandatoryLiteral);
5088 (IsForcedLit64 && !HasMandatoryLiteral)) &&
5089 (!has64BitLiterals() ||
Desc.getSize() != 4)) {
5091 "invalid operand for instruction");
5096 if (!IsForcedFP64 && (IsForcedLit64 || !IsValid32Op) &&
5097 OpIdx != getNamedOperandIdx(Opcode, OpName::src0)) {
5099 "invalid operand for instruction");
5104 if (IsValid32Op && !IsForcedFP64 && !IsForcedLit64) {
5105 Value =
static_cast<uint32_t
>(
5113 if (IsAnotherLiteral && !HasMandatoryLiteral &&
5114 !getFeatureBits()[FeatureVOP3Literal]) {
5116 "literal operands are not supported");
5120 if (LiteralOpIdx && IsAnotherLiteral) {
5122 getOperandLoc(
Operands, *LiteralOpIdx)),
5123 "only one unique literal operand is allowed");
5127 if (IsAnotherLiteral)
5128 LiteralOpIdx = OpIdx;
5137 int OpIdx = AMDGPU::getNamedOperandIdx(Inst.
getOpcode(), Name);
5151bool AMDGPUAsmParser::validateAGPRLdSt(
const MCInst &Inst)
const {
5157 ? AMDGPU::OpName::data0
5158 : AMDGPU::OpName::vdata;
5160 const MCRegisterInfo *
MRI = getMRI();
5166 if (Data2Areg >= 0 && Data2Areg != DataAreg)
5170 auto FB = getFeatureBits();
5171 if (FB[AMDGPU::FeatureGFX90AInsts]) {
5172 if (DataAreg < 0 || DstAreg < 0)
5174 return DstAreg == DataAreg;
5177 return DstAreg < 1 && DataAreg < 1;
5180bool AMDGPUAsmParser::validateVGPRAlign(
const MCInst &Inst)
const {
5181 auto FB = getFeatureBits();
5182 if (!FB[AMDGPU::FeatureRequiresAlignedVGPRs])
5186 const MCRegisterInfo *
MRI = getMRI();
5189 if (FB[AMDGPU::FeatureGFX90AInsts] &&
Opc == AMDGPU::DS_READ_B96_TR_B6_vi)
5192 if (FB[AMDGPU::FeatureGFX1250Insts]) {
5196 case AMDGPU::DS_LOAD_TR6_B96:
5197 case AMDGPU::DS_LOAD_TR6_B96_gfx12:
5201 case AMDGPU::GLOBAL_LOAD_TR6_B96:
5202 case AMDGPU::GLOBAL_LOAD_TR6_B96_gfx1250: {
5206 int VAddrIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::vaddr);
5207 if (VAddrIdx != -1) {
5209 MCRegister
Sub =
MRI->getSubReg(
Op.getReg(), AMDGPU::sub0);
5210 if ((
Sub - AMDGPU::VGPR0) & 1)
5215 case AMDGPU::GLOBAL_LOAD_TR6_B96_SADDR:
5216 case AMDGPU::GLOBAL_LOAD_TR6_B96_SADDR_gfx1250:
5221 const MCRegisterClass &VGPR32 =
MRI->
getRegClass(AMDGPU::VGPR_32RegClassID);
5222 const MCRegisterClass &AGPR32 =
MRI->
getRegClass(AMDGPU::AGPR_32RegClassID);
5228 MCRegister
Sub =
MRI->getSubReg(
Op.getReg(), AMDGPU::sub0);
5242 for (
unsigned i = 1, e =
Operands.size(); i != e; ++i) {
5243 AMDGPUOperand &
Op = ((AMDGPUOperand &)*
Operands[i]);
5245 return Op.getStartLoc();
5250bool AMDGPUAsmParser::validateBLGP(
const MCInst &Inst,
5253 int BlgpIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::blgp);
5256 SMLoc BLGPLoc = getBLGPLoc(
Operands);
5259 bool IsNeg = StringRef(BLGPLoc.
getPointer()).starts_with(
"neg:");
5260 auto FB = getFeatureBits();
5261 bool UsesNeg =
false;
5262 if (FB[AMDGPU::FeatureGFX940Insts]) {
5264 case AMDGPU::V_MFMA_F64_16X16X4F64_gfx940_acd:
5265 case AMDGPU::V_MFMA_F64_16X16X4F64_gfx940_vcd:
5266 case AMDGPU::V_MFMA_F64_4X4X4F64_gfx940_acd:
5267 case AMDGPU::V_MFMA_F64_4X4X4F64_gfx940_vcd:
5272 if (IsNeg == UsesNeg)
5275 Error(BLGPLoc, UsesNeg ?
"invalid modifier: blgp is not supported"
5276 :
"invalid modifier: neg is not supported");
5281bool AMDGPUAsmParser::validateWaitCnt(
const MCInst &Inst,
5287 if (
Opc != AMDGPU::S_WAITCNT_EXPCNT_gfx11 &&
5288 Opc != AMDGPU::S_WAITCNT_LGKMCNT_gfx11 &&
5289 Opc != AMDGPU::S_WAITCNT_VMCNT_gfx11 &&
5290 Opc != AMDGPU::S_WAITCNT_VSCNT_gfx11)
5293 int Src0Idx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::sdst);
5296 if (
Reg == AMDGPU::SGPR_NULL)
5299 Error(getOperandLoc(
Operands, Src0Idx),
"src0 must be null");
5303bool AMDGPUAsmParser::validateDS(
const MCInst &Inst,
5308 return validateGWS(Inst,
Operands);
5313 AMDGPU::getNamedOperandIdx(Inst.
getOpcode(), AMDGPU::OpName::gds);
5318 SMLoc S = getImmLoc(AMDGPUOperand::ImmTyGDS,
Operands);
5319 Error(S,
"gds modifier is not supported on this GPU");
5327bool AMDGPUAsmParser::validateGWS(
const MCInst &Inst,
5329 if (!getFeatureBits()[AMDGPU::FeatureGFX90AInsts])
5333 if (
Opc != AMDGPU::DS_GWS_INIT_vi &&
Opc != AMDGPU::DS_GWS_BARRIER_vi &&
5334 Opc != AMDGPU::DS_GWS_SEMA_BR_vi)
5337 const MCRegisterInfo *
MRI = getMRI();
5338 const MCRegisterClass &VGPR32 =
MRI->
getRegClass(AMDGPU::VGPR_32RegClassID);
5340 AMDGPU::getNamedOperandIdx(Inst.
getOpcode(), AMDGPU::OpName::data0);
5343 auto RegIdx =
Reg - (VGPR32.
contains(
Reg) ? AMDGPU::VGPR0 : AMDGPU::AGPR0);
5345 Error(getOperandLoc(
Operands, Data0Pos),
"vgpr must be even aligned");
5352bool AMDGPUAsmParser::validateCoherencyBits(
const MCInst &Inst,
5356 AMDGPU::getNamedOperandIdx(Inst.
getOpcode(), AMDGPU::OpName::cpol);
5363 if (!hasCacheFillSize()) {
5364 SMLoc S = getImmLoc(AMDGPUOperand::ImmTyCPol,
Operands);
5367 Error(S,
"Cache fill size is not supported on this GPU");
5368 }
else if (!validateCFSBits(Inst,
Operands)) {
5373 if (!hasScaleOffset() && (CPol &
CPol::SCAL)) {
5374 SMLoc S = getImmLoc(AMDGPUOperand::ImmTyCPol,
Operands);
5377 Error(S,
"scale_offset is not supported on this GPU");
5381 SMLoc S = getImmLoc(AMDGPUOperand::ImmTyCPol,
Operands);
5384 Error(S,
"nv is not supported on this GPU");
5388 SMLoc S = getImmLoc(AMDGPUOperand::ImmTyCPol,
Operands);
5391 Error(S,
"scale_offset is not supported for this instruction");
5395 return validateTHAndScopeBits(Inst,
Operands, CPol);
5399 SMLoc S = getImmLoc(AMDGPUOperand::ImmTyCPol,
Operands);
5400 Error(S,
"cache policy is not supported for SMRD instructions");
5404 Error(IDLoc,
"invalid cache policy for SMEM instruction");
5411 SMLoc S = getImmLoc(AMDGPUOperand::ImmTyCPol,
Operands);
5415 "scc modifier is not supported for this instruction on this GPU");
5426 :
"instruction must use glc");
5431 SMLoc S = getImmLoc(AMDGPUOperand::ImmTyCPol,
Operands);
5434 &CStr.data()[CStr.find(
isGFX940() ?
"sc0" :
"glc")]);
5436 :
"instruction must not use glc");
5444bool AMDGPUAsmParser::validateTHAndScopeBits(
const MCInst &Inst,
5446 const unsigned CPol) {
5451 SMLoc S = getImmLoc(AMDGPUOperand::ImmTyCPol,
Operands);
5458 return PrintError(
"th:TH_ATOMIC_RETURN requires a destination operand");
5463 return PrintError(
"instruction must use th:TH_ATOMIC_RETURN");
5471 return PrintError(
"invalid th value for SMEM instruction");
5478 return PrintError(
"scope and th combination is not valid");
5484 return PrintError(
"invalid th value for atomic instructions");
5487 return PrintError(
"invalid th value for store instructions");
5490 return PrintError(
"invalid th value for load instructions");
5496bool AMDGPUAsmParser::validateCFSBits(
const MCInst &Inst,
5498 const unsigned Opcode = Inst.
getOpcode();
5499 const MCInstrDesc &
Desc = MII.
get(Opcode);
5502 SMLoc S = getImmLoc(AMDGPUOperand::ImmTyCPol,
Operands);
5510 return PrintError(
"Cache fill size is only supported for VC operations");
5513bool AMDGPUAsmParser::validateTFE(
const MCInst &Inst,
5517 SMLoc Loc = getImmLoc(AMDGPUOperand::ImmTyTFE,
Operands);
5519 Error(Loc,
"TFE modifier has no meaning for store instructions");
5527bool AMDGPUAsmParser::validateWMMA(
const MCInst &Inst,
5533 int AFmtIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::matrix_a_fmt);
5537 int BFmtIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::matrix_b_fmt);
5540 auto validateFmt = [&](
unsigned Fmt, AMDGPU::OpName SrcOp) ->
bool {
5541 int SrcIdx = AMDGPU::getNamedOperandIdx(
Opc, SrcOp);
5550 "wrong register tuple size for " +
5555 if (!validateFmt(AFmt, AMDGPU::OpName::src0) ||
5556 !validateFmt(BFmt, AMDGPU::OpName::src1))
5560 AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::matrix_a_scale_fmt);
5561 if (AScaleIdx == -1)
5565 AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::matrix_b_scale_fmt);
5569 "invalid matrix and scale format combination");
5576bool AMDGPUAsmParser::validateMonitorSleep(
const MCInst &Inst,
5579 if (
Opc != AMDGPU::S_MONITOR_SLEEP_gfx12 ||
5580 !getSTI().
hasFeature(AMDGPU::FeatureNoSleepForever))
5583 int ImmIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::simm16);
5586 "sleep forever is unsupported on the target");
5593bool AMDGPUAsmParser::validateClusterBarrierIsFirst(
5596 if (
Opc != AMDGPU::S_BARRIER_SIGNAL_ISFIRST_IMM_gfx12 &&
5597 Opc != AMDGPU::S_BARRIER_SIGNAL_ISFIRST_IMM_gfx13)
5600 int Src0Idx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::src0);
5607 "s_barrier_signal_isfirst does not support user_cluster_barrier_id (-3)");
5611bool AMDGPUAsmParser::validateScaleSel(
const MCInst &Inst,
5614 int ScaleSelIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::scale_sel);
5615 if (ScaleSelIdx == -1)
5619 case AMDGPU::V_CVT_SCALE_PK16_F16_FP6_e64_gfx1250:
5620 case AMDGPU::V_CVT_SCALE_PK16_BF16_FP6_e64_gfx1250:
5621 case AMDGPU::V_CVT_SCALE_PK16_F16_BF6_e64_gfx1250:
5622 case AMDGPU::V_CVT_SCALE_PK16_BF16_BF6_e64_gfx1250:
5623 case AMDGPU::V_CVT_SCALE_PK16_F32_FP6_e64_gfx1250:
5624 case AMDGPU::V_CVT_SCALE_PK16_F32_BF6_e64_gfx1250:
5625 case AMDGPU::V_CVT_SCALE_PK8_F16_FP4_e64_gfx1250:
5626 case AMDGPU::V_CVT_SCALE_PK8_BF16_FP4_e64_gfx1250:
5627 case AMDGPU::V_CVT_SCALE_PK8_F32_FP4_e64_gfx1250:
5630 case AMDGPU::V_CVT_SCALE_PK8_F16_FP8_e64_gfx1250:
5631 case AMDGPU::V_CVT_SCALE_PK8_BF16_FP8_e64_gfx1250:
5632 case AMDGPU::V_CVT_SCALE_PK8_F16_BF8_e64_gfx1250:
5633 case AMDGPU::V_CVT_SCALE_PK8_BF16_BF8_e64_gfx1250:
5634 case AMDGPU::V_CVT_SCALE_PK8_F32_FP8_e64_gfx1250:
5635 case AMDGPU::V_CVT_SCALE_PK8_F32_BF8_e64_gfx1250:
5642 if (getSTI().
hasFeature(AMDGPU::FeatureBlock16ConversionScaleInsts))
5646 if (ScaleSel < MaxSel)
5650 "scale_sel maximum supported value is " + Twine(MaxSel - 1));
5654bool AMDGPUAsmParser::validateInstruction(
const MCInst &Inst, SMLoc IDLoc,
5656 if (!validateLdsDirect(Inst,
Operands))
5658 if (!validateTrue16OpSel(Inst)) {
5660 "op_sel operand conflicts with 16-bit operand suffix");
5663 if (!validateSOPLiteral(Inst,
Operands))
5665 if (!validateVOPLiteral(Inst,
Operands)) {
5668 if (!validateConstantBusLimitations(Inst,
Operands)) {
5671 if (!validateVOPD(Inst,
Operands)) {
5674 if (!validateIntClampSupported(Inst)) {
5676 "integer clamping is not supported on this GPU");
5679 if (!validateOpSel(Inst)) {
5681 "invalid op_sel operand");
5684 if (!validateNeg(Inst, AMDGPU::OpName::neg_lo)) {
5686 "invalid neg_lo operand");
5689 if (!validateNeg(Inst, AMDGPU::OpName::neg_hi)) {
5691 "invalid neg_hi operand");
5694 if (!validateDPP(Inst,
Operands)) {
5698 if (!validateMIMGD16(Inst)) {
5700 "d16 modifier is not supported on this GPU");
5703 if (!validateMIMGDim(Inst,
Operands)) {
5704 Error(IDLoc,
"missing dim operand");
5707 if (!validateTensorR128(Inst)) {
5709 "instruction must set modifier r128=0");
5712 if (!validateMIMGMSAA(Inst)) {
5714 "invalid dim; must be MSAA type");
5717 if (!validateMIMGDataSize(Inst, IDLoc)) {
5720 if (!validateMIMGAddrSize(Inst, IDLoc))
5722 if (!validateMIMGAtomicDMask(Inst)) {
5724 "invalid atomic image dmask");
5727 if (!validateMIMGGatherDMask(Inst)) {
5729 "invalid image_gather dmask: only one bit must be set");
5732 if (!validateMovrels(Inst,
Operands)) {
5735 if (!validateOffset(Inst,
Operands)) {
5738 if (!validateSMEMSData(Inst,
Operands))
5740 if (!validateBF16InlineConst(Inst,
Operands)) {
5743 if (!validateMAIAccWrite(Inst,
Operands)) {
5746 if (!validateMAISrc2(Inst,
Operands)) {
5749 if (!validateMFMA(Inst,
Operands)) {
5752 if (!validateCoherencyBits(Inst,
Operands, IDLoc)) {
5756 if (!validateAGPRLdSt(Inst)) {
5759 getFeatureBits()[AMDGPU::FeatureGFX90AInsts]
5760 ?
"invalid register class: data and dst should be all VGPR or AGPR"
5761 :
"invalid register class: agpr loads and stores not supported on "
5765 if (!validateVGPRAlign(Inst)) {
5766 Error(IDLoc,
"invalid register class: vgpr tuples must be 64 bit aligned");
5773 if (!validateBLGP(Inst,
Operands)) {
5777 if (!validateDivScale(Inst)) {
5778 Error(IDLoc,
"ABS not allowed in VOP3B instructions");
5781 if (!validateWaitCnt(Inst,
Operands)) {
5784 if (!validateTFE(Inst,
Operands)) {
5787 if (!validateWMMA(Inst,
Operands)) {
5790 if (!validateMonitorSleep(Inst,
Operands)) {
5793 if (!validateClusterBarrierIsFirst(Inst,
Operands)) {
5796 if (!validateScaleSel(Inst,
Operands)) {
5805 unsigned VariantID = 0);
5809 unsigned VariantID);
5811bool AMDGPUAsmParser::isSupportedMnemo(
StringRef Mnemo,
5816bool AMDGPUAsmParser::isSupportedMnemo(StringRef Mnemo,
5817 const FeatureBitset &FBS,
5818 ArrayRef<unsigned> Variants) {
5819 for (
auto Variant : Variants) {
5827bool AMDGPUAsmParser::checkUnsupportedInstruction(StringRef Mnemo,
5829 FeatureBitset FBS = ComputeAvailableFeatures(getFeatureBits());
5832 if (isSupportedMnemo(Mnemo, FBS, getMatchedVariants()))
5837 getParser().clearPendingErrors();
5841 StringRef VariantName = getMatchedVariantName();
5842 if (!VariantName.
empty() && isSupportedMnemo(Mnemo, FBS)) {
5843 return Error(IDLoc, Twine(VariantName,
5844 " variant of this instruction is not supported"));
5848 if (
isGFX10Plus() && getFeatureBits()[AMDGPU::FeatureWavefrontSize64] &&
5849 !getFeatureBits()[AMDGPU::FeatureWavefrontSize32]) {
5851 FeatureBitset FeaturesWS32 = getFeatureBits();
5852 FeaturesWS32.
flip(AMDGPU::FeatureWavefrontSize64)
5853 .
flip(AMDGPU::FeatureWavefrontSize32);
5854 FeatureBitset AvailableFeaturesWS32 =
5855 ComputeAvailableFeatures(FeaturesWS32);
5857 if (isSupportedMnemo(Mnemo, AvailableFeaturesWS32, getMatchedVariants()))
5858 return Error(IDLoc,
"instruction requires wavesize=32");
5862 if (isSupportedMnemo(Mnemo, FeatureBitset().set())) {
5863 return Error(IDLoc,
"instruction not supported on this GPU (" +
5864 getSTI().
getCPU() +
")" +
": " + Mnemo);
5869 return Error(IDLoc,
"invalid instruction" + Suggestion);
5875 const auto &
Op = ((AMDGPUOperand &)*
Operands[InvalidOprIdx]);
5876 if (
Op.isToken() && InvalidOprIdx > 1) {
5877 const auto &PrevOp = ((AMDGPUOperand &)*
Operands[InvalidOprIdx - 1]);
5878 return PrevOp.isToken() && PrevOp.getToken() ==
"::";
5883bool AMDGPUAsmParser::matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
5887 bool MatchingInlineAsm) {
5890 unsigned Result = Match_Success;
5895 auto atLeastAsSpecific = [](
unsigned New,
unsigned Cur) {
5896 auto rank = [](
unsigned M) {
5897 return M == Match_MnemonicFail ? 1
5898 :
M == Match_InvalidOperand ? 2
5899 :
M == Match_MissingFeature ? 3
5902 return rank(New) >= rank(Cur);
5905 for (
auto Variant : getMatchedVariants()) {
5908 MatchInstructionImpl(
Operands, Inst, EI, MatchingInlineAsm, Variant);
5909 if (R == Match_Success || atLeastAsSpecific(R, Result)) {
5913 if (R == Match_Success)
5917 if (Result == Match_Success) {
5918 if (!validateInstruction(Inst, IDLoc,
Operands)) {
5921 emitTargetDirective();
5922 Out.emitInstruction(Inst, getSTI());
5929 if (checkUnsupportedInstruction(Mnemo, IDLoc)) {
5936 case Match_MissingFeature:
5940 return Error(IDLoc,
"operands are not valid for this GPU or mode");
5942 case Match_InvalidOperand: {
5943 SMLoc ErrorLoc = IDLoc;
5944 if (ErrorInfo != ~0ULL) {
5945 if (ErrorInfo >=
Operands.size()) {
5946 return Error(IDLoc,
"too few operands for instruction");
5948 AMDGPUOperand &ErrorOp = (AMDGPUOperand &)*
Operands[ErrorInfo];
5949 ErrorLoc = ErrorOp.getStartLoc();
5950 if (ErrorLoc == SMLoc())
5954 return Error(ErrorLoc,
"invalid VOPDY instruction");
5956 return Error(ErrorLoc,
"invalid operand for instruction");
5959 case Match_MnemonicFail:
5965bool AMDGPUAsmParser::ParseAsAbsoluteExpression(uint32_t &Ret) {
5970 if (getParser().parseAbsoluteExpression(Tmp)) {
5973 Ret =
static_cast<uint32_t
>(Tmp);
5977bool AMDGPUAsmParser::ParseDirectiveAMDGCNTarget() {
5978 if (!getSTI().getTargetTriple().isAMDGCN())
5979 return TokError(
"directive only supported for amdgcn architecture");
5981 std::string TargetIDDirective;
5982 SMLoc TargetStart = getTok().getLoc();
5983 if (getParser().parseEscapedString(TargetIDDirective))
5986 std::optional<AMDGPU::TargetID> MaybeParsed =
5989 return getParser().Error(TargetStart,
5990 "malformed target id '" + TargetIDDirective +
"'");
5993 const Triple &
TT = getSTI().getTargetTriple();
5999 return getParser().Error(
6000 TargetStart,
"target id '" + TargetIDDirective +
6001 "' specifies a processor that is not valid for "
6003 TT.getArchName() +
"'");
6006 const std::optional<AMDGPU::TargetID> &CurrentTargetID =
6007 getTargetStreamer().getTargetID();
6010 const Triple &STITriple = getSTI().getTargetTriple();
6011 if (!DirectiveTriple.isCompatibleWith(STITriple)) {
6012 return getParser().Error(
6013 TargetStart,
".amdgcn_target " + Twine(ParsedTargetID.
toString()) +
6014 " is incompatible with " +
6015 Twine(CurrentTargetID->toString()));
6019 StringRef DirectiveProcessor =
6022 if (DirectiveISA != ISA) {
6023 return getParser().Error(TargetStart,
6024 ".amdgcn_target directive processor " +
6025 Twine(DirectiveProcessor) +
6026 " does not match the specified processor " +
6027 Twine(getSTI().
getCPU()));
6033 CurrentTargetID->getXnackSetting())) {
6035 ".amdgcn_target directive has conflicting xnack settings");
6039 CurrentTargetID->getSramEccSetting())) {
6041 ".amdgcn_target directive has conflicting sramecc settings");
6047 getTargetStreamer().getTargetID()->setXnackSetting(
6049 getTargetStreamer().getTargetID()->setSramEccSetting(
6055bool AMDGPUAsmParser::OutOfRangeError(SMRange
Range) {
6059bool AMDGPUAsmParser::calculateGPRBlocks(
6060 const FeatureBitset &Features,
const MCExpr *VCCUsed,
6061 const MCExpr *FlatScrUsed,
bool XNACKUsed,
6062 std::optional<bool> EnableWavefrontSize32,
const MCExpr *NextFreeVGPR,
6063 SMRange VGPRRange,
const MCExpr *NextFreeSGPR, SMRange SGPRRange,
6064 const MCExpr *&VGPRBlocks,
const MCExpr *&SGPRBlocks) {
6069 const MCExpr *
NumSGPRs = NextFreeSGPR;
6070 int64_t EvaluatedSGPRs;
6072 if (
ISA.Major >= 10)
6077 if (
NumSGPRs->evaluateAsAbsolute(EvaluatedSGPRs) &&
ISA.Major >= 8 &&
6078 !Features.
test(FeatureSGPRInitBug) &&
6079 static_cast<uint64_t>(EvaluatedSGPRs) > MaxAddressableNumSGPRs)
6080 return OutOfRangeError(SGPRRange);
6082 const MCExpr *ExtraSGPRs =
6086 if (
NumSGPRs->evaluateAsAbsolute(EvaluatedSGPRs) &&
6087 (
ISA.Major <= 7 || Features.
test(FeatureSGPRInitBug)) &&
6088 static_cast<uint64_t>(EvaluatedSGPRs) > MaxAddressableNumSGPRs)
6089 return OutOfRangeError(SGPRRange);
6091 if (Features.
test(FeatureSGPRInitBug))
6098 auto GetNumGPRBlocks = [&Ctx](
const MCExpr *NumGPR,
6099 unsigned Granule) ->
const MCExpr * {
6103 const MCExpr *AlignToGPR =
6105 const MCExpr *DivGPR =
6111 VGPRBlocks = GetNumGPRBlocks(
6120bool AMDGPUAsmParser::ParseDirectiveAMDHSAKernel() {
6121 if (!getSTI().getTargetTriple().isAMDGCN())
6122 return TokError(
"directive only supported for amdgcn architecture");
6125 return TokError(
"directive only supported for amdhsa OS");
6127 StringRef KernelName;
6128 if (getParser().parseIdentifier(KernelName))
6135 AMDGPU::MCKernelDescriptor KD =
6145 const MCExpr *NextFreeVGPR = ZeroExpr;
6147 const MCExpr *NamedBarCnt = ZeroExpr;
6152 const MCExpr *NextFreeSGPR = ZeroExpr;
6155 unsigned ImpliedUserSGPRCount = 0;
6159 std::optional<unsigned> ExplicitUserSGPRCount;
6160 const MCExpr *ReserveVCC = OneExpr;
6161 const MCExpr *ReserveFlatScr = OneExpr;
6162 std::optional<bool> EnableWavefrontSize32;
6169 SMRange IDRange = getTok().getLocRange();
6170 if (!parseId(ID,
"expected .amdhsa_ directive or .end_amdhsa_kernel"))
6173 if (ID ==
".end_amdhsa_kernel")
6176 if (!Seen.
insert(ID).second)
6177 return TokError(
".amdhsa_ directives cannot be repeated");
6179 SMLoc ValStart = getLoc();
6180 const MCExpr *ExprVal;
6181 if (getParser().parseExpression(ExprVal))
6183 SMLoc ValEnd = getLoc();
6184 SMRange ValRange = SMRange(ValStart, ValEnd);
6188 bool EvaluatableExpr;
6189 if ((EvaluatableExpr = ExprVal->evaluateAsAbsolute(IVal))) {
6191 return OutOfRangeError(ValRange);
6195#define PARSE_BITS_ENTRY(FIELD, ENTRY, VALUE, RANGE) \
6196 if (!isUInt<ENTRY##_WIDTH>(Val)) \
6197 return OutOfRangeError(RANGE); \
6198 AMDGPU::MCKernelDescriptor::bits_set(FIELD, VALUE, ENTRY##_SHIFT, ENTRY, \
6203#define EXPR_RESOLVE_OR_ERROR(RESOLVED) \
6205 return Error(IDRange.Start, "directive should have resolvable expression", \
6208 if (ID ==
".amdhsa_group_segment_fixed_size") {
6211 return OutOfRangeError(ValRange);
6213 }
else if (ID ==
".amdhsa_private_segment_fixed_size") {
6216 return OutOfRangeError(ValRange);
6218 }
else if (ID ==
".amdhsa_kernarg_size") {
6220 return OutOfRangeError(ValRange);
6222 }
else if (ID ==
".amdhsa_user_sgpr_count") {
6224 ExplicitUserSGPRCount = Val;
6225 }
else if (ID ==
".amdhsa_user_sgpr_private_segment_buffer") {
6229 "directive is not supported with architected flat scratch",
6232 KERNEL_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_BUFFER,
6235 ImpliedUserSGPRCount += 4;
6236 }
else if (ID ==
".amdhsa_user_sgpr_kernarg_preload_length") {
6239 return Error(IDRange.
Start,
"directive requires gfx90a+", IDRange);
6242 return OutOfRangeError(ValRange);
6246 ImpliedUserSGPRCount += Val;
6247 PreloadLength = Val;
6249 }
else if (ID ==
".amdhsa_user_sgpr_kernarg_preload_offset") {
6252 return Error(IDRange.
Start,
"directive requires gfx90a+", IDRange);
6255 return OutOfRangeError(ValRange);
6259 PreloadOffset = Val;
6260 }
else if (ID ==
".amdhsa_user_sgpr_dispatch_ptr") {
6263 KERNEL_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_PTR, ExprVal,
6266 ImpliedUserSGPRCount += 2;
6267 }
else if (ID ==
".amdhsa_user_sgpr_queue_ptr") {
6270 KERNEL_CODE_PROPERTY_ENABLE_SGPR_QUEUE_PTR, ExprVal,
6273 ImpliedUserSGPRCount += 2;
6274 }
else if (ID ==
".amdhsa_user_sgpr_kernarg_segment_ptr") {
6277 KERNEL_CODE_PROPERTY_ENABLE_SGPR_KERNARG_SEGMENT_PTR,
6280 ImpliedUserSGPRCount += 2;
6281 }
else if (ID ==
".amdhsa_user_sgpr_dispatch_id") {
6284 KERNEL_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_ID, ExprVal,
6287 ImpliedUserSGPRCount += 2;
6288 }
else if (ID ==
".amdhsa_user_sgpr_flat_scratch_init") {
6291 "directive is not supported with architected flat scratch",
6295 KERNEL_CODE_PROPERTY_ENABLE_SGPR_FLAT_SCRATCH_INIT,
6298 ImpliedUserSGPRCount += 2;
6299 }
else if (ID ==
".amdhsa_user_sgpr_private_segment_size") {
6302 KERNEL_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_SIZE,
6305 ImpliedUserSGPRCount += 1;
6306 }
else if (ID ==
".amdhsa_wavefront_size32") {
6309 return Error(IDRange.
Start,
"directive requires gfx10+", IDRange);
6310 EnableWavefrontSize32 = Val;
6312 KERNEL_CODE_PROPERTY_ENABLE_WAVEFRONT_SIZE32, ExprVal,
6314 }
else if (ID ==
".amdhsa_uses_dynamic_stack") {
6316 KERNEL_CODE_PROPERTY_USES_DYNAMIC_STACK, ExprVal,
6318 }
else if (ID ==
".amdhsa_system_sgpr_private_segment_wavefront_offset") {
6321 "directive is not supported with architected flat scratch",
6324 COMPUTE_PGM_RSRC2_ENABLE_PRIVATE_SEGMENT, ExprVal,
6326 }
else if (ID ==
".amdhsa_enable_private_segment") {
6330 "directive is not supported without architected flat scratch",
6333 COMPUTE_PGM_RSRC2_ENABLE_PRIVATE_SEGMENT, ExprVal,
6335 }
else if (ID ==
".amdhsa_system_sgpr_workgroup_id_x") {
6337 COMPUTE_PGM_RSRC2_ENABLE_SGPR_WORKGROUP_ID_X, ExprVal,
6339 }
else if (ID ==
".amdhsa_system_sgpr_workgroup_id_y") {
6341 COMPUTE_PGM_RSRC2_ENABLE_SGPR_WORKGROUP_ID_Y, ExprVal,
6343 }
else if (ID ==
".amdhsa_system_sgpr_workgroup_id_z") {
6345 COMPUTE_PGM_RSRC2_ENABLE_SGPR_WORKGROUP_ID_Z, ExprVal,
6347 }
else if (ID ==
".amdhsa_system_sgpr_workgroup_info") {
6349 COMPUTE_PGM_RSRC2_ENABLE_SGPR_WORKGROUP_INFO, ExprVal,
6351 }
else if (ID ==
".amdhsa_system_vgpr_workitem_id") {
6353 COMPUTE_PGM_RSRC2_ENABLE_VGPR_WORKITEM_ID, ExprVal,
6355 }
else if (ID ==
".amdhsa_next_free_vgpr") {
6356 VGPRRange = ValRange;
6357 NextFreeVGPR = ExprVal;
6358 }
else if (ID ==
".amdhsa_next_free_sgpr") {
6359 SGPRRange = ValRange;
6360 NextFreeSGPR = ExprVal;
6361 }
else if (ID ==
".amdhsa_accum_offset") {
6363 return Error(IDRange.
Start,
"directive requires gfx90a+", IDRange);
6364 AccumOffset = ExprVal;
6365 }
else if (ID ==
".amdhsa_named_barrier_count") {
6367 return Error(IDRange.
Start,
"directive requires gfx1250+", IDRange);
6368 NamedBarCnt = ExprVal;
6369 }
else if (ID ==
".amdhsa_reserve_vcc") {
6371 return OutOfRangeError(ValRange);
6372 ReserveVCC = ExprVal;
6373 }
else if (ID ==
".amdhsa_reserve_flat_scratch") {
6375 return Error(IDRange.
Start,
"directive requires gfx7+", IDRange);
6378 "directive is not supported with architected flat scratch",
6381 return OutOfRangeError(ValRange);
6382 ReserveFlatScr = ExprVal;
6383 }
else if (ID ==
".amdhsa_reserve_xnack_mask") {
6385 return Error(IDRange.
Start,
"directive requires gfx8+", IDRange);
6387 return OutOfRangeError(ValRange);
6388 bool XnackOn = getTargetStreamer().getTargetID()->isXnackOnOrAny();
6389 if (Val != XnackOn) {
6390 return getParser().Error(
6392 ".amdhsa_reserve_xnack_mask does not match target id", IDRange);
6394 }
else if (ID ==
".amdhsa_float_round_mode_32") {
6396 COMPUTE_PGM_RSRC1_FLOAT_ROUND_MODE_32, ExprVal,
6398 }
else if (ID ==
".amdhsa_float_round_mode_16_64") {
6400 COMPUTE_PGM_RSRC1_FLOAT_ROUND_MODE_16_64, ExprVal,
6402 }
else if (ID ==
".amdhsa_float_denorm_mode_32") {
6404 COMPUTE_PGM_RSRC1_FLOAT_DENORM_MODE_32, ExprVal,
6406 }
else if (ID ==
".amdhsa_float_denorm_mode_16_64") {
6408 COMPUTE_PGM_RSRC1_FLOAT_DENORM_MODE_16_64, ExprVal,
6410 }
else if (ID ==
".amdhsa_dx10_clamp") {
6411 if (!getSTI().
hasFeature(AMDGPU::FeatureDX10ClampAndIEEEMode))
6412 return Error(IDRange.
Start,
"directive unsupported on gfx1170+",
6415 COMPUTE_PGM_RSRC1_GFX6_GFX11_ENABLE_DX10_CLAMP, ExprVal,
6417 }
else if (ID ==
".amdhsa_ieee_mode") {
6418 if (!getSTI().
hasFeature(AMDGPU::FeatureDX10ClampAndIEEEMode))
6419 return Error(IDRange.
Start,
"directive unsupported on gfx1170+",
6422 COMPUTE_PGM_RSRC1_GFX6_GFX11_ENABLE_IEEE_MODE, ExprVal,
6424 }
else if (ID ==
".amdhsa_fp16_overflow") {
6426 return Error(IDRange.
Start,
"directive requires gfx9+", IDRange);
6428 COMPUTE_PGM_RSRC1_GFX9_PLUS_FP16_OVFL, ExprVal,
6430 }
else if (ID ==
".amdhsa_tg_split") {
6432 return Error(IDRange.
Start,
"directive requires gfx90a+", IDRange);
6435 }
else if (ID ==
".amdhsa_workgroup_processor_mode") {
6438 "directive unsupported on " + getSTI().
getCPU(), IDRange);
6440 COMPUTE_PGM_RSRC1_GFX10_PLUS_WGP_MODE, ExprVal,
6442 }
else if (ID ==
".amdhsa_memory_ordered") {
6444 return Error(IDRange.
Start,
"directive requires gfx10+", IDRange);
6446 COMPUTE_PGM_RSRC1_GFX10_PLUS_MEM_ORDERED, ExprVal,
6448 }
else if (ID ==
".amdhsa_forward_progress") {
6450 return Error(IDRange.
Start,
"directive requires gfx10+", IDRange);
6452 COMPUTE_PGM_RSRC1_GFX10_PLUS_FWD_PROGRESS, ExprVal,
6454 }
else if (ID ==
".amdhsa_shared_vgpr_count") {
6456 if (
ISA.Major < 10 ||
ISA.Major >= 12)
6457 return Error(IDRange.
Start,
"directive requires gfx10 or gfx11",
6459 SharedVGPRCount = Val;
6461 COMPUTE_PGM_RSRC3_GFX10_GFX11_SHARED_VGPR_COUNT, ExprVal,
6463 }
else if (ID ==
".amdhsa_inst_pref_size") {
6465 return Error(IDRange.
Start,
"directive requires gfx11+", IDRange);
6466 if (
ISA.Major == 11) {
6468 COMPUTE_PGM_RSRC3_GFX11_INST_PREF_SIZE, ExprVal,
6472 COMPUTE_PGM_RSRC3_GFX12_PLUS_INST_PREF_SIZE, ExprVal,
6475 }
else if (ID ==
".amdhsa_exception_fp_ieee_invalid_op") {
6478 COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_INVALID_OPERATION,
6480 }
else if (ID ==
".amdhsa_exception_fp_denorm_src") {
6482 COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_FP_DENORMAL_SOURCE,
6484 }
else if (ID ==
".amdhsa_exception_fp_ieee_div_zero") {
6487 COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_DIVISION_BY_ZERO,
6489 }
else if (ID ==
".amdhsa_exception_fp_ieee_overflow") {
6491 COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_OVERFLOW,
6493 }
else if (ID ==
".amdhsa_exception_fp_ieee_underflow") {
6495 COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_UNDERFLOW,
6497 }
else if (ID ==
".amdhsa_exception_fp_ieee_inexact") {
6499 COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_INEXACT,
6501 }
else if (ID ==
".amdhsa_exception_int_div_zero") {
6503 COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_INT_DIVIDE_BY_ZERO,
6505 }
else if (ID ==
".amdhsa_round_robin_scheduling") {
6507 return Error(IDRange.
Start,
"directive requires gfx12+", IDRange);
6509 COMPUTE_PGM_RSRC1_GFX12_PLUS_ENABLE_WG_RR_EN, ExprVal,
6512 return Error(IDRange.
Start,
"unknown .amdhsa_kernel directive", IDRange);
6515#undef PARSE_BITS_ENTRY
6518 if (!Seen.
contains(
".amdhsa_next_free_vgpr"))
6519 return TokError(
".amdhsa_next_free_vgpr directive is required");
6521 if (!Seen.
contains(
".amdhsa_next_free_sgpr"))
6522 return TokError(
".amdhsa_next_free_sgpr directive is required");
6524 unsigned UserSGPRCount = ExplicitUserSGPRCount.value_or(ImpliedUserSGPRCount);
6526 return TokError(
"too many user SGPRs enabled, found " +
6527 Twine(UserSGPRCount) +
", but only " +
6533 if (PreloadLength) {
6539 const MCExpr *VGPRBlocks;
6540 const MCExpr *SGPRBlocks;
6541 if (calculateGPRBlocks(getFeatureBits(), ReserveVCC, ReserveFlatScr,
6542 getTargetStreamer().getTargetID()->isXnackOnOrAny(),
6543 EnableWavefrontSize32, NextFreeVGPR, VGPRRange,
6544 NextFreeSGPR, SGPRRange, VGPRBlocks, SGPRBlocks))
6547 int64_t EvaluatedVGPRBlocks;
6548 bool VGPRBlocksEvaluatable =
6549 VGPRBlocks->evaluateAsAbsolute(EvaluatedVGPRBlocks);
6550 if (VGPRBlocksEvaluatable &&
6552 static_cast<uint64_t>(EvaluatedVGPRBlocks))) {
6553 return OutOfRangeError(VGPRRange);
6557 COMPUTE_PGM_RSRC1_GRANULATED_WORKITEM_VGPR_COUNT_SHIFT,
6558 COMPUTE_PGM_RSRC1_GRANULATED_WORKITEM_VGPR_COUNT,
getContext());
6560 int64_t EvaluatedSGPRBlocks;
6561 if (SGPRBlocks->evaluateAsAbsolute(EvaluatedSGPRBlocks) &&
6563 static_cast<uint64_t>(EvaluatedSGPRBlocks)))
6564 return OutOfRangeError(SGPRRange);
6567 COMPUTE_PGM_RSRC1_GRANULATED_WAVEFRONT_SGPR_COUNT_SHIFT,
6568 COMPUTE_PGM_RSRC1_GRANULATED_WAVEFRONT_SGPR_COUNT,
getContext());
6570 if (ExplicitUserSGPRCount && ImpliedUserSGPRCount > *ExplicitUserSGPRCount)
6571 return TokError(
"amdgpu_user_sgpr_count smaller than implied by "
6572 "enabled user SGPRs");
6578 COMPUTE_PGM_RSRC2_GFX125_USER_SGPR_COUNT_SHIFT,
6579 COMPUTE_PGM_RSRC2_GFX125_USER_SGPR_COUNT,
getContext());
6584 COMPUTE_PGM_RSRC2_GFX6_GFX120_USER_SGPR_COUNT_SHIFT,
6585 COMPUTE_PGM_RSRC2_GFX6_GFX120_USER_SGPR_COUNT,
getContext());
6590 return TokError(
"Kernarg size should be resolvable");
6592 if (PreloadLength && kernarg_size &&
6593 (PreloadLength * 4 + PreloadOffset * 4 > kernarg_size))
6594 return TokError(
"Kernarg preload length + offset is larger than the "
6595 "kernarg segment size");
6598 if (!Seen.
contains(
".amdhsa_accum_offset"))
6599 return TokError(
".amdhsa_accum_offset directive is required");
6600 int64_t EvaluatedAccum;
6601 bool AccumEvaluatable = AccumOffset->evaluateAsAbsolute(EvaluatedAccum);
6602 uint64_t UEvaluatedAccum = EvaluatedAccum;
6603 if (AccumEvaluatable &&
6604 (UEvaluatedAccum < 4 || UEvaluatedAccum > 256 || (UEvaluatedAccum & 3)))
6605 return TokError(
"accum_offset should be in range [4..256] in "
6608 int64_t EvaluatedNumVGPR;
6609 if (NextFreeVGPR->evaluateAsAbsolute(EvaluatedNumVGPR) &&
6613 return TokError(
"accum_offset exceeds total VGPR allocation");
6619 COMPUTE_PGM_RSRC3_GFX90A_ACCUM_OFFSET_SHIFT,
6620 COMPUTE_PGM_RSRC3_GFX90A_ACCUM_OFFSET,
6626 COMPUTE_PGM_RSRC3_GFX125_NAMED_BAR_CNT_SHIFT,
6627 COMPUTE_PGM_RSRC3_GFX125_NAMED_BAR_CNT,
6630 if (
ISA.Major >= 10 &&
ISA.Major < 12) {
6632 if (SharedVGPRCount && EnableWavefrontSize32 && *EnableWavefrontSize32) {
6633 return TokError(
"shared_vgpr_count directive not valid on "
6634 "wavefront size 32");
6637 if (VGPRBlocksEvaluatable &&
6638 (SharedVGPRCount * 2 +
static_cast<uint64_t>(EvaluatedVGPRBlocks) >
6640 return TokError(
"shared_vgpr_count*2 + "
6641 "compute_pgm_rsrc1.GRANULATED_WORKITEM_VGPR_COUNT cannot "
6646 emitTargetDirective();
6647 getTargetStreamer().EmitAmdhsaKernelDescriptor(getSTI(), KernelName, KD,
6648 NextFreeVGPR, NextFreeSGPR,
6649 ReserveVCC, ReserveFlatScr);
6653bool AMDGPUAsmParser::ParseDirectiveAMDHSACodeObjectVersion() {
6655 if (ParseAsAbsoluteExpression(
Version))
6658 getTargetStreamer().EmitDirectiveAMDHSACodeObjectVersion(
Version);
6659 emitTargetDirective();
6663bool AMDGPUAsmParser::ParseAMDKernelCodeTValue(StringRef ID,
6664 AMDGPUMCKernelCodeT &
C) {
6667 if (ID ==
"max_scratch_backing_memory_byte_size") {
6668 Parser.eatToEndOfStatement();
6672 SmallString<40> ErrStr;
6673 raw_svector_ostream Err(ErrStr);
6674 if (!
C.ParseKernelCodeT(ID, getParser(), Err)) {
6675 return TokError(Err.
str());
6679 if (ID ==
"enable_wavefront_size32") {
6682 return TokError(
"enable_wavefront_size32=1 is only allowed on GFX10+");
6684 return TokError(
"enable_wavefront_size32=1 requires +WavefrontSize32");
6687 return TokError(
"enable_wavefront_size32=0 requires +WavefrontSize64");
6691 if (ID ==
"wavefront_size") {
6692 if (
C.wavefront_size == 5) {
6694 return TokError(
"wavefront_size=5 is only allowed on GFX10+");
6696 return TokError(
"wavefront_size=5 requires +WavefrontSize32");
6697 }
else if (
C.wavefront_size == 6) {
6699 return TokError(
"wavefront_size=6 requires +WavefrontSize64");
6706bool AMDGPUAsmParser::ParseDirectiveAMDKernelCodeT() {
6707 AMDGPUMCKernelCodeT KernelCode;
6717 if (!parseId(ID,
"expected value identifier or .end_amd_kernel_code_t"))
6720 if (ID ==
".end_amd_kernel_code_t")
6723 if (ParseAMDKernelCodeTValue(ID, KernelCode))
6728 getTargetStreamer().EmitAMDKernelCodeT(KernelCode);
6733bool AMDGPUAsmParser::ParseDirectiveAMDGPUHsaKernel() {
6734 StringRef KernelName;
6735 if (!parseId(KernelName,
"expected symbol name"))
6738 getTargetStreamer().EmitAMDGPUSymbolType(KernelName,
6745bool AMDGPUAsmParser::ParseDirectiveISAVersion() {
6746 if (!getSTI().getTargetTriple().isAMDGCN()) {
6747 return Error(getLoc(),
6748 ".amd_amdgpu_isa directive is not available on non-amdgcn "
6752 StringRef TargetIDDirective = getLexer().getTok().getStringContents();
6754 std::optional<AMDGPU::TargetID> MaybeParsed =
6757 return Error(getParser().getTok().getLoc(),
6758 "malformed target id '" + TargetIDDirective +
"'");
6761 const Triple &
TT = getSTI().getTargetTriple();
6767 return Error(getParser().getTok().getLoc(),
6768 "target id '" + TargetIDDirective +
6769 "' specifies a processor that is not valid for subarch '" +
6770 TT.getArchName() +
"'");
6773 const std::optional<AMDGPU::TargetID> &CurrentTargetID =
6774 getTargetStreamer().getTargetID();
6777 const Triple &STITriple = getSTI().getTargetTriple();
6778 if (!DirectiveTriple.isCompatibleWith(STITriple)) {
6779 return Error(getParser().getTok().getLoc(),
6780 ".amd_amdgpu_isa " + Twine(ParsedTargetID.
toString()) +
6781 " is incompatible with " +
6782 Twine(CurrentTargetID->toString()));
6786 StringRef DirectiveProcessor =
6789 if (DirectiveISA != ISA) {
6790 return Error(getParser().getTok().getLoc(),
6791 ".amd_amdgpu_isa directive processor " +
6792 Twine(DirectiveProcessor) +
6793 " does not match the specified processor " +
6794 Twine(getSTI().
getCPU()));
6797 getTargetStreamer().EmitISAVersion();
6803bool AMDGPUAsmParser::ParseDirectiveHSAMetadata() {
6806 std::string HSAMetadataString;
6811 if (!getTargetStreamer().EmitHSAMetadataV3(HSAMetadataString))
6812 return Error(getLoc(),
"invalid HSA metadata");
6819bool AMDGPUAsmParser::ParseToEndDirective(
const char *AssemblerDirectiveBegin,
6820 const char *AssemblerDirectiveEnd,
6821 std::string &CollectString) {
6823 raw_string_ostream CollectStream(CollectString);
6825 getLexer().setSkipSpace(
false);
6827 bool FoundEnd =
false;
6830 CollectStream << getTokenStr();
6834 if (trySkipId(AssemblerDirectiveEnd)) {
6839 CollectStream << Parser.parseStringToEndOfStatement()
6840 <<
getContext().getAsmInfo().getSeparatorString();
6842 Parser.eatToEndOfStatement();
6845 getLexer().setSkipSpace(
true);
6848 return TokError(Twine(
"expected directive ") +
6849 Twine(AssemblerDirectiveEnd) + Twine(
" not found"));
6856bool AMDGPUAsmParser::ParseDirectivePALMetadataBegin() {
6862 auto *PALMetadata = getTargetStreamer().getPALMetadata();
6863 if (!PALMetadata->setFromString(
String))
6864 return Error(getLoc(),
"invalid PAL metadata");
6869bool AMDGPUAsmParser::ParseDirectivePALMetadata() {
6872 Twine(
" directive is "
6873 "not available on non-amdpal OSes"))
6877 auto *PALMetadata = getTargetStreamer().getPALMetadata();
6878 PALMetadata->setLegacy();
6881 if (ParseAsAbsoluteExpression(
Key)) {
6882 return TokError(Twine(
"invalid value in ") +
6886 return TokError(Twine(
"expected an even number of values in ") +
6889 if (ParseAsAbsoluteExpression(
Value)) {
6890 return TokError(Twine(
"invalid value in ") +
6893 PALMetadata->setRegister(
Key,
Value);
6902bool AMDGPUAsmParser::ParseDirectiveAMDGPULDS() {
6903 if (getParser().checkForValidSection())
6907 SMLoc NameLoc = getLoc();
6908 if (getParser().parseIdentifier(Name))
6909 return TokError(
"expected identifier in directive");
6912 if (getParser().parseComma())
6918 SMLoc SizeLoc = getLoc();
6919 if (getParser().parseAbsoluteExpression(
Size))
6922 return Error(SizeLoc,
"size must be non-negative");
6923 if (
Size > LocalMemorySize)
6924 return Error(SizeLoc,
"size is too large");
6928 SMLoc AlignLoc = getLoc();
6929 if (getParser().parseAbsoluteExpression(Alignment))
6932 return Error(AlignLoc,
"alignment must be a power of two");
6937 if (Alignment >= 1u << 31)
6938 return Error(AlignLoc,
"alignment is too large");
6944 Symbol->redefineIfPossible();
6945 if (!
Symbol->isUndefined())
6946 return Error(NameLoc,
"invalid symbol redefinition");
6948 getTargetStreamer().emitAMDGPULDS(Symbol,
Size,
Align(Alignment));
6952bool AMDGPUAsmParser::ParseDirectiveAMDGPUInfo() {
6953 if (getParser().checkForValidSection())
6957 if (getParser().parseIdentifier(FuncName))
6958 return TokError(
"expected symbol name after .amdgpu_info");
6961 AMDGPU::InfoSectionData ParsedInfoData;
6962 AMDGPU::FuncInfo FI;
6964 bool HasScalarAttrs =
false;
6971 SMLoc IDLoc = getLoc();
6972 if (!parseId(ID,
"expected directive or .end_amdgpu_info"))
6975 if (ID ==
".end_amdgpu_info")
6983 return Error(IDLoc,
"unknown .amdgpu_info directive '" + ID +
"'");
6985 if (Dir ==
"flags") {
6987 if (getParser().parseAbsoluteExpression(Val))
6990 FI.
UsesVCC = !!(
Flags & AMDGPU::FuncInfoFlags::FUNC_USES_VCC);
6992 !!(
Flags & AMDGPU::FuncInfoFlags::FUNC_USES_FLAT_SCRATCH);
6994 HasScalarAttrs =
true;
6995 }
else if (Dir ==
"num_sgpr") {
6997 if (getParser().parseAbsoluteExpression(Val))
6999 FI.
NumSGPR =
static_cast<uint32_t
>(Val);
7000 HasScalarAttrs =
true;
7001 }
else if (Dir ==
"num_vgpr") {
7003 if (getParser().parseAbsoluteExpression(Val))
7006 HasScalarAttrs =
true;
7007 }
else if (Dir ==
"num_agpr") {
7009 if (getParser().parseAbsoluteExpression(Val))
7012 HasScalarAttrs =
true;
7013 }
else if (Dir ==
"private_segment_size") {
7015 if (getParser().parseAbsoluteExpression(Val))
7018 HasScalarAttrs =
true;
7019 }
else if (Dir ==
"use") {
7021 if (getParser().parseIdentifier(ResName))
7022 return TokError(
"expected resource symbol for .amdgpu_use");
7023 ParsedInfoData.
Uses.push_back(
7024 {FuncSym,
getContext().getOrCreateSymbol(ResName)});
7025 }
else if (Dir ==
"call") {
7027 if (getParser().parseIdentifier(DstName))
7028 return TokError(
"expected callee symbol for .amdgpu_call");
7029 ParsedInfoData.
Calls.push_back(
7030 {FuncSym,
getContext().getOrCreateSymbol(DstName)});
7031 }
else if (Dir ==
"indirect_call") {
7033 if (getParser().parseEscapedString(TypeId))
7034 return TokError(
"expected type ID string for .amdgpu_indirect_call");
7035 ParsedInfoData.
IndirectCalls.push_back({FuncSym, std::move(TypeId)});
7036 }
else if (Dir ==
"typeid") {
7038 if (getParser().parseEscapedString(TypeId))
7039 return TokError(
"expected type ID string for .amdgpu_typeid");
7040 ParsedInfoData.
TypeIds.push_back({FuncSym, std::move(TypeId)});
7042 return Error(IDLoc,
"unknown .amdgpu_info directive '" + ID +
"'");
7047 ParsedInfoData.
Funcs.push_back(std::move(FI));
7049 AMDGPU::InfoSectionData &
Data = InfoData ? *InfoData : InfoData.emplace();
7050 for (AMDGPU::FuncInfo &Func : ParsedInfoData.
Funcs)
7051 Data.Funcs.push_back(std::move(Func));
7052 for (std::pair<MCSymbol *, MCSymbol *> &Use : ParsedInfoData.
Uses)
7053 Data.Uses.push_back(Use);
7054 for (std::pair<MCSymbol *, MCSymbol *> &
Call : ParsedInfoData.
Calls)
7056 for (std::pair<MCSymbol *, std::string> &
IndirectCall :
7059 for (std::pair<MCSymbol *, std::string> &TypeId : ParsedInfoData.
TypeIds)
7060 Data.TypeIds.push_back(std::move(TypeId));
7065void AMDGPUAsmParser::doBeforeLabelEmit(MCSymbol *Symbol, SMLoc IDLoc) {
7072void AMDGPUAsmParser::checkKernelPrologues() {
7073 if (getFeatureBits()[AMDGPU::FeatureRequiresInitialUnclausedVmem]) {
7074 static const unsigned Required[] = {S_MOV_B64_gfx12, V_NOP_e32_gfx12,
7075 GLOBAL_PREFETCH_B8_SADDR_gfx1250};
7076 for (
auto [Sym, Loc,
Offset] : OpcodeStreamSymbols) {
7077 if (!AMDHSAKernelSymbols.
contains(Sym))
7079 ArrayRef<unsigned> Prologue =
ArrayRef(OpcodeStream).drop_front(
Offset);
7080 if (!Prologue.
empty() && Prologue.
front() == S_SETREG_IMM32_B32_gfx12)
7084 "' does not begin with the required prologue "
7085 "sequence: s_mov_b64 followed by v_nop and "
7086 "global_prefetch_b8");
7090 OpcodeStream.
clear();
7091 OpcodeStreamSymbols.clear();
7092 AMDHSAKernelSymbols.
clear();
7095void AMDGPUAsmParser::onEndOfFile() {
7096 emitTargetDirective();
7097 checkKernelPrologues();
7099 getTargetStreamer().emitAMDGPUInfo(*InfoData);
7102bool AMDGPUAsmParser::ParseDirective(AsmToken DirectiveID) {
7103 StringRef IDVal = DirectiveID.
getString();
7106 if (IDVal ==
".amdhsa_kernel")
7107 return ParseDirectiveAMDHSAKernel();
7109 if (IDVal ==
".amdhsa_code_object_version")
7110 return ParseDirectiveAMDHSACodeObjectVersion();
7114 return ParseDirectiveHSAMetadata();
7116 if (IDVal ==
".amd_kernel_code_t")
7117 return ParseDirectiveAMDKernelCodeT();
7119 if (IDVal ==
".amdgpu_hsa_kernel")
7120 return ParseDirectiveAMDGPUHsaKernel();
7122 if (IDVal ==
".amd_amdgpu_isa")
7123 return ParseDirectiveISAVersion();
7127 Twine(
" directive is "
7128 "not available on non-amdhsa OSes"))
7133 if (IDVal ==
".amdgcn_target")
7134 return ParseDirectiveAMDGCNTarget();
7136 if (IDVal ==
".amdgpu_lds")
7137 return ParseDirectiveAMDGPULDS();
7139 if (IDVal ==
".amdgpu_info")
7140 return ParseDirectiveAMDGPUInfo();
7143 return ParseDirectivePALMetadataBegin();
7146 return ParseDirectivePALMetadata();
7151bool AMDGPUAsmParser::subtargetHasRegister(
const MCRegisterInfo &
MRI,
7153 if (
MRI.regsOverlap(TTMP12_TTMP13_TTMP14_TTMP15,
Reg))
7157 if (
MRI.regsOverlap(SGPR104_SGPR105,
Reg))
7158 return hasSGPR104_SGPR105();
7161 case SRC_SHARED_BASE_LO:
7162 case SRC_SHARED_BASE:
7163 case SRC_SHARED_LIMIT_LO:
7164 case SRC_SHARED_LIMIT:
7166 case SRC_PRIVATE_BASE_LO:
7167 case SRC_PRIVATE_BASE:
7168 case SRC_PRIVATE_LIMIT_LO:
7169 case SRC_PRIVATE_LIMIT:
7171 case SRC_FLAT_SCRATCH_BASE_LO:
7172 case SRC_FLAT_SCRATCH_BASE_HI:
7173 return hasGloballyAddressableScratch();
7174 case SRC_POPS_EXITING_WAVE_ID:
7187 getTargetStreamer().getTargetID()->isXnackSupported();
7216 if (
MRI.regsOverlap(SGPR102_SGPR103,
Reg))
7217 return hasSGPR102_SGPR103();
7225 ParseStatus Res = parseVOPD(
Operands);
7230 Res = MatchOperandParserImpl(
Operands, Mnemonic);
7242 SMLoc LBraceLoc = getLoc();
7247 auto Loc = getLoc();
7250 Error(Loc,
"expected a register");
7254 RBraceLoc = getLoc();
7259 "expected a comma or a closing square bracket"))
7263 if (
Operands.size() - Prefix > 1) {
7265 AMDGPUOperand::CreateToken(
this,
"[", LBraceLoc));
7266 Operands.push_back(AMDGPUOperand::CreateToken(
this,
"]", RBraceLoc));
7275StringRef AMDGPUAsmParser::parseMnemonicSuffix(StringRef Name) {
7277 setForcedEncodingSize(0);
7278 setForcedDPP(
false);
7279 setForcedSDWA(
false);
7281 if (
Name.consume_back(
"_e64_dpp")) {
7283 setForcedEncodingSize(64);
7286 if (
Name.consume_back(
"_e64")) {
7287 setForcedEncodingSize(64);
7290 if (
Name.consume_back(
"_e32")) {
7291 setForcedEncodingSize(32);
7294 if (
Name.consume_back(
"_dpp")) {
7298 if (
Name.consume_back(
"_sdwa")) {
7299 setForcedSDWA(
true);
7307 unsigned VariantID);
7313 Name = parseMnemonicSuffix(Name);
7319 Operands.push_back(AMDGPUOperand::CreateToken(
this, Name, NameLoc));
7321 bool IsMIMG = Name.starts_with(
"image_");
7324 OperandMode
Mode = OperandMode_Default;
7326 Mode = OperandMode_NSA;
7330 checkUnsupportedInstruction(Name, NameLoc);
7331 if (!Parser.hasPendingError()) {
7334 :
"not a valid operand.";
7354ParseStatus AMDGPUAsmParser::parseTokenOp(StringRef Name,
7357 if (!trySkipId(Name))
7360 Operands.push_back(AMDGPUOperand::CreateToken(
this, Name, S));
7364ParseStatus AMDGPUAsmParser::parseIntWithPrefix(
const char *Prefix,
7373ParseStatus AMDGPUAsmParser::parseIntWithPrefix(
7375 std::function<
bool(int64_t &)> ConvertResult) {
7379 ParseStatus Res = parseIntWithPrefix(Prefix,
Value);
7383 if (ConvertResult && !ConvertResult(
Value)) {
7384 Error(S,
"invalid " + StringRef(Prefix) +
" value.");
7387 Operands.push_back(AMDGPUOperand::CreateImm(
this,
Value, S, ImmTy));
7391ParseStatus AMDGPUAsmParser::parseOperandArrayWithPrefix(
7393 bool (*ConvertResult)(int64_t &)) {
7402 const unsigned MaxSize = 4;
7406 for (
int I = 0;; ++
I) {
7408 SMLoc Loc = getLoc();
7412 if (
Op != 0 &&
Op != 1)
7413 return Error(Loc,
"invalid " + StringRef(Prefix) +
" value.");
7420 if (
I + 1 == MaxSize)
7421 return Error(getLoc(),
"expected a closing square bracket");
7427 Operands.push_back(AMDGPUOperand::CreateImm(
this, Val, S, ImmTy));
7431ParseStatus AMDGPUAsmParser::parseNamedBit(StringRef Name,
7433 AMDGPUOperand::ImmTy ImmTy,
7434 bool IgnoreNegative) {
7438 if (trySkipId(Name)) {
7440 }
else if (trySkipId(
"no", Name)) {
7449 return Error(S,
"r128 modifier is not supported on this GPU");
7450 if (Name ==
"a16" && !
hasA16())
7451 return Error(S,
"a16 modifier is not supported on this GPU");
7453 if (Bit == 0 && Name ==
"gds") {
7456 return Error(S,
"nogds is not allowed");
7459 if (
isGFX9() && ImmTy == AMDGPUOperand::ImmTyA16)
7460 ImmTy = AMDGPUOperand::ImmTyR128A16;
7462 Operands.push_back(AMDGPUOperand::CreateImm(
this, Bit, S, ImmTy));
7466unsigned AMDGPUAsmParser::getCPolKind(StringRef Id, StringRef Mnemo,
7467 bool &Disabling)
const {
7468 Disabling =
Id.consume_front(
"no");
7471 return StringSwitch<unsigned>(Id)
7478 return StringSwitch<unsigned>(Id)
7488 SMLoc StringLoc = getLoc();
7490 int64_t CPolVal = 0;
7511 ResScope = parseScope(
Operands, Scope);
7524 if (trySkipId(
"nv")) {
7528 }
else if (trySkipId(
"no",
"nv")) {
7535 if (trySkipId(
"scale_offset")) {
7539 }
else if (trySkipId(
"no",
"scale_offset")) {
7563 Operands.push_back(AMDGPUOperand::CreateImm(
this, CPolVal, StringLoc,
7564 AMDGPUOperand::ImmTyCPol));
7569 SMLoc OpLoc = getLoc();
7570 unsigned Enabled = 0, Seen = 0;
7574 unsigned CPol = getCPolKind(getId(), Mnemo, Disabling);
7581 return Error(S,
"dlc modifier is not supported on this GPU");
7584 return Error(S,
"scc modifier is not supported on this GPU");
7587 return Error(S,
"duplicate cache policy modifier");
7599 AMDGPUOperand::CreateImm(
this,
Enabled, OpLoc, AMDGPUOperand::ImmTyCPol));
7608 ParseStatus Res = parseStringOrIntWithPrefix(
7609 Operands,
"scope", {
"SCOPE_CU",
"SCOPE_SE",
"SCOPE_DEV",
"SCOPE_SYS"},
7623 ParseStatus Res = parseStringWithPrefix(
"th",
Value, StringLoc);
7627 if (
Value ==
"TH_DEFAULT")
7629 else if (
Value ==
"TH_STORE_LU" ||
Value ==
"TH_LOAD_WB" ||
7630 Value ==
"TH_LOAD_NT_WB") {
7631 return Error(StringLoc,
"invalid th value");
7632 }
else if (
Value.consume_front(
"TH_ATOMIC_")) {
7634 }
else if (
Value.consume_front(
"TH_LOAD_")) {
7636 }
else if (
Value.consume_front(
"TH_STORE_")) {
7639 return Error(StringLoc,
"invalid th value");
7642 if (
Value ==
"BYPASS")
7647 TH |= StringSwitch<int64_t>(
Value)
7657 .Default(0xffffffff);
7659 TH |= StringSwitch<int64_t>(
Value)
7670 .Default(0xffffffff);
7673 if (TH == 0xffffffff)
7674 return Error(StringLoc,
"invalid th value");
7683 ParseStatus Res = parseStringOrIntWithPrefix(
7684 Operands,
"cfs", {
"CFS_256B",
"CFS_128B",
"CFS_64B",
"CFS_32B"},
CFS);
7694 AMDGPUAsmParser::OptionalImmIndexMap &OptionalIdx,
7695 AMDGPUOperand::ImmTy ImmT, int64_t
Default = 0,
7696 std::optional<unsigned> InsertAt = std::nullopt) {
7697 auto i = OptionalIdx.find(ImmT);
7698 if (i != OptionalIdx.end()) {
7699 unsigned Idx = i->second;
7700 const AMDGPUOperand &
Op =
7701 static_cast<const AMDGPUOperand &
>(*
Operands[
Idx]);
7705 Op.addImmOperands(Inst, 1);
7707 if (InsertAt.has_value())
7714ParseStatus AMDGPUAsmParser::parseStringWithPrefix(StringRef Prefix,
7720 StringLoc = getLoc();
7725ParseStatus AMDGPUAsmParser::parseStringOrIntWithPrefix(
7731 SMLoc StringLoc = getLoc();
7735 Value = getTokenStr();
7739 if (
Value == Ids[IntVal])
7744 if (IntVal < 0 || IntVal >= (int64_t)Ids.
size())
7745 return Error(StringLoc,
"invalid " + Twine(Name) +
" value");
7750ParseStatus AMDGPUAsmParser::parseStringOrIntWithPrefix(
7752 AMDGPUOperand::ImmTy
Type) {
7756 ParseStatus Res = parseStringOrIntWithPrefix(
Operands, Name, Ids, IntVal);
7758 Operands.push_back(AMDGPUOperand::CreateImm(
this, IntVal, S,
Type));
7767ParseStatus AMDGPUAsmParser::tryParseFmt(
const char *Pref, int64_t MaxVal,
7770 SMLoc Loc = getLoc();
7772 ParseStatus Res = parseIntWithPrefix(Pref, Val);
7776 if (Val < 0 || Val > MaxVal)
7777 return Error(Loc, Twine(
"out of range ", StringRef(Pref)));
7784 AMDGPUOperand::ImmTy ImmTy) {
7785 const char *Pref =
"index_key";
7787 SMLoc Loc = getLoc();
7788 auto Res = parseIntWithPrefix(Pref, ImmVal);
7792 if ((ImmTy == AMDGPUOperand::ImmTyIndexKey16bit ||
7793 ImmTy == AMDGPUOperand::ImmTyIndexKey32bit) &&
7794 (ImmVal < 0 || ImmVal > 1))
7795 return Error(Loc, Twine(
"out of range ", StringRef(Pref)));
7797 if (ImmTy == AMDGPUOperand::ImmTyIndexKey8bit && (ImmVal < 0 || ImmVal > 3))
7798 return Error(Loc, Twine(
"out of range ", StringRef(Pref)));
7800 Operands.push_back(AMDGPUOperand::CreateImm(
this, ImmVal, Loc, ImmTy));
7805 return tryParseIndexKey(
Operands, AMDGPUOperand::ImmTyIndexKey8bit);
7809 return tryParseIndexKey(
Operands, AMDGPUOperand::ImmTyIndexKey16bit);
7813 return tryParseIndexKey(
Operands, AMDGPUOperand::ImmTyIndexKey32bit);
7818 AMDGPUOperand::ImmTy
Type) {
7824 return tryParseMatrixFMT(
Operands,
"matrix_a_fmt",
7825 AMDGPUOperand::ImmTyMatrixAFMT);
7829 return tryParseMatrixFMT(
Operands,
"matrix_b_fmt",
7830 AMDGPUOperand::ImmTyMatrixBFMT);
7835 AMDGPUOperand::ImmTy
Type) {
7841 return tryParseMatrixScale(
Operands,
"matrix_a_scale",
7842 AMDGPUOperand::ImmTyMatrixAScale);
7846 return tryParseMatrixScale(
Operands,
"matrix_b_scale",
7847 AMDGPUOperand::ImmTyMatrixBScale);
7852 AMDGPUOperand::ImmTy
Type) {
7858 return tryParseMatrixScaleFmt(
Operands,
"matrix_a_scale_fmt",
7859 AMDGPUOperand::ImmTyMatrixAScaleFmt);
7863 return tryParseMatrixScaleFmt(
Operands,
"matrix_b_scale_fmt",
7864 AMDGPUOperand::ImmTyMatrixBScaleFmt);
7869ParseStatus AMDGPUAsmParser::parseDfmtNfmt(int64_t &
Format) {
7870 using namespace llvm::AMDGPU::MTBUFFormat;
7875 auto TryAfterComma = [&](
const char *Pref, int64_t MaxVal,
7876 int64_t &Fmt) -> ParseStatus {
7878 return Error(getLoc(),
"expected a comma");
7879 AsmToken NextTokens[2];
7880 peekTokens(NextTokens);
7885 return tryParseFmt(Pref, MaxVal, Fmt);
7890 ParseStatus Res = tryParseFmt(
"dfmt", DFMT_MAX, Dfmt);
7892 Res = TryAfterComma(
"nfmt", NFMT_MAX, Nfmt);
7894 Res = tryParseFmt(
"nfmt", NFMT_MAX, Nfmt);
7896 Res = TryAfterComma(
"dfmt", DFMT_MAX, Dfmt);
7905ParseStatus AMDGPUAsmParser::parseUfmt(int64_t &
Format) {
7909bool AMDGPUAsmParser::matchDfmtNfmt(int64_t &Dfmt, int64_t &Nfmt,
7910 StringRef FormatStr, SMLoc Loc) {
7911 using namespace llvm::AMDGPU::MTBUFFormat;
7915 if (
Format != DFMT_UNDEF) {
7921 if (
Format != NFMT_UNDEF) {
7926 Error(Loc,
"unsupported format");
7930ParseStatus AMDGPUAsmParser::parseSymbolicSplitFormat(StringRef FormatStr,
7933 using namespace llvm::AMDGPU::MTBUFFormat;
7937 if (!matchDfmtNfmt(Dfmt, Nfmt, FormatStr, FormatLoc))
7942 SMLoc Loc = getLoc();
7943 if (!parseId(Str,
"expected a format string") ||
7944 !matchDfmtNfmt(Dfmt, Nfmt, Str, Loc))
7946 if (Dfmt == DFMT_UNDEF)
7947 return Error(Loc,
"duplicate numeric format");
7948 if (Nfmt == NFMT_UNDEF)
7949 return Error(Loc,
"duplicate data format");
7952 Dfmt = (Dfmt ==
DFMT_UNDEF) ? DFMT_DEFAULT : Dfmt;
7953 Nfmt = (Nfmt ==
NFMT_UNDEF) ? NFMT_DEFAULT : Nfmt;
7957 if (Ufmt == UFMT_UNDEF)
7958 return Error(FormatLoc,
"unsupported format");
7967ParseStatus AMDGPUAsmParser::parseSymbolicUnifiedFormat(StringRef FormatStr,
7970 using namespace llvm::AMDGPU::MTBUFFormat;
7973 if (Id == UFMT_UNDEF)
7977 return Error(Loc,
"unified format is not supported on this GPU");
7983ParseStatus AMDGPUAsmParser::parseNumericFormat(int64_t &
Format) {
7984 using namespace llvm::AMDGPU::MTBUFFormat;
7985 SMLoc Loc = getLoc();
7990 return Error(Loc,
"out of range format");
7995ParseStatus AMDGPUAsmParser::parseSymbolicOrNumericFormat(int64_t &
Format) {
7996 using namespace llvm::AMDGPU::MTBUFFormat;
8002 StringRef FormatStr;
8003 SMLoc Loc = getLoc();
8004 if (!parseId(FormatStr,
"expected a format string"))
8007 auto Res = parseSymbolicUnifiedFormat(FormatStr, Loc,
Format);
8009 Res = parseSymbolicSplitFormat(FormatStr, Loc,
Format);
8019 return parseNumericFormat(
Format);
8023 SMLoc Loc = getLoc();
8025 ParseStatus Res = parseSymbolicOrNumericFormat(
Format);
8030 AMDGPUOperand::CreateImm(
this,
Format, Loc, AMDGPUOperand::ImmTyFormat));
8035 SMLoc Loc = getLoc();
8042 AMDGPUOperand::ImmTyFormatOp));
8048 parseIntWithPrefix(
"offset",
Operands, AMDGPUOperand::ImmTyOffset);
8050 Res = parseIntWithPrefix(
"inst_offset",
Operands,
8051 AMDGPUOperand::ImmTyInstOffset);
8058 parseNamedBit(
"r128",
Operands, AMDGPUOperand::ImmTyR128A16);
8060 Res = parseNamedBit(
"a16",
Operands, AMDGPUOperand::ImmTyA16);
8066 parseIntWithPrefix(
"blgp",
Operands, AMDGPUOperand::ImmTyBLGP);
8069 parseOperandArrayWithPrefix(
"neg",
Operands, AMDGPUOperand::ImmTyBLGP);
8079 OptionalImmIndexMap OptionalIdx;
8081 unsigned OperandIdx[4];
8082 unsigned EnMask = 0;
8085 for (
unsigned i = 1, e =
Operands.size(); i != e; ++i) {
8086 AMDGPUOperand &
Op = ((AMDGPUOperand &)*
Operands[i]);
8091 OperandIdx[SrcIdx] = Inst.
size();
8092 Op.addRegOperands(Inst, 1);
8099 OperandIdx[SrcIdx] = Inst.
size();
8105 if (
Op.isImm() &&
Op.getImmTy() == AMDGPUOperand::ImmTyExpTgt) {
8106 Op.addImmOperands(Inst, 1);
8111 OptionalIdx[
Op.getImmTy()] = i;
8116 auto ComprIt = OptionalIdx.find(AMDGPUOperand::ImmTyExpCompr);
8117 bool Compr = ComprIt != OptionalIdx.end() &&
8125 for (
auto i = 0; i < SrcIdx; ++i) {
8127 EnMask |= Compr ? (0x3 << i * 2) : (0x1 << i);
8133 AMDGPUOperand::ImmTyExpCompr);
8146 int64_t CntVal,
bool Saturate,
8152 IntVal =
encode(ISA, IntVal, CntVal);
8153 if (CntVal !=
decode(ISA, IntVal)) {
8155 IntVal =
encode(ISA, IntVal, -1);
8163bool AMDGPUAsmParser::parseCnt(int64_t &IntVal) {
8165 SMLoc CntLoc = getLoc();
8166 StringRef CntName = getTokenStr();
8173 SMLoc ValLoc = getLoc();
8180 if (CntName ==
"vmcnt" || CntName ==
"vmcnt_sat") {
8182 }
else if (CntName ==
"expcnt" || CntName ==
"expcnt_sat") {
8184 }
else if (CntName ==
"lgkmcnt" || CntName ==
"lgkmcnt_sat") {
8187 Error(CntLoc,
"invalid counter name " + CntName);
8192 Error(ValLoc,
"too large value for " + CntName);
8201 Error(getLoc(),
"expected a counter name");
8215 if (!parseCnt(Waitcnt))
8223 Operands.push_back(AMDGPUOperand::CreateImm(
this, Waitcnt, S));
8227bool AMDGPUAsmParser::parseDelay(int64_t &Delay) {
8228 SMLoc FieldLoc = getLoc();
8229 StringRef FieldName = getTokenStr();
8234 SMLoc ValueLoc = getLoc();
8241 if (FieldName ==
"instid0") {
8243 }
else if (FieldName ==
"instskip") {
8245 }
else if (FieldName ==
"instid1") {
8248 Error(FieldLoc,
"invalid field name " + FieldName);
8267 .Case(
"VALU_DEP_1", 1)
8268 .Case(
"VALU_DEP_2", 2)
8269 .Case(
"VALU_DEP_3", 3)
8270 .Case(
"VALU_DEP_4", 4)
8271 .Case(
"TRANS32_DEP_1", 5)
8272 .Case(
"TRANS32_DEP_2", 6)
8273 .Case(
"TRANS32_DEP_3", 7)
8274 .Case(
"FMA_ACCUM_CYCLE_1", 8)
8275 .Case(
"SALU_CYCLE_1", 9)
8276 .Case(
"SALU_CYCLE_2", 10)
8277 .Case(
"SALU_CYCLE_3", 11)
8285 Delay |=
Value << Shift;
8295 if (!parseDelay(Delay))
8303 Operands.push_back(AMDGPUOperand::CreateImm(
this, Delay, S));
8307bool AMDGPUOperand::isSWaitCnt()
const {
return isImm(); }
8309bool AMDGPUOperand::isSDelayALU()
const {
return isImm(); }
8315void AMDGPUAsmParser::depCtrError(SMLoc Loc,
int ErrorId,
8316 StringRef DepCtrName) {
8319 Error(Loc, Twine(
"invalid counter name ", DepCtrName));
8322 Error(Loc, Twine(DepCtrName,
" is not supported on this GPU"));
8325 Error(Loc, Twine(
"duplicate counter name ", DepCtrName));
8328 Error(Loc, Twine(
"invalid value for ", DepCtrName));
8335bool AMDGPUAsmParser::parseDepCtr(int64_t &DepCtr,
unsigned &UsedOprMask) {
8337 using namespace llvm::AMDGPU::DepCtr;
8339 SMLoc DepCtrLoc = getLoc();
8340 StringRef DepCtrName = getTokenStr();
8350 unsigned PrevOprMask = UsedOprMask;
8351 int CntVal =
encodeDepCtr(DepCtrName, ExprVal, UsedOprMask, getSTI());
8354 depCtrError(DepCtrLoc, CntVal, DepCtrName);
8363 Error(getLoc(),
"expected a counter name");
8368 int64_t CntValMask = PrevOprMask ^ UsedOprMask;
8369 DepCtr = (DepCtr & ~CntValMask) | CntVal;
8374 using namespace llvm::AMDGPU::DepCtr;
8377 SMLoc Loc = getLoc();
8380 unsigned UsedOprMask = 0;
8382 if (!parseDepCtr(DepCtr, UsedOprMask))
8390 Operands.push_back(AMDGPUOperand::CreateImm(
this, DepCtr, Loc));
8394bool AMDGPUOperand::isDepCtr()
const {
return isS16Imm(); }
8400ParseStatus AMDGPUAsmParser::parseHwregFunc(OperandInfoTy &HwReg,
8402 OperandInfoTy &Width) {
8403 using namespace llvm::AMDGPU::Hwreg;
8409 HwReg.Loc = getLoc();
8412 HwReg.IsSymbolic =
true;
8414 }
else if (!
parseExpr(HwReg.Val,
"a register name")) {
8422 if (!skipToken(
AsmToken::Comma,
"expected a comma or a closing parenthesis"))
8432 Width.Loc = getLoc();
8441 using namespace llvm::AMDGPU::Hwreg;
8444 SMLoc Loc = getLoc();
8446 StructuredOpField HwReg(
"id",
"hardware register", HwregId::Width,
8448 StructuredOpField
Offset(
"offset",
"bit offset", HwregOffset::Width,
8449 HwregOffset::Default);
8450 struct : StructuredOpField {
8451 using StructuredOpField::StructuredOpField;
8452 bool validate(AMDGPUAsmParser &Parser)
const override {
8454 return Error(Parser,
"only values from 1 to 32 are legal");
8457 } Width(
"size",
"bitfield width", HwregSize::Width, HwregSize::Default);
8458 ParseStatus Res = parseStructuredOpFields({&HwReg, &
Offset, &Width});
8461 Res = parseHwregFunc(HwReg,
Offset, Width);
8464 if (!validateStructuredOpFields({&HwReg, &
Offset, &Width}))
8466 ImmVal = HwregEncoding::encode(HwReg.Val,
Offset.Val, Width.Val);
8470 parseExpr(ImmVal,
"a hwreg macro, structured immediate"))
8477 return Error(Loc,
"invalid immediate: only 16-bit values are legal");
8479 AMDGPUOperand::CreateImm(
this, ImmVal, Loc, AMDGPUOperand::ImmTyHwreg));
8483bool AMDGPUOperand::isHwreg()
const {
return isImmTy(ImmTyHwreg); }
8489bool AMDGPUAsmParser::parseSendMsgBody(OperandInfoTy &
Msg, OperandInfoTy &
Op,
8490 OperandInfoTy &Stream) {
8491 using namespace llvm::AMDGPU::SendMsg;
8496 Msg.IsSymbolic =
true;
8503 Op.IsDefined =
true;
8509 }
else if (!
parseExpr(
Op.Val,
"an operation name")) {
8514 Stream.IsDefined =
true;
8515 Stream.Loc = getLoc();
8524bool AMDGPUAsmParser::validateSendMsg(
const OperandInfoTy &
Msg,
8525 const OperandInfoTy &
Op,
8526 const OperandInfoTy &Stream) {
8527 using namespace llvm::AMDGPU::SendMsg;
8536 Error(
Msg.Loc,
"specified message id is not supported on this GPU");
8541 Error(
Msg.Loc,
"invalid message id");
8547 Error(
Op.Loc,
"message does not support operations");
8549 Error(
Msg.Loc,
"missing message operation");
8555 Error(
Op.Loc,
"specified operation id is not supported on this GPU");
8557 Error(
Op.Loc,
"invalid operation id");
8562 Error(Stream.Loc,
"message operation does not support streams");
8566 Error(Stream.Loc,
"invalid message stream id");
8573 using namespace llvm::AMDGPU::SendMsg;
8576 SMLoc Loc = getLoc();
8580 OperandInfoTy
Op(OP_NONE_);
8581 OperandInfoTy Stream(STREAM_ID_NONE_);
8582 if (parseSendMsgBody(
Msg,
Op, Stream) && validateSendMsg(
Msg,
Op, Stream)) {
8587 }
else if (
parseExpr(ImmVal,
"a sendmsg macro")) {
8589 return Error(Loc,
"invalid immediate: only 16-bit values are legal");
8595 AMDGPUOperand::CreateImm(
this, ImmVal, Loc, AMDGPUOperand::ImmTySendMsg));
8599bool AMDGPUOperand::isSendMsg()
const {
return isImmTy(ImmTySendMsg); }
8602 using namespace llvm::AMDGPU::WaitEvent;
8604 SMLoc Loc = getLoc();
8607 StructuredOpField DontWaitExportReady(
"dont_wait_export_ready",
"bit value",
8609 StructuredOpField ExportReady(
"export_ready",
"bit value", 1, 0);
8611 StructuredOpField *TargetBitfield =
8612 isGFX11() ? &DontWaitExportReady : &ExportReady;
8614 ParseStatus Res = parseStructuredOpFields({TargetBitfield});
8618 if (!validateStructuredOpFields({TargetBitfield}))
8620 ImmVal = TargetBitfield->Val;
8627 return Error(Loc,
"invalid immediate: only 16-bit values are legal");
8629 Operands.push_back(AMDGPUOperand::CreateImm(
this, ImmVal, Loc,
8630 AMDGPUOperand::ImmTyWaitEvent));
8634bool AMDGPUOperand::isWaitEvent()
const {
return isImmTy(ImmTyWaitEvent); }
8647 int Slot = StringSwitch<int>(Str)
8654 return Error(S,
"invalid interpolation slot");
8657 AMDGPUOperand::CreateImm(
this, Slot, S, AMDGPUOperand::ImmTyInterpSlot));
8668 if (!Str.starts_with(
"attr"))
8669 return Error(S,
"invalid interpolation attribute");
8671 StringRef Chan = Str.take_back(2);
8672 int AttrChan = StringSwitch<int>(Chan)
8679 return Error(S,
"invalid or missing interpolation attribute channel");
8681 Str = Str.drop_back(2).drop_front(4);
8684 if (Str.getAsInteger(10, Attr))
8685 return Error(S,
"invalid or missing interpolation attribute number");
8688 return Error(S,
"out of bounds interpolation attribute number");
8693 AMDGPUOperand::CreateImm(
this, Attr, S, AMDGPUOperand::ImmTyInterpAttr));
8694 Operands.push_back(AMDGPUOperand::CreateImm(
8695 this, AttrChan, SChan, AMDGPUOperand::ImmTyInterpAttrChan));
8704 using namespace llvm::AMDGPU::Exp;
8714 return Error(S, (Id == ET_INVALID)
8715 ?
"invalid exp target"
8716 :
"exp target is not supported on this GPU");
8719 AMDGPUOperand::CreateImm(
this, Id, S, AMDGPUOperand::ImmTyExpTgt));
8727bool AMDGPUAsmParser::isId(
const AsmToken &Token,
const StringRef Id)
const {
8731bool AMDGPUAsmParser::isId(
const StringRef Id)
const {
8736 return getTokenKind() ==
Kind;
8739StringRef AMDGPUAsmParser::getId()
const {
8743bool AMDGPUAsmParser::trySkipId(
const StringRef Id) {
8751bool AMDGPUAsmParser::trySkipId(
const StringRef Pref,
const StringRef Id) {
8753 StringRef Tok = getTokenStr();
8762bool AMDGPUAsmParser::trySkipId(
const StringRef Id,
8764 if (isId(Id) && peekToken().is(Kind)) {
8773 if (isToken(Kind)) {
8781 const StringRef ErrMsg) {
8782 if (!trySkipToken(Kind)) {
8783 Error(getLoc(), ErrMsg);
8789bool AMDGPUAsmParser::parseExpr(int64_t &
Imm, StringRef Expected) {
8793 if (Parser.parseExpression(Expr))
8796 if (Expr->evaluateAsAbsolute(
Imm))
8799 if (Expected.empty()) {
8800 Error(S,
"expected absolute expression");
8803 Twine(
"expected ", Expected) + Twine(
" or an absolute expression"));
8812 if (Parser.parseExpression(Expr))
8816 if (Expr->evaluateAsAbsolute(IntVal)) {
8817 Operands.push_back(AMDGPUOperand::CreateImm(
this, IntVal, S));
8819 Operands.push_back(AMDGPUOperand::CreateExpr(
this, Expr, S));
8824bool AMDGPUAsmParser::parseString(StringRef &Val,
const StringRef ErrMsg) {
8826 Val =
getToken().getStringContents();
8830 Error(getLoc(), ErrMsg);
8834bool AMDGPUAsmParser::parseId(StringRef &Val,
const StringRef ErrMsg) {
8836 Val = getTokenStr();
8840 if (!ErrMsg.
empty())
8841 Error(getLoc(), ErrMsg);
8845AsmToken AMDGPUAsmParser::getToken()
const {
return Parser.getTok(); }
8847AsmToken AMDGPUAsmParser::peekToken(
bool ShouldSkipSpace) {
8850 : getLexer().peekTok(ShouldSkipSpace);
8854 auto TokCount = getLexer().peekTokens(Tokens);
8861 return getLexer().getKind();
8864SMLoc AMDGPUAsmParser::getLoc()
const {
return getToken().getLoc(); }
8866StringRef AMDGPUAsmParser::getTokenStr()
const {
8870void AMDGPUAsmParser::lex() { Parser.Lex(); }
8872const AMDGPUOperand &
8874 int MCOpIdx)
const {
8876 const AMDGPUOperand &TargetOp =
static_cast<AMDGPUOperand &
>(*Op);
8877 if (TargetOp.getMCOpIdx() == MCOpIdx)
8884 return ((AMDGPUOperand &)*
Operands[0]).getStartLoc();
8888SMLoc AMDGPUAsmParser::getLaterLoc(SMLoc a, SMLoc b) {
8893 int MCOpIdx)
const {
8894 return findMCOperand(
Operands, MCOpIdx).getStartLoc();
8897SMLoc AMDGPUAsmParser::getOperandLoc(
8898 std::function<
bool(
const AMDGPUOperand &)>
Test,
8900 for (
unsigned i =
Operands.size() - 1; i > 0; --i) {
8901 AMDGPUOperand &
Op = ((AMDGPUOperand &)*
Operands[i]);
8903 return Op.getStartLoc();
8908SMLoc AMDGPUAsmParser::getImmLoc(AMDGPUOperand::ImmTy
Type,
8910 auto Test = [=](
const AMDGPUOperand &
Op) {
return Op.isImmTy(
Type); };
8925 StringRef
Id = getTokenStr();
8926 SMLoc IdLoc = getLoc();
8932 find_if(Fields, [Id](StructuredOpField *
F) {
return F->Id ==
Id; });
8933 if (
I == Fields.
end())
8934 return Error(IdLoc,
"unknown field");
8935 if ((*I)->IsDefined)
8936 return Error(IdLoc,
"duplicate field");
8939 (*I)->Loc = getLoc();
8942 (*I)->IsDefined =
true;
8949bool AMDGPUAsmParser::validateStructuredOpFields(
8951 return all_of(Fields, [
this](
const StructuredOpField *
F) {
8952 return F->validate(*
this);
8962 const unsigned XorMask) {
8969bool AMDGPUAsmParser::parseSwizzleOperand(int64_t &
Op,
const unsigned MinVal,
8970 const unsigned MaxVal,
8971 const Twine &ErrMsg, SMLoc &Loc) {
8987bool AMDGPUAsmParser::parseSwizzleOperands(
const unsigned OpNum, int64_t *
Op,
8988 const unsigned MinVal,
8989 const unsigned MaxVal,
8990 const StringRef ErrMsg) {
8992 for (
unsigned i = 0; i < OpNum; ++i) {
8993 if (!parseSwizzleOperand(
Op[i], MinVal, MaxVal, ErrMsg, Loc))
9000bool AMDGPUAsmParser::parseSwizzleQuadPerm(int64_t &
Imm) {
9001 using namespace llvm::AMDGPU::Swizzle;
9004 if (parseSwizzleOperands(LANE_NUM, Lane, 0, LANE_MAX,
9005 "expected a 2-bit lane id")) {
9015bool AMDGPUAsmParser::parseSwizzleBroadcast(int64_t &
Imm) {
9016 using namespace llvm::AMDGPU::Swizzle;
9022 if (!parseSwizzleOperand(GroupSize, 2, 32,
9023 "group size must be in the interval [2,32]", Loc)) {
9027 Error(Loc,
"group size must be a power of two");
9030 if (parseSwizzleOperand(LaneIdx, 0, GroupSize - 1,
9031 "lane id must be in the interval [0,group size - 1]",
9039bool AMDGPUAsmParser::parseSwizzleReverse(int64_t &
Imm) {
9040 using namespace llvm::AMDGPU::Swizzle;
9045 if (!parseSwizzleOperand(GroupSize, 2, 32,
9046 "group size must be in the interval [2,32]", Loc)) {
9050 Error(Loc,
"group size must be a power of two");
9058bool AMDGPUAsmParser::parseSwizzleSwap(int64_t &
Imm) {
9059 using namespace llvm::AMDGPU::Swizzle;
9064 if (!parseSwizzleOperand(GroupSize, 1, 16,
9065 "group size must be in the interval [1,16]", Loc)) {
9069 Error(Loc,
"group size must be a power of two");
9077bool AMDGPUAsmParser::parseSwizzleBitmaskPerm(int64_t &
Imm) {
9078 using namespace llvm::AMDGPU::Swizzle;
9085 SMLoc StrLoc = getLoc();
9086 if (!parseString(Ctl)) {
9089 if (Ctl.
size() != BITMASK_WIDTH) {
9090 Error(StrLoc,
"expected a 5-character mask");
9094 unsigned AndMask = 0;
9095 unsigned OrMask = 0;
9096 unsigned XorMask = 0;
9098 for (
size_t i = 0; i < Ctl.
size(); ++i) {
9102 Error(StrLoc,
"invalid mask");
9123bool AMDGPUAsmParser::parseSwizzleFFT(int64_t &
Imm) {
9124 using namespace llvm::AMDGPU::Swizzle;
9127 Error(getLoc(),
"FFT mode swizzle not supported on this GPU");
9133 if (!parseSwizzleOperand(Swizzle, 0, FFT_SWIZZLE_MAX,
9134 "FFT swizzle must be in the interval [0," +
9135 Twine(FFT_SWIZZLE_MAX) + Twine(
']'),
9143bool AMDGPUAsmParser::parseSwizzleRotate(int64_t &
Imm) {
9144 using namespace llvm::AMDGPU::Swizzle;
9147 Error(getLoc(),
"Rotate mode swizzle not supported on this GPU");
9154 if (!parseSwizzleOperand(
Direction, 0, 1,
9155 "direction must be 0 (left) or 1 (right)", Loc))
9159 if (!parseSwizzleOperand(
9160 RotateSize, 0, ROTATE_MAX_SIZE,
9161 "number of threads to rotate must be in the interval [0," +
9162 Twine(ROTATE_MAX_SIZE) + Twine(
']'),
9167 (RotateSize << ROTATE_SIZE_SHIFT);
9171bool AMDGPUAsmParser::parseSwizzleOffset(int64_t &
Imm) {
9173 SMLoc OffsetLoc = getLoc();
9179 Error(OffsetLoc,
"expected a 16-bit offset");
9185bool AMDGPUAsmParser::parseSwizzleMacro(int64_t &
Imm) {
9186 using namespace llvm::AMDGPU::Swizzle;
9190 SMLoc ModeLoc = getLoc();
9193 if (trySkipId(IdSymbolic[ID_QUAD_PERM])) {
9194 Ok = parseSwizzleQuadPerm(
Imm);
9195 }
else if (trySkipId(IdSymbolic[ID_BITMASK_PERM])) {
9196 Ok = parseSwizzleBitmaskPerm(
Imm);
9197 }
else if (trySkipId(IdSymbolic[ID_BROADCAST])) {
9198 Ok = parseSwizzleBroadcast(
Imm);
9199 }
else if (trySkipId(IdSymbolic[ID_SWAP])) {
9200 Ok = parseSwizzleSwap(
Imm);
9201 }
else if (trySkipId(IdSymbolic[ID_REVERSE])) {
9202 Ok = parseSwizzleReverse(
Imm);
9203 }
else if (trySkipId(IdSymbolic[ID_FFT])) {
9204 Ok = parseSwizzleFFT(
Imm);
9205 }
else if (trySkipId(IdSymbolic[ID_ROTATE])) {
9206 Ok = parseSwizzleRotate(
Imm);
9208 Error(ModeLoc,
"expected a swizzle mode");
9211 return Ok && skipToken(
AsmToken::RParen,
"expected a closing parentheses");
9221 if (trySkipId(
"offset")) {
9225 if (trySkipId(
"swizzle")) {
9226 Ok = parseSwizzleMacro(
Imm);
9228 Ok = parseSwizzleOffset(
Imm);
9233 AMDGPUOperand::CreateImm(
this,
Imm, S, AMDGPUOperand::ImmTySwizzle));
9240bool AMDGPUOperand::isSwizzle()
const {
return isImmTy(ImmTySwizzle); }
9246int64_t AMDGPUAsmParser::parseGPRIdxMacro() {
9248 using namespace llvm::AMDGPU::VGPRIndexMode;
9260 for (
unsigned ModeId = ID_MIN; ModeId <=
ID_MAX; ++ModeId) {
9261 if (trySkipId(IdSymbolic[ModeId])) {
9269 ?
"expected a VGPR index mode or a closing parenthesis"
9270 :
"expected a VGPR index mode");
9275 Error(S,
"duplicate VGPR index mode");
9283 "expected a comma or a closing parenthesis"))
9292 using namespace llvm::AMDGPU::VGPRIndexMode;
9298 Imm = parseGPRIdxMacro();
9302 if (getParser().parseAbsoluteExpression(
Imm))
9305 return Error(S,
"invalid immediate: only 4-bit values are legal");
9309 AMDGPUOperand::CreateImm(
this,
Imm, S, AMDGPUOperand::ImmTyGprIdxMode));
9313bool AMDGPUOperand::isGPRIdxMode()
const {
return isImmTy(ImmTyGprIdxMode); }
9324 if (isRegister() || isModifier())
9331 assert(Opr.isImm() || Opr.isExpr());
9332 SMLoc Loc = Opr.getStartLoc();
9336 if (Opr.isExpr() && !Opr.isSymbolRefExpr()) {
9337 Error(Loc,
"expected an absolute expression or a label");
9338 }
else if (Opr.isImm() && !Opr.isS16Imm()) {
9339 Error(Loc,
"expected a 16-bit signed jump offset");
9346 if (isRegister() || isModifier())
9351 assert(Opr.isImm() || Opr.isExpr());
9354 if (Opr.isExpr() && (!Opr.isSymbolRefExpr() || Opr.hasSymbolSpecifier()))
9355 Error(Opr.getStartLoc(),
9356 "expected an absolute expression or an unqualified label");
9374 OptionalImmIndexMap OptionalIdx;
9375 unsigned FirstOperandIdx = 1;
9376 bool IsAtomicReturn =
false;
9382 for (
unsigned i = FirstOperandIdx, e =
Operands.size(); i != e; ++i) {
9383 AMDGPUOperand &
Op = ((AMDGPUOperand &)*
Operands[i]);
9387 Op.addRegOperands(Inst, 1);
9391 if (IsAtomicReturn && i == FirstOperandIdx)
9392 Op.addRegOperands(Inst, 1);
9397 if (
Op.isImm() &&
Op.getImmTy() == AMDGPUOperand::ImmTyNone) {
9398 Op.addImmOperands(Inst, 1);
9410 OptionalIdx[
Op.getImmTy()] = i;
9414 AMDGPUOperand::ImmTyOffset);
9430bool AMDGPUOperand::isSMRDOffset8()
const {
9434bool AMDGPUOperand::isSMEMOffset()
const {
9436 return isImmLiteral();
9439bool AMDGPUOperand::isSMRDLiteralOffset()
const {
9474bool AMDGPUAsmParser::convertDppBoundCtrl(int64_t &BoundCtrl) {
9475 if (BoundCtrl == 0 || BoundCtrl == 1) {
9483void AMDGPUAsmParser::onBeginOfFile() {
9484 if (!getParser().getStreamer().getTargetStreamer())
9487 if (!getTargetStreamer().getTargetID())
9488 getTargetStreamer().initializeTargetID(getSTI(),
9492void AMDGPUAsmParser::emitTargetDirective() {
9493 if (!getParser().getStreamer().getTargetStreamer() ||
9498 getTargetStreamer().emitDirectiveAMDGCNTargetOnce();
9507bool AMDGPUAsmParser::parsePrimaryExpr(
const MCExpr *&Res, SMLoc &EndLoc) {
9511 StringRef TokenId = getTokenStr();
9512 AGVK VK = StringSwitch<AGVK>(TokenId)
9513 .Case(
"max", AGVK::AGVK_Max)
9514 .Case(
"min", AGVK::AGVK_Min)
9515 .Case(
"or", AGVK::AGVK_Or)
9516 .Case(
"extrasgprs", AGVK::AGVK_ExtraSGPRs)
9517 .Case(
"totalnumvgprs", AGVK::AGVK_TotalNumVGPRs)
9518 .Case(
"alignto", AGVK::AGVK_AlignTo)
9519 .Case(
"occupancy", AGVK::AGVK_Occupancy)
9520 .Case(
"instprefsize", AGVK::AGVK_InstPrefSize)
9521 .Default(AGVK::AGVK_None);
9530 if (Exprs.
empty()) {
9532 "empty " + Twine(TokenId) +
" expression");
9535 if (CommaCount + 1 != Exprs.
size()) {
9537 "mismatch of commas in " + Twine(TokenId) +
" expression");
9541 Expected && Exprs.
size() != Expected) {
9542 Error(
getToken().getLoc(), Twine(TokenId) +
" expression expects " +
9543 Twine(Expected) +
" operands");
9550 if (getParser().parseExpression(Expr, EndLoc))
9554 if (LastTokenWasComma)
9558 "unexpected token in " + Twine(TokenId) +
" expression");
9564 return getParser().parsePrimaryExpr(Res, EndLoc,
nullptr);
9568 StringRef
Name = getTokenStr();
9569 if (Name ==
"mul") {
9570 return parseIntWithPrefix(
"mul",
Operands, AMDGPUOperand::ImmTyOModSI,
9574 if (Name ==
"div") {
9575 return parseIntWithPrefix(
"div",
Operands, AMDGPUOperand::ImmTyOModSI,
9586 int OpSelIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::op_sel);
9591 const AMDGPU::OpName
Ops[] = {AMDGPU::OpName::src0, AMDGPU::OpName::src1,
9592 AMDGPU::OpName::src2};
9600 int DstIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::vdst);
9605 int ModIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::src0_modifiers);
9607 if (
DstOp.isReg() &&
9608 MRI.getRegClass(AMDGPU::VGPR_16RegClassID).contains(
DstOp.
getReg())) {
9612 if ((OpSel & (1 << SrcNum)) != 0)
9618void AMDGPUAsmParser::cvtVOP3OpSel(MCInst &Inst,
9625 OptionalImmIndexMap &OptionalIdx) {
9626 cvtVOP3P(Inst,
Operands, OptionalIdx);
9635 &&
Desc.NumOperands > (OpNum + 1)
9637 &&
Desc.operands()[OpNum + 1].RegClass != -1
9639 &&
Desc.getOperandConstraint(OpNum + 1,
9643void AMDGPUAsmParser::cvtOpSelHelper(MCInst &Inst,
unsigned OpSel) {
9645 constexpr AMDGPU::OpName
Ops[] = {AMDGPU::OpName::src0, AMDGPU::OpName::src1,
9646 AMDGPU::OpName::src2};
9647 constexpr AMDGPU::OpName ModOps[] = {AMDGPU::OpName::src0_modifiers,
9648 AMDGPU::OpName::src1_modifiers,
9649 AMDGPU::OpName::src2_modifiers};
9650 for (
int J = 0; J < 3; ++J) {
9651 int OpIdx = AMDGPU::getNamedOperandIdx(
Opc,
Ops[J]);
9657 int ModIdx = AMDGPU::getNamedOperandIdx(
Opc, ModOps[J]);
9660 if ((OpSel & (1 << J)) != 0)
9663 if (ModOps[J] == AMDGPU::OpName::src0_modifiers && (OpSel & (1 << 3)) != 0)
9670void AMDGPUAsmParser::cvtVOP3Interp(MCInst &Inst,
9672 OptionalImmIndexMap OptionalIdx;
9677 for (
unsigned J = 0; J <
Desc.getNumDefs(); ++J) {
9678 ((AMDGPUOperand &)*
Operands[
I++]).addRegOperands(Inst, 1);
9682 AMDGPUOperand &
Op = ((AMDGPUOperand &)*
Operands[
I]);
9684 Op.addRegOrImmWithFPInputModsOperands(Inst, 2);
9685 }
else if (
Op.isInterpSlot() ||
Op.isInterpAttr() ||
9686 Op.isInterpAttrChan()) {
9688 }
else if (
Op.isImmModifier()) {
9689 OptionalIdx[
Op.getImmTy()] =
I;
9697 AMDGPUOperand::ImmTyHigh);
9701 AMDGPUOperand::ImmTyClamp);
9705 AMDGPUOperand::ImmTyOModSI);
9710 AMDGPUOperand::ImmTyOpSel);
9711 int OpSelIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::op_sel);
9714 cvtOpSelHelper(Inst, OpSel);
9719 OptionalImmIndexMap OptionalIdx;
9724 for (
unsigned J = 0; J <
Desc.getNumDefs(); ++J) {
9725 ((AMDGPUOperand &)*
Operands[
I++]).addRegOperands(Inst, 1);
9729 AMDGPUOperand &
Op = ((AMDGPUOperand &)*
Operands[
I]);
9731 Op.addRegOrImmWithFPInputModsOperands(Inst, 2);
9732 }
else if (
Op.isImmModifier()) {
9733 OptionalIdx[
Op.getImmTy()] =
I;
9741 int OpSelIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::op_sel);
9744 AMDGPUOperand::ImmTyOpSel);
9747 AMDGPUOperand::ImmTyWaitEXP);
9753 cvtOpSelHelper(Inst, OpSel);
9756void AMDGPUAsmParser::cvtScaledMFMA(MCInst &Inst,
9758 OptionalImmIndexMap OptionalIdx;
9761 int CbszOpIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::cbsz);
9765 for (
unsigned J = 0; J <
Desc.getNumDefs(); ++J)
9766 static_cast<AMDGPUOperand &
>(*
Operands[
I++]).addRegOperands(Inst, 1);
9769 AMDGPUOperand &
Op =
static_cast<AMDGPUOperand &
>(*
Operands[
I]);
9774 if (NumOperands == CbszOpIdx) {
9779 Op.addRegOrImmWithFPInputModsOperands(Inst, 2);
9780 }
else if (
Op.isImmModifier()) {
9781 OptionalIdx[
Op.getImmTy()] =
I;
9783 Op.addRegOrImmOperands(Inst, 1);
9788 auto CbszIdx = OptionalIdx.find(AMDGPUOperand::ImmTyCBSZ);
9789 if (CbszIdx != OptionalIdx.end()) {
9790 int CbszVal = ((AMDGPUOperand &)*
Operands[CbszIdx->second]).
getImm();
9794 int BlgpOpIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::blgp);
9795 auto BlgpIdx = OptionalIdx.find(AMDGPUOperand::ImmTyBLGP);
9796 if (BlgpIdx != OptionalIdx.end()) {
9797 int BlgpVal = ((AMDGPUOperand &)*
Operands[BlgpIdx->second]).
getImm();
9808 auto OpselIdx = OptionalIdx.find(AMDGPUOperand::ImmTyOpSel);
9809 if (OpselIdx != OptionalIdx.end()) {
9810 OpSel =
static_cast<const AMDGPUOperand &
>(*
Operands[OpselIdx->second])
9814 unsigned OpSelHi = 0;
9815 auto OpselHiIdx = OptionalIdx.find(AMDGPUOperand::ImmTyOpSelHi);
9816 if (OpselHiIdx != OptionalIdx.end()) {
9817 OpSelHi =
static_cast<const AMDGPUOperand &
>(*
Operands[OpselHiIdx->second])
9820 const AMDGPU::OpName ModOps[] = {AMDGPU::OpName::src0_modifiers,
9821 AMDGPU::OpName::src1_modifiers};
9823 for (
unsigned J = 0; J < 2; ++J) {
9824 unsigned ModVal = 0;
9825 if (OpSel & (1 << J))
9827 if (OpSelHi & (1 << J))
9830 const int ModIdx = AMDGPU::getNamedOperandIdx(
Opc, ModOps[J]);
9836 OptionalImmIndexMap &OptionalIdx) {
9841 for (
unsigned J = 0; J <
Desc.getNumDefs(); ++J) {
9842 ((AMDGPUOperand &)*
Operands[
I++]).addRegOperands(Inst, 1);
9846 AMDGPUOperand &
Op = ((AMDGPUOperand &)*
Operands[
I]);
9848 Op.addRegOrImmWithFPInputModsOperands(Inst, 2);
9849 }
else if (
Op.isImmModifier()) {
9850 OptionalIdx[
Op.getImmTy()] =
I;
9852 Op.addRegOrImmOperands(Inst, 1);
9858 AMDGPUOperand::ImmTyScaleSel);
9862 AMDGPUOperand::ImmTyClamp);
9868 AMDGPUOperand::ImmTyByteSel);
9873 AMDGPUOperand::ImmTyOModSI);
9880 auto *it = Inst.
begin();
9882 it, AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::src2_modifiers));
9891 OptionalImmIndexMap OptionalIdx;
9892 cvtVOP3(Inst,
Operands, OptionalIdx);
9896 OptionalImmIndexMap &OptIdx) {
9901 if (
Opc == AMDGPU::V_CVT_SCALEF32_PK_FP4_F16_vi ||
9902 Opc == AMDGPU::V_CVT_SCALEF32_PK_FP4_BF16_vi ||
9903 Opc == AMDGPU::V_CVT_SR_BF8_F32_vi ||
9904 Opc == AMDGPU::V_CVT_SR_FP8_F32_vi ||
9905 Opc == AMDGPU::V_CVT_SR_BF8_F32_gfx12_e64_gfx11 ||
9906 Opc == AMDGPU::V_CVT_SR_FP8_F32_gfx12_e64_gfx11 ||
9907 Opc == AMDGPU::V_CVT_SR_BF8_F32_gfx12_e64_gfx12 ||
9908 Opc == AMDGPU::V_CVT_SR_FP8_F32_gfx12_e64_gfx12 ||
9909 Opc == AMDGPU::V_CVT_SR_BF8_F32_gfx12_e64_gfx13 ||
9910 Opc == AMDGPU::V_CVT_SR_FP8_F32_gfx12_e64_gfx13) {
9919 int VdstInIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::vdst_in);
9920 if (VdstInIdx != -1 && VdstInIdx ==
static_cast<int>(Inst.
getNumOperands()))
9923 int BitOp3Idx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::bitop3);
9924 if (BitOp3Idx != -1) {
9931 int OpSelIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::op_sel);
9932 if (OpSelIdx != -1) {
9936 int OpSelHiIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::op_sel_hi);
9937 if (OpSelHiIdx != -1) {
9938 int DefaultVal =
IsPacked ? -1 : 0;
9944 AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::matrix_a_fmt);
9945 if (MatrixAFMTIdx != -1) {
9947 AMDGPUOperand::ImmTyMatrixAFMT, 0);
9951 AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::matrix_b_fmt);
9952 if (MatrixBFMTIdx != -1) {
9954 AMDGPUOperand::ImmTyMatrixBFMT, 0);
9957 int MatrixAScaleIdx =
9958 AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::matrix_a_scale);
9959 if (MatrixAScaleIdx != -1) {
9961 AMDGPUOperand::ImmTyMatrixAScale, 0);
9964 int MatrixBScaleIdx =
9965 AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::matrix_b_scale);
9966 if (MatrixBScaleIdx != -1) {
9968 AMDGPUOperand::ImmTyMatrixBScale, 0);
9971 int MatrixAScaleFmtIdx =
9972 AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::matrix_a_scale_fmt);
9973 if (MatrixAScaleFmtIdx != -1) {
9975 AMDGPUOperand::ImmTyMatrixAScaleFmt, 0);
9978 int MatrixBScaleFmtIdx =
9979 AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::matrix_b_scale_fmt);
9980 if (MatrixBScaleFmtIdx != -1) {
9982 AMDGPUOperand::ImmTyMatrixBScaleFmt, 0);
9987 AMDGPUOperand::ImmTyMatrixAReuse, 0);
9991 AMDGPUOperand::ImmTyMatrixBReuse, 0);
9993 int NegLoIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::neg_lo);
9997 int NegHiIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::neg_hi);
10001 const AMDGPU::OpName
Ops[] = {AMDGPU::OpName::src0, AMDGPU::OpName::src1,
10002 AMDGPU::OpName::src2};
10003 const AMDGPU::OpName ModOps[] = {AMDGPU::OpName::src0_modifiers,
10004 AMDGPU::OpName::src1_modifiers,
10005 AMDGPU::OpName::src2_modifiers};
10007 unsigned OpSel = 0;
10008 unsigned OpSelHi = 0;
10009 unsigned NegLo = 0;
10010 unsigned NegHi = 0;
10012 if (OpSelIdx != -1)
10015 if (OpSelHiIdx != -1)
10018 if (NegLoIdx != -1)
10021 if (NegHiIdx != -1)
10024 for (
int J = 0; J < 3; ++J) {
10025 int OpIdx = AMDGPU::getNamedOperandIdx(
Opc,
Ops[J]);
10029 int ModIdx = AMDGPU::getNamedOperandIdx(
Opc, ModOps[J]);
10039 uint32_t ModVal = 0;
10041 const MCOperand &SrcOp = Inst.
getOperand(OpIdx);
10042 if (SrcOp.
isReg() && getMRI()
10046 if (VGPRSuffixIsHi)
10049 if ((OpSel & (1 << J)) != 0)
10053 if ((OpSelHi & (1 << J)) != 0)
10056 if ((NegLo & (1 << J)) != 0)
10059 if ((NegHi & (1 << J)) != 0)
10067 OptionalImmIndexMap OptIdx;
10073 unsigned i,
unsigned Opc,
10074 AMDGPU::OpName
OpName) {
10075 if (AMDGPU::getNamedOperandIdx(
Opc,
OpName) != -1)
10076 ((AMDGPUOperand &)*
Operands[i]).addRegOrImmWithFPInputModsOperands(Inst, 2);
10078 ((AMDGPUOperand &)*
Operands[i]).addRegOperands(Inst, 1);
10084 ((AMDGPUOperand &)*
Operands[1]).addRegOperands(Inst, 1);
10087 ((AMDGPUOperand &)*
Operands[1]).addRegOperands(Inst, 1);
10088 ((AMDGPUOperand &)*
Operands[4]).addRegOperands(Inst, 1);
10090 OptionalImmIndexMap OptIdx;
10091 for (
unsigned i = 5; i <
Operands.size(); ++i) {
10092 AMDGPUOperand &
Op = ((AMDGPUOperand &)*
Operands[i]);
10093 OptIdx[
Op.getImmTy()] = i;
10098 AMDGPUOperand::ImmTyIndexKey8bit);
10102 AMDGPUOperand::ImmTyIndexKey16bit);
10106 AMDGPUOperand::ImmTyIndexKey32bit);
10123 SMLoc S = getLoc();
10126 Operands.push_back(AMDGPUOperand::CreateToken(
this,
"::", S));
10127 SMLoc OpYLoc = getLoc();
10130 Operands.push_back(AMDGPUOperand::CreateToken(
this, OpYName, OpYLoc));
10133 return Error(OpYLoc,
"expected a VOPDY instruction after ::");
10142 auto addOp = [&](uint16_t ParsedOprIdx) {
10143 AMDGPUOperand &
Op = ((AMDGPUOperand &)*
Operands[ParsedOprIdx]);
10145 Op.addRegOrImmWithFPInputModsOperands(Inst, 2);
10149 Op.addRegOperands(Inst, 1);
10152 if (
Op.isImm() ||
Op.isExpr()) {
10153 Op.addImmOperands(Inst, 1);
10165 addOp(InstInfo[CompIdx].getIndexOfDstInParsedOperands());
10169 const auto &CInfo = InstInfo[CompIdx];
10170 auto CompSrcOperandsNum = InstInfo[CompIdx].getCompParsedSrcOperandsNum();
10171 for (
unsigned CompSrcIdx = 0; CompSrcIdx < CompSrcOperandsNum; ++CompSrcIdx)
10172 addOp(CInfo.getIndexOfSrcInParsedOperands(CompSrcIdx));
10173 if (CInfo.hasSrc2Acc())
10174 addOp(CInfo.getIndexOfDstInParsedOperands());
10178 AMDGPU::getNamedOperandIdx(Inst.
getOpcode(), AMDGPU::OpName::bitop3);
10179 if (BitOp3Idx != -1) {
10180 OptionalImmIndexMap OptIdx;
10181 AMDGPUOperand &
Op = ((AMDGPUOperand &)*
Operands.back());
10183 OptIdx[
Op.getImmTy()] =
Operands.size() - 1;
10193bool AMDGPUOperand::isDPP8()
const {
return isImmTy(ImmTyDPP8); }
10195bool AMDGPUOperand::isDPPCtrl()
const {
10196 using namespace AMDGPU::DPP;
10198 bool result = isImm() && getImmTy() == ImmTyDppCtrl &&
isUInt<9>(
getImm());
10201 return (
Imm >= DppCtrl::QUAD_PERM_FIRST &&
10202 Imm <= DppCtrl::QUAD_PERM_LAST) ||
10203 (
Imm >= DppCtrl::ROW_SHL_FIRST &&
Imm <= DppCtrl::ROW_SHL_LAST) ||
10204 (
Imm >= DppCtrl::ROW_SHR_FIRST &&
Imm <= DppCtrl::ROW_SHR_LAST) ||
10205 (
Imm >= DppCtrl::ROW_ROR_FIRST &&
Imm <= DppCtrl::ROW_ROR_LAST) ||
10206 (
Imm == DppCtrl::WAVE_SHL1) || (
Imm == DppCtrl::WAVE_ROL1) ||
10207 (
Imm == DppCtrl::WAVE_SHR1) || (
Imm == DppCtrl::WAVE_ROR1) ||
10208 (
Imm == DppCtrl::ROW_MIRROR) || (
Imm == DppCtrl::ROW_HALF_MIRROR) ||
10209 (
Imm == DppCtrl::BCAST15) || (
Imm == DppCtrl::BCAST31) ||
10210 (
Imm >= DppCtrl::ROW_SHARE_FIRST &&
10211 Imm <= DppCtrl::ROW_SHARE_LAST) ||
10212 (
Imm >= DppCtrl::ROW_XMASK_FIRST &&
Imm <= DppCtrl::ROW_XMASK_LAST);
10221bool AMDGPUOperand::isBLGP()
const {
10225bool AMDGPUOperand::isS16Imm()
const {
10229bool AMDGPUOperand::isU16Imm()
const {
10237bool AMDGPUAsmParser::parseDimId(
unsigned &Encoding) {
10242 SMLoc Loc =
getToken().getEndLoc();
10243 Token = std::string(getTokenStr());
10245 if (getLoc() != Loc)
10250 if (!parseId(Suffix))
10254 StringRef DimId = Token;
10269 SMLoc S = getLoc();
10275 SMLoc Loc = getLoc();
10276 if (!parseDimId(Encoding))
10277 return Error(Loc,
"invalid dim value");
10280 AMDGPUOperand::CreateImm(
this, Encoding, S, AMDGPUOperand::ImmTyDim));
10289 SMLoc S = getLoc();
10298 if (!skipToken(
AsmToken::LBrac,
"expected an opening square bracket"))
10301 for (
size_t i = 0; i < 8; ++i) {
10305 SMLoc Loc = getLoc();
10306 if (getParser().parseAbsoluteExpression(Sels[i]))
10308 if (0 > Sels[i] || 7 < Sels[i])
10309 return Error(Loc,
"expected a 3-bit value");
10312 if (!skipToken(
AsmToken::RBrac,
"expected a closing square bracket"))
10316 for (
size_t i = 0; i < 8; ++i)
10317 DPP8 |= (Sels[i] << (i * 3));
10320 AMDGPUOperand::CreateImm(
this, DPP8, S, AMDGPUOperand::ImmTyDPP8));
10324bool AMDGPUAsmParser::isSupportedDPPCtrl(StringRef Ctrl,
10326 if (Ctrl ==
"row_newbcast")
10329 if (Ctrl ==
"row_share" || Ctrl ==
"row_xmask")
10332 if (Ctrl ==
"wave_shl" || Ctrl ==
"wave_shr" || Ctrl ==
"wave_rol" ||
10333 Ctrl ==
"wave_ror" || Ctrl ==
"row_bcast")
10336 return Ctrl ==
"row_mirror" ||
Ctrl ==
"row_half_mirror" ||
10337 Ctrl ==
"quad_perm" ||
Ctrl ==
"row_shl" ||
Ctrl ==
"row_shr" ||
10341int64_t AMDGPUAsmParser::parseDPPCtrlPerm() {
10344 if (!skipToken(
AsmToken::LBrac,
"expected an opening square bracket"))
10348 for (
int i = 0; i < 4; ++i) {
10353 SMLoc Loc = getLoc();
10354 if (getParser().parseAbsoluteExpression(Temp))
10356 if (Temp < 0 || Temp > 3) {
10357 Error(Loc,
"expected a 2-bit value");
10361 Val += (Temp << i * 2);
10364 if (!skipToken(
AsmToken::RBrac,
"expected a closing square bracket"))
10370int64_t AMDGPUAsmParser::parseDPPCtrlSel(StringRef Ctrl) {
10371 using namespace AMDGPU::DPP;
10376 SMLoc Loc = getLoc();
10378 if (getParser().parseAbsoluteExpression(Val))
10381 struct DppCtrlCheck {
10387 DppCtrlCheck
Check =
10388 StringSwitch<DppCtrlCheck>(Ctrl)
10389 .Case(
"wave_shl", {DppCtrl::WAVE_SHL1, 1, 1})
10390 .Case(
"wave_rol", {DppCtrl::WAVE_ROL1, 1, 1})
10391 .Case(
"wave_shr", {DppCtrl::WAVE_SHR1, 1, 1})
10392 .Case(
"wave_ror", {DppCtrl::WAVE_ROR1, 1, 1})
10393 .Case(
"row_shl", {DppCtrl::ROW_SHL0, 1, 15})
10394 .Case(
"row_shr", {DppCtrl::ROW_SHR0, 1, 15})
10395 .Case(
"row_ror", {DppCtrl::ROW_ROR0, 1, 15})
10396 .Case(
"row_share", {DppCtrl::ROW_SHARE_FIRST, 0, 15})
10397 .Case(
"row_xmask", {DppCtrl::ROW_XMASK_FIRST, 0, 15})
10398 .Case(
"row_newbcast", {DppCtrl::ROW_NEWBCAST_FIRST, 0, 15})
10402 if (
Check.Ctrl == -1) {
10403 Valid = (
Ctrl ==
"row_bcast" && (Val == 15 || Val == 31));
10411 Error(Loc, Twine(
"invalid ", Ctrl) + Twine(
" value"));
10419 using namespace AMDGPU::DPP;
10422 !isSupportedDPPCtrl(getTokenStr(),
Operands))
10425 SMLoc S = getLoc();
10431 if (Ctrl ==
"row_mirror") {
10432 Val = DppCtrl::ROW_MIRROR;
10433 }
else if (Ctrl ==
"row_half_mirror") {
10434 Val = DppCtrl::ROW_HALF_MIRROR;
10437 if (Ctrl ==
"quad_perm") {
10438 Val = parseDPPCtrlPerm();
10440 Val = parseDPPCtrlSel(Ctrl);
10449 AMDGPUOperand::CreateImm(
this, Val, S, AMDGPUOperand::ImmTyDppCtrl));
10455 OptionalImmIndexMap OptionalIdx;
10462 int OldIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::old);
10464 AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::src2_modifiers);
10465 bool IsMAC = OldIdx != -1 && Src2ModIdx != -1 &&
10469 for (
unsigned J = 0; J <
Desc.getNumDefs(); ++J) {
10470 ((AMDGPUOperand &)*
Operands[
I++]).addRegOperands(Inst, 1);
10474 int VdstInIdx = AMDGPU::getNamedOperandIdx(
Opc, AMDGPU::OpName::vdst_in);
10475 bool IsVOP3CvtSrDpp =
Opc == AMDGPU::V_CVT_SR_BF8_F32_gfx12_e64_dpp8_gfx12 ||
10476 Opc == AMDGPU::V_CVT_SR_BF8_F32_gfx12_e64_dpp8_gfx13 ||
10477 Opc == AMDGPU::V_CVT_SR_FP8_F32_gfx12_e64_dpp8_gfx12 ||
10478 Opc == AMDGPU::V_CVT_SR_FP8_F32_gfx12_e64_dpp8_gfx13 ||
10479 Opc == AMDGPU::V_CVT_SR_BF8_F32_gfx12_e64_dpp_gfx12 ||
10480 Opc == AMDGPU::V_CVT_SR_BF8_F32_gfx12_e64_dpp_gfx13 ||
10481 Opc == AMDGPU::V_CVT_SR_FP8_F32_gfx12_e64_dpp_gfx12 ||
10482 Opc == AMDGPU::V_CVT_SR_FP8_F32_gfx12_e64_dpp_gfx13;
10488 if (OldIdx == NumOperands) {
10490 constexpr int DST_IDX = 0;
10492 }
else if (Src2ModIdx == NumOperands) {
10502 if (IsVOP3CvtSrDpp) {
10511 if (TiedTo != -1) {
10516 AMDGPUOperand &
Op = ((AMDGPUOperand &)*
Operands[
I]);
10518 if (IsDPP8 &&
Op.isDppFI()) {
10521 Op.addRegOrImmWithFPInputModsOperands(Inst, 2);
10522 }
else if (
Op.isReg()) {
10523 Op.addRegOperands(Inst, 1);
10524 }
else if (
Op.isImm() &&
10526 Op.addImmOperands(Inst, 1);
10527 }
else if (
Op.isImm()) {
10528 OptionalIdx[
Op.getImmTy()] =
I;
10536 AMDGPUOperand::ImmTyClamp);
10542 AMDGPUOperand::ImmTyByteSel);
10547 AMDGPUOperand::ImmTyOModSI);
10550 cvtVOP3P(Inst,
Operands, OptionalIdx);
10552 cvtVOP3OpSel(Inst,
Operands, OptionalIdx);
10555 AMDGPUOperand::ImmTyOpSel);
10560 AMDGPUOperand::ImmTyDPP8);
10561 using namespace llvm::AMDGPU::DPP;
10565 AMDGPUOperand::ImmTyDppCtrl, 0xe4);
10567 AMDGPUOperand::ImmTyDppRowMask, 0xf);
10569 AMDGPUOperand::ImmTyDppBankMask, 0xf);
10571 AMDGPUOperand::ImmTyDppBoundCtrl);
10575 AMDGPUOperand::ImmTyDppFI);
10581 OptionalImmIndexMap OptionalIdx;
10585 for (
unsigned J = 0; J <
Desc.getNumDefs(); ++J) {
10586 ((AMDGPUOperand &)*
Operands[
I++]).addRegOperands(Inst, 1);
10593 if (TiedTo != -1) {
10598 AMDGPUOperand &
Op = ((AMDGPUOperand &)*
Operands[
I]);
10600 if (
Op.isReg() && validateVccOperand(
Op.getReg())) {
10608 Op.addImmOperands(Inst, 1);
10610 Op.addRegWithFPInputModsOperands(Inst, 2);
10611 }
else if (
Op.isDppFI()) {
10613 }
else if (
Op.isReg()) {
10614 Op.addRegOperands(Inst, 1);
10620 Op.addRegWithFPInputModsOperands(Inst, 2);
10621 }
else if (
Op.isReg()) {
10622 Op.addRegOperands(Inst, 1);
10623 }
else if (
Op.isDPPCtrl()) {
10624 Op.addImmOperands(Inst, 1);
10625 }
else if (
Op.isImm()) {
10627 OptionalIdx[
Op.getImmTy()] =
I;
10635 using namespace llvm::AMDGPU::DPP;
10639 AMDGPUOperand::ImmTyDppRowMask, 0xf);
10641 AMDGPUOperand::ImmTyDppBankMask, 0xf);
10643 AMDGPUOperand::ImmTyDppBoundCtrl);
10646 AMDGPUOperand::ImmTyDppFI);
10657 AMDGPUOperand::ImmTy
Type) {
10658 return parseStringOrIntWithPrefix(
10660 {
"BYTE_0",
"BYTE_1",
"BYTE_2",
"BYTE_3",
"WORD_0",
"WORD_1",
"DWORD"},
10665 return parseStringOrIntWithPrefix(
10666 Operands,
"dst_unused", {
"UNUSED_PAD",
"UNUSED_SEXT",
"UNUSED_PRESERVE"},
10667 AMDGPUOperand::ImmTySDWADstUnused);
10671 cvtSDWA(Inst,
Operands, SDWAInstType::VOP1);
10675 cvtSDWA(Inst,
Operands, SDWAInstType::VOP2);
10678void AMDGPUAsmParser::cvtSdwaVOP2b(MCInst &Inst,
10680 cvtSDWA(Inst,
Operands, SDWAInstType::VOP2,
true,
true);
10683void AMDGPUAsmParser::cvtSdwaVOP2e(MCInst &Inst,
10685 cvtSDWA(Inst,
Operands, SDWAInstType::VOP2,
false,
true);
10693 SDWAInstType BasicInstType,
bool SkipDstVcc,
10695 using namespace llvm::AMDGPU::SDWA;
10697 OptionalImmIndexMap OptionalIdx;
10698 bool SkipVcc = SkipDstVcc || SkipSrcVcc;
10699 bool SkippedVcc =
false;
10703 for (
unsigned J = 0; J <
Desc.getNumDefs(); ++J) {
10704 ((AMDGPUOperand &)*
Operands[
I++]).addRegOperands(Inst, 1);
10708 AMDGPUOperand &
Op = ((AMDGPUOperand &)*
Operands[
I]);
10709 if (SkipVcc && !SkippedVcc &&
Op.isReg() &&
10710 (
Op.getReg() == AMDGPU::VCC ||
Op.getReg() == AMDGPU::VCC_LO)) {
10716 if (BasicInstType == SDWAInstType::VOP2 &&
10722 if (BasicInstType == SDWAInstType::VOPC && Inst.
getNumOperands() == 0) {
10728 Op.addRegOrImmWithInputModsOperands(Inst, 2);
10729 }
else if (
Op.isImm()) {
10731 OptionalIdx[
Op.getImmTy()] =
I;
10735 SkippedVcc =
false;
10739 if (
Opc != AMDGPU::V_NOP_sdwa_gfx10 &&
Opc != AMDGPU::V_NOP_sdwa_gfx9 &&
10740 Opc != AMDGPU::V_NOP_sdwa_vi) {
10742 switch (BasicInstType) {
10743 case SDWAInstType::VOP1:
10746 AMDGPUOperand::ImmTyClamp, 0);
10750 AMDGPUOperand::ImmTyOModSI, 0);
10754 AMDGPUOperand::ImmTySDWADstSel, SdwaSel::DWORD);
10758 AMDGPUOperand::ImmTySDWADstUnused,
10759 DstUnused::UNUSED_PRESERVE);
10762 AMDGPUOperand::ImmTySDWASrc0Sel, SdwaSel::DWORD);
10765 case SDWAInstType::VOP2:
10767 AMDGPUOperand::ImmTyClamp, 0);
10771 AMDGPUOperand::ImmTyOModSI, 0);
10774 AMDGPUOperand::ImmTySDWADstSel, SdwaSel::DWORD);
10776 AMDGPUOperand::ImmTySDWADstUnused,
10777 DstUnused::UNUSED_PRESERVE);
10779 AMDGPUOperand::ImmTySDWASrc0Sel, SdwaSel::DWORD);
10781 AMDGPUOperand::ImmTySDWASrc1Sel, SdwaSel::DWORD);
10784 case SDWAInstType::VOPC:
10787 AMDGPUOperand::ImmTyClamp, 0);
10789 AMDGPUOperand::ImmTySDWASrc0Sel, SdwaSel::DWORD);
10791 AMDGPUOperand::ImmTySDWASrc1Sel, SdwaSel::DWORD);
10798 if (Inst.
getOpcode() == AMDGPU::V_MAC_F32_sdwa_vi ||
10799 Inst.
getOpcode() == AMDGPU::V_MAC_F16_sdwa_vi) {
10800 auto *it = Inst.
begin();
10802 it, AMDGPU::getNamedOperandIdx(Inst.
getOpcode(), AMDGPU::OpName::src2));
10815#define GET_MATCHER_IMPLEMENTATION
10816#define GET_MNEMONIC_SPELL_CHECKER
10817#define GET_MNEMONIC_CHECKER
10818#include "AMDGPUGenAsmMatcher.inc"
10824 return parseTokenOp(
"addr64",
Operands);
10826 return parseTokenOp(
"idxen",
Operands);
10828 return parseNamedBit(
"lds",
Operands, AMDGPUOperand::ImmTyLDS,
10831 return parseTokenOp(
"offen",
Operands);
10833 return parseTokenOp(
"off",
Operands);
10835 return parseNamedBit(
"gds",
Operands, AMDGPUOperand::ImmTyGDS);
10837 return parseNamedBit(
"tfe",
Operands, AMDGPUOperand::ImmTyTFE);
10839 return tryCustomParseOperand(
Operands, MCK);
10845AMDGPUAsmParser::validateTargetOperandClass(
const MCParsedAsmOperand &
Op,
10851 const AMDGPUOperand &Operand =
static_cast<const AMDGPUOperand &
>(
Op);
10854 return Operand.isAddr64() ? Match_Success : Match_InvalidOperand;
10856 return Operand.isGDS() ? Match_Success : Match_InvalidOperand;
10858 return Operand.isLDS() ? Match_Success : Match_InvalidOperand;
10860 return Operand.isIdxen() ? Match_Success : Match_InvalidOperand;
10862 return Operand.isOffen() ? Match_Success : Match_InvalidOperand;
10864 return Operand.isTFE() ? Match_Success : Match_InvalidOperand;
10872 return Operand.isSSrc_b32() ? Match_Success : Match_InvalidOperand;
10874 return Operand.isSSrc_f32() ? Match_Success : Match_InvalidOperand;
10875 case MCK_SOPPBrTarget:
10876 return Operand.isSOPPBrTarget() ? Match_Success : Match_InvalidOperand;
10877 case MCK_VReg32OrOff:
10878 return Operand.isVReg32OrOff() ? Match_Success : Match_InvalidOperand;
10879 case MCK_InterpSlot:
10880 return Operand.isInterpSlot() ? Match_Success : Match_InvalidOperand;
10881 case MCK_InterpAttr:
10882 return Operand.isInterpAttr() ? Match_Success : Match_InvalidOperand;
10883 case MCK_InterpAttrChan:
10884 return Operand.isInterpAttrChan() ? Match_Success : Match_InvalidOperand;
10886 case MCK_SReg_64_XEXEC:
10896 return Operand.isNull() ? Match_Success : Match_InvalidOperand;
10898 return Match_InvalidOperand;
10907 SMLoc S = getLoc();
10916 return Error(S,
"expected a 16-bit value");
10919 AMDGPUOperand::CreateImm(
this,
Imm, S, AMDGPUOperand::ImmTyEndpgm));
10923bool AMDGPUOperand::isEndpgm()
const {
return isImmTy(ImmTyEndpgm); }
10929bool AMDGPUOperand::isSplitBarrier()
const {
static const TargetRegisterClass * getRegClass(const MachineInstr &MI, Register Reg)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
SmallVector< int16_t, MAX_SRC_OPERANDS_NUM > OperandIndices
static bool checkWriteLane(const MCInst &Inst)
static bool getRegNum(StringRef Str, unsigned &Num)
static void addSrcModifiersAndSrc(MCInst &Inst, const OperandVector &Operands, unsigned i, unsigned Opc, AMDGPU::OpName OpName)
static constexpr RegInfo RegularRegisters[]
static const RegInfo * getRegularRegInfo(StringRef Str)
static ArrayRef< unsigned > getAllVariants()
static OperandIndices getSrcOperandIndices(unsigned Opcode, bool AddMandatoryLiterals=false)
static int IsAGPROperand(const MCInst &Inst, AMDGPU::OpName Name, const MCRegisterInfo *MRI)
static bool IsMovrelsSDWAOpcode(const unsigned Opcode)
static const fltSemantics * getFltSemantics(unsigned Size)
static bool isRegularReg(RegisterKind Kind)
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUAsmParser()
Force static initialization.
static bool ConvertOmodMul(int64_t &Mul)
#define PARSE_BITS_ENTRY(FIELD, ENTRY, VALUE, RANGE)
static bool isInlineableLiteralOp16(int64_t Val, MVT VT, bool HasInv2Pi)
static bool canLosslesslyConvertToFPType(APFloat &FPLiteral, MVT VT)
static bool AMDGPUCheckMnemonic(StringRef Mnemonic, const FeatureBitset &AvailableFeatures, unsigned VariantID)
static void applyMnemonicAliases(StringRef &Mnemonic, const FeatureBitset &Features, unsigned VariantID)
constexpr unsigned MAX_SRC_OPERANDS_NUM
#define EXPR_RESOLVE_OR_ERROR(RESOLVED)
static bool ConvertOmodDiv(int64_t &Div)
static bool IsRevOpcode(const unsigned Opcode)
static bool encodeCnt(const AMDGPU::IsaVersion ISA, int64_t &IntVal, int64_t CntVal, bool Saturate, unsigned(*encode)(const IsaVersion &Version, unsigned, unsigned), unsigned(*decode)(const IsaVersion &Version, unsigned))
static MCRegister getSpecialRegForName(StringRef RegName)
static void addOptionalImmOperand(MCInst &Inst, const OperandVector &Operands, AMDGPUAsmParser::OptionalImmIndexMap &OptionalIdx, AMDGPUOperand::ImmTy ImmT, int64_t Default=0, std::optional< unsigned > InsertAt=std::nullopt)
static void cvtVOP3DstOpSelOnly(MCInst &Inst, const MCRegisterInfo &MRI)
static bool isRegOrImmWithInputMods(const MCInstrDesc &Desc, unsigned OpNum)
static const fltSemantics * getOpFltSemantics(uint8_t OperandType)
static bool isInvalidVOPDY(const OperandVector &Operands, uint64_t InvalidOprIdx)
static std::string AMDGPUMnemonicSpellCheck(StringRef S, const FeatureBitset &FBS, unsigned VariantID=0)
static LLVM_READNONE unsigned encodeBitmaskPerm(const unsigned AndMask, const unsigned OrMask, const unsigned XorMask)
static bool isSafeTruncation(int64_t Val, unsigned Size)
AMDHSA kernel descriptor MCExpr struct for use in MC layer.
Provides AMDGPU specific target descriptions.
Enums shared between the AMDGPU backend (LLVM) and the ELF linker (LLD) for the .amdgpu....
AMDHSA kernel descriptor definitions.
static bool parseExpr(MCAsmParser &MCParser, const MCExpr *&Value, raw_ostream &Err)
MC layer struct for AMDGPUMCKernelCodeT, provides MCExpr functionality where required.
@ AMD_CODE_PROPERTY_ENABLE_WAVEFRONT_SIZE32
This file declares a class to represent arbitrary precision floating point values and provide a varie...
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_EXTERNAL_VISIBILITY
static llvm::Expected< InlineInfo > decode(GsymDataExtractor &Data, uint64_t &Offset, uint64_t BaseAddr)
Decode an InlineInfo in Data at the specified offset.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
Loop::LoopBounds::Direction Direction
static bool hasFeature(StringRef Feature, const FeatureBitset &FeatureBits, ArrayRef< SubtargetFeatureKV > ProcFeatures)
Register const TargetRegisterInfo * TRI
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
static bool isReg(const MCInst &MI, unsigned OpNo)
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
MachineRegisterInfo & MRI
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
Interface definition for SIInstrInfo.
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
This file implements the SmallBitVector class.
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, const llvm::StringTable &StandardNames, VectorLibrary VecLib)
Initialize the set of available library functions based on the specified target triple.
static Triple::ObjectFormatType parseFormat(StringRef EnvironmentName)
static const char * getRegisterName(MCRegister Reg)
static const AMDGPUMCExpr * createMax(ArrayRef< const MCExpr * > Args, MCContext &Ctx)
static unsigned getNumExpectedArgs(VariantKind Kind)
static const AMDGPUMCExpr * createLit(LitModifier Lit, int64_t Value, MCContext &Ctx)
static const AMDGPUMCExpr * create(VariantKind Kind, ArrayRef< const MCExpr * > Args, MCContext &Ctx)
static const AMDGPUMCExpr * createExtraSGPRs(const MCExpr *VCCUsed, const MCExpr *FlatScrUsed, bool XNACKUsed, MCContext &Ctx)
Allow delayed MCExpr resolve of ExtraSGPRs (in case VCCUsed or FlatScrUsed are unresolvable but neede...
static const AMDGPUMCExpr * createAlignTo(const MCExpr *Value, const MCExpr *Align, MCContext &Ctx)
static std::optional< TargetID > parseTargetIDString(StringRef TargetIDDirective)
Parse and validate a TargetID from a full "<triple>-<processor>:<features>" directive string.
TargetIDSetting getXnackSetting() const
GPUKind getGPUKind() const
StringRef getTargetTripleString() const
std::string toString() const
TargetIDSetting getSramEccSetting() const
static constexpr roundingMode rmNearestTiesToEven
static constexpr const fltSemantics & IEEEhalf()
static constexpr const fltSemantics & IEEEsingle()
static constexpr const fltSemantics & BFloat()
static constexpr const fltSemantics & IEEEdouble()
opStatus
IEEE-754R 7: Default exception handling.
LLVM_ABI opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
ArrayRef< T > take_front(size_t N=1) const
Return a copy of *this with only the first N elements.
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
const T & front() const
Get the first element.
size_t size() const
Get the array size.
bool empty() const
Check if the array is empty.
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
bool is(TokenKind K) const
Container class for subtarget features.
constexpr bool test(unsigned I) const
constexpr FeatureBitset & flip(unsigned I)
void printExpr(raw_ostream &, const MCExpr &) const
virtual void Initialize(MCAsmParser &Parser)
Initialize the extension for parsing using the given Parser.
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
static const MCBinaryExpr * createDiv(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Context object for machine code objects.
LLVM_ABI MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Instances of this class represent a single low-level machine instruction.
unsigned getNumOperands() const
unsigned getOpcode() const
iterator insert(iterator I, const MCOperand &Op)
void addOperand(const MCOperand Op)
const MCOperand & getOperand(unsigned i) const
Describe properties that are true of each instruction in the target description file.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
const int16_t * getRegClassByHwModeTable(unsigned ModeId) const
int16_t getOpRegClassID(const MCOperandInfo &OpInfo, unsigned HwModeId) const
Return the ID of the register class to use for OpInfo, for the active HwMode HwModeId.
Instances of this class represent operands of the MCInst class.
static MCOperand createExpr(const MCExpr *Val)
static MCOperand createReg(MCRegister Reg)
static MCOperand createImm(int64_t Val)
void setReg(MCRegister Reg)
Set the register number.
MCRegister getReg() const
Returns the register number.
const MCExpr * getExpr() const
MCParsedAsmOperand - This abstract class represents a source-level assembly instruction operand.
MCRegisterClass - Base class of TargetRegisterClass.
MCRegister getRegister(unsigned i) const
getRegister - Return the specified register in the class.
unsigned getNumRegs() const
getNumRegs - Return the number of registers in this class.
bool contains(MCRegister Reg) const
contains - Return true if the specified register is included in this register class.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Wrapper class representing physical registers and target specific virtual registers.
constexpr bool isValid() const
Generic base class for all target subtargets.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
StringRef getName() const
getName - Get the symbol name.
bool isVariable() const
isVariable - Check if this is a variable symbol.
LLVM_ABI void setVariableValue(const MCExpr *Value)
void setRedefinable(bool Value)
Mark this symbol as redefinable.
const MCExpr * getVariableValue() const
Get the expression of the variable symbol.
MCTargetAsmParser - Generic interface to target specific assembly parsers.
uint64_t getScalarSizeInBits() const
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
MVT getScalarType() const
If this is a vector, return the element type, otherwise return this.
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
Ternary parse status returned by various parse* methods.
constexpr bool isFailure() const
static constexpr StatusTy Failure
constexpr bool isSuccess() const
static constexpr StatusTy Success
static constexpr StatusTy NoMatch
constexpr bool isNoMatch() const
constexpr unsigned id() const
Represents a location in source code.
static SMLoc getFromPointer(const char *Ptr)
constexpr const char * getPointer() const
constexpr bool isValid() const
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool contains(ConstPtrType Ptr) const
reference emplace_back(ArgTypes &&... Args)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Represent a constant reference to a string, i.e.
bool consume_back(StringRef Suffix)
Returns true if this StringRef has the given suffix and removes that suffix.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
Check if the string is empty.
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
constexpr size_t size() const
Get the string size.
constexpr const char * data() const
Get a pointer to the start of the string (which may not be null terminated).
bool ends_with(StringRef Suffix) const
Check if this string ends with the given Suffix.
bool consume_front(char Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
bool contains(StringRef key) const
Check if the set contains the given key.
std::pair< typename Base::iterator, bool > insert(StringRef key)
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM_ABI std::string str() const
Return the twine contents as a std::string.
std::pair< iterator, bool > insert(const ValueT &V)
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
int encodeDepCtr(const StringRef Name, int64_t Val, unsigned &UsedOprMask, const MCSubtargetInfo &STI)
int getDefaultDepCtrEncoding(const MCSubtargetInfo &STI)
bool isSupportedTgtId(unsigned Id, const MCSubtargetInfo &STI)
unsigned getTgtId(const StringRef Name)
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
constexpr char NumSGPRs[]
Key for Kernel::CodeProps::Metadata::mNumSGPRs.
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
constexpr char AssemblerDirectiveBegin[]
HSA metadata beginning assembler directive.
constexpr char AssemblerDirectiveEnd[]
HSA metadata ending assembler directive.
constexpr char AssemblerDirectiveBegin[]
Old HSA metadata beginning assembler directive for V2.
int64_t getHwregId(StringRef Name, const MCSubtargetInfo &STI)
@ FIXED_NUM_SGPRS_FOR_INIT_BUG
unsigned getVGPREncodingGranule(const MCSubtargetInfo &STI, std::optional< bool > EnableWavefrontSize32)
unsigned getSGPREncodingGranule(const MCSubtargetInfo &STI)
bool targetIDSettingsConflict(TargetIDSetting Lhs, TargetIDSetting Rhs)
Returns true if Lhs and Rhs are incompatible (both specific but different).
unsigned getLocalMemorySize(const MCSubtargetInfo &STI)
constexpr char AssemblerDirective[]
PAL metadata (old linear format) assembler directive.
constexpr char AssemblerDirectiveBegin[]
PAL metadata (new MsgPack format) beginning assembler directive.
constexpr char AssemblerDirectiveEnd[]
PAL metadata (new MsgPack format) ending assembler directive.
int64_t getMsgOpId(int64_t MsgId, StringRef Name, const MCSubtargetInfo &STI)
Map from a symbolic name for a sendmsg operation to the operation portion of the immediate encoding.
int64_t getMsgId(StringRef Name, const MCSubtargetInfo &STI)
Map from a symbolic name for a msg_id to the message portion of the immediate encoding.
uint64_t encodeMsg(uint64_t MsgId, uint64_t OpId, uint64_t StreamId)
bool msgSupportsStream(int64_t MsgId, int64_t OpId, const MCSubtargetInfo &STI)
bool isValidMsgId(int64_t MsgId, const MCSubtargetInfo &STI)
bool isValidMsgStream(int64_t MsgId, int64_t OpId, int64_t StreamId, const MCSubtargetInfo &STI, bool Strict)
bool msgRequiresOp(int64_t MsgId, const MCSubtargetInfo &STI)
bool isValidMsgOp(int64_t MsgId, int64_t OpId, const MCSubtargetInfo &STI, bool Strict)
ArrayRef< GFXVersion > getGFXVersions()
constexpr unsigned COMPONENTS[]
constexpr const char *const ModMatrixFmt[]
constexpr const char *const ModMatrixScaleFmt[]
constexpr const char *const ModMatrixScale[]
bool isInlineValue(MCRegister Reg)
bool isPKFMACF16InlineConstant(uint32_t Literal, bool IsGFX11Plus)
LLVM_READONLY const MIMGInfo * getMIMGInfo(unsigned Opc)
bool isInlinableLiteralFP16(int16_t Literal, bool HasInv2Pi)
bool isSGPR(MCRegister Reg, const MCRegisterInfo *TRI)
Is Reg - scalar register.
MCRegister getMCReg(MCRegister Reg, const MCSubtargetInfo &STI)
If Reg is a pseudo reg, return the correct hardware register given STI otherwise return Reg.
FuncInfoFlags
Per-function flags packed into INFO_FLAGS entries.
uint8_t wmmaScaleF8F6F4FormatToNumRegs(unsigned Fmt)
const int OPR_ID_UNSUPPORTED
bool isInlinableLiteralV2I16(uint32_t Literal)
bool isHi16Reg(MCRegister Reg, const MCRegisterInfo &MRI)
unsigned getTemporalHintType(const MCInstrDesc TID)
static AMDGPUMCExpr::Specifier getSpecifier(const MCSymbolRefExpr *SRE)
LLVM_READONLY bool isLitExpr(const MCExpr *Expr)
bool isInlinableLiteralV2BF16(uint32_t Literal)
LLVM_ABI bool isCPUValidForSubArch(Triple::SubArchType SubArch, GPUKind AK)
Return true if the GPU AK is usable with the triple subarch SubArch.
unsigned getMaxNumUserSGPRs(const MCSubtargetInfo &STI)
unsigned getNumFlatOffsetBits(const MCSubtargetInfo &ST)
For pre-GFX12 FLAT instructions the offset must be positive; MSB is ignored and forced to zero.
bool hasA16(const MCSubtargetInfo &STI)
bool isLegalSMRDEncodedSignedOffset(const MCSubtargetInfo &ST, int64_t EncodedOffset, bool IsBuffer)
bool isGFX12Plus(const MCSubtargetInfo &STI)
unsigned getNSAMaxSize(const MCSubtargetInfo &STI, bool HasSampler)
bool hasPackedD16(const MCSubtargetInfo &STI)
bool isGFX940(const MCSubtargetInfo &STI)
bool isInlinableLiteralV2F16(uint32_t Literal)
bool isHsaAbi(const MCSubtargetInfo &STI)
bool isGFX11(const MCSubtargetInfo &STI)
const int OPR_VAL_INVALID
bool getSMEMIsBuffer(unsigned Opc)
bool isPackedSingleSGPRFP32Inst(unsigned Opc)
The opcode is a packed fp32 instruction which only reads low 32 bits of a scalar operand and propagat...
LLVM_ABI unsigned getAddressableNumSGPRs(GPUKind AK)
uint8_t mfmaScaleF8F6F4FormatToNumRegs(unsigned EncodingVal)
LLVM_ABI IsaVersion getIsaVersion(StringRef GPU)
unsigned getRegBitWidth(unsigned RCID)
Get the size in bits of a register from the register class RC.
bool isValid32BitLiteral(uint64_t Val, bool IsFP64)
LLVM_ABI unsigned getTotalNumVGPRs(GPUKind AK, bool IsWave32)
CanBeVOPD getCanBeVOPD(unsigned Opc, unsigned EncodingFamily, bool VOPD3)
LLVM_READNONE bool isLegalDPALU_DPPControl(const MCSubtargetInfo &ST, unsigned DC)
bool isVOP3DPPSrc1RevOpc(const MCSubtargetInfo &STI, unsigned Opc)
bool isSI(const MCSubtargetInfo &STI)
bool hasPrivateApertureRegs(const MCSubtargetInfo &STI)
unsigned decodeLgkmcnt(const IsaVersion &Version, unsigned Waitcnt)
unsigned getWaitcntBitMask(const IsaVersion &Version)
bool isGFX9(const MCSubtargetInfo &STI)
unsigned getVOPDEncodingFamily(const MCSubtargetInfo &ST)
LLVM_READONLY bool hasNamedOperand(uint32_t Opcode, OpName NamedIdx)
bool isKImmOperand(const MCInstrDesc &Desc, unsigned OpNo)
Is this a KImm operand?
GPUKind
GPU kinds supported by the AMDGPU target.
bool isGFX90A(const MCSubtargetInfo &STI)
LLVM_READONLY const MIMGDimInfo * getMIMGDimInfoByEncoding(uint8_t DimEnc)
bool isInlinableLiteral32(int32_t Literal, bool HasInv2Pi)
bool isGFX12(const MCSubtargetInfo &STI)
unsigned encodeExpcnt(const IsaVersion &Version, unsigned Waitcnt, unsigned Expcnt)
bool hasMAIInsts(const MCSubtargetInfo &STI)
constexpr bool isSISrcOperand(const MCOperandInfo &OpInfo)
Is this an AMDGPU specific source operand?
bool isInlinableLiteralBF16(int16_t Literal, bool HasInv2Pi, bool *IsBF16)
LLVM_READONLY const MIMGDimInfo * getMIMGDimInfoByAsmSuffix(StringRef AsmSuffix)
bool hasMIMG_R128(const MCSubtargetInfo &STI)
LLVM_ABI GPUKind parseArchAMDGCN(StringRef CPU)
bool hasG16(const MCSubtargetInfo &STI)
unsigned getAddrSizeMIMGOp(const MIMGBaseOpcodeInfo *BaseOpcode, const MIMGDimInfo *Dim, bool IsA16, bool IsG16Supported)
bool hasArchitectedFlatScratch(const MCSubtargetInfo &STI)
LLVM_READONLY int64_t getLitValue(const MCExpr *Expr)
bool isGFX11Plus(const MCSubtargetInfo &STI)
bool isSISrcFPOperand(const MCInstrDesc &Desc, unsigned OpNo)
Is this floating-point operand?
bool isGFX10Plus(const MCSubtargetInfo &STI)
AMDGPU::TargetID TargetID
int64_t encode32BitLiteral(int64_t Imm, OperandType Type, bool IsLit)
bool isValidWMMAScaleFmtCombination(unsigned AFmt, unsigned AScale, unsigned BFmt, unsigned BScale)
@ OPERAND_KIMM32
Operand with 32-bit immediate that uses the constant bus.
@ OPERAND_REG_INLINE_C_FP64
@ OPERAND_REG_IMM_NOINLINE_FP16
@ OPERAND_REG_INLINE_C_BF16
@ OPERAND_REG_INLINE_C_V2BF16
@ OPERAND_REG_IMM_V2INT64
@ OPERAND_REG_IMM_V2INT16
@ OPERAND_REG_IMM_INT32
Operands with register, 32-bit, or 64-bit immediate.
@ OPERAND_REG_IMM_V2FP16_SPLAT
@ OPERAND_REG_INLINE_C_INT64
@ OPERAND_REG_INLINE_C_INT16
Operands with register or inline constant.
@ OPERAND_REG_IMM_NOINLINE_V2FP16
@ OPERAND_REG_INLINE_C_V2FP16
@ OPERAND_REG_INLINE_AC_INT32
Operands with an AccVGPR register or inline constant.
@ OPERAND_REG_INLINE_AC_FP32
@ OPERAND_REG_IMM_V2INT32
@ OPERAND_REG_INLINE_C_FP32
@ OPERAND_REG_INLINE_C_INT32
@ OPERAND_REG_INLINE_C_V2INT16
@ OPERAND_REG_INLINE_AC_FP64
@ OPERAND_REG_INLINE_C_FP16
@ OPERAND_INLINE_SPLIT_BARRIER_INT32
constexpr bool isBF16SrcOperand(const MCOperandInfo &OpInfo)
Is this a scalar (i.e. not packed) bf16 source operand?
bool isDPALU_DPP(const MCInstrDesc &OpDesc, const MCInstrInfo &MII, const MCSubtargetInfo &ST)
LLVM_ABI StringRef getArchNameAMDGCN(GPUKind AK)
bool hasGDS(const MCSubtargetInfo &STI)
bool isLegalSMRDEncodedUnsignedOffset(const MCSubtargetInfo &ST, int64_t EncodedOffset)
bool isGFX9Plus(const MCSubtargetInfo &STI)
bool hasDPPSrc1SGPR(const MCSubtargetInfo &STI)
const int OPR_ID_DUPLICATE
bool isVOPD(unsigned Opc)
VOPD::InstInfo getVOPDInstInfo(const MCInstrDesc &OpX, const MCInstrDesc &OpY)
unsigned encodeVmcnt(const IsaVersion &Version, unsigned Waitcnt, unsigned Vmcnt)
unsigned decodeExpcnt(const IsaVersion &Version, unsigned Waitcnt)
const MIMGBaseOpcodeInfo * getMIMGBaseOpcode(unsigned Opc)
bool isVI(const MCSubtargetInfo &STI)
bool supportsScaleOffset(const MCInstrInfo &MII, unsigned Opcode)
MCRegister mc2PseudoReg(MCRegister Reg)
Convert hardware register Reg to a pseudo register.
unsigned hasKernargPreload(const MCSubtargetInfo &STI)
bool supportsWGP(const MCSubtargetInfo &STI)
LLVM_READNONE unsigned getOperandSize(const MCOperandInfo &OpInfo)
bool isCI(const MCSubtargetInfo &STI)
unsigned encodeLgkmcnt(const IsaVersion &Version, unsigned Waitcnt, unsigned Lgkmcnt)
LLVM_READONLY const MIMGBaseOpcodeInfo * getMIMGBaseOpcodeInfo(unsigned BaseOpcode)
bool isGFX1250Plus(const MCSubtargetInfo &STI)
bool hasPopsExitingWaveID(const MCSubtargetInfo &STI)
unsigned decodeVmcnt(const IsaVersion &Version, unsigned Waitcnt)
bool isInlinableLiteralI16(int32_t Literal, bool HasInv2Pi)
bool hasVOPD(const MCSubtargetInfo &STI)
bool isInlinableLiteral64(int64_t Literal, bool HasInv2Pi)
Is this literal inlinable.
bool isPermlane16(unsigned Opc)
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
@ UNDEF
UNDEF - An undefined node.
Predicate getPredicate(unsigned Condition, unsigned Hint)
Return predicate consisting of specified condition and hint bits.
void validate(const Triple &TT, const FeatureBitset &FeatureBits)
constexpr bool isAtomicRet(const T &...O)
constexpr bool isVOPC(const T &...O)
constexpr bool isVOP3(const T &...O)
constexpr bool isVOP1(const T &...O)
constexpr bool usesTENSOR_CNT(const T &...O)
constexpr bool isMAI(const T &...O)
constexpr bool isVOP2(const T &...O)
constexpr bool isSWMMAC(const T &...O)
constexpr bool isSOP2(const T &...O)
constexpr bool isFLAT(const T &...O)
constexpr bool isVOP3P(const T &...O)
constexpr bool isBuffer(const T &...O)
constexpr bool hasIntClamp(const T &...O)
constexpr bool isAtomicNoRet(const T &...O)
constexpr bool isSMRD(const T &...O)
constexpr bool isVOP3Like(const T &...O)
constexpr bool isMIMG(const T &...O)
constexpr bool isVMEM(const T &...O)
constexpr bool isImage(const T &...O)
constexpr bool isWMMA(const T &...O)
constexpr bool isVOPD3(const T &...O)
constexpr bool isGWS(const T &...O)
constexpr bool isMUBUF(const T &...O)
constexpr bool isSDWA(const T &...O)
constexpr bool isSOPC(const T &...O)
constexpr bool isDOT(const T &...O)
constexpr bool isVSAMPLE(const T &...O)
constexpr bool isDS(const T &...O)
constexpr bool isAtomic(const T &...O)
constexpr bool isGather4(const T &...O)
constexpr bool isPacked(const T &...O)
constexpr bool isDPP(const T &...O)
constexpr bool isSegmentSpecificFLAT(const T &...O)
@ Valid
The data is already valid.
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface o...
EnumSet< Modifier > Modifiers
unsigned getOpcode(const VPValue *V)
Return the instruction opcode for the recipe defining V or 0 for unsupported recipes and VPValues not...
This is an optimization pass for GlobalISel generic memory operations.
bool errorToBool(Error Err)
Helper for converting an Error to a bool.
StringMapEntry< Value * > ValueName
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
unsigned encode(MaybeAlign A)
Returns a representation of the alignment that encodes undefined as 0.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
static bool isMem(const MachineInstr &MI, unsigned Op)
LLVM_ABI std::pair< StringRef, StringRef > getToken(StringRef Source, StringRef Delimiters=" \t\n\v\f\r")
getToken - This function extracts one token from source, ignoring any leading characters that appear ...
static StringRef getCPU(StringRef CPU)
Processes a CPU name.
testing::Matcher< const detail::ErrorHolder & > Failed()
LLVM_ABI void PrintError(const Twine &Msg)
constexpr bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
T bit_ceil(T Value)
Returns the smallest integral power of two no smaller than Value if Value is nonzero.
Target & getTheR600Target()
The target for R600 GPUs.
constexpr int popcount(T Value) noexcept
Count the number of set bits in a value.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
SmallVectorImpl< std::unique_ptr< MCParsedAsmOperand > > OperandVector
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
constexpr uint32_t Hi_32(uint64_t Value)
Return the high 32 bits of a 64 bit value.
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
constexpr uint32_t Lo_32(uint64_t Value)
Return the low 32 bits of a 64 bit value.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
MutableArrayRef(T &OneElt) -> MutableArrayRef< T >
constexpr T divideCeil(U Numerator, V Denominator)
Returns the integer ceil(Numerator / Denominator).
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
Target & getTheGCNTarget()
The target for GCN GPUs.
@ Sub
Subtraction of integers.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
DWARFExpression::Operation Op
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
unsigned M0(unsigned Val)
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
constexpr bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
Target & getTheGCNLegacyTarget()
The target for GCN GPUs, registered under the legacy "amdgcn" architecture name for use with -march.
@ Enabled
Convert any .debug_str_offsets tables to DWARF64 if needed.
void initDefault(const MCSubtargetInfo &STI, MCContext &Ctx, bool InitMCExpr=true)
void validate(const MCSubtargetInfo *STI, MCContext &Ctx)
uint32_t PrivateSegmentSize
SmallVector< std::pair< MCSymbol *, std::string >, 4 > IndirectCalls
SmallVector< std::pair< MCSymbol *, MCSymbol * >, 8 > Calls
SmallVector< FuncInfo, 8 > Funcs
SmallVector< std::pair< MCSymbol *, std::string >, 4 > TypeIds
SmallVector< std::pair< MCSymbol *, MCSymbol * >, 4 > Uses
Instruction set architecture version.
const MCExpr * compute_pgm_rsrc2
const MCExpr * kernarg_size
const MCExpr * kernarg_preload
const MCExpr * compute_pgm_rsrc3
const MCExpr * private_segment_fixed_size
const MCExpr * compute_pgm_rsrc1
static void bits_set(const MCExpr *&Dst, const MCExpr *Value, uint32_t Shift, uint32_t Mask, MCContext &Ctx)
const MCExpr * group_segment_fixed_size
static MCKernelDescriptor getDefaultAmdhsaKernelDescriptor(const MCSubtargetInfo *STI, MCContext &Ctx)
const MCExpr * kernel_code_properties
RegisterMCAsmParser - Helper template for registering a target specific assembly parser,...
uint32_t group_segment_fixed_size
uint32_t private_segment_fixed_size