86 static PrefixInfo CreateFromInst(
const MCInst &Inst, uint64_t TSFlags) {
89 case AArch64::MOVPRFX_ZZ:
93 case AArch64::MOVPRFX_ZPmZ_B:
94 case AArch64::MOVPRFX_ZPmZ_H:
95 case AArch64::MOVPRFX_ZPmZ_S:
96 case AArch64::MOVPRFX_ZPmZ_D:
98 Prefix.Predicated =
true;
101 "No destructive element size set for movprfx");
105 case AArch64::MOVPRFX_ZPzZ_B:
106 case AArch64::MOVPRFX_ZPzZ_H:
107 case AArch64::MOVPRFX_ZPzZ_S:
108 case AArch64::MOVPRFX_ZPzZ_D:
109 Prefix.Active =
true;
110 Prefix.Predicated =
true;
113 "No destructive element size set for movprfx");
124 PrefixInfo() : Active(
false), Predicated(
false) {}
125 bool isActive()
const {
return Active; }
127 unsigned getElementSize()
const {
131 unsigned getDstReg()
const {
return Dst; }
132 unsigned getPgReg()
const {
140 unsigned ElementSize;
150 SMLoc getLoc()
const {
return getParser().getTok().getLoc(); }
155 bool parseCondCode(
OperandVector &Operands,
bool invertCondCode);
158 bool parseSymbolicImmVal(
const MCExpr *&ImmVal);
162 bool invertCondCode);
164 bool showMatchError(
SMLoc Loc,
unsigned ErrCode, uint64_t
ErrorInfo,
167 bool parseDirectiveArch(
SMLoc L);
168 bool parseDirectiveArchExtension(
SMLoc L);
169 bool parseDirectiveCPU(
SMLoc L);
170 bool parseDirectiveInst(
SMLoc L);
172 bool parseDirectiveTLSDescCall(
SMLoc L);
175 bool parseDirectiveLtorg(
SMLoc L);
178 bool parseDirectiveUnreq(
SMLoc L);
179 bool parseDirectiveCFINegateRAState();
180 bool parseDirectiveCFIBKeyFrame();
182 bool validateInstruction(
MCInst &Inst,
SMLoc &IDLoc,
184 bool MatchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
187 bool MatchingInlineAsm)
override;
191 #define GET_ASSEMBLER_HEADER 192 #include "AArch64GenAsmMatcher.inc" 204 template <
bool IsSVEPrefetch = false>
210 template<
bool AddFPZeroAsLiteral>
217 template <
bool ParseShiftExtend,
220 template <
bool ParseShiftExtend,
bool ParseSuffix>
223 template <RegKind VectorKind>
225 bool ExpectMatch =
false);
229 enum AArch64MatchResultTy {
230 Match_InvalidSuffix = FIRST_TARGET_MATCH_RESULT_TY,
231 #define GET_OPERAND_DIAGNOSTIC_TYPES 232 #include "AArch64GenAsmMatcher.inc" 255 setAvailableFeatures(ComputeAvailableFeatures(getSTI().getFeatureBits()));
262 bool ParseRegister(
unsigned &RegNo,
SMLoc &StartLoc,
SMLoc &EndLoc)
override;
263 bool ParseDirective(
AsmToken DirectiveID)
override;
265 unsigned Kind)
override;
267 static bool classifySymbolRef(
const MCExpr *Expr,
295 SMLoc StartLoc, EndLoc;
304 struct ShiftExtendOp {
307 bool HasExplicitAmount;
333 ShiftExtendOp ShiftExtend;
336 struct VectorListOp {
339 unsigned NumElements;
340 unsigned ElementWidth;
344 struct VectorIndexOp {
352 struct ShiftedImmOp {
354 unsigned ShiftAmount;
409 struct VectorListOp VectorList;
410 struct VectorIndexOp VectorIndex;
412 struct ShiftedImmOp ShiftedImm;
413 struct CondCodeOp CondCode;
414 struct FPImmOp FPImm;
415 struct BarrierOp Barrier;
416 struct SysRegOp SysReg;
417 struct SysCRImmOp SysCRImm;
418 struct PrefetchOp Prefetch;
419 struct PSBHintOp PSBHint;
420 struct BTIHintOp BTIHint;
421 struct ShiftExtendOp ShiftExtend;
429 AArch64Operand(KindTy K,
MCContext &Ctx) :
Kind(K), Ctx(Ctx) {}
433 StartLoc = o.StartLoc;
443 ShiftedImm = o.ShiftedImm;
458 VectorList = o.VectorList;
461 VectorIndex = o.VectorIndex;
467 SysCRImm = o.SysCRImm;
479 ShiftExtend = o.ShiftExtend;
485 SMLoc getStartLoc()
const override {
return StartLoc; }
487 SMLoc getEndLoc()
const override {
return EndLoc; }
490 assert(Kind == k_Token &&
"Invalid access!");
494 bool isTokenSuffix()
const {
495 assert(Kind == k_Token &&
"Invalid access!");
499 const MCExpr *getImm()
const {
500 assert(Kind == k_Immediate &&
"Invalid access!");
504 const MCExpr *getShiftedImmVal()
const {
505 assert(Kind == k_ShiftedImm &&
"Invalid access!");
506 return ShiftedImm.Val;
509 unsigned getShiftedImmShift()
const {
510 assert(Kind == k_ShiftedImm &&
"Invalid access!");
511 return ShiftedImm.ShiftAmount;
515 assert(Kind == k_CondCode &&
"Invalid access!");
520 assert (Kind == k_FPImm &&
"Invalid access!");
524 bool getFPImmIsExact()
const {
525 assert (Kind == k_FPImm &&
"Invalid access!");
526 return FPImm.IsExact;
529 unsigned getBarrier()
const {
530 assert(Kind == k_Barrier &&
"Invalid access!");
535 assert(Kind == k_Barrier &&
"Invalid access!");
539 unsigned getReg()
const override {
540 assert(Kind == k_Register &&
"Invalid access!");
545 assert(Kind == k_Register &&
"Invalid access!");
546 return Reg.EqualityTy;
549 unsigned getVectorListStart()
const {
550 assert(Kind == k_VectorList &&
"Invalid access!");
551 return VectorList.RegNum;
554 unsigned getVectorListCount()
const {
555 assert(Kind == k_VectorList &&
"Invalid access!");
556 return VectorList.Count;
559 unsigned getVectorIndex()
const {
560 assert(Kind == k_VectorIndex &&
"Invalid access!");
561 return VectorIndex.Val;
565 assert(Kind == k_SysReg &&
"Invalid access!");
566 return StringRef(SysReg.Data, SysReg.Length);
569 unsigned getSysCR()
const {
570 assert(Kind == k_SysCR &&
"Invalid access!");
574 unsigned getPrefetch()
const {
575 assert(Kind == k_Prefetch &&
"Invalid access!");
579 unsigned getPSBHint()
const {
580 assert(Kind == k_PSBHint &&
"Invalid access!");
585 assert(Kind == k_PSBHint &&
"Invalid access!");
586 return StringRef(PSBHint.Data, PSBHint.Length);
589 unsigned getBTIHint()
const {
590 assert(Kind == k_BTIHint &&
"Invalid access!");
595 assert(Kind == k_BTIHint &&
"Invalid access!");
596 return StringRef(BTIHint.Data, BTIHint.Length);
600 assert(Kind == k_Prefetch &&
"Invalid access!");
605 if (Kind == k_ShiftExtend)
606 return ShiftExtend.Type;
607 if (Kind == k_Register)
608 return Reg.ShiftExtend.Type;
612 unsigned getShiftExtendAmount()
const {
613 if (Kind == k_ShiftExtend)
614 return ShiftExtend.Amount;
615 if (Kind == k_Register)
616 return Reg.ShiftExtend.Amount;
620 bool hasShiftExtendAmount()
const {
621 if (Kind == k_ShiftExtend)
622 return ShiftExtend.HasExplicitAmount;
623 if (Kind == k_Register)
624 return Reg.ShiftExtend.HasExplicitAmount;
628 bool isImm()
const override {
return Kind == k_Immediate; }
629 bool isMem()
const override {
return false; }
631 bool isUImm6()
const {
638 return (Val >= 0 && Val < 64);
641 template <
int W
idth>
bool isSImm()
const {
return isSImmScaled<Width, 1>(); }
644 return isImmScaled<Bits, Scale>(
true);
648 return isImmScaled<Bits, Scale>(
false);
651 template <
int Bits,
int Scale>
660 int64_t MinVal, MaxVal;
662 int64_t Shift =
Bits - 1;
663 MinVal = (int64_t(1) << Shift) * -Scale;
664 MaxVal = ((int64_t(1) << Shift) - 1) * Scale;
667 MaxVal = ((int64_t(1) <<
Bits) - 1) * Scale;
671 if (Val >= MinVal && Val <= MaxVal && (Val % Scale) == 0)
683 int64_t Val = MCE->getValue();
684 if (Val >= 0 && Val < 32)
689 bool isSymbolicUImm12Offset(
const MCExpr *Expr)
const {
693 if (!AArch64AsmParser::classifySymbolRef(Expr, ELFRefKind, DarwinRefKind,
724 template <
int Scale>
bool isUImm12Offset()
const {
730 return isSymbolicUImm12Offset(getImm());
733 return (Val % Scale) == 0 && Val >= 0 && (Val / Scale) < 0x1000;
736 template <
int N,
int M>
737 bool isImmInRange()
const {
744 return (Val >=
N && Val <= M);
749 template <
typename T>
750 bool isLogicalImm()
const {
758 int64_t SVal =
typename std::make_signed<T>::type(Val);
759 int64_t UVal =
typename std::make_unsigned<T>::type(Val);
760 if (Val != SVal && Val != UVal)
766 bool isShiftedImm()
const {
return Kind == k_ShiftedImm; }
771 template <
unsigned W
idth>
773 if (isShiftedImm() &&
Width == getShiftedImmShift())
774 if (
auto *CE = dyn_cast<MCConstantExpr>(getShiftedImmVal()))
775 return std::make_pair(CE->getValue(),
Width);
778 if (
auto *CE = dyn_cast<MCConstantExpr>(getImm())) {
779 int64_t Val = CE->getValue();
780 if ((Val != 0) && (uint64_t(Val >>
Width) <<
Width) == uint64_t(Val))
783 return std::make_pair(Val, 0u);
789 bool isAddSubImm()
const {
790 if (!isShiftedImm() && !isImm())
796 if (isShiftedImm()) {
797 unsigned Shift = ShiftedImm.ShiftAmount;
798 Expr = ShiftedImm.Val;
799 if (Shift != 0 && Shift != 12)
808 if (AArch64AsmParser::classifySymbolRef(Expr, ELFRefKind,
809 DarwinRefKind, Addend)) {
826 if (
auto ShiftedVal = getShiftedVal<12>())
827 return ShiftedVal->first >= 0 && ShiftedVal->first <= 0xfff;
834 bool isAddSubImmNeg()
const {
835 if (!isShiftedImm() && !isImm())
839 if (
auto ShiftedVal = getShiftedVal<12>())
840 return ShiftedVal->first < 0 && -ShiftedVal->first <= 0xfff;
850 template <
typename T>
852 if (!isShiftedImm() && (!isImm() || !isa<MCConstantExpr>(getImm())))
856 std::is_same<int8_t, typename std::make_signed<T>::type>::value;
857 if (
auto ShiftedImm = getShiftedVal<8>())
858 if (!(IsByte && ShiftedImm->second) &&
859 AArch64_AM::isSVECpyImm<T>(uint64_t(ShiftedImm->first)
860 << ShiftedImm->second))
870 if (!isShiftedImm() && (!isImm() || !isa<MCConstantExpr>(getImm())))
874 std::is_same<int8_t, typename std::make_signed<T>::type>::value;
875 if (
auto ShiftedImm = getShiftedVal<8>())
876 if (!(IsByte && ShiftedImm->second) &&
877 AArch64_AM::isSVEAddSubImm<T>(ShiftedImm->first
878 << ShiftedImm->second))
885 if (isLogicalImm<T>() && !isSVECpyImm<T>())
890 bool isCondCode()
const {
return Kind == k_CondCode; }
892 bool isSIMDImmType10()
const {
902 bool isBranchTarget()
const {
911 assert(
N > 0 &&
"Branch target immediate cannot be 0 bits!");
912 return (Val >= -((1<<(
N-1)) << 2) && Val <= (((1<<(
N-1))-1) << 2));
923 if (!AArch64AsmParser::classifySymbolRef(getImm(), ELFRefKind,
924 DarwinRefKind, Addend)) {
930 for (
unsigned i = 0; i != AllowedModifiers.
size(); ++i) {
931 if (ELFRefKind == AllowedModifiers[i])
938 bool isMovWSymbolG3()
const {
942 bool isMovWSymbolG2()
const {
950 bool isMovWSymbolG1()
const {
959 bool isMovWSymbolG0()
const {
968 template<
int RegW
idth,
int Shift>
970 if (!isImm())
return false;
973 if (!CE)
return false;
979 template<
int RegW
idth,
int Shift>
981 if (!isImm())
return false;
984 if (!CE)
return false;
990 bool isFPImm()
const {
991 return Kind == k_FPImm &&
995 bool isBarrier()
const {
return Kind == k_Barrier; }
996 bool isSysReg()
const {
return Kind == k_SysReg; }
998 bool isMRSSystemRegister()
const {
999 if (!isSysReg())
return false;
1001 return SysReg.MRSReg != -1U;
1004 bool isMSRSystemRegister()
const {
1005 if (!isSysReg())
return false;
1006 return SysReg.MSRReg != -1U;
1009 bool isSystemPStateFieldWithImm0_1()
const {
1010 if (!isSysReg())
return false;
1011 return (SysReg.PStateField == AArch64PState::PAN ||
1012 SysReg.PStateField == AArch64PState::DIT ||
1013 SysReg.PStateField == AArch64PState::UAO ||
1014 SysReg.PStateField == AArch64PState::SSBS);
1017 bool isSystemPStateFieldWithImm0_15()
const {
1018 if (!isSysReg() || isSystemPStateFieldWithImm0_1())
return false;
1019 return SysReg.PStateField != -1U;
1022 bool isReg()
const override {
1023 return Kind == k_Register;
1026 bool isScalarReg()
const {
1030 bool isNeonVectorReg()
const {
1031 return Kind == k_Register &&
Reg.Kind == RegKind::NeonVector;
1034 bool isNeonVectorRegLo()
const {
1035 return Kind == k_Register &&
Reg.Kind == RegKind::NeonVector &&
1036 AArch64MCRegisterClasses[AArch64::FPR128_loRegClassID].contains(
1040 template <
unsigned Class>
bool isSVEVectorReg()
const {
1043 case AArch64::ZPRRegClassID:
1044 case AArch64::ZPR_3bRegClassID:
1045 case AArch64::ZPR_4bRegClassID:
1046 RK = RegKind::SVEDataVector;
1048 case AArch64::PPRRegClassID:
1049 case AArch64::PPR_3bRegClassID:
1050 RK = RegKind::SVEPredicateVector;
1056 return (Kind == k_Register &&
Reg.Kind == RK) &&
1057 AArch64MCRegisterClasses[
Class].contains(
getReg());
1060 template <
unsigned Class>
bool isFPRasZPR()
const {
1062 AArch64MCRegisterClasses[
Class].contains(
getReg());
1065 template <
int ElementW
idth,
unsigned Class>
1067 if (Kind != k_Register ||
Reg.Kind != RegKind::SVEPredicateVector)
1070 if (isSVEVectorReg<Class>() && (
Reg.ElementWidth == ElementWidth))
1076 template <
int ElementW
idth,
unsigned Class>
1078 if (Kind != k_Register ||
Reg.Kind != RegKind::SVEDataVector)
1081 if (isSVEVectorReg<Class>() &&
Reg.ElementWidth == ElementWidth)
1087 template <
int ElementWidth,
unsigned Class,
1089 bool ShiftWidthAlwaysSame>
1091 auto VectorMatch = isSVEDataVectorRegOfWidth<ElementWidth, Class>();
1092 if (!VectorMatch.isMatch())
1098 bool MatchShift = getShiftExtendAmount() ==
Log2_32(ShiftWidth / 8);
1101 !ShiftWidthAlwaysSame && hasShiftExtendAmount() && ShiftWidth == 8)
1104 if (MatchShift && ShiftExtendTy == getShiftExtendType())
1110 bool isGPR32as64()
const {
1112 AArch64MCRegisterClasses[AArch64::GPR64RegClassID].contains(
Reg.RegNum);
1115 bool isGPR64as32()
const {
1117 AArch64MCRegisterClasses[AArch64::GPR32RegClassID].contains(
Reg.RegNum);
1120 bool isWSeqPair()
const {
1122 AArch64MCRegisterClasses[AArch64::WSeqPairsClassRegClassID].contains(
1126 bool isXSeqPair()
const {
1128 AArch64MCRegisterClasses[AArch64::XSeqPairsClassRegClassID].contains(
1132 template<
int64_t Angle,
int64_t Remainder>
1140 if (Value % Angle == Remainder && Value <= 270)
1145 template <
unsigned RegClassID>
bool isGPR64()
const {
1147 AArch64MCRegisterClasses[RegClassID].contains(
getReg());
1150 template <
unsigned RegClassID,
int ExtW
idth>
1155 if (isGPR64<RegClassID>() && getShiftExtendType() ==
AArch64_AM::LSL &&
1156 getShiftExtendAmount() ==
Log2_32(ExtWidth / 8))
1163 template <RegKind VectorKind,
unsigned NumRegs>
1164 bool isImplicitlyTypedVectorList()
const {
1165 return Kind == k_VectorList && VectorList.Count == NumRegs &&
1166 VectorList.NumElements == 0 &&
1167 VectorList.RegisterKind == VectorKind;
1170 template <
RegKind VectorKind,
unsigned NumRegs,
unsigned NumElements,
1171 unsigned ElementWidth>
1172 bool isTypedVectorList()
const {
1173 if (Kind != k_VectorList)
1175 if (VectorList.Count != NumRegs)
1177 if (VectorList.RegisterKind != VectorKind)
1179 if (VectorList.ElementWidth != ElementWidth)
1181 return VectorList.NumElements == NumElements;
1184 template <
int Min,
int Max>
1186 if (Kind != k_VectorIndex)
1188 if (VectorIndex.Val >= Min && VectorIndex.Val <= Max)
1193 bool isToken()
const override {
return Kind == k_Token; }
1195 bool isTokenEqual(
StringRef Str)
const {
1196 return Kind == k_Token &&
getToken() == Str;
1198 bool isSysCR()
const {
return Kind == k_SysCR; }
1199 bool isPrefetch()
const {
return Kind == k_Prefetch; }
1200 bool isPSBHint()
const {
return Kind == k_PSBHint; }
1201 bool isBTIHint()
const {
return Kind == k_BTIHint; }
1202 bool isShiftExtend()
const {
return Kind == k_ShiftExtend; }
1203 bool isShifter()
const {
1204 if (!isShiftExtend())
1214 if (Kind != k_FPImm)
1217 if (getFPImmIsExact()) {
1219 auto *Desc = AArch64ExactFPImm::lookupExactFPImmByEnum(ImmEnum);
1220 assert(Desc &&
"Unknown enum value");
1229 if (getFPImm().bitwiseIsEqual(RealVal))
1236 template <
unsigned ImmA,
unsigned ImmB>
1239 if ((Res = isExactFPImm<ImmA>()))
1241 if ((Res = isExactFPImm<ImmB>()))
1246 bool isExtend()
const {
1247 if (!isShiftExtend())
1256 getShiftExtendAmount() <= 4;
1259 bool isExtend64()
const {
1269 bool isExtendLSL64()
const {
1275 getShiftExtendAmount() <= 4;
1278 template<
int W
idth>
bool isMemXExtend()
const {
1284 getShiftExtendAmount() == 0);
1287 template<
int W
idth>
bool isMemWExtend()
const {
1293 getShiftExtendAmount() == 0);
1296 template <
unsigned w
idth>
1297 bool isArithmeticShifter()
const {
1307 template <
unsigned w
idth>
1308 bool isLogicalShifter()
const {
1316 getShiftExtendAmount() < width;
1319 bool isMovImm32Shifter()
const {
1327 uint64_t Val = getShiftExtendAmount();
1328 return (Val == 0 || Val == 16);
1331 bool isMovImm64Shifter()
const {
1339 uint64_t Val = getShiftExtendAmount();
1340 return (Val == 0 || Val == 16 || Val == 32 || Val == 48);
1343 bool isLogicalVecShifter()
const {
1348 unsigned Shift = getShiftExtendAmount();
1350 (Shift == 0 || Shift == 8 || Shift == 16 || Shift == 24);
1353 bool isLogicalVecHalfWordShifter()
const {
1354 if (!isLogicalVecShifter())
1358 unsigned Shift = getShiftExtendAmount();
1360 (Shift == 0 || Shift == 8);
1363 bool isMoveVecShifter()
const {
1364 if (!isShiftExtend())
1368 unsigned Shift = getShiftExtendAmount();
1370 (Shift == 8 || Shift == 16);
1379 bool isSImm9OffsetFB()
const {
1380 return isSImm<9>() && !isUImm12Offset<Width / 8>();
1383 bool isAdrpLabel()
const {
1389 if (
const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
1390 int64_t Val = CE->getValue();
1391 int64_t Min = - (4096 * (1LL << (21 - 1)));
1392 int64_t Max = 4096 * ((1LL << (21 - 1)) - 1);
1393 return (Val % 4096) == 0 && Val >= Min && Val <= Max;
1399 bool isAdrLabel()
const {
1405 if (
const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
1406 int64_t Val = CE->getValue();
1407 int64_t Min = - (1LL << (21 - 1));
1408 int64_t Max = ((1LL << (21 - 1)) - 1);
1409 return Val >= Min && Val <= Max;
1419 else if (
const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
1425 void addRegOperands(
MCInst &Inst,
unsigned N)
const {
1426 assert(N == 1 &&
"Invalid number of operands!");
1430 void addGPR32as64Operands(
MCInst &Inst,
unsigned N)
const {
1431 assert(N == 1 &&
"Invalid number of operands!");
1433 AArch64MCRegisterClasses[AArch64::GPR64RegClassID].
contains(
getReg()));
1442 void addGPR64as32Operands(
MCInst &Inst,
unsigned N)
const {
1443 assert(N == 1 &&
"Invalid number of operands!");
1445 AArch64MCRegisterClasses[AArch64::GPR32RegClassID].
contains(
getReg()));
1454 template <
int W
idth>
1455 void addFPRasZPRRegOperands(
MCInst &Inst,
unsigned N)
const {
1458 case 8: Base = AArch64::B0;
break;
1459 case 16: Base = AArch64::H0;
break;
1460 case 32: Base = AArch64::S0;
break;
1461 case 64: Base = AArch64::D0;
break;
1462 case 128: Base = AArch64::Q0;
break;
1469 void addVectorReg64Operands(
MCInst &Inst,
unsigned N)
const {
1470 assert(N == 1 &&
"Invalid number of operands!");
1472 AArch64MCRegisterClasses[AArch64::FPR128RegClassID].
contains(
getReg()));
1476 void addVectorReg128Operands(
MCInst &Inst,
unsigned N)
const {
1477 assert(N == 1 &&
"Invalid number of operands!");
1479 AArch64MCRegisterClasses[AArch64::FPR128RegClassID].
contains(
getReg()));
1483 void addVectorRegLoOperands(
MCInst &Inst,
unsigned N)
const {
1484 assert(N == 1 &&
"Invalid number of operands!");
1488 enum VecListIndexType {
1489 VecListIdx_DReg = 0,
1490 VecListIdx_QReg = 1,
1491 VecListIdx_ZReg = 2,
1494 template <VecListIndexType RegTy,
unsigned NumRegs>
1495 void addVectorListOperands(
MCInst &Inst,
unsigned N)
const {
1496 assert(N == 1 &&
"Invalid number of operands!");
1497 static const unsigned FirstRegs[][5] = {
1499 AArch64::D0, AArch64::D0_D1,
1500 AArch64::D0_D1_D2, AArch64::D0_D1_D2_D3 },
1502 AArch64::Q0, AArch64::Q0_Q1,
1503 AArch64::Q0_Q1_Q2, AArch64::Q0_Q1_Q2_Q3 },
1505 AArch64::Z0, AArch64::Z0_Z1,
1506 AArch64::Z0_Z1_Z2, AArch64::Z0_Z1_Z2_Z3 }
1509 assert((RegTy != VecListIdx_ZReg || NumRegs <= 4) &&
1510 " NumRegs must be <= 4 for ZRegs");
1512 unsigned FirstReg = FirstRegs[(
unsigned)RegTy][NumRegs];
1514 FirstRegs[(
unsigned)RegTy][0]));
1517 void addVectorIndexOperands(
MCInst &Inst,
unsigned N)
const {
1518 assert(N == 1 &&
"Invalid number of operands!");
1522 template <
unsigned ImmIs0,
unsigned ImmIs1>
1523 void addExactFPImmOperands(
MCInst &Inst,
unsigned N)
const {
1524 assert(N == 1 &&
"Invalid number of operands!");
1525 assert(
bool(isExactFPImm<ImmIs0, ImmIs1>()) &&
"Invalid operand");
1529 void addImmOperands(
MCInst &Inst,
unsigned N)
const {
1530 assert(N == 1 &&
"Invalid number of operands!");
1534 addExpr(Inst, getImm());
1537 template <
int Shift>
1538 void addImmWithOptionalShiftOperands(
MCInst &Inst,
unsigned N)
const {
1539 assert(N == 2 &&
"Invalid number of operands!");
1540 if (
auto ShiftedVal = getShiftedVal<Shift>()) {
1543 }
else if (isShiftedImm()) {
1544 addExpr(Inst, getShiftedImmVal());
1547 addExpr(Inst, getImm());
1552 template <
int Shift>
1553 void addImmNegWithOptionalShiftOperands(
MCInst &Inst,
unsigned N)
const {
1554 assert(N == 2 &&
"Invalid number of operands!");
1555 if (
auto ShiftedVal = getShiftedVal<Shift>()) {
1562 void addCondCodeOperands(
MCInst &Inst,
unsigned N)
const {
1563 assert(N == 1 &&
"Invalid number of operands!");
1567 void addAdrpLabelOperands(
MCInst &Inst,
unsigned N)
const {
1568 assert(N == 1 &&
"Invalid number of operands!");
1571 addExpr(Inst, getImm());
1576 void addAdrLabelOperands(
MCInst &Inst,
unsigned N)
const {
1577 addImmOperands(Inst, N);
1581 void addUImm12OffsetOperands(
MCInst &Inst,
unsigned N)
const {
1582 assert(N == 1 &&
"Invalid number of operands!");
1592 void addUImm6Operands(
MCInst &Inst,
unsigned N)
const {
1593 assert(N == 1 &&
"Invalid number of operands!");
1598 template <
int Scale>
1599 void addImmScaledOperands(
MCInst &Inst,
unsigned N)
const {
1600 assert(N == 1 &&
"Invalid number of operands!");
1605 template <
typename T>
1606 void addLogicalImmOperands(
MCInst &Inst,
unsigned N)
const {
1607 assert(N == 1 &&
"Invalid number of operands!");
1609 typename std::make_unsigned<T>::type Val = MCE->
getValue();
1614 template <
typename T>
1615 void addLogicalImmNotOperands(
MCInst &Inst,
unsigned N)
const {
1616 assert(N == 1 &&
"Invalid number of operands!");
1618 typename std::make_unsigned<T>::type Val = ~MCE->
getValue();
1623 void addSIMDImmType10Operands(
MCInst &Inst,
unsigned N)
const {
1624 assert(N == 1 &&
"Invalid number of operands!");
1630 void addBranchTarget26Operands(
MCInst &Inst,
unsigned N)
const {
1634 assert(N == 1 &&
"Invalid number of operands!");
1637 addExpr(Inst, getImm());
1640 assert(MCE &&
"Invalid constant immediate operand!");
1644 void addPCRelLabel19Operands(
MCInst &Inst,
unsigned N)
const {
1648 assert(N == 1 &&
"Invalid number of operands!");
1651 addExpr(Inst, getImm());
1654 assert(MCE &&
"Invalid constant immediate operand!");
1658 void addBranchTarget14Operands(
MCInst &Inst,
unsigned N)
const {
1662 assert(N == 1 &&
"Invalid number of operands!");
1665 addExpr(Inst, getImm());
1668 assert(MCE &&
"Invalid constant immediate operand!");
1672 void addFPImmOperands(
MCInst &Inst,
unsigned N)
const {
1673 assert(N == 1 &&
"Invalid number of operands!");
1678 void addBarrierOperands(
MCInst &Inst,
unsigned N)
const {
1679 assert(N == 1 &&
"Invalid number of operands!");
1683 void addMRSSystemRegisterOperands(
MCInst &Inst,
unsigned N)
const {
1684 assert(N == 1 &&
"Invalid number of operands!");
1689 void addMSRSystemRegisterOperands(
MCInst &Inst,
unsigned N)
const {
1690 assert(N == 1 &&
"Invalid number of operands!");
1695 void addSystemPStateFieldWithImm0_1Operands(
MCInst &Inst,
unsigned N)
const {
1696 assert(N == 1 &&
"Invalid number of operands!");
1701 void addSystemPStateFieldWithImm0_15Operands(
MCInst &Inst,
unsigned N)
const {
1702 assert(N == 1 &&
"Invalid number of operands!");
1707 void addSysCROperands(
MCInst &Inst,
unsigned N)
const {
1708 assert(N == 1 &&
"Invalid number of operands!");
1712 void addPrefetchOperands(
MCInst &Inst,
unsigned N)
const {
1713 assert(N == 1 &&
"Invalid number of operands!");
1717 void addPSBHintOperands(
MCInst &Inst,
unsigned N)
const {
1718 assert(N == 1 &&
"Invalid number of operands!");
1722 void addBTIHintOperands(
MCInst &Inst,
unsigned N)
const {
1723 assert(N == 1 &&
"Invalid number of operands!");
1727 void addShifterOperands(
MCInst &Inst,
unsigned N)
const {
1728 assert(N == 1 &&
"Invalid number of operands!");
1734 void addExtendOperands(
MCInst &Inst,
unsigned N)
const {
1735 assert(N == 1 &&
"Invalid number of operands!");
1742 void addExtend64Operands(
MCInst &Inst,
unsigned N)
const {
1743 assert(N == 1 &&
"Invalid number of operands!");
1750 void addMemExtendOperands(
MCInst &Inst,
unsigned N)
const {
1751 assert(N == 2 &&
"Invalid number of operands!");
1762 void addMemExtend8Operands(
MCInst &Inst,
unsigned N)
const {
1763 assert(N == 2 &&
"Invalid number of operands!");
1771 void addMOVZMovAliasOperands(
MCInst &Inst,
unsigned N)
const {
1772 assert(N == 1 &&
"Invalid number of operands!");
1780 void addMOVNMovAliasOperands(
MCInst &Inst,
unsigned N)
const {
1781 assert(N == 1 &&
"Invalid number of operands!");
1788 void addComplexRotationEvenOperands(
MCInst &Inst,
unsigned N)
const {
1789 assert(N == 1 &&
"Invalid number of operands!");
1794 void addComplexRotationOddOperands(
MCInst &Inst,
unsigned N)
const {
1795 assert(N == 1 &&
"Invalid number of operands!");
1802 static std::unique_ptr<AArch64Operand>
1804 auto Op = std::make_unique<AArch64Operand>(k_Token, Ctx);
1805 Op->Tok.Data = Str.
data();
1806 Op->Tok.Length = Str.
size();
1807 Op->Tok.IsSuffix = IsSuffix;
1813 static std::unique_ptr<AArch64Operand>
1817 unsigned ShiftAmount = 0,
1818 unsigned HasExplicitAmount =
false) {
1819 auto Op = std::make_unique<AArch64Operand>(k_Register, Ctx);
1820 Op->Reg.RegNum = RegNum;
1822 Op->Reg.ElementWidth = 0;
1823 Op->Reg.EqualityTy = EqTy;
1824 Op->Reg.ShiftExtend.Type = ExtTy;
1825 Op->Reg.ShiftExtend.Amount = ShiftAmount;
1826 Op->Reg.ShiftExtend.HasExplicitAmount = HasExplicitAmount;
1832 static std::unique_ptr<AArch64Operand>
1833 CreateVectorReg(
unsigned RegNum,
RegKind Kind,
unsigned ElementWidth,
1836 unsigned ShiftAmount = 0,
1837 unsigned HasExplicitAmount =
false) {
1838 assert((Kind == RegKind::NeonVector || Kind == RegKind::SVEDataVector ||
1839 Kind == RegKind::SVEPredicateVector) &&
1840 "Invalid vector kind");
1841 auto Op = CreateReg(RegNum, Kind, S, E, Ctx, EqualsReg, ExtTy, ShiftAmount,
1843 Op->Reg.ElementWidth = ElementWidth;
1847 static std::unique_ptr<AArch64Operand>
1848 CreateVectorList(
unsigned RegNum,
unsigned Count,
unsigned NumElements,
1851 auto Op = std::make_unique<AArch64Operand>(k_VectorList, Ctx);
1852 Op->VectorList.RegNum = RegNum;
1853 Op->VectorList.Count = Count;
1854 Op->VectorList.NumElements = NumElements;
1855 Op->VectorList.ElementWidth = ElementWidth;
1862 static std::unique_ptr<AArch64Operand>
1864 auto Op = std::make_unique<AArch64Operand>(k_VectorIndex, Ctx);
1865 Op->VectorIndex.Val = Idx;
1871 static std::unique_ptr<AArch64Operand> CreateImm(
const MCExpr *Val,
SMLoc S,
1873 auto Op = std::make_unique<AArch64Operand>(k_Immediate, Ctx);
1880 static std::unique_ptr<AArch64Operand> CreateShiftedImm(
const MCExpr *Val,
1881 unsigned ShiftAmount,
1884 auto Op = std::make_unique<AArch64Operand>(k_ShiftedImm, Ctx);
1885 Op->ShiftedImm .Val = Val;
1886 Op->ShiftedImm.ShiftAmount = ShiftAmount;
1892 static std::unique_ptr<AArch64Operand>
1894 auto Op = std::make_unique<AArch64Operand>(k_CondCode, Ctx);
1895 Op->CondCode.Code =
Code;
1901 static std::unique_ptr<AArch64Operand>
1903 auto Op = std::make_unique<AArch64Operand>(k_FPImm, Ctx);
1905 Op->FPImm.IsExact = IsExact;
1911 static std::unique_ptr<AArch64Operand> CreateBarrier(
unsigned Val,
1915 auto Op = std::make_unique<AArch64Operand>(k_Barrier, Ctx);
1916 Op->Barrier.Val = Val;
1917 Op->Barrier.Data = Str.
data();
1918 Op->Barrier.Length = Str.
size();
1924 static std::unique_ptr<AArch64Operand> CreateSysReg(
StringRef Str,
SMLoc S,
1929 auto Op = std::make_unique<AArch64Operand>(k_SysReg, Ctx);
1930 Op->SysReg.Data = Str.
data();
1931 Op->SysReg.Length = Str.
size();
1932 Op->SysReg.MRSReg = MRSReg;
1933 Op->SysReg.MSRReg = MSRReg;
1934 Op->SysReg.PStateField = PStateField;
1940 static std::unique_ptr<AArch64Operand> CreateSysCR(
unsigned Val,
SMLoc S,
1942 auto Op = std::make_unique<AArch64Operand>(k_SysCR, Ctx);
1943 Op->SysCRImm.Val = Val;
1949 static std::unique_ptr<AArch64Operand> CreatePrefetch(
unsigned Val,
1953 auto Op = std::make_unique<AArch64Operand>(k_Prefetch, Ctx);
1954 Op->Prefetch.Val = Val;
1955 Op->Barrier.Data = Str.
data();
1956 Op->Barrier.Length = Str.
size();
1962 static std::unique_ptr<AArch64Operand> CreatePSBHint(
unsigned Val,
1966 auto Op = std::make_unique<AArch64Operand>(k_PSBHint, Ctx);
1967 Op->PSBHint.Val = Val;
1968 Op->PSBHint.Data = Str.
data();
1969 Op->PSBHint.Length = Str.
size();
1975 static std::unique_ptr<AArch64Operand> CreateBTIHint(
unsigned Val,
1979 auto Op = std::make_unique<AArch64Operand>(k_BTIHint, Ctx);
1980 Op->BTIHint.Val = Val << 1 | 32;
1981 Op->BTIHint.Data = Str.
data();
1982 Op->BTIHint.Length = Str.
size();
1988 static std::unique_ptr<AArch64Operand>
1991 auto Op = std::make_unique<AArch64Operand>(k_ShiftExtend, Ctx);
1992 Op->ShiftExtend.Type = ShOp;
1993 Op->ShiftExtend.Amount = Val;
1994 Op->ShiftExtend.HasExplicitAmount = HasExplicitAmount;
2006 OS <<
"<fpimm " << getFPImm().bitcastToAPInt().getZExtValue();
2007 if (!getFPImmIsExact())
2014 OS <<
"<barrier " << Name <<
">";
2016 OS <<
"<barrier invalid #" << getBarrier() <<
">";
2022 case k_ShiftedImm: {
2023 unsigned Shift = getShiftedImmShift();
2024 OS <<
"<shiftedimm ";
2025 OS << *getShiftedImmVal();
2032 case k_VectorList: {
2033 OS <<
"<vectorlist ";
2034 unsigned Reg = getVectorListStart();
2035 for (
unsigned i = 0,
e = getVectorListCount(); i !=
e; ++i)
2036 OS << Reg + i <<
" ";
2041 OS <<
"<vectorindex " << getVectorIndex() <<
">";
2044 OS <<
"<sysreg: " << getSysReg() <<
'>';
2050 OS <<
"c" << getSysCR();
2055 OS <<
"<prfop " << Name <<
">";
2057 OS <<
"<prfop invalid #" << getPrefetch() <<
">";
2061 OS << getPSBHintName();
2064 OS <<
"<register " <<
getReg() <<
">";
2065 if (!getShiftExtendAmount() && !hasShiftExtendAmount())
2069 OS << getBTIHintName();
2073 << getShiftExtendAmount();
2074 if (!hasShiftExtendAmount())
2084 static unsigned MatchRegisterName(StringRef Name);
2088 static unsigned MatchNeonVectorRegName(StringRef Name) {
2089 return StringSwitch<unsigned>(Name.lower())
2090 .Case("v0", AArch64::Q0)
2091 .Case("v1", AArch64::Q1)
2092 .Case("v2", AArch64::Q2)
2093 .Case("v3", AArch64::Q3)
2094 .Case("v4", AArch64::Q4)
2095 .Case("v5", AArch64::Q5)
2096 .Case("v6", AArch64::Q6)
2097 .Case("v7", AArch64::Q7)
2098 .Case("v8", AArch64::Q8)
2099 .Case("v9", AArch64::Q9)
2100 .Case("v10", AArch64::Q10)
2101 .Case("v11", AArch64::Q11)
2102 .Case("v12", AArch64::Q12)
2103 .Case("v13", AArch64::Q13)
2104 .Case("v14", AArch64::Q14)
2105 .Case("v15", AArch64::Q15)
2106 .Case("v16", AArch64::Q16)
2107 .Case("v17", AArch64::Q17)
2108 .Case("v18", AArch64::Q18)
2109 .Case("v19", AArch64::Q19)
2110 .Case("v20", AArch64::Q20)
2111 .Case("v21", AArch64::Q21)
2112 .Case("v22", AArch64::Q22)
2113 .Case("v23", AArch64::Q23)
2114 .Case("v24", AArch64::Q24)
2115 .Case("v25", AArch64::Q25)
2116 .Case("v26", AArch64::Q26)
2117 .Case("v27", AArch64::Q27)
2118 .Case("v28", AArch64::Q28)
2119 .Case("v29", AArch64::Q29)
2120 .Case("v30", AArch64::Q30)
2121 .Case("v31", AArch64::Q31)
2129 static Optional<std::pair<int, int>> parseVectorKind(StringRef Suffix,
2130 RegKind VectorKind) {
2131 std::pair<int, int> Res = {-1, -1};
2133 switch (VectorKind) {
2134 case RegKind::NeonVector:
2136 StringSwitch<std::pair<int, int>>(Suffix.lower())
2138 .Case(".1d", {1, 64})
2139 .Case(".1q", {1, 128})
2140 // '.2h
' needed for fp16 scalar pairwise reductions 2141 .Case(".2h", {2, 16}) 2142 .Case(".2s", {2, 32}) 2143 .Case(".2d", {2, 64}) 2144 // '.4b
' is another special case for the ARMv8.2a dot product 2146 .Case(".4b", {4, 8}) 2147 .Case(".4h", {4, 16}) 2148 .Case(".4s", {4, 32}) 2149 .Case(".8b", {8, 8}) 2150 .Case(".8h", {8, 16}) 2151 .Case(".16b", {16, 8}) 2152 // Accept the width neutral ones, too, for verbose syntax. If those 2153 // aren't used in the right places, the token operand won
't match so 2154 // all will work out. 2156 .Case(".h", {0, 16}) 2157 .Case(".s", {0, 32}) 2158 .Case(".d", {0, 64}) 2161 case RegKind::SVEPredicateVector: 2162 case RegKind::SVEDataVector: 2163 Res = StringSwitch<std::pair<int, int>>(Suffix.lower()) 2166 .Case(".h", {0, 16}) 2167 .Case(".s", {0, 32}) 2168 .Case(".d", {0, 64}) 2169 .Case(".q", {0, 128}) 2173 llvm_unreachable("Unsupported RegKind"); 2176 if (Res == std::make_pair(-1, -1)) 2177 return Optional<std::pair<int, int>>(); 2179 return Optional<std::pair<int, int>>(Res); 2182 static bool isValidVectorKind(StringRef Suffix, RegKind VectorKind) { 2183 return parseVectorKind(Suffix, VectorKind).hasValue(); 2186 static unsigned matchSVEDataVectorRegName(StringRef Name) { 2187 return StringSwitch<unsigned>(Name.lower()) 2188 .Case("z0", AArch64::Z0) 2189 .Case("z1", AArch64::Z1) 2190 .Case("z2", AArch64::Z2) 2191 .Case("z3", AArch64::Z3) 2192 .Case("z4", AArch64::Z4) 2193 .Case("z5", AArch64::Z5) 2194 .Case("z6", AArch64::Z6) 2195 .Case("z7", AArch64::Z7) 2196 .Case("z8", AArch64::Z8) 2197 .Case("z9", AArch64::Z9) 2198 .Case("z10", AArch64::Z10) 2199 .Case("z11", AArch64::Z11) 2200 .Case("z12", AArch64::Z12) 2201 .Case("z13", AArch64::Z13) 2202 .Case("z14", AArch64::Z14) 2203 .Case("z15", AArch64::Z15) 2204 .Case("z16", AArch64::Z16) 2205 .Case("z17", AArch64::Z17) 2206 .Case("z18", AArch64::Z18) 2207 .Case("z19", AArch64::Z19) 2208 .Case("z20", AArch64::Z20) 2209 .Case("z21", AArch64::Z21) 2210 .Case("z22", AArch64::Z22) 2211 .Case("z23", AArch64::Z23) 2212 .Case("z24", AArch64::Z24) 2213 .Case("z25", AArch64::Z25) 2214 .Case("z26", AArch64::Z26) 2215 .Case("z27", AArch64::Z27) 2216 .Case("z28", AArch64::Z28) 2217 .Case("z29", AArch64::Z29) 2218 .Case("z30", AArch64::Z30) 2219 .Case("z31", AArch64::Z31) 2223 static unsigned matchSVEPredicateVectorRegName(StringRef Name) { 2224 return StringSwitch<unsigned>(Name.lower()) 2225 .Case("p0", AArch64::P0) 2226 .Case("p1", AArch64::P1) 2227 .Case("p2", AArch64::P2) 2228 .Case("p3", AArch64::P3) 2229 .Case("p4", AArch64::P4) 2230 .Case("p5", AArch64::P5) 2231 .Case("p6", AArch64::P6) 2232 .Case("p7", AArch64::P7) 2233 .Case("p8", AArch64::P8) 2234 .Case("p9", AArch64::P9) 2235 .Case("p10", AArch64::P10) 2236 .Case("p11", AArch64::P11) 2237 .Case("p12", AArch64::P12) 2238 .Case("p13", AArch64::P13) 2239 .Case("p14", AArch64::P14) 2240 .Case("p15", AArch64::P15) 2244 bool AArch64AsmParser::ParseRegister(unsigned &RegNo, SMLoc &StartLoc, 2246 StartLoc = getLoc(); 2247 auto Res = tryParseScalarRegister(RegNo); 2248 EndLoc = SMLoc::getFromPointer(getLoc().getPointer() - 1); 2249 return Res != MatchOperand_Success; 2252 // Matches a register name or register alias previously defined by '.req
' 2253 unsigned AArch64AsmParser::matchRegisterNameAlias(StringRef Name, 2255 unsigned RegNum = 0; 2256 if ((RegNum = matchSVEDataVectorRegName(Name))) 2257 return Kind == RegKind::SVEDataVector ? RegNum : 0; 2259 if ((RegNum = matchSVEPredicateVectorRegName(Name))) 2260 return Kind == RegKind::SVEPredicateVector ? RegNum : 0; 2262 if ((RegNum = MatchNeonVectorRegName(Name))) 2263 return Kind == RegKind::NeonVector ? RegNum : 0; 2265 // The parsed register must be of RegKind Scalar 2266 if ((RegNum = MatchRegisterName(Name))) 2267 return Kind == RegKind::Scalar ? RegNum : 0; 2270 // Handle a few common aliases of registers. 2271 if (auto RegNum = StringSwitch<unsigned>(Name.lower()) 2272 .Case("fp", AArch64::FP) 2273 .Case("lr", AArch64::LR) 2274 .Case("x31", AArch64::XZR) 2275 .Case("w31", AArch64::WZR) 2277 return Kind == RegKind::Scalar ? RegNum : 0; 2279 // Check for aliases registered via .req. Canonicalize to lower case. 2280 // That's more consistent since
register names are
case insensitive, and
2282 auto Entry = RegisterReqs.find(
Name.lower());
2283 if (Entry == RegisterReqs.end())
2287 if (
Kind == Entry->getValue().first)
2288 RegNum = Entry->getValue().second;
2297 AArch64AsmParser::tryParseScalarRegister(
unsigned &RegNum) {
2320 Error(S,
"Expected cN operand where 0 <= N <= 15");
2325 if (Tok[0] !=
'c' && Tok[0] !=
'C') {
2326 Error(S,
"Expected cN operand where 0 <= N <= 15");
2332 if (BadNum || CRNum > 15) {
2333 Error(S,
"Expected cN operand where 0 <= N <= 15");
2339 AArch64Operand::CreateSysCR(CRNum, S, getLoc(), getContext()));
2344 template <
bool IsSVEPrefetch>
2346 AArch64AsmParser::tryParsePrefetch(
OperandVector &Operands) {
2352 if (IsSVEPrefetch) {
2353 if (
auto Res = AArch64SVEPRFM::lookupSVEPRFMByName(
N))
2355 }
else if (
auto Res = AArch64PRFM::lookupPRFMByName(
N))
2360 auto LookupByEncoding = [](
unsigned E) {
2361 if (IsSVEPrefetch) {
2362 if (
auto Res = AArch64SVEPRFM::lookupSVEPRFMByEncoding(
E))
2364 }
else if (
auto Res = AArch64PRFM::lookupPRFMByEncoding(
E))
2368 unsigned MaxVal = IsSVEPrefetch ? 15 : 31;
2375 if (getParser().parseExpression(ImmVal))
2380 TokError(
"immediate value expected for prefetch operand");
2384 if (prfop > MaxVal) {
2385 TokError(
"prefetch operand out of range, [0," +
utostr(MaxVal) +
2390 auto PRFM = LookupByEncoding(MCE->
getValue());
2391 Operands.
push_back(AArch64Operand::CreatePrefetch(
2392 prfop, PRFM.getValueOr(
""), S, getContext()));
2397 TokError(
"prefetch hint expected");
2401 auto PRFM = LookupByName(Tok.
getString());
2403 TokError(
"prefetch hint expected");
2408 Operands.
push_back(AArch64Operand::CreatePrefetch(
2409 *PRFM, Tok.
getString(), S, getContext()));
2415 AArch64AsmParser::tryParsePSBHint(
OperandVector &Operands) {
2420 TokError(
"invalid operand for instruction");
2424 auto PSB = AArch64PSBHint::lookupPSBByName(Tok.
getString());
2426 TokError(
"invalid operand for instruction");
2431 Operands.
push_back(AArch64Operand::CreatePSBHint(
2432 PSB->Encoding, Tok.
getString(), S, getContext()));
2438 AArch64AsmParser::tryParseBTIHint(
OperandVector &Operands) {
2443 TokError(
"invalid operand for instruction");
2447 auto BTI = AArch64BTIHint::lookupBTIByName(Tok.
getString());
2449 TokError(
"invalid operand for instruction");
2454 Operands.
push_back(AArch64Operand::CreateBTIHint(
2455 BTI->Encoding, Tok.
getString(), S, getContext()));
2462 AArch64AsmParser::tryParseAdrpLabel(
OperandVector &Operands) {
2465 const MCExpr *Expr =
nullptr;
2471 if (parseSymbolicImmVal(Expr))
2477 if (classifySymbolRef(Expr, ELFRefKind, DarwinRefKind, Addend)) {
2487 Error(S,
"gotpage label reference not allowed an addend");
2497 Error(S,
"page or gotpage label reference expected");
2506 Operands.
push_back(AArch64Operand::CreateImm(Expr, S, E, getContext()));
2514 AArch64AsmParser::tryParseAdrLabel(
OperandVector &Operands) {
2516 const MCExpr *Expr =
nullptr;
2525 if (parseSymbolicImmVal(Expr))
2531 if (classifySymbolRef(Expr, ELFRefKind, DarwinRefKind, Addend)) {
2538 Error(S,
"unexpected adr label");
2544 Operands.
push_back(AArch64Operand::CreateImm(Expr, S, E, getContext()));
2549 template<
bool AddFPZeroAsLiteral>
2564 TokError(
"invalid floating point immediate");
2570 if (Tok.
getIntVal() > 255 || isNegative) {
2571 TokError(
"encoded floating point value out of range");
2577 AArch64Operand::CreateFPImm(F,
true, S, getContext()));
2584 TokError(
"invalid floating point representation");
2591 if (AddFPZeroAsLiteral && RealVal.
isPosZero()) {
2593 AArch64Operand::CreateToken(
"#0",
false, S, getContext()));
2595 AArch64Operand::CreateToken(
".0",
false, S, getContext()));
2597 Operands.
push_back(AArch64Operand::CreateFPImm(
2609 AArch64AsmParser::tryParseImmWithOptionalShift(
OperandVector &Operands) {
2619 const MCExpr *Imm =
nullptr;
2620 if (parseSymbolicImmVal(Imm))
2625 AArch64Operand::CreateImm(Imm, S, E, getContext()));
2651 if (ShiftAmount < 0) {
2658 if (ShiftAmount == 0 && Imm !=
nullptr) {
2660 Operands.
push_back(AArch64Operand::CreateImm(Imm, S, E, getContext()));
2665 Operands.
push_back(AArch64Operand::CreateShiftedImm(Imm, ShiftAmount,
2666 S, E, getContext()));
2694 getSTI().getFeatureBits()[AArch64::FeatureSVE])
2712 bool AArch64AsmParser::parseCondCode(
OperandVector &Operands,
2713 bool invertCondCode) {
2722 return TokError(
"invalid condition code");
2725 if (invertCondCode) {
2727 return TokError(
"condition codes AL and NV are invalid for this instruction");
2732 AArch64Operand::CreateCondCode(CC, S, getLoc(), getContext()));
2739 AArch64AsmParser::tryParseOptionalShiftExtend(
OperandVector &Operands) {
2773 TokError(
"expected #imm after shift specifier");
2780 AArch64Operand::CreateShiftExtend(ShOp, 0,
false, S, E, getContext()));
2790 Error(E,
"expected integer shift amount");
2795 if (getParser().parseExpression(ImmVal))
2800 Error(E,
"expected constant '#imm' after shift specifier");
2805 Operands.
push_back(AArch64Operand::CreateShiftExtend(
2806 ShOp, MCE->
getValue(),
true, S,
E, getContext()));
2814 {
"crc", {AArch64::FeatureCRC}},
2815 {
"sm4", {AArch64::FeatureSM4}},
2816 {
"sha3", {AArch64::FeatureSHA3}},
2817 {
"sha2", {AArch64::FeatureSHA2}},
2818 {
"aes", {AArch64::FeatureAES}},
2819 {
"crypto", {AArch64::FeatureCrypto}},
2820 {
"fp", {AArch64::FeatureFPARMv8}},
2821 {
"simd", {AArch64::FeatureNEON}},
2822 {
"ras", {AArch64::FeatureRAS}},
2823 {
"lse", {AArch64::FeatureLSE}},
2824 {
"predres", {AArch64::FeaturePredRes}},
2825 {
"ccdp", {AArch64::FeatureCacheDeepPersist}},
2826 {
"mte", {AArch64::FeatureMTE}},
2827 {
"tlb-rmi", {AArch64::FeatureTLB_RMI}},
2828 {
"pan-rwv", {AArch64::FeaturePAN_RWV}},
2829 {
"ccpp", {AArch64::FeatureCCPP}},
2830 {
"sve", {AArch64::FeatureSVE}},
2831 {
"sve2", {AArch64::FeatureSVE2}},
2832 {
"sve2-aes", {AArch64::FeatureSVE2AES}},
2833 {
"sve2-sm4", {AArch64::FeatureSVE2SM4}},
2834 {
"sve2-sha3", {AArch64::FeatureSVE2SHA3}},
2835 {
"sve2-bitperm", {AArch64::FeatureSVE2BitPerm}},
2844 if (FBS[AArch64::HasV8_1aOps])
2846 else if (FBS[AArch64::HasV8_2aOps])
2848 else if (FBS[AArch64::HasV8_3aOps])
2850 else if (FBS[AArch64::HasV8_4aOps])
2852 else if (FBS[AArch64::HasV8_5aOps])
2869 const uint16_t Cm = (Encoding & 0x78) >> 3;
2870 const uint16_t Cn = (Encoding & 0x780) >> 7;
2871 const uint16_t Op1 = (Encoding & 0x3800) >> 11;
2876 AArch64Operand::CreateImm(Expr, S, getLoc(), getContext()));
2878 AArch64Operand::CreateSysCR(Cn, S, getLoc(), getContext()));
2880 AArch64Operand::CreateSysCR(Cm, S, getLoc(), getContext()));
2883 AArch64Operand::CreateImm(Expr, S, getLoc(), getContext()));
2891 return TokError(
"invalid operand");
2895 AArch64Operand::CreateToken(
"sys",
false, NameLoc, getContext()));
2902 if (Mnemonic ==
"ic") {
2905 return TokError(
"invalid operand for IC instruction");
2906 else if (!IC->
haveFeatures(getSTI().getFeatureBits())) {
2907 std::string Str(
"IC " + std::string(IC->
Name) +
" requires ");
2909 return TokError(Str.c_str());
2911 createSysAlias(IC->
Encoding, Operands, S);
2912 }
else if (Mnemonic ==
"dc") {
2915 return TokError(
"invalid operand for DC instruction");
2916 else if (!DC->
haveFeatures(getSTI().getFeatureBits())) {
2917 std::string Str(
"DC " + std::string(DC->
Name) +
" requires ");
2919 return TokError(Str.c_str());
2921 createSysAlias(DC->
Encoding, Operands, S);
2922 }
else if (Mnemonic ==
"at") {
2925 return TokError(
"invalid operand for AT instruction");
2926 else if (!AT->
haveFeatures(getSTI().getFeatureBits())) {
2927 std::string Str(
"AT " + std::string(AT->
Name) +
" requires ");
2929 return TokError(Str.c_str());
2931 createSysAlias(AT->
Encoding, Operands, S);
2932 }
else if (Mnemonic ==
"tlbi") {
2935 return TokError(
"invalid operand for TLBI instruction");
2936 else if (!TLBI->
haveFeatures(getSTI().getFeatureBits())) {
2937 std::string Str(
"TLBI " + std::string(TLBI->
Name) +
" requires ");
2939 return TokError(Str.c_str());
2941 createSysAlias(TLBI->
Encoding, Operands, S);
2942 }
else if (Mnemonic ==
"cfp" || Mnemonic ==
"dvp" || Mnemonic ==
"cpp") {
2945 return TokError(
"invalid operand for prediction restriction instruction");
2946 else if (!PRCTX->
haveFeatures(getSTI().getFeatureBits())) {
2948 Mnemonic.upper() + std::string(PRCTX->
Name) +
" requires ");
2950 return TokError(Str.c_str());
2953 Mnemonic ==
"cfp" ? 4 :
2954 Mnemonic ==
"dvp" ? 5 :
2955 Mnemonic ==
"cpp" ? 7 :
2957 assert(PRCTX_Op2 &&
"Invalid mnemonic for prediction restriction instruction");
2958 createSysAlias(PRCTX->
Encoding << 3 | PRCTX_Op2 , Operands, S);
2964 bool HasRegister =
false;
2969 return TokError(
"expected register operand");
2973 if (ExpectRegister && !HasRegister)
2974 return TokError(
"specified " + Mnemonic +
" op requires a register");
2975 else if (!ExpectRegister && HasRegister)
2976 return TokError(
"specified " + Mnemonic +
" op does not use a register");
2985 AArch64AsmParser::tryParseBarrierOperand(
OperandVector &Operands) {
2990 TokError(
"'csync' operand expected");
2996 SMLoc ExprLoc = getLoc();
2997 if (getParser().parseExpression(ImmVal))
3001 Error(ExprLoc,
"immediate value expected for barrier operand");
3005 Error(ExprLoc,
"barrier operand out of range");
3008 auto DB = AArch64DB::lookupDBByEncoding(MCE->
getValue());
3009 Operands.
push_back(AArch64Operand::CreateBarrier(
3010 MCE->
getValue(), DB ? DB->Name :
"", ExprLoc, getContext()));
3015 TokError(
"invalid operand for instruction");
3019 auto TSB = AArch64TSB::lookupTSBByName(Tok.
getString());
3021 auto DB = AArch64DB::lookupDBByName(Tok.
getString());
3022 if (Mnemonic ==
"isb" && (!DB || DB->Encoding != AArch64DB::sy)) {
3023 TokError(
"'sy' or #imm operand expected");
3026 }
else if (Mnemonic ==
"tsb" && (!TSB || TSB->Encoding != AArch64TSB::csync)) {
3027 TokError(
"'csync' operand expected");
3029 }
else if (!DB && !TSB) {
3030 TokError(
"invalid barrier option name");
3034 Operands.
push_back(AArch64Operand::CreateBarrier(
3035 DB ? DB->Encoding : TSB->Encoding, Tok.
getString(), getLoc(), getContext()));
3051 if (SysReg && SysReg->haveFeatures(getSTI().getFeatureBits())) {
3052 MRSReg = SysReg->
Readable ? SysReg->Encoding : -1;
3053 MSRReg = SysReg->Writeable ? SysReg->Encoding : -1;
3057 auto PState = AArch64PState::lookupPStateByName(Tok.
getString());
3058 unsigned PStateImm = -1;
3059 if (PState && PState->haveFeatures(getSTI().getFeatureBits()))
3060 PStateImm = PState->Encoding;
3063 AArch64Operand::CreateSysReg(Tok.
getString(), getLoc(), MRSReg, MSRReg,
3064 PStateImm, getContext()));
3071 bool AArch64AsmParser::tryParseNeonVectorRegister(
OperandVector &Operands) {
3081 tryParseVectorRegister(Reg, Kind, RegKind::NeonVector);
3089 unsigned ElementWidth = KindRes->second;
3091 AArch64Operand::CreateVectorReg(Reg, RegKind::NeonVector, ElementWidth,
3092 S, getLoc(), getContext()));
3098 AArch64Operand::CreateToken(Kind,
false, S, getContext()));
3104 AArch64AsmParser::tryParseVectorIndex(
OperandVector &Operands) {
3105 SMLoc SIdx = getLoc();
3108 if (getParser().parseExpression(ImmVal))
3112 TokError(
"immediate value expected for vector index");
3144 size_t Start = 0, Next = Name.
find(
'.');
3146 unsigned RegNum = matchRegisterNameAlias(Head, MatchKind);
3152 TokError(
"invalid vector kind qualifier");
3167 AArch64AsmParser::tryParseSVEPredicateVector(
OperandVector &Operands) {
3169 const SMLoc S = getLoc();
3172 auto Res = tryParseVectorRegister(RegNum, Kind, RegKind::SVEPredicateVector);
3176 const auto &KindRes =
parseVectorKind(Kind, RegKind::SVEPredicateVector);
3180 unsigned ElementWidth = KindRes->second;
3181 Operands.
push_back(AArch64Operand::CreateVectorReg(
3182 RegNum, RegKind::SVEPredicateVector, ElementWidth, S,
3183 getLoc(), getContext()));
3191 if (!Kind.
empty()) {
3192 Error(S,
"not expecting size suffix");
3198 AArch64Operand::CreateToken(
"/" ,
false, getLoc(), getContext()));
3204 if (Pred !=
"z" && Pred !=
"m") {
3205 Error(getLoc(),
"expecting 'm' or 'z' predication");
3210 const char *ZM = Pred ==
"z" ?
"z" :
"m";
3212 AArch64Operand::CreateToken(ZM,
false, getLoc(), getContext()));
3219 bool AArch64AsmParser::parseRegister(
OperandVector &Operands) {
3221 if (!tryParseNeonVectorRegister(Operands))
3231 bool AArch64AsmParser::parseSymbolicImmVal(
const MCExpr *&ImmVal) {
3233 bool HasELFModifier =
false;
3237 HasELFModifier =
true;
3240 return TokError(
"expect relocation specifier in operand after ':'");
3292 return TokError(
"expect relocation specifier in operand after ':'");
3296 if (parseToken(
AsmToken::Colon,
"expect ':' after relocation specifier"))
3300 if (getParser().parseExpression(ImmVal))
3309 template <RegKind VectorKind>
3311 AArch64AsmParser::tryParseVectorList(
OperandVector &Operands,
3319 bool NoMatchIsError) {
3320 auto RegTok = Parser.
getTok();
3321 auto ParseRes = tryParseVectorRegister(Reg, Kind, VectorKind);
3331 Error(Loc,
"vector register expected");
3339 auto LCurly = Parser.
getTok();
3344 auto ParseRes = ParseVector(FirstReg, Kind, getLoc(), ExpectMatch);
3354 int64_t PrevReg = FirstReg;
3358 SMLoc Loc = getLoc();
3362 ParseRes = ParseVector(Reg, NextKind, getLoc(),
true);
3367 if (Kind != NextKind) {
3368 Error(Loc,
"mismatched register size suffix");
3372 unsigned Space = (PrevReg <
Reg) ? (Reg - PrevReg) : (Reg + 32 - PrevReg);
3374 if (Space == 0 || Space > 3) {
3375 Error(Loc,
"invalid number of vectors");
3383 SMLoc Loc = getLoc();
3386 ParseRes = ParseVector(Reg, NextKind, getLoc(),
true);
3391 if (Kind != NextKind) {
3392 Error(Loc,
"mismatched register size suffix");
3397 if (getContext().getRegisterInfo()->getEncodingValue(Reg) !=
3398 (getContext().getRegisterInfo()->getEncodingValue(PrevReg) + 1) % 32) {
3399 Error(Loc,
"registers must be sequential");
3412 Error(S,
"invalid number of vectors");
3416 unsigned NumElements = 0;
3417 unsigned ElementWidth = 0;
3418 if (!Kind.
empty()) {
3420 std::tie(NumElements, ElementWidth) = *VK;
3423 Operands.
push_back(AArch64Operand::CreateVectorList(
3424 FirstReg, Count, NumElements, ElementWidth, VectorKind, S, getLoc(),
3431 bool AArch64AsmParser::parseNeonVectorList(
OperandVector &Operands) {
3432 auto ParseRes = tryParseVectorList<RegKind::NeonVector>(
Operands,
true);
3440 AArch64AsmParser::tryParseGPR64sp0Operand(
OperandVector &Operands) {
3441 SMLoc StartLoc = getLoc();
3449 Operands.
push_back(AArch64Operand::CreateReg(
3457 Error(getLoc(),
"index must be absent or #0");
3462 if (getParser().parseExpression(ImmVal) || !isa<MCConstantExpr>(ImmVal) ||
3463 cast<MCConstantExpr>(ImmVal)->getValue() != 0) {
3464 Error(getLoc(),
"index must be absent or #0");
3468 Operands.
push_back(AArch64Operand::CreateReg(
3473 template <
bool ParseShiftExtend, RegConstra
intEqualityTy EqTy>
3475 AArch64AsmParser::tryParseGPROperand(
OperandVector &Operands) {
3476 SMLoc StartLoc = getLoc();
3484 if (!ParseShiftExtend || getParser().getTok().isNot(
AsmToken::Comma)) {
3485 Operands.
push_back(AArch64Operand::CreateReg(
3495 Res = tryParseOptionalShiftExtend(ExtOpnd);
3499 auto Ext =
static_cast<AArch64Operand*
>(ExtOpnd.
back().get());
3500 Operands.
push_back(AArch64Operand::CreateReg(
3502 Ext->getShiftExtendType(),
Ext->getShiftExtendAmount(),
3503 Ext->hasShiftExtendAmount()));
3508 bool AArch64AsmParser::parseOptionalMulOperand(
OperandVector &Operands) {
3517 !(NextIsVL || NextIsHash))
3521 AArch64Operand::CreateToken(
"mul",
false, getLoc(), getContext()));
3526 AArch64Operand::CreateToken(
"vl",
false, getLoc(), getContext()));
3538 if (
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal)) {
3539 Operands.
push_back(AArch64Operand::CreateImm(
3546 return Error(getLoc(),
"expected 'vl' or '#<imm>'");
3551 bool AArch64AsmParser::parseOperand(
OperandVector &Operands,
bool isCondCode,
3552 bool invertCondCode) {
3556 MatchOperandParserImpl(Operands, Mnemonic,
true);
3570 switch (getLexer().getKind()) {
3574 if (parseSymbolicImmVal(Expr))
3575 return Error(S,
"invalid operand");
3578 Operands.
push_back(AArch64Operand::CreateImm(Expr, S, E, getContext()));
3583 Operands.
push_back(AArch64Operand::CreateToken(
"[",
false, Loc,
3589 return parseOperand(Operands,
false,
false);
3592 return parseNeonVectorList(Operands);
3596 return parseCondCode(Operands, invertCondCode);
3599 if (!parseRegister(Operands))
3604 if (!parseOptionalMulOperand(Operands))
3617 if (getParser().parseExpression(IdVal))
3620 Operands.
push_back(AArch64Operand::CreateImm(IdVal, S, E, getContext()));
3632 bool isNegative =
false;
3647 uint64_t
IntVal = RealVal.bitcastToAPInt().getZExtValue();
3648 if (Mnemonic !=
"fcmp" && Mnemonic !=
"fcmpe" && Mnemonic !=
"fcmeq" &&
3649 Mnemonic !=
"fcmge" && Mnemonic !=
"fcmgt" && Mnemonic !=
"fcmle" &&
3650 Mnemonic !=
"fcmlt" && Mnemonic !=
"fcmne")
3651 return TokError(
"unexpected floating point literal");
3652 else if (IntVal != 0 || isNegative)
3653 return TokError(
"expected floating-point constant #0.0");
3657 AArch64Operand::CreateToken(
"#0",
false, S, getContext()));
3659 AArch64Operand::CreateToken(
".0",
false, S, getContext()));
3664 if (parseSymbolicImmVal(ImmVal))
3668 Operands.
push_back(AArch64Operand::CreateImm(ImmVal, S, E, getContext()));
3672 SMLoc Loc = getLoc();
3673 if (Mnemonic !=
"ldr")
3674 return TokError(
"unexpected token in operand");
3676 const MCExpr *SubExprVal;
3677 if (getParser().parseExpression(SubExprVal))
3680 if (Operands.
size() < 2 ||
3681 !
static_cast<AArch64Operand &
>(*Operands[1]).isScalarReg())
3682 return Error(Loc,
"Only valid when first operand is register");
3685 AArch64MCRegisterClasses[AArch64::GPR64allRegClassID].contains(
3691 if (isa<MCConstantExpr>(SubExprVal)) {
3692 uint64_t Imm = (cast<MCConstantExpr>(SubExprVal))->getValue();
3693 uint32_t ShiftAmt = 0, MaxShiftAmt = IsXReg ? 48 : 16;
3698 if (ShiftAmt <= MaxShiftAmt && Imm <= 0xFFFF) {
3699 Operands[0] = AArch64Operand::CreateToken(
"movz",
false, Loc, Ctx);
3700 Operands.
push_back(AArch64Operand::CreateImm(
3704 ShiftAmt,
true, S, E, Ctx));
3710 return Error(Loc,
"Immediate too large for register");
3714 getTargetStreamer().addConstantPoolEntry(SubExprVal, IsXReg ? 8 : 4, Loc);
3715 Operands.
push_back(AArch64Operand::CreateImm(CPLoc, S, E, Ctx));
3723 auto &AOp1 =
static_cast<const AArch64Operand&
>(Op1);
3724 auto &AOp2 =
static_cast<const AArch64Operand&
>(Op2);
3725 if (AOp1.getRegEqualityTy() == RegConstraintEqualityTy::EqualsReg &&
3726 AOp2.getRegEqualityTy() == RegConstraintEqualityTy::EqualsReg)
3729 assert(AOp1.isScalarReg() && AOp2.isScalarReg() &&
3730 "Testing equality of non-scalar registers not supported");
3733 if (AOp1.getRegEqualityTy() == EqualsSuperReg)
3735 if (AOp1.getRegEqualityTy() == EqualsSubReg)
3737 if (AOp2.getRegEqualityTy() == EqualsSuperReg)
3739 if (AOp2.getRegEqualityTy() == EqualsSubReg)
3752 .Case(
"beq",
"b.eq")
3753 .
Case(
"bne",
"b.ne")
3754 .
Case(
"bhs",
"b.hs")
3755 .
Case(
"bcs",
"b.cs")
3756 .
Case(
"blo",
"b.lo")
3757 .
Case(
"bcc",
"b.cc")
3758 .
Case(
"bmi",
"b.mi")
3759 .
Case(
"bpl",
"b.pl")
3760 .
Case(
"bvs",
"b.vs")
3761 .
Case(
"bvc",
"b.vc")
3762 .
Case(
"bhi",
"b.hi")
3763 .
Case(
"bls",
"b.ls")
3764 .
Case(
"bge",
"b.ge")
3765 .
Case(
"blt",
"b.lt")
3766 .
Case(
"bgt",
"b.gt")
3767 .
Case(
"ble",
"b.le")
3768 .
Case(
"bal",
"b.al")
3769 .
Case(
"bnv",
"b.nv")
3775 parseDirectiveReq(Name, NameLoc);
3782 size_t Start = 0, Next = Name.
find(
'.');
3787 if (Head ==
"ic" || Head ==
"dc" || Head ==
"at" || Head ==
"tlbi" ||
3788 Head ==
"cfp" || Head ==
"dvp" || Head ==
"cpp")
3789 return parseSysAlias(Head, NameLoc, Operands);
3792 AArch64Operand::CreateToken(Head,
false, NameLoc, getContext()));
3798 Next = Name.
find(
'.', Start + 1);
3799 Head = Name.
slice(Start + 1, Next);
3805 return Error(SuffixLoc,
"invalid condition code");
3807 AArch64Operand::CreateToken(
".",
true, SuffixLoc, getContext()));
3809 AArch64Operand::CreateCondCode(CC, NameLoc, NameLoc, getContext()));
3815 Next = Name.
find(
'.', Start + 1);
3816 Head = Name.
slice(Start, Next);
3820 AArch64Operand::CreateToken(Head,
true, SuffixLoc, getContext()));
3825 bool condCodeFourthOperand =
3826 (Head ==
"ccmp" || Head ==
"ccmn" || Head ==
"fccmp" ||
3827 Head ==
"fccmpe" || Head ==
"fcsel" || Head ==
"csel" ||
3828 Head ==
"csinc" || Head ==
"csinv" || Head ==
"csneg");
3836 bool condCodeSecondOperand = (Head ==
"cset" || Head ==
"csetm");
3837 bool condCodeThirdOperand =
3838 (Head ==
"cinc" || Head ==
"cinv" || Head ==
"cneg");
3846 if (parseOperand(Operands, (N == 4 && condCodeFourthOperand) ||
3847 (N == 3 && condCodeThirdOperand) ||
3848 (N == 2 && condCodeSecondOperand),
3849 condCodeSecondOperand || condCodeThirdOperand)) {
3865 AArch64Operand::CreateToken(
"]",
false, RLoc, getContext()));
3869 AArch64Operand::CreateToken(
"!",
false, ELoc, getContext()));
3882 assert((ZReg >= AArch64::Z0) && (ZReg <= AArch64::Z31));
3883 return (ZReg == ((Reg - AArch64::B0) + AArch64::Z0)) ||
3884 (ZReg == ((Reg - AArch64::H0) + AArch64::Z0)) ||
3885 (ZReg == ((Reg - AArch64::S0) + AArch64::Z0)) ||
3886 (ZReg == ((Reg - AArch64::D0) + AArch64::Z0)) ||
3887 (ZReg == ((Reg - AArch64::Q0) + AArch64::Z0)) ||
3888 (ZReg == ((Reg - AArch64::Z0) + AArch64::Z0));
3894 bool AArch64AsmParser::validateInstruction(
MCInst &Inst,
SMLoc &IDLoc,
3903 PrefixInfo
Prefix = NextPrefix;
3904 NextPrefix = PrefixInfo::CreateFromInst(Inst, MCID.
TSFlags);
3909 if (Prefix.isActive() &&
3916 return Error(IDLoc,
"instruction is unpredictable when following a" 3917 " movprfx, suggest replacing movprfx with mov");
3921 return Error(Loc[0],
"instruction is unpredictable when following a" 3922 " movprfx writing to a different destination");
3929 return Error(Loc[0],
"instruction is unpredictable when following a" 3930 " movprfx and destination also used as non-destructive" 3934 auto PPRRegClass = AArch64MCRegisterClasses[AArch64::PPRRegClassID];
3935 if (Prefix.isPredicated()) {
3949 return Error(IDLoc,
"instruction is unpredictable when following a" 3950 " predicated movprfx, suggest using unpredicated movprfx");
3954 return Error(IDLoc,
"instruction is unpredictable when following a" 3955 " predicated movprfx using a different general predicate");
3959 return Error(IDLoc,
"instruction is unpredictable when following a" 3960 " predicated movprfx with a different element size");
3968 case AArch64::LDPSWpre:
3969 case AArch64::LDPWpost:
3970 case AArch64::LDPWpre:
3971 case AArch64::LDPXpost:
3972 case AArch64::LDPXpre: {
3977 return Error(Loc[0],
"unpredictable LDP instruction, writeback base " 3978 "is also a destination");
3980 return Error(Loc[1],
"unpredictable LDP instruction, writeback base " 3981 "is also a destination");
3984 case AArch64::LDPDi:
3985 case AArch64::LDPQi:
3986 case AArch64::LDPSi:
3987 case AArch64::LDPSWi:
3988 case AArch64::LDPWi:
3989 case AArch64::LDPXi: {
3993 return Error(Loc[1],
"unpredictable LDP instruction, Rt2==Rt");
3996 case AArch64::LDPDpost:
3997 case AArch64::LDPDpre:
3998 case AArch64::LDPQpost:
3999 case AArch64::LDPQpre:
4000 case AArch64::LDPSpost:
4001 case AArch64::LDPSpre:
4002 case AArch64::LDPSWpost: {
4006 return Error(Loc[1],
"unpredictable LDP instruction, Rt2==Rt");
4009 case AArch64::STPDpost:
4010 case AArch64::STPDpre:
4011 case AArch64::STPQpost:
4012 case AArch64::STPQpre:
4013 case AArch64::STPSpost:
4014 case AArch64::STPSpre:
4015 case AArch64::STPWpost:
4016 case AArch64::STPWpre:
4017 case AArch64::STPXpost:
4018 case AArch64::STPXpre: {
4023 return Error(Loc[0],
"unpredictable STP instruction, writeback base " 4024 "is also a source");
4026 return Error(Loc[1],
"unpredictable STP instruction, writeback base " 4027 "is also a source");
4030 case AArch64::LDRBBpre:
4031 case AArch64::LDRBpre:
4032 case AArch64::LDRHHpre:
4033 case AArch64::LDRHpre:
4034 case AArch64::LDRSBWpre:
4035 case AArch64::LDRSBXpre:
4036 case AArch64::LDRSHWpre:
4037 case AArch64::LDRSHXpre:
4038 case AArch64::LDRSWpre:
4039 case AArch64::LDRWpre:
4040 case AArch64::LDRXpre:
4041 case AArch64::LDRBBpost:
4042 case AArch64::LDRBpost:
4043 case AArch64::LDRHHpost:
4044 case AArch64::LDRHpost:
4045 case AArch64::LDRSBWpost:
4046 case AArch64::LDRSBXpost:
4047 case AArch64::LDRSHWpost:
4048 case AArch64::LDRSHXpost:
4049 case AArch64::LDRSWpost:
4050 case AArch64::LDRWpost:
4051 case AArch64::LDRXpost: {
4055 return Error(Loc[0],
"unpredictable LDR instruction, writeback base " 4056 "is also a source");
4059 case AArch64::STRBBpost:
4060 case AArch64::STRBpost:
4061 case AArch64::STRHHpost:
4062 case AArch64::STRHpost:
4063 case AArch64::STRWpost:
4064 case AArch64::STRXpost:
4065 case AArch64::STRBBpre:
4066 case AArch64::STRBpre:
4067 case AArch64::STRHHpre:
4068 case AArch64::STRHpre:
4069 case AArch64::STRWpre:
4070 case AArch64::STRXpre: {
4074 return Error(Loc[0],
"unpredictable STR instruction, writeback base " 4075 "is also a source");
4078 case AArch64::STXRB:
4079 case AArch64::STXRH:
4080 case AArch64::STXRW:
4081 case AArch64::STXRX:
4082 case AArch64::STLXRB:
4083 case AArch64::STLXRH:
4084 case AArch64::STLXRW:
4085 case AArch64::STLXRX: {
4091 return Error(Loc[0],
4092 "unpredictable STXR instruction, status is also a source");
4095 case AArch64::STXPW:
4096 case AArch64::STXPX:
4097 case AArch64::STLXPW:
4098 case AArch64::STLXPX: {
4105 return Error(Loc[0],
4106 "unpredictable STXP instruction, status is also a source");
4116 case AArch64::ADDSWri:
4117 case AArch64::ADDSXri:
4118 case AArch64::ADDWri:
4119 case AArch64::ADDXri:
4120 case AArch64::SUBSWri:
4121 case AArch64::SUBSXri:
4122 case AArch64::SUBWri:
4123 case AArch64::SUBXri: {
4131 if (classifySymbolRef(Expr, ELFRefKind, DarwinRefKind, Addend)) {
4158 return Error(Loc.
back(),
"invalid immediate expression");
4171 unsigned VariantID = 0);
4173 bool AArch64AsmParser::showMatchError(
SMLoc Loc,
unsigned ErrCode,
4177 case Match_InvalidTiedOperand: {
4179 static_cast<const AArch64Operand &
>(*Operands[ErrorInfo])
4180 .getRegEqualityTy();
4182 case RegConstraintEqualityTy::EqualsSubReg:
4183 return Error(Loc,
"operand must be 64-bit form of destination register");
4184 case RegConstraintEqualityTy::EqualsSuperReg:
4185 return Error(Loc,
"operand must be 32-bit form of destination register");
4186 case RegConstraintEqualityTy::EqualsReg:
4187 return Error(Loc,
"operand must match destination register");
4191 case Match_MissingFeature:
4193 "instruction requires a CPU feature not currently enabled");
4194 case Match_InvalidOperand:
4195 return Error(Loc,
"invalid operand for instruction");
4196 case Match_InvalidSuffix:
4197 return Error(Loc,
"invalid type suffix for instruction");
4198 case Match_InvalidCondCode:
4199 return Error(Loc,
"expected AArch64 condition code");
4200 case Match_AddSubRegExtendSmall:
4202 "expected '[su]xt[bhw]' with optional integer in range [0, 4]");
4203 case Match_AddSubRegExtendLarge:
4205 "expected 'sxtx' 'uxtx' or 'lsl' with optional integer in range [0, 4]");
4206 case Match_AddSubSecondSource:
4208 "expected compatible register, symbol or integer in range [0, 4095]");
4209 case Match_LogicalSecondSource:
4210 return Error(Loc,
"expected compatible register or logical immediate");
4211 case Match_InvalidMovImm32Shift:
4212 return Error(Loc,
"expected 'lsl' with optional integer 0 or 16");
4213 case Match_InvalidMovImm64Shift:
4214 return Error(Loc,
"expected 'lsl' with optional integer 0, 16, 32 or 48");
4215 case Match_AddSubRegShift32:
4217 "expected 'lsl', 'lsr' or 'asr' with optional integer in range [0, 31]");
4218 case Match_AddSubRegShift64:
4220 "expected 'lsl', 'lsr' or 'asr' with optional integer in range [0, 63]");
4221 case Match_InvalidFPImm:
4223 "expected compatible register or floating-point constant");
4224 case Match_InvalidMemoryIndexedSImm6:
4225 return Error(Loc,
"index must be an integer in range [-32, 31].");
4226 case Match_InvalidMemoryIndexedSImm5:
4227 return Error(Loc,
"index must be an integer in range [-16, 15].");
4228 case Match_InvalidMemoryIndexed1SImm4:
4229 return Error(Loc,
"index must be an integer in range [-8, 7].");
4230 case Match_InvalidMemoryIndexed2SImm4:
4231 return Error(Loc,
"index must be a multiple of 2 in range [-16, 14].");
4232 case Match_InvalidMemoryIndexed3SImm4:
4233 return Error(Loc,
"index must be a multiple of 3 in range [-24, 21].");
4234 case Match_InvalidMemoryIndexed4SImm4:
4235 return Error(Loc,
"index must be a multiple of 4 in range [-32, 28].");
4236 case Match_InvalidMemoryIndexed16SImm4:
4237 return Error(Loc,
"index must be a multiple of 16 in range [-128, 112].");
4238 case Match_InvalidMemoryIndexed1SImm6:
4239 return Error(Loc,
"index must be an integer in range [-32, 31].");
4240 case Match_InvalidMemoryIndexedSImm8:
4241 return Error(Loc,
"index must be an integer in range [-128, 127].");
4242 case Match_InvalidMemoryIndexedSImm9:
4243 return Error(Loc,
"index must be an integer in range [-256, 255].");
4244 case Match_InvalidMemoryIndexed16SImm9:
4245 return Error(Loc,
"index must be a multiple of 16 in range [-4096, 4080].");
4246 case Match_InvalidMemoryIndexed8SImm10:
4247 return Error(Loc,
"index must be a multiple of 8 in range [-4096, 4088].");
4248 case Match_InvalidMemoryIndexed4SImm7:
4249 return Error(Loc,
"index must be a multiple of 4 in range [-256, 252].");
4250 case Match_InvalidMemoryIndexed8SImm7:
4251 return Error(Loc,
"index must be a multiple of 8 in range [-512, 504].");
4252 case Match_InvalidMemoryIndexed16SImm7:
4253 return Error(Loc,
"index must be a multiple of 16 in range [-1024, 1008].");
4254 case Match_InvalidMemoryIndexed8UImm5:
4255 return Error(Loc,
"index must be a multiple of 8 in range [0, 248].");
4256 case Match_InvalidMemoryIndexed4UImm5:
4257 return Error(Loc,
"index must be a multiple of 4 in range [0, 124].");
4258 case Match_InvalidMemoryIndexed2UImm5:
4259 return Error(Loc,
"index must be a multiple of 2 in range [0, 62].");
4260 case Match_InvalidMemoryIndexed8UImm6:
4261 return Error(Loc,
"index must be a multiple of 8 in range [0, 504].");
4262 case Match_InvalidMemoryIndexed16UImm6:
4263 return Error(Loc,
"index must be a multiple of 16 in range [0, 1008].");
4264 case Match_InvalidMemoryIndexed4UImm6:
4265 return Error(Loc,
"index must be a multiple of 4 in range [0, 252].");
4266 case Match_InvalidMemoryIndexed2UImm6:
4267 return Error(Loc,
"index must be a multiple of 2 in range [0, 126].");
4268 case Match_InvalidMemoryIndexed1UImm6:
4269 return Error(Loc,
"index must be in range [0, 63].");
4270 case Match_InvalidMemoryWExtend8:
4272 "expected 'uxtw' or 'sxtw' with optional shift of #0");
4273 case Match_InvalidMemoryWExtend16:
4275 "expected 'uxtw' or 'sxtw' with optional shift of #0 or #1");
4276 case Match_InvalidMemoryWExtend32:
4278 "expected 'uxtw' or 'sxtw' with optional shift of #0 or #2");
4279 case Match_InvalidMemoryWExtend64:
4281 "expected 'uxtw' or 'sxtw' with optional shift of #0 or #3");
4282 case Match_InvalidMemoryWExtend128:
4284 "expected 'uxtw' or 'sxtw' with optional shift of #0 or #4");
4285 case Match_InvalidMemoryXExtend8:
4287 "expected 'lsl' or 'sxtx' with optional shift of #0");
4288 case Match_InvalidMemoryXExtend16:
4290 "expected 'lsl' or 'sxtx' with optional shift of #0 or #1");
4291 case Match_InvalidMemoryXExtend32:
4293 "expected 'lsl' or 'sxtx' with optional shift of #0 or #2");
4294 case Match_InvalidMemoryXExtend64:
4296 "expected 'lsl' or 'sxtx' with optional shift of #0 or #3");
4297 case Match_InvalidMemoryXExtend128:
4299 "expected 'lsl' or 'sxtx' with optional shift of #0 or #4");
4300 case Match_InvalidMemoryIndexed1:
4301 return Error(Loc,
"index must be an integer in range [0, 4095].");
4302 case Match_InvalidMemoryIndexed2:
4303 return Error(Loc,
"index must be a multiple of 2 in range [0, 8190].");
4304 case Match_InvalidMemoryIndexed4:
4305 return Error(Loc,
"index must be a multiple of 4 in range [0, 16380].");
4306 case Match_InvalidMemoryIndexed8:
4307 return Error(Loc,
"index must be a multiple of 8 in range [0, 32760].");
4308 case Match_InvalidMemoryIndexed16:
4309 return Error(Loc,
"index must be a multiple of 16 in range [0, 65520].");
4310 case Match_InvalidImm0_1:
4311 return Error(Loc,
"immediate must be an integer in range [0, 1].");
4312 case Match_InvalidImm0_7:
4313 return Error(Loc,
"immediate must be an integer in range [0, 7].");
4314 case Match_InvalidImm0_15:
4315 return Error(Loc,
"immediate must be an integer in range [0, 15].");
4316 case Match_InvalidImm0_31:
4317 return Error(Loc,
"immediate must be an integer in range [0, 31].");
4318 case Match_InvalidImm0_63:
4319 return Error(Loc,
"immediate must be an integer in range [0, 63].");
4320 case Match_InvalidImm0_127:
4321 return Error(Loc,
"immediate must be an integer in range [0, 127].");
4322 case Match_InvalidImm0_255:
4323 return Error(Loc,
"immediate must be an integer in range [0, 255].");
4324 case Match_InvalidImm0_65535:
4325 return Error(Loc,
"immediate must be an integer in range [0, 65535].");
4326 case Match_InvalidImm1_8:
4327 return Error(Loc,
"immediate must be an integer in range [1, 8].");
4328 case Match_InvalidImm1_16:
4329 return Error(Loc,
"immediate must be an integer in range [1, 16].");
4330 case Match_InvalidImm1_32:
4331 return Error(Loc,
"immediate must be an integer in range [1, 32].");
4332 case Match_InvalidImm1_64:
4333 return Error(Loc,
"immediate must be an integer in range [1, 64].");
4334 case Match_InvalidSVEAddSubImm8:
4335 return Error(Loc,
"immediate must be an integer in range [0, 255]" 4336 " with a shift amount of 0");
4337 case Match_InvalidSVEAddSubImm16:
4338 case Match_InvalidSVEAddSubImm32:
4339 case Match_InvalidSVEAddSubImm64:
4340 return Error(Loc,
"immediate must be an integer in range [0, 255] or a " 4341 "multiple of 256 in range [256, 65280]");
4342 case Match_InvalidSVECpyImm8:
4343 return Error(Loc,
"immediate must be an integer in range [-128, 255]" 4344 " with a shift amount of 0");
4345 case Match_InvalidSVECpyImm16:
4346 return Error(Loc,
"immediate must be an integer in range [-128, 127] or a " 4347 "multiple of 256 in range [-32768, 65280]");
4348 case Match_InvalidSVECpyImm32:
4349 case Match_InvalidSVECpyImm64:
4350 return Error(Loc,
"immediate must be an integer in range [-128, 127] or a " 4351 "multiple of 256 in range [-32768, 32512]");
4352 case Match_InvalidIndexRange1_1:
4353 return Error(Loc,
"expected lane specifier '[1]'");
4354 case Match_InvalidIndexRange0_15:
4355 return Error(Loc,
"vector lane must be an integer in range [0, 15].");
4356 case Match_InvalidIndexRange0_7:
4357 return Error(Loc,
"vector lane must be an integer in range [0, 7].");
4358 case Match_InvalidIndexRange0_3:
4359 return Error(Loc,
"vector lane must be an integer in range [0, 3].");
4360 case Match_InvalidIndexRange0_1:
4361 return Error(Loc,
"vector lane must be an integer in range [0, 1].");
4362 case Match_InvalidSVEIndexRange0_63:
4363 return Error(Loc,
"vector lane must be an integer in range [0, 63].");
4364 case Match_InvalidSVEIndexRange0_31:
4365 return Error(Loc,
"vector lane must be an integer in range [0, 31].");
4366 case Match_InvalidSVEIndexRange0_15:
4367 return Error(Loc,
"vector lane must be an integer in range [0, 15].");
4368 case Match_InvalidSVEIndexRange0_7:
4369 return Error(Loc,
"vector lane must be an integer in range [0, 7].");
4370 case Match_InvalidSVEIndexRange0_3:
4371 return Error(Loc,
"vector lane must be an integer in range [0, 3].");
4372 case Match_InvalidLabel:
4373 return Error(Loc,
"expected label or encodable integer pc offset");
4375 return Error(Loc,
"expected readable system register");
4377 return Error(Loc,
"expected writable system register or pstate");
4378 case Match_InvalidComplexRotationEven:
4379 return Error(Loc,
"complex rotation must be 0, 90, 180 or 270.");
4380 case Match_InvalidComplexRotationOdd:
4381 return Error(Loc,
"complex rotation must be 90 or 270.");
4382 case Match_MnemonicFail: {
4384 ((AArch64Operand &)*Operands[0]).
getToken(),
4385 ComputeAvailableFeatures(STI->getFeatureBits()));
4386 return Error(Loc,
"unrecognized instruction mnemonic" + Suggestion);
4388 case Match_InvalidGPR64shifted8:
4389 return Error(Loc,
"register must be x0..x30 or xzr, without shift");
4390 case Match_InvalidGPR64shifted16:
4391 return Error(Loc,
"register must be x0..x30 or xzr, with required shift 'lsl #1'");
4392 case Match_InvalidGPR64shifted32:
4393 return Error(Loc,
"register must be x0..x30 or xzr, with required shift 'lsl #2'");
4394 case Match_InvalidGPR64shifted64:
4395 return Error(Loc,
"register must be x0..x30 or xzr, with required shift 'lsl #3'");
4396 case Match_InvalidGPR64NoXZRshifted8:
4397 return Error(Loc,
"register must be x0..x30 without shift");
4398 case Match_InvalidGPR64NoXZRshifted16:
4399 return Error(Loc,
"register must be x0..x30 with required shift 'lsl #1'");
4400 case Match_InvalidGPR64NoXZRshifted32:
4401 return Error(Loc,
"register must be x0..x30 with required shift 'lsl #2'");
4402 case Match_InvalidGPR64NoXZRshifted64:
4403 return Error(Loc,
"register must be x0..x30 with required shift 'lsl #3'");
4404 case Match_InvalidZPR32UXTW8:
4405 case Match_InvalidZPR32SXTW8:
4406 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].s, (uxtw|sxtw)'");
4407 case Match_InvalidZPR32UXTW16:
4408 case Match_InvalidZPR32SXTW16:
4409 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].s, (uxtw|sxtw) #1'");
4410 case Match_InvalidZPR32UXTW32:
4411 case Match_InvalidZPR32SXTW32:
4412 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].s, (uxtw|sxtw) #2'");
4413 case Match_InvalidZPR32UXTW64:
4414 case Match_InvalidZPR32SXTW64:
4415 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].s, (uxtw|sxtw) #3'");
4416 case Match_InvalidZPR64UXTW8:
4417 case Match_InvalidZPR64SXTW8:
4418 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].d, (uxtw|sxtw)'");
4419 case Match_InvalidZPR64UXTW16:
4420 case Match_InvalidZPR64SXTW16:
4421 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].d, (lsl|uxtw|sxtw) #1'");
4422 case Match_InvalidZPR64UXTW32:
4423 case Match_InvalidZPR64SXTW32:
4424 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].d, (lsl|uxtw|sxtw) #2'");
4425 case Match_InvalidZPR64UXTW64:
4426 case Match_InvalidZPR64SXTW64:
4427 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].d, (lsl|uxtw|sxtw) #3'");
4428 case Match_InvalidZPR32LSL8:
4429 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].s'");
4430 case Match_InvalidZPR32LSL16:
4431 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].s, lsl #1'");
4432 case Match_InvalidZPR32LSL32:
4433 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].s, lsl #2'");
4434 case Match_InvalidZPR32LSL64:
4435 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].s, lsl #3'");
4436 case Match_InvalidZPR64LSL8:
4437 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].d'");
4438 case Match_InvalidZPR64LSL16:
4439 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].d, lsl #1'");
4440 case Match_InvalidZPR64LSL32:
4441 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].d, lsl #2'");
4442 case Match_InvalidZPR64LSL64:
4443 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].d, lsl #3'");
4444 case Match_InvalidZPR0:
4445 return Error(Loc,
"expected register without element width suffix");
4446 case Match_InvalidZPR8:
4447 case Match_InvalidZPR16:
4448 case Match_InvalidZPR32:
4449 case Match_InvalidZPR64:
4450 case Match_InvalidZPR128:
4451 return Error(Loc,
"invalid element width");
4452 case Match_InvalidZPR_3b8:
4453 return Error(Loc,
"Invalid restricted vector register, expected z0.b..z7.b");
4454 case Match_InvalidZPR_3b16:
4455 return Error(Loc,
"Invalid restricted vector register, expected z0.h..z7.h");
4456 case Match_InvalidZPR_3b32:
4457 return Error(Loc,
"Invalid restricted vector register, expected z0.s..z7.s");
4458 case Match_InvalidZPR_4b16:
4459 return Error(Loc,
"Invalid restricted vector register, expected z0.h..z15.h");
4460 case Match_InvalidZPR_4b32:
4461 return Error(Loc,
"Invalid restricted vector register, expected z0.s..z15.s");
4462 case Match_InvalidZPR_4b64:
4463 return Error(Loc,
"Invalid restricted vector register, expected z0.d..z15.d");
4464 case Match_InvalidSVEPattern:
4465 return Error(Loc,
"invalid predicate pattern");
4466 case Match_InvalidSVEPredicateAnyReg:
4467 case Match_InvalidSVEPredicateBReg:
4468 case Match_InvalidSVEPredicateHReg:
4469 case Match_InvalidSVEPredicateSReg:
4470 case Match_InvalidSVEPredicateDReg:
4471 return Error(Loc,
"invalid predicate register.");
4472 case Match_InvalidSVEPredicate3bAnyReg:
4473 return Error(Loc,
"invalid restricted predicate register, expected p0..p7 (without element suffix)");
4474 case Match_InvalidSVEPredicate3bBReg:
4475 return Error(Loc,
"invalid restricted predicate register, expected p0.b..p7.b");
4476 case Match_InvalidSVEPredicate3bHReg:
4477 return Error(Loc,
"invalid restricted predicate register, expected p0.h..p7.h");
4478 case Match_InvalidSVEPredicate3bSReg:
4479 return Error(Loc,
"invalid restricted predicate register, expected p0.s..p7.s");
4480 case Match_InvalidSVEPredicate3bDReg:
4481 return Error(Loc,
"invalid restricted predicate register, expected p0.d..p7.d");
4482 case Match_InvalidSVEExactFPImmOperandHalfOne:
4483 return Error(Loc,
"Invalid floating point constant, expected 0.5 or 1.0.");
4484 case Match_InvalidSVEExactFPImmOperandHalfTwo:
4485 return Error(Loc,
"Invalid floating point constant, expected 0.5 or 2.0.");
4486 case Match_InvalidSVEExactFPImmOperandZeroOne:
4487 return Error(Loc,
"Invalid floating point constant, expected 0.0 or 1.0.");
4495 bool AArch64AsmParser::MatchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
4498 uint64_t &ErrorInfo,
4499 bool MatchingInlineAsm) {
4500 assert(!Operands.
empty() &&
"Unexpect empty operand list!");
4501 AArch64Operand &
Op =
static_cast<AArch64Operand &
>(*Operands[0]);
4502 assert(Op.isToken() &&
"Leading operand should always be a mnemonic!");
4505 unsigned NumOperands = Operands.
size();
4507 if (NumOperands == 4 && Tok ==
"lsl") {
4508 AArch64Operand &Op2 =
static_cast<AArch64Operand &
>(*Operands[2]);
4509 AArch64Operand &Op3 =
static_cast<AArch64Operand &
>(*Operands[3]);
4510 if (Op2.isScalarReg() && Op3.isImm()) {
4513 uint64_t Op3Val = Op3CE->
getValue();
4514 uint64_t NewOp3Val = 0;
4515 uint64_t NewOp4Val = 0;
4516 if (AArch64MCRegisterClasses[AArch64::GPR32allRegClassID].
contains(
4518 NewOp3Val = (32 - Op3Val) & 0x1f;
4519 NewOp4Val = 31 - Op3Val;
4521 NewOp3Val = (64 - Op3Val) & 0x3f;
4522 NewOp4Val = 63 - Op3Val;
4528 Operands[0] = AArch64Operand::CreateToken(
4529 "ubfm",
false, Op.getStartLoc(), getContext());
4530 Operands.
push_back(AArch64Operand::CreateImm(
4531 NewOp4, Op3.getStartLoc(), Op3.getEndLoc(), getContext()));
4532 Operands[3] = AArch64Operand::CreateImm(NewOp3, Op3.getStartLoc(),
4533 Op3.getEndLoc(), getContext());
4536 }
else if (NumOperands == 4 && Tok ==
"bfc") {
4538 AArch64Operand &Op1 =
static_cast<AArch64Operand &
>(*Operands[1]);
4539 AArch64Operand LSBOp =
static_cast<AArch64Operand &
>(*Operands[2]);
4540 AArch64Operand WidthOp =
static_cast<AArch64Operand &
>(*Operands[3]);
4542 if (Op1.isScalarReg() && LSBOp.isImm() && WidthOp.isImm()) {
4546 if (LSBCE && WidthCE) {
4548 uint64_t
Width = WidthCE->getValue();
4550 uint64_t RegWidth = 0;
4551 if (AArch64MCRegisterClasses[AArch64::GPR64allRegClassID].
contains(
4557 if (LSB >= RegWidth)
4558 return Error(LSBOp.getStartLoc(),
4559 "expected integer in range [0, 31]");
4560 if (Width < 1 || Width > RegWidth)
4561 return Error(WidthOp.getStartLoc(),
4562 "expected integer in range [1, 32]");
4566 ImmR = (32 - LSB) & 0x1f;
4568 ImmR = (64 - LSB) & 0x3f;
4570 uint64_t ImmS = Width - 1;
4572 if (ImmR != 0 && ImmS >= ImmR)
4573 return Error(WidthOp.getStartLoc(),
4574 "requested insert overflows register");
4578 Operands[0] = AArch64Operand::CreateToken(
4579 "bfm",
false, Op.getStartLoc(), getContext());
4580 Operands[2] = AArch64Operand::CreateReg(
4583 Operands[3] = AArch64Operand::CreateImm(
4584 ImmRExpr, LSBOp.getStartLoc(), LSBOp.getEndLoc(), getContext());
4585 Operands.emplace_back(
4586 AArch64Operand::CreateImm(ImmSExpr, WidthOp.getStartLoc(),
4587 WidthOp.getEndLoc(), getContext()));
4590 }
else if (NumOperands == 5) {
4593 if (Tok ==
"bfi" || Tok ==
"sbfiz" || Tok ==
"ubfiz") {
4594 AArch64Operand &Op1 =
static_cast<AArch64Operand &
>(*Operands[1]);
4595 AArch64Operand &Op3 =
static_cast<AArch64Operand &
>(*Operands[3]);
4596 AArch64Operand &Op4 =
static_cast<AArch64Operand &
>(*Operands[4]);
4598 if (Op1.isScalarReg() && Op3.isImm() && Op4.isImm()) {
4602 if (Op3CE && Op4CE) {
4603 uint64_t Op3Val = Op3CE->
getValue();
4604 uint64_t Op4Val = Op4CE->getValue();
4606 uint64_t RegWidth = 0;
4607 if (AArch64MCRegisterClasses[AArch64::GPR64allRegClassID].
contains(
4613 if (Op3Val >= RegWidth)
4614 return Error(Op3.getStartLoc(),
4615 "expected integer in range [0, 31]");
4616 if (Op4Val < 1 || Op4Val > RegWidth)
4617 return Error(Op4.getStartLoc(),
4618 "expected integer in range [1, 32]");
4620 uint64_t NewOp3Val = 0;
4622 NewOp3Val = (32 - Op3Val) & 0x1f;
4624 NewOp3Val = (64 - Op3Val) & 0x3f;
4626 uint64_t NewOp4Val = Op4Val - 1;
4628 if (NewOp3Val != 0 && NewOp4Val >= NewOp3Val)
4629 return Error(Op4.getStartLoc(),
4630 "requested insert overflows register");
4636 Operands[3] = AArch64Operand::CreateImm(
4637 NewOp3, Op3.getStartLoc(), Op3.getEndLoc(), getContext());
4638 Operands[4] = AArch64Operand::CreateImm(
4639 NewOp4, Op4.getStartLoc(), Op4.getEndLoc(), getContext());
4641 Operands[0] = AArch64Operand::CreateToken(
4642 "bfm",
false, Op.getStartLoc(), getContext());
4643 else if (Tok ==
"sbfiz")
4644 Operands[0] = AArch64Operand::CreateToken(
4645 "sbfm",
false, Op.getStartLoc(), getContext());
4646 else if (Tok ==
"ubfiz")
4647 Operands[0] = AArch64Operand::CreateToken(
4648 "ubfm",
false, Op.getStartLoc(), getContext());
4656 }
else if (NumOperands == 5 &&
4657 (Tok ==
"bfxil" || Tok ==
"sbfx" || Tok ==
"ubfx")) {
4658 AArch64Operand &Op1 =
static_cast<AArch64Operand &
>(*Operands[1]);
4659 AArch64Operand &Op3 =
static_cast<AArch64Operand &
>(*Operands[3]);
4660 AArch64Operand &Op4 =
static_cast<AArch64Operand &
>(*Operands[4]);
4662 if (Op1.isScalarReg() && Op3.isImm() && Op4.isImm()) {
4666 if (Op3CE && Op4CE) {
4667 uint64_t Op3Val = Op3CE->
getValue();
4668 uint64_t Op4Val = Op4CE->getValue();
4670 uint64_t RegWidth = 0;
4671 if (AArch64MCRegisterClasses[AArch64::GPR64allRegClassID].
contains(
4677 if (Op3Val >= RegWidth)
4678 return Error(Op3.getStartLoc(),
4679 "expected integer in range [0, 31]");
4680 if (Op4Val < 1 || Op4Val > RegWidth)
4681 return Error(Op4.getStartLoc(),
4682 "expected integer in range [1, 32]");
4684 uint64_t NewOp4Val = Op3Val + Op4Val - 1;
4686 if (NewOp4Val >= RegWidth || NewOp4Val < Op3Val)
4687 return Error(Op4.getStartLoc(),
4688 "requested extract overflows register");
4692 Operands[4] = AArch64Operand::CreateImm(
4693 NewOp4, Op4.getStartLoc(), Op4.getEndLoc(), getContext());
4695 Operands[0] = AArch64Operand::CreateToken(
4696 "bfm",
false, Op.getStartLoc(), getContext());
4697 else if (Tok ==
"sbfx")
4698 Operands[0] = AArch64Operand::CreateToken(
4699 "sbfm",
false, Op.getStartLoc(), getContext());
4700 else if (Tok ==
"ubfx")
4701 Operands[0] = AArch64Operand::CreateToken(
4702 "ubfm",
false, Op.getStartLoc(), getContext());
4714 if (getSTI().getFeatureBits()[AArch64::FeatureZCZeroingFPWorkaround] &&
4715 NumOperands == 4 && Tok ==
"movi") {
4716 AArch64Operand &Op1 =
static_cast<AArch64Operand &
>(*Operands[1]);
4717 AArch64Operand &Op2 =
static_cast<AArch64Operand &
>(*Operands[2]);
4718 AArch64Operand &Op3 =
static_cast<AArch64Operand &
>(*Operands[3]);
4719 if ((Op1.isToken() && Op2.isNeonVectorReg() && Op3.isImm()) ||
4720 (Op1.isNeonVectorReg() && Op2.isToken() && Op3.isImm())) {
4721 StringRef Suffix = Op1.isToken() ? Op1.getToken() : Op2.getToken();
4722 if (Suffix.
lower() ==
".2d" &&
4723 cast<MCConstantExpr>(Op3.getImm())->getValue() == 0) {
4724 Warning(IDLoc,
"instruction movi.2d with immediate #0 may not function" 4725 " correctly on this CPU, converting to equivalent movi.16b");
4727 unsigned Idx = Op1.isToken() ? 1 : 2;
4728 Operands[Idx] = AArch64Operand::CreateToken(
".16b",
false, IDLoc,
4737 if (NumOperands == 3 && (Tok ==
"sxtw" || Tok ==
"uxtw")) {
4740 AArch64Operand &Op =
static_cast<AArch64Operand &
>(*Operands[2]);
4741 if (Op.isScalarReg()) {
4744 Op.getStartLoc(), Op.getEndLoc(),
4749 else if (NumOperands == 3 && (Tok ==
"sxtb" || Tok ==
"sxth")) {
4750 AArch64Operand &Op =
static_cast<AArch64Operand &
>(*Operands[1]);
4751 if (Op.isScalarReg() &&
4752 AArch64MCRegisterClasses[AArch64::GPR64allRegClassID].contains(
4756 AArch64Operand &Op =
static_cast<AArch64Operand &
>(*Operands[2]);
4757 if (Op.isScalarReg()) {
4761 Op.getEndLoc(), getContext());
4766 else if (NumOperands == 3 && (Tok ==
"uxtb" || Tok ==
"uxth")) {
4767 AArch64Operand &Op =
static_cast<AArch64Operand &
>(*Operands[1]);
4768 if (Op.isScalarReg() &&
4769 AArch64MCRegisterClasses[AArch64::GPR64allRegClassID].contains(
4773 AArch64Operand &Op =
static_cast<AArch64Operand &
>(*Operands[1]);
4774 if (Op.isScalarReg()) {
4778 Op.getEndLoc(), getContext());
4787 unsigned MatchResult =
4788 MatchInstructionImpl(Operands, Inst, ErrorInfo, MissingFeatures,
4789 MatchingInlineAsm, 1);
4793 if (MatchResult != Match_Success) {
4796 auto ShortFormNEONErrorInfo = ErrorInfo;
4797 auto ShortFormNEONMatchResult = MatchResult;
4798 auto ShortFormNEONMissingFeatures = MissingFeatures;
4801 MatchInstructionImpl(Operands, Inst, ErrorInfo, MissingFeatures,
4802 MatchingInlineAsm, 0);
4807 if (MatchResult == Match_InvalidOperand && ErrorInfo == 1 &&
4808 Operands.
size() > 1 && ((AArch64Operand &)*Operands[1]).isToken() &&
4809 ((AArch64Operand &)*Operands[1]).isTokenSuffix()) {
4810 MatchResult = ShortFormNEONMatchResult;
4811 ErrorInfo = ShortFormNEONErrorInfo;
4812 MissingFeatures = ShortFormNEONMissingFeatures;
4816 switch (MatchResult) {
4817 case Match_Success: {
4820 NumOperands = Operands.
size();
4821 for (
unsigned i = 1; i < NumOperands; ++i)
4822 OperandLocs.
push_back(Operands[i]->getStartLoc());
4823 if (validateInstruction(Inst, IDLoc, OperandLocs))
4830 case Match_MissingFeature: {
4831 assert(MissingFeatures.
any() &&
"Unknown missing feature!");
4834 std::string Msg =
"instruction requires:";
4835 for (
unsigned i = 0,
e = MissingFeatures.
size(); i !=
e; ++i) {
4836 if (MissingFeatures[i]) {
4841 return Error(IDLoc, Msg);
4843 case Match_MnemonicFail:
4844 return showMatchError(IDLoc, MatchResult, ErrorInfo, Operands);
4845 case Match_InvalidOperand: {
4846 SMLoc ErrorLoc = IDLoc;
4848 if (ErrorInfo != ~0ULL) {
4849 if (ErrorInfo >= Operands.
size())
4850 return Error(IDLoc,
"too few operands for instruction",
4851 SMRange(IDLoc, getTok().getLoc()));
4853 ErrorLoc = ((AArch64Operand &)*Operands[ErrorInfo]).getStartLoc();
4854 if (ErrorLoc ==
SMLoc())
4859 if (((AArch64Operand &)*Operands[ErrorInfo]).isToken() &&
4860 ((AArch64Operand &)*Operands[ErrorInfo]).isTokenSuffix())
4861 MatchResult = Match_InvalidSuffix;
4863 return showMatchError(ErrorLoc, MatchResult, ErrorInfo, Operands);
4865 case Match_InvalidTiedOperand:
4866 case Match_InvalidMemoryIndexed1:
4867 case Match_InvalidMemoryIndexed2:
4868 case Match_InvalidMemoryIndexed4:
4869 case Match_InvalidMemoryIndexed8:
4870 case Match_InvalidMemoryIndexed16:
4871 case Match_InvalidCondCode:
4872 case Match_AddSubRegExtendSmall:
4873 case Match_AddSubRegExtendLarge:
4874 case Match_AddSubSecondSource:
4875 case Match_LogicalSecondSource:
4876 case Match_AddSubRegShift32:
4877 case Match_AddSubRegShift64:
4878 case Match_InvalidMovImm32Shift:
4879 case Match_InvalidMovImm64Shift:
4880 case Match_InvalidFPImm:
4881 case Match_InvalidMemoryWExtend8:
4882 case Match_InvalidMemoryWExtend16:
4883 case Match_InvalidMemoryWExtend32:
4884 case Match_InvalidMemoryWExtend64:
4885 case Match_InvalidMemoryWExtend128:
4886 case Match_InvalidMemoryXExtend8:
4887 case Match_InvalidMemoryXExtend16:
4888 case Match_InvalidMemoryXExtend32:
4889 case Match_InvalidMemoryXExtend64:
4890 case Match_InvalidMemoryXExtend128:
4891 case Match_InvalidMemoryIndexed1SImm4:
4892 case Match_InvalidMemoryIndexed2SImm4:
4893 case Match_InvalidMemoryIndexed3SImm4:
4894 case Match_InvalidMemoryIndexed4SImm4:
4895 case Match_InvalidMemoryIndexed1SImm6:
4896 case Match_InvalidMemoryIndexed16SImm4:
4897 case Match_InvalidMemoryIndexed4SImm7:
4898 case Match_InvalidMemoryIndexed8SImm7:
4899 case Match_InvalidMemoryIndexed16SImm7:
4900 case Match_InvalidMemoryIndexed8UImm5:
4901 case Match_InvalidMemoryIndexed4UImm5:
4902 case Match_InvalidMemoryIndexed2UImm5:
4903 case Match_InvalidMemoryIndexed1UImm6:
4904 case Match_InvalidMemoryIndexed2UImm6:
4905 case Match_InvalidMemoryIndexed4UImm6:
4906 case Match_InvalidMemoryIndexed8UImm6:
4907 case Match_InvalidMemoryIndexed16UImm6:
4908 case Match_InvalidMemoryIndexedSImm6:
4909 case Match_InvalidMemoryIndexedSImm5:
4910 case Match_InvalidMemoryIndexedSImm8:
4911 case Match_InvalidMemoryIndexedSImm9:
4912 case Match_InvalidMemoryIndexed16SImm9:
4913 case Match_InvalidMemoryIndexed8SImm10:
4914 case Match_InvalidImm0_1:
4915 case Match_InvalidImm0_7:
4916 case Match_InvalidImm0_15:
4917 case Match_InvalidImm0_31:
4918 case Match_InvalidImm0_63:
4919 case Match_InvalidImm0_127:
4920 case Match_InvalidImm0_255:
4921 case Match_InvalidImm0_65535:
4922 case Match_InvalidImm1_8:
4923 case Match_InvalidImm1_16:
4924 case Match_InvalidImm1_32:
4925 case Match_InvalidImm1_64:
4926 case Match_InvalidSVEAddSubImm8:
4927 case Match_InvalidSVEAddSubImm16:
4928 case Match_InvalidSVEAddSubImm32:
4929 case Match_InvalidSVEAddSubImm64:
4930 case Match_InvalidSVECpyImm8:
4931 case Match_InvalidSVECpyImm16:
4932 case Match_InvalidSVECpyImm32:
4933 case Match_InvalidSVECpyImm64:
4934 case Match_InvalidIndexRange1_1:
4935 case Match_InvalidIndexRange0_15:
4936 case Match_InvalidIndexRange0_7:
4937 case Match_InvalidIndexRange0_3:
4938 case Match_InvalidIndexRange0_1:
4939 case Match_InvalidSVEIndexRange0_63:
4940 case Match_InvalidSVEIndexRange0_31:
4941 case Match_InvalidSVEIndexRange0_15:
4942 case Match_InvalidSVEIndexRange0_7:
4943 case Match_InvalidSVEIndexRange0_3:
4944 case Match_InvalidLabel:
4945 case Match_InvalidComplexRotationEven:
4946 case Match_InvalidComplexRotationOdd:
4947 case Match_InvalidGPR64shifted8:
4948 case Match_InvalidGPR64shifted16:
4949 case Match_InvalidGPR64shifted32:
4950 case Match_InvalidGPR64shifted64:
4951 case Match_InvalidGPR64NoXZRshifted8:
4952 case Match_InvalidGPR64NoXZRshifted16:
4953 case Match_InvalidGPR64NoXZRshifted32:
4954 case Match_InvalidGPR64NoXZRshifted64:
4955 case Match_InvalidZPR32UXTW8:
4956 case Match_InvalidZPR32UXTW16:
4957 case Match_InvalidZPR32UXTW32:
4958 case Match_InvalidZPR32UXTW64:
4959 case Match_InvalidZPR32SXTW8:
4960 case Match_InvalidZPR32SXTW16:
4961 case Match_InvalidZPR32SXTW32:
4962 case Match_InvalidZPR32SXTW64:
4963 case Match_InvalidZPR64UXTW8:
4964 case Match_InvalidZPR64SXTW8:
4965 case Match_InvalidZPR64UXTW16:
4966 case Match_InvalidZPR64SXTW16:
4967 case Match_InvalidZPR64UXTW32:
4968 case Match_InvalidZPR64SXTW32:
4969 case Match_InvalidZPR64UXTW64:
4970 case Match_InvalidZPR64SXTW64:
4971 case Match_InvalidZPR32LSL8:
4972 case Match_InvalidZPR32LSL16:
4973 case Match_InvalidZPR32LSL32:
4974 case Match_InvalidZPR32LSL64:
4975 case Match_InvalidZPR64LSL8:
4976 case Match_InvalidZPR64LSL16:
4977 case Match_InvalidZPR64LSL32:
4978 case Match_InvalidZPR64LSL64:
4979 case Match_InvalidZPR0:
4980 case Match_InvalidZPR8:
4981 case Match_InvalidZPR16:
4982 case Match_InvalidZPR32:
4983 case Match_InvalidZPR64:
4984 case Match_InvalidZPR128:
4985 case Match_InvalidZPR_3b8:
4986 case Match_InvalidZPR_3b16:
4987 case Match_InvalidZPR_3b32:
4988 case Match_InvalidZPR_4b16:
4989 case Match_InvalidZPR_4b32:
4990 case Match_InvalidZPR_4b64:
4991 case Match_InvalidSVEPredicateAnyReg:
4992 case Match_InvalidSVEPattern:
4993 case Match_InvalidSVEPredicateBReg:
4994 case Match_InvalidSVEPredicateHReg:
4995 case Match_InvalidSVEPredicateSReg:
4996 case Match_InvalidSVEPredicateDReg:
4997 case Match_InvalidSVEPredicate3bAnyReg:
4998 case Match_InvalidSVEPredicate3bBReg:
4999 case Match_InvalidSVEPredicate3bHReg:
5000 case Match_InvalidSVEPredicate3bSReg:
5001 case Match_InvalidSVEPredicate3bDReg:
5002 case Match_InvalidSVEExactFPImmOperandHalfOne:
5003 case Match_InvalidSVEExactFPImmOperandHalfTwo:
5004 case Match_InvalidSVEExactFPImmOperandZeroOne:
5007 if (ErrorInfo >= Operands.
size())
5008 return Error(IDLoc,
"too few operands for instruction",
SMRange(IDLoc, (*Operands.
back()).getEndLoc()));
5011 SMLoc ErrorLoc = ((AArch64Operand &)*Operands[ErrorInfo]).getStartLoc();
5012 if (ErrorLoc ==
SMLoc())
5014 return showMatchError(ErrorLoc, MatchResult, ErrorInfo, Operands);
5022 bool AArch64AsmParser::ParseDirective(
AsmToken DirectiveID) {
5024 getContext().getObjectFileInfo()->getObjectFileType();
5029 if (IDVal ==
".arch")
5030 parseDirectiveArch(Loc);
5031 else if (IDVal ==
".cpu")
5032 parseDirectiveCPU(Loc);
5033 else if (IDVal ==
".tlsdesccall")
5034 parseDirectiveTLSDescCall(Loc);
5035 else if (IDVal ==
".ltorg" || IDVal ==
".pool")
5036 parseDirectiveLtorg(Loc);
5037 else if (IDVal ==
".unreq")
5038 parseDirectiveUnreq(Loc);
5039 else if (IDVal ==
".inst")
5040 parseDirectiveInst(Loc);
5041 else if (IDVal ==
".cfi_negate_ra_state")
5042 parseDirectiveCFINegateRAState();
5043 else if (IDVal ==
".cfi_b_key_frame")
5044 parseDirectiveCFIBKeyFrame();
5045 else if (IDVal ==
".arch_extension")
5046 parseDirectiveArchExtension(Loc);
5049 parseDirectiveLOH(IDVal, Loc);
5059 const bool NoCrypto =
5061 "nocrypto") !=
std::end(RequestedExtensions));
5064 "crypto") !=
std::end(RequestedExtensions));
5066 if (!NoCrypto && Crypto) {
5071 case AArch64::ArchKind::ARMV8_1A:
5072 case AArch64::ArchKind::ARMV8_2A:
5073 case AArch64::ArchKind::ARMV8_3A:
5077 case AArch64::ArchKind::ARMV8_4A:
5078 case AArch64::ArchKind::ARMV8_5A:
5085 }
else if (NoCrypto) {
5090 case AArch64::ArchKind::ARMV8_1A:
5091 case AArch64::ArchKind::ARMV8_2A:
5092 case AArch64::ArchKind::ARMV8_3A:
5093 RequestedExtensions.
push_back(
"nosha2");
5096 case AArch64::ArchKind::ARMV8_4A:
5097 case AArch64::ArchKind::ARMV8_5A:
5099 RequestedExtensions.
push_back(
"nosha3");
5100 RequestedExtensions.
push_back(
"nosha2");
5109 bool AArch64AsmParser::parseDirectiveArch(
SMLoc L) {
5110 SMLoc ArchLoc = getLoc();
5113 std::tie(Arch, ExtensionString) =
5114 getParser().parseStringToEndOfStatement().
trim().
split(
'+');
5117 if (ID == AArch64::ArchKind::INVALID)
5118 return Error(ArchLoc,
"unknown arch name");
5124 std::vector<StringRef> AArch64Features;
5130 std::vector<std::string> ArchFeatures(AArch64Features.begin(), AArch64Features.end());
5134 if (!ExtensionString.
empty())
5135 ExtensionString.
split(RequestedExtensions,
'+');
5140 for (
auto Name : RequestedExtensions) {
5141 bool EnableFeature =
true;
5144 EnableFeature =
false;
5159 ComputeAvailableFeatures(STI.
ToggleFeature(ToggleFeatures));
5160 setAvailableFeatures(Features);
5169 bool AArch64AsmParser::parseDirectiveArchExtension(
SMLoc L) {
5170 SMLoc ExtLoc = getLoc();
5172 StringRef Name = getParser().parseStringToEndOfStatement().
trim();
5175 "unexpected token in '.arch_extension' directive"))
5178 bool EnableFeature =
true;
5180 EnableFeature =
false;
5191 return Error(ExtLoc,
"unsupported architectural extension: " + Name);
5197 ComputeAvailableFeatures(STI.
ToggleFeature(ToggleFeatures));
5198 setAvailableFeatures(Features);
5202 return Error(ExtLoc,
"unknown architectural extension: " + Name);
5211 bool AArch64AsmParser::parseDirectiveCPU(
SMLoc L) {
5212 SMLoc CurLoc = getLoc();
5215 std::tie(CPU, ExtensionString) =
5216 getParser().parseStringToEndOfStatement().
trim().
split(
'+');
5222 if (!ExtensionString.
empty())
5223 ExtensionString.
split(RequestedExtensions,
'+');
5227 if (!getSTI().isCPUStringValid(CPU)) {
5228 Error(CurLoc,
"unknown CPU name");
5239 for (
auto Name : RequestedExtensions) {
5243 bool EnableFeature =
true;
5246 EnableFeature =
false;
5250 bool FoundExtension =
false;
5262 ComputeAvailableFeatures(STI.
ToggleFeature(ToggleFeatures));
5263 setAvailableFeatures(Features);
5264 FoundExtension =
true;
5269 if (!FoundExtension)
5270 Error(CurLoc,
"unsupported architectural extension");
5279 bool AArch64AsmParser::parseDirectiveInst(
SMLoc Loc) {
5281 return Error(Loc,
"expected expression following '.inst' directive");
5283 auto parseOp = [&]() ->
bool {
5285 const MCExpr *Expr =
nullptr;
5286 if (check(getParser().parseExpression(Expr), L,
"expected expression"))
5289 if (check(!Value, L,
"expected constant expression"))
5291 getTargetStreamer().emitInst(Value->
getValue());
5295 if (parseMany(parseOp))
5296 return addErrorSuffix(
" in '.inst' directive");
5302 bool AArch64AsmParser::parseDirectiveTLSDescCall(
SMLoc L) {
5304 if (check(getParser().parseIdentifier(Name), L,
5305 "expected symbol after directive") ||
5309 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
5317 getParser().getStreamer().EmitInstruction(Inst, getSTI());
5323 bool AArch64AsmParser::parseDirectiveLOH(
StringRef IDVal,
SMLoc Loc) {
5327 return TokError(
"expected an identifier or a number in directive");
5330 int64_t
Id = getParser().getTok().getIntVal();
5332 return TokError(
"invalid numeric identifier in directive");
5335 StringRef Name = getTok().getIdentifier();
5341 return TokError(
"invalid identifier in directive");
5349 assert(NbArgs != -1 &&
"Invalid number of arguments");
5352 for (
int Idx = 0; Idx < NbArgs; ++Idx) {
5354 if (getParser().parseIdentifier(Name))
5355 return TokError(
"expected identifier in directive");
5356 Args.
push_back(getContext().getOrCreateSymbol(Name));
5358 if (Idx + 1 == NbArgs)
5361 "unexpected token in '" +
Twine(IDVal) +
"' directive"))
5365 "unexpected token in '" +
Twine(IDVal) +
"' directive"))
5368 getStreamer().EmitLOHDirective((
MCLOHType)Kind, Args);
5374 bool AArch64AsmParser::parseDirectiveLtorg(
SMLoc L) {
5377 getTargetStreamer().emitCurrentConstantPool();
5383 bool AArch64AsmParser::parseDirectiveReq(
StringRef Name,
SMLoc L) {
5386 SMLoc SRegLoc = getLoc();
5393 RegisterKind = RegKind::NeonVector;
5394 ParseRes = tryParseVectorRegister(RegNum, Kind, RegKind::NeonVector);
5400 return Error(SRegLoc,
"vector register without type specifier expected");
5405 RegisterKind = RegKind::SVEDataVector;
5407 tryParseVectorRegister(RegNum, Kind, RegKind::SVEDataVector);
5413 return Error(SRegLoc,
5414 "sve vector register without type specifier expected");
5419 RegisterKind = RegKind::SVEPredicateVector;
5420 ParseRes = tryParseVectorRegister(RegNum, Kind, RegKind::SVEPredicateVector);
5426 return Error(SRegLoc,
5427 "sve predicate register without type specifier expected");
5431 return Error(SRegLoc,
"register name or alias expected");
5435 "unexpected input in .req directive"))
5438 auto pair = std::make_pair(RegisterKind, (
unsigned) RegNum);
5439 if (RegisterReqs.insert(std::make_pair(Name, pair)).first->second != pair)
5440 Warning(L,
"ignoring redefinition of register alias '" + Name +
"'");
5447 bool AArch64AsmParser::parseDirectiveUnreq(
SMLoc L) {
5450 return TokError(
"unexpected input in .unreq directive.");
5454 return addErrorSuffix(
"in '.unreq' directive");
5458 bool AArch64AsmParser::parseDirectiveCFINegateRAState() {
5461 getStreamer().EmitCFINegateRAState();
5467 bool AArch64AsmParser::parseDirectiveCFIBKeyFrame() {
5469 "unexpected token in '.cfi_b_key_frame'"))
5471 getStreamer().EmitCFIBKeyFrame();
5476 AArch64AsmParser::classifySymbolRef(
const MCExpr *Expr,
5484 if (
const AArch64MCExpr *AE = dyn_cast<AArch64MCExpr>(Expr)) {
5485 ELFRefKind = AE->getKind();
5486 Expr = AE->getSubExpr();
5492 DarwinRefKind = SE->
getKind();
5499 if (!Relocatable || Res.
getSymB())
5526 #define GET_REGISTER_MATCHER 5527 #define GET_SUBTARGET_FEATURE_NAME 5528 #define GET_MATCHER_IMPLEMENTATION 5529 #define GET_MNEMONIC_SPELL_CHECKER 5530 #include "AArch64GenAsmMatcher.inc" 5536 AArch64Operand &
Op =
static_cast<AArch64Operand &
>(AsmOp);
5540 int64_t ExpectedVal;
5543 return Match_InvalidOperand;
5585 return Match_InvalidOperand;
5588 return Match_InvalidOperand;
5590 return Match_Success;
5591 return Match_InvalidOperand;
5595 AArch64AsmParser::tryParseGPRSeqPair(
OperandVector &Operands) {
5600 Error(S,
"expected register");
5610 AArch64MCRegisterClasses[AArch64::GPR32RegClassID];
5612 AArch64MCRegisterClasses[AArch64::GPR64RegClassID];
5614 bool isXReg = XRegClass.
contains(FirstReg),
5615 isWReg = WRegClass.
contains(FirstReg);
5616 if (!isXReg && !isWReg) {
5617 Error(S,
"expected first even register of a " 5618 "consecutive same-size even/odd register pair");
5625 if (FirstEncoding & 0x1) {
5626 Error(S,
"expected first even register of a " 5627 "consecutive same-size even/odd register pair");
5632 Error(getLoc(),
"expected comma");
5640 Res = tryParseScalarRegister(SecondReg);
5645 (isXReg && !XRegClass.
contains(SecondReg)) ||
5646 (isWReg && !WRegClass.
contains(SecondReg))) {
5647 Error(E,
"expected second odd register of a " 5648 "consecutive same-size even/odd register pair");
5655 &AArch64MCRegisterClasses[AArch64::XSeqPairsClassRegClassID]);
5658 &AArch64MCRegisterClasses[AArch64::WSeqPairsClassRegClassID]);
5662 getLoc(), getContext()));
5667 template <
bool ParseShiftExtend,
bool ParseSuffix>
5669 AArch64AsmParser::tryParseSVEDataVector(
OperandVector &Operands) {
5670 const SMLoc S = getLoc();
5676 tryParseVectorRegister(RegNum, Kind, RegKind::SVEDataVector);
5681 if (ParseSuffix && Kind.
empty())
5688 unsigned ElementWidth = KindRes->second;
5691 if (!ParseShiftExtend || getParser().getTok().isNot(
AsmToken::Comma)) {
5692 Operands.
push_back(AArch64Operand::CreateVectorReg(
5693 RegNum, RegKind::SVEDataVector, ElementWidth, S, S, getContext()));
5706 Res = tryParseOptionalShiftExtend(ExtOpnd);
5710 auto Ext =
static_cast<AArch64Operand *
>(ExtOpnd.
back().get());
5711 Operands.
push_back(AArch64Operand::CreateVectorReg(
5712 RegNum, RegKind::SVEDataVector, ElementWidth, S,
Ext->getEndLoc(),
5713 getContext(),
Ext->getShiftExtendType(),
Ext->getShiftExtendAmount(),
5714 Ext->hasShiftExtendAmount()));
5720 AArch64AsmParser::tryParseSVEPattern(
OperandVector &Operands) {
5744 Pattern = MCE->getValue();
5747 auto Pat = AArch64SVEPredPattern::lookupSVEPREDPATByName(TokE.
getString());
5752 Pattern = Pat->Encoding;
5753 assert(Pattern >= 0 && Pattern < 32);
5758 SS, getLoc(), getContext()));
static bool isReg(const MCInst &MI, unsigned OpNo)
Represents a range in source code.
const_iterator end(StringRef path)
Get end iterator over path.
Target & getTheAArch64beTarget()
static MSP430CC::CondCodes getCondCode(unsigned Cond)
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static float getFPImmFloat(unsigned Imm)
LLVM_NODISCARD bool startswith_lower(StringRef Prefix) const
Check if this string starts with the given Prefix, ignoring case.
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
ArchKind getCPUArchKind(StringRef CPU)
This represents an "assembler immediate".
Target & getTheARM64_32Target()
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
VariantKind getKind() const
LLVM_NODISCARD bool equals_lower(StringRef RHS) const
equals_lower - Check for string equality, ignoring case.
static const AArch64MCExpr * create(const MCExpr *Expr, VariantKind Kind, MCContext &Ctx)
virtual bool regsEqual(const MCParsedAsmOperand &Op1, const MCParsedAsmOperand &Op2) const
Returns whether two registers are equal and is used by the tied-operands checks in the AsmMatcher...
Generic assembler parser interface, for use by target specific assembly parsers.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
virtual void Initialize(MCAsmParser &Parser)
Initialize the extension for parsing using the given Parser.
Target & getTheAArch64leTarget()
static MCOperand createExpr(const MCExpr *Val)
MCTargetAsmParser - Generic interface to target specific assembly parsers.
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
void push_back(const T &Elt)
static CondCode getInvertedCondCode(CondCode Code)
Describe properties that are true of each instruction in the target description file.
constexpr size_t size() const
Target specific streamer interface.
bool isNot(TokenKind K) const
virtual const AsmToken & Lex()=0
Get the next AsmToken in the stream, possibly handling file inclusion first.
static unsigned getXRegFromWReg(unsigned Reg)
static bool isMOVZMovAlias(uint64_t Value, int Shift, int RegWidth)
Expected< opStatus > convertFromString(StringRef, roundingMode)
const AsmToken & getTok() const
Get the current AsmToken from the stream.
virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI)
Emit the given Instruction into the current section.
StringSwitch & Case(StringLiteral S, T Value)
return AArch64::GPR64RegClass contains(Reg)
static SMLoc incrementLoc(SMLoc L, int Offset)
unsigned countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the least significant bit to the most stopping at the first 1...
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string...
int64_t getConstant() const
const MCSymbolRefExpr * getSymB() const
static MCOperand createReg(unsigned Reg)
static ManagedStatic< DebugCounter > DC
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
const FeatureBitset & getFeatureBits() const
static bool isSVEAddSubImm(int64_t Imm)
Returns true if Imm is valid for ADD/SUB.
LLVM_NODISCARD StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
static Optional< std::pair< int, int > > parseVectorKind(StringRef Suffix, RegKind VectorKind)
Returns an optional pair of (#elements, element-width) if Suffix is a valid vector kind...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Base class for the full range of assembler expressions which are needed for parsing.
LLVM_NODISCARD R Default(T Value)
Target independent representation for an assembler token.
Represent a reference to a symbol from inside an expression.
bool getExtensionFeatures(unsigned Extensions, std::vector< StringRef > &Features)
static bool isLogicalImmediate(uint64_t imm, unsigned regSize)
isLogicalImmediate - Return true if the immediate is valid for a logical immediate instruction of the...
std::string join(IteratorT Begin, IteratorT End, StringRef Separator)
Joins the strings in the range [Begin, End), adding Separator between the elements.
LLVM_NODISCARD StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
Target & getTheARM64Target()
static std::string AArch64MnemonicSpellCheck(StringRef S, const FeatureBitset &FBS, unsigned VariantID=0)
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).
static bool isSVECpyImm(int64_t Imm)
Returns true if Imm is valid for CPY/DUP.
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...
virtual bool parseExpression(const MCExpr *&Res, SMLoc &EndLoc)=0
Parse an arbitrary expression.
unsigned getReg() const
Returns the register number.
ArchKind parseArch(StringRef Arch)
static bool isMOVNMovAlias(uint64_t Value, int Shift, int RegWidth)
Context object for machine code objects.
std::pair< StringRef, StringRef > getToken(StringRef Source, StringRef Delimiters=" \\\)
getToken - This function extracts one token from source, ignoring any leading characters that appear ...
int64_t getSExtValue() const
Get sign extended value.
static const struct Extension ExtensionMap[]
RegisterMCAsmParser - Helper template for registering a target specific assembly parser, for use in the target machine initialization function.
bool evaluateAsRelocatable(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const
Try to evaluate the expression to a relocatable value, i.e.
bool contains(MCRegister Reg) const
contains - Return true if the specified register is included in this register class.
static bool isMatchingOrAlias(unsigned ZReg, unsigned Reg)
unsigned getRegister(unsigned i) const
getRegister - Return the specified register in the class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
LLVM_NODISCARD size_t size() const
size - Get the string size.
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out...
const MCExpr * getExpr() const
static const fltSemantics & IEEEdouble() LLVM_READNONE
MCRegisterClass - Base class of TargetRegisterClass.
FeatureBitset getRequiredFeatures() const
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)
static unsigned getShifterImm(AArch64_AM::ShiftExtendType ST, unsigned Imm)
getShifterImm - Encode the shift type and amount: imm: 6-bit shift amount shifter: 000 ==> lsl 001 ==...
static unsigned getWRegFromXReg(unsigned Reg)
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
virtual void addAliasForDirective(StringRef Directive, StringRef Alias)=0
FeatureBitset ToggleFeature(uint64_t FB)
Toggle a feature and return the re-computed feature bits.
static unsigned getShiftValue(unsigned Imm)
getShiftValue - Extract the shift value.
const char * getPointer() const
A switch()-like statement whose cases are string literals.
Streaming machine code generation interface.
static void ExpandCryptoAEK(AArch64::ArchKind ArchKind, SmallVector< StringRef, 4 > &RequestedExtensions)
MCTargetStreamer * getTargetStreamer()
Container class for subtarget features.
LLVM_NODISCARD StringRef trim(char Char) const
Return string with consecutive Char characters starting from the left and right removed.
The instances of the Type class are immutable: once they are created, they are never changed...
static const char * getShiftExtendName(AArch64_AM::ShiftExtendType ST)
getShiftName - Get the string encoding for the shift type.
Target & getTheAArch64_32Target()
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")
static int MCLOHNameToId(StringRef Name)
Interface to description of machine instruction set.
LLVM_NODISCARD size_t find(char C, size_t From=0) const
Search for the first character C in the string.
MCRegister getMatchingSuperReg(MCRegister Reg, unsigned SubIdx, const MCRegisterClass *RC) const
Return a super-register of the specified register Reg so its sub-register of index SubIdx is Reg...
virtual MCAsmLexer & getLexer()=0
This file declares a class to represent arbitrary precision floating point values and provide a varie...
MCLOHType
Linker Optimization Hint Type.
const MCSymbolRefExpr * getSymA() const
int64_t getIntVal() const
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
unsigned getNumOperands() const
static bool isValidVectorKind(StringRef Suffix, RegKind VectorKind)
const AsmToken peekTok(bool ShouldSkipSpace=true)
Look ahead at the next token to be lexed.
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
bool isIntN(unsigned N) const
Check if this APInt has an N-bits unsigned integer value.
uint16_t getEncodingValue(MCRegister RegNo) const
Returns the encoding for RegNo.
virtual unsigned getReg() const =0
bool isSubRegisterEq(MCRegister RegA, MCRegister RegB) const
Returns true if RegB is a sub-register of RegA or if RegB == RegA.
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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.
int getOperandConstraint(unsigned OpNum, MCOI::OperandConstraint Constraint) const
Returns the value of the specific constraint if it is set.
static uint64_t encodeLogicalImmediate(uint64_t imm, unsigned regSize)
encodeLogicalImmediate - Return the encoded immediate value for a logical immediate instruction of th...
static int getFP64Imm(const APInt &Imm)
getFP64Imm - Return an 8-bit floating-point version of the 64-bit floating-point value.
MCStreamer & getStreamer()
void setOpcode(unsigned Op)
void UnLex(AsmToken const &Token)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
const MCOperand & getOperand(unsigned i) const
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
const FeatureBitset Features
#define LLVM_EXTERNAL_VISIBILITY
std::string utostr(uint64_t X, bool isNeg=false)
static StringRef MCLOHDirectiveName()
static void setRequiredFeatureString(FeatureBitset FBS, std::string &Str)
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
bool is(TokenKind K) const
Class for arbitrary precision integers.
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
static uint8_t encodeAdvSIMDModImmType10(uint64_t Imm)
const SysReg * lookupSysRegByName(StringRef)
Base class for user error types.
bool isPredicated(MCInstrInfo const &MCII, MCInst const &MCI)
uint32_t parseGenericRegister(StringRef Name)
static unsigned getArithExtendImm(AArch64_AM::ShiftExtendType ET, unsigned Imm)
getArithExtendImm - Encode the extend type and shift amount for an arithmetic instruction: imm: 3-bit...
loop data Loop Data Prefetch
static SMLoc getFromPointer(const char *Ptr)
bool haveFeatures(FeatureBitset ActiveFeatures) const
static bool isAdvSIMDModImmType10(uint64_t Imm)
StringRef getABIName() const
getABIName - If this returns a non-empty string this represents the textual name of the ABI that we w...
LLVM_NODISCARD bool empty() const
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAArch64AsmParser()
Force static initialization.
static bool isValidMCLOHType(unsigned Kind)
Generic base class for all target subtargets.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
bool isSignedIntN(unsigned N) const
Check if this APInt has an N-bits signed integer value.
LLVM_NODISCARD std::string lower() const
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static int MCLOHIdToNbArgs(MCLOHType Kind)
const MCRegisterInfo * getRegisterInfo() const
LLVM Value Representation.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
This class implements an extremely fast bulk output stream that can only output to a stream...
void addOperand(const MCOperand &Op)
StringRef - Represent a constant reference to a string, i.e.
APInt bitcastToAPInt() const
Represents a location in source code.
static const char * getSubtargetFeatureName(uint64_t Val)
unsigned getOpcode() const
static MCOperand createImm(int64_t Val)
bool getArchFeatures(ArchKind AK, std::vector< StringRef > &Features)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
const MCRegisterClass & getRegClass(unsigned i) const
Returns the register class associated with the enumeration value.
unsigned getDefaultExtensions(StringRef CPU, ArchKind AK)
void setDefaultFeatures(StringRef CPU, StringRef FS)
Set the features to the default for the given CPU with an appended feature string.