69 class AMDGPUAsmParser;
71 enum RegisterKind { IS_UNKNOWN, IS_VGPR, IS_SGPR, IS_TTMP, IS_SPECIAL };
85 SMLoc StartLoc, EndLoc;
86 const AMDGPUAsmParser *AsmParser;
89 AMDGPUOperand(KindTy Kind_,
const AMDGPUAsmParser *AsmParser_)
92 using Ptr = std::unique_ptr<AMDGPUOperand>;
99 bool hasFPModifiers()
const {
return Abs || Neg; }
100 bool hasIntModifiers()
const {
return Sext; }
101 bool hasModifiers()
const {
return hasFPModifiers() || hasIntModifiers(); }
103 int64_t getFPModifiersOperand()
const {
110 int64_t getIntModifiersOperand()
const {
116 int64_t getModifiersOperand()
const {
117 assert(!(hasFPModifiers() && hasIntModifiers())
118 &&
"fp and int modifiers should not be used simultaneously");
119 if (hasFPModifiers()) {
120 return getFPModifiersOperand();
121 }
else if (hasIntModifiers()) {
122 return getIntModifiersOperand();
205 bool isToken()
const override {
209 if (Kind != Expression || !Expr)
216 return isa<MCSymbolRefExpr>(Expr);
219 bool isImm()
const override {
220 return Kind == Immediate;
223 bool isInlinableImm(
MVT type)
const;
224 bool isLiteralImm(
MVT type)
const;
226 bool isRegKind()
const {
230 bool isReg()
const override {
231 return isRegKind() && !hasModifiers();
235 return isRegKind() || isInlinableImm(type);
238 bool isRegOrImmWithInt16InputMods()
const {
242 bool isRegOrImmWithInt32InputMods()
const {
246 bool isRegOrImmWithInt64InputMods()
const {
250 bool isRegOrImmWithFP16InputMods()
const {
254 bool isRegOrImmWithFP32InputMods()
const {
258 bool isRegOrImmWithFP64InputMods()
const {
262 bool isVReg()
const {
263 return isRegClass(AMDGPU::VGPR_32RegClassID) ||
264 isRegClass(AMDGPU::VReg_64RegClassID) ||
265 isRegClass(AMDGPU::VReg_96RegClassID) ||
266 isRegClass(AMDGPU::VReg_128RegClassID) ||
267 isRegClass(AMDGPU::VReg_256RegClassID) ||
268 isRegClass(AMDGPU::VReg_512RegClassID);
271 bool isVReg32OrOff()
const {
272 return isOff() || isRegClass(AMDGPU::VGPR_32RegClassID);
275 bool isSDWAOperand(
MVT type)
const;
276 bool isSDWAFP16Operand()
const;
277 bool isSDWAFP32Operand()
const;
278 bool isSDWAInt16Operand()
const;
279 bool isSDWAInt32Operand()
const;
281 bool isImmTy(ImmTy ImmT)
const {
282 return isImm() && Imm.Type == ImmT;
285 bool isImmModifier()
const {
286 return isImm() && Imm.Type != ImmTyNone;
289 bool isClampSI()
const {
return isImmTy(ImmTyClampSI); }
290 bool isOModSI()
const {
return isImmTy(ImmTyOModSI); }
291 bool isDMask()
const {
return isImmTy(ImmTyDMask); }
292 bool isUNorm()
const {
return isImmTy(ImmTyUNorm); }
293 bool isDA()
const {
return isImmTy(ImmTyDA); }
294 bool isR128()
const {
return isImmTy(ImmTyR128); }
295 bool isLWE()
const {
return isImmTy(ImmTyLWE); }
296 bool isOff()
const {
return isImmTy(ImmTyOff); }
297 bool isExpTgt()
const {
return isImmTy(ImmTyExpTgt); }
298 bool isExpVM()
const {
return isImmTy(ImmTyExpVM); }
299 bool isExpCompr()
const {
return isImmTy(ImmTyExpCompr); }
300 bool isOffen()
const {
return isImmTy(ImmTyOffen); }
301 bool isIdxen()
const {
return isImmTy(ImmTyIdxen); }
302 bool isAddr64()
const {
return isImmTy(ImmTyAddr64); }
303 bool isOffset()
const {
return isImmTy(ImmTyOffset) &&
isUInt<16>(getImm()); }
304 bool isOffset0()
const {
return isImmTy(ImmTyOffset0) &&
isUInt<16>(getImm()); }
305 bool isOffset1()
const {
return isImmTy(ImmTyOffset1) &&
isUInt<8>(getImm()); }
307 bool isOffsetU12()
const {
return (isImmTy(ImmTyOffset) || isImmTy(ImmTyInstOffset)) && isUInt<12>(getImm()); }
308 bool isOffsetS13()
const {
return (isImmTy(ImmTyOffset) || isImmTy(ImmTyInstOffset)) && isInt<13>(getImm()); }
309 bool isGDS()
const {
return isImmTy(ImmTyGDS); }
310 bool isLDS()
const {
return isImmTy(ImmTyLDS); }
311 bool isGLC()
const {
return isImmTy(ImmTyGLC); }
312 bool isSLC()
const {
return isImmTy(ImmTySLC); }
313 bool isTFE()
const {
return isImmTy(ImmTyTFE); }
314 bool isD16()
const {
return isImmTy(ImmTyD16); }
315 bool isDFMT()
const {
return isImmTy(ImmTyDFMT) &&
isUInt<8>(getImm()); }
316 bool isNFMT()
const {
return isImmTy(ImmTyNFMT) &&
isUInt<8>(getImm()); }
317 bool isBankMask()
const {
return isImmTy(ImmTyDppBankMask); }
318 bool isRowMask()
const {
return isImmTy(ImmTyDppRowMask); }
319 bool isBoundCtrl()
const {
return isImmTy(ImmTyDppBoundCtrl); }
320 bool isSDWADstSel()
const {
return isImmTy(ImmTySdwaDstSel); }
321 bool isSDWASrc0Sel()
const {
return isImmTy(ImmTySdwaSrc0Sel); }
322 bool isSDWASrc1Sel()
const {
return isImmTy(ImmTySdwaSrc1Sel); }
323 bool isSDWADstUnused()
const {
return isImmTy(ImmTySdwaDstUnused); }
324 bool isInterpSlot()
const {
return isImmTy(ImmTyInterpSlot); }
325 bool isInterpAttr()
const {
return isImmTy(ImmTyInterpAttr); }
326 bool isAttrChan()
const {
return isImmTy(ImmTyAttrChan); }
327 bool isOpSel()
const {
return isImmTy(ImmTyOpSel); }
328 bool isOpSelHi()
const {
return isImmTy(ImmTyOpSelHi); }
329 bool isNegLo()
const {
return isImmTy(ImmTyNegLo); }
330 bool isNegHi()
const {
return isImmTy(ImmTyNegHi); }
331 bool isHigh()
const {
return isImmTy(ImmTyHigh); }
334 return isClampSI() || isOModSI();
337 bool isRegOrImm()
const {
338 return isReg() || isImm();
341 bool isRegClass(
unsigned RCID)
const;
343 bool isRegOrInlineNoMods(
unsigned RCID,
MVT type)
const {
344 return (isRegClass(RCID) || isInlinableImm(type)) && !hasModifiers();
347 bool isSCSrcB16()
const {
348 return isRegOrInlineNoMods(AMDGPU::SReg_32RegClassID,
MVT::i16);
351 bool isSCSrcV2B16()
const {
355 bool isSCSrcB32()
const {
356 return isRegOrInlineNoMods(AMDGPU::SReg_32RegClassID,
MVT::i32);
359 bool isSCSrcB64()
const {
360 return isRegOrInlineNoMods(AMDGPU::SReg_64RegClassID,
MVT::i64);
363 bool isSCSrcF16()
const {
364 return isRegOrInlineNoMods(AMDGPU::SReg_32RegClassID,
MVT::f16);
367 bool isSCSrcV2F16()
const {
371 bool isSCSrcF32()
const {
372 return isRegOrInlineNoMods(AMDGPU::SReg_32RegClassID,
MVT::f32);
375 bool isSCSrcF64()
const {
376 return isRegOrInlineNoMods(AMDGPU::SReg_64RegClassID,
MVT::f64);
379 bool isSSrcB32()
const {
380 return isSCSrcB32() || isLiteralImm(
MVT::i32) || isExpr();
383 bool isSSrcB16()
const {
384 return isSCSrcB16() || isLiteralImm(
MVT::i16);
387 bool isSSrcV2B16()
const {
392 bool isSSrcB64()
const {
395 return isSCSrcB64() || isLiteralImm(
MVT::i64);
398 bool isSSrcF32()
const {
399 return isSCSrcB32() || isLiteralImm(
MVT::f32) || isExpr();
402 bool isSSrcF64()
const {
403 return isSCSrcB64() || isLiteralImm(
MVT::f64);
406 bool isSSrcF16()
const {
407 return isSCSrcB16() || isLiteralImm(
MVT::f16);
410 bool isSSrcV2F16()
const {
415 bool isVCSrcB32()
const {
416 return isRegOrInlineNoMods(AMDGPU::VS_32RegClassID,
MVT::i32);
419 bool isVCSrcB64()
const {
420 return isRegOrInlineNoMods(AMDGPU::VS_64RegClassID,
MVT::i64);
423 bool isVCSrcB16()
const {
424 return isRegOrInlineNoMods(AMDGPU::VS_32RegClassID,
MVT::i16);
427 bool isVCSrcV2B16()
const {
431 bool isVCSrcF32()
const {
432 return isRegOrInlineNoMods(AMDGPU::VS_32RegClassID,
MVT::f32);
435 bool isVCSrcF64()
const {
436 return isRegOrInlineNoMods(AMDGPU::VS_64RegClassID,
MVT::f64);
439 bool isVCSrcF16()
const {
440 return isRegOrInlineNoMods(AMDGPU::VS_32RegClassID,
MVT::f16);
443 bool isVCSrcV2F16()
const {
447 bool isVSrcB32()
const {
448 return isVCSrcF32() || isLiteralImm(
MVT::i32) || isExpr();
451 bool isVSrcB64()
const {
452 return isVCSrcF64() || isLiteralImm(
MVT::i64);
455 bool isVSrcB16()
const {
456 return isVCSrcF16() || isLiteralImm(
MVT::i16);
459 bool isVSrcV2B16()
const {
464 bool isVSrcF32()
const {
465 return isVCSrcF32() || isLiteralImm(
MVT::f32) || isExpr();
468 bool isVSrcF64()
const {
469 return isVCSrcF64() || isLiteralImm(
MVT::f64);
472 bool isVSrcF16()
const {
473 return isVCSrcF16() || isLiteralImm(
MVT::f16);
476 bool isVSrcV2F16()
const {
481 bool isKImmFP32()
const {
485 bool isKImmFP16()
const {
489 bool isMem()
const override {
493 bool isExpr()
const {
494 return Kind == Expression;
497 bool isSoppBrTarget()
const {
498 return isExpr() || isImm();
501 bool isSWaitCnt()
const;
502 bool isHwreg()
const;
503 bool isSendMsg()
const;
504 bool isSwizzle()
const;
505 bool isSMRDOffset8()
const;
506 bool isSMRDOffset20()
const;
507 bool isSMRDLiteralOffset()
const;
508 bool isDPPCtrl()
const;
509 bool isGPRIdxMode()
const;
510 bool isS16Imm()
const;
511 bool isU16Imm()
const;
522 if (Kind == Expression)
523 return getExpressionAsToken();
528 int64_t getImm()
const {
533 ImmTy getImmTy()
const {
538 unsigned getReg()
const override {
542 SMLoc getStartLoc()
const override {
546 SMLoc getEndLoc()
const override {
551 return SMRange(StartLoc, EndLoc);
554 Modifiers getModifiers()
const {
555 assert(isRegKind() || isImmTy(ImmTyNone));
556 return isRegKind() ?
Reg.Mods : Imm.Mods;
559 void setModifiers(Modifiers Mods) {
560 assert(isRegKind() || isImmTy(ImmTyNone));
567 bool hasModifiers()
const {
568 return getModifiers().hasModifiers();
571 bool hasFPModifiers()
const {
572 return getModifiers().hasFPModifiers();
575 bool hasIntModifiers()
const {
576 return getModifiers().hasIntModifiers();
579 uint64_t applyInputFPModifiers(uint64_t Val,
unsigned Size)
const;
581 void addImmOperands(
MCInst &Inst,
unsigned N,
bool ApplyModifiers =
true)
const;
583 void addLiteralImmOperand(
MCInst &Inst, int64_t Val,
bool ApplyModifiers)
const;
585 template <
unsigned Bitw
idth>
586 void addKImmFPOperands(
MCInst &Inst,
unsigned N)
const;
588 void addKImmFP16Operands(
MCInst &Inst,
unsigned N)
const {
589 addKImmFPOperands<16>(Inst,
N);
592 void addKImmFP32Operands(
MCInst &Inst,
unsigned N)
const {
593 addKImmFPOperands<32>(Inst,
N);
596 void addRegOperands(
MCInst &Inst,
unsigned N)
const;
598 void addRegOrImmOperands(
MCInst &Inst,
unsigned N)
const {
600 addRegOperands(Inst, N);
604 addImmOperands(Inst, N);
607 void addRegOrImmWithInputModsOperands(
MCInst &Inst,
unsigned N)
const {
608 Modifiers Mods = getModifiers();
611 addRegOperands(Inst, N);
613 addImmOperands(Inst, N,
false);
617 void addRegOrImmWithFPInputModsOperands(
MCInst &Inst,
unsigned N)
const {
618 assert(!hasIntModifiers());
619 addRegOrImmWithInputModsOperands(Inst, N);
622 void addRegOrImmWithIntInputModsOperands(
MCInst &Inst,
unsigned N)
const {
623 assert(!hasFPModifiers());
624 addRegOrImmWithInputModsOperands(Inst, N);
627 void addRegWithInputModsOperands(
MCInst &Inst,
unsigned N)
const {
628 Modifiers Mods = getModifiers();
631 addRegOperands(Inst, N);
634 void addRegWithFPInputModsOperands(
MCInst &Inst,
unsigned N)
const {
635 assert(!hasIntModifiers());
636 addRegWithInputModsOperands(Inst, N);
639 void addRegWithIntInputModsOperands(
MCInst &Inst,
unsigned N)
const {
640 assert(!hasFPModifiers());
641 addRegWithInputModsOperands(Inst, N);
644 void addSoppBrTargetOperands(
MCInst &Inst,
unsigned N)
const {
646 addImmOperands(Inst, N);
655 case ImmTyNone: OS <<
"None";
break;
656 case ImmTyGDS: OS <<
"GDS";
break;
657 case ImmTyLDS: OS <<
"LDS";
break;
658 case ImmTyOffen: OS <<
"Offen";
break;
659 case ImmTyIdxen: OS <<
"Idxen";
break;
660 case ImmTyAddr64: OS <<
"Addr64";
break;
661 case ImmTyOffset: OS <<
"Offset";
break;
662 case ImmTyInstOffset: OS <<
"InstOffset";
break;
663 case ImmTyOffset0: OS <<
"Offset0";
break;
664 case ImmTyOffset1: OS <<
"Offset1";
break;
665 case ImmTyGLC: OS <<
"GLC";
break;
666 case ImmTySLC: OS <<
"SLC";
break;
667 case ImmTyTFE: OS <<
"TFE";
break;
668 case ImmTyD16: OS <<
"D16";
break;
669 case ImmTyDFMT: OS <<
"DFMT";
break;
670 case ImmTyNFMT: OS <<
"NFMT";
break;
671 case ImmTyClampSI: OS <<
"ClampSI";
break;
672 case ImmTyOModSI: OS <<
"OModSI";
break;
673 case ImmTyDppCtrl: OS <<
"DppCtrl";
break;
674 case ImmTyDppRowMask: OS <<
"DppRowMask";
break;
675 case ImmTyDppBankMask: OS <<
"DppBankMask";
break;
676 case ImmTyDppBoundCtrl: OS <<
"DppBoundCtrl";
break;
677 case ImmTySdwaDstSel: OS <<
"SdwaDstSel";
break;
678 case ImmTySdwaSrc0Sel: OS <<
"SdwaSrc0Sel";
break;
679 case ImmTySdwaSrc1Sel: OS <<
"SdwaSrc1Sel";
break;
680 case ImmTySdwaDstUnused: OS <<
"SdwaDstUnused";
break;
681 case ImmTyDMask: OS <<
"DMask";
break;
682 case ImmTyUNorm: OS <<
"UNorm";
break;
683 case ImmTyDA: OS <<
"DA";
break;
684 case ImmTyR128: OS <<
"R128";
break;
685 case ImmTyLWE: OS <<
"LWE";
break;
686 case ImmTyOff: OS <<
"Off";
break;
687 case ImmTyExpTgt: OS <<
"ExpTgt";
break;
688 case ImmTyExpCompr: OS <<
"ExpCompr";
break;
689 case ImmTyExpVM: OS <<
"ExpVM";
break;
690 case ImmTyHwreg: OS <<
"Hwreg";
break;
691 case ImmTySendMsg: OS <<
"SendMsg";
break;
692 case ImmTyInterpSlot: OS <<
"InterpSlot";
break;
693 case ImmTyInterpAttr: OS <<
"InterpAttr";
break;
694 case ImmTyAttrChan: OS <<
"AttrChan";
break;
695 case ImmTyOpSel: OS <<
"OpSel";
break;
696 case ImmTyOpSelHi: OS <<
"OpSelHi";
break;
697 case ImmTyNegLo: OS <<
"NegLo";
break;
698 case ImmTyNegHi: OS <<
"NegHi";
break;
699 case ImmTySwizzle: OS <<
"Swizzle";
break;
700 case ImmTyHigh: OS <<
"High";
break;
707 OS <<
"<register " <<
getReg() <<
" mods: " <<
Reg.Mods <<
'>';
710 OS <<
'<' << getImm();
711 if (getImmTy() != ImmTyNone) {
712 OS <<
" type: "; printImmTy(OS, getImmTy());
714 OS <<
" mods: " << Imm.Mods <<
'>';
720 OS <<
"<expr " << *Expr << '>
'; 725 static AMDGPUOperand::Ptr CreateImm(const AMDGPUAsmParser *AsmParser, 726 int64_t Val, SMLoc Loc, 727 ImmTy Type = ImmTyNone, 728 bool IsFPImm = false) { 729 auto Op = llvm::make_unique<AMDGPUOperand>(Immediate, AsmParser); 731 Op->Imm.IsFPImm = IsFPImm; 733 Op->Imm.Mods = Modifiers(); 739 static AMDGPUOperand::Ptr CreateToken(const AMDGPUAsmParser *AsmParser, 740 StringRef Str, SMLoc Loc, 741 bool HasExplicitEncodingSize = true) { 742 auto Res = llvm::make_unique<AMDGPUOperand>(Token, AsmParser); 743 Res->Tok.Data = Str.data(); 744 Res->Tok.Length = Str.size(); 750 static AMDGPUOperand::Ptr CreateReg(const AMDGPUAsmParser *AsmParser, 751 unsigned RegNo, SMLoc S, 754 auto Op = llvm::make_unique<AMDGPUOperand>(Register, AsmParser); 755 Op->Reg.RegNo = RegNo; 756 Op->Reg.Mods = Modifiers(); 757 Op->Reg.IsForcedVOP3 = ForceVOP3; 763 static AMDGPUOperand::Ptr CreateExpr(const AMDGPUAsmParser *AsmParser, 764 const class MCExpr *Expr, SMLoc S) { 765 auto Op = llvm::make_unique<AMDGPUOperand>(Expression, AsmParser); 773 raw_ostream &operator <<(raw_ostream &OS, AMDGPUOperand::Modifiers Mods) { 774 OS << "abs:" << Mods.Abs << " neg: " << Mods.Neg << " sext:" << Mods.Sext; 778 //===----------------------------------------------------------------------===// 780 //===----------------------------------------------------------------------===// 782 // Holds info related to the current kernel, e.g. count of SGPRs used. 783 // Kernel scope begins at .amdgpu_hsa_kernel directive, ends at next 784 // .amdgpu_hsa_kernel or at EOF. 785 class KernelScopeInfo { 786 int SgprIndexUnusedMin = -1; 787 int VgprIndexUnusedMin = -1; 788 MCContext *Ctx = nullptr; 790 void usesSgprAt(int i) { 791 if (i >= SgprIndexUnusedMin) { 792 SgprIndexUnusedMin = ++i; 794 MCSymbol * const Sym = Ctx->getOrCreateSymbol(Twine(".kernel.sgpr_count")); 795 Sym->setVariableValue(MCConstantExpr::create(SgprIndexUnusedMin, *Ctx)); 800 void usesVgprAt(int i) { 801 if (i >= VgprIndexUnusedMin) { 802 VgprIndexUnusedMin = ++i; 804 MCSymbol * const Sym = Ctx->getOrCreateSymbol(Twine(".kernel.vgpr_count")); 805 Sym->setVariableValue(MCConstantExpr::create(VgprIndexUnusedMin, *Ctx)); 811 KernelScopeInfo() = default; 813 void initialize(MCContext &Context) { 815 usesSgprAt(SgprIndexUnusedMin = -1); 816 usesVgprAt(VgprIndexUnusedMin = -1); 819 void usesRegister(RegisterKind RegKind, unsigned DwordRegIndex, unsigned RegWidth) { 821 case IS_SGPR: usesSgprAt(DwordRegIndex + RegWidth - 1); break; 822 case IS_VGPR: usesVgprAt(DwordRegIndex + RegWidth - 1); break; 828 class AMDGPUAsmParser : public MCTargetAsmParser { 831 // Number of extra operands parsed after the first optional operand. 832 // This may be necessary to skip hardcoded mandatory operands. 833 static const unsigned MAX_OPR_LOOKAHEAD = 8; 835 unsigned ForcedEncodingSize = 0; 836 bool ForcedDPP = false; 837 bool ForcedSDWA = false; 838 KernelScopeInfo KernelScope; 843 #define GET_ASSEMBLER_HEADER
844 #include "AMDGPUGenAsmMatcher.inc"
849 bool ParseAsAbsoluteExpression(uint32_t &Ret);
850 bool OutOfRangeError(SMRange Range);
864 bool calculateGPRBlocks(const FeatureBitset &Features, bool VCCUsed,
865 bool FlatScrUsed, bool XNACKUsed,
866 unsigned NextFreeVGPR, SMRange VGPRRange,
867 unsigned NextFreeSGPR, SMRange SGPRRange,
868 unsigned &VGPRBlocks, unsigned &SGPRBlocks);
869 bool ParseDirectiveAMDGCNTarget();
870 bool ParseDirectiveAMDHSAKernel();
871 bool ParseDirectiveMajorMinor(uint32_t &Major, uint32_t &Minor);
872 bool ParseDirectiveHSACodeObjectVersion();
873 bool ParseDirectiveHSACodeObjectISA();
874 bool ParseAMDKernelCodeTValue(StringRef ID, amd_kernel_code_t &Header);
875 bool ParseDirectiveAMDKernelCodeT();
876 bool subtargetHasRegister(const MCRegisterInfo &MRI, unsigned RegNo) const;
877 bool ParseDirectiveAMDGPUHsaKernel();
879 bool ParseDirectiveISAVersion();
880 bool ParseDirectiveHSAMetadata();
881 bool ParseDirectivePALMetadata();
883 bool AddNextRegisterToList(unsigned& Reg, unsigned& RegWidth,
884 RegisterKind RegKind, unsigned Reg1,
886 bool ParseAMDGPURegister(RegisterKind& RegKind, unsigned& Reg,
887 unsigned& RegNum, unsigned& RegWidth,
888 unsigned *DwordRegIndex);
889 Optional<StringRef> getGprCountSymbolName(RegisterKind RegKind);
890 void initializeGprCountSymbol(RegisterKind RegKind);
891 bool updateGprCountSymbols(RegisterKind RegKind, unsigned DwordRegIndex,
893 void cvtMubufImpl(MCInst &Inst, const OperandVector &Operands,
894 bool IsAtomic, bool IsAtomicReturn, bool IsLds = false);
895 void cvtDSImpl(MCInst &Inst, const OperandVector &Operands,
896 bool IsGdsHardcoded);
899 enum AMDGPUMatchResultTy {
900 Match_PreferE32 = FIRST_TARGET_MATCH_RESULT_TY
903 using OptionalImmIndexMap = std::map<AMDGPUOperand::ImmTy, unsigned>;
905 AMDGPUAsmParser(const MCSubtargetInfo &STI, MCAsmParser &_Parser,
906 const MCInstrInfo &MII,
907 const MCTargetOptions &Options)
908 : MCTargetAsmParser(Options, STI, MII), Parser(_Parser) {
909 MCAsmParserExtension::Initialize(Parser);
911 if (getFeatureBits().none()) {
912 // Set default features.
913 copySTI().ToggleFeature("SOUTHERN_ISLANDS");
916 setAvailableFeatures(ComputeAvailableFeatures(getFeatureBits()));
919 // TODO: make those pre-defined variables read-only.
920 // Currently there is none suitable machinery in the core llvm-mc for this.
921 // MCSymbol::isRedefinable is intended for another purpose, and
922 // AsmParser::parseDirectiveSet() cannot be specialized for specific target.
923 AMDGPU::IsaInfo::IsaVersion ISA =
924 AMDGPU::IsaInfo::getIsaVersion(getFeatureBits());
925 MCContext &Ctx = getContext();
926 if (ISA.Major >= 6 && AMDGPU::IsaInfo::hasCodeObjectV3(&getSTI())) {
928 Ctx.getOrCreateSymbol(Twine(".amdgcn.gfx_generation_number"));
929 Sym->setVariableValue(MCConstantExpr::create(ISA.Major, Ctx));
932 Ctx.getOrCreateSymbol(Twine(".option.machine_version_major"));
933 Sym->setVariableValue(MCConstantExpr::create(ISA.Major, Ctx));
934 Sym = Ctx.getOrCreateSymbol(Twine(".option.machine_version_minor"));
935 Sym->setVariableValue(MCConstantExpr::create(ISA.Minor, Ctx));
936 Sym = Ctx.getOrCreateSymbol(Twine(".option.machine_version_stepping"));
937 Sym->setVariableValue(MCConstantExpr::create(ISA.Stepping, Ctx));
939 if (ISA.Major >= 6 && AMDGPU::IsaInfo::hasCodeObjectV3(&getSTI())) {
940 initializeGprCountSymbol(IS_VGPR);
941 initializeGprCountSymbol(IS_SGPR);
943 KernelScope.initialize(getContext());
947 bool hasXNACK() const {
948 return AMDGPU::hasXNACK(getSTI());
951 bool hasMIMG_R128() const {
952 return AMDGPU::hasMIMG_R128(getSTI());
955 bool hasPackedD16() const {
956 return AMDGPU::hasPackedD16(getSTI());
960 return AMDGPU::isSI(getSTI());
964 return AMDGPU::isCI(getSTI());
968 return AMDGPU::isVI(getSTI());
971 bool isGFX9() const {
972 return AMDGPU::isGFX9(getSTI());
975 bool hasInv2PiInlineImm() const {
976 return getFeatureBits()[AMDGPU::FeatureInv2PiInlineImm];
979 bool hasFlatOffsets() const {
980 return getFeatureBits()[AMDGPU::FeatureFlatInstOffsets];
983 bool hasSGPR102_SGPR103() const {
987 bool hasIntClamp() const {
988 return getFeatureBits()[AMDGPU::FeatureIntClamp];
991 AMDGPUTargetStreamer &getTargetStreamer() {
992 MCTargetStreamer &TS = *getParser().getStreamer().getTargetStreamer();
993 return static_cast<AMDGPUTargetStreamer &>(TS);
996 const MCRegisterInfo *getMRI() const {
997 // We need this const_cast because for some reason getContext() is not const
999 return const_cast<AMDGPUAsmParser*>(this)->getContext().getRegisterInfo();
1002 const MCInstrInfo *getMII() const {
1006 const FeatureBitset &getFeatureBits() const {
1007 return getSTI().getFeatureBits();
1010 void setForcedEncodingSize(unsigned Size) { ForcedEncodingSize = Size; }
1011 void setForcedDPP(bool ForceDPP_) { ForcedDPP = ForceDPP_; }
1012 void setForcedSDWA(bool ForceSDWA_) { ForcedSDWA = ForceSDWA_; }
1014 unsigned getForcedEncodingSize() const { return ForcedEncodingSize; }
1015 bool isForcedVOP3() const { return ForcedEncodingSize == 64; }
1016 bool isForcedDPP() const { return ForcedDPP; }
1017 bool isForcedSDWA() const { return ForcedSDWA; }
1018 ArrayRef<unsigned> getMatchedVariants() const;
1020 std::unique_ptr<AMDGPUOperand> parseRegister();
1021 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) override;
1022 unsigned checkTargetMatchPredicate(MCInst &Inst) override;
1023 unsigned validateTargetOperandClass(MCParsedAsmOperand &Op,
1024 unsigned Kind) override;
1025 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
1026 OperandVector &Operands, MCStreamer &Out,
1027 uint64_t &ErrorInfo,
1028 bool MatchingInlineAsm) override;
1029 bool ParseDirective(AsmToken DirectiveID) override;
1030 OperandMatchResultTy parseOperand(OperandVector &Operands, StringRef Mnemonic);
1031 StringRef parseMnemonicSuffix(StringRef Name);
1032 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
1033 SMLoc NameLoc, OperandVector &Operands) override;
1034 //bool ProcessInstruction(MCInst &Inst);
1036 OperandMatchResultTy parseIntWithPrefix(const char *Prefix, int64_t &Int);
1038 OperandMatchResultTy
1039 parseIntWithPrefix(const char *Prefix, OperandVector &Operands,
1040 AMDGPUOperand::ImmTy ImmTy = AMDGPUOperand::ImmTyNone,
1041 bool (*ConvertResult)(int64_t &) = nullptr);
1043 OperandMatchResultTy parseOperandArrayWithPrefix(
1045 OperandVector &Operands,
1046 AMDGPUOperand::ImmTy ImmTy = AMDGPUOperand::ImmTyNone,
1047 bool (*ConvertResult)(int64_t&) = nullptr);
1049 OperandMatchResultTy
1050 parseNamedBit(const char *Name, OperandVector &Operands,
1051 AMDGPUOperand::ImmTy ImmTy = AMDGPUOperand::ImmTyNone);
1052 OperandMatchResultTy parseStringWithPrefix(StringRef Prefix,
1055 bool parseAbsoluteExpr(int64_t &Val, bool AbsMod = false);
1056 OperandMatchResultTy parseImm(OperandVector &Operands, bool AbsMod = false);
1057 OperandMatchResultTy parseReg(OperandVector &Operands);
1058 OperandMatchResultTy parseRegOrImm(OperandVector &Operands, bool AbsMod = false);
1059 OperandMatchResultTy parseRegOrImmWithFPInputMods(OperandVector &Operands, bool AllowImm = true);
1060 OperandMatchResultTy parseRegOrImmWithIntInputMods(OperandVector &Operands, bool AllowImm = true);
1061 OperandMatchResultTy parseRegWithFPInputMods(OperandVector &Operands);
1062 OperandMatchResultTy parseRegWithIntInputMods(OperandVector &Operands);
1063 OperandMatchResultTy parseVReg32OrOff(OperandVector &Operands);
1065 void cvtDSOffset01(MCInst &Inst, const OperandVector &Operands);
1066 void cvtDS(MCInst &Inst, const OperandVector &Operands) { cvtDSImpl(Inst, Operands, false); }
1067 void cvtDSGds(MCInst &Inst, const OperandVector &Operands) { cvtDSImpl(Inst, Operands, true); }
1068 void cvtExp(MCInst &Inst, const OperandVector &Operands);
1070 bool parseCnt(int64_t &IntVal);
1071 OperandMatchResultTy parseSWaitCntOps(OperandVector &Operands);
1072 OperandMatchResultTy parseHwreg(OperandVector &Operands);
1075 struct OperandInfoTy {
1077 bool IsSymbolic = false;
1079 OperandInfoTy(int64_t Id_) : Id(Id_) {}
1082 bool parseSendMsgConstruct(OperandInfoTy &Msg, OperandInfoTy &Operation, int64_t &StreamId);
1083 bool parseHwregConstruct(OperandInfoTy &HwReg, int64_t &Offset, int64_t &Width);
1086 OperandMatchResultTy parseExpTgtImpl(StringRef Str, uint8_t &Val);
1088 bool validateInstruction(const MCInst &Inst, const SMLoc &IDLoc);
1089 bool validateConstantBusLimitations(const MCInst &Inst);
1090 bool validateEarlyClobberLimitations(const MCInst &Inst);
1091 bool validateIntClampSupported(const MCInst &Inst);
1092 bool validateMIMGAtomicDMask(const MCInst &Inst);
1093 bool validateMIMGGatherDMask(const MCInst &Inst);
1094 bool validateMIMGDataSize(const MCInst &Inst);
1095 bool validateMIMGR128(const MCInst &Inst);
1096 bool validateMIMGD16(const MCInst &Inst);
1097 bool usesConstantBus(const MCInst &Inst, unsigned OpIdx);
1098 bool isInlineConstant(const MCInst &Inst, unsigned OpIdx) const;
1099 unsigned findImplicitSGPRReadInVOP(const MCInst &Inst) const;
1101 bool trySkipId(const StringRef Id);
1102 bool trySkipToken(const AsmToken::TokenKind Kind);
1103 bool skipToken(const AsmToken::TokenKind Kind, const StringRef ErrMsg);
1104 bool parseString(StringRef &Val, const StringRef ErrMsg = "expected a string");
1105 bool parseExpr(int64_t &Imm);
1108 OperandMatchResultTy parseOptionalOperand(OperandVector &Operands);
1109 OperandMatchResultTy parseOptionalOpr(OperandVector &Operands);
1111 OperandMatchResultTy parseExpTgt(OperandVector &Operands);
1112 OperandMatchResultTy parseSendMsgOp(OperandVector &Operands);
1113 OperandMatchResultTy parseInterpSlot(OperandVector &Operands);
1114 OperandMatchResultTy parseInterpAttr(OperandVector &Operands);
1115 OperandMatchResultTy parseSOppBrTarget(OperandVector &Operands);
1117 bool parseSwizzleOperands(const unsigned OpNum, int64_t* Op,
1118 const unsigned MinVal,
1119 const unsigned MaxVal,
1120 const StringRef ErrMsg);
1121 OperandMatchResultTy parseSwizzleOp(OperandVector &Operands);
1122 bool parseSwizzleOffset(int64_t &Imm);
1123 bool parseSwizzleMacro(int64_t &Imm);
1124 bool parseSwizzleQuadPerm(int64_t &Imm);
1125 bool parseSwizzleBitmaskPerm(int64_t &Imm);
1126 bool parseSwizzleBroadcast(int64_t &Imm);
1127 bool parseSwizzleSwap(int64_t &Imm);
1128 bool parseSwizzleReverse(int64_t &Imm);
1130 void cvtMubuf(MCInst &Inst, const OperandVector &Operands) { cvtMubufImpl(Inst, Operands, false, false); }
1131 void cvtMubufAtomic(MCInst &Inst, const OperandVector &Operands) { cvtMubufImpl(Inst, Operands, true, false); }
1132 void cvtMubufAtomicReturn(MCInst &Inst, const OperandVector &Operands) { cvtMubufImpl(Inst, Operands, true, true); }
1133 void cvtMubufLds(MCInst &Inst, const OperandVector &Operands) { cvtMubufImpl(Inst, Operands, false, false, true); }
1134 void cvtMtbuf(MCInst &Inst, const OperandVector &Operands);
1136 AMDGPUOperand::Ptr defaultGLC() const;
1137 AMDGPUOperand::Ptr defaultSLC() const;
1139 AMDGPUOperand::Ptr defaultSMRDOffset8() const;
1140 AMDGPUOperand::Ptr defaultSMRDOffset20() const;
1141 AMDGPUOperand::Ptr defaultSMRDLiteralOffset() const;
1142 AMDGPUOperand::Ptr defaultOffsetU12() const;
1143 AMDGPUOperand::Ptr defaultOffsetS13() const;
1145 OperandMatchResultTy parseOModOperand(OperandVector &Operands);
1147 void cvtVOP3(MCInst &Inst, const OperandVector &Operands,
1148 OptionalImmIndexMap &OptionalIdx);
1149 void cvtVOP3OpSel(MCInst &Inst, const OperandVector &Operands);
1150 void cvtVOP3(MCInst &Inst, const OperandVector &Operands);
1151 void cvtVOP3P(MCInst &Inst, const OperandVector &Operands);
1153 void cvtVOP3Interp(MCInst &Inst, const OperandVector &Operands);
1155 void cvtMIMG(MCInst &Inst, const OperandVector &Operands,
1156 bool IsAtomic = false);
1157 void cvtMIMGAtomic(MCInst &Inst, const OperandVector &Operands);
1159 OperandMatchResultTy parseDPPCtrl(OperandVector &Operands);
1160 AMDGPUOperand::Ptr defaultRowMask() const;
1161 AMDGPUOperand::Ptr defaultBankMask() const;
1162 AMDGPUOperand::Ptr defaultBoundCtrl() const;
1163 void cvtDPP(MCInst &Inst, const OperandVector &Operands);
1165 OperandMatchResultTy parseSDWASel(OperandVector &Operands, StringRef Prefix,
1166 AMDGPUOperand::ImmTy Type);
1167 OperandMatchResultTy parseSDWADstUnused(OperandVector &Operands);
1168 void cvtSdwaVOP1(MCInst &Inst, const OperandVector &Operands);
1169 void cvtSdwaVOP2(MCInst &Inst, const OperandVector &Operands);
1170 void cvtSdwaVOP2b(MCInst &Inst, const OperandVector &Operands);
1171 void cvtSdwaVOPC(MCInst &Inst, const OperandVector &Operands);
1172 void cvtSDWA(MCInst &Inst, const OperandVector &Operands,
1173 uint64_t BasicInstType, bool skipVcc = false);
1176 struct OptionalOperand {
1178 AMDGPUOperand::ImmTy Type;
1180 bool (*ConvertResult)(int64_t&);
1183 } // end anonymous namespace
1185 // May be called with integer type with equivalent bitwidth.
1186 static const fltSemantics *getFltSemantics(unsigned Size) {
1189 return &APFloat::IEEEsingle();
1191 return &APFloat::IEEEdouble();
1193 return &APFloat::IEEEhalf();
1195 llvm_unreachable("unsupported fp type");
1199 static const fltSemantics *getFltSemantics(MVT VT) {
1200 return getFltSemantics(VT.getSizeInBits() / 8);
1203 static const fltSemantics *getOpFltSemantics(uint8_t OperandType) {
1204 switch (OperandType) {
1205 case AMDGPU::OPERAND_REG_IMM_INT32:
1206 case AMDGPU::OPERAND_REG_IMM_FP32:
1207 case AMDGPU::OPERAND_REG_INLINE_C_INT32:
1208 case AMDGPU::OPERAND_REG_INLINE_C_FP32:
1209 return &APFloat::IEEEsingle();
1210 case AMDGPU::OPERAND_REG_IMM_INT64:
1211 case AMDGPU::OPERAND_REG_IMM_FP64:
1212 case AMDGPU::OPERAND_REG_INLINE_C_INT64:
1213 case AMDGPU::OPERAND_REG_INLINE_C_FP64:
1214 return &APFloat::IEEEdouble();
1215 case AMDGPU::OPERAND_REG_IMM_INT16:
1216 case AMDGPU::OPERAND_REG_IMM_FP16:
1217 case AMDGPU::OPERAND_REG_INLINE_C_INT16:
1218 case AMDGPU::OPERAND_REG_INLINE_C_FP16:
1219 case AMDGPU::OPERAND_REG_INLINE_C_V2INT16:
1220 case AMDGPU::OPERAND_REG_INLINE_C_V2FP16:
1221 return &APFloat::IEEEhalf();
1223 llvm_unreachable("unsupported fp type");
1227 //===----------------------------------------------------------------------===//
1229 //===----------------------------------------------------------------------===//
1231 static bool canLosslesslyConvertToFPType(APFloat &FPLiteral, MVT VT) {
1234 // Convert literal to single precision
1235 APFloat::opStatus Status = FPLiteral.convert(*getFltSemantics(VT),
1236 APFloat::rmNearestTiesToEven,
1238 // We allow precision lost but not overflow or underflow
1239 if (Status != APFloat::opOK &&
1241 ((Status & APFloat::opOverflow) != 0 ||
1242 (Status & APFloat::opUnderflow) != 0)) {
1249 bool AMDGPUOperand::isInlinableImm(MVT type) const {
1250 if (!isImmTy(ImmTyNone)) {
1251 // Only plain immediates are inlinable (e.g. "clamp" attribute is not)
1254 // TODO: We should avoid using host float here. It would be better to
1255 // check the float bit values which is what a few other places do.
1256 // We've had bot failures before due to weird NaN support on mips hosts.
1263 AsmParser->hasInv2PiInlineImm());
1272 static_cast<int16_t>(FPLiteral.bitcastToAPInt().getZExtValue()),
1273 AsmParser->hasInv2PiInlineImm());
1278 static_cast<int32_t>(FPLiteral.bitcastToAPInt().getZExtValue()),
1279 AsmParser->hasInv2PiInlineImm());
1285 AsmParser->hasInv2PiInlineImm());
1290 static_cast<int16_t>(
Literal.getLoBits(16).getSExtValue()),
1291 AsmParser->hasInv2PiInlineImm());
1295 static_cast<int32_t>(
Literal.getLoBits(32).getZExtValue()),
1296 AsmParser->hasInv2PiInlineImm());
1299 bool AMDGPUOperand::isLiteralImm(
MVT type)
const {
1301 if (!isImmTy(ImmTyNone)) {
1308 if (type ==
MVT::f64 && hasFPModifiers()) {
1340 bool AMDGPUOperand::isRegClass(
unsigned RCID)
const {
1341 return isRegKind() && AsmParser->getMRI()->getRegClass(RCID).contains(
getReg());
1344 bool AMDGPUOperand::isSDWAOperand(
MVT type)
const {
1345 if (AsmParser->isVI())
1347 else if (AsmParser->isGFX9())
1348 return isRegKind() || isInlinableImm(type);
1353 bool AMDGPUOperand::isSDWAFP16Operand()
const {
1357 bool AMDGPUOperand::isSDWAFP32Operand()
const {
1361 bool AMDGPUOperand::isSDWAInt16Operand()
const {
1365 bool AMDGPUOperand::isSDWAInt32Operand()
const {
1369 uint64_t AMDGPUOperand::applyInputFPModifiers(uint64_t Val,
unsigned Size)
const 1371 assert(isImmTy(ImmTyNone) && Imm.Mods.hasFPModifiers());
1372 assert(Size == 2 || Size == 4 || Size == 8);
1374 const uint64_t FpSignMask = (1ULL << (Size * 8 - 1));
1386 void AMDGPUOperand::addImmOperands(
MCInst &Inst,
unsigned N,
bool ApplyModifiers)
const {
1389 addLiteralImmOperand(Inst, Imm.Val,
1391 isImmTy(ImmTyNone) && Imm.Mods.hasFPModifiers());
1393 assert(!isImmTy(ImmTyNone) || !hasModifiers());
1398 void AMDGPUOperand::addLiteralImmOperand(
MCInst &Inst, int64_t Val,
bool ApplyModifiers)
const {
1399 const auto& InstDesc = AsmParser->getMII()->get(Inst.
getOpcode());
1404 if (ApplyModifiers) {
1406 const unsigned Size = Imm.IsFPImm ?
sizeof(double) :
getOperandSize(InstDesc, OpNum);
1407 Val = applyInputFPModifiers(Val, Size);
1411 uint8_t OpTy = InstDesc.OpInfo[OpNum].OperandType;
1420 AsmParser->hasInv2PiInlineImm())) {
1428 if (
Literal.getLoBits(32) != 0) {
1429 const_cast<AMDGPUAsmParser *
>(AsmParser)->
Warning(Inst.
getLoc(),
1430 "Can't encode literal as exact 64-bit floating-point operand. " 1431 "Low 32-bits will be set to zero");
1461 uint64_t ImmVal = FPLiteral.bitcastToAPInt().getZExtValue();
1464 ImmVal |= (ImmVal << 16);
1487 AsmParser->hasInv2PiInlineImm())) {
1513 AsmParser->hasInv2PiInlineImm())) {
1523 auto LiteralVal =
static_cast<uint16_t
>(
Literal.getLoBits(16).getZExtValue());
1525 AsmParser->hasInv2PiInlineImm()));
1528 static_cast<uint32_t>(LiteralVal);
1537 template <
unsigned Bitw
idth>
1538 void AMDGPUOperand::addKImmFPOperands(
MCInst &Inst,
unsigned N)
const {
1554 void AMDGPUOperand::addRegOperands(
MCInst &Inst,
unsigned N)
const {
1563 if (Is == IS_VGPR) {
1566 case 1:
return AMDGPU::VGPR_32RegClassID;
1567 case 2:
return AMDGPU::VReg_64RegClassID;
1568 case 3:
return AMDGPU::VReg_96RegClassID;
1569 case 4:
return AMDGPU::VReg_128RegClassID;
1570 case 8:
return AMDGPU::VReg_256RegClassID;
1571 case 16:
return AMDGPU::VReg_512RegClassID;
1573 }
else if (Is == IS_TTMP) {
1576 case 1:
return AMDGPU::TTMP_32RegClassID;
1577 case 2:
return AMDGPU::TTMP_64RegClassID;
1578 case 4:
return AMDGPU::TTMP_128RegClassID;
1579 case 8:
return AMDGPU::TTMP_256RegClassID;
1580 case 16:
return AMDGPU::TTMP_512RegClassID;
1582 }
else if (Is == IS_SGPR) {
1585 case 1:
return AMDGPU::SGPR_32RegClassID;
1586 case 2:
return AMDGPU::SGPR_64RegClassID;
1587 case 4:
return AMDGPU::SGPR_128RegClassID;
1588 case 8:
return AMDGPU::SGPR_256RegClassID;
1589 case 16:
return AMDGPU::SGPR_512RegClassID;
1597 .Case(
"exec", AMDGPU::EXEC)
1598 .
Case(
"vcc", AMDGPU::VCC)
1599 .
Case(
"flat_scratch", AMDGPU::FLAT_SCR)
1600 .
Case(
"xnack_mask", AMDGPU::XNACK_MASK)
1601 .
Case(
"m0", AMDGPU::M0)
1602 .
Case(
"scc", AMDGPU::SCC)
1603 .
Case(
"tba", AMDGPU::TBA)
1604 .
Case(
"tma", AMDGPU::TMA)
1605 .
Case(
"flat_scratch_lo", AMDGPU::FLAT_SCR_LO)
1606 .
Case(
"flat_scratch_hi", AMDGPU::FLAT_SCR_HI)
1607 .
Case(
"xnack_mask_lo", AMDGPU::XNACK_MASK_LO)
1608 .
Case(
"xnack_mask_hi", AMDGPU::XNACK_MASK_HI)
1609 .
Case(
"vcc_lo", AMDGPU::VCC_LO)
1610 .
Case(
"vcc_hi", AMDGPU::VCC_HI)
1611 .
Case(
"exec_lo", AMDGPU::EXEC_LO)
1612 .
Case(
"exec_hi", AMDGPU::EXEC_HI)
1613 .
Case(
"tma_lo", AMDGPU::TMA_LO)
1614 .
Case(
"tma_hi", AMDGPU::TMA_HI)
1615 .
Case(
"tba_lo", AMDGPU::TBA_LO)
1616 .
Case(
"tba_hi", AMDGPU::TBA_HI)
1620 bool AMDGPUAsmParser::ParseRegister(
unsigned &RegNo,
SMLoc &StartLoc,
1622 auto R = parseRegister();
1623 if (!R)
return true;
1625 RegNo = R->getReg();
1626 StartLoc = R->getStartLoc();
1627 EndLoc = R->getEndLoc();
1631 bool AMDGPUAsmParser::AddNextRegisterToList(
unsigned &
Reg,
unsigned &RegWidth,
1636 if (Reg == AMDGPU::EXEC_LO && Reg1 == AMDGPU::EXEC_HI) {
1641 if (Reg == AMDGPU::FLAT_SCR_LO && Reg1 == AMDGPU::FLAT_SCR_HI) {
1642 Reg = AMDGPU::FLAT_SCR;
1646 if (Reg == AMDGPU::XNACK_MASK_LO && Reg1 == AMDGPU::XNACK_MASK_HI) {
1647 Reg = AMDGPU::XNACK_MASK;
1651 if (Reg == AMDGPU::VCC_LO && Reg1 == AMDGPU::VCC_HI) {
1656 if (Reg == AMDGPU::TBA_LO && Reg1 == AMDGPU::TBA_HI) {
1661 if (Reg == AMDGPU::TMA_LO && Reg1 == AMDGPU::TMA_HI) {
1670 if (Reg1 != Reg + RegWidth) {
1680 bool AMDGPUAsmParser::ParseAMDGPURegister(
RegisterKind &RegKind,
unsigned &Reg,
1681 unsigned &RegNum,
unsigned &RegWidth,
1682 unsigned *DwordRegIndex) {
1683 if (DwordRegIndex) { *DwordRegIndex = 0; }
1686 StringRef RegName = Parser.getTok().getString();
1689 RegKind = IS_SPECIAL;
1691 unsigned RegNumIndex = 0;
1692 if (RegName[0] ==
'v') {
1695 }
else if (RegName[0] ==
's') {
1699 RegNumIndex = strlen(
"ttmp");
1704 if (RegName.
size() > RegNumIndex) {
1713 int64_t RegLo, RegHi;
1718 if (getParser().parseAbsoluteExpression(RegLo))
1729 if (getParser().parseAbsoluteExpression(RegHi))
1737 RegWidth = (RegHi - RegLo) + 1;
1743 if (!ParseAMDGPURegister(RegKind, Reg, RegNum, RegWidth,
nullptr))
1748 unsigned Reg1, RegNum1, RegWidth1;
1755 }
else if (ParseAMDGPURegister(RegKind1, Reg1, RegNum1, RegWidth1,
nullptr)) {
1756 if (RegWidth1 != 1) {
1759 if (RegKind1 != RegKind) {
1762 if (!AddNextRegisterToList(Reg, RegWidth, RegKind1, Reg1, RegNum1)) {
1782 if (RegKind == IS_SGPR || RegKind == IS_TTMP) {
1784 Size = std::min(RegWidth, 4u);
1786 if (RegNum % Size != 0)
1788 if (DwordRegIndex) { *DwordRegIndex = RegNum; }
1789 RegNum = RegNum /
Size;
1804 if (!subtargetHasRegister(*TRI, Reg))
1810 AMDGPUAsmParser::getGprCountSymbolName(
RegisterKind RegKind) {
1813 return StringRef(
".amdgcn.next_free_vgpr");
1815 return StringRef(
".amdgcn.next_free_sgpr");
1821 void AMDGPUAsmParser::initializeGprCountSymbol(
RegisterKind RegKind) {
1822 auto SymbolName = getGprCountSymbolName(RegKind);
1828 bool AMDGPUAsmParser::updateGprCountSymbols(
RegisterKind RegKind,
1829 unsigned DwordRegIndex,
1830 unsigned RegWidth) {
1835 auto SymbolName = getGprCountSymbolName(RegKind);
1840 int64_t NewMax = DwordRegIndex + RegWidth - 1;
1844 return !
Error(getParser().getTok().getLoc(),
1845 ".amdgcn.next_free_{v,s}gpr symbols must be variable");
1848 getParser().getTok().getLoc(),
1849 ".amdgcn.next_free_{v,s}gpr symbols must be absolute expressions");
1851 if (OldCount <= NewMax)
1857 std::unique_ptr<AMDGPUOperand> AMDGPUAsmParser::parseRegister() {
1858 const auto &Tok = Parser.getTok();
1859 SMLoc StartLoc = Tok.getLoc();
1860 SMLoc EndLoc = Tok.getEndLoc();
1862 unsigned Reg, RegNum, RegWidth, DwordRegIndex;
1864 if (!ParseAMDGPURegister(RegKind, Reg, RegNum, RegWidth, &DwordRegIndex)) {
1868 if (!updateGprCountSymbols(RegKind, DwordRegIndex, RegWidth))
1871 KernelScope.usesRegister(RegKind, DwordRegIndex, RegWidth);
1872 return AMDGPUOperand::CreateReg(
this, Reg, StartLoc, EndLoc,
false);
1876 AMDGPUAsmParser::parseAbsoluteExpr(int64_t &Val,
bool AbsMod) {
1889 if (getParser().parsePrimaryExpr(Expr, EndLoc)) {
1893 return !Expr->evaluateAsAbsolute(Val);
1896 return getParser().parseAbsoluteExpression(Val);
1900 AMDGPUAsmParser::parseImm(
OperandVector &Operands,
bool AbsMod) {
1904 const AsmToken NextToken = getLexer().peekTok();
1913 SMLoc S = Parser.getTok().getLoc();
1914 switch(getLexer().getKind()) {
1917 if (parseAbsoluteExpr(IntVal, AbsMod))
1921 Operands.
push_back(AMDGPUOperand::CreateImm(
this, IntVal, S));
1926 if (parseAbsoluteExpr(IntVal, AbsMod))
1934 AMDGPUOperand::ImmTyNone,
true));
1944 if (
auto R = parseRegister()) {
1946 R->Reg.IsForcedVOP3 = isForcedVOP3();
1954 AMDGPUAsmParser::parseRegOrImm(
OperandVector &Operands,
bool AbsMod) {
1955 auto res = parseImm(Operands, AbsMod);
1960 return parseReg(Operands);
1964 AMDGPUAsmParser::parseRegOrImmWithFPInputMods(
OperandVector &Operands,
1966 bool Negate =
false, Negate2 =
false, Abs =
false, Abs2 =
false;
1969 const AsmToken NextToken = getLexer().peekTok();
1973 Error(Parser.getTok().getLoc(),
"invalid syntax, expected 'neg' modifier");
1992 Parser.getTok().getString() ==
"neg") {
1994 Error(Parser.getTok().getLoc(),
"expected register or immediate");
2000 Error(Parser.getTok().getLoc(),
"expected left paren after neg");
2007 Parser.getTok().getString() ==
"abs") {
2011 Error(Parser.getTok().getLoc(),
"expected left paren after abs");
2019 Error(Parser.getTok().getLoc(),
"expected register or immediate");
2028 Res = parseRegOrImm(Operands, Abs);
2030 Res = parseReg(Operands);
2036 AMDGPUOperand::Modifiers Mods;
2039 Error(Parser.getTok().getLoc(),
"expected vertical bar");
2047 Error(Parser.getTok().getLoc(),
"expected closing parentheses");
2056 }
else if (Negate2) {
2058 Error(Parser.getTok().getLoc(),
"expected closing parentheses");
2065 if (Mods.hasFPModifiers()) {
2066 AMDGPUOperand &
Op =
static_cast<AMDGPUOperand &
>(*Operands.
back());
2067 Op.setModifiers(Mods);
2073 AMDGPUAsmParser::parseRegOrImmWithIntInputMods(
OperandVector &Operands,
2078 Parser.getTok().getString() ==
"sext") {
2082 Error(Parser.getTok().getLoc(),
"expected left paren after sext");
2090 Res = parseRegOrImm(Operands);
2092 Res = parseReg(Operands);
2098 AMDGPUOperand::Modifiers Mods;
2101 Error(Parser.getTok().getLoc(),
"expected closing parentheses");
2108 if (Mods.hasIntModifiers()) {
2109 AMDGPUOperand &
Op =
static_cast<AMDGPUOperand &
>(*Operands.
back());
2110 Op.setModifiers(Mods);
2117 AMDGPUAsmParser::parseRegWithFPInputMods(
OperandVector &Operands) {
2118 return parseRegOrImmWithFPInputMods(Operands,
false);
2122 AMDGPUAsmParser::parseRegWithIntInputMods(
OperandVector &Operands) {
2123 return parseRegOrImmWithIntInputMods(Operands,
false);
2127 std::unique_ptr<AMDGPUOperand> Reg = parseRegister();
2133 const AsmToken &Tok = Parser.getTok();
2136 AMDGPUOperand::ImmTyOff,
false));
2144 unsigned AMDGPUAsmParser::checkTargetMatchPredicate(
MCInst &Inst) {
2145 uint64_t TSFlags = MII.get(Inst.
getOpcode()).TSFlags;
2151 return Match_InvalidOperand;
2153 if ((TSFlags & SIInstrFlags::VOP3) &&
2155 getForcedEncodingSize() != 64)
2156 return Match_PreferE32;
2158 if (Inst.
getOpcode() == AMDGPU::V_MAC_F32_sdwa_vi ||
2159 Inst.
getOpcode() == AMDGPU::V_MAC_F16_sdwa_vi) {
2165 return Match_InvalidOperand;
2174 if (Op.getImm() != 0)
2175 return Match_InvalidOperand;
2178 return Match_Success;
2183 if (getForcedEncodingSize() == 32) {
2188 if (isForcedVOP3()) {
2193 if (isForcedSDWA()) {
2199 if (isForcedDPP()) {
2204 static const unsigned Variants[] = {
2212 unsigned AMDGPUAsmParser::findImplicitSGPRReadInVOP(
const MCInst &Inst)
const {
2215 for (
unsigned i = 0; i < Num; ++i) {
2218 case AMDGPU::FLAT_SCR:
2226 return AMDGPU::NoRegister;
2233 bool AMDGPUAsmParser::isInlineConstant(
const MCInst &Inst,
2234 unsigned OpIdx)
const {
2243 int64_t Val = MO.
getImm();
2265 bool AMDGPUAsmParser::usesConstantBus(
const MCInst &Inst,
unsigned OpIdx) {
2268 return !isInlineConstant(Inst, OpIdx);
2270 return !MO.
isReg() ||
2274 bool AMDGPUAsmParser::validateConstantBusLimitations(
const MCInst &Inst) {
2275 const unsigned Opcode = Inst.
getOpcode();
2277 unsigned ConstantBusUseCount = 0;
2286 ++ConstantBusUseCount;
2289 unsigned SGPRUsed = findImplicitSGPRReadInVOP(Inst);
2290 if (SGPRUsed != AMDGPU::NoRegister) {
2291 ++ConstantBusUseCount;
2298 const int OpIndices[] = { Src0Idx, Src1Idx, Src2Idx };
2300 for (
int OpIdx : OpIndices) {
2301 if (OpIdx == -1)
break;
2304 if (usesConstantBus(Inst, OpIdx)) {
2313 if (Reg != SGPRUsed) {
2314 ++ConstantBusUseCount;
2318 ++ConstantBusUseCount;
2324 return ConstantBusUseCount <= 1;
2327 bool AMDGPUAsmParser::validateEarlyClobberLimitations(
const MCInst &Inst) {
2328 const unsigned Opcode = Inst.
getOpcode();
2348 const int SrcIndices[] = { Src0Idx, Src1Idx, Src2Idx };
2350 for (
int SrcIdx : SrcIndices) {
2351 if (SrcIdx == -1)
break;
2364 bool AMDGPUAsmParser::validateIntClampSupported(
const MCInst &Inst) {
2378 bool AMDGPUAsmParser::validateMIMGDataSize(
const MCInst &Inst) {
2405 DataSize = (DataSize + 1) / 2;
2408 return (VDataSize / 4) == DataSize + TFESize;
2411 bool AMDGPUAsmParser::validateMIMGAtomicDMask(
const MCInst &Inst) {
2428 return DMask == 0x1 || DMask == 0x3 || DMask == 0xf;
2431 bool AMDGPUAsmParser::validateMIMGGatherDMask(
const MCInst &Inst) {
2447 return DMask == 0x1 || DMask == 0x2 || DMask == 0x4 || DMask == 0x8;
2450 bool AMDGPUAsmParser::validateMIMGR128(
const MCInst &Inst) {
2466 bool AMDGPUAsmParser::validateMIMGD16(
const MCInst &Inst) {
2483 bool AMDGPUAsmParser::validateInstruction(
const MCInst &Inst,
2484 const SMLoc &IDLoc) {
2485 if (!validateConstantBusLimitations(Inst)) {
2487 "invalid operand (violates constant bus restrictions)");
2490 if (!validateEarlyClobberLimitations(Inst)) {
2492 "destination must be different than all sources");
2495 if (!validateIntClampSupported(Inst)) {
2497 "integer clamping is not supported on this GPU");
2500 if (!validateMIMGR128(Inst)) {
2502 "r128 modifier is not supported on this GPU");
2506 if (!validateMIMGD16(Inst)) {
2508 "d16 modifier is not supported on this GPU");
2511 if (!validateMIMGDataSize(Inst)) {
2513 "image data size does not match dmask and tfe");
2516 if (!validateMIMGAtomicDMask(Inst)) {
2518 "invalid atomic image dmask");
2521 if (!validateMIMGGatherDMask(Inst)) {
2523 "invalid image_gather dmask: only one bit must be set");
2531 unsigned VariantID = 0);
2533 bool AMDGPUAsmParser::MatchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
2537 bool MatchingInlineAsm) {
2539 unsigned Result = Match_Success;
2540 for (
auto Variant : getMatchedVariants()) {
2542 auto R = MatchInstructionImpl(Operands, Inst, EI, MatchingInlineAsm,
2547 if ((R == Match_Success) ||
2548 (R == Match_PreferE32) ||
2549 (R == Match_MissingFeature && Result != Match_PreferE32) ||
2550 (R == Match_InvalidOperand && Result != Match_MissingFeature
2551 && Result != Match_PreferE32) ||
2552 (R == Match_MnemonicFail && Result != Match_InvalidOperand
2553 && Result != Match_MissingFeature
2554 && Result != Match_PreferE32)) {
2558 if (R == Match_Success)
2565 if (!validateInstruction(Inst, IDLoc)) {
2572 case Match_MissingFeature:
2573 return Error(IDLoc,
"instruction not supported on this GPU");
2575 case Match_MnemonicFail: {
2576 uint64_t FBS = ComputeAvailableFeatures(getSTI().getFeatureBits());
2578 ((AMDGPUOperand &)*Operands[0]).
getToken(), FBS);
2579 return Error(IDLoc,
"invalid instruction" + Suggestion,
2580 ((AMDGPUOperand &)*Operands[0]).getLocRange());
2583 case Match_InvalidOperand: {
2584 SMLoc ErrorLoc = IDLoc;
2585 if (ErrorInfo != ~0ULL) {
2586 if (ErrorInfo >= Operands.
size()) {
2587 return Error(IDLoc,
"too few operands for instruction");
2589 ErrorLoc = ((AMDGPUOperand &)*Operands[ErrorInfo]).getStartLoc();
2590 if (ErrorLoc ==
SMLoc())
2593 return Error(ErrorLoc,
"invalid operand for instruction");
2596 case Match_PreferE32:
2597 return Error(IDLoc,
"internal error: instruction without _e64 suffix " 2598 "should be encoded as e32");
2603 bool AMDGPUAsmParser::ParseAsAbsoluteExpression(
uint32_t &
Ret) {
2608 if (getParser().parseAbsoluteExpression(Tmp)) {
2615 bool AMDGPUAsmParser::ParseDirectiveMajorMinor(
uint32_t &Major,
2617 if (ParseAsAbsoluteExpression(Major))
2618 return TokError(
"invalid major version");
2621 return TokError(
"minor version number required, comma expected");
2624 if (ParseAsAbsoluteExpression(Minor))
2625 return TokError(
"invalid minor version");
2630 bool AMDGPUAsmParser::ParseDirectiveAMDGCNTarget() {
2632 return TokError(
"directive only supported for amdgcn architecture");
2636 SMLoc TargetStart = getTok().getLoc();
2637 if (getParser().parseEscapedString(Target))
2641 std::string ExpectedTarget;
2645 if (Target != ExpectedTargetOS.
str())
2646 return getParser().Error(TargetRange.
Start,
"target must match options",
2649 getTargetStreamer().EmitDirectiveAMDGCNTarget(Target);
2653 bool AMDGPUAsmParser::OutOfRangeError(
SMRange Range) {
2654 return getParser().Error(Range.
Start,
"value out of range", Range);
2657 bool AMDGPUAsmParser::calculateGPRBlocks(
2659 bool XNACKUsed,
unsigned NextFreeVGPR,
SMRange VGPRRange,
2660 unsigned NextFreeSGPR,
SMRange SGPRRange,
unsigned &VGPRBlocks,
2661 unsigned &SGPRBlocks) {
2670 if (Version.
Major >= 8 && !Features.test(FeatureSGPRInitBug) &&
2671 NumSGPRs > MaxAddressableNumSGPRs)
2672 return OutOfRangeError(SGPRRange);
2677 if ((Version.
Major <= 7 || Features.test(FeatureSGPRInitBug)) &&
2678 NumSGPRs > MaxAddressableNumSGPRs)
2679 return OutOfRangeError(SGPRRange);
2681 if (Features.test(FeatureSGPRInitBug))
2690 bool AMDGPUAsmParser::ParseDirectiveAMDHSAKernel() {
2692 return TokError(
"directive only supported for amdgcn architecture");
2695 return TokError(
"directive only supported for amdhsa OS");
2698 if (getParser().parseIdentifier(KernelName))
2709 uint64_t NextFreeVGPR = 0;
2711 uint64_t NextFreeSGPR = 0;
2712 unsigned UserSGPRCount = 0;
2713 bool ReserveVCC =
true;
2714 bool ReserveFlatScr =
true;
2722 return TokError(
"expected .amdhsa_ directive or .end_amdhsa_kernel");
2725 SMRange IDRange = getTok().getLocRange();
2728 if (ID ==
".end_amdhsa_kernel")
2731 if (Seen.
find(ID) != Seen.
end())
2732 return TokError(
".amdhsa_ directives cannot be repeated");
2735 SMLoc ValStart = getTok().getLoc();
2737 if (getParser().parseAbsoluteExpression(IVal))
2739 SMLoc ValEnd = getTok().getLoc();
2743 return OutOfRangeError(ValRange);
2745 uint64_t Val = IVal;
2747 #define PARSE_BITS_ENTRY(FIELD, ENTRY, VALUE, RANGE) \ 2748 if (!isUInt<ENTRY##_WIDTH>(VALUE)) \ 2749 return OutOfRangeError(RANGE); \ 2750 AMDHSA_BITS_SET(FIELD, ENTRY, VALUE); 2752 if (ID ==
".amdhsa_group_segment_fixed_size") {
2754 return OutOfRangeError(ValRange);
2756 }
else if (ID ==
".amdhsa_private_segment_fixed_size") {
2758 return OutOfRangeError(ValRange);
2760 }
else if (ID ==
".amdhsa_user_sgpr_private_segment_buffer") {
2762 KERNEL_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_BUFFER,
2765 }
else if (ID ==
".amdhsa_user_sgpr_dispatch_ptr") {
2767 KERNEL_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_PTR, Val,
2770 }
else if (ID ==
".amdhsa_user_sgpr_queue_ptr") {
2772 KERNEL_CODE_PROPERTY_ENABLE_SGPR_QUEUE_PTR, Val,
2775 }
else if (ID ==
".amdhsa_user_sgpr_kernarg_segment_ptr") {
2777 KERNEL_CODE_PROPERTY_ENABLE_SGPR_KERNARG_SEGMENT_PTR,
2780 }
else if (ID ==
".amdhsa_user_sgpr_dispatch_id") {
2782 KERNEL_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_ID, Val,
2785 }
else if (ID ==
".amdhsa_user_sgpr_flat_scratch_init") {
2787 KERNEL_CODE_PROPERTY_ENABLE_SGPR_FLAT_SCRATCH_INIT, Val,
2790 }
else if (ID ==
".amdhsa_user_sgpr_private_segment_size") {
2792 KERNEL_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_SIZE,
2795 }
else if (ID ==
".amdhsa_system_sgpr_private_segment_wavefront_offset") {
2798 COMPUTE_PGM_RSRC2_ENABLE_SGPR_PRIVATE_SEGMENT_WAVEFRONT_OFFSET, Val,
2800 }
else if (ID ==
".amdhsa_system_sgpr_workgroup_id_x") {
2802 COMPUTE_PGM_RSRC2_ENABLE_SGPR_WORKGROUP_ID_X, Val,
2804 }
else if (ID ==
".amdhsa_system_sgpr_workgroup_id_y") {
2806 COMPUTE_PGM_RSRC2_ENABLE_SGPR_WORKGROUP_ID_Y, Val,
2808 }
else if (ID ==
".amdhsa_system_sgpr_workgroup_id_z") {
2810 COMPUTE_PGM_RSRC2_ENABLE_SGPR_WORKGROUP_ID_Z, Val,
2812 }
else if (ID ==
".amdhsa_system_sgpr_workgroup_info") {
2814 COMPUTE_PGM_RSRC2_ENABLE_SGPR_WORKGROUP_INFO, Val,
2816 }
else if (ID ==
".amdhsa_system_vgpr_workitem_id") {
2818 COMPUTE_PGM_RSRC2_ENABLE_VGPR_WORKITEM_ID, Val,
2820 }
else if (ID ==
".amdhsa_next_free_vgpr") {
2821 VGPRRange = ValRange;
2823 }
else if (ID ==
".amdhsa_next_free_sgpr") {
2824 SGPRRange = ValRange;
2826 }
else if (ID ==
".amdhsa_reserve_vcc") {
2827 if (!isUInt<1>(Val))
2828 return OutOfRangeError(ValRange);
2830 }
else if (ID ==
".amdhsa_reserve_flat_scratch") {
2831 if (IVersion.
Major < 7)
2832 return getParser().Error(IDRange.
Start,
"directive requires gfx7+",
2834 if (!isUInt<1>(Val))
2835 return OutOfRangeError(ValRange);
2836 ReserveFlatScr = Val;
2837 }
else if (ID ==
".amdhsa_reserve_xnack_mask") {
2838 if (IVersion.
Major < 8)
2839 return getParser().Error(IDRange.
Start,
"directive requires gfx8+",
2841 if (!isUInt<1>(Val))
2842 return OutOfRangeError(ValRange);
2844 }
else if (ID ==
".amdhsa_float_round_mode_32") {
2846 COMPUTE_PGM_RSRC1_FLOAT_ROUND_MODE_32, Val, ValRange);
2847 }
else if (ID ==
".amdhsa_float_round_mode_16_64") {
2849 COMPUTE_PGM_RSRC1_FLOAT_ROUND_MODE_16_64, Val, ValRange);
2850 }
else if (ID ==
".amdhsa_float_denorm_mode_32") {
2852 COMPUTE_PGM_RSRC1_FLOAT_DENORM_MODE_32, Val, ValRange);
2853 }
else if (ID ==
".amdhsa_float_denorm_mode_16_64") {
2855 COMPUTE_PGM_RSRC1_FLOAT_DENORM_MODE_16_64, Val,
2857 }
else if (ID ==
".amdhsa_dx10_clamp") {
2859 COMPUTE_PGM_RSRC1_ENABLE_DX10_CLAMP, Val, ValRange);
2860 }
else if (ID ==
".amdhsa_ieee_mode") {
2863 }
else if (ID ==
".amdhsa_fp16_overflow") {
2864 if (IVersion.
Major < 9)
2865 return getParser().Error(IDRange.
Start,
"directive requires gfx9+",
2869 }
else if (ID ==
".amdhsa_exception_fp_ieee_invalid_op") {
2872 COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_INVALID_OPERATION, Val,
2874 }
else if (ID ==
".amdhsa_exception_fp_denorm_src") {
2876 COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_FP_DENORMAL_SOURCE,
2878 }
else if (ID ==
".amdhsa_exception_fp_ieee_div_zero") {
2881 COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_DIVISION_BY_ZERO, Val,
2883 }
else if (ID ==
".amdhsa_exception_fp_ieee_overflow") {
2885 COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_OVERFLOW,
2887 }
else if (ID ==
".amdhsa_exception_fp_ieee_underflow") {
2889 COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_UNDERFLOW,
2891 }
else if (ID ==
".amdhsa_exception_fp_ieee_inexact") {
2893 COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_INEXACT,
2895 }
else if (ID ==
".amdhsa_exception_int_div_zero") {
2897 COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_INT_DIVIDE_BY_ZERO,
2900 return getParser().Error(IDRange.
Start,
2901 "unknown .amdhsa_kernel directive", IDRange);
2904 #undef PARSE_BITS_ENTRY 2907 if (Seen.
find(
".amdhsa_next_free_vgpr") == Seen.
end())
2908 return TokError(
".amdhsa_next_free_vgpr directive is required");
2910 if (Seen.
find(
".amdhsa_next_free_sgpr") == Seen.
end())
2911 return TokError(
".amdhsa_next_free_sgpr directive is required");
2913 unsigned VGPRBlocks;
2914 unsigned SGPRBlocks;
2915 if (calculateGPRBlocks(getFeatureBits(), ReserveVCC, ReserveFlatScr,
2916 ReserveXNACK, NextFreeVGPR, VGPRRange, NextFreeSGPR,
2917 SGPRRange, VGPRBlocks, SGPRBlocks))
2920 if (!isUInt<COMPUTE_PGM_RSRC1_GRANULATED_WORKITEM_VGPR_COUNT_WIDTH>(
2922 return OutOfRangeError(VGPRRange);
2924 COMPUTE_PGM_RSRC1_GRANULATED_WORKITEM_VGPR_COUNT, VGPRBlocks);
2926 if (!isUInt<COMPUTE_PGM_RSRC1_GRANULATED_WAVEFRONT_SGPR_COUNT_WIDTH>(
2928 return OutOfRangeError(SGPRRange);
2930 COMPUTE_PGM_RSRC1_GRANULATED_WAVEFRONT_SGPR_COUNT,
2933 if (!isUInt<COMPUTE_PGM_RSRC2_USER_SGPR_COUNT_WIDTH>(UserSGPRCount))
2934 return TokError(
"too many user SGPRs enabled");
2938 getTargetStreamer().EmitAmdhsaKernelDescriptor(
2939 getSTI(), KernelName, KD, NextFreeVGPR, NextFreeSGPR, ReserveVCC,
2940 ReserveFlatScr, ReserveXNACK);
2944 bool AMDGPUAsmParser::ParseDirectiveHSACodeObjectVersion() {
2948 if (ParseDirectiveMajorMinor(Major, Minor))
2951 getTargetStreamer().EmitDirectiveHSACodeObjectVersion(Major, Minor);
2955 bool AMDGPUAsmParser::ParseDirectiveHSACodeObjectISA() {
2967 getTargetStreamer().EmitDirectiveHSACodeObjectISA(ISA.
Major, ISA.
Minor,
2973 if (ParseDirectiveMajorMinor(Major, Minor))
2977 return TokError(
"stepping version number required, comma expected");
2980 if (ParseAsAbsoluteExpression(Stepping))
2981 return TokError(
"invalid stepping version");
2984 return TokError(
"vendor name required, comma expected");
2988 return TokError(
"invalid vendor name");
2990 VendorName = getLexer().getTok().getStringContents();
2994 return TokError(
"arch name required, comma expected");
2998 return TokError(
"invalid arch name");
3000 ArchName = getLexer().getTok().getStringContents();
3003 getTargetStreamer().EmitDirectiveHSACodeObjectISA(Major, Minor, Stepping,
3004 VendorName, ArchName);
3008 bool AMDGPUAsmParser::ParseAMDKernelCodeTValue(
StringRef ID,
3012 if (ID ==
"max_scratch_backing_memory_byte_size") {
3013 Parser.eatToEndOfStatement();
3020 return TokError(Err.
str());
3026 bool AMDGPUAsmParser::ParseDirectiveAMDKernelCodeT() {
3037 return TokError(
"expected value identifier or .end_amd_kernel_code_t");
3039 StringRef ID = getLexer().getTok().getIdentifier();
3042 if (ID ==
".end_amd_kernel_code_t")
3045 if (ParseAMDKernelCodeTValue(ID, Header))
3049 getTargetStreamer().EmitAMDKernelCodeT(Header);
3054 bool AMDGPUAsmParser::ParseDirectiveAMDGPUHsaKernel() {
3056 return TokError(
"expected symbol name");
3058 StringRef KernelName = Parser.getTok().getString();
3060 getTargetStreamer().EmitAMDGPUSymbolType(KernelName,
3064 KernelScope.initialize(getContext());
3068 bool AMDGPUAsmParser::ParseDirectiveISAVersion() {
3070 return Error(getParser().getTok().getLoc(),
3071 ".amd_amdgpu_isa directive is not available on non-amdgcn " 3075 auto ISAVersionStringFromASM = getLexer().getTok().getStringContents();
3077 std::string ISAVersionStringFromSTI;
3081 if (ISAVersionStringFromASM != ISAVersionStreamFromSTI.
str()) {
3082 return Error(getParser().getTok().getLoc(),
3083 ".amd_amdgpu_isa directive does not match triple and/or mcpu " 3084 "arguments specified through the command line");
3087 getTargetStreamer().EmitISAVersion(ISAVersionStreamFromSTI.
str());
3093 bool AMDGPUAsmParser::ParseDirectiveHSAMetadata() {
3095 return Error(getParser().getTok().getLoc(),
3097 "not available on non-amdhsa OSes")).str());
3100 std::string HSAMetadataString;
3103 getLexer().setSkipSpace(
false);
3105 bool FoundEnd =
false;
3108 YamlStream << getLexer().getTok().getString();
3113 StringRef ID = getLexer().getTok().getIdentifier();
3121 YamlStream << Parser.parseStringToEndOfStatement()
3122 << getContext().getAsmInfo()->getSeparatorString();
3124 Parser.eatToEndOfStatement();
3127 getLexer().setSkipSpace(
true);
3130 return TokError(
Twine(
"expected directive ") +
3136 if (!getTargetStreamer().EmitHSAMetadata(HSAMetadataString))
3137 return Error(getParser().getTok().getLoc(),
"invalid HSA metadata");
3142 bool AMDGPUAsmParser::ParseDirectivePALMetadata() {
3144 return Error(getParser().getTok().getLoc(),
3146 "not available on non-amdpal OSes")).str());
3152 if (ParseAsAbsoluteExpression(Value)) {
3153 return TokError(
Twine(
"invalid value in ") +
3156 PALMetadata.push_back(Value);
3161 getTargetStreamer().EmitPALMetadata(PALMetadata);
3165 bool AMDGPUAsmParser::ParseDirective(
AsmToken DirectiveID) {
3169 if (IDVal ==
".amdgcn_target")
3170 return ParseDirectiveAMDGCNTarget();
3172 if (IDVal ==
".amdhsa_kernel")
3173 return ParseDirectiveAMDHSAKernel();
3175 if (IDVal ==
".hsa_code_object_version")
3176 return ParseDirectiveHSACodeObjectVersion();
3178 if (IDVal ==
".hsa_code_object_isa")
3179 return ParseDirectiveHSACodeObjectISA();
3181 if (IDVal ==
".amd_kernel_code_t")
3182 return ParseDirectiveAMDKernelCodeT();
3184 if (IDVal ==
".amdgpu_hsa_kernel")
3185 return ParseDirectiveAMDGPUHsaKernel();
3187 if (IDVal ==
".amd_amdgpu_isa")
3188 return ParseDirectiveISAVersion();
3192 return ParseDirectiveHSAMetadata();
3195 return ParseDirectivePALMetadata();
3201 unsigned RegNo)
const {
3211 case AMDGPU::TBA_LO:
3212 case AMDGPU::TBA_HI:
3214 case AMDGPU::TMA_LO:
3215 case AMDGPU::TMA_HI:
3217 case AMDGPU::XNACK_MASK:
3218 case AMDGPU::XNACK_MASK_LO:
3219 case AMDGPU::XNACK_MASK_HI:
3231 case AMDGPU::FLAT_SCR:
3232 case AMDGPU::FLAT_SCR_LO:
3233 case AMDGPU::FLAT_SCR_HI:
3266 ResTy = parseRegOrImm(Operands);
3271 const auto &Tok = Parser.getTok();
3272 SMLoc S = Tok.getLoc();
3274 const MCExpr *Expr =
nullptr;
3275 if (!Parser.parseExpression(Expr)) {
3276 Operands.
push_back(AMDGPUOperand::CreateExpr(
this, Expr, S));
3282 Operands.
push_back(AMDGPUOperand::CreateToken(
this, Tok.getString(), S));
3292 setForcedEncodingSize(0);
3293 setForcedDPP(
false);
3294 setForcedSDWA(
false);
3297 setForcedEncodingSize(64);
3299 }
else if (Name.
endswith(
"_e32")) {
3300 setForcedEncodingSize(32);
3302 }
else if (Name.
endswith(
"_dpp")) {
3305 }
else if (Name.
endswith(
"_sdwa")) {
3306 setForcedSDWA(
true);
3316 Name = parseMnemonicSuffix(Name);
3317 Operands.
push_back(AMDGPUOperand::CreateToken(
this, Name, NameLoc));
3329 Error(getLexer().getLoc(),
"failed parsing operand.");
3335 Error(getLexer().getLoc(),
"not a valid operand.");
3351 AMDGPUAsmParser::parseIntWithPrefix(
const char *
Prefix, int64_t &Int) {
3352 switch(getLexer().getKind()) {
3355 StringRef Name = Parser.getTok().getString();
3356 if (!Name.
equals(Prefix)) {
3366 bool IsMinus =
false;
3375 if (getParser().parseAbsoluteExpression(Int))
3387 AMDGPUAsmParser::parseIntWithPrefix(
const char *Prefix,
OperandVector &Operands,
3388 AMDGPUOperand::ImmTy ImmTy,
3389 bool (*ConvertResult)(int64_t&)) {
3390 SMLoc S = Parser.getTok().getLoc();
3397 if (ConvertResult && !ConvertResult(Value)) {
3401 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Value, S, ImmTy));
3408 AMDGPUOperand::ImmTy ImmTy,
3409 bool (*ConvertResult)(int64_t&)) {
3410 StringRef Name = Parser.getTok().getString();
3411 if (!Name.
equals(Prefix))
3424 SMLoc S = Parser.getTok().getLoc();
3428 for (
int I = 0;
I < 4; ++
I) {
3442 if (getParser().parseAbsoluteExpression(Op))
3445 if (Op != 0 && Op != 1)
3451 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Val, S, ImmTy));
3456 AMDGPUAsmParser::parseNamedBit(
const char *Name,
OperandVector &Operands,
3457 AMDGPUOperand::ImmTy ImmTy) {
3459 SMLoc S = Parser.getTok().getLoc();
3464 switch(getLexer().getKind()) {
3466 StringRef Tok = Parser.getTok().getString();
3483 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Bit, S, ImmTy));
3489 AMDGPUAsmParser::OptionalImmIndexMap& OptionalIdx,
3490 AMDGPUOperand::ImmTy ImmT,
3491 int64_t Default = 0) {
3492 auto i = OptionalIdx.find(ImmT);
3493 if (i != OptionalIdx.end()) {
3494 unsigned Idx = i->second;
3495 ((AMDGPUOperand &)*Operands[Idx]).addImmOperands(Inst, 1);
3506 StringRef Tok = Parser.getTok().getString();
3507 if (Tok != Prefix) {
3521 Value = Parser.getTok().getString();
3529 void AMDGPUAsmParser::cvtDSOffset01(
MCInst &Inst,
3531 OptionalImmIndexMap OptionalIdx;
3533 for (
unsigned i = 1, e = Operands.
size(); i != e; ++i) {
3534 AMDGPUOperand &
Op = ((AMDGPUOperand &)*Operands[i]);
3538 Op.addRegOperands(Inst, 1);
3543 OptionalIdx[Op.getImmTy()] = i;
3554 bool IsGdsHardcoded) {
3555 OptionalImmIndexMap OptionalIdx;
3557 for (
unsigned i = 1, e = Operands.
size(); i != e; ++i) {
3558 AMDGPUOperand &
Op = ((AMDGPUOperand &)*Operands[i]);
3562 Op.addRegOperands(Inst, 1);
3566 if (Op.isToken() && Op.getToken() ==
"gds") {
3567 IsGdsHardcoded =
true;
3572 OptionalIdx[Op.getImmTy()] = i;
3575 AMDGPUOperand::ImmTy OffsetType =
3576 (Inst.
getOpcode() == AMDGPU::DS_SWIZZLE_B32_si ||
3577 Inst.
getOpcode() == AMDGPU::DS_SWIZZLE_B32_vi) ? AMDGPUOperand::ImmTySwizzle :
3578 AMDGPUOperand::ImmTyOffset;
3582 if (!IsGdsHardcoded) {
3589 OptionalImmIndexMap OptionalIdx;
3591 unsigned OperandIdx[4];
3592 unsigned EnMask = 0;
3595 for (
unsigned i = 1, e = Operands.
size(); i != e; ++i) {
3596 AMDGPUOperand &
Op = ((AMDGPUOperand &)*Operands[i]);
3601 OperandIdx[SrcIdx] = Inst.
size();
3602 Op.addRegOperands(Inst, 1);
3609 OperandIdx[SrcIdx] = Inst.
size();
3615 if (Op.isImm() && Op.getImmTy() == AMDGPUOperand::ImmTyExpTgt) {
3616 Op.addImmOperands(Inst, 1);
3620 if (Op.isToken() && Op.getToken() ==
"done")
3624 OptionalIdx[Op.getImmTy()] = i;
3630 if (OptionalIdx.find(AMDGPUOperand::ImmTyExpCompr) != OptionalIdx.end()) {
3637 for (
auto i = 0; i < SrcIdx; ++i) {
3639 EnMask |= Compr? (0x3 << i * 2) : (0x1 << i);
3664 IntVal = encode(ISA, IntVal, CntVal);
3665 if (CntVal !=
decode(ISA, IntVal)) {
3667 IntVal = encode(ISA, IntVal, -1);
3675 bool AMDGPUAsmParser::parseCnt(int64_t &IntVal) {
3676 StringRef CntName = Parser.getTok().getString();
3687 SMLoc ValLoc = Parser.getTok().getLoc();
3688 if (getParser().parseAbsoluteExpression(CntVal))
3695 bool Sat = CntName.
endswith(
"_sat");
3697 if (CntName ==
"vmcnt" || CntName ==
"vmcnt_sat") {
3699 }
else if (CntName ==
"expcnt" || CntName ==
"expcnt_sat") {
3701 }
else if (CntName ==
"lgkmcnt" || CntName ==
"lgkmcnt_sat") {
3706 Error(ValLoc,
"too large value for " + CntName);
3716 const AsmToken NextToken = getLexer().peekTok();
3726 AMDGPUAsmParser::parseSWaitCntOps(
OperandVector &Operands) {
3730 SMLoc S = Parser.getTok().getLoc();
3732 switch(getLexer().getKind()) {
3736 if (getParser().parseAbsoluteExpression(Waitcnt))
3742 if (parseCnt(Waitcnt))
3747 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Waitcnt, S));
3751 bool AMDGPUAsmParser::parseHwregConstruct(OperandInfoTy &HwReg, int64_t &
Offset,
3755 if (Parser.getTok().getString() !=
"hwreg")
3764 HwReg.IsSymbolic =
true;
3766 const StringRef tok = Parser.getTok().getString();
3778 HwReg.IsSymbolic =
false;
3781 if (getParser().parseAbsoluteExpression(HwReg.Id))
3797 if (getParser().parseAbsoluteExpression(Offset))
3806 if (getParser().parseAbsoluteExpression(Width))
3819 int64_t Imm16Val = 0;
3820 SMLoc S = Parser.getTok().getLoc();
3822 switch(getLexer().getKind()) {
3826 if (getParser().parseAbsoluteExpression(Imm16Val))
3829 Error(S,
"invalid immediate: only 16-bit values are legal");
3839 if (parseHwregConstruct(HwReg, Offset, Width))
3841 if (HwReg.Id < 0 || !isUInt<ID_WIDTH_>(HwReg.Id)) {
3842 if (HwReg.IsSymbolic)
3843 Error(S,
"invalid symbolic name of hardware register");
3845 Error(S,
"invalid code of hardware register: only 6-bit values are legal");
3847 if (Offset < 0 || !isUInt<OFFSET_WIDTH_>(Offset))
3848 Error(S,
"invalid bit offset: only 5-bit values are legal");
3849 if ((Width-1) < 0 || !isUInt<WIDTH_M1_WIDTH_>(Width-1))
3850 Error(S,
"invalid bitfield width: only values from 1 to 32 are legal");
3855 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Imm16Val, S, AMDGPUOperand::ImmTyHwreg));
3859 bool AMDGPUOperand::isSWaitCnt()
const {
3863 bool AMDGPUOperand::isHwreg()
const {
3864 return isImmTy(ImmTyHwreg);
3867 bool AMDGPUAsmParser::parseSendMsgConstruct(OperandInfoTy &Msg, OperandInfoTy &
Operation, int64_t &
StreamId) {
3870 if (Parser.getTok().getString() !=
"sendmsg")
3879 Msg.IsSymbolic =
true;
3881 const std::string tok = Parser.getTok().getString();
3894 Msg.IsSymbolic =
false;
3897 if (getParser().parseAbsoluteExpression(Msg.Id))
3900 if (getParser().parseAbsoluteExpression(Msg.Id))
3920 Operation.IsSymbolic =
true;
3924 const StringRef Tok = Parser.getTok().getString();
3925 for (
int i = F; i < L; ++i) {
3933 Operation.IsSymbolic =
false;
3936 if (getParser().parseAbsoluteExpression(Operation.Id))
3953 if (getParser().parseAbsoluteExpression(StreamId))
3967 StringRef Str = Parser.getTok().getString();
3974 SMLoc S = Parser.getTok().getLoc();
3979 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Slot, S,
3980 AMDGPUOperand::ImmTyInterpSlot));
3988 StringRef Str = Parser.getTok().getString();
4008 SMLoc S = Parser.getTok().getLoc();
4011 Error(S,
"out of bounds attr");
4017 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Attr, S,
4018 AMDGPUOperand::ImmTyInterpAttr));
4019 Operands.
push_back(AMDGPUOperand::CreateImm(
this, AttrChan, SChan,
4020 AMDGPUOperand::ImmTyAttrChan));
4024 void AMDGPUAsmParser::errorExpTgt() {
4025 Error(Parser.getTok().getLoc(),
"invalid exp target");
4030 if (Str ==
"null") {
4089 StringRef Str = Parser.getTok().getString();
4091 auto Res = parseExpTgtImpl(Str, Val);
4095 SMLoc S = Parser.getTok().getLoc();
4098 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Val, S,
4099 AMDGPUOperand::ImmTyExpTgt));
4107 int64_t Imm16Val = 0;
4108 SMLoc S = Parser.getTok().getLoc();
4110 switch(getLexer().getKind()) {
4115 if (getParser().parseAbsoluteExpression(Imm16Val))
4118 Error(S,
"invalid immediate: only 16-bit values are legal");
4127 if (parseSendMsgConstruct(Msg, Operation, StreamId))
4134 Error(S,
"invalid/unsupported symbolic name of message");
4136 Error(S,
"invalid/unsupported code of message");
4143 if (Operation.IsSymbolic)
4144 Error(S,
"invalid symbolic name of GS_OP");
4146 Error(S,
"invalid code of GS_OP: only 2-bit values are legal");
4151 Error(S,
"invalid GS_OP: NOP is for GS_DONE only");
4154 Imm16Val |= (Operation.Id <<
OP_SHIFT_);
4158 if (Operation.IsSymbolic)
4159 Error(S,
"invalid/unsupported symbolic name of SYSMSG_OP");
4161 Error(S,
"invalid/unsupported code of SYSMSG_OP");
4164 Imm16Val |= (Operation.Id <<
OP_SHIFT_);
4169 Error(S,
"invalid stream id: only 2-bit values are legal");
4178 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Imm16Val, S, AMDGPUOperand::ImmTySendMsg));
4182 bool AMDGPUOperand::isSendMsg()
const {
4183 return isImmTy(ImmTySendMsg);
4193 Parser.getTok().getString() ==
Id) {
4202 if (getLexer().getKind() == Kind) {
4212 if (!trySkipToken(Kind)) {
4213 Error(Parser.getTok().getLoc(), ErrMsg);
4220 AMDGPUAsmParser::parseExpr(int64_t &Imm) {
4221 return !getParser().parseAbsoluteExpression(Imm);
4226 SMLoc S = Parser.getTok().getLoc();
4228 Val = Parser.getTok().getStringContents();
4244 const unsigned OrMask,
4245 const unsigned XorMask) {
4255 AMDGPUAsmParser::parseSwizzleOperands(
const unsigned OpNum, int64_t*
Op,
4256 const unsigned MinVal,
4257 const unsigned MaxVal,
4259 for (
unsigned i = 0; i < OpNum; ++i) {
4263 SMLoc ExprLoc = Parser.getTok().getLoc();
4264 if (!parseExpr(Op[i])) {
4267 if (Op[i] < MinVal || Op[i] > MaxVal) {
4268 Error(ExprLoc, ErrMsg);
4277 AMDGPUAsmParser::parseSwizzleQuadPerm(int64_t &Imm) {
4282 "expected a 2-bit lane id")) {
4284 for (
auto i = 0; i <
LANE_NUM; ++i) {
4293 AMDGPUAsmParser::parseSwizzleBroadcast(int64_t &Imm) {
4296 SMLoc S = Parser.getTok().getLoc();
4300 if (!parseSwizzleOperands(1, &GroupSize,
4302 "group size must be in the interval [2,32]")) {
4306 Error(S,
"group size must be a power of two");
4309 if (parseSwizzleOperands(1, &LaneIdx,
4311 "lane id must be in the interval [0,group size - 1]")) {
4319 AMDGPUAsmParser::parseSwizzleReverse(int64_t &Imm) {
4322 SMLoc S = Parser.getTok().getLoc();
4325 if (!parseSwizzleOperands(1, &GroupSize,
4326 2, 32,
"group size must be in the interval [2,32]")) {
4330 Error(S,
"group size must be a power of two");
4339 AMDGPUAsmParser::parseSwizzleSwap(int64_t &Imm) {
4342 SMLoc S = Parser.getTok().getLoc();
4345 if (!parseSwizzleOperands(1, &GroupSize,
4346 1, 16,
"group size must be in the interval [1,16]")) {
4350 Error(S,
"group size must be a power of two");
4359 AMDGPUAsmParser::parseSwizzleBitmaskPerm(int64_t &Imm) {
4367 SMLoc StrLoc = Parser.getTok().getLoc();
4368 if (!parseString(Ctl)) {
4372 Error(StrLoc,
"expected a 5-character mask");
4376 unsigned AndMask = 0;
4377 unsigned OrMask = 0;
4378 unsigned XorMask = 0;
4380 for (
size_t i = 0; i < Ctl.
size(); ++i) {
4384 Error(StrLoc,
"invalid mask");
4406 AMDGPUAsmParser::parseSwizzleOffset(int64_t &Imm) {
4408 SMLoc OffsetLoc = Parser.getTok().getLoc();
4410 if (!parseExpr(Imm)) {
4414 Error(OffsetLoc,
"expected a 16-bit offset");
4421 AMDGPUAsmParser::parseSwizzleMacro(int64_t &Imm) {
4426 SMLoc ModeLoc = Parser.getTok().getLoc();
4430 Ok = parseSwizzleQuadPerm(Imm);
4432 Ok = parseSwizzleBitmaskPerm(Imm);
4434 Ok = parseSwizzleBroadcast(Imm);
4436 Ok = parseSwizzleSwap(Imm);
4438 Ok = parseSwizzleReverse(Imm);
4440 Error(ModeLoc,
"expected a swizzle mode");
4443 return Ok && skipToken(
AsmToken::RParen,
"expected a closing parentheses");
4451 SMLoc S = Parser.getTok().getLoc();
4454 if (trySkipId(
"offset")) {
4458 if (trySkipId(
"swizzle")) {
4459 Ok = parseSwizzleMacro(Imm);
4461 Ok = parseSwizzleOffset(Imm);
4465 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Imm, S, AMDGPUOperand::ImmTySwizzle));
4471 return parseOptionalOpr(Operands);
4476 AMDGPUOperand::isSwizzle()
const {
4477 return isImmTy(ImmTySwizzle);
4485 AMDGPUAsmParser::parseSOppBrTarget(
OperandVector &Operands) {
4486 SMLoc S = Parser.getTok().getLoc();
4488 switch (getLexer().getKind()) {
4492 if (getParser().parseAbsoluteExpression(Imm))
4494 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Imm, S));
4499 Operands.
push_back(AMDGPUOperand::CreateExpr(
this,
4501 Parser.getTok().getString()), getContext()), S));
4511 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultGLC()
const {
4512 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyGLC);
4515 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultSLC()
const {
4516 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTySLC);
4519 void AMDGPUAsmParser::cvtMubufImpl(
MCInst &Inst,
4522 bool IsAtomicReturn,
4524 bool IsLdsOpcode = IsLds;
4525 bool HasLdsModifier =
false;
4526 OptionalImmIndexMap OptionalIdx;
4527 assert(IsAtomicReturn ? IsAtomic :
true);
4529 for (
unsigned i = 1, e = Operands.
size(); i != e; ++i) {
4530 AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[i]);
4534 Op.addRegOperands(Inst, 1);
4539 if (Op.isImm() && Op.getImmTy() == AMDGPUOperand::ImmTyNone) {
4540 Op.addImmOperands(Inst, 1);
4544 HasLdsModifier = Op.isLDS();
4554 OptionalIdx[Op.getImmTy()] = i;
4564 if (IsLdsOpcode && !HasLdsModifier) {
4566 if (NoLdsOpcode != -1) {
4568 IsLdsOpcode =
false;
4573 if (IsAtomicReturn) {
4590 OptionalImmIndexMap OptionalIdx;
4592 for (
unsigned i = 1, e = Operands.
size(); i != e; ++i) {
4593 AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[i]);
4597 Op.addRegOperands(Inst, 1);
4602 if (Op.isImm() && Op.getImmTy() == AMDGPUOperand::ImmTyNone) {
4603 Op.addImmOperands(Inst, 1);
4615 OptionalIdx[Op.getImmTy()] = i;
4619 AMDGPUOperand::ImmTyOffset);
4635 for (
unsigned J = 0; J < Desc.
getNumDefs(); ++J) {
4636 ((AMDGPUOperand &)*Operands[I++]).addRegOperands(Inst, 1);
4642 ((AMDGPUOperand &)*Operands[I - 1]).addRegOperands(Inst, 1);
4645 OptionalImmIndexMap OptionalIdx;
4647 for (
unsigned E = Operands.
size(); I !=
E; ++
I) {
4648 AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[I]);
4652 Op.addRegOperands(Inst, 1);
4653 }
else if (Op.isImmModifier()) {
4654 OptionalIdx[Op.getImmTy()] =
I;
4672 cvtMIMG(Inst, Operands,
true);
4679 bool AMDGPUOperand::isSMRDOffset8()
const {
4683 bool AMDGPUOperand::isSMRDOffset20()
const {
4684 return isImm() && isUInt<20>(getImm());
4687 bool AMDGPUOperand::isSMRDLiteralOffset()
const {
4693 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultSMRDOffset8()
const {
4694 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyOffset);
4697 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultSMRDOffset20()
const {
4698 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyOffset);
4701 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultSMRDLiteralOffset()
const {
4702 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyOffset);
4705 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultOffsetU12()
const {
4706 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyOffset);
4709 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultOffsetS13()
const {
4710 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyOffset);
4718 if (Mul != 1 && Mul != 2 && Mul != 4)
4740 if (BoundCtrl == 0) {
4745 if (BoundCtrl == -1) {
4755 {
"offen", AMDGPUOperand::ImmTyOffen,
true,
nullptr},
4756 {
"idxen", AMDGPUOperand::ImmTyIdxen,
true,
nullptr},
4757 {
"addr64", AMDGPUOperand::ImmTyAddr64,
true,
nullptr},
4758 {
"offset0", AMDGPUOperand::ImmTyOffset0,
false,
nullptr},
4759 {
"offset1", AMDGPUOperand::ImmTyOffset1,
false,
nullptr},
4760 {
"gds", AMDGPUOperand::ImmTyGDS,
true,
nullptr},
4761 {
"lds", AMDGPUOperand::ImmTyLDS,
true,
nullptr},
4762 {
"offset", AMDGPUOperand::ImmTyOffset,
false,
nullptr},
4763 {
"inst_offset", AMDGPUOperand::ImmTyInstOffset,
false,
nullptr},
4764 {
"dfmt", AMDGPUOperand::ImmTyDFMT,
false,
nullptr},
4765 {
"nfmt", AMDGPUOperand::ImmTyNFMT,
false,
nullptr},
4766 {
"glc", AMDGPUOperand::ImmTyGLC,
true,
nullptr},
4767 {
"slc", AMDGPUOperand::ImmTySLC,
true,
nullptr},
4768 {
"tfe", AMDGPUOperand::ImmTyTFE,
true,
nullptr},
4769 {
"d16", AMDGPUOperand::ImmTyD16,
true,
nullptr},
4770 {
"high", AMDGPUOperand::ImmTyHigh,
true,
nullptr},
4771 {
"clamp", AMDGPUOperand::ImmTyClampSI,
true,
nullptr},
4773 {
"unorm", AMDGPUOperand::ImmTyUNorm,
true,
nullptr},
4774 {
"da", AMDGPUOperand::ImmTyDA,
true,
nullptr},
4775 {
"r128", AMDGPUOperand::ImmTyR128,
true,
nullptr},
4776 {
"lwe", AMDGPUOperand::ImmTyLWE,
true,
nullptr},
4777 {
"d16", AMDGPUOperand::ImmTyD16,
true,
nullptr},
4778 {
"dmask", AMDGPUOperand::ImmTyDMask,
false,
nullptr},
4779 {
"row_mask", AMDGPUOperand::ImmTyDppRowMask,
false,
nullptr},
4780 {
"bank_mask", AMDGPUOperand::ImmTyDppBankMask,
false,
nullptr},
4782 {
"dst_sel", AMDGPUOperand::ImmTySdwaDstSel,
false,
nullptr},
4783 {
"src0_sel", AMDGPUOperand::ImmTySdwaSrc0Sel,
false,
nullptr},
4784 {
"src1_sel", AMDGPUOperand::ImmTySdwaSrc1Sel,
false,
nullptr},
4785 {
"dst_unused", AMDGPUOperand::ImmTySdwaDstUnused,
false,
nullptr},
4786 {
"compr", AMDGPUOperand::ImmTyExpCompr,
true,
nullptr },
4787 {
"vm", AMDGPUOperand::ImmTyExpVM,
true,
nullptr},
4788 {
"op_sel", AMDGPUOperand::ImmTyOpSel,
false,
nullptr},
4789 {
"op_sel_hi", AMDGPUOperand::ImmTyOpSelHi,
false,
nullptr},
4790 {
"neg_lo", AMDGPUOperand::ImmTyNegLo,
false,
nullptr},
4791 {
"neg_hi", AMDGPUOperand::ImmTyNegHi,
false,
nullptr}
4811 if (size == 1 || ((AMDGPUOperand &)*Operands[size - 1]).isRegKind()) {
4816 for (
unsigned i = 0; i < MAX_OPR_LOOKAHEAD; ++i) {
4820 res = parseOptionalOpr(Operands);
4829 for (
const OptionalOperand &Op : AMDGPUOptionalOperandTable) {
4832 res = parseNamedBit(Op.Name, Operands, Op.Type);
4833 }
else if (Op.Type == AMDGPUOperand::ImmTyOModSI) {
4834 res = parseOModOperand(Operands);
4835 }
else if (Op.Type == AMDGPUOperand::ImmTySdwaDstSel ||
4836 Op.Type == AMDGPUOperand::ImmTySdwaSrc0Sel ||
4837 Op.Type == AMDGPUOperand::ImmTySdwaSrc1Sel) {
4838 res = parseSDWASel(Operands, Op.Name, Op.Type);
4839 }
else if (Op.Type == AMDGPUOperand::ImmTySdwaDstUnused) {
4840 res = parseSDWADstUnused(Operands);
4841 }
else if (Op.Type == AMDGPUOperand::ImmTyOpSel ||
4842 Op.Type == AMDGPUOperand::ImmTyOpSelHi ||
4843 Op.Type == AMDGPUOperand::ImmTyNegLo ||
4844 Op.Type == AMDGPUOperand::ImmTyNegHi) {
4845 res = parseOperandArrayWithPrefix(Op.Name, Operands, Op.Type,
4848 res = parseIntWithPrefix(Op.Name, Operands, Op.Type, Op.ConvertResult);
4858 StringRef Name = Parser.getTok().getString();
4859 if (Name ==
"mul") {
4860 return parseIntWithPrefix(
"mul", Operands,
4864 if (Name ==
"div") {
4865 return parseIntWithPrefix(
"div", Operands,
4873 cvtVOP3P(Inst, Operands);
4878 const int Ops[] = { AMDGPU::OpName::src0,
4879 AMDGPU::OpName::src1,
4880 AMDGPU::OpName::src2 };
4889 if ((OpSel & (1 << SrcNum)) != 0) {
4909 OptionalImmIndexMap OptionalIdx;
4914 for (
unsigned J = 0; J < Desc.
getNumDefs(); ++J) {
4915 ((AMDGPUOperand &)*Operands[I++]).addRegOperands(Inst, 1);
4918 for (
unsigned E = Operands.
size(); I !=
E; ++
I) {
4919 AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[I]);
4921 Op.addRegOrImmWithFPInputModsOperands(Inst, 2);
4922 }
else if (Op.isInterpSlot() ||
4923 Op.isInterpAttr() ||
4926 }
else if (Op.isImmModifier()) {
4927 OptionalIdx[Op.getImmTy()] =
I;
4947 OptionalImmIndexMap &OptionalIdx) {
4952 for (
unsigned J = 0; J < Desc.
getNumDefs(); ++J) {
4953 ((AMDGPUOperand &)*Operands[I++]).addRegOperands(Inst, 1);
4958 for (
unsigned E = Operands.
size(); I !=
E; ++
I) {
4959 AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[I]);
4961 Op.addRegOrImmWithFPInputModsOperands(Inst, 2);
4962 }
else if (Op.isImmModifier()) {
4963 OptionalIdx[Op.getImmTy()] =
I;
4964 }
else if (Op.isRegOrImm()) {
4965 Op.addRegOrImmOperands(Inst, 1);
4972 for (
unsigned E = Operands.
size(); I !=
E; ++
I) {
4973 AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[I]);
4975 OptionalIdx[Op.getImmTy()] =
I;
4977 Op.addRegOrImmOperands(Inst, 1);
4994 if (Opc == AMDGPU::V_MAC_F32_e64_si ||
4995 Opc == AMDGPU::V_MAC_F32_e64_vi ||
4996 Opc == AMDGPU::V_MAC_F16_e64_vi ||
4997 Opc == AMDGPU::V_FMAC_F32_e64_vi) {
4998 auto it = Inst.
begin();
5007 OptionalImmIndexMap OptionalIdx;
5008 cvtVOP3(Inst, Operands, OptionalIdx);
5011 void AMDGPUAsmParser::cvtVOP3P(
MCInst &Inst,
5013 OptionalImmIndexMap OptIdx;
5019 cvtVOP3(Inst, Operands, OptIdx);
5032 if (OpSelHiIdx != -1) {
5033 int DefaultVal = IsPacked ? -1 : 0;
5039 if (NegLoIdx != -1) {
5045 const int Ops[] = { AMDGPU::OpName::src0,
5046 AMDGPU::OpName::src1,
5047 AMDGPU::OpName::src2 };
5048 const int ModOps[] = { AMDGPU::OpName::src0_modifiers,
5049 AMDGPU::OpName::src1_modifiers,
5050 AMDGPU::OpName::src2_modifiers };
5055 unsigned OpSelHi = 0;
5059 if (OpSelHiIdx != -1) {
5063 if (NegLoIdx != -1) {
5069 for (
int J = 0; J < 3; ++J) {
5076 if ((OpSel & (1 << J)) != 0)
5079 if ((OpSelHi & (1 << J)) != 0)
5082 if ((NegLo & (1 << J)) != 0)
5085 if ((NegHi & (1 << J)) != 0)
5098 bool AMDGPUOperand::isDPPCtrl()
const {
5101 bool result = isImm() && getImmTy() == ImmTyDppCtrl && isUInt<9>(getImm());
5103 int64_t Imm = getImm();
5120 bool AMDGPUOperand::isGPRIdxMode()
const {
5121 return isImm() && isUInt<4>(getImm());
5124 bool AMDGPUOperand::isS16Imm()
const {
5128 bool AMDGPUOperand::isU16Imm()
const {
5136 SMLoc S = Parser.getTok().getLoc();
5141 Prefix = Parser.getTok().getString();
5146 if (Prefix ==
"row_mirror") {
5149 }
else if (Prefix ==
"row_half_mirror") {
5154 if (Prefix !=
"quad_perm" 5155 && Prefix !=
"row_shl" 5156 && Prefix !=
"row_shr" 5157 && Prefix !=
"row_ror" 5158 && Prefix !=
"wave_shl" 5159 && Prefix !=
"wave_rol" 5160 && Prefix !=
"wave_shr" 5161 && Prefix !=
"wave_ror" 5162 && Prefix !=
"row_bcast") {
5170 if (Prefix ==
"quad_perm") {
5177 if (getParser().parseAbsoluteExpression(Int) || !(0 <= Int && Int <=3))
5180 for (
int i = 0; i < 3; ++i) {
5186 if (getParser().parseAbsoluteExpression(Temp) || !(0 <= Temp && Temp <=3))
5188 const int shift = i*2 + 2;
5189 Int += (Temp << shift);
5198 if (getParser().parseAbsoluteExpression(Int))
5201 if (Prefix ==
"row_shl" && 1 <= Int && Int <= 15) {
5203 }
else if (Prefix ==
"row_shr" && 1 <= Int && Int <= 15) {
5205 }
else if (Prefix ==
"row_ror" && 1 <= Int && Int <= 15) {
5207 }
else if (Prefix ==
"wave_shl" && 1 == Int) {
5209 }
else if (Prefix ==
"wave_rol" && 1 == Int) {
5211 }
else if (Prefix ==
"wave_shr" && 1 == Int) {
5213 }
else if (Prefix ==
"wave_ror" && 1 == Int) {
5215 }
else if (Prefix ==
"row_bcast") {
5218 }
else if (Int == 31) {
5229 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Int, S, AMDGPUOperand::ImmTyDppCtrl));
5233 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultRowMask()
const {
5234 return AMDGPUOperand::CreateImm(
this, 0xf,
SMLoc(), AMDGPUOperand::ImmTyDppRowMask);
5237 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultBankMask()
const {
5238 return AMDGPUOperand::CreateImm(
this, 0xf,
SMLoc(), AMDGPUOperand::ImmTyDppBankMask);
5241 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultBoundCtrl()
const {
5242 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyDppBoundCtrl);
5246 OptionalImmIndexMap OptionalIdx;
5250 for (
unsigned J = 0; J < Desc.
getNumDefs(); ++J) {
5251 ((AMDGPUOperand &)*Operands[I++]).addRegOperands(Inst, 1);
5259 for (
unsigned E = Operands.
size(); I !=
E; ++
I) {
5260 AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[I]);
5262 if (Op.isReg() && Op.Reg.RegNo == AMDGPU::VCC) {
5267 Op.addRegWithFPInputModsOperands(Inst, 2);
5268 }
else if (Op.isDPPCtrl()) {
5269 Op.addImmOperands(Inst, 1);
5270 }
else if (Op.isImm()) {
5272 OptionalIdx[Op.getImmTy()] =
I;
5289 AMDGPUOperand::ImmTy Type) {
5292 SMLoc S = Parser.getTok().getLoc();
5296 res = parseStringWithPrefix(Prefix, Value);
5313 if (Int == 0xffffffff) {
5317 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Int, S, Type));
5322 AMDGPUAsmParser::parseSDWADstUnused(
OperandVector &Operands) {
5325 SMLoc S = Parser.getTok().getLoc();
5329 res = parseStringWithPrefix(
"dst_unused", Value);
5342 if (Int == 0xffffffff) {
5346 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Int, S, AMDGPUOperand::ImmTySdwaDstUnused));
5367 uint64_t BasicInstType,
bool skipVcc) {
5370 OptionalImmIndexMap OptionalIdx;
5371 bool skippedVcc =
false;
5375 for (
unsigned J = 0; J < Desc.
getNumDefs(); ++J) {
5376 ((AMDGPUOperand &)*Operands[I++]).addRegOperands(Inst, 1);
5379 for (
unsigned E = Operands.
size(); I !=
E; ++
I) {
5380 AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[I]);
5381 if (skipVcc && !skippedVcc && Op.isReg() && Op.Reg.RegNo == AMDGPU::VCC) {
5397 Op.addRegOrImmWithInputModsOperands(Inst, 2);
5398 }
else if (Op.isImm()) {
5400 OptionalIdx[Op.getImmTy()] =
I;
5407 if (Inst.
getOpcode() != AMDGPU::V_NOP_sdwa_gfx9 &&
5408 Inst.
getOpcode() != AMDGPU::V_NOP_sdwa_vi) {
5410 switch (BasicInstType) {
5439 llvm_unreachable(
"Invalid instruction type. Only VOP1, VOP2 and VOPC allowed");
5445 if (Inst.
getOpcode() == AMDGPU::V_MAC_F32_sdwa_vi ||
5446 Inst.
getOpcode() == AMDGPU::V_MAC_F16_sdwa_vi) {
5447 auto it = Inst.
begin();
5460 #define GET_REGISTER_MATCHER 5461 #define GET_MATCHER_IMPLEMENTATION 5462 #define GET_MNEMONIC_SPELL_CHECKER 5463 #include "AMDGPUGenAsmMatcher.inc" 5473 AMDGPUOperand &Operand = (AMDGPUOperand&)Op;
5476 return Operand.isAddr64() ? Match_Success : Match_InvalidOperand;
5478 return Operand.isGDS() ? Match_Success : Match_InvalidOperand;
5480 return Operand.isLDS() ? Match_Success : Match_InvalidOperand;
5482 return Operand.isGLC() ? Match_Success : Match_InvalidOperand;
5484 return Operand.isIdxen() ? Match_Success : Match_InvalidOperand;
5486 return Operand.isOffen() ? Match_Success : Match_InvalidOperand;
5494 return Operand.isSSrcB32() ? Match_Success : Match_InvalidOperand;
5496 return Operand.isSSrcF32() ? Match_Success : Match_InvalidOperand;
5497 case MCK_SoppBrTarget:
5498 return Operand.isSoppBrTarget() ? Match_Success : Match_InvalidOperand;
5499 case MCK_VReg32OrOff:
5500 return Operand.isVReg32OrOff() ? Match_Success : Match_InvalidOperand;
5501 case MCK_InterpSlot:
5502 return Operand.isInterpSlot() ? Match_Success : Match_InvalidOperand;
5504 return Operand.isInterpAttr() ? Match_Success : Match_InvalidOperand;
5506 return Operand.isAttrChan() ? Match_Success : Match_InvalidOperand;
5508 return Match_InvalidOperand;
static bool isReg(const MCInst &MI, unsigned OpNo)
unsigned getNumImplicitUses() const
Return the number of implicit uses this instruction has.
constexpr bool isUInt< 32 >(uint64_t x)
unsigned getNumExtraSGPRs(const FeatureBitset &Features, bool VCCUsed, bool FlatScrUsed, bool XNACKUsed)
Represents a range in source code.
void push_back(const T &Elt)
unsigned mc2PseudoReg(unsigned Reg)
Convert hardware register Reg to a pseudo register.
Target & getTheGCNTarget()
The target for GCN GPUs.
bool hasPackedD16(const MCSubtargetInfo &STI)
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
static bool isRegOrImmWithInputMods(const MCInstrDesc &Desc, unsigned OpNum)
uint64_t getZExtValue() const
Get zero extended value.
static const fltSemantics * getOpFltSemantics(uint8_t OperandType)
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Compute iterated dominance frontiers using a linear time algorithm.
bool isVariable() const
isVariable - Check if this is a variable symbol.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
static MCOperand createExpr(const MCExpr *Val)
constexpr uint32_t Lo_32(uint64_t Value)
Return the low 32 bits of a 64 bit value.
Target & getTheAMDGPUTarget()
The target which supports all AMD GPUs.
Describe properties that are true of each instruction in the target description file.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
iterator find(StringRef Key)
static unsigned getSpecialRegForName(StringRef RegName)
static InstrUID decode(OpcodeType type, InstructionContext insnContext, uint8_t opcode, uint8_t modRM)
A raw_ostream that writes to an SmallVector or SmallString.
constexpr bool isInt< 16 >(int64_t x)
unsigned const TargetRegisterInfo * TRI
bool isInlinableLiteralV216(int32_t Literal, bool HasInv2Pi)
static void addOptionalImmOperand(MCInst &Inst, const OperandVector &Operands, AMDGPUAsmParser::OptionalImmIndexMap &OptionalIdx, AMDGPUOperand::ImmTy ImmT, int64_t Default=0)
bool mayLoad() const
Return true if this instruction could possibly read memory.
static bool ConvertOmodDiv(int64_t &Div)
bool parseAmdKernelCodeField(StringRef ID, MCAsmParser &Parser, amd_kernel_code_t &C, raw_ostream &Err)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
static LLVM_READNONE unsigned encodeBitmaskPerm(const unsigned AndMask, const unsigned OrMask, const unsigned XorMask)
virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, bool PrintSchedInfo=false)
Emit the given Instruction into the current section.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef take_back(size_t N=1) const
Return a StringRef equal to 'this' but with only the last N elements remaining.
bool isInlinableLiteral16(int16_t Literal, bool HasInv2Pi)
amdhsa::kernel_descriptor_t getDefaultAmdhsaKernelDescriptor()
LLVM_READONLY int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIdx)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool endswith(StringRef Suffix) const
Check if this string ends with the given Suffix.
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
static MCOperand createReg(unsigned Reg)
bool isRegIntersect(unsigned Reg0, unsigned Reg1, const MCRegisterInfo *TRI)
Is there any intersection between registers.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
AMD Kernel Code Object (amd_kernel_code_t).
unsigned getRegOperandSize(const MCRegisterInfo *MRI, const MCInstrDesc &Desc, unsigned OpNo)
Get size of register operand.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Base class for the full range of assembler expressions which are needed for parsing.
Target independent representation for an assembler token.
static int getRegClass(RegisterKind Is, unsigned RegWidth)
Represent a reference to a symbol from inside an expression.
unsigned encodeLgkmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt, unsigned Lgkmcnt)
uint32_t compute_pgm_rsrc2
unsigned decodeLgkmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE R Default(T Value)
static bool isMem(const MachineInstr &MI, unsigned Op)
unsigned encodeExpcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt, unsigned Expcnt)
MCParsedAsmOperand - This abstract class represents a source-level assembly instruction operand...
This file implements a class to represent arbitrary precision integral constant values and operations...
uint32_t private_segment_fixed_size
unsigned getReg() const
Returns the register number.
bool hasCodeObjectV3(const MCSubtargetInfo *STI)
unsigned getSizeInBits() const
unsigned getWaitcntBitMask(const IsaInfo::IsaVersion &Version)
std::pair< StringRef, StringRef > getToken(StringRef Source, StringRef Delimiters=" \\\)
getToken - This function extracts one token from source, ignoring any leading characters that appear ...
uint8_t OperandType
Information about the type of the operand.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
uint32_t group_segment_fixed_size
static bool encodeCnt(const AMDGPU::IsaInfo::IsaVersion ISA, int64_t &IntVal, int64_t CntVal, bool Saturate, unsigned(*encode)(const IsaInfo::IsaVersion &Version, unsigned, unsigned), unsigned(*decode)(const IsaInfo::IsaVersion &Version, unsigned))
RegisterMCAsmParser - Helper template for registering a target specific assembly parser, for use in the target machine initialization function.
unsigned getRegister(unsigned i) const
getRegister - Return the specified register in the class.
#define PARSE_BITS_ENTRY(FIELD, ENTRY, VALUE, RANGE)
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
static const fltSemantics & IEEEdouble() LLVM_READNONE
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
uint16_t kernel_code_properties
MCRegisterClass - Base class of TargetRegisterClass.
iterator insert(iterator I, const MCOperand &Op)
Instances of this class represent a single low-level machine instruction.
unsigned getNumRegs() const
getNumRegs - Return the number of registers in this class.
unsigned short NumOperands
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
bool isSISrcFPOperand(const MCInstrDesc &Desc, unsigned OpNo)
Is this floating-point operand?
unsigned getNumSGPRBlocks(const FeatureBitset &Features, unsigned NumSGPRs)
A switch()-like statement whose cases are string literals.
bool isInlinableLiteral64(int64_t Literal, bool HasInv2Pi)
Is this literal inlinable.
Streaming machine code generation interface.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
bool isSI(const MCSubtargetInfo &STI)
constexpr bool isUInt< 8 >(uint64_t x)
unsigned const MachineRegisterInfo * MRI
constexpr char AssemblerDirectiveBegin[]
HSA metadata beginning assembler directive.
Container class for subtarget features.
The instances of the Type class are immutable: once they are created, they are never changed...
PowerPC Reduce CR logical Operation
bool hasMIMG_R128(const MCSubtargetInfo &STI)
unsigned getScalarSizeInBits() const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const char *const IdSymbolic[]
MCRegAliasIterator enumerates all registers aliasing Reg.
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
This file declares a class to represent arbitrary precision floating point values and provide a varie...
Instruction set architecture version.
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
unsigned getNumOperands() const
static const OptionalOperand AMDGPUOptionalOperandTable[]
SmallVectorImpl< MCOperand >::iterator iterator
constexpr char AssemblerDirectiveEnd[]
HSA metadata ending assembler directive.
constexpr char AssemblerDirective[]
PAL metadata assembler directive.
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
#define AMDHSA_BITS_SET(DST, MSK, VAL)
void initDefaultAMDKernelCodeT(amd_kernel_code_t &Header, const FeatureBitset &Features)
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::pair< typename base::iterator, bool > insert(StringRef Key)
constexpr char NumSGPRs[]
Key for Kernel::CodeProps::Metadata::mNumSGPRs.
Operands with register or inline constant.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef drop_back(size_t N=1) const
Return a StringRef equal to 'this' but with the last N elements dropped.
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
int getOperandConstraint(unsigned OpNum, MCOI::OperandConstraint Constraint) const
Returns the value of the specific constraint if it is set.
static bool ConvertBoundCtrl(int64_t &BoundCtrl)
AMDHSA kernel descriptor definitions.
unsigned decodeVmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt)
void setOpcode(unsigned Op)
unsigned countPopulation(T Value)
Count the number of set bits in a value.
constexpr std::enable_if<(N< 64), bool >::type isUInt(uint64_t X)
Checks if an unsigned integer fits into the given bit width.
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
LLVM_READONLY int getMUBUFNoLdsInst(uint16_t Opcode)
constexpr bool isInt< 32 >(int64_t x)
testing::Matcher< const detail::ErrorHolder & > Failed()
const MCSymbol & getSymbol() const
const MCOperand & getOperand(unsigned i) const
Promote Memory to Register
static bool ConvertOmodMul(int64_t &Mul)
StringRef str()
Return a StringRef for the vector contents.
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
void setVariableValue(const MCExpr *Value)
unsigned encodeVmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt, unsigned Vmcnt)
double BitsToDouble(uint64_t Bits)
This function takes a 64-bit integer and returns the bit equivalent double.
void LLVMInitializeAMDGPUAsmParser()
Force static initialization.
bool is(TokenKind K) const
unsigned getNumVGPRBlocks(const FeatureBitset &Features, unsigned NumVGPRs)
Target - Wrapper for Target specific information.
Class for arbitrary precision integers.
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
const char *const OpSysSymbolic[]
Base class for user error types.
bool mayStore() const
Return true if this instruction could possibly modify memory.
constexpr char NumVGPRs[]
Key for Kernel::CodeProps::Metadata::mNumVGPRs.
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & Case(StringLiteral S, T Value)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
static std::string AMDGPUMnemonicSpellCheck(StringRef S, uint64_t FBS, unsigned VariantID=0)
bool isCI(const MCSubtargetInfo &STI)
static SMLoc getFromPointer(const char *Ptr)
uint32_t compute_pgm_rsrc1
bool isGFX9(const MCSubtargetInfo &STI)
const char *const OpGsSymbolic[]
Provides AMDGPU specific target descriptions.
Interface definition for SIInstrInfo.
static bool canLosslesslyConvertToFPType(APFloat &FPLiteral, MVT VT)
bool isVI(const MCSubtargetInfo &STI)
int16_t RegClass
This specifies the register class enumeration of the operand if the operand is a register.
unsigned decodeExpcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt)
bool hasXNACK(const MCSubtargetInfo &STI)
unsigned getAddressableNumSGPRs(const FeatureBitset &Features)
constexpr bool isUInt< 16 >(uint64_t x)
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
Operands with register or 32-bit immediate.
void setReg(unsigned Reg)
Set the register number.
StringRef getName() const
getName - Get the symbol name.
bool isSISrcOperand(const MCInstrDesc &Desc, unsigned OpNo)
Can this operand also contain immediate values?
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const MCExpr * getVariableValue(bool SetUsed=true) const
getVariableValue - Get the value for variable symbols.
A raw_ostream that writes to an std::string.
bool isInlinableLiteral32(int32_t Literal, bool HasInv2Pi)
LLVM Value Representation.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
Lightweight error class with error context and mandatory checking.
const FeatureBitset Features
const MCOperandInfo * OpInfo
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
LLVM_READNONE unsigned getOperandSize(const MCOperandInfo &OpInfo)
StringSet - A wrapper for StringMap that provides set-like functionality.
unsigned getMCReg(unsigned Reg, const MCSubtargetInfo &STI)
If Reg is a pseudo reg, return the correct hardware register given STI otherwise return Reg...
This class implements an extremely fast bulk output stream that can only output to a stream...
static const fltSemantics * getFltSemantics(unsigned Size)
void addOperand(const MCOperand &Op)
StringRef - Represent a constant reference to a string, i.e.
APInt bitcastToAPInt() const
bool isSGPR(unsigned Reg, const MCRegisterInfo *TRI)
Is Reg - scalar register.
Represents a location in source code.
unsigned getOpcode() const
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Instances of this class represent operands of the MCInst class.
static MCOperand createImm(int64_t Val)
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
IsaVersion getIsaVersion(const FeatureBitset &Features)
std::vector< uint32_t > Metadata
PAL metadata represented as a vector.
void streamIsaVersion(const MCSubtargetInfo *STI, raw_ostream &Stream)
Streams isa version string for given subtarget STI into Stream.
const MCRegisterClass & getRegClass(unsigned i) const
Returns the register class associated with the enumeration value.
const MCPhysReg * ImplicitUses