59 using namespace llvm::AMDGPU;
63 class AMDGPUAsmParser;
65 enum RegisterKind { IS_UNKNOWN, IS_VGPR, IS_SGPR, IS_TTMP, IS_SPECIAL };
79 SMLoc StartLoc, EndLoc;
80 const AMDGPUAsmParser *AsmParser;
83 AMDGPUOperand(KindTy Kind_,
const AMDGPUAsmParser *AsmParser_)
86 typedef std::unique_ptr<AMDGPUOperand>
Ptr;
93 bool hasFPModifiers()
const {
return Abs || Neg; }
94 bool hasIntModifiers()
const {
return Sext; }
95 bool hasModifiers()
const {
return hasFPModifiers() || hasIntModifiers(); }
97 int64_t getFPModifiersOperand()
const {
104 int64_t getIntModifiersOperand()
const {
110 int64_t getModifiersOperand()
const {
111 assert(!(hasFPModifiers() && hasIntModifiers())
112 &&
"fp and int modifiers should not be used simultaneously");
113 if (hasFPModifiers()) {
114 return getFPModifiersOperand();
115 }
else if (hasIntModifiers()) {
116 return getIntModifiersOperand();
195 bool isToken()
const override {
199 if (
Kind != Expression || !Expr)
206 return isa<MCSymbolRefExpr>(Expr);
209 bool isImm()
const override {
210 return Kind == Immediate;
213 bool isInlinableImm(
MVT type)
const;
214 bool isLiteralImm(
MVT type)
const;
216 bool isRegKind()
const {
220 bool isReg()
const override {
221 return isRegKind() && !hasModifiers();
225 return isRegKind() || isInlinableImm(type);
228 bool isRegOrImmWithInt16InputMods()
const {
232 bool isRegOrImmWithInt32InputMods()
const {
236 bool isRegOrImmWithInt64InputMods()
const {
240 bool isRegOrImmWithFP16InputMods()
const {
244 bool isRegOrImmWithFP32InputMods()
const {
248 bool isRegOrImmWithFP64InputMods()
const {
252 bool isVReg()
const {
253 return isRegClass(AMDGPU::VGPR_32RegClassID) ||
254 isRegClass(AMDGPU::VReg_64RegClassID) ||
255 isRegClass(AMDGPU::VReg_96RegClassID) ||
256 isRegClass(AMDGPU::VReg_128RegClassID) ||
257 isRegClass(AMDGPU::VReg_256RegClassID) ||
258 isRegClass(AMDGPU::VReg_512RegClassID);
261 bool isVReg32OrOff()
const {
262 return isOff() || isRegClass(AMDGPU::VGPR_32RegClassID);
265 bool isSDWARegKind()
const;
267 bool isImmTy(ImmTy ImmT)
const {
268 return isImm() && Imm.Type == ImmT;
271 bool isImmModifier()
const {
272 return isImm() && Imm.Type != ImmTyNone;
275 bool isClampSI()
const {
return isImmTy(ImmTyClampSI); }
276 bool isOModSI()
const {
return isImmTy(ImmTyOModSI); }
277 bool isDMask()
const {
return isImmTy(ImmTyDMask); }
278 bool isUNorm()
const {
return isImmTy(ImmTyUNorm); }
279 bool isDA()
const {
return isImmTy(ImmTyDA); }
280 bool isR128()
const {
return isImmTy(ImmTyUNorm); }
281 bool isLWE()
const {
return isImmTy(ImmTyLWE); }
282 bool isOff()
const {
return isImmTy(ImmTyOff); }
283 bool isExpTgt()
const {
return isImmTy(ImmTyExpTgt); }
284 bool isExpVM()
const {
return isImmTy(ImmTyExpVM); }
285 bool isExpCompr()
const {
return isImmTy(ImmTyExpCompr); }
286 bool isOffen()
const {
return isImmTy(ImmTyOffen); }
287 bool isIdxen()
const {
return isImmTy(ImmTyIdxen); }
288 bool isAddr64()
const {
return isImmTy(ImmTyAddr64); }
289 bool isOffset()
const {
return isImmTy(ImmTyOffset) &&
isUInt<16>(getImm()); }
290 bool isOffset0()
const {
return isImmTy(ImmTyOffset0) &&
isUInt<16>(getImm()); }
291 bool isOffset1()
const {
return isImmTy(ImmTyOffset1) &&
isUInt<8>(getImm()); }
293 bool isOffsetU12()
const {
return isImmTy(ImmTyOffset) && isUInt<12>(getImm()); }
294 bool isOffsetS13()
const {
return isImmTy(ImmTyOffset) && isInt<13>(getImm()); }
295 bool isGDS()
const {
return isImmTy(ImmTyGDS); }
296 bool isGLC()
const {
return isImmTy(ImmTyGLC); }
297 bool isSLC()
const {
return isImmTy(ImmTySLC); }
298 bool isTFE()
const {
return isImmTy(ImmTyTFE); }
299 bool isDFMT()
const {
return isImmTy(ImmTyDFMT) &&
isUInt<8>(getImm()); }
300 bool isNFMT()
const {
return isImmTy(ImmTyNFMT) &&
isUInt<8>(getImm()); }
301 bool isBankMask()
const {
return isImmTy(ImmTyDppBankMask); }
302 bool isRowMask()
const {
return isImmTy(ImmTyDppRowMask); }
303 bool isBoundCtrl()
const {
return isImmTy(ImmTyDppBoundCtrl); }
304 bool isSDWADstSel()
const {
return isImmTy(ImmTySdwaDstSel); }
305 bool isSDWASrc0Sel()
const {
return isImmTy(ImmTySdwaSrc0Sel); }
306 bool isSDWASrc1Sel()
const {
return isImmTy(ImmTySdwaSrc1Sel); }
307 bool isSDWADstUnused()
const {
return isImmTy(ImmTySdwaDstUnused); }
308 bool isInterpSlot()
const {
return isImmTy(ImmTyInterpSlot); }
309 bool isInterpAttr()
const {
return isImmTy(ImmTyInterpAttr); }
310 bool isAttrChan()
const {
return isImmTy(ImmTyAttrChan); }
311 bool isOpSel()
const {
return isImmTy(ImmTyOpSel); }
312 bool isOpSelHi()
const {
return isImmTy(ImmTyOpSelHi); }
313 bool isNegLo()
const {
return isImmTy(ImmTyNegLo); }
314 bool isNegHi()
const {
return isImmTy(ImmTyNegHi); }
317 return isClampSI() || isOModSI();
320 bool isRegOrImm()
const {
321 return isReg() || isImm();
324 bool isRegClass(
unsigned RCID)
const;
326 bool isRegOrInlineNoMods(
unsigned RCID,
MVT type)
const {
327 return (isRegClass(RCID) || isInlinableImm(type)) && !hasModifiers();
330 bool isSCSrcB16()
const {
331 return isRegOrInlineNoMods(AMDGPU::SReg_32RegClassID,
MVT::i16);
334 bool isSCSrcV2B16()
const {
338 bool isSCSrcB32()
const {
339 return isRegOrInlineNoMods(AMDGPU::SReg_32RegClassID,
MVT::i32);
342 bool isSCSrcB64()
const {
343 return isRegOrInlineNoMods(AMDGPU::SReg_64RegClassID,
MVT::i64);
346 bool isSCSrcF16()
const {
347 return isRegOrInlineNoMods(AMDGPU::SReg_32RegClassID,
MVT::f16);
350 bool isSCSrcV2F16()
const {
354 bool isSCSrcF32()
const {
355 return isRegOrInlineNoMods(AMDGPU::SReg_32RegClassID,
MVT::f32);
358 bool isSCSrcF64()
const {
359 return isRegOrInlineNoMods(AMDGPU::SReg_64RegClassID,
MVT::f64);
362 bool isSSrcB32()
const {
363 return isSCSrcB32() || isLiteralImm(
MVT::i32) || isExpr();
366 bool isSSrcB16()
const {
367 return isSCSrcB16() || isLiteralImm(
MVT::i16);
370 bool isSSrcV2B16()
const {
375 bool isSSrcB64()
const {
378 return isSCSrcB64() || isLiteralImm(
MVT::i64);
381 bool isSSrcF32()
const {
382 return isSCSrcB32() || isLiteralImm(
MVT::f32) || isExpr();
385 bool isSSrcF64()
const {
386 return isSCSrcB64() || isLiteralImm(
MVT::f64);
389 bool isSSrcF16()
const {
390 return isSCSrcB16() || isLiteralImm(
MVT::f16);
393 bool isSSrcV2F16()
const {
398 bool isVCSrcB32()
const {
399 return isRegOrInlineNoMods(AMDGPU::VS_32RegClassID,
MVT::i32);
402 bool isVCSrcB64()
const {
403 return isRegOrInlineNoMods(AMDGPU::VS_64RegClassID,
MVT::i64);
406 bool isVCSrcB16()
const {
407 return isRegOrInlineNoMods(AMDGPU::VS_32RegClassID,
MVT::i16);
410 bool isVCSrcV2B16()
const {
414 bool isVCSrcF32()
const {
415 return isRegOrInlineNoMods(AMDGPU::VS_32RegClassID,
MVT::f32);
418 bool isVCSrcF64()
const {
419 return isRegOrInlineNoMods(AMDGPU::VS_64RegClassID,
MVT::f64);
422 bool isVCSrcF16()
const {
423 return isRegOrInlineNoMods(AMDGPU::VS_32RegClassID,
MVT::f16);
426 bool isVCSrcV2F16()
const {
430 bool isVSrcB32()
const {
431 return isVCSrcF32() || isLiteralImm(
MVT::i32);
434 bool isVSrcB64()
const {
435 return isVCSrcF64() || isLiteralImm(
MVT::i64);
438 bool isVSrcB16()
const {
439 return isVCSrcF16() || isLiteralImm(
MVT::i16);
442 bool isVSrcV2B16()
const {
447 bool isVSrcF32()
const {
448 return isVCSrcF32() || isLiteralImm(
MVT::f32);
451 bool isVSrcF64()
const {
452 return isVCSrcF64() || isLiteralImm(
MVT::f64);
455 bool isVSrcF16()
const {
456 return isVCSrcF16() || isLiteralImm(
MVT::f16);
459 bool isVSrcV2F16()
const {
464 bool isKImmFP32()
const {
468 bool isKImmFP16()
const {
472 bool isMem()
const override {
476 bool isExpr()
const {
477 return Kind == Expression;
480 bool isSoppBrTarget()
const {
481 return isExpr() || isImm();
484 bool isSWaitCnt()
const;
485 bool isHwreg()
const;
486 bool isSendMsg()
const;
487 bool isSwizzle()
const;
488 bool isSMRDOffset8()
const;
489 bool isSMRDOffset20()
const;
490 bool isSMRDLiteralOffset()
const;
491 bool isDPPCtrl()
const;
492 bool isGPRIdxMode()
const;
493 bool isS16Imm()
const;
494 bool isU16Imm()
const;
505 if (
Kind == Expression)
506 return getExpressionAsToken();
511 int64_t getImm()
const {
516 ImmTy getImmTy()
const {
521 unsigned getReg()
const override {
525 SMLoc getStartLoc()
const override {
529 SMLoc getEndLoc()
const override {
533 Modifiers getModifiers()
const {
534 assert(isRegKind() || isImmTy(ImmTyNone));
535 return isRegKind() ?
Reg.Mods : Imm.Mods;
538 void setModifiers(Modifiers Mods) {
539 assert(isRegKind() || isImmTy(ImmTyNone));
546 bool hasModifiers()
const {
547 return getModifiers().hasModifiers();
550 bool hasFPModifiers()
const {
551 return getModifiers().hasFPModifiers();
554 bool hasIntModifiers()
const {
555 return getModifiers().hasIntModifiers();
558 uint64_t applyInputFPModifiers(uint64_t Val,
unsigned Size)
const;
560 void addImmOperands(
MCInst &Inst,
unsigned N,
bool ApplyModifiers =
true)
const;
562 void addLiteralImmOperand(
MCInst &Inst, int64_t Val,
bool ApplyModifiers)
const;
564 template <
unsigned Bitw
idth>
565 void addKImmFPOperands(
MCInst &Inst,
unsigned N)
const;
567 void addKImmFP16Operands(
MCInst &Inst,
unsigned N)
const {
568 addKImmFPOperands<16>(Inst,
N);
571 void addKImmFP32Operands(
MCInst &Inst,
unsigned N)
const {
572 addKImmFPOperands<32>(Inst,
N);
575 void addRegOperands(
MCInst &Inst,
unsigned N)
const;
577 void addRegOrImmOperands(
MCInst &Inst,
unsigned N)
const {
579 addRegOperands(Inst, N);
583 addImmOperands(Inst, N);
586 void addRegOrImmWithInputModsOperands(
MCInst &Inst,
unsigned N)
const {
587 Modifiers Mods = getModifiers();
590 addRegOperands(Inst, N);
592 addImmOperands(Inst, N,
false);
596 void addRegOrImmWithFPInputModsOperands(
MCInst &Inst,
unsigned N)
const {
597 assert(!hasIntModifiers());
598 addRegOrImmWithInputModsOperands(Inst, N);
601 void addRegOrImmWithIntInputModsOperands(
MCInst &Inst,
unsigned N)
const {
602 assert(!hasFPModifiers());
603 addRegOrImmWithInputModsOperands(Inst, N);
606 void addRegWithInputModsOperands(
MCInst &Inst,
unsigned N)
const {
607 Modifiers Mods = getModifiers();
610 addRegOperands(Inst, N);
613 void addRegWithFPInputModsOperands(
MCInst &Inst,
unsigned N)
const {
614 assert(!hasIntModifiers());
615 addRegWithInputModsOperands(Inst, N);
618 void addRegWithIntInputModsOperands(
MCInst &Inst,
unsigned N)
const {
619 assert(!hasFPModifiers());
620 addRegWithInputModsOperands(Inst, N);
623 void addSoppBrTargetOperands(
MCInst &Inst,
unsigned N)
const {
625 addImmOperands(Inst, N);
634 case ImmTyNone: OS <<
"None";
break;
635 case ImmTyGDS: OS <<
"GDS";
break;
636 case ImmTyOffen: OS <<
"Offen";
break;
637 case ImmTyIdxen: OS <<
"Idxen";
break;
638 case ImmTyAddr64: OS <<
"Addr64";
break;
639 case ImmTyOffset: OS <<
"Offset";
break;
640 case ImmTyOffset0: OS <<
"Offset0";
break;
641 case ImmTyOffset1: OS <<
"Offset1";
break;
642 case ImmTyGLC: OS <<
"GLC";
break;
643 case ImmTySLC: OS <<
"SLC";
break;
644 case ImmTyTFE: OS <<
"TFE";
break;
645 case ImmTyDFMT: OS <<
"DFMT";
break;
646 case ImmTyNFMT: OS <<
"NFMT";
break;
647 case ImmTyClampSI: OS <<
"ClampSI";
break;
648 case ImmTyOModSI: OS <<
"OModSI";
break;
649 case ImmTyDppCtrl: OS <<
"DppCtrl";
break;
650 case ImmTyDppRowMask: OS <<
"DppRowMask";
break;
651 case ImmTyDppBankMask: OS <<
"DppBankMask";
break;
652 case ImmTyDppBoundCtrl: OS <<
"DppBoundCtrl";
break;
653 case ImmTySdwaDstSel: OS <<
"SdwaDstSel";
break;
654 case ImmTySdwaSrc0Sel: OS <<
"SdwaSrc0Sel";
break;
655 case ImmTySdwaSrc1Sel: OS <<
"SdwaSrc1Sel";
break;
656 case ImmTySdwaDstUnused: OS <<
"SdwaDstUnused";
break;
657 case ImmTyDMask: OS <<
"DMask";
break;
658 case ImmTyUNorm: OS <<
"UNorm";
break;
659 case ImmTyDA: OS <<
"DA";
break;
660 case ImmTyR128: OS <<
"R128";
break;
661 case ImmTyLWE: OS <<
"LWE";
break;
662 case ImmTyOff: OS <<
"Off";
break;
663 case ImmTyExpTgt: OS <<
"ExpTgt";
break;
664 case ImmTyExpCompr: OS <<
"ExpCompr";
break;
665 case ImmTyExpVM: OS <<
"ExpVM";
break;
666 case ImmTyHwreg: OS <<
"Hwreg";
break;
667 case ImmTySendMsg: OS <<
"SendMsg";
break;
668 case ImmTyInterpSlot: OS <<
"InterpSlot";
break;
669 case ImmTyInterpAttr: OS <<
"InterpAttr";
break;
670 case ImmTyAttrChan: OS <<
"AttrChan";
break;
671 case ImmTyOpSel: OS <<
"OpSel";
break;
672 case ImmTyOpSelHi: OS <<
"OpSelHi";
break;
673 case ImmTyNegLo: OS <<
"NegLo";
break;
674 case ImmTyNegHi: OS <<
"NegHi";
break;
675 case ImmTySwizzle: OS <<
"Swizzle";
break;
682 OS <<
"<register " <<
getReg() <<
" mods: " <<
Reg.Mods <<
'>';
685 OS <<
'<' << getImm();
686 if (getImmTy() != ImmTyNone) {
687 OS <<
" type: "; printImmTy(OS, getImmTy());
689 OS <<
" mods: " << Imm.Mods <<
'>';
695 OS <<
"<expr " << *Expr << '>
';
700 static AMDGPUOperand::Ptr CreateImm(const AMDGPUAsmParser *AsmParser,
701 int64_t Val, SMLoc Loc,
702 ImmTy Type = ImmTyNone,
703 bool IsFPImm = false) {
704 auto Op = llvm::make_unique<AMDGPUOperand>(Immediate, AsmParser);
706 Op->Imm.IsFPImm = IsFPImm;
708 Op->Imm.Mods = Modifiers();
714 static AMDGPUOperand::Ptr CreateToken(const AMDGPUAsmParser *AsmParser,
715 StringRef Str, SMLoc Loc,
716 bool HasExplicitEncodingSize = true) {
717 auto Res = llvm::make_unique<AMDGPUOperand>(Token, AsmParser);
718 Res->Tok.Data = Str.data();
719 Res->Tok.Length = Str.size();
725 static AMDGPUOperand::Ptr CreateReg(const AMDGPUAsmParser *AsmParser,
726 unsigned RegNo, SMLoc S,
729 auto Op = llvm::make_unique<AMDGPUOperand>(Register, AsmParser);
730 Op->Reg.RegNo = RegNo;
731 Op->Reg.Mods = Modifiers();
732 Op->Reg.IsForcedVOP3 = ForceVOP3;
738 static AMDGPUOperand::Ptr CreateExpr(const AMDGPUAsmParser *AsmParser,
739 const class MCExpr *Expr, SMLoc S) {
740 auto Op = llvm::make_unique<AMDGPUOperand>(Expression, AsmParser);
748 raw_ostream &operator <<(raw_ostream &OS, AMDGPUOperand::Modifiers Mods) {
749 OS << "abs:" << Mods.Abs << " neg: " << Mods.Neg << " sext:" << Mods.Sext;
753 //===----------------------------------------------------------------------===//
755 //===----------------------------------------------------------------------===//
757 // Holds info related to the current kernel, e.g. count of SGPRs used.
758 // Kernel scope begins at .amdgpu_hsa_kernel directive, ends at next
759 // .amdgpu_hsa_kernel or at EOF.
760 class KernelScopeInfo {
761 int SgprIndexUnusedMin = -1;
762 int VgprIndexUnusedMin = -1;
763 MCContext *Ctx = nullptr;
765 void usesSgprAt(int i) {
766 if (i >= SgprIndexUnusedMin) {
767 SgprIndexUnusedMin = ++i;
769 MCSymbol * const Sym = Ctx->getOrCreateSymbol(Twine(".kernel.sgpr_count"));
770 Sym->setVariableValue(MCConstantExpr::create(SgprIndexUnusedMin, *Ctx));
775 void usesVgprAt(int i) {
776 if (i >= VgprIndexUnusedMin) {
777 VgprIndexUnusedMin = ++i;
779 MCSymbol * const Sym = Ctx->getOrCreateSymbol(Twine(".kernel.vgpr_count"));
780 Sym->setVariableValue(MCConstantExpr::create(VgprIndexUnusedMin, *Ctx));
786 KernelScopeInfo() = default;
788 void initialize(MCContext &Context) {
790 usesSgprAt(SgprIndexUnusedMin = -1);
791 usesVgprAt(VgprIndexUnusedMin = -1);
794 void usesRegister(RegisterKind RegKind, unsigned DwordRegIndex, unsigned RegWidth) {
796 case IS_SGPR: usesSgprAt(DwordRegIndex + RegWidth - 1); break;
797 case IS_VGPR: usesVgprAt(DwordRegIndex + RegWidth - 1); break;
803 class AMDGPUAsmParser : public MCTargetAsmParser {
804 const MCInstrInfo &MII;
807 unsigned ForcedEncodingSize = 0;
808 bool ForcedDPP = false;
809 bool ForcedSDWA = false;
810 KernelScopeInfo KernelScope;
815 #define GET_ASSEMBLER_HEADER
816 #include "AMDGPUGenAsmMatcher.inc"
821 bool ParseAsAbsoluteExpression(uint32_t &Ret);
822 bool ParseDirectiveMajorMinor(uint32_t &Major, uint32_t &Minor);
823 bool ParseDirectiveHSACodeObjectVersion();
824 bool ParseDirectiveHSACodeObjectISA();
825 bool ParseDirectiveCodeObjectMetadata();
826 bool ParseAMDKernelCodeTValue(StringRef ID, amd_kernel_code_t &Header);
827 bool ParseDirectiveAMDKernelCodeT();
828 bool subtargetHasRegister(const MCRegisterInfo &MRI, unsigned RegNo) const;
829 bool ParseDirectiveAMDGPUHsaKernel();
830 bool AddNextRegisterToList(unsigned& Reg, unsigned& RegWidth,
831 RegisterKind RegKind, unsigned Reg1,
833 bool ParseAMDGPURegister(RegisterKind& RegKind, unsigned& Reg,
834 unsigned& RegNum, unsigned& RegWidth,
835 unsigned *DwordRegIndex);
836 void cvtMubufImpl(MCInst &Inst, const OperandVector &Operands,
837 bool IsAtomic, bool IsAtomicReturn);
838 void cvtDSImpl(MCInst &Inst, const OperandVector &Operands,
839 bool IsGdsHardcoded);
842 enum AMDGPUMatchResultTy {
843 Match_PreferE32 = FIRST_TARGET_MATCH_RESULT_TY
846 typedef std::map<AMDGPUOperand::ImmTy, unsigned> OptionalImmIndexMap;
848 AMDGPUAsmParser(const MCSubtargetInfo &STI, MCAsmParser &_Parser,
849 const MCInstrInfo &MII,
850 const MCTargetOptions &Options)
851 : MCTargetAsmParser(Options, STI), MII(MII), Parser(_Parser) {
852 MCAsmParserExtension::Initialize(Parser);
854 if (getFeatureBits().none()) {
855 // Set default features.
856 copySTI().ToggleFeature("SOUTHERN_ISLANDS");
859 setAvailableFeatures(ComputeAvailableFeatures(getFeatureBits()));
862 // TODO: make those pre-defined variables read-only.
863 // Currently there is none suitable machinery in the core llvm-mc for this.
864 // MCSymbol::isRedefinable is intended for another purpose, and
865 // AsmParser::parseDirectiveSet() cannot be specialized for specific target.
866 AMDGPU::IsaInfo::IsaVersion ISA =
867 AMDGPU::IsaInfo::getIsaVersion(getFeatureBits());
868 MCContext &Ctx = getContext();
870 Ctx.getOrCreateSymbol(Twine(".option.machine_version_major"));
871 Sym->setVariableValue(MCConstantExpr::create(ISA.Major, Ctx));
872 Sym = Ctx.getOrCreateSymbol(Twine(".option.machine_version_minor"));
873 Sym->setVariableValue(MCConstantExpr::create(ISA.Minor, Ctx));
874 Sym = Ctx.getOrCreateSymbol(Twine(".option.machine_version_stepping"));
875 Sym->setVariableValue(MCConstantExpr::create(ISA.Stepping, Ctx));
877 KernelScope.initialize(getContext());
881 return AMDGPU::isSI(getSTI());
885 return AMDGPU::isCI(getSTI());
889 return AMDGPU::isVI(getSTI());
892 bool isGFX9() const {
893 return AMDGPU::isGFX9(getSTI());
896 bool hasInv2PiInlineImm() const {
897 return getFeatureBits()[AMDGPU::FeatureInv2PiInlineImm];
900 bool hasFlatOffsets() const {
901 return getFeatureBits()[AMDGPU::FeatureFlatInstOffsets];
904 bool hasSGPR102_SGPR103() const {
908 AMDGPUTargetStreamer &getTargetStreamer() {
909 MCTargetStreamer &TS = *getParser().getStreamer().getTargetStreamer();
910 return static_cast<AMDGPUTargetStreamer &>(TS);
913 const MCRegisterInfo *getMRI() const {
914 // We need this const_cast because for some reason getContext() is not const
916 return const_cast<AMDGPUAsmParser*>(this)->getContext().getRegisterInfo();
919 const MCInstrInfo *getMII() const {
923 const FeatureBitset &getFeatureBits() const {
924 return getSTI().getFeatureBits();
927 void setForcedEncodingSize(unsigned Size) { ForcedEncodingSize = Size; }
928 void setForcedDPP(bool ForceDPP_) { ForcedDPP = ForceDPP_; }
929 void setForcedSDWA(bool ForceSDWA_) { ForcedSDWA = ForceSDWA_; }
931 unsigned getForcedEncodingSize() const { return ForcedEncodingSize; }
932 bool isForcedVOP3() const { return ForcedEncodingSize == 64; }
933 bool isForcedDPP() const { return ForcedDPP; }
934 bool isForcedSDWA() const { return ForcedSDWA; }
935 ArrayRef<unsigned> getMatchedVariants() const;
937 std::unique_ptr<AMDGPUOperand> parseRegister();
938 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) override;
939 unsigned checkTargetMatchPredicate(MCInst &Inst) override;
940 unsigned validateTargetOperandClass(MCParsedAsmOperand &Op,
941 unsigned Kind) override;
942 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
943 OperandVector &Operands, MCStreamer &Out,
945 bool MatchingInlineAsm) override;
946 bool ParseDirective(AsmToken DirectiveID) override;
947 OperandMatchResultTy parseOperand(OperandVector &Operands, StringRef Mnemonic);
948 StringRef parseMnemonicSuffix(StringRef Name);
949 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
950 SMLoc NameLoc, OperandVector &Operands) override;
951 //bool ProcessInstruction(MCInst &Inst);
953 OperandMatchResultTy parseIntWithPrefix(const char *Prefix, int64_t &Int);
956 parseIntWithPrefix(const char *Prefix, OperandVector &Operands,
957 AMDGPUOperand::ImmTy ImmTy = AMDGPUOperand::ImmTyNone,
958 bool (*ConvertResult)(int64_t &) = nullptr);
960 OperandMatchResultTy parseOperandArrayWithPrefix(
962 OperandVector &Operands,
963 AMDGPUOperand::ImmTy ImmTy = AMDGPUOperand::ImmTyNone,
964 bool (*ConvertResult)(int64_t&) = nullptr);
967 parseNamedBit(const char *Name, OperandVector &Operands,
968 AMDGPUOperand::ImmTy ImmTy = AMDGPUOperand::ImmTyNone);
969 OperandMatchResultTy parseStringWithPrefix(StringRef Prefix,
972 bool parseAbsoluteExpr(int64_t &Val, bool AbsMod = false);
973 OperandMatchResultTy parseImm(OperandVector &Operands, bool AbsMod = false);
974 OperandMatchResultTy parseReg(OperandVector &Operands);
975 OperandMatchResultTy parseRegOrImm(OperandVector &Operands, bool AbsMod = false);
976 OperandMatchResultTy parseRegOrImmWithFPInputMods(OperandVector &Operands, bool AllowImm = true);
977 OperandMatchResultTy parseRegOrImmWithIntInputMods(OperandVector &Operands, bool AllowImm = true);
978 OperandMatchResultTy parseRegWithFPInputMods(OperandVector &Operands);
979 OperandMatchResultTy parseRegWithIntInputMods(OperandVector &Operands);
980 OperandMatchResultTy parseVReg32OrOff(OperandVector &Operands);
982 void cvtDSOffset01(MCInst &Inst, const OperandVector &Operands);
983 void cvtDS(MCInst &Inst, const OperandVector &Operands) { cvtDSImpl(Inst, Operands, false); }
984 void cvtDSGds(MCInst &Inst, const OperandVector &Operands) { cvtDSImpl(Inst, Operands, true); }
985 void cvtExp(MCInst &Inst, const OperandVector &Operands);
987 bool parseCnt(int64_t &IntVal);
988 OperandMatchResultTy parseSWaitCntOps(OperandVector &Operands);
989 OperandMatchResultTy parseHwreg(OperandVector &Operands);
992 struct OperandInfoTy {
995 OperandInfoTy(int64_t Id_) : Id(Id_), IsSymbolic(false) { }
998 bool parseSendMsgConstruct(OperandInfoTy &Msg, OperandInfoTy &Operation, int64_t &StreamId);
999 bool parseHwregConstruct(OperandInfoTy &HwReg, int64_t &Offset, int64_t &Width);
1002 OperandMatchResultTy parseExpTgtImpl(StringRef Str, uint8_t &Val);
1004 bool validateInstruction(const MCInst &Inst, const SMLoc &IDLoc);
1005 bool validateConstantBusLimitations(const MCInst &Inst);
1006 bool validateEarlyClobberLimitations(const MCInst &Inst);
1007 bool usesConstantBus(const MCInst &Inst, unsigned OpIdx);
1008 bool isInlineConstant(const MCInst &Inst, unsigned OpIdx) const;
1009 unsigned findImplicitSGPRReadInVOP(const MCInst &Inst) const;
1011 bool trySkipId(const StringRef Id);
1012 bool trySkipToken(const AsmToken::TokenKind Kind);
1013 bool skipToken(const AsmToken::TokenKind Kind, const StringRef ErrMsg);
1014 bool parseString(StringRef &Val, const StringRef ErrMsg = "expected a string");
1015 bool parseExpr(int64_t &Imm);
1018 OperandMatchResultTy parseOptionalOperand(OperandVector &Operands);
1020 OperandMatchResultTy parseExpTgt(OperandVector &Operands);
1021 OperandMatchResultTy parseSendMsgOp(OperandVector &Operands);
1022 OperandMatchResultTy parseInterpSlot(OperandVector &Operands);
1023 OperandMatchResultTy parseInterpAttr(OperandVector &Operands);
1024 OperandMatchResultTy parseSOppBrTarget(OperandVector &Operands);
1026 bool parseSwizzleOperands(const unsigned OpNum, int64_t* Op,
1027 const unsigned MinVal,
1028 const unsigned MaxVal,
1029 const StringRef ErrMsg);
1030 OperandMatchResultTy parseSwizzleOp(OperandVector &Operands);
1031 bool parseSwizzleOffset(int64_t &Imm);
1032 bool parseSwizzleMacro(int64_t &Imm);
1033 bool parseSwizzleQuadPerm(int64_t &Imm);
1034 bool parseSwizzleBitmaskPerm(int64_t &Imm);
1035 bool parseSwizzleBroadcast(int64_t &Imm);
1036 bool parseSwizzleSwap(int64_t &Imm);
1037 bool parseSwizzleReverse(int64_t &Imm);
1039 void cvtMubuf(MCInst &Inst, const OperandVector &Operands) { cvtMubufImpl(Inst, Operands, false, false); }
1040 void cvtMubufAtomic(MCInst &Inst, const OperandVector &Operands) { cvtMubufImpl(Inst, Operands, true, false); }
1041 void cvtMubufAtomicReturn(MCInst &Inst, const OperandVector &Operands) { cvtMubufImpl(Inst, Operands, true, true); }
1042 void cvtMtbuf(MCInst &Inst, const OperandVector &Operands);
1044 AMDGPUOperand::Ptr defaultGLC() const;
1045 AMDGPUOperand::Ptr defaultSLC() const;
1046 AMDGPUOperand::Ptr defaultTFE() const;
1048 AMDGPUOperand::Ptr defaultDMask() const;
1049 AMDGPUOperand::Ptr defaultUNorm() const;
1050 AMDGPUOperand::Ptr defaultDA() const;
1051 AMDGPUOperand::Ptr defaultR128() const;
1052 AMDGPUOperand::Ptr defaultLWE() const;
1053 AMDGPUOperand::Ptr defaultSMRDOffset8() const;
1054 AMDGPUOperand::Ptr defaultSMRDOffset20() const;
1055 AMDGPUOperand::Ptr defaultSMRDLiteralOffset() const;
1056 AMDGPUOperand::Ptr defaultOffsetU12() const;
1057 AMDGPUOperand::Ptr defaultOffsetS13() const;
1059 OperandMatchResultTy parseOModOperand(OperandVector &Operands);
1061 void cvtVOP3(MCInst &Inst, const OperandVector &Operands,
1062 OptionalImmIndexMap &OptionalIdx);
1063 void cvtVOP3(MCInst &Inst, const OperandVector &Operands);
1064 void cvtVOP3P(MCInst &Inst, const OperandVector &Operands);
1066 void cvtMIMG(MCInst &Inst, const OperandVector &Operands,
1067 bool IsAtomic = false);
1068 void cvtMIMGAtomic(MCInst &Inst, const OperandVector &Operands);
1070 OperandMatchResultTy parseDPPCtrl(OperandVector &Operands);
1071 AMDGPUOperand::Ptr defaultRowMask() const;
1072 AMDGPUOperand::Ptr defaultBankMask() const;
1073 AMDGPUOperand::Ptr defaultBoundCtrl() const;
1074 void cvtDPP(MCInst &Inst, const OperandVector &Operands);
1076 OperandMatchResultTy parseSDWASel(OperandVector &Operands, StringRef Prefix,
1077 AMDGPUOperand::ImmTy Type);
1078 OperandMatchResultTy parseSDWADstUnused(OperandVector &Operands);
1079 void cvtSdwaVOP1(MCInst &Inst, const OperandVector &Operands);
1080 void cvtSdwaVOP2(MCInst &Inst, const OperandVector &Operands);
1081 void cvtSdwaVOP2b(MCInst &Inst, const OperandVector &Operands);
1082 void cvtSdwaVOPC(MCInst &Inst, const OperandVector &Operands);
1083 void cvtSDWA(MCInst &Inst, const OperandVector &Operands,
1084 uint64_t BasicInstType, bool skipVcc = false);
1087 struct OptionalOperand {
1089 AMDGPUOperand::ImmTy Type;
1091 bool (*ConvertResult)(int64_t&);
1094 } // end anonymous namespace
1096 // May be called with integer type with equivalent bitwidth.
1097 static const fltSemantics *getFltSemantics(unsigned Size) {
1100 return &APFloat::IEEEsingle();
1102 return &APFloat::IEEEdouble();
1104 return &APFloat::IEEEhalf();
1106 llvm_unreachable("unsupported fp type");
1110 static const fltSemantics *getFltSemantics(MVT VT) {
1111 return getFltSemantics(VT.getSizeInBits() / 8);
1114 static const fltSemantics *getOpFltSemantics(uint8_t OperandType) {
1115 switch (OperandType) {
1116 case AMDGPU::OPERAND_REG_IMM_INT32:
1117 case AMDGPU::OPERAND_REG_IMM_FP32:
1118 case AMDGPU::OPERAND_REG_INLINE_C_INT32:
1119 case AMDGPU::OPERAND_REG_INLINE_C_FP32:
1120 return &APFloat::IEEEsingle();
1121 case AMDGPU::OPERAND_REG_IMM_INT64:
1122 case AMDGPU::OPERAND_REG_IMM_FP64:
1123 case AMDGPU::OPERAND_REG_INLINE_C_INT64:
1124 case AMDGPU::OPERAND_REG_INLINE_C_FP64:
1125 return &APFloat::IEEEdouble();
1126 case AMDGPU::OPERAND_REG_IMM_INT16:
1127 case AMDGPU::OPERAND_REG_IMM_FP16:
1128 case AMDGPU::OPERAND_REG_INLINE_C_INT16:
1129 case AMDGPU::OPERAND_REG_INLINE_C_FP16:
1130 case AMDGPU::OPERAND_REG_INLINE_C_V2INT16:
1131 case AMDGPU::OPERAND_REG_INLINE_C_V2FP16:
1132 return &APFloat::IEEEhalf();
1134 llvm_unreachable("unsupported fp type");
1138 //===----------------------------------------------------------------------===//
1140 //===----------------------------------------------------------------------===//
1142 static bool canLosslesslyConvertToFPType(APFloat &FPLiteral, MVT VT) {
1145 // Convert literal to single precision
1146 APFloat::opStatus Status = FPLiteral.convert(*getFltSemantics(VT),
1147 APFloat::rmNearestTiesToEven,
1149 // We allow precision lost but not overflow or underflow
1150 if (Status != APFloat::opOK &&
1152 ((Status & APFloat::opOverflow) != 0 ||
1153 (Status & APFloat::opUnderflow) != 0)) {
1160 bool AMDGPUOperand::isInlinableImm(MVT type) const {
1161 if (!isImmTy(ImmTyNone)) {
1162 // Only plain immediates are inlinable (e.g. "clamp" attribute is not)
1165 // TODO: We should avoid using host float here. It would be better to
1166 // check the float bit values which is what a few other places do.
1167 // We've had bot failures before due to weird NaN support on mips hosts.
1174 AsmParser->hasInv2PiInlineImm());
1183 static_cast<int16_t>(FPLiteral.bitcastToAPInt().getZExtValue()),
1184 AsmParser->hasInv2PiInlineImm());
1189 static_cast<int32_t>(FPLiteral.bitcastToAPInt().getZExtValue()),
1190 AsmParser->hasInv2PiInlineImm());
1196 AsmParser->hasInv2PiInlineImm());
1201 static_cast<int16_t>(
Literal.getLoBits(16).getSExtValue()),
1202 AsmParser->hasInv2PiInlineImm());
1206 static_cast<int32_t>(
Literal.getLoBits(32).getZExtValue()),
1207 AsmParser->hasInv2PiInlineImm());
1210 bool AMDGPUOperand::isLiteralImm(
MVT type)
const {
1212 if (!isImmTy(ImmTyNone)) {
1219 if (type ==
MVT::f64 && hasFPModifiers()) {
1251 bool AMDGPUOperand::isRegClass(
unsigned RCID)
const {
1252 return isRegKind() && AsmParser->getMRI()->getRegClass(RCID).contains(
getReg());
1255 bool AMDGPUOperand::isSDWARegKind()
const {
1256 if (AsmParser->isVI())
1258 else if (AsmParser->isGFX9())
1264 uint64_t AMDGPUOperand::applyInputFPModifiers(uint64_t Val,
unsigned Size)
const
1266 assert(isImmTy(ImmTyNone) && Imm.Mods.hasFPModifiers());
1267 assert(Size == 2 || Size == 4 || Size == 8);
1269 const uint64_t FpSignMask = (1ULL << (Size * 8 - 1));
1281 void AMDGPUOperand::addImmOperands(
MCInst &Inst,
unsigned N,
bool ApplyModifiers)
const {
1285 addLiteralImmOperand(Inst, Imm.Val,
1287 isImmTy(ImmTyNone) && Imm.Mods.hasFPModifiers());
1289 assert(!isImmTy(ImmTyNone) || !hasModifiers());
1294 void AMDGPUOperand::addLiteralImmOperand(
MCInst &Inst, int64_t Val,
bool ApplyModifiers)
const {
1295 const auto& InstDesc = AsmParser->getMII()->get(Inst.
getOpcode());
1300 if (ApplyModifiers) {
1302 const unsigned Size = Imm.IsFPImm ?
sizeof(double) :
getOperandSize(InstDesc, OpNum);
1303 Val = applyInputFPModifiers(Val, Size);
1307 uint8_t OpTy = InstDesc.OpInfo[OpNum].OperandType;
1316 AsmParser->hasInv2PiInlineImm())) {
1324 if (
Literal.getLoBits(32) != 0) {
1325 const_cast<AMDGPUAsmParser *
>(AsmParser)->Warning(Inst.
getLoc(),
1326 "Can't encode literal as exact 64-bit floating-point operand. "
1327 "Low 32-bits will be set to zero");
1357 uint64_t ImmVal = FPLiteral.bitcastToAPInt().getZExtValue();
1360 ImmVal |= (ImmVal << 16);
1383 AsmParser->hasInv2PiInlineImm())) {
1409 AsmParser->hasInv2PiInlineImm())) {
1419 auto LiteralVal =
static_cast<uint16_t
>(
Literal.getLoBits(16).getZExtValue());
1421 AsmParser->hasInv2PiInlineImm()));
1424 static_cast<uint32_t>(LiteralVal);
1433 template <
unsigned Bitw
idth>
1434 void AMDGPUOperand::addKImmFPOperands(
MCInst &Inst,
unsigned N)
const {
1450 void AMDGPUOperand::addRegOperands(
MCInst &Inst,
unsigned N)
const {
1459 if (Is == IS_VGPR) {
1462 case 1:
return AMDGPU::VGPR_32RegClassID;
1463 case 2:
return AMDGPU::VReg_64RegClassID;
1464 case 3:
return AMDGPU::VReg_96RegClassID;
1465 case 4:
return AMDGPU::VReg_128RegClassID;
1466 case 8:
return AMDGPU::VReg_256RegClassID;
1467 case 16:
return AMDGPU::VReg_512RegClassID;
1469 }
else if (Is == IS_TTMP) {
1472 case 1:
return AMDGPU::TTMP_32RegClassID;
1473 case 2:
return AMDGPU::TTMP_64RegClassID;
1474 case 4:
return AMDGPU::TTMP_128RegClassID;
1476 }
else if (Is == IS_SGPR) {
1479 case 1:
return AMDGPU::SGPR_32RegClassID;
1480 case 2:
return AMDGPU::SGPR_64RegClassID;
1481 case 4:
return AMDGPU::SGPR_128RegClassID;
1482 case 8:
return AMDGPU::SReg_256RegClassID;
1483 case 16:
return AMDGPU::SReg_512RegClassID;
1491 .Case(
"exec", AMDGPU::EXEC)
1492 .
Case(
"vcc", AMDGPU::VCC)
1493 .
Case(
"flat_scratch", AMDGPU::FLAT_SCR)
1494 .
Case(
"m0", AMDGPU::M0)
1495 .
Case(
"scc", AMDGPU::SCC)
1496 .
Case(
"tba", AMDGPU::TBA)
1497 .
Case(
"tma", AMDGPU::TMA)
1498 .
Case(
"flat_scratch_lo", AMDGPU::FLAT_SCR_LO)
1499 .
Case(
"flat_scratch_hi", AMDGPU::FLAT_SCR_HI)
1500 .
Case(
"vcc_lo", AMDGPU::VCC_LO)
1501 .
Case(
"vcc_hi", AMDGPU::VCC_HI)
1502 .
Case(
"exec_lo", AMDGPU::EXEC_LO)
1503 .
Case(
"exec_hi", AMDGPU::EXEC_HI)
1504 .
Case(
"tma_lo", AMDGPU::TMA_LO)
1505 .
Case(
"tma_hi", AMDGPU::TMA_HI)
1506 .
Case(
"tba_lo", AMDGPU::TBA_LO)
1507 .
Case(
"tba_hi", AMDGPU::TBA_HI)
1511 bool AMDGPUAsmParser::ParseRegister(
unsigned &RegNo,
SMLoc &StartLoc,
1513 auto R = parseRegister();
1514 if (!R)
return true;
1516 RegNo = R->getReg();
1517 StartLoc = R->getStartLoc();
1518 EndLoc = R->getEndLoc();
1522 bool AMDGPUAsmParser::AddNextRegisterToList(
unsigned &
Reg,
unsigned &RegWidth,
1527 if (Reg == AMDGPU::EXEC_LO && Reg1 == AMDGPU::EXEC_HI) {
1532 if (Reg == AMDGPU::FLAT_SCR_LO && Reg1 == AMDGPU::FLAT_SCR_HI) {
1533 Reg = AMDGPU::FLAT_SCR;
1537 if (Reg == AMDGPU::VCC_LO && Reg1 == AMDGPU::VCC_HI) {
1542 if (Reg == AMDGPU::TBA_LO && Reg1 == AMDGPU::TBA_HI) {
1547 if (Reg == AMDGPU::TMA_LO && Reg1 == AMDGPU::TMA_HI) {
1556 if (Reg1 != Reg + RegWidth) {
1566 bool AMDGPUAsmParser::ParseAMDGPURegister(
RegisterKind &RegKind,
unsigned &Reg,
1567 unsigned &RegNum,
unsigned &RegWidth,
1568 unsigned *DwordRegIndex) {
1569 if (DwordRegIndex) { *DwordRegIndex = 0; }
1572 StringRef RegName = Parser.getTok().getString();
1575 RegKind = IS_SPECIAL;
1577 unsigned RegNumIndex = 0;
1578 if (RegName[0] ==
'v') {
1581 }
else if (RegName[0] ==
's') {
1585 RegNumIndex = strlen(
"ttmp");
1590 if (RegName.
size() > RegNumIndex) {
1599 int64_t RegLo, RegHi;
1604 if (getParser().parseAbsoluteExpression(RegLo))
1615 if (getParser().parseAbsoluteExpression(RegHi))
1623 RegWidth = (RegHi - RegLo) + 1;
1629 if (!ParseAMDGPURegister(RegKind, Reg, RegNum, RegWidth,
nullptr))
1634 unsigned Reg1, RegNum1, RegWidth1;
1641 }
else if (ParseAMDGPURegister(RegKind1, Reg1, RegNum1, RegWidth1,
nullptr)) {
1642 if (RegWidth1 != 1) {
1645 if (RegKind1 != RegKind) {
1648 if (!AddNextRegisterToList(Reg, RegWidth, RegKind1, Reg1, RegNum1)) {
1668 if (RegKind == IS_SGPR || RegKind == IS_TTMP) {
1672 if (RegNum % Size != 0)
1674 if (DwordRegIndex) { *DwordRegIndex = RegNum; }
1675 RegNum = RegNum /
Size;
1690 if (!subtargetHasRegister(*TRI, Reg))
1695 std::unique_ptr<AMDGPUOperand> AMDGPUAsmParser::parseRegister() {
1696 const auto &Tok = Parser.getTok();
1697 SMLoc StartLoc = Tok.getLoc();
1698 SMLoc EndLoc = Tok.getEndLoc();
1700 unsigned Reg, RegNum, RegWidth, DwordRegIndex;
1702 if (!ParseAMDGPURegister(RegKind, Reg, RegNum, RegWidth, &DwordRegIndex)) {
1705 KernelScope.usesRegister(RegKind, DwordRegIndex, RegWidth);
1706 return AMDGPUOperand::CreateReg(
this, Reg, StartLoc, EndLoc,
false);
1710 AMDGPUAsmParser::parseAbsoluteExpr(int64_t &Val,
bool AbsMod) {
1724 if (getParser().parsePrimaryExpr(Expr, EndLoc)) {
1728 return !Expr->evaluateAsAbsolute(Val);
1731 return getParser().parseAbsoluteExpression(Val);
1735 AMDGPUAsmParser::parseImm(
OperandVector &Operands,
bool AbsMod) {
1744 switch(getLexer().getKind()) {
1747 if (parseAbsoluteExpr(IntVal, AbsMod))
1751 Operands.
push_back(AMDGPUOperand::CreateImm(
this, IntVal, S));
1756 if (parseAbsoluteExpr(IntVal, AbsMod))
1763 AMDGPUOperand::CreateImm(
this,
F.bitcastToAPInt().getZExtValue(), S,
1764 AMDGPUOperand::ImmTyNone,
true));
1774 if (
auto R = parseRegister()) {
1776 R->Reg.IsForcedVOP3 = isForcedVOP3();
1784 AMDGPUAsmParser::parseRegOrImm(
OperandVector &Operands,
bool AbsMod) {
1785 auto res = parseImm(Operands, AbsMod);
1790 return parseReg(Operands);
1794 AMDGPUAsmParser::parseRegOrImmWithFPInputMods(
OperandVector &Operands,
1796 bool Negate =
false, Negate2 =
false, Abs =
false, Abs2 =
false;
1799 const AsmToken NextToken = getLexer().peekTok();
1803 Error(Parser.getTok().getLoc(),
"invalid syntax, expected 'neg' modifier");
1822 Parser.getTok().getString() ==
"neg") {
1824 Error(Parser.getTok().getLoc(),
"expected register or immediate");
1830 Error(Parser.getTok().getLoc(),
"expected left paren after neg");
1837 Parser.getTok().getString() ==
"abs") {
1841 Error(Parser.getTok().getLoc(),
"expected left paren after abs");
1849 Error(Parser.getTok().getLoc(),
"expected register or immediate");
1858 Res = parseRegOrImm(Operands, Abs);
1860 Res = parseReg(Operands);
1866 AMDGPUOperand::Modifiers Mods;
1869 Error(Parser.getTok().getLoc(),
"expected vertical bar");
1877 Error(Parser.getTok().getLoc(),
"expected closing parentheses");
1886 }
else if (Negate2) {
1888 Error(Parser.getTok().getLoc(),
"expected closing parentheses");
1895 if (Mods.hasFPModifiers()) {
1896 AMDGPUOperand &
Op =
static_cast<AMDGPUOperand &
>(*Operands.
back());
1897 Op.setModifiers(Mods);
1903 AMDGPUAsmParser::parseRegOrImmWithIntInputMods(
OperandVector &Operands,
1908 Parser.getTok().getString() ==
"sext") {
1912 Error(Parser.getTok().getLoc(),
"expected left paren after sext");
1920 Res = parseRegOrImm(Operands);
1922 Res = parseReg(Operands);
1928 AMDGPUOperand::Modifiers Mods;
1931 Error(Parser.getTok().getLoc(),
"expected closing parentheses");
1938 if (Mods.hasIntModifiers()) {
1939 AMDGPUOperand &Op =
static_cast<AMDGPUOperand &
>(*Operands.
back());
1940 Op.setModifiers(Mods);
1947 AMDGPUAsmParser::parseRegWithFPInputMods(
OperandVector &Operands) {
1948 return parseRegOrImmWithFPInputMods(Operands,
false);
1952 AMDGPUAsmParser::parseRegWithIntInputMods(
OperandVector &Operands) {
1953 return parseRegOrImmWithIntInputMods(Operands,
false);
1957 std::unique_ptr<AMDGPUOperand> Reg = parseRegister();
1963 const AsmToken &Tok = Parser.getTok();
1966 AMDGPUOperand::ImmTyOff,
false));
1974 unsigned AMDGPUAsmParser::checkTargetMatchPredicate(
MCInst &Inst) {
1975 uint64_t TSFlags = MII.get(Inst.
getOpcode()).TSFlags;
1981 return Match_InvalidOperand;
1983 if ((TSFlags & SIInstrFlags::VOP3) &&
1985 getForcedEncodingSize() != 64)
1986 return Match_PreferE32;
1988 if (Inst.
getOpcode() == AMDGPU::V_MAC_F32_sdwa_vi ||
1989 Inst.
getOpcode() == AMDGPU::V_MAC_F16_sdwa_vi) {
1995 return Match_InvalidOperand;
2004 if (Op.getImm() != 0)
2005 return Match_InvalidOperand;
2008 return Match_Success;
2013 if (getForcedEncodingSize() == 32) {
2018 if (isForcedVOP3()) {
2023 if (isForcedSDWA()) {
2029 if (isForcedDPP()) {
2034 static const unsigned Variants[] = {
2042 unsigned AMDGPUAsmParser::findImplicitSGPRReadInVOP(
const MCInst &Inst)
const {
2045 for (
unsigned i = 0; i < Num; ++i) {
2048 case AMDGPU::FLAT_SCR:
2056 return AMDGPU::NoRegister;
2063 bool AMDGPUAsmParser::isInlineConstant(
const MCInst &Inst,
2064 unsigned OpIdx)
const {
2073 int64_t Val = MO.
getImm();
2095 bool AMDGPUAsmParser::usesConstantBus(
const MCInst &Inst,
unsigned OpIdx) {
2098 return !isInlineConstant(Inst, OpIdx);
2100 return !MO.
isReg() ||
2104 bool AMDGPUAsmParser::validateConstantBusLimitations(
const MCInst &Inst) {
2105 const unsigned Opcode = Inst.
getOpcode();
2107 unsigned ConstantBusUseCount = 0;
2117 ++ConstantBusUseCount;
2120 unsigned SGPRUsed = findImplicitSGPRReadInVOP(Inst);
2121 if (SGPRUsed != AMDGPU::NoRegister) {
2122 ++ConstantBusUseCount;
2129 const int OpIndices[] = { Src0Idx, Src1Idx, Src2Idx };
2131 for (
int OpIdx : OpIndices) {
2132 if (OpIdx == -1)
break;
2135 if (usesConstantBus(Inst, OpIdx)) {
2144 if (Reg != SGPRUsed) {
2145 ++ConstantBusUseCount;
2149 ++ConstantBusUseCount;
2155 return ConstantBusUseCount <= 1;
2158 bool AMDGPUAsmParser::validateEarlyClobberLimitations(
const MCInst &Inst) {
2160 const unsigned Opcode = Inst.
getOpcode();
2180 const int SrcIndices[] = { Src0Idx, Src1Idx, Src2Idx };
2182 for (
int SrcIdx : SrcIndices) {
2183 if (SrcIdx == -1)
break;
2196 bool AMDGPUAsmParser::validateInstruction(
const MCInst &Inst,
2197 const SMLoc &IDLoc) {
2198 if (!validateConstantBusLimitations(Inst)) {
2200 "invalid operand (violates constant bus restrictions)");
2203 if (!validateEarlyClobberLimitations(Inst)) {
2205 "destination must be different than all sources");
2212 bool AMDGPUAsmParser::MatchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
2216 bool MatchingInlineAsm) {
2218 unsigned Result = Match_Success;
2219 for (
auto Variant : getMatchedVariants()) {
2221 auto R = MatchInstructionImpl(Operands, Inst, EI, MatchingInlineAsm,
2226 if ((R == Match_Success) ||
2227 (R == Match_PreferE32) ||
2228 (R == Match_MissingFeature && Result != Match_PreferE32) ||
2229 (R == Match_InvalidOperand && Result != Match_MissingFeature
2230 && Result != Match_PreferE32) ||
2231 (R == Match_MnemonicFail && Result != Match_InvalidOperand
2232 && Result != Match_MissingFeature
2233 && Result != Match_PreferE32)) {
2237 if (R == Match_Success)
2244 if (!validateInstruction(Inst, IDLoc)) {
2251 case Match_MissingFeature:
2252 return Error(IDLoc,
"instruction not supported on this GPU");
2254 case Match_MnemonicFail:
2255 return Error(IDLoc,
"unrecognized instruction mnemonic");
2257 case Match_InvalidOperand: {
2258 SMLoc ErrorLoc = IDLoc;
2259 if (ErrorInfo != ~0ULL) {
2260 if (ErrorInfo >= Operands.
size()) {
2261 return Error(IDLoc,
"too few operands for instruction");
2263 ErrorLoc = ((AMDGPUOperand &)*Operands[ErrorInfo]).getStartLoc();
2264 if (ErrorLoc ==
SMLoc())
2267 return Error(ErrorLoc,
"invalid operand for instruction");
2270 case Match_PreferE32:
2271 return Error(IDLoc,
"internal error: instruction without _e64 suffix "
2272 "should be encoded as e32");
2277 bool AMDGPUAsmParser::ParseAsAbsoluteExpression(
uint32_t &
Ret) {
2282 if (getParser().parseAbsoluteExpression(Tmp)) {
2289 bool AMDGPUAsmParser::ParseDirectiveMajorMinor(
uint32_t &Major,
2291 if (ParseAsAbsoluteExpression(Major))
2292 return TokError(
"invalid major version");
2295 return TokError(
"minor version number required, comma expected");
2298 if (ParseAsAbsoluteExpression(Minor))
2299 return TokError(
"invalid minor version");
2304 bool AMDGPUAsmParser::ParseDirectiveHSACodeObjectVersion() {
2308 if (ParseDirectiveMajorMinor(Major, Minor))
2311 getTargetStreamer().EmitDirectiveHSACodeObjectVersion(Major, Minor);
2315 bool AMDGPUAsmParser::ParseDirectiveHSACodeObjectISA() {
2327 getTargetStreamer().EmitDirectiveHSACodeObjectISA(ISA.
Major, ISA.
Minor,
2333 if (ParseDirectiveMajorMinor(Major, Minor))
2337 return TokError(
"stepping version number required, comma expected");
2340 if (ParseAsAbsoluteExpression(Stepping))
2341 return TokError(
"invalid stepping version");
2344 return TokError(
"vendor name required, comma expected");
2348 return TokError(
"invalid vendor name");
2350 VendorName = getLexer().getTok().getStringContents();
2354 return TokError(
"arch name required, comma expected");
2358 return TokError(
"invalid arch name");
2360 ArchName = getLexer().getTok().getStringContents();
2363 getTargetStreamer().EmitDirectiveHSACodeObjectISA(Major, Minor, Stepping,
2364 VendorName, ArchName);
2368 bool AMDGPUAsmParser::ParseDirectiveCodeObjectMetadata() {
2369 std::string YamlString;
2372 getLexer().setSkipSpace(
false);
2374 bool FoundEnd =
false;
2377 YamlStream << getLexer().getTok().getString();
2382 StringRef ID = getLexer().getTok().getIdentifier();
2390 YamlStream << Parser.parseStringToEndOfStatement()
2391 << getContext().getAsmInfo()->getSeparatorString();
2393 Parser.eatToEndOfStatement();
2396 getLexer().setSkipSpace(
true);
2400 "expected directive .end_amdgpu_code_object_metadata not found");
2405 if (!getTargetStreamer().EmitCodeObjectMetadata(YamlString))
2406 return Error(getParser().getTok().getLoc(),
"invalid code object metadata");
2411 bool AMDGPUAsmParser::ParseAMDKernelCodeTValue(
StringRef ID,
2416 return TokError(Err.str());
2422 bool AMDGPUAsmParser::ParseDirectiveAMDKernelCodeT() {
2433 return TokError(
"expected value identifier or .end_amd_kernel_code_t");
2435 StringRef ID = getLexer().getTok().getIdentifier();
2438 if (ID ==
".end_amd_kernel_code_t")
2441 if (ParseAMDKernelCodeTValue(ID, Header))
2445 getTargetStreamer().EmitAMDKernelCodeT(Header);
2450 bool AMDGPUAsmParser::ParseDirectiveAMDGPUHsaKernel() {
2452 return TokError(
"expected symbol name");
2454 StringRef KernelName = Parser.getTok().getString();
2456 getTargetStreamer().EmitAMDGPUSymbolType(KernelName,
2459 KernelScope.initialize(getContext());
2463 bool AMDGPUAsmParser::ParseDirective(
AsmToken DirectiveID) {
2466 if (IDVal ==
".hsa_code_object_version")
2467 return ParseDirectiveHSACodeObjectVersion();
2469 if (IDVal ==
".hsa_code_object_isa")
2470 return ParseDirectiveHSACodeObjectISA();
2473 return ParseDirectiveCodeObjectMetadata();
2475 if (IDVal ==
".amd_kernel_code_t")
2476 return ParseDirectiveAMDKernelCodeT();
2478 if (IDVal ==
".amdgpu_hsa_kernel")
2479 return ParseDirectiveAMDGPUHsaKernel();
2485 unsigned RegNo)
const {
2492 case AMDGPU::FLAT_SCR:
2493 case AMDGPU::FLAT_SCR_LO:
2494 case AMDGPU::FLAT_SCR_HI:
2527 ResTy = parseRegOrImm(Operands);
2538 const auto &Tok = Parser.getTok();
2540 const MCExpr *Expr =
nullptr;
2541 if (!Parser.parseExpression(Expr)) {
2542 Operands.
push_back(AMDGPUOperand::CreateExpr(
this, Expr, S));
2555 setForcedEncodingSize(0);
2556 setForcedDPP(
false);
2557 setForcedSDWA(
false);
2560 setForcedEncodingSize(64);
2562 }
else if (Name.
endswith(
"_e32")) {
2563 setForcedEncodingSize(32);
2565 }
else if (Name.
endswith(
"_dpp")) {
2568 }
else if (Name.
endswith(
"_sdwa")) {
2569 setForcedSDWA(
true);
2579 Name = parseMnemonicSuffix(Name);
2580 Operands.
push_back(AMDGPUOperand::CreateToken(
this, Name, NameLoc));
2592 Error(getLexer().getLoc(),
"failed parsing operand.");
2598 Error(getLexer().getLoc(),
"not a valid operand.");
2614 AMDGPUAsmParser::parseIntWithPrefix(
const char *
Prefix, int64_t &Int) {
2615 switch(getLexer().getKind()) {
2618 StringRef Name = Parser.getTok().getString();
2619 if (!Name.
equals(Prefix)) {
2629 bool IsMinus =
false;
2638 if (getParser().parseAbsoluteExpression(Int))
2650 AMDGPUAsmParser::parseIntWithPrefix(
const char *Prefix,
OperandVector &Operands,
2651 AMDGPUOperand::ImmTy ImmTy,
2652 bool (*ConvertResult)(int64_t&)) {
2653 SMLoc S = Parser.getTok().getLoc();
2660 if (ConvertResult && !ConvertResult(Value)) {
2664 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Value, S, ImmTy));
2671 AMDGPUOperand::ImmTy ImmTy,
2672 bool (*ConvertResult)(int64_t&)) {
2673 StringRef Name = Parser.getTok().getString();
2674 if (!Name.
equals(Prefix))
2687 SMLoc S = Parser.getTok().getLoc();
2691 for (
int I = 0;
I < 3; ++
I) {
2705 if (getParser().parseAbsoluteExpression(Op))
2708 if (Op != 0 && Op != 1)
2714 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Val, S, ImmTy));
2719 AMDGPUAsmParser::parseNamedBit(
const char *Name,
OperandVector &Operands,
2720 AMDGPUOperand::ImmTy ImmTy) {
2722 SMLoc S = Parser.getTok().getLoc();
2727 switch(getLexer().getKind()) {
2746 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Bit, S, ImmTy));
2752 AMDGPUAsmParser::OptionalImmIndexMap& OptionalIdx,
2753 AMDGPUOperand::ImmTy ImmT,
2754 int64_t Default = 0) {
2755 auto i = OptionalIdx.find(ImmT);
2756 if (i != OptionalIdx.end()) {
2757 unsigned Idx = i->second;
2758 ((AMDGPUOperand &)*Operands[Idx]).addImmOperands(Inst, 1);
2769 StringRef Tok = Parser.getTok().getString();
2770 if (Tok != Prefix) {
2784 Value = Parser.getTok().getString();
2792 void AMDGPUAsmParser::cvtDSOffset01(
MCInst &Inst,
2794 OptionalImmIndexMap OptionalIdx;
2796 for (
unsigned i = 1, e = Operands.
size(); i != e; ++i) {
2797 AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[i]);
2801 Op.addRegOperands(Inst, 1);
2806 OptionalIdx[Op.getImmTy()] = i;
2817 bool IsGdsHardcoded) {
2818 OptionalImmIndexMap OptionalIdx;
2820 for (
unsigned i = 1, e = Operands.
size(); i != e; ++i) {
2821 AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[i]);
2825 Op.addRegOperands(Inst, 1);
2829 if (Op.isToken() && Op.getToken() ==
"gds") {
2830 IsGdsHardcoded =
true;
2835 OptionalIdx[Op.getImmTy()] = i;
2838 AMDGPUOperand::ImmTy OffsetType =
2839 (Inst.
getOpcode() == AMDGPU::DS_SWIZZLE_B32_si ||
2840 Inst.
getOpcode() == AMDGPU::DS_SWIZZLE_B32_vi) ? AMDGPUOperand::ImmTySwizzle :
2841 AMDGPUOperand::ImmTyOffset;
2845 if (!IsGdsHardcoded) {
2852 OptionalImmIndexMap OptionalIdx;
2854 unsigned OperandIdx[4];
2855 unsigned EnMask = 0;
2858 for (
unsigned i = 1, e = Operands.
size(); i != e; ++i) {
2859 AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[i]);
2864 OperandIdx[SrcIdx] = Inst.
size();
2865 Op.addRegOperands(Inst, 1);
2872 OperandIdx[SrcIdx] = Inst.
size();
2878 if (Op.isImm() && Op.getImmTy() == AMDGPUOperand::ImmTyExpTgt) {
2879 Op.addImmOperands(Inst, 1);
2883 if (Op.isToken() && Op.getToken() ==
"done")
2887 OptionalIdx[Op.getImmTy()] = i;
2893 if (OptionalIdx.find(AMDGPUOperand::ImmTyExpCompr) != OptionalIdx.end()) {
2900 for (
auto i = 0; i < SrcIdx; ++i) {
2902 EnMask |= Compr? (0x3 << i * 2) : (0x1 << i);
2925 bool Failed =
false;
2927 IntVal = encode(ISA, IntVal, CntVal);
2928 if (CntVal !=
decode(ISA, IntVal)) {
2930 IntVal = encode(ISA, IntVal, -1);
2938 bool AMDGPUAsmParser::parseCnt(int64_t &IntVal) {
2939 StringRef CntName = Parser.getTok().getString();
2950 SMLoc ValLoc = Parser.getTok().getLoc();
2951 if (getParser().parseAbsoluteExpression(CntVal))
2958 bool Sat = CntName.
endswith(
"_sat");
2960 if (CntName ==
"vmcnt" || CntName ==
"vmcnt_sat") {
2962 }
else if (CntName ==
"expcnt" || CntName ==
"expcnt_sat") {
2964 }
else if (CntName ==
"lgkmcnt" || CntName ==
"lgkmcnt_sat") {
2969 Error(ValLoc,
"too large value for " + CntName);
2979 const AsmToken NextToken = getLexer().peekTok();
2989 AMDGPUAsmParser::parseSWaitCntOps(
OperandVector &Operands) {
2993 SMLoc S = Parser.getTok().getLoc();
2995 switch(getLexer().getKind()) {
2999 if (getParser().parseAbsoluteExpression(Waitcnt))
3005 if (parseCnt(Waitcnt))
3010 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Waitcnt, S));
3014 bool AMDGPUAsmParser::parseHwregConstruct(OperandInfoTy &HwReg, int64_t &
Offset,
3016 using namespace llvm::AMDGPU::Hwreg;
3018 if (Parser.getTok().getString() !=
"hwreg")
3027 HwReg.IsSymbolic =
true;
3029 const StringRef tok = Parser.getTok().getString();
3038 HwReg.IsSymbolic =
false;
3041 if (getParser().parseAbsoluteExpression(HwReg.Id))
3057 if (getParser().parseAbsoluteExpression(Offset))
3066 if (getParser().parseAbsoluteExpression(Width))
3077 using namespace llvm::AMDGPU::Hwreg;
3079 int64_t Imm16Val = 0;
3080 SMLoc S = Parser.getTok().getLoc();
3082 switch(getLexer().getKind()) {
3086 if (getParser().parseAbsoluteExpression(Imm16Val))
3089 Error(S,
"invalid immediate: only 16-bit values are legal");
3099 if (parseHwregConstruct(HwReg, Offset, Width))
3101 if (HwReg.Id < 0 || !isUInt<ID_WIDTH_>(HwReg.Id)) {
3102 if (HwReg.IsSymbolic)
3103 Error(S,
"invalid symbolic name of hardware register");
3105 Error(S,
"invalid code of hardware register: only 6-bit values are legal");
3107 if (Offset < 0 || !isUInt<OFFSET_WIDTH_>(Offset))
3108 Error(S,
"invalid bit offset: only 5-bit values are legal");
3109 if ((Width-1) < 0 || !isUInt<WIDTH_M1_WIDTH_>(Width-1))
3110 Error(S,
"invalid bitfield width: only values from 1 to 32 are legal");
3115 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Imm16Val, S, AMDGPUOperand::ImmTyHwreg));
3119 bool AMDGPUOperand::isSWaitCnt()
const {
3123 bool AMDGPUOperand::isHwreg()
const {
3124 return isImmTy(ImmTyHwreg);
3127 bool AMDGPUAsmParser::parseSendMsgConstruct(OperandInfoTy &Msg, OperandInfoTy &Operation, int64_t &
StreamId) {
3128 using namespace llvm::AMDGPU::SendMsg;
3130 if (Parser.getTok().getString() !=
"sendmsg")
3139 Msg.IsSymbolic =
true;
3141 const std::string tok = Parser.getTok().getString();
3154 Msg.IsSymbolic =
false;
3157 if (getParser().parseAbsoluteExpression(Msg.Id))
3160 if (getParser().parseAbsoluteExpression(Msg.Id))
3180 Operation.IsSymbolic =
true;
3184 const StringRef Tok = Parser.getTok().getString();
3185 for (
int i = F; i <
L; ++i) {
3193 Operation.IsSymbolic =
false;
3196 if (getParser().parseAbsoluteExpression(Operation.Id))
3213 if (getParser().parseAbsoluteExpression(StreamId))
3227 StringRef Str = Parser.getTok().getString();
3234 SMLoc S = Parser.getTok().getLoc();
3239 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Slot, S,
3240 AMDGPUOperand::ImmTyInterpSlot));
3248 StringRef Str = Parser.getTok().getString();
3268 SMLoc S = Parser.getTok().getLoc();
3271 Error(S,
"out of bounds attr");
3277 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Attr, S,
3278 AMDGPUOperand::ImmTyInterpAttr));
3279 Operands.
push_back(AMDGPUOperand::CreateImm(
this, AttrChan, SChan,
3280 AMDGPUOperand::ImmTyAttrChan));
3284 void AMDGPUAsmParser::errorExpTgt() {
3285 Error(Parser.getTok().getLoc(),
"invalid exp target");
3290 if (Str ==
"null") {
3349 StringRef Str = Parser.getTok().getString();
3351 auto Res = parseExpTgtImpl(Str, Val);
3355 SMLoc S = Parser.getTok().getLoc();
3358 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Val, S,
3359 AMDGPUOperand::ImmTyExpTgt));
3365 using namespace llvm::AMDGPU::SendMsg;
3367 int64_t Imm16Val = 0;
3368 SMLoc S = Parser.getTok().getLoc();
3370 switch(getLexer().getKind()) {
3375 if (getParser().parseAbsoluteExpression(Imm16Val))
3378 Error(S,
"invalid immediate: only 16-bit values are legal");
3387 if (parseSendMsgConstruct(Msg, Operation, StreamId))
3394 Error(S,
"invalid/unsupported symbolic name of message");
3396 Error(S,
"invalid/unsupported code of message");
3403 if (Operation.IsSymbolic)
3404 Error(S,
"invalid symbolic name of GS_OP");
3406 Error(S,
"invalid code of GS_OP: only 2-bit values are legal");
3411 Error(S,
"invalid GS_OP: NOP is for GS_DONE only");
3414 Imm16Val |= (Operation.Id <<
OP_SHIFT_);
3418 if (Operation.IsSymbolic)
3419 Error(S,
"invalid/unsupported symbolic name of SYSMSG_OP");
3421 Error(S,
"invalid/unsupported code of SYSMSG_OP");
3424 Imm16Val |= (Operation.Id <<
OP_SHIFT_);
3429 Error(S,
"invalid stream id: only 2-bit values are legal");
3438 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Imm16Val, S, AMDGPUOperand::ImmTySendMsg));
3442 bool AMDGPUOperand::isSendMsg()
const {
3443 return isImmTy(ImmTySendMsg);
3453 Parser.getTok().getString() ==
Id) {
3462 if (getLexer().getKind() == Kind) {
3472 if (!trySkipToken(Kind)) {
3480 AMDGPUAsmParser::parseExpr(int64_t &Imm) {
3481 return !getParser().parseAbsoluteExpression(Imm);
3486 SMLoc S = Parser.getTok().getLoc();
3488 Val = Parser.getTok().getStringContents();
3504 const unsigned OrMask,
3505 const unsigned XorMask) {
3515 AMDGPUAsmParser::parseSwizzleOperands(
const unsigned OpNum, int64_t* Op,
3516 const unsigned MinVal,
3517 const unsigned MaxVal,
3519 for (
unsigned i = 0; i < OpNum; ++i) {
3523 SMLoc ExprLoc = Parser.getTok().getLoc();
3524 if (!parseExpr(Op[i])) {
3527 if (Op[i] < MinVal || Op[i] > MaxVal) {
3528 Error(ExprLoc, ErrMsg);
3537 AMDGPUAsmParser::parseSwizzleQuadPerm(int64_t &Imm) {
3542 "expected a 2-bit lane id")) {
3544 for (
auto i = 0; i <
LANE_NUM; ++i) {
3553 AMDGPUAsmParser::parseSwizzleBroadcast(int64_t &Imm) {
3556 SMLoc S = Parser.getTok().getLoc();
3560 if (!parseSwizzleOperands(1, &GroupSize,
3562 "group size must be in the interval [2,32]")) {
3566 Error(S,
"group size must be a power of two");
3569 if (parseSwizzleOperands(1, &LaneIdx,
3571 "lane id must be in the interval [0,group size - 1]")) {
3579 AMDGPUAsmParser::parseSwizzleReverse(int64_t &Imm) {
3582 SMLoc S = Parser.getTok().getLoc();
3585 if (!parseSwizzleOperands(1, &GroupSize,
3586 2, 32,
"group size must be in the interval [2,32]")) {
3590 Error(S,
"group size must be a power of two");
3599 AMDGPUAsmParser::parseSwizzleSwap(int64_t &Imm) {
3602 SMLoc S = Parser.getTok().getLoc();
3605 if (!parseSwizzleOperands(1, &GroupSize,
3606 1, 16,
"group size must be in the interval [1,16]")) {
3610 Error(S,
"group size must be a power of two");
3619 AMDGPUAsmParser::parseSwizzleBitmaskPerm(int64_t &Imm) {
3627 SMLoc StrLoc = Parser.getTok().getLoc();
3628 if (!parseString(Ctl)) {
3632 Error(StrLoc,
"expected a 5-character mask");
3636 unsigned AndMask = 0;
3637 unsigned OrMask = 0;
3638 unsigned XorMask = 0;
3640 for (
size_t i = 0; i < Ctl.size(); ++i) {
3644 Error(StrLoc,
"invalid mask");
3666 AMDGPUAsmParser::parseSwizzleOffset(int64_t &Imm) {
3668 SMLoc OffsetLoc = Parser.getTok().getLoc();
3670 if (!parseExpr(Imm)) {
3674 Error(OffsetLoc,
"expected a 16-bit offset");
3681 AMDGPUAsmParser::parseSwizzleMacro(int64_t &Imm) {
3686 SMLoc ModeLoc = Parser.getTok().getLoc();
3690 Ok = parseSwizzleQuadPerm(Imm);
3692 Ok = parseSwizzleBitmaskPerm(Imm);
3694 Ok = parseSwizzleBroadcast(Imm);
3696 Ok = parseSwizzleSwap(Imm);
3698 Ok = parseSwizzleReverse(Imm);
3700 Error(ModeLoc,
"expected a swizzle mode");
3703 return Ok && skipToken(
AsmToken::RParen,
"expected a closing parentheses");
3711 SMLoc S = Parser.getTok().getLoc();
3714 if (trySkipId(
"offset")) {
3718 if (trySkipId(
"swizzle")) {
3719 Ok = parseSwizzleMacro(Imm);
3721 Ok = parseSwizzleOffset(Imm);
3725 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Imm, S, AMDGPUOperand::ImmTySwizzle));
3734 AMDGPUOperand::isSwizzle()
const {
3735 return isImmTy(ImmTySwizzle);
3743 AMDGPUAsmParser::parseSOppBrTarget(
OperandVector &Operands) {
3744 SMLoc S = Parser.getTok().getLoc();
3746 switch (getLexer().getKind()) {
3750 if (getParser().parseAbsoluteExpression(Imm))
3752 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Imm, S));
3757 Operands.
push_back(AMDGPUOperand::CreateExpr(
this,
3759 Parser.getTok().getString()), getContext()), S));
3769 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultGLC()
const {
3770 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyGLC);
3773 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultSLC()
const {
3774 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTySLC);
3777 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultTFE()
const {
3778 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyTFE);
3781 void AMDGPUAsmParser::cvtMubufImpl(
MCInst &Inst,
3783 bool IsAtomic,
bool IsAtomicReturn) {
3784 OptionalImmIndexMap OptionalIdx;
3785 assert(IsAtomicReturn ? IsAtomic :
true);
3787 for (
unsigned i = 1, e = Operands.
size(); i != e; ++i) {
3788 AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[i]);
3792 Op.addRegOperands(Inst, 1);
3797 if (Op.isImm() && Op.getImmTy() == AMDGPUOperand::ImmTyNone) {
3798 Op.addImmOperands(Inst, 1);
3810 OptionalIdx[Op.getImmTy()] = i;
3814 if (IsAtomicReturn) {
3828 OptionalImmIndexMap OptionalIdx;
3830 for (
unsigned i = 1, e = Operands.
size(); i != e; ++i) {
3831 AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[i]);
3835 Op.addRegOperands(Inst, 1);
3840 if (Op.isImm() && Op.getImmTy() == AMDGPUOperand::ImmTyNone) {
3841 Op.addImmOperands(Inst, 1);
3853 OptionalIdx[Op.getImmTy()] = i;
3857 AMDGPUOperand::ImmTyOffset);
3873 for (
unsigned J = 0; J < Desc.
getNumDefs(); ++J) {
3874 ((AMDGPUOperand &)*Operands[I++]).addRegOperands(Inst, 1);
3879 ((AMDGPUOperand &)*Operands[I]).addRegOperands(Inst, 1);
3882 OptionalImmIndexMap OptionalIdx;
3884 for (
unsigned E = Operands.
size(); I !=
E; ++
I) {
3885 AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[I]);
3888 if (Op.isRegOrImm()) {
3889 Op.addRegOrImmOperands(Inst, 1);
3891 }
else if (Op.isImmModifier()) {
3892 OptionalIdx[Op.getImmTy()] =
I;
3909 cvtMIMG(Inst, Operands,
true);
3912 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultDMask()
const {
3913 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyDMask);
3916 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultUNorm()
const {
3917 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyUNorm);
3920 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultDA()
const {
3921 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyDA);
3924 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultR128()
const {
3925 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyR128);
3928 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultLWE()
const {
3929 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyLWE);
3936 bool AMDGPUOperand::isSMRDOffset8()
const {
3940 bool AMDGPUOperand::isSMRDOffset20()
const {
3941 return isImm() && isUInt<20>(getImm());
3944 bool AMDGPUOperand::isSMRDLiteralOffset()
const {
3950 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultSMRDOffset8()
const {
3951 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyOffset);
3954 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultSMRDOffset20()
const {
3955 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyOffset);
3958 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultSMRDLiteralOffset()
const {
3959 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyOffset);
3962 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultOffsetU12()
const {
3963 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyOffset);
3966 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultOffsetS13()
const {
3967 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyOffset);
3975 if (Mul != 1 && Mul != 2 && Mul != 4)
3997 if (BoundCtrl == 0) {
4002 if (BoundCtrl == -1) {
4012 {
"offen", AMDGPUOperand::ImmTyOffen,
true,
nullptr},
4013 {
"idxen", AMDGPUOperand::ImmTyIdxen,
true,
nullptr},
4014 {
"addr64", AMDGPUOperand::ImmTyAddr64,
true,
nullptr},
4015 {
"offset0", AMDGPUOperand::ImmTyOffset0,
false,
nullptr},
4016 {
"offset1", AMDGPUOperand::ImmTyOffset1,
false,
nullptr},
4017 {
"gds", AMDGPUOperand::ImmTyGDS,
true,
nullptr},
4018 {
"offset", AMDGPUOperand::ImmTyOffset,
false,
nullptr},
4019 {
"dfmt", AMDGPUOperand::ImmTyDFMT,
false,
nullptr},
4020 {
"nfmt", AMDGPUOperand::ImmTyNFMT,
false,
nullptr},
4021 {
"glc", AMDGPUOperand::ImmTyGLC,
true,
nullptr},
4022 {
"slc", AMDGPUOperand::ImmTySLC,
true,
nullptr},
4023 {
"tfe", AMDGPUOperand::ImmTyTFE,
true,
nullptr},
4024 {
"clamp", AMDGPUOperand::ImmTyClampSI,
true,
nullptr},
4026 {
"unorm", AMDGPUOperand::ImmTyUNorm,
true,
nullptr},
4027 {
"da", AMDGPUOperand::ImmTyDA,
true,
nullptr},
4028 {
"r128", AMDGPUOperand::ImmTyR128,
true,
nullptr},
4029 {
"lwe", AMDGPUOperand::ImmTyLWE,
true,
nullptr},
4030 {
"dmask", AMDGPUOperand::ImmTyDMask,
false,
nullptr},
4031 {
"row_mask", AMDGPUOperand::ImmTyDppRowMask,
false,
nullptr},
4032 {
"bank_mask", AMDGPUOperand::ImmTyDppBankMask,
false,
nullptr},
4034 {
"dst_sel", AMDGPUOperand::ImmTySdwaDstSel,
false,
nullptr},
4035 {
"src0_sel", AMDGPUOperand::ImmTySdwaSrc0Sel,
false,
nullptr},
4036 {
"src1_sel", AMDGPUOperand::ImmTySdwaSrc1Sel,
false,
nullptr},
4037 {
"dst_unused", AMDGPUOperand::ImmTySdwaDstUnused,
false,
nullptr},
4038 {
"compr", AMDGPUOperand::ImmTyExpCompr,
true,
nullptr },
4039 {
"vm", AMDGPUOperand::ImmTyExpVM,
true,
nullptr},
4040 {
"op_sel", AMDGPUOperand::ImmTyOpSel,
false,
nullptr},
4041 {
"op_sel_hi", AMDGPUOperand::ImmTyOpSelHi,
false,
nullptr},
4042 {
"neg_lo", AMDGPUOperand::ImmTyNegLo,
false,
nullptr},
4043 {
"neg_hi", AMDGPUOperand::ImmTyNegHi,
false,
nullptr}
4048 for (
const OptionalOperand &Op : AMDGPUOptionalOperandTable) {
4051 res = parseNamedBit(Op.Name, Operands, Op.Type);
4052 }
else if (Op.Type == AMDGPUOperand::ImmTyOModSI) {
4053 res = parseOModOperand(Operands);
4054 }
else if (Op.Type == AMDGPUOperand::ImmTySdwaDstSel ||
4055 Op.Type == AMDGPUOperand::ImmTySdwaSrc0Sel ||
4056 Op.Type == AMDGPUOperand::ImmTySdwaSrc1Sel) {
4057 res = parseSDWASel(Operands, Op.Name, Op.Type);
4058 }
else if (Op.Type == AMDGPUOperand::ImmTySdwaDstUnused) {
4059 res = parseSDWADstUnused(Operands);
4060 }
else if (Op.Type == AMDGPUOperand::ImmTyOpSel ||
4061 Op.Type == AMDGPUOperand::ImmTyOpSelHi ||
4062 Op.Type == AMDGPUOperand::ImmTyNegLo ||
4063 Op.Type == AMDGPUOperand::ImmTyNegHi) {
4064 res = parseOperandArrayWithPrefix(Op.Name, Operands, Op.Type,
4067 res = parseIntWithPrefix(Op.Name, Operands, Op.Type, Op.ConvertResult);
4077 StringRef Name = Parser.getTok().getString();
4078 if (Name ==
"mul") {
4079 return parseIntWithPrefix(
"mul", Operands,
4083 if (Name ==
"div") {
4084 return parseIntWithPrefix(
"div", Operands,
4103 OptionalImmIndexMap &OptionalIdx) {
4108 for (
unsigned J = 0; J < Desc.
getNumDefs(); ++J) {
4109 ((AMDGPUOperand &)*Operands[I++]).addRegOperands(Inst, 1);
4114 for (
unsigned E = Operands.
size(); I !=
E; ++
I) {
4115 AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[I]);
4117 Op.addRegOrImmWithFPInputModsOperands(Inst, 2);
4118 }
else if (Op.isImmModifier()) {
4119 OptionalIdx[Op.getImmTy()] =
I;
4120 }
else if (Op.isRegOrImm()) {
4121 Op.addRegOrImmOperands(Inst, 1);
4128 for (
unsigned E = Operands.
size(); I !=
E; ++
I) {
4129 AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[I]);
4131 OptionalIdx[Op.getImmTy()] =
I;
4133 Op.addRegOrImmOperands(Inst, 1);
4150 if (Opc == AMDGPU::V_MAC_F32_e64_si || Opc == AMDGPU::V_MAC_F32_e64_vi ||
4151 Opc == AMDGPU::V_MAC_F16_e64_vi) {
4152 auto it = Inst.
begin();
4161 OptionalImmIndexMap OptionalIdx;
4162 cvtVOP3(Inst, Operands, OptionalIdx);
4166 OptionalImmIndexMap OptIdx;
4168 cvtVOP3(Inst, Operands, OptIdx);
4178 if (NegLoIdx != -1) {
4183 const int Ops[] = { AMDGPU::OpName::src0,
4184 AMDGPU::OpName::src1,
4185 AMDGPU::OpName::src2 };
4186 const int ModOps[] = { AMDGPU::OpName::src0_modifiers,
4187 AMDGPU::OpName::src1_modifiers,
4188 AMDGPU::OpName::src2_modifiers };
4198 if (NegLoIdx != -1) {
4204 for (
int J = 0; J < 3; ++J) {
4211 if ((OpSel & (1 << J)) != 0)
4214 if ((OpSelHi & (1 << J)) != 0)
4217 if ((NegLo & (1 << J)) != 0)
4220 if ((NegHi & (1 << J)) != 0)
4233 bool AMDGPUOperand::isDPPCtrl()
const {
4234 bool result = isImm() && getImmTy() == ImmTyDppCtrl && isUInt<9>(getImm());
4236 int64_t Imm = getImm();
4237 return ((Imm >= 0x000) && (Imm <= 0x0ff)) ||
4238 ((Imm >= 0x101) && (Imm <= 0x10f)) ||
4239 ((Imm >= 0x111) && (Imm <= 0x11f)) ||
4240 ((Imm >= 0x121) && (Imm <= 0x12f)) ||
4253 bool AMDGPUOperand::isGPRIdxMode()
const {
4254 return isImm() && isUInt<4>(getImm());
4257 bool AMDGPUOperand::isS16Imm()
const {
4261 bool AMDGPUOperand::isU16Imm()
const {
4267 SMLoc S = Parser.getTok().getLoc();
4272 Prefix = Parser.getTok().getString();
4277 if (Prefix ==
"row_mirror") {
4280 }
else if (Prefix ==
"row_half_mirror") {
4285 if (Prefix !=
"quad_perm"
4286 && Prefix !=
"row_shl"
4287 && Prefix !=
"row_shr"
4288 && Prefix !=
"row_ror"
4289 && Prefix !=
"wave_shl"
4290 && Prefix !=
"wave_rol"
4291 && Prefix !=
"wave_shr"
4292 && Prefix !=
"wave_ror"
4293 && Prefix !=
"row_bcast") {
4301 if (Prefix ==
"quad_perm") {
4308 if (getParser().parseAbsoluteExpression(Int) || !(0 <= Int && Int <=3))
4311 for (
int i = 0; i < 3; ++i) {
4317 if (getParser().parseAbsoluteExpression(Temp) || !(0 <= Temp && Temp <=3))
4319 const int shift = i*2 + 2;
4320 Int += (Temp << shift);
4330 if (getParser().parseAbsoluteExpression(Int))
4333 if (Prefix ==
"row_shl" && 1 <= Int && Int <= 15) {
4335 }
else if (Prefix ==
"row_shr" && 1 <= Int && Int <= 15) {
4337 }
else if (Prefix ==
"row_ror" && 1 <= Int && Int <= 15) {
4339 }
else if (Prefix ==
"wave_shl" && 1 == Int) {
4341 }
else if (Prefix ==
"wave_rol" && 1 == Int) {
4343 }
else if (Prefix ==
"wave_shr" && 1 == Int) {
4345 }
else if (Prefix ==
"wave_ror" && 1 == Int) {
4347 }
else if (Prefix ==
"row_bcast") {
4350 }
else if (Int == 31) {
4361 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Int, S, AMDGPUOperand::ImmTyDppCtrl));
4365 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultRowMask()
const {
4366 return AMDGPUOperand::CreateImm(
this, 0xf,
SMLoc(), AMDGPUOperand::ImmTyDppRowMask);
4369 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultBankMask()
const {
4370 return AMDGPUOperand::CreateImm(
this, 0xf,
SMLoc(), AMDGPUOperand::ImmTyDppBankMask);
4373 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultBoundCtrl()
const {
4374 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyDppBoundCtrl);
4378 OptionalImmIndexMap OptionalIdx;
4382 for (
unsigned J = 0; J < Desc.
getNumDefs(); ++J) {
4383 ((AMDGPUOperand &)*Operands[I++]).addRegOperands(Inst, 1);
4386 for (
unsigned E = Operands.
size(); I !=
E; ++
I) {
4387 AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[I]);
4389 if (Op.isReg() && Op.Reg.RegNo == AMDGPU::VCC) {
4394 Op.addRegWithFPInputModsOperands(Inst, 2);
4395 }
else if (Op.isDPPCtrl()) {
4396 Op.addImmOperands(Inst, 1);
4397 }
else if (Op.isImm()) {
4399 OptionalIdx[Op.getImmTy()] =
I;
4411 if (Inst.
getOpcode() == AMDGPU::V_MAC_F32_dpp ||
4412 Inst.
getOpcode() == AMDGPU::V_MAC_F16_dpp) {
4413 auto it = Inst.
begin();
4426 AMDGPUOperand::ImmTy Type) {
4429 SMLoc S = Parser.getTok().getLoc();
4433 res = parseStringWithPrefix(Prefix, Value);
4450 if (Int == 0xffffffff) {
4454 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Int, S, Type));
4459 AMDGPUAsmParser::parseSDWADstUnused(
OperandVector &Operands) {
4462 SMLoc S = Parser.getTok().getLoc();
4466 res = parseStringWithPrefix(
"dst_unused", Value);
4479 if (Int == 0xffffffff) {
4483 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Int, S, AMDGPUOperand::ImmTySdwaDstUnused));
4504 uint64_t BasicInstType,
bool skipVcc) {
4506 OptionalImmIndexMap OptionalIdx;
4507 bool skippedVcc =
false;
4511 for (
unsigned J = 0; J < Desc.
getNumDefs(); ++J) {
4512 ((AMDGPUOperand &)*Operands[I++]).addRegOperands(Inst, 1);
4515 for (
unsigned E = Operands.
size(); I !=
E; ++
I) {
4516 AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[I]);
4517 if (skipVcc && !skippedVcc && Op.isReg() && Op.Reg.RegNo == AMDGPU::VCC) {
4533 Op.addRegWithInputModsOperands(Inst, 2);
4534 }
else if (Op.isImm()) {
4536 OptionalIdx[Op.getImmTy()] =
I;
4543 if (Inst.
getOpcode() != AMDGPU::V_NOP_sdwa_gfx9 &&
4544 Inst.
getOpcode() != AMDGPU::V_NOP_sdwa_vi) {
4546 switch (BasicInstType) {
4575 llvm_unreachable(
"Invalid instruction type. Only VOP1, VOP2 and VOPC allowed");
4581 if (Inst.
getOpcode() == AMDGPU::V_MAC_F32_sdwa_vi ||
4582 Inst.
getOpcode() == AMDGPU::V_MAC_F16_sdwa_vi) {
4583 auto it = Inst.
begin();
4596 #define GET_REGISTER_MATCHER
4597 #define GET_MATCHER_IMPLEMENTATION
4598 #include "AMDGPUGenAsmMatcher.inc"
4608 AMDGPUOperand &Operand = (AMDGPUOperand&)Op;
4611 return Operand.isAddr64() ? Match_Success : Match_InvalidOperand;
4613 return Operand.isGDS() ? Match_Success : Match_InvalidOperand;
4615 return Operand.isGLC() ? Match_Success : Match_InvalidOperand;
4617 return Operand.isIdxen() ? Match_Success : Match_InvalidOperand;
4619 return Operand.isOffen() ? Match_Success : Match_InvalidOperand;
4627 return Operand.isSSrcB32() ? Match_Success : Match_InvalidOperand;
4629 return Operand.isSSrcF32() ? Match_Success : Match_InvalidOperand;
4630 case MCK_SoppBrTarget:
4631 return Operand.isSoppBrTarget() ? Match_Success : Match_InvalidOperand;
4632 case MCK_VReg32OrOff:
4633 return Operand.isVReg32OrOff() ? Match_Success : Match_InvalidOperand;
4634 case MCK_InterpSlot:
4635 return Operand.isInterpSlot() ? Match_Success : Match_InvalidOperand;
4637 return Operand.isInterpAttr() ? Match_Success : Match_InvalidOperand;
4639 return Operand.isAttrChan() ? Match_Success : Match_InvalidOperand;
4641 return Match_InvalidOperand;
static bool isReg(const MCInst &MI, unsigned OpNo)
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.
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.
constexpr bool isUInt< 32 >(uint64_t x)
void push_back(const T &Elt)
unsigned mc2PseudoReg(unsigned Reg)
Convert hardware register Reg to a pseudo register.
unsigned getNumImplicitUses() const
Return the number of implicit uses this instruction has.
Target & getTheGCNTarget()
The target for GCN GPUs.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool endswith(StringRef Suffix) const
Check if this string ends with the given Suffix.
static bool isRegOrImmWithInputMods(const MCInstrDesc &Desc, unsigned OpNum)
static const fltSemantics * getOpFltSemantics(uint8_t OperandType)
const MCSymbol & getSymbol() const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
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.
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
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.
MachineInstrBuilder MachineInstrBuilder &DefMI const MCInstrDesc & Desc
unsigned getScalarSizeInBits() const
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
static unsigned getSpecialRegForName(StringRef RegName)
unsigned getSizeInBits() const
static std::vector< std::pair< int, unsigned > > Swizzle(std::vector< std::pair< int, unsigned >> Src, R600InstrInfo::BankSwizzle Swz)
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)
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)
static bool ConvertOmodDiv(int64_t &Div)
bool parseAmdKernelCodeField(StringRef ID, MCAsmParser &Parser, amd_kernel_code_t &C, raw_ostream &Err)
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.
bool isInlinableLiteral16(int16_t Literal, bool HasInv2Pi)
LLVM_READONLY int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIdx)
static MCOperand createReg(unsigned Reg)
unsigned getNumRegs() const
getNumRegs - Return the number of registers in this class.
bool isRegIntersect(unsigned Reg0, unsigned Reg1, const MCRegisterInfo *TRI)
Is there any intersection between registers.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
std::pair< StringRef, StringRef > getToken(StringRef Source, StringRef Delimiters=" \t\n\v\f\r")
getToken - This function extracts one token from source, ignoring any leading characters that appear ...
AMD Kernel Code Object (amd_kernel_code_t).
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.
LLVM_ATTRIBUTE_ALWAYS_INLINE R Default(const T &Value) const
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 ...
Reg
All possible values of the reg field in the ModR/M byte.
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)
unsigned decodeLgkmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt)
static bool isMem(const MachineInstr &MI, unsigned Op)
unsigned encodeExpcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt, unsigned Expcnt)
constexpr char MetadataAssemblerDirectiveBegin[]
Code object metadata beginning assembler directive.
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...
unsigned getWaitcntBitMask(const IsaInfo::IsaVersion &Version)
uint8_t OperandType
Information about the type of the operand.
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & Case(const char(&S)[N], const T &Value)
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))
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
unsigned getReg() const
Returns the register number.
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 size_t size() const
size - Get the string size.
MCRegisterClass - Base class of TargetRegisterClass.
iterator insert(iterator I, const MCOperand &Op)
Instances of this class represent a single low-level machine instruction.
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?
constexpr char MetadataAssemblerDirectiveEnd[]
Code object metadata ending assembler directive.
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.
bool isSI(const MCSubtargetInfo &STI)
constexpr bool isUInt< 8 >(uint64_t x)
unsigned const MachineRegisterInfo * MRI
The instances of the Type class are immutable: once they are created, they are never changed...
const MCRegisterClass & getRegClass(unsigned i) const
Returns the register class associated with the enumeration value.
const char *const IdSymbolic[]
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).
unsigned getRegister(unsigned i) const
getRegister - Return the specified register in the class.
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 const OptionalOperand AMDGPUOptionalOperandTable[]
SmallVectorImpl< MCOperand >::iterator iterator
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
void initDefaultAMDKernelCodeT(amd_kernel_code_t &Header, const FeatureBitset &Features)
int getOperandConstraint(unsigned OpNum, MCOI::OperandConstraint Constraint) const
Returns the value of the specific constraint if it is set.
Operands with register or inline constant.
static bool ConvertBoundCtrl(int64_t &BoundCtrl)
unsigned decodeVmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt)
constexpr bool isInt< 32 >(int64_t x)
Promote Memory to Register
static bool ConvertOmodMul(int64_t &Mul)
bool is(TokenKind K) const
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.
unsigned getOpcode() const
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 isCI(const MCSubtargetInfo &STI)
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
static SMLoc getFromPointer(const char *Ptr)
llvm_unreachable("Unknown RegBank!")
const char *const OpGsSymbolic[]
Provides AMDGPU specific target descriptions.
RegisterMCAsmParser - Helper template for registering a target specific assembly parser, for use in the target machine initialization function.
StringRef getName() const
getName - Get the symbol name.
OperandType
Types of operands to CF instructions.
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)
unsigned getNumOperands() const
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
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.
bool isSISrcOperand(const MCInstrDesc &Desc, unsigned OpNo)
Can this operand also contain immediate values?
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A raw_ostream that writes to an std::string.
bool isInlinableLiteral32(int32_t Literal, bool HasInv2Pi)
LLVM Value Representation.
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)
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...
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 const fltSemantics * getFltSemantics(unsigned Size)
void addOperand(const MCOperand &Op)
StringRef - Represent a constant reference to a string, i.e.
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.
bool isSGPR(unsigned Reg, const MCRegisterInfo *TRI)
Is Reg - scalar register.
Represents a location in source code.
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)
IsaVersion getIsaVersion(const FeatureBitset &Features)
const MCOperand & getOperand(unsigned i) const
const MCPhysReg * ImplicitUses