70 class AMDGPUAsmParser;
72 enum RegisterKind { IS_UNKNOWN, IS_VGPR, IS_SGPR, IS_AGPR, IS_TTMP, IS_SPECIAL };
86 SMLoc StartLoc, EndLoc;
87 const AMDGPUAsmParser *AsmParser;
90 AMDGPUOperand(KindTy Kind_,
const AMDGPUAsmParser *AsmParser_)
93 using Ptr = std::unique_ptr<AMDGPUOperand>;
100 bool hasFPModifiers()
const {
return Abs || Neg; }
101 bool hasIntModifiers()
const {
return Sext; }
102 bool hasModifiers()
const {
return hasFPModifiers() || hasIntModifiers(); }
104 int64_t getFPModifiersOperand()
const {
111 int64_t getIntModifiersOperand()
const {
117 int64_t getModifiersOperand()
const {
118 assert(!(hasFPModifiers() && hasIntModifiers())
119 &&
"fp and int modifiers should not be used simultaneously");
120 if (hasFPModifiers()) {
121 return getFPModifiersOperand();
122 }
else if (hasIntModifiers()) {
123 return getIntModifiersOperand();
216 bool isToken()
const override {
224 return isSymbolRefExpr();
227 bool isSymbolRefExpr()
const {
228 return isExpr() && Expr && isa<MCSymbolRefExpr>(Expr);
231 bool isImm()
const override {
232 return Kind == Immediate;
235 bool isInlinableImm(
MVT type)
const;
236 bool isLiteralImm(
MVT type)
const;
238 bool isRegKind()
const {
242 bool isReg()
const override {
243 return isRegKind() && !hasModifiers();
247 return isRegClass(RCID) || isInlinableImm(type) || isLiteralImm(type);
250 bool isRegOrImmWithInt16InputMods()
const {
254 bool isRegOrImmWithInt32InputMods()
const {
258 bool isRegOrImmWithInt64InputMods()
const {
262 bool isRegOrImmWithFP16InputMods()
const {
266 bool isRegOrImmWithFP32InputMods()
const {
270 bool isRegOrImmWithFP64InputMods()
const {
274 bool isVReg()
const {
275 return isRegClass(AMDGPU::VGPR_32RegClassID) ||
276 isRegClass(AMDGPU::VReg_64RegClassID) ||
277 isRegClass(AMDGPU::VReg_96RegClassID) ||
278 isRegClass(AMDGPU::VReg_128RegClassID) ||
279 isRegClass(AMDGPU::VReg_160RegClassID) ||
280 isRegClass(AMDGPU::VReg_256RegClassID) ||
281 isRegClass(AMDGPU::VReg_512RegClassID) ||
282 isRegClass(AMDGPU::VReg_1024RegClassID);
285 bool isVReg32()
const {
286 return isRegClass(AMDGPU::VGPR_32RegClassID);
289 bool isVReg32OrOff()
const {
290 return isOff() || isVReg32();
293 bool isNull()
const {
294 return isRegKind() &&
getReg() == AMDGPU::SGPR_NULL;
297 bool isSDWAOperand(
MVT type)
const;
298 bool isSDWAFP16Operand()
const;
299 bool isSDWAFP32Operand()
const;
300 bool isSDWAInt16Operand()
const;
301 bool isSDWAInt32Operand()
const;
303 bool isImmTy(ImmTy ImmT)
const {
304 return isImm() && Imm.Type == ImmT;
307 bool isImmModifier()
const {
308 return isImm() && Imm.Type != ImmTyNone;
311 bool isClampSI()
const {
return isImmTy(ImmTyClampSI); }
312 bool isOModSI()
const {
return isImmTy(ImmTyOModSI); }
313 bool isDMask()
const {
return isImmTy(ImmTyDMask); }
314 bool isDim()
const {
return isImmTy(ImmTyDim); }
315 bool isUNorm()
const {
return isImmTy(ImmTyUNorm); }
316 bool isDA()
const {
return isImmTy(ImmTyDA); }
317 bool isR128A16()
const {
return isImmTy(ImmTyR128A16); }
318 bool isLWE()
const {
return isImmTy(ImmTyLWE); }
319 bool isOff()
const {
return isImmTy(ImmTyOff); }
320 bool isExpTgt()
const {
return isImmTy(ImmTyExpTgt); }
321 bool isExpVM()
const {
return isImmTy(ImmTyExpVM); }
322 bool isExpCompr()
const {
return isImmTy(ImmTyExpCompr); }
323 bool isOffen()
const {
return isImmTy(ImmTyOffen); }
324 bool isIdxen()
const {
return isImmTy(ImmTyIdxen); }
325 bool isAddr64()
const {
return isImmTy(ImmTyAddr64); }
326 bool isOffset()
const {
return isImmTy(ImmTyOffset) &&
isUInt<16>(getImm()); }
327 bool isOffset0()
const {
return isImmTy(ImmTyOffset0) &&
isUInt<8>(getImm()); }
328 bool isOffset1()
const {
return isImmTy(ImmTyOffset1) &&
isUInt<8>(getImm()); }
330 bool isFlatOffset()
const {
return isImmTy(ImmTyOffset) || isImmTy(ImmTyInstOffset); }
331 bool isGDS()
const {
return isImmTy(ImmTyGDS); }
332 bool isLDS()
const {
return isImmTy(ImmTyLDS); }
333 bool isDLC()
const {
return isImmTy(ImmTyDLC); }
334 bool isGLC()
const {
return isImmTy(ImmTyGLC); }
335 bool isSLC()
const {
return isImmTy(ImmTySLC); }
336 bool isSWZ()
const {
return isImmTy(ImmTySWZ); }
337 bool isTFE()
const {
return isImmTy(ImmTyTFE); }
338 bool isD16()
const {
return isImmTy(ImmTyD16); }
339 bool isFORMAT()
const {
return isImmTy(ImmTyFORMAT) &&
isUInt<8>(getImm()); }
340 bool isBankMask()
const {
return isImmTy(ImmTyDppBankMask); }
341 bool isRowMask()
const {
return isImmTy(ImmTyDppRowMask); }
342 bool isBoundCtrl()
const {
return isImmTy(ImmTyDppBoundCtrl); }
343 bool isFI()
const {
return isImmTy(ImmTyDppFi); }
344 bool isSDWADstSel()
const {
return isImmTy(ImmTySdwaDstSel); }
345 bool isSDWASrc0Sel()
const {
return isImmTy(ImmTySdwaSrc0Sel); }
346 bool isSDWASrc1Sel()
const {
return isImmTy(ImmTySdwaSrc1Sel); }
347 bool isSDWADstUnused()
const {
return isImmTy(ImmTySdwaDstUnused); }
348 bool isInterpSlot()
const {
return isImmTy(ImmTyInterpSlot); }
349 bool isInterpAttr()
const {
return isImmTy(ImmTyInterpAttr); }
350 bool isAttrChan()
const {
return isImmTy(ImmTyAttrChan); }
351 bool isOpSel()
const {
return isImmTy(ImmTyOpSel); }
352 bool isOpSelHi()
const {
return isImmTy(ImmTyOpSelHi); }
353 bool isNegLo()
const {
return isImmTy(ImmTyNegLo); }
354 bool isNegHi()
const {
return isImmTy(ImmTyNegHi); }
355 bool isHigh()
const {
return isImmTy(ImmTyHigh); }
358 return isClampSI() || isOModSI();
361 bool isRegOrImm()
const {
362 return isReg() || isImm();
365 bool isRegClass(
unsigned RCID)
const;
369 bool isRegOrInlineNoMods(
unsigned RCID,
MVT type)
const {
370 return (isRegClass(RCID) || isInlinableImm(type)) && !hasModifiers();
373 bool isSCSrcB16()
const {
374 return isRegOrInlineNoMods(AMDGPU::SReg_32RegClassID,
MVT::i16);
377 bool isSCSrcV2B16()
const {
381 bool isSCSrcB32()
const {
382 return isRegOrInlineNoMods(AMDGPU::SReg_32RegClassID,
MVT::i32);
385 bool isSCSrcB64()
const {
386 return isRegOrInlineNoMods(AMDGPU::SReg_64RegClassID,
MVT::i64);
389 bool isBoolReg()
const;
391 bool isSCSrcF16()
const {
392 return isRegOrInlineNoMods(AMDGPU::SReg_32RegClassID,
MVT::f16);
395 bool isSCSrcV2F16()
const {
399 bool isSCSrcF32()
const {
400 return isRegOrInlineNoMods(AMDGPU::SReg_32RegClassID,
MVT::f32);
403 bool isSCSrcF64()
const {
404 return isRegOrInlineNoMods(AMDGPU::SReg_64RegClassID,
MVT::f64);
407 bool isSSrcB32()
const {
408 return isSCSrcB32() || isLiteralImm(
MVT::i32) || isExpr();
411 bool isSSrcB16()
const {
412 return isSCSrcB16() || isLiteralImm(
MVT::i16);
415 bool isSSrcV2B16()
const {
420 bool isSSrcB64()
const {
423 return isSCSrcB64() || isLiteralImm(
MVT::i64);
426 bool isSSrcF32()
const {
427 return isSCSrcB32() || isLiteralImm(
MVT::f32) || isExpr();
430 bool isSSrcF64()
const {
431 return isSCSrcB64() || isLiteralImm(
MVT::f64);
434 bool isSSrcF16()
const {
435 return isSCSrcB16() || isLiteralImm(
MVT::f16);
438 bool isSSrcV2F16()
const {
443 bool isSSrcOrLdsB32()
const {
444 return isRegOrInlineNoMods(AMDGPU::SRegOrLds_32RegClassID,
MVT::i32) ||
448 bool isVCSrcB32()
const {
449 return isRegOrInlineNoMods(AMDGPU::VS_32RegClassID,
MVT::i32);
452 bool isVCSrcB64()
const {
453 return isRegOrInlineNoMods(AMDGPU::VS_64RegClassID,
MVT::i64);
456 bool isVCSrcB16()
const {
457 return isRegOrInlineNoMods(AMDGPU::VS_32RegClassID,
MVT::i16);
460 bool isVCSrcV2B16()
const {
464 bool isVCSrcF32()
const {
465 return isRegOrInlineNoMods(AMDGPU::VS_32RegClassID,
MVT::f32);
468 bool isVCSrcF64()
const {
469 return isRegOrInlineNoMods(AMDGPU::VS_64RegClassID,
MVT::f64);
472 bool isVCSrcF16()
const {
473 return isRegOrInlineNoMods(AMDGPU::VS_32RegClassID,
MVT::f16);
476 bool isVCSrcV2F16()
const {
480 bool isVSrcB32()
const {
481 return isVCSrcF32() || isLiteralImm(
MVT::i32) || isExpr();
484 bool isVSrcB64()
const {
485 return isVCSrcF64() || isLiteralImm(
MVT::i64);
488 bool isVSrcB16()
const {
489 return isVCSrcF16() || isLiteralImm(
MVT::i16);
492 bool isVSrcV2B16()
const {
493 return isVSrcB16() || isLiteralImm(
MVT::v2i16);
496 bool isVSrcF32()
const {
497 return isVCSrcF32() || isLiteralImm(
MVT::f32) || isExpr();
500 bool isVSrcF64()
const {
501 return isVCSrcF64() || isLiteralImm(
MVT::f64);
504 bool isVSrcF16()
const {
505 return isVCSrcF16() || isLiteralImm(
MVT::f16);
508 bool isVSrcV2F16()
const {
509 return isVSrcF16() || isLiteralImm(
MVT::v2f16);
512 bool isVISrcB32()
const {
513 return isRegOrInlineNoMods(AMDGPU::VGPR_32RegClassID,
MVT::i32);
516 bool isVISrcB16()
const {
517 return isRegOrInlineNoMods(AMDGPU::VGPR_32RegClassID,
MVT::i16);
520 bool isVISrcV2B16()
const {
524 bool isVISrcF32()
const {
525 return isRegOrInlineNoMods(AMDGPU::VGPR_32RegClassID,
MVT::f32);
528 bool isVISrcF16()
const {
529 return isRegOrInlineNoMods(AMDGPU::VGPR_32RegClassID,
MVT::f16);
532 bool isVISrcV2F16()
const {
533 return isVISrcF16() || isVISrcB32();
536 bool isAISrcB32()
const {
537 return isRegOrInlineNoMods(AMDGPU::AGPR_32RegClassID,
MVT::i32);
540 bool isAISrcB16()
const {
541 return isRegOrInlineNoMods(AMDGPU::AGPR_32RegClassID,
MVT::i16);
544 bool isAISrcV2B16()
const {
548 bool isAISrcF32()
const {
549 return isRegOrInlineNoMods(AMDGPU::AGPR_32RegClassID,
MVT::f32);
552 bool isAISrcF16()
const {
553 return isRegOrInlineNoMods(AMDGPU::AGPR_32RegClassID,
MVT::f16);
556 bool isAISrcV2F16()
const {
557 return isAISrcF16() || isAISrcB32();
560 bool isAISrc_128B32()
const {
561 return isRegOrInlineNoMods(AMDGPU::AReg_128RegClassID,
MVT::i32);
564 bool isAISrc_128B16()
const {
565 return isRegOrInlineNoMods(AMDGPU::AReg_128RegClassID,
MVT::i16);
568 bool isAISrc_128V2B16()
const {
569 return isAISrc_128B16();
572 bool isAISrc_128F32()
const {
573 return isRegOrInlineNoMods(AMDGPU::AReg_128RegClassID,
MVT::f32);
576 bool isAISrc_128F16()
const {
577 return isRegOrInlineNoMods(AMDGPU::AReg_128RegClassID,
MVT::f16);
580 bool isAISrc_128V2F16()
const {
581 return isAISrc_128F16() || isAISrc_128B32();
584 bool isAISrc_512B32()
const {
585 return isRegOrInlineNoMods(AMDGPU::AReg_512RegClassID,
MVT::i32);
588 bool isAISrc_512B16()
const {
589 return isRegOrInlineNoMods(AMDGPU::AReg_512RegClassID,
MVT::i16);
592 bool isAISrc_512V2B16()
const {
593 return isAISrc_512B16();
596 bool isAISrc_512F32()
const {
597 return isRegOrInlineNoMods(AMDGPU::AReg_512RegClassID,
MVT::f32);
600 bool isAISrc_512F16()
const {
601 return isRegOrInlineNoMods(AMDGPU::AReg_512RegClassID,
MVT::f16);
604 bool isAISrc_512V2F16()
const {
605 return isAISrc_512F16() || isAISrc_512B32();
608 bool isAISrc_1024B32()
const {
609 return isRegOrInlineNoMods(AMDGPU::AReg_1024RegClassID,
MVT::i32);
612 bool isAISrc_1024B16()
const {
613 return isRegOrInlineNoMods(AMDGPU::AReg_1024RegClassID,
MVT::i16);
616 bool isAISrc_1024V2B16()
const {
617 return isAISrc_1024B16();
620 bool isAISrc_1024F32()
const {
621 return isRegOrInlineNoMods(AMDGPU::AReg_1024RegClassID,
MVT::f32);
624 bool isAISrc_1024F16()
const {
625 return isRegOrInlineNoMods(AMDGPU::AReg_1024RegClassID,
MVT::f16);
628 bool isAISrc_1024V2F16()
const {
629 return isAISrc_1024F16() || isAISrc_1024B32();
632 bool isKImmFP32()
const {
636 bool isKImmFP16()
const {
640 bool isMem()
const override {
644 bool isExpr()
const {
645 return Kind == Expression;
648 bool isSoppBrTarget()
const {
649 return isExpr() || isImm();
652 bool isSWaitCnt()
const;
653 bool isHwreg()
const;
654 bool isSendMsg()
const;
655 bool isSwizzle()
const;
656 bool isSMRDOffset8()
const;
657 bool isSMRDOffset20()
const;
658 bool isSMRDLiteralOffset()
const;
660 bool isDPPCtrl()
const;
664 bool isGPRIdxMode()
const;
665 bool isS16Imm()
const;
666 bool isU16Imm()
const;
667 bool isEndpgm()
const;
678 if (Kind == Expression)
679 return getExpressionAsToken();
684 int64_t getImm()
const {
689 ImmTy getImmTy()
const {
694 unsigned getReg()
const override {
699 SMLoc getStartLoc()
const override {
703 SMLoc getEndLoc()
const override {
708 return SMRange(StartLoc, EndLoc);
711 Modifiers getModifiers()
const {
712 assert(isRegKind() || isImmTy(ImmTyNone));
713 return isRegKind() ?
Reg.Mods : Imm.Mods;
716 void setModifiers(Modifiers Mods) {
717 assert(isRegKind() || isImmTy(ImmTyNone));
724 bool hasModifiers()
const {
725 return getModifiers().hasModifiers();
728 bool hasFPModifiers()
const {
729 return getModifiers().hasFPModifiers();
732 bool hasIntModifiers()
const {
733 return getModifiers().hasIntModifiers();
736 uint64_t applyInputFPModifiers(uint64_t Val,
unsigned Size)
const;
738 void addImmOperands(
MCInst &Inst,
unsigned N,
bool ApplyModifiers =
true)
const;
740 void addLiteralImmOperand(
MCInst &Inst, int64_t Val,
bool ApplyModifiers)
const;
742 template <
unsigned Bitw
idth>
743 void addKImmFPOperands(
MCInst &Inst,
unsigned N)
const;
745 void addKImmFP16Operands(
MCInst &Inst,
unsigned N)
const {
746 addKImmFPOperands<16>(Inst,
N);
749 void addKImmFP32Operands(
MCInst &Inst,
unsigned N)
const {
750 addKImmFPOperands<32>(Inst,
N);
753 void addRegOperands(
MCInst &Inst,
unsigned N)
const;
755 void addBoolRegOperands(
MCInst &Inst,
unsigned N)
const {
756 addRegOperands(Inst, N);
759 void addRegOrImmOperands(
MCInst &Inst,
unsigned N)
const {
761 addRegOperands(Inst, N);
765 addImmOperands(Inst, N);
768 void addRegOrImmWithInputModsOperands(
MCInst &Inst,
unsigned N)
const {
769 Modifiers Mods = getModifiers();
772 addRegOperands(Inst, N);
774 addImmOperands(Inst, N,
false);
778 void addRegOrImmWithFPInputModsOperands(
MCInst &Inst,
unsigned N)
const {
779 assert(!hasIntModifiers());
780 addRegOrImmWithInputModsOperands(Inst, N);
783 void addRegOrImmWithIntInputModsOperands(
MCInst &Inst,
unsigned N)
const {
784 assert(!hasFPModifiers());
785 addRegOrImmWithInputModsOperands(Inst, N);
788 void addRegWithInputModsOperands(
MCInst &Inst,
unsigned N)
const {
789 Modifiers Mods = getModifiers();
792 addRegOperands(Inst, N);
795 void addRegWithFPInputModsOperands(
MCInst &Inst,
unsigned N)
const {
796 assert(!hasIntModifiers());
797 addRegWithInputModsOperands(Inst, N);
800 void addRegWithIntInputModsOperands(
MCInst &Inst,
unsigned N)
const {
801 assert(!hasFPModifiers());
802 addRegWithInputModsOperands(Inst, N);
805 void addSoppBrTargetOperands(
MCInst &Inst,
unsigned N)
const {
807 addImmOperands(Inst, N);
816 case ImmTyNone: OS <<
"None";
break;
817 case ImmTyGDS: OS <<
"GDS";
break;
818 case ImmTyLDS: OS <<
"LDS";
break;
819 case ImmTyOffen: OS <<
"Offen";
break;
820 case ImmTyIdxen: OS <<
"Idxen";
break;
821 case ImmTyAddr64: OS <<
"Addr64";
break;
822 case ImmTyOffset: OS <<
"Offset";
break;
823 case ImmTyInstOffset: OS <<
"InstOffset";
break;
824 case ImmTyOffset0: OS <<
"Offset0";
break;
825 case ImmTyOffset1: OS <<
"Offset1";
break;
826 case ImmTyDLC: OS <<
"DLC";
break;
827 case ImmTyGLC: OS <<
"GLC";
break;
828 case ImmTySLC: OS <<
"SLC";
break;
829 case ImmTySWZ: OS <<
"SWZ";
break;
830 case ImmTyTFE: OS <<
"TFE";
break;
831 case ImmTyD16: OS <<
"D16";
break;
832 case ImmTyFORMAT: OS <<
"FORMAT";
break;
833 case ImmTyClampSI: OS <<
"ClampSI";
break;
834 case ImmTyOModSI: OS <<
"OModSI";
break;
835 case ImmTyDPP8: OS <<
"DPP8";
break;
836 case ImmTyDppCtrl: OS <<
"DppCtrl";
break;
837 case ImmTyDppRowMask: OS <<
"DppRowMask";
break;
838 case ImmTyDppBankMask: OS <<
"DppBankMask";
break;
839 case ImmTyDppBoundCtrl: OS <<
"DppBoundCtrl";
break;
840 case ImmTyDppFi: OS <<
"FI";
break;
841 case ImmTySdwaDstSel: OS <<
"SdwaDstSel";
break;
842 case ImmTySdwaSrc0Sel: OS <<
"SdwaSrc0Sel";
break;
843 case ImmTySdwaSrc1Sel: OS <<
"SdwaSrc1Sel";
break;
844 case ImmTySdwaDstUnused: OS <<
"SdwaDstUnused";
break;
845 case ImmTyDMask: OS <<
"DMask";
break;
846 case ImmTyDim: OS <<
"Dim";
break;
847 case ImmTyUNorm: OS <<
"UNorm";
break;
848 case ImmTyDA: OS <<
"DA";
break;
849 case ImmTyR128A16: OS <<
"R128A16";
break;
850 case ImmTyLWE: OS <<
"LWE";
break;
851 case ImmTyOff: OS <<
"Off";
break;
852 case ImmTyExpTgt: OS <<
"ExpTgt";
break;
853 case ImmTyExpCompr: OS <<
"ExpCompr";
break;
854 case ImmTyExpVM: OS <<
"ExpVM";
break;
855 case ImmTyHwreg: OS <<
"Hwreg";
break;
856 case ImmTySendMsg: OS <<
"SendMsg";
break;
857 case ImmTyInterpSlot: OS <<
"InterpSlot";
break;
858 case ImmTyInterpAttr: OS <<
"InterpAttr";
break;
859 case ImmTyAttrChan: OS <<
"AttrChan";
break;
860 case ImmTyOpSel: OS <<
"OpSel";
break;
861 case ImmTyOpSelHi: OS <<
"OpSelHi";
break;
862 case ImmTyNegLo: OS <<
"NegLo";
break;
863 case ImmTyNegHi: OS <<
"NegHi";
break;
864 case ImmTySwizzle: OS <<
"Swizzle";
break;
865 case ImmTyGprIdxMode: OS <<
"GprIdxMode";
break;
866 case ImmTyHigh: OS <<
"High";
break;
867 case ImmTyBLGP: OS <<
"BLGP";
break;
868 case ImmTyCBSZ: OS <<
"CBSZ";
break;
869 case ImmTyABID: OS <<
"ABID";
break;
870 case ImmTyEndpgm: OS <<
"Endpgm";
break;
877 OS <<
"<register " <<
getReg() <<
" mods: " <<
Reg.Mods <<
'>';
880 OS <<
'<' << getImm();
881 if (getImmTy() != ImmTyNone) {
882 OS <<
" type: "; printImmTy(OS, getImmTy());
884 OS <<
" mods: " << Imm.Mods <<
'>';
890 OS <<
"<expr " << *Expr << '>
'; 895 static AMDGPUOperand::Ptr CreateImm(const AMDGPUAsmParser *AsmParser, 896 int64_t Val, SMLoc Loc, 897 ImmTy Type = ImmTyNone, 898 bool IsFPImm = false) { 899 auto Op = std::make_unique<AMDGPUOperand>(Immediate, AsmParser); 901 Op->Imm.IsFPImm = IsFPImm; 903 Op->Imm.Mods = Modifiers(); 909 static AMDGPUOperand::Ptr CreateToken(const AMDGPUAsmParser *AsmParser, 910 StringRef Str, SMLoc Loc, 911 bool HasExplicitEncodingSize = true) { 912 auto Res = std::make_unique<AMDGPUOperand>(Token, AsmParser); 913 Res->Tok.Data = Str.data(); 914 Res->Tok.Length = Str.size(); 920 static AMDGPUOperand::Ptr CreateReg(const AMDGPUAsmParser *AsmParser, 921 unsigned RegNo, SMLoc S, 923 auto Op = std::make_unique<AMDGPUOperand>(Register, AsmParser); 924 Op->Reg.RegNo = RegNo; 925 Op->Reg.Mods = Modifiers(); 931 static AMDGPUOperand::Ptr CreateExpr(const AMDGPUAsmParser *AsmParser, 932 const class MCExpr *Expr, SMLoc S) { 933 auto Op = std::make_unique<AMDGPUOperand>(Expression, AsmParser); 941 raw_ostream &operator <<(raw_ostream &OS, AMDGPUOperand::Modifiers Mods) { 942 OS << "abs:" << Mods.Abs << " neg: " << Mods.Neg << " sext:" << Mods.Sext; 946 //===----------------------------------------------------------------------===// 948 //===----------------------------------------------------------------------===// 950 // Holds info related to the current kernel, e.g. count of SGPRs used. 951 // Kernel scope begins at .amdgpu_hsa_kernel directive, ends at next 952 // .amdgpu_hsa_kernel or at EOF. 953 class KernelScopeInfo { 954 int SgprIndexUnusedMin = -1; 955 int VgprIndexUnusedMin = -1; 956 MCContext *Ctx = nullptr; 958 void usesSgprAt(int i) { 959 if (i >= SgprIndexUnusedMin) { 960 SgprIndexUnusedMin = ++i; 962 MCSymbol * const Sym = Ctx->getOrCreateSymbol(Twine(".kernel.sgpr_count")); 963 Sym->setVariableValue(MCConstantExpr::create(SgprIndexUnusedMin, *Ctx)); 968 void usesVgprAt(int i) { 969 if (i >= VgprIndexUnusedMin) { 970 VgprIndexUnusedMin = ++i; 972 MCSymbol * const Sym = Ctx->getOrCreateSymbol(Twine(".kernel.vgpr_count")); 973 Sym->setVariableValue(MCConstantExpr::create(VgprIndexUnusedMin, *Ctx)); 979 KernelScopeInfo() = default; 981 void initialize(MCContext &Context) { 983 usesSgprAt(SgprIndexUnusedMin = -1); 984 usesVgprAt(VgprIndexUnusedMin = -1); 987 void usesRegister(RegisterKind RegKind, unsigned DwordRegIndex, unsigned RegWidth) { 989 case IS_SGPR: usesSgprAt(DwordRegIndex + RegWidth - 1); break; 990 case IS_AGPR: // fall through 991 case IS_VGPR: usesVgprAt(DwordRegIndex + RegWidth - 1); break; 997 class AMDGPUAsmParser : public MCTargetAsmParser { 1000 // Number of extra operands parsed after the first optional operand. 1001 // This may be necessary to skip hardcoded mandatory operands. 1002 static const unsigned MAX_OPR_LOOKAHEAD = 8; 1004 unsigned ForcedEncodingSize = 0; 1005 bool ForcedDPP = false; 1006 bool ForcedSDWA = false; 1007 KernelScopeInfo KernelScope; 1012 #define GET_ASSEMBLER_HEADER
1013 #include "AMDGPUGenAsmMatcher.inc"
1018 bool ParseAsAbsoluteExpression(uint32_t &Ret);
1019 bool OutOfRangeError(SMRange Range);
1035 bool calculateGPRBlocks(const FeatureBitset &Features, bool VCCUsed,
1036 bool FlatScrUsed, bool XNACKUsed,
1037 Optional<bool> EnableWavefrontSize32, unsigned NextFreeVGPR,
1038 SMRange VGPRRange, unsigned NextFreeSGPR,
1039 SMRange SGPRRange, unsigned &VGPRBlocks,
1040 unsigned &SGPRBlocks);
1041 bool ParseDirectiveAMDGCNTarget();
1042 bool ParseDirectiveAMDHSAKernel();
1043 bool ParseDirectiveMajorMinor(uint32_t &Major, uint32_t &Minor);
1044 bool ParseDirectiveHSACodeObjectVersion();
1045 bool ParseDirectiveHSACodeObjectISA();
1046 bool ParseAMDKernelCodeTValue(StringRef ID, amd_kernel_code_t &Header);
1047 bool ParseDirectiveAMDKernelCodeT();
1048 bool subtargetHasRegister(const MCRegisterInfo &MRI, unsigned RegNo) const;
1049 bool ParseDirectiveAMDGPUHsaKernel();
1051 bool ParseDirectiveISAVersion();
1052 bool ParseDirectiveHSAMetadata();
1053 bool ParseDirectivePALMetadataBegin();
1054 bool ParseDirectivePALMetadata();
1055 bool ParseDirectiveAMDGPULDS();
1059 bool ParseToEndDirective(const char *AssemblerDirectiveBegin,
1060 const char *AssemblerDirectiveEnd,
1061 std::string &CollectString);
1063 bool AddNextRegisterToList(unsigned& Reg, unsigned& RegWidth,
1064 RegisterKind RegKind, unsigned Reg1);
1065 bool ParseAMDGPURegister(RegisterKind& RegKind, unsigned& Reg,
1066 unsigned& RegNum, unsigned& RegWidth);
1067 unsigned ParseRegularReg(RegisterKind &RegKind,
1069 unsigned &RegWidth);
1070 unsigned ParseSpecialReg(RegisterKind &RegKind,
1072 unsigned &RegWidth);
1073 unsigned ParseRegList(RegisterKind &RegKind,
1075 unsigned &RegWidth);
1076 bool ParseRegRange(unsigned& Num, unsigned& Width);
1077 unsigned getRegularReg(RegisterKind RegKind,
1082 bool isRegister(const AsmToken &Token, const AsmToken &NextToken) const;
1083 Optional<StringRef> getGprCountSymbolName(RegisterKind RegKind);
1084 void initializeGprCountSymbol(RegisterKind RegKind);
1085 bool updateGprCountSymbols(RegisterKind RegKind, unsigned DwordRegIndex,
1087 void cvtMubufImpl(MCInst &Inst, const OperandVector &Operands,
1088 bool IsAtomic, bool IsAtomicReturn, bool IsLds = false);
1089 void cvtDSImpl(MCInst &Inst, const OperandVector &Operands,
1090 bool IsGdsHardcoded);
1093 enum AMDGPUMatchResultTy {
1094 Match_PreferE32 = FIRST_TARGET_MATCH_RESULT_TY
1097 OperandMode_Default,
1101 using OptionalImmIndexMap = std::map<AMDGPUOperand::ImmTy, unsigned>;
1103 AMDGPUAsmParser(const MCSubtargetInfo &STI, MCAsmParser &_Parser,
1104 const MCInstrInfo &MII,
1105 const MCTargetOptions &Options)
1106 : MCTargetAsmParser(Options, STI, MII), Parser(_Parser) {
1107 MCAsmParserExtension::Initialize(Parser);
1109 if (getFeatureBits().none()) {
1110 // Set default features.
1111 copySTI().ToggleFeature("southern-islands");
1114 setAvailableFeatures(ComputeAvailableFeatures(getFeatureBits()));
1117 // TODO: make those pre-defined variables read-only.
1118 // Currently there is none suitable machinery in the core llvm-mc for this.
1119 // MCSymbol::isRedefinable is intended for another purpose, and
1120 // AsmParser::parseDirectiveSet() cannot be specialized for specific target.
1121 AMDGPU::IsaVersion ISA = AMDGPU::getIsaVersion(getSTI().getCPU());
1122 MCContext &Ctx = getContext();
1123 if (ISA.Major >= 6 && AMDGPU::IsaInfo::hasCodeObjectV3(&getSTI())) {
1125 Ctx.getOrCreateSymbol(Twine(".amdgcn.gfx_generation_number"));
1126 Sym->setVariableValue(MCConstantExpr::create(ISA.Major, Ctx));
1127 Sym = Ctx.getOrCreateSymbol(Twine(".amdgcn.gfx_generation_minor"));
1128 Sym->setVariableValue(MCConstantExpr::create(ISA.Minor, Ctx));
1129 Sym = Ctx.getOrCreateSymbol(Twine(".amdgcn.gfx_generation_stepping"));
1130 Sym->setVariableValue(MCConstantExpr::create(ISA.Stepping, Ctx));
1133 Ctx.getOrCreateSymbol(Twine(".option.machine_version_major"));
1134 Sym->setVariableValue(MCConstantExpr::create(ISA.Major, Ctx));
1135 Sym = Ctx.getOrCreateSymbol(Twine(".option.machine_version_minor"));
1136 Sym->setVariableValue(MCConstantExpr::create(ISA.Minor, Ctx));
1137 Sym = Ctx.getOrCreateSymbol(Twine(".option.machine_version_stepping"));
1138 Sym->setVariableValue(MCConstantExpr::create(ISA.Stepping, Ctx));
1140 if (ISA.Major >= 6 && AMDGPU::IsaInfo::hasCodeObjectV3(&getSTI())) {
1141 initializeGprCountSymbol(IS_VGPR);
1142 initializeGprCountSymbol(IS_SGPR);
1144 KernelScope.initialize(getContext());
1148 bool hasXNACK() const {
1149 return AMDGPU::hasXNACK(getSTI());
1152 bool hasMIMG_R128() const {
1153 return AMDGPU::hasMIMG_R128(getSTI());
1156 bool hasPackedD16() const {
1157 return AMDGPU::hasPackedD16(getSTI());
1161 return AMDGPU::isSI(getSTI());
1165 return AMDGPU::isCI(getSTI());
1169 return AMDGPU::isVI(getSTI());
1172 bool isGFX9() const {
1173 return AMDGPU::isGFX9(getSTI());
1176 bool isGFX10() const {
1177 return AMDGPU::isGFX10(getSTI());
1180 bool hasInv2PiInlineImm() const {
1181 return getFeatureBits()[AMDGPU::FeatureInv2PiInlineImm];
1184 bool hasFlatOffsets() const {
1185 return getFeatureBits()[AMDGPU::FeatureFlatInstOffsets];
1188 bool hasSGPR102_SGPR103() const {
1189 return !isVI() && !isGFX9();
1192 bool hasSGPR104_SGPR105() const {
1196 bool hasIntClamp() const {
1197 return getFeatureBits()[AMDGPU::FeatureIntClamp];
1200 AMDGPUTargetStreamer &getTargetStreamer() {
1201 MCTargetStreamer &TS = *getParser().getStreamer().getTargetStreamer();
1202 return static_cast<AMDGPUTargetStreamer &>(TS);
1205 const MCRegisterInfo *getMRI() const {
1206 // We need this const_cast because for some reason getContext() is not const
1208 return const_cast<AMDGPUAsmParser*>(this)->getContext().getRegisterInfo();
1211 const MCInstrInfo *getMII() const {
1215 const FeatureBitset &getFeatureBits() const {
1216 return getSTI().getFeatureBits();
1219 void setForcedEncodingSize(unsigned Size) { ForcedEncodingSize = Size; }
1220 void setForcedDPP(bool ForceDPP_) { ForcedDPP = ForceDPP_; }
1221 void setForcedSDWA(bool ForceSDWA_) { ForcedSDWA = ForceSDWA_; }
1223 unsigned getForcedEncodingSize() const { return ForcedEncodingSize; }
1224 bool isForcedVOP3() const { return ForcedEncodingSize == 64; }
1225 bool isForcedDPP() const { return ForcedDPP; }
1226 bool isForcedSDWA() const { return ForcedSDWA; }
1227 ArrayRef<unsigned> getMatchedVariants() const;
1229 std::unique_ptr<AMDGPUOperand> parseRegister();
1230 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) override;
1231 unsigned checkTargetMatchPredicate(MCInst &Inst) override;
1232 unsigned validateTargetOperandClass(MCParsedAsmOperand &Op,
1233 unsigned Kind) override;
1234 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
1235 OperandVector &Operands, MCStreamer &Out,
1236 uint64_t &ErrorInfo,
1237 bool MatchingInlineAsm) override;
1238 bool ParseDirective(AsmToken DirectiveID) override;
1239 OperandMatchResultTy parseOperand(OperandVector &Operands, StringRef Mnemonic,
1240 OperandMode Mode = OperandMode_Default);
1241 StringRef parseMnemonicSuffix(StringRef Name);
1242 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
1243 SMLoc NameLoc, OperandVector &Operands) override;
1244 //bool ProcessInstruction(MCInst &Inst);
1246 OperandMatchResultTy parseIntWithPrefix(const char *Prefix, int64_t &Int);
1248 OperandMatchResultTy
1249 parseIntWithPrefix(const char *Prefix, OperandVector &Operands,
1250 AMDGPUOperand::ImmTy ImmTy = AMDGPUOperand::ImmTyNone,
1251 bool (*ConvertResult)(int64_t &) = nullptr);
1253 OperandMatchResultTy
1254 parseOperandArrayWithPrefix(const char *Prefix,
1255 OperandVector &Operands,
1256 AMDGPUOperand::ImmTy ImmTy = AMDGPUOperand::ImmTyNone,
1257 bool (*ConvertResult)(int64_t&) = nullptr);
1259 OperandMatchResultTy
1260 parseNamedBit(const char *Name, OperandVector &Operands,
1261 AMDGPUOperand::ImmTy ImmTy = AMDGPUOperand::ImmTyNone);
1262 OperandMatchResultTy parseStringWithPrefix(StringRef Prefix,
1266 bool isOperandModifier(const AsmToken &Token, const AsmToken &NextToken) const;
1267 bool isRegOrOperandModifier(const AsmToken &Token, const AsmToken &NextToken) const;
1268 bool isNamedOperandModifier(const AsmToken &Token, const AsmToken &NextToken) const;
1269 bool isOpcodeModifierWithVal(const AsmToken &Token, const AsmToken &NextToken) const;
1270 bool parseSP3NegModifier();
1271 OperandMatchResultTy parseImm(OperandVector &Operands, bool HasSP3AbsModifier = false);
1272 OperandMatchResultTy parseReg(OperandVector &Operands);
1273 OperandMatchResultTy parseRegOrImm(OperandVector &Operands, bool HasSP3AbsMod = false);
1274 OperandMatchResultTy parseRegOrImmWithFPInputMods(OperandVector &Operands, bool AllowImm = true);
1275 OperandMatchResultTy parseRegOrImmWithIntInputMods(OperandVector &Operands, bool AllowImm = true);
1276 OperandMatchResultTy parseRegWithFPInputMods(OperandVector &Operands);
1277 OperandMatchResultTy parseRegWithIntInputMods(OperandVector &Operands);
1278 OperandMatchResultTy parseVReg32OrOff(OperandVector &Operands);
1279 OperandMatchResultTy parseDfmtNfmt(OperandVector &Operands);
1281 void cvtDSOffset01(MCInst &Inst, const OperandVector &Operands);
1282 void cvtDS(MCInst &Inst, const OperandVector &Operands) { cvtDSImpl(Inst, Operands, false); }
1283 void cvtDSGds(MCInst &Inst, const OperandVector &Operands) { cvtDSImpl(Inst, Operands, true); }
1284 void cvtExp(MCInst &Inst, const OperandVector &Operands);
1286 bool parseCnt(int64_t &IntVal);
1287 OperandMatchResultTy parseSWaitCntOps(OperandVector &Operands);
1288 OperandMatchResultTy parseHwreg(OperandVector &Operands);
1291 struct OperandInfoTy {
1293 bool IsSymbolic = false;
1294 bool IsDefined = false;
1296 OperandInfoTy(int64_t Id_) : Id(Id_) {}
1299 bool parseSendMsgBody(OperandInfoTy &Msg, OperandInfoTy &Op, OperandInfoTy &Stream);
1300 bool validateSendMsg(const OperandInfoTy &Msg,
1301 const OperandInfoTy &Op,
1302 const OperandInfoTy &Stream,
1305 bool parseHwregBody(OperandInfoTy &HwReg, int64_t &Offset, int64_t &Width);
1306 bool validateHwreg(const OperandInfoTy &HwReg,
1307 const int64_t Offset,
1308 const int64_t Width,
1312 OperandMatchResultTy parseExpTgtImpl(StringRef Str, uint8_t &Val);
1313 SMLoc getFlatOffsetLoc(const OperandVector &Operands) const;
1315 bool validateInstruction(const MCInst &Inst, const SMLoc &IDLoc, const OperandVector &Operands);
1316 bool validateFlatOffset(const MCInst &Inst, const OperandVector &Operands);
1317 bool validateSOPLiteral(const MCInst &Inst) const;
1318 bool validateConstantBusLimitations(const MCInst &Inst);
1319 bool validateEarlyClobberLimitations(const MCInst &Inst);
1320 bool validateIntClampSupported(const MCInst &Inst);
1321 bool validateMIMGAtomicDMask(const MCInst &Inst);
1322 bool validateMIMGGatherDMask(const MCInst &Inst);
1323 bool validateMovrels(const MCInst &Inst);
1324 bool validateMIMGDataSize(const MCInst &Inst);
1325 bool validateMIMGAddrSize(const MCInst &Inst);
1326 bool validateMIMGD16(const MCInst &Inst);
1327 bool validateMIMGDim(const MCInst &Inst);
1328 bool validateLdsDirect(const MCInst &Inst);
1329 bool validateOpSel(const MCInst &Inst);
1330 bool validateVccOperand(unsigned Reg) const;
1331 bool validateVOP3Literal(const MCInst &Inst) const;
1332 unsigned getConstantBusLimit(unsigned Opcode) const;
1333 bool usesConstantBus(const MCInst &Inst, unsigned OpIdx);
1334 bool isInlineConstant(const MCInst &Inst, unsigned OpIdx) const;
1335 unsigned findImplicitSGPRReadInVOP(const MCInst &Inst) const;
1337 bool isId(const StringRef Id) const;
1338 bool isId(const AsmToken &Token, const StringRef Id) const;
1339 bool isToken(const AsmToken::TokenKind Kind) const;
1340 bool trySkipId(const StringRef Id);
1341 bool trySkipId(const StringRef Id, const AsmToken::TokenKind Kind);
1342 bool trySkipToken(const AsmToken::TokenKind Kind);
1343 bool skipToken(const AsmToken::TokenKind Kind, const StringRef ErrMsg);
1344 bool parseString(StringRef &Val, const StringRef ErrMsg = "expected a string");
1345 void peekTokens(MutableArrayRef<AsmToken> Tokens);
1346 AsmToken::TokenKind getTokenKind() const;
1347 bool parseExpr(int64_t &Imm);
1348 bool parseExpr(OperandVector &Operands);
1349 StringRef getTokenStr() const;
1350 AsmToken peekToken();
1351 AsmToken getToken() const;
1352 SMLoc getLoc() const;
1356 OperandMatchResultTy parseOptionalOperand(OperandVector &Operands);
1357 OperandMatchResultTy parseOptionalOpr(OperandVector &Operands);
1359 OperandMatchResultTy parseExpTgt(OperandVector &Operands);
1360 OperandMatchResultTy parseSendMsgOp(OperandVector &Operands);
1361 OperandMatchResultTy parseInterpSlot(OperandVector &Operands);
1362 OperandMatchResultTy parseInterpAttr(OperandVector &Operands);
1363 OperandMatchResultTy parseSOppBrTarget(OperandVector &Operands);
1364 OperandMatchResultTy parseBoolReg(OperandVector &Operands);
1366 bool parseSwizzleOperands(const unsigned OpNum, int64_t* Op,
1367 const unsigned MinVal,
1368 const unsigned MaxVal,
1369 const StringRef ErrMsg);
1370 OperandMatchResultTy parseSwizzleOp(OperandVector &Operands);
1371 bool parseSwizzleOffset(int64_t &Imm);
1372 bool parseSwizzleMacro(int64_t &Imm);
1373 bool parseSwizzleQuadPerm(int64_t &Imm);
1374 bool parseSwizzleBitmaskPerm(int64_t &Imm);
1375 bool parseSwizzleBroadcast(int64_t &Imm);
1376 bool parseSwizzleSwap(int64_t &Imm);
1377 bool parseSwizzleReverse(int64_t &Imm);
1379 OperandMatchResultTy parseGPRIdxMode(OperandVector &Operands);
1380 int64_t parseGPRIdxMacro();
1382 void cvtMubuf(MCInst &Inst, const OperandVector &Operands) { cvtMubufImpl(Inst, Operands, false, false); }
1383 void cvtMubufAtomic(MCInst &Inst, const OperandVector &Operands) { cvtMubufImpl(Inst, Operands, true, false); }
1384 void cvtMubufAtomicReturn(MCInst &Inst, const OperandVector &Operands) { cvtMubufImpl(Inst, Operands, true, true); }
1385 void cvtMubufLds(MCInst &Inst, const OperandVector &Operands) { cvtMubufImpl(Inst, Operands, false, false, true); }
1386 void cvtMtbuf(MCInst &Inst, const OperandVector &Operands);
1388 AMDGPUOperand::Ptr defaultDLC() const;
1389 AMDGPUOperand::Ptr defaultGLC() const;
1390 AMDGPUOperand::Ptr defaultSLC() const;
1392 AMDGPUOperand::Ptr defaultSMRDOffset8() const;
1393 AMDGPUOperand::Ptr defaultSMRDOffset20() const;
1394 AMDGPUOperand::Ptr defaultSMRDLiteralOffset() const;
1395 AMDGPUOperand::Ptr defaultFlatOffset() const;
1397 OperandMatchResultTy parseOModOperand(OperandVector &Operands);
1399 void cvtVOP3(MCInst &Inst, const OperandVector &Operands,
1400 OptionalImmIndexMap &OptionalIdx);
1401 void cvtVOP3OpSel(MCInst &Inst, const OperandVector &Operands);
1402 void cvtVOP3(MCInst &Inst, const OperandVector &Operands);
1403 void cvtVOP3P(MCInst &Inst, const OperandVector &Operands);
1405 void cvtVOP3Interp(MCInst &Inst, const OperandVector &Operands);
1407 void cvtMIMG(MCInst &Inst, const OperandVector &Operands,
1408 bool IsAtomic = false);
1409 void cvtMIMGAtomic(MCInst &Inst, const OperandVector &Operands);
1411 OperandMatchResultTy parseDim(OperandVector &Operands);
1412 OperandMatchResultTy parseDPP8(OperandVector &Operands);
1413 OperandMatchResultTy parseDPPCtrl(OperandVector &Operands);
1414 AMDGPUOperand::Ptr defaultRowMask() const;
1415 AMDGPUOperand::Ptr defaultBankMask() const;
1416 AMDGPUOperand::Ptr defaultBoundCtrl() const;
1417 AMDGPUOperand::Ptr defaultFI() const;
1418 void cvtDPP(MCInst &Inst, const OperandVector &Operands, bool IsDPP8 = false);
1419 void cvtDPP8(MCInst &Inst, const OperandVector &Operands) { cvtDPP(Inst, Operands, true); }
1421 OperandMatchResultTy parseSDWASel(OperandVector &Operands, StringRef Prefix,
1422 AMDGPUOperand::ImmTy Type);
1423 OperandMatchResultTy parseSDWADstUnused(OperandVector &Operands);
1424 void cvtSdwaVOP1(MCInst &Inst, const OperandVector &Operands);
1425 void cvtSdwaVOP2(MCInst &Inst, const OperandVector &Operands);
1426 void cvtSdwaVOP2b(MCInst &Inst, const OperandVector &Operands);
1427 void cvtSdwaVOP2e(MCInst &Inst, const OperandVector &Operands);
1428 void cvtSdwaVOPC(MCInst &Inst, const OperandVector &Operands);
1429 void cvtSDWA(MCInst &Inst, const OperandVector &Operands,
1430 uint64_t BasicInstType,
1431 bool SkipDstVcc = false,
1432 bool SkipSrcVcc = false);
1434 AMDGPUOperand::Ptr defaultBLGP() const;
1435 AMDGPUOperand::Ptr defaultCBSZ() const;
1436 AMDGPUOperand::Ptr defaultABID() const;
1438 OperandMatchResultTy parseEndpgmOp(OperandVector &Operands);
1439 AMDGPUOperand::Ptr defaultEndpgmImmOperands() const;
1442 struct OptionalOperand {
1444 AMDGPUOperand::ImmTy Type;
1446 bool (*ConvertResult)(int64_t&);
1449 } // end anonymous namespace
1451 // May be called with integer type with equivalent bitwidth.
1452 static const fltSemantics *getFltSemantics(unsigned Size) {
1455 return &APFloat::IEEEsingle();
1457 return &APFloat::IEEEdouble();
1459 return &APFloat::IEEEhalf();
1461 llvm_unreachable("unsupported fp type");
1465 static const fltSemantics *getFltSemantics(MVT VT) {
1466 return getFltSemantics(VT.getSizeInBits() / 8);
1469 static const fltSemantics *getOpFltSemantics(uint8_t OperandType) {
1470 switch (OperandType) {
1471 case AMDGPU::OPERAND_REG_IMM_INT32:
1472 case AMDGPU::OPERAND_REG_IMM_FP32:
1473 case AMDGPU::OPERAND_REG_INLINE_C_INT32:
1474 case AMDGPU::OPERAND_REG_INLINE_C_FP32:
1475 case AMDGPU::OPERAND_REG_INLINE_AC_INT32:
1476 case AMDGPU::OPERAND_REG_INLINE_AC_FP32:
1477 return &APFloat::IEEEsingle();
1478 case AMDGPU::OPERAND_REG_IMM_INT64:
1479 case AMDGPU::OPERAND_REG_IMM_FP64:
1480 case AMDGPU::OPERAND_REG_INLINE_C_INT64:
1481 case AMDGPU::OPERAND_REG_INLINE_C_FP64:
1482 return &APFloat::IEEEdouble();
1483 case AMDGPU::OPERAND_REG_IMM_INT16:
1484 case AMDGPU::OPERAND_REG_IMM_FP16:
1485 case AMDGPU::OPERAND_REG_INLINE_C_INT16:
1486 case AMDGPU::OPERAND_REG_INLINE_C_FP16:
1487 case AMDGPU::OPERAND_REG_INLINE_C_V2INT16:
1488 case AMDGPU::OPERAND_REG_INLINE_C_V2FP16:
1489 case AMDGPU::OPERAND_REG_INLINE_AC_INT16:
1490 case AMDGPU::OPERAND_REG_INLINE_AC_FP16:
1491 case AMDGPU::OPERAND_REG_INLINE_AC_V2INT16:
1492 case AMDGPU::OPERAND_REG_INLINE_AC_V2FP16:
1493 case AMDGPU::OPERAND_REG_IMM_V2INT16:
1494 case AMDGPU::OPERAND_REG_IMM_V2FP16:
1495 return &APFloat::IEEEhalf();
1497 llvm_unreachable("unsupported fp type");
1501 //===----------------------------------------------------------------------===//
1503 //===----------------------------------------------------------------------===//
1505 static bool canLosslesslyConvertToFPType(APFloat &FPLiteral, MVT VT) {
1508 // Convert literal to single precision
1509 APFloat::opStatus Status = FPLiteral.convert(*getFltSemantics(VT),
1510 APFloat::rmNearestTiesToEven,
1512 // We allow precision lost but not overflow or underflow
1513 if (Status != APFloat::opOK &&
1515 ((Status & APFloat::opOverflow) != 0 ||
1516 (Status & APFloat::opUnderflow) != 0)) {
1523 static bool isSafeTruncation(int64_t Val, unsigned Size) {
1524 return isUIntN(Size, Val) || isIntN(Size, Val);
1527 bool AMDGPUOperand::isInlinableImm(MVT type) const {
1529 // This is a hack to enable named inline values like
1530 // shared_base with both 32-bit and 64-bit operands.
1531 // Note that these values are defined as
1532 // 32-bit operands only.
1533 if (isInlineValue()) {
1537 if (!isImmTy(ImmTyNone)) {
1538 // Only plain immediates are inlinable (e.g. "clamp" attribute is not)
1541 // TODO: We should avoid using host float here. It would be better to
1542 // check the float bit values which is what a few other places do.
1543 // We've had bot failures before due to weird NaN support on mips hosts.
1550 AsmParser->hasInv2PiInlineImm());
1559 static_cast<int16_t>(FPLiteral.bitcastToAPInt().getZExtValue()),
1560 AsmParser->hasInv2PiInlineImm());
1565 static_cast<int32_t>(FPLiteral.bitcastToAPInt().getZExtValue()),
1566 AsmParser->hasInv2PiInlineImm());
1572 AsmParser->hasInv2PiInlineImm());
1581 static_cast<int16_t>(
Literal.getLoBits(16).getSExtValue()),
1582 AsmParser->hasInv2PiInlineImm());
1586 static_cast<int32_t>(
Literal.getLoBits(32).getZExtValue()),
1587 AsmParser->hasInv2PiInlineImm());
1590 bool AMDGPUOperand::isLiteralImm(
MVT type)
const {
1592 if (!isImmTy(ImmTyNone)) {
1599 if (type ==
MVT::f64 && hasFPModifiers()) {
1637 bool AMDGPUOperand::isRegClass(
unsigned RCID)
const {
1638 return isRegKind() && AsmParser->getMRI()->getRegClass(RCID).contains(
getReg());
1641 bool AMDGPUOperand::isSDWAOperand(
MVT type)
const {
1642 if (AsmParser->isVI())
1644 else if (AsmParser->isGFX9() || AsmParser->isGFX10())
1645 return isRegClass(AMDGPU::VS_32RegClassID) || isInlinableImm(type);
1650 bool AMDGPUOperand::isSDWAFP16Operand()
const {
1654 bool AMDGPUOperand::isSDWAFP32Operand()
const {
1658 bool AMDGPUOperand::isSDWAInt16Operand()
const {
1662 bool AMDGPUOperand::isSDWAInt32Operand()
const {
1666 bool AMDGPUOperand::isBoolReg()
const {
1667 return (AsmParser->getFeatureBits()[AMDGPU::FeatureWavefrontSize64] && isSCSrcB64()) ||
1668 (AsmParser->getFeatureBits()[AMDGPU::FeatureWavefrontSize32] && isSCSrcB32());
1671 uint64_t AMDGPUOperand::applyInputFPModifiers(uint64_t Val,
unsigned Size)
const 1673 assert(isImmTy(ImmTyNone) && Imm.Mods.hasFPModifiers());
1674 assert(Size == 2 || Size == 4 || Size == 8);
1676 const uint64_t FpSignMask = (1ULL << (Size * 8 - 1));
1688 void AMDGPUOperand::addImmOperands(
MCInst &Inst,
unsigned N,
bool ApplyModifiers)
const {
1691 addLiteralImmOperand(Inst, Imm.Val,
1693 isImmTy(ImmTyNone) && Imm.Mods.hasFPModifiers());
1695 assert(!isImmTy(ImmTyNone) || !hasModifiers());
1700 void AMDGPUOperand::addLiteralImmOperand(
MCInst &Inst, int64_t Val,
bool ApplyModifiers)
const {
1701 const auto& InstDesc = AsmParser->getMII()->get(Inst.
getOpcode());
1706 if (ApplyModifiers) {
1708 const unsigned Size = Imm.IsFPImm ?
sizeof(double) :
getOperandSize(InstDesc, OpNum);
1709 Val = applyInputFPModifiers(Val, Size);
1713 uint8_t OpTy = InstDesc.OpInfo[OpNum].OperandType;
1722 AsmParser->hasInv2PiInlineImm())) {
1730 if (
Literal.getLoBits(32) != 0) {
1731 const_cast<AMDGPUAsmParser *
>(AsmParser)->
Warning(Inst.
getLoc(),
1732 "Can't encode literal as exact 64-bit floating-point operand. " 1733 "Low 32-bits will be set to zero");
1771 uint64_t ImmVal = FPLiteral.bitcastToAPInt().getZExtValue();
1795 AsmParser->hasInv2PiInlineImm())) {
1823 AsmParser->hasInv2PiInlineImm())) {
1837 AsmParser->hasInv2PiInlineImm()));
1847 template <
unsigned Bitw
idth>
1848 void AMDGPUOperand::addKImmFPOperands(
MCInst &Inst,
unsigned N)
const {
1864 void AMDGPUOperand::addRegOperands(
MCInst &Inst,
unsigned N)
const {
1870 case AMDGPU::SRC_SHARED_BASE:
1871 case AMDGPU::SRC_SHARED_LIMIT:
1872 case AMDGPU::SRC_PRIVATE_BASE:
1873 case AMDGPU::SRC_PRIVATE_LIMIT:
1874 case AMDGPU::SRC_POPS_EXITING_WAVE_ID:
1876 case AMDGPU::SRC_VCCZ:
1877 case AMDGPU::SRC_EXECZ:
1878 case AMDGPU::SRC_SCC:
1880 case AMDGPU::SGPR_NULL:
1896 if (Is == IS_VGPR) {
1899 case 1:
return AMDGPU::VGPR_32RegClassID;
1900 case 2:
return AMDGPU::VReg_64RegClassID;
1901 case 3:
return AMDGPU::VReg_96RegClassID;
1902 case 4:
return AMDGPU::VReg_128RegClassID;
1903 case 5:
return AMDGPU::VReg_160RegClassID;
1904 case 8:
return AMDGPU::VReg_256RegClassID;
1905 case 16:
return AMDGPU::VReg_512RegClassID;
1906 case 32:
return AMDGPU::VReg_1024RegClassID;
1908 }
else if (Is == IS_TTMP) {
1911 case 1:
return AMDGPU::TTMP_32RegClassID;
1912 case 2:
return AMDGPU::TTMP_64RegClassID;
1913 case 4:
return AMDGPU::TTMP_128RegClassID;
1914 case 8:
return AMDGPU::TTMP_256RegClassID;
1915 case 16:
return AMDGPU::TTMP_512RegClassID;
1917 }
else if (Is == IS_SGPR) {
1920 case 1:
return AMDGPU::SGPR_32RegClassID;
1921 case 2:
return AMDGPU::SGPR_64RegClassID;
1922 case 4:
return AMDGPU::SGPR_128RegClassID;
1923 case 8:
return AMDGPU::SGPR_256RegClassID;
1924 case 16:
return AMDGPU::SGPR_512RegClassID;
1926 }
else if (Is == IS_AGPR) {
1929 case 1:
return AMDGPU::AGPR_32RegClassID;
1930 case 2:
return AMDGPU::AReg_64RegClassID;
1931 case 4:
return AMDGPU::AReg_128RegClassID;
1932 case 16:
return AMDGPU::AReg_512RegClassID;
1933 case 32:
return AMDGPU::AReg_1024RegClassID;
1941 .Case(
"exec", AMDGPU::EXEC)
1942 .
Case(
"vcc", AMDGPU::VCC)
1943 .
Case(
"flat_scratch", AMDGPU::FLAT_SCR)
1944 .
Case(
"xnack_mask", AMDGPU::XNACK_MASK)
1945 .
Case(
"shared_base", AMDGPU::SRC_SHARED_BASE)
1946 .
Case(
"src_shared_base", AMDGPU::SRC_SHARED_BASE)
1947 .
Case(
"shared_limit", AMDGPU::SRC_SHARED_LIMIT)
1948 .
Case(
"src_shared_limit", AMDGPU::SRC_SHARED_LIMIT)
1949 .
Case(
"private_base", AMDGPU::SRC_PRIVATE_BASE)
1950 .
Case(
"src_private_base", AMDGPU::SRC_PRIVATE_BASE)
1951 .
Case(
"private_limit", AMDGPU::SRC_PRIVATE_LIMIT)
1952 .
Case(
"src_private_limit", AMDGPU::SRC_PRIVATE_LIMIT)
1953 .
Case(
"pops_exiting_wave_id", AMDGPU::SRC_POPS_EXITING_WAVE_ID)
1954 .
Case(
"src_pops_exiting_wave_id", AMDGPU::SRC_POPS_EXITING_WAVE_ID)
1955 .
Case(
"lds_direct", AMDGPU::LDS_DIRECT)
1956 .
Case(
"src_lds_direct", AMDGPU::LDS_DIRECT)
1957 .
Case(
"m0", AMDGPU::M0)
1958 .
Case(
"vccz", AMDGPU::SRC_VCCZ)
1959 .
Case(
"src_vccz", AMDGPU::SRC_VCCZ)
1960 .
Case(
"execz", AMDGPU::SRC_EXECZ)
1961 .
Case(
"src_execz", AMDGPU::SRC_EXECZ)
1962 .
Case(
"scc", AMDGPU::SRC_SCC)
1963 .
Case(
"src_scc", AMDGPU::SRC_SCC)
1964 .
Case(
"tba", AMDGPU::TBA)
1965 .
Case(
"tma", AMDGPU::TMA)
1966 .
Case(
"flat_scratch_lo", AMDGPU::FLAT_SCR_LO)
1967 .
Case(
"flat_scratch_hi", AMDGPU::FLAT_SCR_HI)
1968 .
Case(
"xnack_mask_lo", AMDGPU::XNACK_MASK_LO)
1969 .
Case(
"xnack_mask_hi", AMDGPU::XNACK_MASK_HI)
1970 .
Case(
"vcc_lo", AMDGPU::VCC_LO)
1971 .
Case(
"vcc_hi", AMDGPU::VCC_HI)
1972 .
Case(
"exec_lo", AMDGPU::EXEC_LO)
1973 .
Case(
"exec_hi", AMDGPU::EXEC_HI)
1974 .
Case(
"tma_lo", AMDGPU::TMA_LO)
1975 .
Case(
"tma_hi", AMDGPU::TMA_HI)
1976 .
Case(
"tba_lo", AMDGPU::TBA_LO)
1977 .
Case(
"tba_hi", AMDGPU::TBA_HI)
1978 .
Case(
"null", AMDGPU::SGPR_NULL)
1982 bool AMDGPUAsmParser::ParseRegister(
unsigned &RegNo,
SMLoc &StartLoc,
1984 auto R = parseRegister();
1985 if (!R)
return true;
1987 RegNo = R->getReg();
1988 StartLoc = R->getStartLoc();
1989 EndLoc = R->getEndLoc();
1993 bool AMDGPUAsmParser::AddNextRegisterToList(
unsigned &
Reg,
unsigned &RegWidth,
1997 if (Reg == AMDGPU::EXEC_LO && Reg1 == AMDGPU::EXEC_HI) {
2002 if (Reg == AMDGPU::FLAT_SCR_LO && Reg1 == AMDGPU::FLAT_SCR_HI) {
2003 Reg = AMDGPU::FLAT_SCR;
2007 if (Reg == AMDGPU::XNACK_MASK_LO && Reg1 == AMDGPU::XNACK_MASK_HI) {
2008 Reg = AMDGPU::XNACK_MASK;
2012 if (Reg == AMDGPU::VCC_LO && Reg1 == AMDGPU::VCC_HI) {
2017 if (Reg == AMDGPU::TBA_LO && Reg1 == AMDGPU::TBA_HI) {
2022 if (Reg == AMDGPU::TMA_LO && Reg1 == AMDGPU::TMA_HI) {
2032 if (Reg1 != Reg + RegWidth) {
2050 {{
"ttmp"}, IS_TTMP},
2056 return Kind == IS_VGPR ||
2063 for (
const RegInfo &Reg : RegularRegisters)
2074 AMDGPUAsmParser::isRegister(
const AsmToken &Token,
2091 if (!RegSuffix.
empty()) {
2107 AMDGPUAsmParser::isRegister()
2109 return isRegister(
getToken(), peekToken());
2115 unsigned RegWidth) {
2119 unsigned AlignSize = 1;
2120 if (RegKind == IS_SGPR || RegKind == IS_TTMP) {
2123 AlignSize = std::min(RegWidth, 4u);
2126 if (RegNum % AlignSize != 0)
2127 return AMDGPU::NoRegister;
2129 unsigned RegIdx = RegNum / AlignSize;
2132 return AMDGPU::NoRegister;
2137 return AMDGPU::NoRegister;
2143 AMDGPUAsmParser::ParseRegRange(
unsigned& Num,
unsigned&
Width) {
2144 int64_t RegLo, RegHi;
2148 if (!parseExpr(RegLo))
2152 if (!parseExpr(RegHi))
2164 Num =
static_cast<unsigned>(RegLo);
2165 Width = (RegHi - RegLo) + 1;
2170 AMDGPUAsmParser::ParseSpecialReg(
RegisterKind &RegKind,
2172 unsigned &RegWidth) {
2178 RegKind = IS_SPECIAL;
2185 AMDGPUAsmParser::ParseRegularReg(
RegisterKind &RegKind,
2187 unsigned &RegWidth) {
2193 return AMDGPU::NoRegister;
2198 if (!RegSuffix.
empty()) {
2201 return AMDGPU::NoRegister;
2205 if (!ParseRegRange(RegNum, RegWidth))
2206 return AMDGPU::NoRegister;
2209 return getRegularReg(RegKind, RegNum, RegWidth);
2215 unsigned &RegWidth) {
2216 unsigned Reg = AMDGPU::NoRegister;
2219 return AMDGPU::NoRegister;
2223 if (!ParseAMDGPURegister(RegKind, Reg, RegNum, RegWidth))
2224 return AMDGPU::NoRegister;
2226 return AMDGPU::NoRegister;
2230 unsigned NextReg, NextRegNum, NextRegWidth;
2232 if (!ParseAMDGPURegister(NextRegKind, NextReg, NextRegNum, NextRegWidth))
2233 return AMDGPU::NoRegister;
2234 if (NextRegWidth != 1)
2235 return AMDGPU::NoRegister;
2236 if (NextRegKind != RegKind)
2237 return AMDGPU::NoRegister;
2238 if (!AddNextRegisterToList(Reg, RegWidth, RegKind, NextReg))
2239 return AMDGPU::NoRegister;
2243 return AMDGPU::NoRegister;
2246 Reg = getRegularReg(RegKind, RegNum, RegWidth);
2251 bool AMDGPUAsmParser::ParseAMDGPURegister(
RegisterKind &RegKind,
2254 unsigned &RegWidth) {
2255 Reg = AMDGPU::NoRegister;
2258 Reg = ParseSpecialReg(RegKind, RegNum, RegWidth);
2259 if (Reg == AMDGPU::NoRegister)
2260 Reg = ParseRegularReg(RegKind, RegNum, RegWidth);
2262 Reg = ParseRegList(RegKind, RegNum, RegWidth);
2266 return Reg != AMDGPU::NoRegister && subtargetHasRegister(*TRI, Reg);
2270 AMDGPUAsmParser::getGprCountSymbolName(
RegisterKind RegKind) {
2273 return StringRef(
".amdgcn.next_free_vgpr");
2275 return StringRef(
".amdgcn.next_free_sgpr");
2281 void AMDGPUAsmParser::initializeGprCountSymbol(
RegisterKind RegKind) {
2282 auto SymbolName = getGprCountSymbolName(RegKind);
2288 bool AMDGPUAsmParser::updateGprCountSymbols(
RegisterKind RegKind,
2289 unsigned DwordRegIndex,
2290 unsigned RegWidth) {
2295 auto SymbolName = getGprCountSymbolName(RegKind);
2300 int64_t NewMax = DwordRegIndex + RegWidth - 1;
2304 return !
Error(getParser().getTok().getLoc(),
2305 ".amdgcn.next_free_{v,s}gpr symbols must be variable");
2308 getParser().getTok().getLoc(),
2309 ".amdgcn.next_free_{v,s}gpr symbols must be absolute expressions");
2311 if (OldCount <= NewMax)
2317 std::unique_ptr<AMDGPUOperand> AMDGPUAsmParser::parseRegister() {
2318 const auto &Tok = Parser.getTok();
2319 SMLoc StartLoc = Tok.getLoc();
2320 SMLoc EndLoc = Tok.getEndLoc();
2322 unsigned Reg, RegNum, RegWidth;
2324 if (!ParseAMDGPURegister(RegKind, Reg, RegNum, RegWidth)) {
2326 Error(StartLoc,
"not a valid operand.");
2330 if (!updateGprCountSymbols(RegKind, RegNum, RegWidth))
2333 KernelScope.usesRegister(RegKind, RegNum, RegWidth);
2334 return AMDGPUOperand::CreateReg(
this, Reg, StartLoc, EndLoc);
2345 const auto& NextTok = peekToken();
2348 bool Negate =
false;
2374 AMDGPUOperand::ImmTyNone,
true));
2383 if (HasSP3AbsModifier) {
2392 if (getParser().parsePrimaryExpr(Expr, EndLoc))
2395 if (Parser.parseExpression(Expr))
2399 if (Expr->evaluateAsAbsolute(IntVal)) {
2400 Operands.
push_back(AMDGPUOperand::CreateImm(
this, IntVal, S));
2402 Operands.
push_back(AMDGPUOperand::CreateExpr(
this, Expr, S));
2416 if (
auto R = parseRegister()) {
2425 AMDGPUAsmParser::parseRegOrImm(
OperandVector &Operands,
bool HasSP3AbsMod) {
2426 auto res = parseReg(Operands);
2429 }
else if (isModifier()) {
2432 return parseImm(Operands, HasSP3AbsMod);
2437 AMDGPUAsmParser::isNamedOperandModifier(
const AsmToken &Token,
const AsmToken &NextToken)
const {
2440 return str ==
"abs" || str ==
"neg" || str ==
"sext";
2446 AMDGPUAsmParser::isOpcodeModifierWithVal(
const AsmToken &Token,
const AsmToken &NextToken)
const {
2451 AMDGPUAsmParser::isOperandModifier(
const AsmToken &Token,
const AsmToken &NextToken)
const {
2452 return isNamedOperandModifier(Token, NextToken) || Token.
is(
AsmToken::Pipe);
2456 AMDGPUAsmParser::isRegOrOperandModifier(
const AsmToken &Token,
const AsmToken &NextToken)
const {
2457 return isRegister(Token, NextToken) || isOperandModifier(Token, NextToken);
2476 AMDGPUAsmParser::isModifier() {
2480 peekTokens(NextToken);
2482 return isOperandModifier(Tok, NextToken[0]) ||
2483 (Tok.
is(
AsmToken::Minus) && isRegOrOperandModifier(NextToken[0], NextToken[1])) ||
2484 isOpcodeModifierWithVal(Tok, NextToken[0]);
2510 AMDGPUAsmParser::parseSP3NegModifier() {
2513 peekTokens(NextToken);
2516 (isRegister(NextToken[0], NextToken[1]) ||
2518 isId(NextToken[0],
"abs"))) {
2527 AMDGPUAsmParser::parseRegOrImmWithFPInputMods(
OperandVector &Operands,
2535 Error(getLoc(),
"invalid syntax, expected 'neg' modifier");
2539 SP3Neg = parseSP3NegModifier();
2542 Neg = trySkipId(
"neg");
2543 if (Neg && SP3Neg) {
2544 Error(Loc,
"expected register or immediate");
2550 Abs = trySkipId(
"abs");
2556 if (Abs && SP3Abs) {
2557 Error(Loc,
"expected register or immediate");
2563 Res = parseRegOrImm(Operands, SP3Abs);
2565 Res = parseReg(Operands);
2571 if (SP3Abs && !skipToken(
AsmToken::Pipe,
"expected vertical bar"))
2578 AMDGPUOperand::Modifiers Mods;
2579 Mods.Abs = Abs || SP3Abs;
2580 Mods.Neg = Neg || SP3Neg;
2582 if (Mods.hasFPModifiers()) {
2583 AMDGPUOperand &
Op =
static_cast<AMDGPUOperand &
>(*Operands.
back());
2585 Error(Op.getStartLoc(),
"expected an absolute expression");
2588 Op.setModifiers(Mods);
2594 AMDGPUAsmParser::parseRegOrImmWithIntInputMods(
OperandVector &Operands,
2596 bool Sext = trySkipId(
"sext");
2597 if (Sext && !skipToken(
AsmToken::LParen,
"expected left paren after sext"))
2602 Res = parseRegOrImm(Operands);
2604 Res = parseReg(Operands);
2613 AMDGPUOperand::Modifiers Mods;
2616 if (Mods.hasIntModifiers()) {
2617 AMDGPUOperand &
Op =
static_cast<AMDGPUOperand &
>(*Operands.
back());
2619 Error(Op.getStartLoc(),
"expected an absolute expression");
2622 Op.setModifiers(Mods);
2629 AMDGPUAsmParser::parseRegWithFPInputMods(
OperandVector &Operands) {
2630 return parseRegOrImmWithFPInputMods(Operands,
false);
2634 AMDGPUAsmParser::parseRegWithIntInputMods(
OperandVector &Operands) {
2635 return parseRegOrImmWithIntInputMods(Operands,
false);
2639 auto Loc = getLoc();
2640 if (trySkipId(
"off")) {
2641 Operands.
push_back(AMDGPUOperand::CreateImm(
this, 0, Loc,
2642 AMDGPUOperand::ImmTyOff,
false));
2649 std::unique_ptr<AMDGPUOperand> Reg = parseRegister();
2659 unsigned AMDGPUAsmParser::checkTargetMatchPredicate(
MCInst &Inst) {
2660 uint64_t TSFlags = MII.get(Inst.
getOpcode()).TSFlags;
2666 return Match_InvalidOperand;
2668 if ((TSFlags & SIInstrFlags::VOP3) &&
2670 getForcedEncodingSize() != 64)
2671 return Match_PreferE32;
2673 if (Inst.
getOpcode() == AMDGPU::V_MAC_F32_sdwa_vi ||
2674 Inst.
getOpcode() == AMDGPU::V_MAC_F16_sdwa_vi) {
2680 return Match_InvalidOperand;
2684 return Match_Success;
2689 if (getForcedEncodingSize() == 32) {
2694 if (isForcedVOP3()) {
2699 if (isForcedSDWA()) {
2705 if (isForcedDPP()) {
2710 static const unsigned Variants[] = {
2718 unsigned AMDGPUAsmParser::findImplicitSGPRReadInVOP(
const MCInst &Inst)
const {
2721 for (
unsigned i = 0; i < Num; ++i) {
2724 case AMDGPU::FLAT_SCR:
2726 case AMDGPU::VCC_LO:
2727 case AMDGPU::VCC_HI:
2734 return AMDGPU::NoRegister;
2741 bool AMDGPUAsmParser::isInlineConstant(
const MCInst &Inst,
2742 unsigned OpIdx)
const {
2751 int64_t Val = MO.
getImm();
2777 unsigned AMDGPUAsmParser::getConstantBusLimit(
unsigned Opcode)
const {
2783 case AMDGPU::V_LSHLREV_B64:
2784 case AMDGPU::V_LSHLREV_B64_gfx10:
2785 case AMDGPU::V_LSHL_B64:
2786 case AMDGPU::V_LSHRREV_B64:
2787 case AMDGPU::V_LSHRREV_B64_gfx10:
2788 case AMDGPU::V_LSHR_B64:
2789 case AMDGPU::V_ASHRREV_I64:
2790 case AMDGPU::V_ASHRREV_I64_gfx10:
2791 case AMDGPU::V_ASHR_I64:
2798 bool AMDGPUAsmParser::usesConstantBus(
const MCInst &Inst,
unsigned OpIdx) {
2801 return !isInlineConstant(Inst, OpIdx);
2802 }
else if (MO.
isReg()) {
2811 bool AMDGPUAsmParser::validateConstantBusLimitations(
const MCInst &Inst) {
2812 const unsigned Opcode = Inst.
getOpcode();
2814 unsigned ConstantBusUseCount = 0;
2815 unsigned NumLiterals = 0;
2816 unsigned LiteralSize;
2825 ++ConstantBusUseCount;
2829 unsigned SGPRUsed = findImplicitSGPRReadInVOP(Inst);
2830 if (SGPRUsed != AMDGPU::NoRegister) {
2831 SGPRsUsed.
insert(SGPRUsed);
2832 ++ConstantBusUseCount;
2839 const int OpIndices[] = { Src0Idx, Src1Idx, Src2Idx };
2841 for (
int OpIdx : OpIndices) {
2842 if (OpIdx == -1)
break;
2845 if (usesConstantBus(Inst, OpIdx)) {
2854 if (!SGPRsUsed.
count(Reg)) {
2856 ++ConstantBusUseCount;
2873 if (Size < 4) Size = 4;
2875 if (NumLiterals == 0) {
2878 }
else if (LiteralSize != Size) {
2885 ConstantBusUseCount += NumLiterals;
2887 return ConstantBusUseCount <= getConstantBusLimit(Opcode);
2890 bool AMDGPUAsmParser::validateEarlyClobberLimitations(
const MCInst &Inst) {
2891 const unsigned Opcode = Inst.
getOpcode();
2911 const int SrcIndices[] = { Src0Idx, Src1Idx, Src2Idx };
2913 for (
int SrcIdx : SrcIndices) {
2914 if (SrcIdx == -1)
break;
2927 bool AMDGPUAsmParser::validateIntClampSupported(
const MCInst &Inst) {
2941 bool AMDGPUAsmParser::validateMIMGDataSize(
const MCInst &Inst) {
2968 DataSize = (DataSize + 1) / 2;
2971 return (VDataSize / 4) == DataSize + TFESize;
2974 bool AMDGPUAsmParser::validateMIMGAddrSize(
const MCInst &Inst) {
2982 const AMDGPU::MIMGBaseOpcodeInfo *BaseOpcode =
2991 assert(SrsrcIdx > VAddr0Idx);
2995 bool IsNSA = SrsrcIdx - VAddr0Idx > 1;
2996 unsigned VAddrSize =
2997 IsNSA ? SrsrcIdx - VAddr0Idx
3000 unsigned AddrSize = BaseOpcode->NumExtraArgs +
3001 (BaseOpcode->Gradients ? DimInfo->NumGradients : 0) +
3002 (BaseOpcode->Coordinates ? DimInfo->NumCoords : 0) +
3003 (BaseOpcode->LodOrClampOrMip ? 1 : 0);
3007 else if (AddrSize > 4)
3011 return VAddrSize == AddrSize;
3014 bool AMDGPUAsmParser::validateMIMGAtomicDMask(
const MCInst &Inst) {
3031 return DMask == 0x1 || DMask == 0x3 || DMask == 0xf;
3034 bool AMDGPUAsmParser::validateMIMGGatherDMask(
const MCInst &Inst) {
3050 return DMask == 0x1 || DMask == 0x2 || DMask == 0x4 || DMask == 0x8;
3056 case AMDGPU::V_MOVRELS_B32_sdwa_gfx10:
3057 case AMDGPU::V_MOVRELSD_B32_sdwa_gfx10:
3058 case AMDGPU::V_MOVRELSD_2_B32_sdwa_gfx10:
3068 bool AMDGPUAsmParser::validateMovrels(
const MCInst &Inst) {
3083 auto Reg = Src0.
getReg();
3088 bool AMDGPUAsmParser::validateMIMGD16(
const MCInst &Inst) {
3105 bool AMDGPUAsmParser::validateMIMGDim(
const MCInst &Inst) {
3117 if (Imm < 0 || Imm >= 8)
3126 case AMDGPU::V_SUBREV_F32_e32:
3127 case AMDGPU::V_SUBREV_F32_e64:
3128 case AMDGPU::V_SUBREV_F32_e32_gfx10:
3129 case AMDGPU::V_SUBREV_F32_e32_gfx6_gfx7:
3130 case AMDGPU::V_SUBREV_F32_e32_vi:
3131 case AMDGPU::V_SUBREV_F32_e64_gfx10:
3132 case AMDGPU::V_SUBREV_F32_e64_gfx6_gfx7:
3133 case AMDGPU::V_SUBREV_F32_e64_vi:
3135 case AMDGPU::V_SUBREV_I32_e32:
3136 case AMDGPU::V_SUBREV_I32_e64:
3137 case AMDGPU::V_SUBREV_I32_e32_gfx6_gfx7:
3138 case AMDGPU::V_SUBREV_I32_e64_gfx6_gfx7:
3140 case AMDGPU::V_SUBBREV_U32_e32:
3141 case AMDGPU::V_SUBBREV_U32_e64:
3142 case AMDGPU::V_SUBBREV_U32_e32_gfx6_gfx7:
3143 case AMDGPU::V_SUBBREV_U32_e32_vi:
3144 case AMDGPU::V_SUBBREV_U32_e64_gfx6_gfx7:
3145 case AMDGPU::V_SUBBREV_U32_e64_vi:
3147 case AMDGPU::V_SUBREV_U32_e32:
3148 case AMDGPU::V_SUBREV_U32_e64:
3149 case AMDGPU::V_SUBREV_U32_e32_gfx9:
3150 case AMDGPU::V_SUBREV_U32_e32_vi:
3151 case AMDGPU::V_SUBREV_U32_e64_gfx9:
3152 case AMDGPU::V_SUBREV_U32_e64_vi:
3154 case AMDGPU::V_SUBREV_F16_e32:
3155 case AMDGPU::V_SUBREV_F16_e64:
3156 case AMDGPU::V_SUBREV_F16_e32_gfx10:
3157 case AMDGPU::V_SUBREV_F16_e32_vi:
3158 case AMDGPU::V_SUBREV_F16_e64_gfx10:
3159 case AMDGPU::V_SUBREV_F16_e64_vi:
3161 case AMDGPU::V_SUBREV_U16_e32:
3162 case AMDGPU::V_SUBREV_U16_e64:
3163 case AMDGPU::V_SUBREV_U16_e32_vi:
3164 case AMDGPU::V_SUBREV_U16_e64_vi:
3166 case AMDGPU::V_SUBREV_CO_U32_e32_gfx9:
3167 case AMDGPU::V_SUBREV_CO_U32_e64_gfx10:
3168 case AMDGPU::V_SUBREV_CO_U32_e64_gfx9:
3170 case AMDGPU::V_SUBBREV_CO_U32_e32_gfx9:
3171 case AMDGPU::V_SUBBREV_CO_U32_e64_gfx9:
3173 case AMDGPU::V_SUBREV_NC_U32_e32_gfx10:
3174 case AMDGPU::V_SUBREV_NC_U32_e64_gfx10:
3176 case AMDGPU::V_SUBREV_CO_CI_U32_e32_gfx10:
3177 case AMDGPU::V_SUBREV_CO_CI_U32_e64_gfx10:
3179 case AMDGPU::V_LSHRREV_B32_e32:
3180 case AMDGPU::V_LSHRREV_B32_e64:
3181 case AMDGPU::V_LSHRREV_B32_e32_gfx6_gfx7:
3182 case AMDGPU::V_LSHRREV_B32_e64_gfx6_gfx7:
3183 case AMDGPU::V_LSHRREV_B32_e32_vi:
3184 case AMDGPU::V_LSHRREV_B32_e64_vi:
3185 case AMDGPU::V_LSHRREV_B32_e32_gfx10:
3186 case AMDGPU::V_LSHRREV_B32_e64_gfx10:
3188 case AMDGPU::V_ASHRREV_I32_e32:
3189 case AMDGPU::V_ASHRREV_I32_e64:
3190 case AMDGPU::V_ASHRREV_I32_e32_gfx10:
3191 case AMDGPU::V_ASHRREV_I32_e32_gfx6_gfx7:
3192 case AMDGPU::V_ASHRREV_I32_e32_vi:
3193 case AMDGPU::V_ASHRREV_I32_e64_gfx10:
3194 case AMDGPU::V_ASHRREV_I32_e64_gfx6_gfx7:
3195 case AMDGPU::V_ASHRREV_I32_e64_vi:
3197 case AMDGPU::V_LSHLREV_B32_e32:
3198 case AMDGPU::V_LSHLREV_B32_e64:
3199 case AMDGPU::V_LSHLREV_B32_e32_gfx10:
3200 case AMDGPU::V_LSHLREV_B32_e32_gfx6_gfx7:
3201 case AMDGPU::V_LSHLREV_B32_e32_vi:
3202 case AMDGPU::V_LSHLREV_B32_e64_gfx10:
3203 case AMDGPU::V_LSHLREV_B32_e64_gfx6_gfx7:
3204 case AMDGPU::V_LSHLREV_B32_e64_vi:
3206 case AMDGPU::V_LSHLREV_B16_e32:
3207 case AMDGPU::V_LSHLREV_B16_e64:
3208 case AMDGPU::V_LSHLREV_B16_e32_vi:
3209 case AMDGPU::V_LSHLREV_B16_e64_vi:
3210 case AMDGPU::V_LSHLREV_B16_gfx10:
3212 case AMDGPU::V_LSHRREV_B16_e32:
3213 case AMDGPU::V_LSHRREV_B16_e64:
3214 case AMDGPU::V_LSHRREV_B16_e32_vi:
3215 case AMDGPU::V_LSHRREV_B16_e64_vi:
3216 case AMDGPU::V_LSHRREV_B16_gfx10:
3218 case AMDGPU::V_ASHRREV_I16_e32:
3219 case AMDGPU::V_ASHRREV_I16_e64:
3220 case AMDGPU::V_ASHRREV_I16_e32_vi:
3221 case AMDGPU::V_ASHRREV_I16_e64_vi:
3222 case AMDGPU::V_ASHRREV_I16_gfx10:
3224 case AMDGPU::V_LSHLREV_B64:
3225 case AMDGPU::V_LSHLREV_B64_gfx10:
3226 case AMDGPU::V_LSHLREV_B64_vi:
3228 case AMDGPU::V_LSHRREV_B64:
3229 case AMDGPU::V_LSHRREV_B64_gfx10:
3230 case AMDGPU::V_LSHRREV_B64_vi:
3232 case AMDGPU::V_ASHRREV_I64:
3233 case AMDGPU::V_ASHRREV_I64_gfx10:
3234 case AMDGPU::V_ASHRREV_I64_vi:
3236 case AMDGPU::V_PK_LSHLREV_B16:
3237 case AMDGPU::V_PK_LSHLREV_B16_gfx10:
3238 case AMDGPU::V_PK_LSHLREV_B16_vi:
3240 case AMDGPU::V_PK_LSHRREV_B16:
3241 case AMDGPU::V_PK_LSHRREV_B16_gfx10:
3242 case AMDGPU::V_PK_LSHRREV_B16_vi:
3243 case AMDGPU::V_PK_ASHRREV_I16:
3244 case AMDGPU::V_PK_ASHRREV_I16_gfx10:
3245 case AMDGPU::V_PK_ASHRREV_I16_vi:
3252 bool AMDGPUAsmParser::validateLdsDirect(
const MCInst &Inst) {
3254 using namespace SIInstrFlags;
3255 const unsigned Opcode = Inst.
getOpcode();
3267 const int SrcIndices[] = { Src1Idx, Src2Idx };
3270 for (
int SrcIdx : SrcIndices) {
3271 if (SrcIdx == -1)
break;
3290 for (
unsigned i = 1,
e = Operands.
size(); i !=
e; ++i) {
3291 AMDGPUOperand &
Op = ((AMDGPUOperand &)*Operands[i]);
3292 if (Op.isFlatOffset())
3293 return Op.getStartLoc();
3298 bool AMDGPUAsmParser::validateFlatOffset(
const MCInst &Inst,
3300 uint64_t TSFlags = MII.get(Inst.
getOpcode()).TSFlags;
3309 if (!hasFlatOffsets() &&
Op.getImm() != 0) {
3310 Error(getFlatOffsetLoc(Operands),
3311 "flat offset modifier is not supported on this GPU");
3318 unsigned OffsetSize =
isGFX9() ? 13 : 12;
3320 if (!
isIntN(OffsetSize,
Op.getImm())) {
3321 Error(getFlatOffsetLoc(Operands),
3322 isGFX9() ?
"expected a 13-bit signed offset" :
3323 "expected a 12-bit signed offset");
3327 if (!
isUIntN(OffsetSize - 1,
Op.getImm())) {
3328 Error(getFlatOffsetLoc(Operands),
3329 isGFX9() ?
"expected a 12-bit unsigned offset" :
3330 "expected an 11-bit unsigned offset");
3338 bool AMDGPUAsmParser::validateSOPLiteral(
const MCInst &Inst)
const {
3347 const int OpIndices[] = { Src0Idx, Src1Idx };
3349 unsigned NumExprs = 0;
3350 unsigned NumLiterals = 0;
3353 for (
int OpIdx : OpIndices) {
3354 if (OpIdx == -1)
break;
3359 if (MO.
isImm() && !isInlineConstant(Inst, OpIdx)) {
3361 if (NumLiterals == 0 || LiteralValue != Value) {
3362 LiteralValue =
Value;
3365 }
else if (MO.
isExpr()) {
3371 return NumLiterals + NumExprs <= 1;
3374 bool AMDGPUAsmParser::validateOpSel(
const MCInst &Inst) {
3376 if (Opc == AMDGPU::V_PERMLANE16_B32_gfx10 ||
3377 Opc == AMDGPU::V_PERMLANEX16_B32_gfx10) {
3388 bool AMDGPUAsmParser::validateVccOperand(
unsigned Reg)
const {
3389 auto FB = getFeatureBits();
3390 return (FB[AMDGPU::FeatureWavefrontSize64] && Reg == AMDGPU::VCC) ||
3391 (FB[AMDGPU::FeatureWavefrontSize32] && Reg == AMDGPU::VCC_LO);
3395 bool AMDGPUAsmParser::validateVOP3Literal(
const MCInst &Inst)
const {
3405 const int OpIndices[] = { Src0Idx, Src1Idx, Src2Idx };
3407 unsigned NumExprs = 0;
3408 unsigned NumLiterals = 0;
3411 for (
int OpIdx : OpIndices) {
3412 if (OpIdx == -1)
break;
3421 getFeatureBits()[AMDGPU::FeatureMFMAInlineLiteralBug])
3424 if (MO.
isImm() && !isInlineConstant(Inst, OpIdx)) {
3426 if (NumLiterals == 0 || LiteralValue != Value) {
3427 LiteralValue =
Value;
3430 }
else if (MO.
isExpr()) {
3434 NumLiterals += NumExprs;
3436 return !NumLiterals ||
3437 (NumLiterals == 1 && getFeatureBits()[AMDGPU::FeatureVOP3Literal]);
3440 bool AMDGPUAsmParser::validateInstruction(
const MCInst &Inst,
3443 if (!validateLdsDirect(Inst)) {
3445 "invalid use of lds_direct");
3448 if (!validateSOPLiteral(Inst)) {
3450 "only one literal operand is allowed");
3453 if (!validateVOP3Literal(Inst)) {
3455 "invalid literal operand");
3458 if (!validateConstantBusLimitations(Inst)) {
3460 "invalid operand (violates constant bus restrictions)");
3463 if (!validateEarlyClobberLimitations(Inst)) {
3465 "destination must be different than all sources");
3468 if (!validateIntClampSupported(Inst)) {
3470 "integer clamping is not supported on this GPU");
3473 if (!validateOpSel(Inst)) {
3475 "invalid op_sel operand");
3479 if (!validateMIMGD16(Inst)) {
3481 "d16 modifier is not supported on this GPU");
3484 if (!validateMIMGDim(Inst)) {
3485 Error(IDLoc,
"dim modifier is required on this GPU");
3488 if (!validateMIMGDataSize(Inst)) {
3490 "image data size does not match dmask and tfe");
3493 if (!validateMIMGAddrSize(Inst)) {
3495 "image address size does not match dim and a16");
3498 if (!validateMIMGAtomicDMask(Inst)) {
3500 "invalid atomic image dmask");
3503 if (!validateMIMGGatherDMask(Inst)) {
3505 "invalid image_gather dmask: only one bit must be set");
3508 if (!validateMovrels(Inst)) {
3509 Error(IDLoc,
"source operand must be a VGPR");
3512 if (!validateFlatOffset(Inst, Operands)) {
3521 unsigned VariantID = 0);
3523 bool AMDGPUAsmParser::MatchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
3527 bool MatchingInlineAsm) {
3529 unsigned Result = Match_Success;
3530 for (
auto Variant : getMatchedVariants()) {
3532 auto R = MatchInstructionImpl(Operands, Inst, EI, MatchingInlineAsm,
3537 if ((R == Match_Success) ||
3538 (R == Match_PreferE32) ||
3539 (R == Match_MissingFeature && Result != Match_PreferE32) ||
3540 (R == Match_InvalidOperand && Result != Match_MissingFeature
3541 && Result != Match_PreferE32) ||
3542 (R == Match_MnemonicFail && Result != Match_InvalidOperand
3543 && Result != Match_MissingFeature
3544 && Result != Match_PreferE32)) {
3548 if (R == Match_Success)
3555 if (!validateInstruction(Inst, IDLoc, Operands)) {
3562 case Match_MissingFeature:
3563 return Error(IDLoc,
"instruction not supported on this GPU");
3565 case Match_MnemonicFail: {
3566 FeatureBitset FBS = ComputeAvailableFeatures(getSTI().getFeatureBits());
3568 ((AMDGPUOperand &)*Operands[0]).
getToken(), FBS);
3569 return Error(IDLoc,
"invalid instruction" + Suggestion,
3570 ((AMDGPUOperand &)*Operands[0]).getLocRange());
3573 case Match_InvalidOperand: {
3574 SMLoc ErrorLoc = IDLoc;
3575 if (ErrorInfo != ~0ULL) {
3576 if (ErrorInfo >= Operands.
size()) {
3577 return Error(IDLoc,
"too few operands for instruction");
3579 ErrorLoc = ((AMDGPUOperand &)*Operands[ErrorInfo]).getStartLoc();
3580 if (ErrorLoc ==
SMLoc())
3583 return Error(ErrorLoc,
"invalid operand for instruction");
3586 case Match_PreferE32:
3587 return Error(IDLoc,
"internal error: instruction without _e64 suffix " 3588 "should be encoded as e32");
3593 bool AMDGPUAsmParser::ParseAsAbsoluteExpression(
uint32_t &
Ret) {
3598 if (getParser().parseAbsoluteExpression(Tmp)) {
3605 bool AMDGPUAsmParser::ParseDirectiveMajorMinor(
uint32_t &Major,
3607 if (ParseAsAbsoluteExpression(Major))
3608 return TokError(
"invalid major version");
3611 return TokError(
"minor version number required, comma expected");
3614 if (ParseAsAbsoluteExpression(Minor))
3615 return TokError(
"invalid minor version");
3620 bool AMDGPUAsmParser::ParseDirectiveAMDGCNTarget() {
3622 return TokError(
"directive only supported for amdgcn architecture");
3626 SMLoc TargetStart = getTok().getLoc();
3627 if (getParser().parseEscapedString(Target))
3631 std::string ExpectedTarget;
3635 if (Target != ExpectedTargetOS.
str())
3636 return getParser().Error(TargetRange.
Start,
"target must match options",
3639 getTargetStreamer().EmitDirectiveAMDGCNTarget(Target);
3643 bool AMDGPUAsmParser::OutOfRangeError(
SMRange Range) {
3644 return getParser().Error(Range.
Start,
"value out of range", Range);
3647 bool AMDGPUAsmParser::calculateGPRBlocks(
3648 const FeatureBitset &Features,
bool VCCUsed,
bool FlatScrUsed,
3649 bool XNACKUsed,
Optional<bool> EnableWavefrontSize32,
unsigned NextFreeVGPR,
3651 unsigned &VGPRBlocks,
unsigned &SGPRBlocks) {
3659 if (Version.
Major >= 10)
3662 unsigned MaxAddressableNumSGPRs =
3665 if (Version.
Major >= 8 && !Features.
test(FeatureSGPRInitBug) &&
3666 NumSGPRs > MaxAddressableNumSGPRs)
3667 return OutOfRangeError(SGPRRange);
3672 if ((Version.
Major <= 7 || Features.
test(FeatureSGPRInitBug)) &&
3673 NumSGPRs > MaxAddressableNumSGPRs)
3674 return OutOfRangeError(SGPRRange);
3676 if (Features.
test(FeatureSGPRInitBug))
3687 bool AMDGPUAsmParser::ParseDirectiveAMDHSAKernel() {
3689 return TokError(
"directive only supported for amdgcn architecture");
3692 return TokError(
"directive only supported for amdhsa OS");
3695 if (getParser().parseIdentifier(KernelName))
3705 uint64_t NextFreeVGPR = 0;
3707 uint64_t NextFreeSGPR = 0;
3708 unsigned UserSGPRCount = 0;
3709 bool ReserveVCC =
true;
3710 bool ReserveFlatScr =
true;
3719 return TokError(
"expected .amdhsa_ directive or .end_amdhsa_kernel");
3722 SMRange IDRange = getTok().getLocRange();
3725 if (ID ==
".end_amdhsa_kernel")
3728 if (Seen.
find(ID) != Seen.
end())
3729 return TokError(
".amdhsa_ directives cannot be repeated");
3732 SMLoc ValStart = getTok().getLoc();
3734 if (getParser().parseAbsoluteExpression(IVal))
3736 SMLoc ValEnd = getTok().getLoc();
3740 return OutOfRangeError(ValRange);
3742 uint64_t Val = IVal;
3744 #define PARSE_BITS_ENTRY(FIELD, ENTRY, VALUE, RANGE) \ 3745 if (!isUInt<ENTRY##_WIDTH>(VALUE)) \ 3746 return OutOfRangeError(RANGE); \ 3747 AMDHSA_BITS_SET(FIELD, ENTRY, VALUE); 3749 if (ID ==
".amdhsa_group_segment_fixed_size") {
3751 return OutOfRangeError(ValRange);
3753 }
else if (ID ==
".amdhsa_private_segment_fixed_size") {
3755 return OutOfRangeError(ValRange);
3757 }
else if (ID ==
".amdhsa_user_sgpr_private_segment_buffer") {
3759 KERNEL_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_BUFFER,
3763 }
else if (ID ==
".amdhsa_user_sgpr_dispatch_ptr") {
3765 KERNEL_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_PTR, Val,
3769 }
else if (ID ==
".amdhsa_user_sgpr_queue_ptr") {
3771 KERNEL_CODE_PROPERTY_ENABLE_SGPR_QUEUE_PTR, Val,
3775 }
else if (ID ==
".amdhsa_user_sgpr_kernarg_segment_ptr") {
3777 KERNEL_CODE_PROPERTY_ENABLE_SGPR_KERNARG_SEGMENT_PTR,
3781 }
else if (ID ==
".amdhsa_user_sgpr_dispatch_id") {
3783 KERNEL_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_ID, Val,
3787 }
else if (ID ==
".amdhsa_user_sgpr_flat_scratch_init") {
3789 KERNEL_CODE_PROPERTY_ENABLE_SGPR_FLAT_SCRATCH_INIT, Val,
3793 }
else if (ID ==
".amdhsa_user_sgpr_private_segment_size") {
3795 KERNEL_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_SIZE,
3799 }
else if (ID ==
".amdhsa_wavefront_size32") {
3800 if (IVersion.
Major < 10)
3801 return getParser().Error(IDRange.
Start,
"directive requires gfx10+",
3803 EnableWavefrontSize32 = Val;
3805 KERNEL_CODE_PROPERTY_ENABLE_WAVEFRONT_SIZE32,
3807 }
else if (ID ==
".amdhsa_system_sgpr_private_segment_wavefront_offset") {
3810 COMPUTE_PGM_RSRC2_ENABLE_SGPR_PRIVATE_SEGMENT_WAVEFRONT_OFFSET, Val,
3812 }
else if (ID ==
".amdhsa_system_sgpr_workgroup_id_x") {
3814 COMPUTE_PGM_RSRC2_ENABLE_SGPR_WORKGROUP_ID_X, Val,
3816 }
else if (ID ==
".amdhsa_system_sgpr_workgroup_id_y") {
3818 COMPUTE_PGM_RSRC2_ENABLE_SGPR_WORKGROUP_ID_Y, Val,
3820 }
else if (ID ==
".amdhsa_system_sgpr_workgroup_id_z") {
3822 COMPUTE_PGM_RSRC2_ENABLE_SGPR_WORKGROUP_ID_Z, Val,
3824 }
else if (ID ==
".amdhsa_system_sgpr_workgroup_info") {
3826 COMPUTE_PGM_RSRC2_ENABLE_SGPR_WORKGROUP_INFO, Val,
3828 }
else if (ID ==
".amdhsa_system_vgpr_workitem_id") {
3830 COMPUTE_PGM_RSRC2_ENABLE_VGPR_WORKITEM_ID, Val,
3832 }
else if (ID ==
".amdhsa_next_free_vgpr") {
3833 VGPRRange = ValRange;
3835 }
else if (ID ==
".amdhsa_next_free_sgpr") {
3836 SGPRRange = ValRange;
3838 }
else if (ID ==
".amdhsa_reserve_vcc") {
3839 if (!isUInt<1>(Val))
3840 return OutOfRangeError(ValRange);
3842 }
else if (ID ==
".amdhsa_reserve_flat_scratch") {
3843 if (IVersion.
Major < 7)
3844 return getParser().Error(IDRange.
Start,
"directive requires gfx7+",
3846 if (!isUInt<1>(Val))
3847 return OutOfRangeError(ValRange);
3848 ReserveFlatScr = Val;
3849 }
else if (ID ==
".amdhsa_reserve_xnack_mask") {
3850 if (IVersion.
Major < 8)
3851 return getParser().Error(IDRange.
Start,
"directive requires gfx8+",
3853 if (!isUInt<1>(Val))
3854 return OutOfRangeError(ValRange);
3856 }
else if (ID ==
".amdhsa_float_round_mode_32") {
3858 COMPUTE_PGM_RSRC1_FLOAT_ROUND_MODE_32, Val, ValRange);
3859 }
else if (ID ==
".amdhsa_float_round_mode_16_64") {
3861 COMPUTE_PGM_RSRC1_FLOAT_ROUND_MODE_16_64, Val, ValRange);
3862 }
else if (ID ==
".amdhsa_float_denorm_mode_32") {
3864 COMPUTE_PGM_RSRC1_FLOAT_DENORM_MODE_32, Val, ValRange);
3865 }
else if (ID ==
".amdhsa_float_denorm_mode_16_64") {
3867 COMPUTE_PGM_RSRC1_FLOAT_DENORM_MODE_16_64, Val,
3869 }
else if (ID ==
".amdhsa_dx10_clamp") {
3871 COMPUTE_PGM_RSRC1_ENABLE_DX10_CLAMP, Val, ValRange);
3872 }
else if (ID ==
".amdhsa_ieee_mode") {
3875 }
else if (ID ==
".amdhsa_fp16_overflow") {
3876 if (IVersion.
Major < 9)
3877 return getParser().Error(IDRange.
Start,
"directive requires gfx9+",
3881 }
else if (ID ==
".amdhsa_workgroup_processor_mode") {
3882 if (IVersion.
Major < 10)
3883 return getParser().Error(IDRange.
Start,
"directive requires gfx10+",
3887 }
else if (ID ==
".amdhsa_memory_ordered") {
3888 if (IVersion.
Major < 10)
3889 return getParser().Error(IDRange.
Start,
"directive requires gfx10+",
3893 }
else if (ID ==
".amdhsa_forward_progress") {
3894 if (IVersion.
Major < 10)
3895 return getParser().Error(IDRange.
Start,
"directive requires gfx10+",
3899 }
else if (ID ==
".amdhsa_exception_fp_ieee_invalid_op") {
3902 COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_INVALID_OPERATION, Val,
3904 }
else if (ID ==
".amdhsa_exception_fp_denorm_src") {
3906 COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_FP_DENORMAL_SOURCE,
3908 }
else if (ID ==
".amdhsa_exception_fp_ieee_div_zero") {
3911 COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_DIVISION_BY_ZERO, Val,
3913 }
else if (ID ==
".amdhsa_exception_fp_ieee_overflow") {
3915 COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_OVERFLOW,
3917 }
else if (ID ==
".amdhsa_exception_fp_ieee_underflow") {
3919 COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_UNDERFLOW,
3921 }
else if (ID ==
".amdhsa_exception_fp_ieee_inexact") {
3923 COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_INEXACT,
3925 }
else if (ID ==
".amdhsa_exception_int_div_zero") {
3927 COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_INT_DIVIDE_BY_ZERO,
3930 return getParser().Error(IDRange.
Start,
3931 "unknown .amdhsa_kernel directive", IDRange);
3934 #undef PARSE_BITS_ENTRY 3937 if (Seen.
find(
".amdhsa_next_free_vgpr") == Seen.
end())
3938 return TokError(
".amdhsa_next_free_vgpr directive is required");
3940 if (Seen.
find(
".amdhsa_next_free_sgpr") == Seen.
end())
3941 return TokError(
".amdhsa_next_free_sgpr directive is required");
3943 unsigned VGPRBlocks;
3944 unsigned SGPRBlocks;
3945 if (calculateGPRBlocks(getFeatureBits(), ReserveVCC, ReserveFlatScr,
3946 ReserveXNACK, EnableWavefrontSize32, NextFreeVGPR,
3947 VGPRRange, NextFreeSGPR, SGPRRange, VGPRBlocks,
3951 if (!isUInt<COMPUTE_PGM_RSRC1_GRANULATED_WORKITEM_VGPR_COUNT_WIDTH>(
3953 return OutOfRangeError(VGPRRange);
3955 COMPUTE_PGM_RSRC1_GRANULATED_WORKITEM_VGPR_COUNT, VGPRBlocks);
3957 if (!isUInt<COMPUTE_PGM_RSRC1_GRANULATED_WAVEFRONT_SGPR_COUNT_WIDTH>(
3959 return OutOfRangeError(SGPRRange);
3961 COMPUTE_PGM_RSRC1_GRANULATED_WAVEFRONT_SGPR_COUNT,
3964 if (!isUInt<COMPUTE_PGM_RSRC2_USER_SGPR_COUNT_WIDTH>(UserSGPRCount))
3965 return TokError(
"too many user SGPRs enabled");
3969 getTargetStreamer().EmitAmdhsaKernelDescriptor(
3970 getSTI(), KernelName, KD, NextFreeVGPR, NextFreeSGPR, ReserveVCC,
3971 ReserveFlatScr, ReserveXNACK);
3975 bool AMDGPUAsmParser::ParseDirectiveHSACodeObjectVersion() {
3979 if (ParseDirectiveMajorMinor(Major, Minor))
3982 getTargetStreamer().EmitDirectiveHSACodeObjectVersion(Major, Minor);
3986 bool AMDGPUAsmParser::ParseDirectiveHSACodeObjectISA() {
3997 getTargetStreamer().EmitDirectiveHSACodeObjectISA(ISA.Major, ISA.Minor,
4003 if (ParseDirectiveMajorMinor(Major, Minor))
4007 return TokError(
"stepping version number required, comma expected");
4010 if (ParseAsAbsoluteExpression(Stepping))
4011 return TokError(
"invalid stepping version");
4014 return TokError(
"vendor name required, comma expected");
4018 return TokError(
"invalid vendor name");
4020 VendorName = getLexer().getTok().getStringContents();
4024 return TokError(
"arch name required, comma expected");
4028 return TokError(
"invalid arch name");
4030 ArchName = getLexer().getTok().getStringContents();
4033 getTargetStreamer().EmitDirectiveHSACodeObjectISA(Major, Minor, Stepping,
4034 VendorName, ArchName);
4038 bool AMDGPUAsmParser::ParseAMDKernelCodeTValue(
StringRef ID,
4042 if (ID ==
"max_scratch_backing_memory_byte_size") {
4043 Parser.eatToEndOfStatement();
4050 return TokError(Err.
str());
4054 if (ID ==
"enable_wavefront_size32") {
4057 return TokError(
"enable_wavefront_size32=1 is only allowed on GFX10+");
4058 if (!getFeatureBits()[AMDGPU::FeatureWavefrontSize32])
4059 return TokError(
"enable_wavefront_size32=1 requires +WavefrontSize32");
4061 if (!getFeatureBits()[AMDGPU::FeatureWavefrontSize64])
4062 return TokError(
"enable_wavefront_size32=0 requires +WavefrontSize64");
4066 if (ID ==
"wavefront_size") {
4069 return TokError(
"wavefront_size=5 is only allowed on GFX10+");
4070 if (!getFeatureBits()[AMDGPU::FeatureWavefrontSize32])
4071 return TokError(
"wavefront_size=5 requires +WavefrontSize32");
4073 if (!getFeatureBits()[AMDGPU::FeatureWavefrontSize64])
4074 return TokError(
"wavefront_size=6 requires +WavefrontSize64");
4078 if (ID ==
"enable_wgp_mode") {
4080 return TokError(
"enable_wgp_mode=1 is only allowed on GFX10+");
4083 if (ID ==
"enable_mem_ordered") {
4085 return TokError(
"enable_mem_ordered=1 is only allowed on GFX10+");
4088 if (ID ==
"enable_fwd_progress") {
4090 return TokError(
"enable_fwd_progress=1 is only allowed on GFX10+");
4096 bool AMDGPUAsmParser::ParseDirectiveAMDKernelCodeT() {
4107 return TokError(
"expected value identifier or .end_amd_kernel_code_t");
4109 StringRef ID = getLexer().getTok().getIdentifier();
4112 if (ID ==
".end_amd_kernel_code_t")
4115 if (ParseAMDKernelCodeTValue(ID, Header))
4119 getTargetStreamer().EmitAMDKernelCodeT(Header);
4124 bool AMDGPUAsmParser::ParseDirectiveAMDGPUHsaKernel() {
4126 return TokError(
"expected symbol name");
4128 StringRef KernelName = Parser.getTok().getString();
4130 getTargetStreamer().EmitAMDGPUSymbolType(KernelName,
4134 KernelScope.initialize(getContext());
4138 bool AMDGPUAsmParser::ParseDirectiveISAVersion() {
4140 return Error(getParser().getTok().getLoc(),
4141 ".amd_amdgpu_isa directive is not available on non-amdgcn " 4145 auto ISAVersionStringFromASM = getLexer().getTok().getStringContents();
4147 std::string ISAVersionStringFromSTI;
4151 if (ISAVersionStringFromASM != ISAVersionStreamFromSTI.
str()) {
4152 return Error(getParser().getTok().getLoc(),
4153 ".amd_amdgpu_isa directive does not match triple and/or mcpu " 4154 "arguments specified through the command line");
4157 getTargetStreamer().EmitISAVersion(ISAVersionStreamFromSTI.
str());
4163 bool AMDGPUAsmParser::ParseDirectiveHSAMetadata() {
4166 std::tie(AssemblerDirectiveBegin, AssemblerDirectiveEnd) =
4174 return Error(getParser().getTok().getLoc(),
4175 (
Twine(AssemblerDirectiveBegin) +
Twine(
" directive is " 4176 "not available on non-amdhsa OSes")).str());
4179 std::string HSAMetadataString;
4180 if (ParseToEndDirective(AssemblerDirectiveBegin, AssemblerDirectiveEnd,
4185 if (!getTargetStreamer().EmitHSAMetadataV3(HSAMetadataString))
4186 return Error(getParser().getTok().getLoc(),
"invalid HSA metadata");
4188 if (!getTargetStreamer().EmitHSAMetadataV2(HSAMetadataString))
4189 return Error(getParser().getTok().getLoc(),
"invalid HSA metadata");
4199 std::string &CollectString) {
4203 getLexer().setSkipSpace(
false);
4205 bool FoundEnd =
false;
4208 CollectStream << getLexer().getTok().getString();
4213 StringRef ID = getLexer().getTok().getIdentifier();
4214 if (ID == AssemblerDirectiveEnd) {
4221 CollectStream << Parser.parseStringToEndOfStatement()
4222 << getContext().getAsmInfo()->getSeparatorString();
4224 Parser.eatToEndOfStatement();
4227 getLexer().setSkipSpace(
true);
4230 return TokError(
Twine(
"expected directive ") +
4231 Twine(AssemblerDirectiveEnd) +
Twine(
" not found"));
4234 CollectStream.
flush();
4239 bool AMDGPUAsmParser::ParseDirectivePALMetadataBegin() {
4245 auto PALMetadata = getTargetStreamer().getPALMetadata();
4246 if (!PALMetadata->setFromString(String))
4247 return Error(getParser().getTok().getLoc(),
"invalid PAL metadata");
4252 bool AMDGPUAsmParser::ParseDirectivePALMetadata() {
4254 return Error(getParser().getTok().getLoc(),
4256 "not available on non-amdpal OSes")).str());
4259 auto PALMetadata = getTargetStreamer().getPALMetadata();
4260 PALMetadata->setLegacy();
4263 if (ParseAsAbsoluteExpression(Key)) {
4264 return TokError(
Twine(
"invalid value in ") +
4268 return TokError(
Twine(
"expected an even number of values in ") +
4272 if (ParseAsAbsoluteExpression(Value)) {
4273 return TokError(
Twine(
"invalid value in ") +
4276 PALMetadata->setRegister(Key, Value);
4286 bool AMDGPUAsmParser::ParseDirectiveAMDGPULDS() {
4287 if (getParser().checkForValidSection())
4291 SMLoc NameLoc = getLexer().getLoc();
4292 if (getParser().parseIdentifier(Name))
4293 return TokError(
"expected identifier in directive");
4302 SMLoc SizeLoc = getLexer().getLoc();
4303 if (getParser().parseAbsoluteExpression(Size))
4306 return Error(SizeLoc,
"size must be non-negative");
4307 if (Size > LocalMemorySize)
4308 return Error(SizeLoc,
"size is too large");
4313 SMLoc AlignLoc = getLexer().getLoc();
4314 if (getParser().parseAbsoluteExpression(Align))
4317 return Error(AlignLoc,
"alignment must be a power of two");
4322 if (Align >= 1u << 31)
4323 return Error(AlignLoc,
"alignment is too large");
4327 "unexpected token in '.amdgpu_lds' directive"))
4332 return Error(NameLoc,
"invalid symbol redefinition");
4334 getTargetStreamer().emitAMDGPULDS(Symbol, Size, Align);
4338 bool AMDGPUAsmParser::ParseDirective(
AsmToken DirectiveID) {
4342 if (IDVal ==
".amdgcn_target")
4343 return ParseDirectiveAMDGCNTarget();
4345 if (IDVal ==
".amdhsa_kernel")
4346 return ParseDirectiveAMDHSAKernel();
4350 return ParseDirectiveHSAMetadata();
4352 if (IDVal ==
".hsa_code_object_version")
4353 return ParseDirectiveHSACodeObjectVersion();
4355 if (IDVal ==
".hsa_code_object_isa")
4356 return ParseDirectiveHSACodeObjectISA();
4358 if (IDVal ==
".amd_kernel_code_t")
4359 return ParseDirectiveAMDKernelCodeT();
4361 if (IDVal ==
".amdgpu_hsa_kernel")
4362 return ParseDirectiveAMDGPUHsaKernel();
4364 if (IDVal ==
".amd_amdgpu_isa")
4365 return ParseDirectiveISAVersion();
4368 return ParseDirectiveHSAMetadata();
4371 if (IDVal ==
".amdgpu_lds")
4372 return ParseDirectiveAMDGPULDS();
4375 return ParseDirectivePALMetadataBegin();
4378 return ParseDirectivePALMetadata();
4384 unsigned RegNo)
const {
4396 return hasSGPR104_SGPR105();
4400 case AMDGPU::SRC_SHARED_BASE:
4401 case AMDGPU::SRC_SHARED_LIMIT:
4402 case AMDGPU::SRC_PRIVATE_BASE:
4403 case AMDGPU::SRC_PRIVATE_LIMIT:
4404 case AMDGPU::SRC_POPS_EXITING_WAVE_ID:
4407 case AMDGPU::TBA_LO:
4408 case AMDGPU::TBA_HI:
4410 case AMDGPU::TMA_LO:
4411 case AMDGPU::TMA_HI:
4413 case AMDGPU::XNACK_MASK:
4414 case AMDGPU::XNACK_MASK_LO:
4415 case AMDGPU::XNACK_MASK_HI:
4417 case AMDGPU::SGPR_NULL:
4431 case AMDGPU::FLAT_SCR:
4432 case AMDGPU::FLAT_SCR_LO:
4433 case AMDGPU::FLAT_SCR_HI:
4445 return hasSGPR102_SGPR103();
4469 SMLoc LBraceLoc = getTok().getLoc();
4473 ResTy = parseReg(Operands);
4485 if (Operands.
size() - Prefix > 1) {
4487 AMDGPUOperand::CreateToken(
this,
"[", LBraceLoc));
4488 Operands.
push_back(AMDGPUOperand::CreateToken(
this,
"]",
4489 getTok().getLoc()));
4496 return parseRegOrImm(Operands);
4501 setForcedEncodingSize(0);
4502 setForcedDPP(
false);
4503 setForcedSDWA(
false);
4506 setForcedEncodingSize(64);
4508 }
else if (Name.
endswith(
"_e32")) {
4509 setForcedEncodingSize(32);
4511 }
else if (Name.
endswith(
"_dpp")) {
4514 }
else if (Name.
endswith(
"_sdwa")) {
4515 setForcedSDWA(
true);
4525 Name = parseMnemonicSuffix(Name);
4526 Operands.
push_back(AMDGPUOperand::CreateToken(
this, Name, NameLoc));
4531 OperandMode Mode = OperandMode_Default;
4533 Mode = OperandMode_NSA;
4544 Error(getLexer().getLoc(),
"failed parsing operand.");
4551 Error(getLexer().getLoc(),
"not a valid operand.");
4567 AMDGPUAsmParser::parseIntWithPrefix(
const char *
Prefix, int64_t &
IntVal) {
4576 AMDGPUAsmParser::parseIntWithPrefix(
const char *Prefix,
OperandVector &Operands,
4577 AMDGPUOperand::ImmTy ImmTy,
4578 bool (*ConvertResult)(int64_t&)) {
4586 if (ConvertResult && !ConvertResult(Value)) {
4590 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Value, S, ImmTy));
4595 AMDGPUAsmParser::parseOperandArrayWithPrefix(
const char *Prefix,
4597 AMDGPUOperand::ImmTy ImmTy,
4598 bool (*ConvertResult)(int64_t&)) {
4607 const unsigned MaxSize = 4;
4611 for (
int I = 0; ; ++
I) {
4613 SMLoc Loc = getLoc();
4617 if (Op != 0 && Op != 1) {
4627 if (
I + 1 == MaxSize) {
4628 Error(getLoc(),
"expected a closing square bracket");
4636 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Val, S, ImmTy));
4641 AMDGPUAsmParser::parseNamedBit(
const char *Name,
OperandVector &Operands,
4642 AMDGPUOperand::ImmTy ImmTy) {
4644 SMLoc S = Parser.getTok().getLoc();
4649 switch(getLexer().getKind()) {
4651 StringRef Tok = Parser.getTok().getString();
4653 if (Tok ==
"r128" &&
isGFX9())
4654 Error(S,
"r128 modifier is not supported on this GPU");
4656 Error(S,
"a16 modifier is not supported on this GPU");
4672 if (!
isGFX10() && ImmTy == AMDGPUOperand::ImmTyDLC)
4675 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Bit, S, ImmTy));
4681 AMDGPUAsmParser::OptionalImmIndexMap& OptionalIdx,
4682 AMDGPUOperand::ImmTy ImmT,
4683 int64_t Default = 0) {
4684 auto i = OptionalIdx.find(ImmT);
4685 if (i != OptionalIdx.end()) {
4686 unsigned Idx = i->second;
4687 ((AMDGPUOperand &)*Operands[Idx]).addImmOperands(Inst, 1);
4698 StringRef Tok = Parser.getTok().getString();
4699 if (Tok != Prefix) {
4713 Value = Parser.getTok().getString();
4721 SMLoc S = Parser.getTok().getLoc();
4722 int64_t Dfmt = 0, Nfmt = 0;
4724 bool GotDfmt =
false, GotNfmt =
false;
4725 while (!GotDfmt || !GotNfmt) {
4727 auto Res = parseIntWithPrefix(
"dfmt", Dfmt);
4732 Error(Parser.getTok().getLoc(),
"out of range dfmt");
4741 auto Res = parseIntWithPrefix(
"nfmt", Nfmt);
4746 Error(Parser.getTok().getLoc(),
"out of range nfmt");
4756 if (!GotDfmt && !GotNfmt)
4758 auto Format = Dfmt | Nfmt << 4;
4760 AMDGPUOperand::CreateImm(
this, Format, S, AMDGPUOperand::ImmTyFORMAT));
4768 void AMDGPUAsmParser::cvtDSOffset01(
MCInst &Inst,
4770 OptionalImmIndexMap OptionalIdx;
4772 for (
unsigned i = 1,
e = Operands.
size(); i !=
e; ++i) {
4773 AMDGPUOperand &
Op = ((AMDGPUOperand &)*Operands[i]);
4777 Op.addRegOperands(Inst, 1);
4782 OptionalIdx[Op.getImmTy()] = i;
4793 bool IsGdsHardcoded) {
4794 OptionalImmIndexMap OptionalIdx;
4796 for (
unsigned i = 1,
e = Operands.
size(); i !=
e; ++i) {
4797 AMDGPUOperand &
Op = ((AMDGPUOperand &)*Operands[i]);
4801 Op.addRegOperands(Inst, 1);
4805 if (Op.isToken() && Op.getToken() ==
"gds") {
4806 IsGdsHardcoded =
true;
4811 OptionalIdx[Op.getImmTy()] = i;
4814 AMDGPUOperand::ImmTy OffsetType =
4815 (Inst.
getOpcode() == AMDGPU::DS_SWIZZLE_B32_gfx10 ||
4816 Inst.
getOpcode() == AMDGPU::DS_SWIZZLE_B32_gfx6_gfx7 ||
4817 Inst.
getOpcode() == AMDGPU::DS_SWIZZLE_B32_vi) ? AMDGPUOperand::ImmTySwizzle :
4818 AMDGPUOperand::ImmTyOffset;
4822 if (!IsGdsHardcoded) {
4829 OptionalImmIndexMap OptionalIdx;
4831 unsigned OperandIdx[4];
4832 unsigned EnMask = 0;
4835 for (
unsigned i = 1,
e = Operands.
size(); i !=
e; ++i) {
4836 AMDGPUOperand &
Op = ((AMDGPUOperand &)*Operands[i]);
4841 OperandIdx[SrcIdx] = Inst.
size();
4842 Op.addRegOperands(Inst, 1);
4849 OperandIdx[SrcIdx] = Inst.
size();
4855 if (Op.isImm() && Op.getImmTy() == AMDGPUOperand::ImmTyExpTgt) {
4856 Op.addImmOperands(Inst, 1);
4860 if (Op.isToken() && Op.getToken() ==
"done")
4864 OptionalIdx[Op.getImmTy()] = i;
4870 if (OptionalIdx.find(AMDGPUOperand::ImmTyExpCompr) != OptionalIdx.end()) {
4877 for (
auto i = 0; i < SrcIdx; ++i) {
4879 EnMask |= Compr? (0x3 << i * 2) : (0x1 << i);
4895 const AMDGPU::IsaVersion ISA,
4904 IntVal =
encode(ISA, IntVal, CntVal);
4905 if (CntVal !=
decode(ISA, IntVal)) {
4907 IntVal =
encode(ISA, IntVal, -1);
4915 bool AMDGPUAsmParser::parseCnt(int64_t &IntVal) {
4917 SMLoc CntLoc = getLoc();
4925 SMLoc ValLoc = getLoc();
4926 if (!parseExpr(CntVal))
4932 bool Sat = CntName.
endswith(
"_sat");
4934 if (CntName ==
"vmcnt" || CntName ==
"vmcnt_sat") {
4936 }
else if (CntName ==
"expcnt" || CntName ==
"expcnt_sat") {
4938 }
else if (CntName ==
"lgkmcnt" || CntName ==
"lgkmcnt_sat") {
4941 Error(CntLoc,
"invalid counter name " + CntName);
4946 Error(ValLoc,
"too large value for " + CntName);
4955 Error(getLoc(),
"expected a counter name");
4964 AMDGPUAsmParser::parseSWaitCntOps(
OperandVector &Operands) {
4977 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Waitcnt, S));
4982 AMDGPUOperand::isSWaitCnt()
const {
4991 AMDGPUAsmParser::parseHwregBody(OperandInfoTy &HwReg,
4998 (HwReg.Id =
getHwregId(getTokenStr())) >= 0) {
4999 HwReg.IsSymbolic =
true;
5001 }
else if (!parseExpr(HwReg.Id)) {
5010 skipToken(
AsmToken::Comma,
"expected a comma or a closing parenthesis") &&
5011 parseExpr(Offset) &&
5018 AMDGPUAsmParser::validateHwreg(
const OperandInfoTy &HwReg,
5019 const int64_t Offset,
5020 const int64_t Width,
5025 if (HwReg.IsSymbolic && !
isValidHwreg(HwReg.Id, getSTI())) {
5026 Error(Loc,
"specified hardware register is not supported on this GPU");
5029 Error(Loc,
"invalid code of hardware register: only 6-bit values are legal");
5032 Error(Loc,
"invalid bit offset: only 5-bit values are legal");
5035 Error(Loc,
"invalid bitfield width: only values from 1 to 32 are legal");
5046 SMLoc Loc = getLoc();
5054 if (parseHwregBody(HwReg, Offset, Width) &&
5055 validateHwreg(HwReg, Offset, Width, Loc)) {
5058 }
else if (parseExpr(ImmVal)) {
5060 Error(Loc,
"invalid immediate: only 16-bit values are legal");
5063 Operands.
push_back(AMDGPUOperand::CreateImm(
this, ImmVal, Loc, AMDGPUOperand::ImmTyHwreg));
5067 bool AMDGPUOperand::isHwreg()
const {
5068 return isImmTy(ImmTyHwreg);
5076 AMDGPUAsmParser::parseSendMsgBody(OperandInfoTy &Msg,
5078 OperandInfoTy &Stream) {
5082 Msg.IsSymbolic =
true;
5084 }
else if (!parseExpr(Msg.Id)) {
5089 Op.IsDefined =
true;
5091 (Op.Id =
getMsgOpId(Msg.Id, getTokenStr())) >= 0) {
5093 }
else if (!parseExpr(Op.Id)) {
5098 Stream.IsDefined =
true;
5099 if (!parseExpr(Stream.Id))
5108 AMDGPUAsmParser::validateSendMsg(
const OperandInfoTy &Msg,
5109 const OperandInfoTy &Op,
5110 const OperandInfoTy &Stream,
5117 bool Strict = Msg.IsSymbolic;
5120 Error(S,
"invalid message id");
5122 }
else if (Strict && (
msgRequiresOp(Msg.Id) != Op.IsDefined)) {
5123 Error(S, Op.IsDefined ?
5124 "message does not support operations" :
5125 "missing message operation");
5128 Error(S,
"invalid operation id");
5131 Error(S,
"message operation does not support streams");
5134 Error(S,
"invalid message stream id");
5145 SMLoc Loc = getLoc();
5153 if (parseSendMsgBody(Msg, Op, Stream) &&
5154 validateSendMsg(Msg, Op, Stream, Loc)) {
5155 ImmVal =
encodeMsg(Msg.Id, Op.Id, Stream.Id);
5157 }
else if (parseExpr(ImmVal)) {
5159 Error(Loc,
"invalid immediate: only 16-bit values are legal");
5162 Operands.
push_back(AMDGPUOperand::CreateImm(
this, ImmVal, Loc, AMDGPUOperand::ImmTySendMsg));
5166 bool AMDGPUOperand::isSendMsg()
const {
5167 return isImmTy(ImmTySendMsg);
5178 StringRef Str = Parser.getTok().getString();
5185 SMLoc S = Parser.getTok().getLoc();
5190 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Slot, S,
5191 AMDGPUOperand::ImmTyInterpSlot));
5199 StringRef Str = Parser.getTok().getString();
5219 SMLoc S = Parser.getTok().getLoc();
5222 Error(S,
"out of bounds attr");
5228 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Attr, S,
5229 AMDGPUOperand::ImmTyInterpAttr));
5230 Operands.
push_back(AMDGPUOperand::CreateImm(
this, AttrChan, SChan,
5231 AMDGPUOperand::ImmTyAttrChan));
5239 void AMDGPUAsmParser::errorExpTgt() {
5240 Error(Parser.getTok().getLoc(),
"invalid exp target");
5245 if (Str ==
"null") {
5271 if (Val > 4 || (Val == 4 && !
isGFX10()))
5278 if (
isGFX10() && Str ==
"prim") {
5309 StringRef Str = Parser.getTok().getString();
5311 auto Res = parseExpTgtImpl(Str, Val);
5315 SMLoc S = Parser.getTok().getLoc();
5318 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Val, S,
5319 AMDGPUOperand::ImmTyExpTgt));
5333 AMDGPUAsmParser::isId(
const StringRef Id)
const {
5339 return getTokenKind() ==
Kind;
5343 AMDGPUAsmParser::trySkipId(
const StringRef Id) {
5353 if (isId(Id) && peekToken().is(Kind)) {
5363 if (isToken(Kind)) {
5373 if (!trySkipToken(Kind)) {
5374 Error(getLoc(), ErrMsg);
5381 AMDGPUAsmParser::parseExpr(int64_t &Imm) {
5382 return !getParser().parseAbsoluteExpression(Imm);
5390 if (Parser.parseExpression(Expr))
5394 if (Expr->evaluateAsAbsolute(IntVal)) {
5395 Operands.
push_back(AMDGPUOperand::CreateImm(
this, IntVal, S));
5397 Operands.
push_back(AMDGPUOperand::CreateExpr(
this, Expr, S));
5405 Val =
getToken().getStringContents();
5409 Error(getLoc(), ErrMsg);
5416 return Parser.getTok();
5420 AMDGPUAsmParser::peekToken() {
5421 return getLexer().peekTok();
5426 auto TokCount = getLexer().peekTokens(Tokens);
5428 for (
auto Idx = TokCount; Idx < Tokens.
size(); ++Idx)
5433 AMDGPUAsmParser::getTokenKind()
const {
5438 AMDGPUAsmParser::getLoc()
const {
5443 AMDGPUAsmParser::getTokenStr()
const {
5448 AMDGPUAsmParser::lex() {
5459 const unsigned OrMask,
5460 const unsigned XorMask) {
5470 AMDGPUAsmParser::parseSwizzleOperands(
const unsigned OpNum, int64_t* Op,
5471 const unsigned MinVal,
5472 const unsigned MaxVal,
5474 for (
unsigned i = 0; i < OpNum; ++i) {
5478 SMLoc ExprLoc = Parser.getTok().getLoc();
5479 if (!parseExpr(Op[i])) {
5482 if (Op[i] < MinVal || Op[i] > MaxVal) {
5483 Error(ExprLoc, ErrMsg);
5492 AMDGPUAsmParser::parseSwizzleQuadPerm(int64_t &Imm) {
5497 "expected a 2-bit lane id")) {
5508 AMDGPUAsmParser::parseSwizzleBroadcast(int64_t &Imm) {
5511 SMLoc S = Parser.getTok().getLoc();
5515 if (!parseSwizzleOperands(1, &GroupSize,
5517 "group size must be in the interval [2,32]")) {
5521 Error(S,
"group size must be a power of two");
5524 if (parseSwizzleOperands(1, &LaneIdx,
5526 "lane id must be in the interval [0,group size - 1]")) {
5534 AMDGPUAsmParser::parseSwizzleReverse(int64_t &Imm) {
5537 SMLoc S = Parser.getTok().getLoc();
5540 if (!parseSwizzleOperands(1, &GroupSize,
5541 2, 32,
"group size must be in the interval [2,32]")) {
5545 Error(S,
"group size must be a power of two");
5554 AMDGPUAsmParser::parseSwizzleSwap(int64_t &Imm) {
5557 SMLoc S = Parser.getTok().getLoc();
5560 if (!parseSwizzleOperands(1, &GroupSize,
5561 1, 16,
"group size must be in the interval [1,16]")) {
5565 Error(S,
"group size must be a power of two");
5574 AMDGPUAsmParser::parseSwizzleBitmaskPerm(int64_t &Imm) {
5582 SMLoc StrLoc = Parser.getTok().getLoc();
5583 if (!parseString(Ctl)) {
5587 Error(StrLoc,
"expected a 5-character mask");
5591 unsigned AndMask = 0;
5592 unsigned OrMask = 0;
5593 unsigned XorMask = 0;
5595 for (
size_t i = 0; i < Ctl.
size(); ++i) {
5599 Error(StrLoc,
"invalid mask");
5621 AMDGPUAsmParser::parseSwizzleOffset(int64_t &Imm) {
5623 SMLoc OffsetLoc = Parser.getTok().getLoc();
5625 if (!parseExpr(Imm)) {
5629 Error(OffsetLoc,
"expected a 16-bit offset");
5636 AMDGPUAsmParser::parseSwizzleMacro(int64_t &Imm) {
5641 SMLoc ModeLoc = Parser.getTok().getLoc();
5645 Ok = parseSwizzleQuadPerm(Imm);
5647 Ok = parseSwizzleBitmaskPerm(Imm);
5649 Ok = parseSwizzleBroadcast(Imm);
5651 Ok = parseSwizzleSwap(Imm);
5653 Ok = parseSwizzleReverse(Imm);
5655 Error(ModeLoc,
"expected a swizzle mode");
5658 return Ok && skipToken(
AsmToken::RParen,
"expected a closing parentheses");
5666 SMLoc S = Parser.getTok().getLoc();
5669 if (trySkipId(
"offset")) {
5673 if (trySkipId(
"swizzle")) {
5674 Ok = parseSwizzleMacro(Imm);
5676 Ok = parseSwizzleOffset(Imm);
5680 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Imm, S, AMDGPUOperand::ImmTySwizzle));
5686 return parseOptionalOpr(Operands);
5691 AMDGPUOperand::isSwizzle()
const {
5692 return isImmTy(ImmTySwizzle);
5699 int64_t AMDGPUAsmParser::parseGPRIdxMacro() {
5711 SMLoc S = Parser.getTok().getLoc();
5713 for (
unsigned ModeId =
ID_MIN; ModeId <=
ID_MAX; ++ModeId) {
5721 Error(S, (Imm == 0)?
5722 "expected a VGPR index mode or a closing parenthesis" :
5723 "expected a VGPR index mode");
5728 Error(S,
"duplicate VGPR index mode");
5736 "expected a comma or a closing parenthesis"))
5747 SMLoc S = Parser.getTok().getLoc();
5750 Parser.getTok().getString() ==
"gpr_idx" &&
5758 Imm = parseGPRIdxMacro();
5761 if (getParser().parseAbsoluteExpression(Imm))
5763 if (Imm < 0 || !isUInt<4>(Imm)) {
5764 Error(S,
"invalid immediate: only 4-bit values are legal");
5769 AMDGPUOperand::CreateImm(
this, Imm, S, AMDGPUOperand::ImmTyGprIdxMode));
5773 bool AMDGPUOperand::isGPRIdxMode()
const {
5774 return isImmTy(ImmTyGprIdxMode);
5782 AMDGPUAsmParser::parseSOppBrTarget(
OperandVector &Operands) {
5787 if (isRegister() || isModifier())
5790 if (parseExpr(Operands)) {
5792 AMDGPUOperand &Opr = ((AMDGPUOperand &)*Operands[Operands.
size() - 1]);
5793 assert(Opr.isImm() || Opr.isExpr());
5794 SMLoc Loc = Opr.getStartLoc();
5798 if (Opr.isExpr() && !Opr.isSymbolRefExpr()) {
5799 Error(Loc,
"expected an absolute expression or a label");
5800 }
else if (Opr.isImm() && !Opr.isS16Imm()) {
5801 Error(Loc,
"expected a 16-bit signed jump offset");
5814 return parseReg(Operands);
5821 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultDLC()
const {
5822 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyDLC);
5825 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultGLC()
const {
5826 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyGLC);
5829 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultSLC()
const {
5830 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTySLC);
5833 void AMDGPUAsmParser::cvtMubufImpl(
MCInst &Inst,
5836 bool IsAtomicReturn,
5838 bool IsLdsOpcode = IsLds;
5839 bool HasLdsModifier =
false;
5840 OptionalImmIndexMap OptionalIdx;
5841 assert(IsAtomicReturn ? IsAtomic :
true);
5842 unsigned FirstOperandIdx = 1;
5844 for (
unsigned i = FirstOperandIdx,
e = Operands.
size(); i !=
e; ++i) {
5845 AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[i]);
5849 Op.addRegOperands(Inst, 1);
5853 if (IsAtomicReturn && i == FirstOperandIdx)
5854 Op.addRegOperands(Inst, 1);
5859 if (Op.isImm() && Op.getImmTy() == AMDGPUOperand::ImmTyNone) {
5860 Op.addImmOperands(Inst, 1);
5864 HasLdsModifier |= Op.isLDS();
5874 OptionalIdx[Op.getImmTy()] = i;
5884 if (IsLdsOpcode && !HasLdsModifier) {
5886 if (NoLdsOpcode != -1) {
5888 IsLdsOpcode =
false;
5907 OptionalImmIndexMap OptionalIdx;
5909 for (
unsigned i = 1,
e = Operands.
size(); i !=
e; ++i) {
5910 AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[i]);
5914 Op.addRegOperands(Inst, 1);
5919 if (Op.isImm() && Op.getImmTy() == AMDGPUOperand::ImmTyNone) {
5920 Op.addImmOperands(Inst, 1);
5932 OptionalIdx[Op.getImmTy()] = i;
5936 AMDGPUOperand::ImmTyOffset);
5954 for (
unsigned J = 0; J < Desc.
getNumDefs(); ++J) {
5955 ((AMDGPUOperand &)*Operands[I++]).addRegOperands(Inst, 1);
5961 ((AMDGPUOperand &)*Operands[I - 1]).addRegOperands(Inst, 1);
5964 OptionalImmIndexMap OptionalIdx;
5966 for (
unsigned E = Operands.
size(); I !=
E; ++
I) {
5967 AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[I]);
5971 Op.addRegOperands(Inst, 1);
5972 }
else if (Op.isImmModifier()) {
5973 OptionalIdx[Op.getImmTy()] =
I;
5974 }
else if (!Op.isToken()) {
5998 cvtMIMG(Inst, Operands,
true);
6005 bool AMDGPUOperand::isSMRDOffset8()
const {
6009 bool AMDGPUOperand::isSMRDOffset20()
const {
6010 return isImm() && isUInt<20>(getImm());
6013 bool AMDGPUOperand::isSMRDLiteralOffset()
const {
6019 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultSMRDOffset8()
const {
6020 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyOffset);
6023 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultSMRDOffset20()
const {
6024 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyOffset);
6027 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultSMRDLiteralOffset()
const {
6028 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyOffset);
6031 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultFlatOffset()
const {
6032 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyOffset);
6040 if (Mul != 1 && Mul != 2 && Mul != 4)
6062 if (BoundCtrl == 0) {
6067 if (BoundCtrl == -1) {
6077 {
"offen", AMDGPUOperand::ImmTyOffen,
true,
nullptr},
6078 {
"idxen", AMDGPUOperand::ImmTyIdxen,
true,
nullptr},
6079 {
"addr64", AMDGPUOperand::ImmTyAddr64,
true,
nullptr},
6080 {
"offset0", AMDGPUOperand::ImmTyOffset0,
false,
nullptr},
6081 {
"offset1", AMDGPUOperand::ImmTyOffset1,
false,
nullptr},
6082 {
"gds", AMDGPUOperand::ImmTyGDS,
true,
nullptr},
6083 {
"lds", AMDGPUOperand::ImmTyLDS,
true,
nullptr},
6084 {
"offset", AMDGPUOperand::ImmTyOffset,
false,
nullptr},
6085 {
"inst_offset", AMDGPUOperand::ImmTyInstOffset,
false,
nullptr},
6086 {
"dlc", AMDGPUOperand::ImmTyDLC,
true,
nullptr},
6087 {
"format", AMDGPUOperand::ImmTyFORMAT,
false,
nullptr},
6088 {
"glc", AMDGPUOperand::ImmTyGLC,
true,
nullptr},
6089 {
"slc", AMDGPUOperand::ImmTySLC,
true,
nullptr},
6090 {
"swz", AMDGPUOperand::ImmTySWZ,
true,
nullptr},
6091 {
"tfe", AMDGPUOperand::ImmTyTFE,
true,
nullptr},
6092 {
"d16", AMDGPUOperand::ImmTyD16,
true,
nullptr},
6093 {
"high", AMDGPUOperand::ImmTyHigh,
true,
nullptr},
6094 {
"clamp", AMDGPUOperand::ImmTyClampSI,
true,
nullptr},
6096 {
"unorm", AMDGPUOperand::ImmTyUNorm,
true,
nullptr},
6097 {
"da", AMDGPUOperand::ImmTyDA,
true,
nullptr},
6098 {
"r128", AMDGPUOperand::ImmTyR128A16,
true,
nullptr},
6099 {
"a16", AMDGPUOperand::ImmTyR128A16,
true,
nullptr},
6100 {
"lwe", AMDGPUOperand::ImmTyLWE,
true,
nullptr},
6101 {
"d16", AMDGPUOperand::ImmTyD16,
true,
nullptr},
6102 {
"dmask", AMDGPUOperand::ImmTyDMask,
false,
nullptr},
6103 {
"dim", AMDGPUOperand::ImmTyDim,
false,
nullptr},
6104 {
"row_mask", AMDGPUOperand::ImmTyDppRowMask,
false,
nullptr},
6105 {
"bank_mask", AMDGPUOperand::ImmTyDppBankMask,
false,
nullptr},
6107 {
"fi", AMDGPUOperand::ImmTyDppFi,
false,
nullptr},
6108 {
"dst_sel", AMDGPUOperand::ImmTySdwaDstSel,
false,
nullptr},
6109 {
"src0_sel", AMDGPUOperand::ImmTySdwaSrc0Sel,
false,
nullptr},
6110 {
"src1_sel", AMDGPUOperand::ImmTySdwaSrc1Sel,
false,
nullptr},
6111 {
"dst_unused", AMDGPUOperand::ImmTySdwaDstUnused,
false,
nullptr},
6112 {
"compr", AMDGPUOperand::ImmTyExpCompr,
true,
nullptr },
6113 {
"vm", AMDGPUOperand::ImmTyExpVM,
true,
nullptr},
6114 {
"op_sel", AMDGPUOperand::ImmTyOpSel,
false,
nullptr},
6115 {
"op_sel_hi", AMDGPUOperand::ImmTyOpSelHi,
false,
nullptr},
6116 {
"neg_lo", AMDGPUOperand::ImmTyNegLo,
false,
nullptr},
6117 {
"neg_hi", AMDGPUOperand::ImmTyNegHi,
false,
nullptr},
6118 {
"blgp", AMDGPUOperand::ImmTyBLGP,
false,
nullptr},
6119 {
"cbsz", AMDGPUOperand::ImmTyCBSZ,
false,
nullptr},
6120 {
"abid", AMDGPUOperand::ImmTyABID,
false,
nullptr}
6138 for (
unsigned i = 0; i < MAX_OPR_LOOKAHEAD; ++i) {
6144 res = parseOptionalOpr(Operands);
6152 for (
const OptionalOperand &Op : AMDGPUOptionalOperandTable) {
6155 res = parseNamedBit(Op.Name, Operands, Op.Type);
6156 }
else if (Op.Type == AMDGPUOperand::ImmTyOModSI) {
6157 res = parseOModOperand(Operands);
6158 }
else if (Op.Type == AMDGPUOperand::ImmTySdwaDstSel ||
6159 Op.Type == AMDGPUOperand::ImmTySdwaSrc0Sel ||
6160 Op.Type == AMDGPUOperand::ImmTySdwaSrc1Sel) {
6161 res = parseSDWASel(Operands, Op.Name, Op.Type);
6162 }
else if (Op.Type == AMDGPUOperand::ImmTySdwaDstUnused) {
6163 res = parseSDWADstUnused(Operands);
6164 }
else if (Op.Type == AMDGPUOperand::ImmTyOpSel ||
6165 Op.Type == AMDGPUOperand::ImmTyOpSelHi ||
6166 Op.Type == AMDGPUOperand::ImmTyNegLo ||
6167 Op.Type == AMDGPUOperand::ImmTyNegHi) {
6168 res = parseOperandArrayWithPrefix(Op.Name, Operands, Op.Type,
6170 }
else if (Op.Type == AMDGPUOperand::ImmTyDim) {
6171 res = parseDim(Operands);
6172 }
else if (Op.Type == AMDGPUOperand::ImmTyFORMAT && !
isGFX10()) {
6173 res = parseDfmtNfmt(Operands);
6175 res = parseIntWithPrefix(Op.Name, Operands, Op.Type, Op.ConvertResult);
6185 StringRef Name = Parser.getTok().getString();
6186 if (Name ==
"mul") {
6187 return parseIntWithPrefix(
"mul", Operands,
6191 if (Name ==
"div") {
6192 return parseIntWithPrefix(
"div", Operands,
6200 cvtVOP3P(Inst, Operands);
6205 const int Ops[] = { AMDGPU::OpName::src0,
6206 AMDGPU::OpName::src1,
6207 AMDGPU::OpName::src2 };
6216 if ((OpSel & (1 << SrcNum)) != 0) {
6236 OptionalImmIndexMap OptionalIdx;
6241 for (
unsigned J = 0; J < Desc.
getNumDefs(); ++J) {
6242 ((AMDGPUOperand &)*Operands[I++]).addRegOperands(Inst, 1);
6245 for (
unsigned E = Operands.
size(); I !=
E; ++
I) {
6246 AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[I]);
6248 Op.addRegOrImmWithFPInputModsOperands(Inst, 2);
6249 }
else if (Op.isInterpSlot() ||
6250 Op.isInterpAttr() ||
6253 }
else if (Op.isImmModifier()) {
6254 OptionalIdx[Op.getImmTy()] =
I;
6274 OptionalImmIndexMap &OptionalIdx) {
6279 for (
unsigned J = 0; J < Desc.
getNumDefs(); ++J) {
6280 ((AMDGPUOperand &)*Operands[I++]).addRegOperands(Inst, 1);
6285 for (
unsigned E = Operands.
size(); I !=
E; ++
I) {
6286 AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[I]);
6288 Op.addRegOrImmWithFPInputModsOperands(Inst, 2);
6289 }
else if (Op.isImmModifier()) {
6290 OptionalIdx[Op.getImmTy()] =
I;
6291 }
else if (Op.isRegOrImm()) {
6292 Op.addRegOrImmOperands(Inst, 1);
6299 for (
unsigned E = Operands.
size(); I !=
E; ++
I) {
6300 AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[I]);
6302 OptionalIdx[Op.getImmTy()] =
I;
6304 Op.addRegOrImmOperands(Inst, 1);
6321 if (Opc == AMDGPU::V_MAC_F32_e64_gfx6_gfx7 ||
6322 Opc == AMDGPU::V_MAC_F32_e64_gfx10 ||
6323 Opc == AMDGPU::V_MAC_F32_e64_vi ||
6324 Opc == AMDGPU::V_MAC_F16_e64_vi ||
6325 Opc == AMDGPU::V_FMAC_F32_e64_gfx10 ||
6326 Opc == AMDGPU::V_FMAC_F32_e64_vi ||
6327 Opc == AMDGPU::V_FMAC_F16_e64_gfx10) {
6328 auto it = Inst.
begin();
6337 OptionalImmIndexMap OptionalIdx;
6338 cvtVOP3(Inst, Operands, OptionalIdx);
6341 void AMDGPUAsmParser::cvtVOP3P(
MCInst &Inst,
6343 OptionalImmIndexMap OptIdx;
6349 cvtVOP3(Inst, Operands, OptIdx);
6362 if (OpSelHiIdx != -1) {
6363 int DefaultVal = IsPacked ? -1 : 0;
6369 if (NegLoIdx != -1) {
6375 const int Ops[] = { AMDGPU::OpName::src0,
6376 AMDGPU::OpName::src1,
6377 AMDGPU::OpName::src2 };
6378 const int ModOps[] = { AMDGPU::OpName::src0_modifiers,
6379 AMDGPU::OpName::src1_modifiers,
6380 AMDGPU::OpName::src2_modifiers };
6385 unsigned OpSelHi = 0;
6389 if (OpSelHiIdx != -1) {
6393 if (NegLoIdx != -1) {
6399 for (
int J = 0; J < 3; ++J) {
6406 if ((OpSel & (1 << J)) != 0)
6409 if ((OpSelHi & (1 << J)) != 0)
6412 if ((NegLo & (1 << J)) != 0)
6415 if ((NegHi & (1 << J)) != 0)
6428 bool AMDGPUOperand::isDPP8()
const {
6429 return isImmTy(ImmTyDPP8);
6432 bool AMDGPUOperand::isDPPCtrl()
const {
6435 bool result = isImm() && getImmTy() == ImmTyDppCtrl && isUInt<9>(getImm());
6437 int64_t Imm = getImm();
6460 bool AMDGPUOperand::isBLGP()
const {
6461 return isImm() && getImmTy() == ImmTyBLGP && isUInt<3>(getImm());
6464 bool AMDGPUOperand::isCBSZ()
const {
6465 return isImm() && getImmTy() == ImmTyCBSZ && isUInt<3>(getImm());
6468 bool AMDGPUOperand::isABID()
const {
6469 return isImm() && getImmTy() == ImmTyABID && isUInt<4>(getImm());
6472 bool AMDGPUOperand::isS16Imm()
const {
6476 bool AMDGPUOperand::isU16Imm()
const {
6484 SMLoc S = Parser.getTok().getLoc();
6488 if (getLexer().getTok().getString() !=
"dim")
6501 SMLoc Loc = getLexer().getTok().getEndLoc();
6502 Token = getLexer().getTok().getString();
6504 if (getLexer().getTok().getLoc() != Loc)
6509 Token += getLexer().getTok().getString();
6513 DimId = DimId.
substr(12);
6521 Operands.
push_back(AMDGPUOperand::CreateImm(
this, DimInfo->Encoding, S,
6522 AMDGPUOperand::ImmTyDim));
6527 SMLoc S = Parser.getTok().getLoc();
6531 Prefix = Parser.getTok().getString();
6536 if (Prefix !=
"dpp8")
6537 return parseDPPCtrl(Operands);
6554 if (getParser().parseAbsoluteExpression(Sels[0]))
6556 if (0 > Sels[0] || 7 < Sels[0])
6559 for (
size_t i = 1; i < 8; ++i) {
6564 if (getParser().parseAbsoluteExpression(Sels[i]))
6566 if (0 > Sels[i] || 7 < Sels[i])
6575 for (
size_t i = 0; i < 8; ++i)
6576 DPP8 |= (Sels[i] << (i * 3));
6578 Operands.
push_back(AMDGPUOperand::CreateImm(
this, DPP8, S, AMDGPUOperand::ImmTyDPP8));
6586 SMLoc S = Parser.getTok().getLoc();
6591 Prefix = Parser.getTok().getString();
6596 if (Prefix ==
"row_mirror") {
6599 }
else if (Prefix ==
"row_half_mirror") {
6604 if (Prefix !=
"quad_perm" 6605 && Prefix !=
"row_shl" 6606 && Prefix !=
"row_shr" 6607 && Prefix !=
"row_ror" 6608 && Prefix !=
"wave_shl" 6609 && Prefix !=
"wave_rol" 6610 && Prefix !=
"wave_shr" 6611 && Prefix !=
"wave_ror" 6612 && Prefix !=
"row_bcast" 6613 && Prefix !=
"row_share" 6614 && Prefix !=
"row_xmask") {
6618 if (!
isGFX10() && (Prefix ==
"row_share" || Prefix ==
"row_xmask"))
6622 (Prefix ==
"wave_shl" || Prefix ==
"wave_shr" ||
6623 Prefix ==
"wave_rol" || Prefix ==
"wave_ror" ||
6624 Prefix ==
"row_bcast"))
6631 if (Prefix ==
"quad_perm") {
6638 if (getParser().parseAbsoluteExpression(Int) || !(0 <= Int && Int <=3))
6641 for (
int i = 0; i < 3; ++i) {
6647 if (getParser().parseAbsoluteExpression(Temp) || !(0 <= Temp && Temp <=3))
6649 const int shift = i*2 + 2;
6650 Int += (Temp << shift);
6659 if (getParser().parseAbsoluteExpression(Int))
6662 if (Prefix ==
"row_shl" && 1 <= Int && Int <= 15) {
6664 }
else if (Prefix ==
"row_shr" && 1 <= Int && Int <= 15) {
6666 }
else if (Prefix ==
"row_ror" && 1 <= Int && Int <= 15) {
6668 }
else if (Prefix ==
"wave_shl" && 1 == Int) {
6670 }
else if (Prefix ==
"wave_rol" && 1 == Int) {
6672 }
else if (Prefix ==
"wave_shr" && 1 == Int) {
6674 }
else if (Prefix ==
"wave_ror" && 1 == Int) {
6676 }
else if (Prefix ==
"row_bcast") {
6679 }
else if (Int == 31) {
6684 }
else if (Prefix ==
"row_share" && 0 <= Int && Int <= 15) {
6686 }
else if (Prefix ==
"row_xmask" && 0 <= Int && Int <= 15) {
6694 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Int, S, AMDGPUOperand::ImmTyDppCtrl));
6698 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultRowMask()
const {
6699 return AMDGPUOperand::CreateImm(
this, 0xf,
SMLoc(), AMDGPUOperand::ImmTyDppRowMask);
6702 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultEndpgmImmOperands()
const {
6703 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyEndpgm);
6706 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultBankMask()
const {
6707 return AMDGPUOperand::CreateImm(
this, 0xf,
SMLoc(), AMDGPUOperand::ImmTyDppBankMask);
6710 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultBoundCtrl()
const {
6711 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyDppBoundCtrl);
6714 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultFI()
const {
6715 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyDppFi);
6719 OptionalImmIndexMap OptionalIdx;
6723 for (
unsigned J = 0; J < Desc.
getNumDefs(); ++J) {
6724 ((AMDGPUOperand &)*Operands[I++]).addRegOperands(Inst, 1);
6728 for (
unsigned E = Operands.
size(); I !=
E; ++
I) {
6736 AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[I]);
6738 if (Op.isReg() && validateVccOperand(Op.getReg())) {
6746 Op.addImmOperands(Inst, 1);
6748 Op.addRegWithFPInputModsOperands(Inst, 2);
6749 }
else if (Op.isFI()) {
6751 }
else if (Op.isReg()) {
6752 Op.addRegOperands(Inst, 1);
6758 Op.addRegWithFPInputModsOperands(Inst, 2);
6759 }
else if (Op.isDPPCtrl()) {
6760 Op.addImmOperands(Inst, 1);
6761 }
else if (Op.isImm()) {
6763 OptionalIdx[Op.getImmTy()] =
I;
6789 AMDGPUOperand::ImmTy Type) {
6792 SMLoc S = Parser.getTok().getLoc();
6796 res = parseStringWithPrefix(Prefix, Value);
6813 if (Int == 0xffffffff) {
6817 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Int, S, Type));
6822 AMDGPUAsmParser::parseSDWADstUnused(
OperandVector &Operands) {
6825 SMLoc S = Parser.getTok().getLoc();
6829 res = parseStringWithPrefix(
"dst_unused", Value);
6842 if (Int == 0xffffffff) {
6846 Operands.
push_back(AMDGPUOperand::CreateImm(
this, Int, S, AMDGPUOperand::ImmTySdwaDstUnused));
6871 uint64_t BasicInstType,
6876 OptionalImmIndexMap OptionalIdx;
6877 bool SkipVcc = SkipDstVcc || SkipSrcVcc;
6878 bool SkippedVcc =
false;
6882 for (
unsigned J = 0; J < Desc.
getNumDefs(); ++J) {
6883 ((AMDGPUOperand &)*Operands[I++]).addRegOperands(Inst, 1);
6886 for (
unsigned E = Operands.
size(); I !=
E; ++
I) {
6887 AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[I]);
6888 if (SkipVcc && !SkippedVcc && Op.isReg() &&
6889 (Op.getReg() == AMDGPU::VCC || Op.getReg() == AMDGPU::VCC_LO)) {
6907 Op.addRegOrImmWithInputModsOperands(Inst, 2);
6908 }
else if (Op.isImm()) {
6910 OptionalIdx[Op.getImmTy()] =
I;
6917 if (Inst.
getOpcode() != AMDGPU::V_NOP_sdwa_gfx10 &&
6918 Inst.
getOpcode() != AMDGPU::V_NOP_sdwa_gfx9 &&
6919 Inst.
getOpcode() != AMDGPU::V_NOP_sdwa_vi) {
6921 switch (BasicInstType) {
6951 llvm_unreachable(
"Invalid instruction type. Only VOP1, VOP2 and VOPC allowed");
6957 if (Inst.
getOpcode() == AMDGPU::V_MAC_F32_sdwa_vi ||
6958 Inst.
getOpcode() == AMDGPU::V_MAC_F16_sdwa_vi) {
6959 auto it = Inst.
begin();
6970 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultBLGP()
const {
6971 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyBLGP);
6974 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultCBSZ()
const {
6975 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyCBSZ);
6978 AMDGPUOperand::Ptr AMDGPUAsmParser::defaultABID()
const {
6979 return AMDGPUOperand::CreateImm(
this, 0,
SMLoc(), AMDGPUOperand::ImmTyABID);
6988 #define GET_REGISTER_MATCHER 6989 #define GET_MATCHER_IMPLEMENTATION 6990 #define GET_MNEMONIC_SPELL_CHECKER 6991 #include "AMDGPUGenAsmMatcher.inc" 7001 AMDGPUOperand &Operand = (AMDGPUOperand&)Op;
7004 return Operand.isAddr64() ? Match_Success : Match_InvalidOperand;
7006 return Operand.isGDS() ? Match_Success : Match_InvalidOperand;
7008 return Operand.isLDS() ? Match_Success : Match_InvalidOperand;
7010 return Operand.isGLC() ? Match_Success : Match_InvalidOperand;
7012 return Operand.isIdxen() ? Match_Success : Match_InvalidOperand;
7014 return Operand.isOffen() ? Match_Success : Match_InvalidOperand;
7022 return Operand.isSSrcB32() ? Match_Success : Match_InvalidOperand;
7024 return Operand.isSSrcF32() ? Match_Success : Match_InvalidOperand;
7025 case MCK_SoppBrTarget:
7026 return Operand.isSoppBrTarget() ? Match_Success : Match_InvalidOperand;
7027 case MCK_VReg32OrOff:
7028 return Operand.isVReg32OrOff() ? Match_Success : Match_InvalidOperand;
7029 case MCK_InterpSlot:
7030 return Operand.isInterpSlot() ? Match_Success : Match_InvalidOperand;
7032 return Operand.isInterpAttr() ? Match_Success : Match_InvalidOperand;
7034 return Operand.isAttrChan() ? Match_Success : Match_InvalidOperand;
7036 case MCK_SReg_64_XEXEC:
7042 return Operand.isNull() ? Match_Success : Match_InvalidOperand;
7044 return Match_InvalidOperand;
7053 SMLoc S = Parser.getTok().getLoc();
7056 if (!parseExpr(Imm)) {
7062 Error(S,
"expected a 16-bit value");
7067 AMDGPUOperand::CreateImm(
this, Imm, S, AMDGPUOperand::ImmTyEndpgm));
7071 bool AMDGPUOperand::isEndpgm()
const {
return isImmTy(ImmTyEndpgm); }
static bool isReg(const MCInst &MI, unsigned OpNo)
static const RegInfo * getRegularRegInfo(StringRef Str)
unsigned getNumImplicitUses() const
Return the number of implicit uses this instruction has.
constexpr bool isUInt< 32 >(uint64_t x)
Represents a range in source code.
unsigned mc2PseudoReg(unsigned Reg)
Convert hardware register Reg to a pseudo register.
Target & getTheGCNTarget()
The target for GCN GPUs.
bool hasPackedD16(const MCSubtargetInfo &STI)
int64_t getHwregId(const StringRef Name)
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
uint64_t encodeHwreg(uint64_t Id, uint64_t Offset, uint64_t Width)
static bool isRegOrImmWithInputMods(const MCInstrDesc &Desc, unsigned OpNum)
uint64_t getZExtValue() const
Get zero extended value.
static const fltSemantics * getOpFltSemantics(uint8_t OperandType)
#define G_00B848_FWD_PROGRESS(x)
LLVM_READONLY const MIMGInfo * getMIMGInfo(unsigned Opc)
LLVM_NODISCARD bool endswith(StringRef Suffix) const
Check if this string ends with the given Suffix.
This class represents lattice values for constants.
bool isVariable() const
isVariable - Check if this is a variable symbol.
bool isValidHwregWidth(int64_t Width)
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
unsigned encode(MaybeAlign A)
Returns a representation of the alignment that encodes undefined as 0.
void redefineIfPossible()
Prepare this symbol to be redefined.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
constexpr char AssemblerDirectiveBegin[]
HSA metadata beginning assembler directive.
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.
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
void push_back(const T &Elt)
Represents the counter values to wait for in an s_waitcnt instruction.
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
Describe properties that are true of each instruction in the target description file.
static bool encodeCnt(const AMDGPU::IsaVersion ISA, int64_t &IntVal, int64_t CntVal, bool Saturate, unsigned(*encode)(const IsaVersion &Version, unsigned, unsigned), unsigned(*decode)(const IsaVersion &Version, unsigned))
static bool isSafeTruncation(int64_t Val, unsigned Size)
uint64_t encodeMsg(uint64_t MsgId, uint64_t OpId, uint64_t StreamId)
Instruction set architecture version.
iterator find(StringRef Key)
static unsigned getSpecialRegForName(StringRef RegName)
unsigned decodeVmcnt(const IsaVersion &Version, unsigned Waitcnt)
A raw_ostream that writes to an SmallVector or SmallString.
constexpr bool isInt< 16 >(int64_t x)
unsigned const TargetRegisterInfo * TRI
#define G_00B848_MEM_ORDERED(x)
bool isInlinableLiteralV216(int32_t Literal, bool HasInv2Pi)
Expected< opStatus > convertFromString(StringRef, roundingMode)
bool isValidHwreg(int64_t Id, const MCSubtargetInfo &STI)
unsigned encodeVmcnt(const IsaVersion &Version, unsigned Waitcnt, unsigned Vmcnt)
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.
bool isValidMsgOp(int64_t MsgId, int64_t OpId, bool Strict)
unsigned decodeExpcnt(const IsaVersion &Version, unsigned Waitcnt)
static bool ConvertOmodDiv(int64_t &Div)
virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI)
Emit the given Instruction into the current section.
bool parseAmdKernelCodeField(StringRef ID, MCAsmParser &Parser, amd_kernel_code_t &C, raw_ostream &Err)
StringSwitch & Case(StringLiteral S, T Value)
static LLVM_READNONE unsigned encodeBitmaskPerm(const unsigned AndMask, const unsigned OrMask, const unsigned XorMask)
static bool isInlineValue(unsigned Reg)
bool isInlinableLiteral16(int16_t Literal, bool HasInv2Pi)
LLVM_READONLY int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIdx)
uint32_t code_properties
Code properties.
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...
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
int64_t getMsgId(const StringRef Name)
LLVM_NODISCARD StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
AMD Kernel Code Object (amd_kernel_code_t).
unsigned getLocalMemorySize(const MCSubtargetInfo *STI)
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...
LLVM_NODISCARD StringRef take_back(size_t N=1) const
Return a StringRef equal to 'this' but with only the last N elements remaining.
Base class for the full range of assembler expressions which are needed for parsing.
LLVM_NODISCARD R Default(T Value)
Target independent representation for an assembler token.
static int getRegClass(RegisterKind Is, unsigned RegWidth)
LLVM_READONLY const MIMGDimInfo * getMIMGDimInfoByAsmSuffix(StringRef AsmSuffix)
Represent a reference to a symbol from inside an expression.
uint32_t compute_pgm_rsrc2
LLVM_READONLY const MIMGDimInfo * getMIMGDimInfoByEncoding(uint8_t DimEnc)
mir Rename Register Operands
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
static bool isMem(const MachineInstr &MI, unsigned Op)
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)
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.
uint32_t group_segment_fixed_size
constexpr bool test(unsigned I) const
RegisterMCAsmParser - Helper template for registering a target specific assembly parser, for use in the target machine initialization function.
unsigned getNumExtraSGPRs(const MCSubtargetInfo *STI, bool VCCUsed, bool FlatScrUsed, bool XNACKUsed)
unsigned getRegister(unsigned i) const
getRegister - Return the specified register in the class.
#define PARSE_BITS_ENTRY(FIELD, ENTRY, VALUE, RANGE)
LLVM_NODISCARD size_t size() const
size - Get the string size.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
unsigned encodeExpcnt(const IsaVersion &Version, unsigned Waitcnt, unsigned Expcnt)
LLVM_READONLY const MIMGBaseOpcodeInfo * getMIMGBaseOpcodeInfo(unsigned BaseOpcode)
static const fltSemantics & IEEEdouble() LLVM_READNONE
unsigned decodeLgkmcnt(const IsaVersion &Version, unsigned Waitcnt)
uint16_t kernel_code_properties
MCRegisterClass - Base class of TargetRegisterClass.
static std::string AMDGPUMnemonicSpellCheck(StringRef S, const FeatureBitset &FBS, unsigned VariantID=0)
iterator insert(iterator I, const MCOperand &Op)
uint64_t compute_pgm_resource_registers
Shader program settings for CS.
Analysis containing CSE Info
Instances of this class represent a single low-level machine instruction.
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false)
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?
A switch()-like statement whose cases are string literals.
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
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.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
bool isGFX10(const MCSubtargetInfo &STI)
The instances of the Type class are immutable: once they are created, they are never changed...
size_t size() const
size - Get the array size.
bool errorToBool(Error Err)
Helper for converting an Error to a bool.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const char *const IdSymbolic[]
std::pair< iterator, bool > insert(const ValueT &V)
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...
#define G_00B848_WGP_MODE(x)
bool isValidHwregOffset(int64_t Offset)
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
unsigned getNumOperands() const
static const OptionalOperand AMDGPUOptionalOperandTable[]
constexpr char AssemblerDirectiveEnd[]
HSA metadata ending assembler directive.
static bool IsRevOpcode(const unsigned Opcode)
constexpr char AssemblerDirective[]
PAL metadata (old linear format) assembler directive.
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
constexpr char AssemblerDirectiveEnd[]
PAL metadata (new MsgPack format) ending assembler directive.
#define AMDHSA_BITS_SET(DST, MSK, VAL)
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.
This struct is a compact representation of a valid (non-zero power of two) alignment.
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.
IsaVersion getIsaVersion(StringRef GPU)
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.
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.
LLVM_READONLY int getMUBUFNoLdsInst(uint16_t Opcode)
testing::Matcher< const detail::ErrorHolder & > Failed()
const MCSymbol & getSymbol() const
bool isUndefined(bool SetUsed=true) const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
unsigned getAddressableNumSGPRs(const MCSubtargetInfo *STI)
Operands with register or 32-bit immediate.
const MCOperand & getOperand(unsigned i) const
bool isValidMsgStream(int64_t MsgId, int64_t OpId, int64_t StreamId, bool Strict)
Promote Memory to Register
static bool ConvertOmodMul(int64_t &Mul)
constexpr char AssemblerDirectiveBegin[]
PAL metadata (new MsgPack format) beginning assembler directive.
TypeSize getScalarSizeInBits() const
StringRef str()
Return a StringRef for the vector contents.
uint8_t wavefront_size
Wavefront size expressed as a power of two.
#define LLVM_EXTERNAL_VISIBILITY
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
int64_t getMsgOpId(int64_t MsgId, const StringRef Name)
void setVariableValue(const MCExpr *Value)
Implements a dense probed hash-table based set with some number of buckets stored inline...
bool msgSupportsStream(int64_t MsgId, int64_t OpId)
bool is(TokenKind K) const
Target - Wrapper for Target specific information.
Class for arbitrary precision integers.
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
bool msgRequiresOp(int64_t MsgId)
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.
unsigned getNumVGPRBlocks(const MCSubtargetInfo *STI, unsigned NumVGPRs, Optional< bool > EnableWavefrontSize32)
iterator insert(iterator I, T &&Elt)
bool isCI(const MCSubtargetInfo &STI)
static SMLoc getFromPointer(const char *Ptr)
uint32_t compute_pgm_rsrc1
bool isGFX9(const MCSubtargetInfo &STI)
Provides AMDGPU specific target descriptions.
amdhsa::kernel_descriptor_t getDefaultAmdhsaKernelDescriptor(const MCSubtargetInfo *STI)
Interface definition for SIInstrInfo.
constexpr char AssemblerDirectiveEnd[]
HSA metadata ending assembler directive.
static bool canLosslesslyConvertToFPType(APFloat &FPLiteral, MVT VT)
bool isVI(const MCSubtargetInfo &STI)
unsigned getNumSGPRBlocks(const MCSubtargetInfo *STI, unsigned NumSGPRs)
int16_t RegClass
This specifies the register class enumeration of the operand if the operand is a register.
bool hasXNACK(const MCSubtargetInfo &STI)
unsigned getWaitcntBitMask(const IsaVersion &Version)
Operands with register or inline constant.
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
constexpr bool isUInt< 16 >(uint64_t x)
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUAsmParser()
Force static initialization.
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?
static StringRef getCPU(StringRef CPU)
Processes a CPU name.
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
static llvm::Expected< InlineInfo > decode(DataExtractor &Data, uint64_t &Offset, uint64_t BaseAddr)
Decode an InlineInfo in Data at the specified offset.
static bool IsMovrelsSDWAOpcode(const unsigned Opcode)
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.
LLVM_NODISCARD StringRef drop_back(size_t N=1) const
Return a StringRef equal to 'this' but with the last N elements dropped.
Lightweight error class with error context and mandatory checking.
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.
static bool isValidMsgId(int64_t MsgId)
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)
static bool getRegNum(StringRef Str, unsigned &Num)
static constexpr RegInfo RegularRegisters[]
void addOperand(const MCOperand &Op)
StringRef - Represent a constant reference to a string, i.e.
APInt bitcastToAPInt() const
static bool isRegularReg(RegisterKind Kind)
bool isSGPR(unsigned Reg, const MCRegisterInfo *TRI)
Is Reg - scalar register.
Operands with an AccVGPR register or inline constant.
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.
void initDefaultAMDKernelCodeT(amd_kernel_code_t &Header, const MCSubtargetInfo *STI)
static MCOperand createImm(int64_t Val)
unsigned encodeLgkmcnt(const IsaVersion &Version, unsigned Waitcnt, unsigned Lgkmcnt)
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
TokenKind getKind() const