85 static PrefixInfo CreateFromInst(
const MCInst &Inst, uint64_t TSFlags) {
88 case AArch64::MOVPRFX_ZZ:
92 case AArch64::MOVPRFX_ZPmZ_B:
93 case AArch64::MOVPRFX_ZPmZ_H:
94 case AArch64::MOVPRFX_ZPmZ_S:
95 case AArch64::MOVPRFX_ZPmZ_D:
97 Prefix.Predicated =
true;
100 "No destructive element size set for movprfx");
104 case AArch64::MOVPRFX_ZPzZ_B:
105 case AArch64::MOVPRFX_ZPzZ_H:
106 case AArch64::MOVPRFX_ZPzZ_S:
107 case AArch64::MOVPRFX_ZPzZ_D:
108 Prefix.Active =
true;
109 Prefix.Predicated =
true;
112 "No destructive element size set for movprfx");
123 PrefixInfo() : Active(
false), Predicated(
false) {}
124 bool isActive()
const {
return Active; }
126 unsigned getElementSize()
const {
130 unsigned getDstReg()
const {
return Dst; }
131 unsigned getPgReg()
const {
139 unsigned ElementSize;
149 SMLoc getLoc()
const {
return getParser().getTok().getLoc(); }
154 bool parseCondCode(
OperandVector &Operands,
bool invertCondCode);
157 bool parseSymbolicImmVal(
const MCExpr *&ImmVal);
161 bool invertCondCode);
163 bool showMatchError(
SMLoc Loc,
unsigned ErrCode, uint64_t
ErrorInfo,
166 bool parseDirectiveArch(
SMLoc L);
167 bool parseDirectiveCPU(
SMLoc L);
168 bool parseDirectiveInst(
SMLoc L);
170 bool parseDirectiveTLSDescCall(
SMLoc L);
173 bool parseDirectiveLtorg(
SMLoc L);
176 bool parseDirectiveUnreq(
SMLoc L);
178 bool validateInstruction(
MCInst &Inst,
SMLoc &IDLoc,
180 bool MatchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
183 bool MatchingInlineAsm)
override;
187 #define GET_ASSEMBLER_HEADER 188 #include "AArch64GenAsmMatcher.inc" 200 template <
bool IsSVEPrefetch = false>
205 template<
bool AddFPZeroAsLiteral>
212 template <
bool ParseShiftExtend,
215 template <
bool ParseShiftExtend,
bool ParseSuffix>
218 template <RegKind VectorKind>
220 bool ExpectMatch =
false);
224 enum AArch64MatchResultTy {
225 Match_InvalidSuffix = FIRST_TARGET_MATCH_RESULT_TY,
226 #define GET_OPERAND_DIAGNOSTIC_TYPES 227 #include "AArch64GenAsmMatcher.inc" 248 setAvailableFeatures(ComputeAvailableFeatures(getSTI().getFeatureBits()));
255 bool ParseRegister(
unsigned &RegNo,
SMLoc &StartLoc,
SMLoc &EndLoc)
override;
256 bool ParseDirective(
AsmToken DirectiveID)
override;
258 unsigned Kind)
override;
260 static bool classifySymbolRef(
const MCExpr *Expr,
287 SMLoc StartLoc, EndLoc;
296 struct ShiftExtendOp {
299 bool HasExplicitAmount;
325 ShiftExtendOp ShiftExtend;
328 struct VectorListOp {
331 unsigned NumElements;
332 unsigned ElementWidth;
336 struct VectorIndexOp {
344 struct ShiftedImmOp {
346 unsigned ShiftAmount;
395 struct VectorListOp VectorList;
396 struct VectorIndexOp VectorIndex;
398 struct ShiftedImmOp ShiftedImm;
399 struct CondCodeOp CondCode;
400 struct FPImmOp FPImm;
401 struct BarrierOp Barrier;
402 struct SysRegOp SysReg;
403 struct SysCRImmOp SysCRImm;
404 struct PrefetchOp Prefetch;
405 struct PSBHintOp PSBHint;
406 struct ShiftExtendOp ShiftExtend;
414 AArch64Operand(KindTy K,
MCContext &Ctx) :
Kind(K), Ctx(Ctx) {}
418 StartLoc = o.StartLoc;
428 ShiftedImm = o.ShiftedImm;
443 VectorList = o.VectorList;
446 VectorIndex = o.VectorIndex;
452 SysCRImm = o.SysCRImm;
461 ShiftExtend = o.ShiftExtend;
467 SMLoc getStartLoc()
const override {
return StartLoc; }
469 SMLoc getEndLoc()
const override {
return EndLoc; }
472 assert(Kind == k_Token &&
"Invalid access!");
476 bool isTokenSuffix()
const {
477 assert(Kind == k_Token &&
"Invalid access!");
481 const MCExpr *getImm()
const {
482 assert(Kind == k_Immediate &&
"Invalid access!");
486 const MCExpr *getShiftedImmVal()
const {
487 assert(Kind == k_ShiftedImm &&
"Invalid access!");
488 return ShiftedImm.Val;
491 unsigned getShiftedImmShift()
const {
492 assert(Kind == k_ShiftedImm &&
"Invalid access!");
493 return ShiftedImm.ShiftAmount;
497 assert(Kind == k_CondCode &&
"Invalid access!");
502 assert (Kind == k_FPImm &&
"Invalid access!");
506 bool getFPImmIsExact()
const {
507 assert (Kind == k_FPImm &&
"Invalid access!");
508 return FPImm.IsExact;
511 unsigned getBarrier()
const {
512 assert(Kind == k_Barrier &&
"Invalid access!");
517 assert(Kind == k_Barrier &&
"Invalid access!");
521 unsigned getReg()
const override {
522 assert(Kind == k_Register &&
"Invalid access!");
527 assert(Kind == k_Register &&
"Invalid access!");
528 return Reg.EqualityTy;
531 unsigned getVectorListStart()
const {
532 assert(Kind == k_VectorList &&
"Invalid access!");
533 return VectorList.RegNum;
536 unsigned getVectorListCount()
const {
537 assert(Kind == k_VectorList &&
"Invalid access!");
538 return VectorList.Count;
541 unsigned getVectorIndex()
const {
542 assert(Kind == k_VectorIndex &&
"Invalid access!");
543 return VectorIndex.Val;
547 assert(Kind == k_SysReg &&
"Invalid access!");
548 return StringRef(SysReg.Data, SysReg.Length);
551 unsigned getSysCR()
const {
552 assert(Kind == k_SysCR &&
"Invalid access!");
556 unsigned getPrefetch()
const {
557 assert(Kind == k_Prefetch &&
"Invalid access!");
561 unsigned getPSBHint()
const {
562 assert(Kind == k_PSBHint &&
"Invalid access!");
567 assert(Kind == k_PSBHint &&
"Invalid access!");
568 return StringRef(PSBHint.Data, PSBHint.Length);
572 assert(Kind == k_Prefetch &&
"Invalid access!");
577 if (Kind == k_ShiftExtend)
578 return ShiftExtend.Type;
579 if (Kind == k_Register)
580 return Reg.ShiftExtend.Type;
584 unsigned getShiftExtendAmount()
const {
585 if (Kind == k_ShiftExtend)
586 return ShiftExtend.Amount;
587 if (Kind == k_Register)
588 return Reg.ShiftExtend.Amount;
592 bool hasShiftExtendAmount()
const {
593 if (Kind == k_ShiftExtend)
594 return ShiftExtend.HasExplicitAmount;
595 if (Kind == k_Register)
596 return Reg.ShiftExtend.HasExplicitAmount;
600 bool isImm()
const override {
return Kind == k_Immediate; }
601 bool isMem()
const override {
return false; }
603 bool isUImm6()
const {
610 return (Val >= 0 && Val < 64);
613 template <
int W
idth>
bool isSImm()
const {
return isSImmScaled<Width, 1>(); }
616 return isImmScaled<Bits, Scale>(
true);
620 return isImmScaled<Bits, Scale>(
false);
623 template <
int Bits,
int Scale>
632 int64_t MinVal, MaxVal;
634 int64_t Shift =
Bits - 1;
635 MinVal = (int64_t(1) << Shift) * -Scale;
636 MaxVal = ((int64_t(1) << Shift) - 1) * Scale;
639 MaxVal = ((int64_t(1) <<
Bits) - 1) * Scale;
643 if (Val >= MinVal && Val <= MaxVal && (Val % Scale) == 0)
655 int64_t Val = MCE->getValue();
656 if (Val >= 0 && Val < 32)
661 bool isSymbolicUImm12Offset(
const MCExpr *Expr,
unsigned Scale)
const {
665 if (!AArch64AsmParser::classifySymbolRef(Expr, ELFRefKind, DarwinRefKind,
686 return Addend >= 0 && (Addend % Scale) == 0;
696 template <
int Scale>
bool isUImm12Offset()
const {
702 return isSymbolicUImm12Offset(getImm(), Scale);
705 return (Val % Scale) == 0 && Val >= 0 && (Val / Scale) < 0x1000;
708 template <
int N,
int M>
709 bool isImmInRange()
const {
716 return (Val >=
N && Val <= M);
721 template <
typename T>
722 bool isLogicalImm()
const {
730 int64_t SVal =
typename std::make_signed<T>::type(Val);
731 int64_t UVal =
typename std::make_unsigned<T>::type(Val);
732 if (Val != SVal && Val != UVal)
738 bool isShiftedImm()
const {
return Kind == k_ShiftedImm; }
743 template <
unsigned W
idth>
745 if (isShiftedImm() && Width == getShiftedImmShift())
746 if (
auto *CE = dyn_cast<MCConstantExpr>(getShiftedImmVal()))
747 return std::make_pair(CE->getValue(), Width);
750 if (
auto *CE = dyn_cast<MCConstantExpr>(getImm())) {
751 int64_t Val = CE->getValue();
752 if ((Val != 0) && (uint64_t(Val >> Width) << Width) == uint64_t(Val))
753 return std::make_pair(Val >> Width, Width);
755 return std::make_pair(Val, 0u);
761 bool isAddSubImm()
const {
762 if (!isShiftedImm() && !isImm())
768 if (isShiftedImm()) {
769 unsigned Shift = ShiftedImm.ShiftAmount;
770 Expr = ShiftedImm.Val;
771 if (Shift != 0 && Shift != 12)
780 if (AArch64AsmParser::classifySymbolRef(Expr, ELFRefKind,
781 DarwinRefKind, Addend)) {
798 if (
auto ShiftedVal = getShiftedVal<12>())
799 return ShiftedVal->first >= 0 && ShiftedVal->first <= 0xfff;
806 bool isAddSubImmNeg()
const {
807 if (!isShiftedImm() && !isImm())
811 if (
auto ShiftedVal = getShiftedVal<12>())
812 return ShiftedVal->first < 0 && -ShiftedVal->first <= 0xfff;
822 template <
typename T>
824 if (!isShiftedImm() && (!isImm() || !isa<MCConstantExpr>(getImm())))
828 std::is_same<int8_t, typename std::make_signed<T>::type>::value;
829 if (
auto ShiftedImm = getShiftedVal<8>())
830 if (!(IsByte && ShiftedImm->second) &&
831 AArch64_AM::isSVECpyImm<T>(uint64_t(ShiftedImm->first)
832 << ShiftedImm->second))
842 if (!isShiftedImm() && (!isImm() || !isa<MCConstantExpr>(getImm())))
846 std::is_same<int8_t, typename std::make_signed<T>::type>::value;
847 if (
auto ShiftedImm = getShiftedVal<8>())
848 if (!(IsByte && ShiftedImm->second) &&
849 AArch64_AM::isSVEAddSubImm<T>(ShiftedImm->first
850 << ShiftedImm->second))
857 if (isLogicalImm<T>() && !isSVECpyImm<T>())
862 bool isCondCode()
const {
return Kind == k_CondCode; }
864 bool isSIMDImmType10()
const {
874 bool isBranchTarget()
const {
883 assert(
N > 0 &&
"Branch target immediate cannot be 0 bits!");
884 return (Val >= -((1<<(
N-1)) << 2) && Val <= (((1<<(
N-1))-1) << 2));
895 if (!AArch64AsmParser::classifySymbolRef(getImm(), ELFRefKind,
896 DarwinRefKind, Addend)) {
902 for (
unsigned i = 0; i != AllowedModifiers.
size(); ++i) {
903 if (ELFRefKind == AllowedModifiers[i])
910 bool isMovZSymbolG3()
const {
914 bool isMovZSymbolG2()
const {
920 bool isMovZSymbolG1()
const {
921 return isMovWSymbol({
928 bool isMovZSymbolG0()
const {
934 bool isMovKSymbolG3()
const {
938 bool isMovKSymbolG2()
const {
942 bool isMovKSymbolG1()
const {
948 bool isMovKSymbolG0()
const {
954 template<
int RegW
idth,
int Shift>
956 if (!isImm())
return false;
959 if (!CE)
return false;
965 template<
int RegW
idth,
int Shift>
967 if (!isImm())
return false;
970 if (!CE)
return false;
976 bool isFPImm()
const {
977 return Kind == k_FPImm &&
981 bool isBarrier()
const {
return Kind == k_Barrier; }
982 bool isSysReg()
const {
return Kind == k_SysReg; }
984 bool isMRSSystemRegister()
const {
985 if (!isSysReg())
return false;
987 return SysReg.MRSReg != -1U;
990 bool isMSRSystemRegister()
const {
991 if (!isSysReg())
return false;
992 return SysReg.MSRReg != -1U;
995 bool isSystemPStateFieldWithImm0_1()
const {
996 if (!isSysReg())
return false;
997 return (SysReg.PStateField == AArch64PState::PAN ||
998 SysReg.PStateField == AArch64PState::DIT ||
999 SysReg.PStateField == AArch64PState::UAO);
1002 bool isSystemPStateFieldWithImm0_15()
const {
1003 if (!isSysReg() || isSystemPStateFieldWithImm0_1())
return false;
1004 return SysReg.PStateField != -1U;
1007 bool isReg()
const override {
1008 return Kind == k_Register;
1011 bool isScalarReg()
const {
1015 bool isNeonVectorReg()
const {
1016 return Kind == k_Register &&
Reg.Kind == RegKind::NeonVector;
1019 bool isNeonVectorRegLo()
const {
1020 return Kind == k_Register &&
Reg.Kind == RegKind::NeonVector &&
1021 AArch64MCRegisterClasses[AArch64::FPR128_loRegClassID].contains(
1025 template <
unsigned Class>
bool isSVEVectorReg()
const {
1028 case AArch64::ZPRRegClassID:
1029 case AArch64::ZPR_3bRegClassID:
1030 case AArch64::ZPR_4bRegClassID:
1031 RK = RegKind::SVEDataVector;
1033 case AArch64::PPRRegClassID:
1034 case AArch64::PPR_3bRegClassID:
1035 RK = RegKind::SVEPredicateVector;
1041 return (Kind == k_Register &&
Reg.Kind == RK) &&
1042 AArch64MCRegisterClasses[
Class].contains(
getReg());
1045 template <
unsigned Class>
bool isFPRasZPR()
const {
1047 AArch64MCRegisterClasses[
Class].contains(
getReg());
1050 template <
int ElementW
idth,
unsigned Class>
1052 if (Kind != k_Register ||
Reg.Kind != RegKind::SVEPredicateVector)
1055 if (isSVEVectorReg<Class>() &&
1056 (ElementWidth == 0 ||
Reg.ElementWidth == ElementWidth))
1062 template <
int ElementW
idth,
unsigned Class>
1064 if (Kind != k_Register ||
Reg.Kind != RegKind::SVEDataVector)
1067 if (isSVEVectorReg<Class>() &&
1068 (ElementWidth == 0 ||
Reg.ElementWidth == ElementWidth))
1074 template <
int ElementWidth,
unsigned Class,
1076 bool ShiftWidthAlwaysSame>
1078 auto VectorMatch = isSVEDataVectorRegOfWidth<ElementWidth, Class>();
1079 if (!VectorMatch.isMatch())
1085 bool MatchShift = getShiftExtendAmount() ==
Log2_32(ShiftWidth / 8);
1088 !ShiftWidthAlwaysSame && hasShiftExtendAmount() && ShiftWidth == 8)
1091 if (MatchShift && ShiftExtendTy == getShiftExtendType())
1097 bool isGPR32as64()
const {
1099 AArch64MCRegisterClasses[AArch64::GPR64RegClassID].contains(
Reg.RegNum);
1102 bool isGPR64as32()
const {
1104 AArch64MCRegisterClasses[AArch64::GPR32RegClassID].contains(
Reg.RegNum);
1107 bool isWSeqPair()
const {
1109 AArch64MCRegisterClasses[AArch64::WSeqPairsClassRegClassID].contains(
1113 bool isXSeqPair()
const {
1115 AArch64MCRegisterClasses[AArch64::XSeqPairsClassRegClassID].contains(
1119 template<
int64_t Angle,
int64_t Remainder>
1127 if (Value % Angle == Remainder && Value <= 270)
1132 template <
unsigned RegClassID>
bool isGPR64()
const {
1134 AArch64MCRegisterClasses[RegClassID].contains(
getReg());
1137 template <
unsigned RegClassID,
int ExtW
idth>
1142 if (isGPR64<RegClassID>() && getShiftExtendType() ==
AArch64_AM::LSL &&
1143 getShiftExtendAmount() ==
Log2_32(ExtWidth / 8))
1150 template <RegKind VectorKind,
unsigned NumRegs>
1151 bool isImplicitlyTypedVectorList()
const {
1152 return Kind == k_VectorList && VectorList.Count == NumRegs &&
1153 VectorList.NumElements == 0 &&
1154 VectorList.RegisterKind == VectorKind;
1157 template <
RegKind VectorKind,
unsigned NumRegs,
unsigned NumElements,
1158 unsigned ElementWidth>
1159 bool isTypedVectorList()
const {
1160 if (Kind != k_VectorList)
1162 if (VectorList.Count != NumRegs)
1164 if (VectorList.RegisterKind != VectorKind)
1166 if (VectorList.ElementWidth != ElementWidth)
1168 return VectorList.NumElements == NumElements;
1171 template <
int Min,
int Max>
1173 if (Kind != k_VectorIndex)
1175 if (VectorIndex.Val >= Min && VectorIndex.Val <= Max)
1180 bool isToken()
const override {
return Kind == k_Token; }
1182 bool isTokenEqual(
StringRef Str)
const {
1183 return Kind == k_Token &&
getToken() == Str;
1185 bool isSysCR()
const {
return Kind == k_SysCR; }
1186 bool isPrefetch()
const {
return Kind == k_Prefetch; }
1187 bool isPSBHint()
const {
return Kind == k_PSBHint; }
1188 bool isShiftExtend()
const {
return Kind == k_ShiftExtend; }
1189 bool isShifter()
const {
1190 if (!isShiftExtend())
1200 if (Kind != k_FPImm)
1203 if (getFPImmIsExact()) {
1205 auto *Desc = AArch64ExactFPImm::lookupExactFPImmByEnum(ImmEnum);
1206 assert(Desc &&
"Unknown enum value");
1214 if (getFPImm().bitwiseIsEqual(RealVal))
1221 template <
unsigned ImmA,
unsigned ImmB>
1224 if ((Res = isExactFPImm<ImmA>()))
1226 if ((Res = isExactFPImm<ImmB>()))
1231 bool isExtend()
const {
1232 if (!isShiftExtend())
1241 getShiftExtendAmount() <= 4;
1244 bool isExtend64()
const {
1252 bool isExtendLSL64()
const {
1258 getShiftExtendAmount() <= 4;
1261 template<
int W
idth>
bool isMemXExtend()
const {
1266 (getShiftExtendAmount() ==
Log2_32(Width / 8) ||
1267 getShiftExtendAmount() == 0);
1270 template<
int W
idth>
bool isMemWExtend()
const {
1275 (getShiftExtendAmount() ==
Log2_32(Width / 8) ||
1276 getShiftExtendAmount() == 0);
1279 template <
unsigned w
idth>
1280 bool isArithmeticShifter()
const {
1290 template <
unsigned w
idth>
1291 bool isLogicalShifter()
const {
1299 getShiftExtendAmount() < width;
1302 bool isMovImm32Shifter()
const {
1310 uint64_t Val = getShiftExtendAmount();
1311 return (Val == 0 || Val == 16);
1314 bool isMovImm64Shifter()
const {
1322 uint64_t Val = getShiftExtendAmount();
1323 return (Val == 0 || Val == 16 || Val == 32 || Val == 48);
1326 bool isLogicalVecShifter()
const {
1331 unsigned Shift = getShiftExtendAmount();
1333 (Shift == 0 || Shift == 8 || Shift == 16 || Shift == 24);
1336 bool isLogicalVecHalfWordShifter()
const {
1337 if (!isLogicalVecShifter())
1341 unsigned Shift = getShiftExtendAmount();
1343 (Shift == 0 || Shift == 8);
1346 bool isMoveVecShifter()
const {
1347 if (!isShiftExtend())
1351 unsigned Shift = getShiftExtendAmount();
1353 (Shift == 8 || Shift == 16);
1362 bool isSImm9OffsetFB()
const {
1363 return isSImm<9>() && !isUImm12Offset<Width / 8>();
1366 bool isAdrpLabel()
const {
1372 if (
const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
1373 int64_t Val = CE->getValue();
1374 int64_t Min = - (4096 * (1LL << (21 - 1)));
1375 int64_t Max = 4096 * ((1LL << (21 - 1)) - 1);
1376 return (Val % 4096) == 0 && Val >= Min && Val <= Max;
1382 bool isAdrLabel()
const {
1388 if (
const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
1389 int64_t Val = CE->getValue();
1390 int64_t Min = - (1LL << (21 - 1));
1391 int64_t Max = ((1LL << (21 - 1)) - 1);
1392 return Val >= Min && Val <= Max;
1402 else if (
const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
1408 void addRegOperands(
MCInst &Inst,
unsigned N)
const {
1409 assert(N == 1 &&
"Invalid number of operands!");
1413 void addGPR32as64Operands(
MCInst &Inst,
unsigned N)
const {
1414 assert(N == 1 &&
"Invalid number of operands!");
1416 AArch64MCRegisterClasses[AArch64::GPR64RegClassID].
contains(
getReg()));
1425 void addGPR64as32Operands(
MCInst &Inst,
unsigned N)
const {
1426 assert(N == 1 &&
"Invalid number of operands!");
1428 AArch64MCRegisterClasses[AArch64::GPR32RegClassID].
contains(
getReg()));
1437 template <
int W
idth>
1438 void addFPRasZPRRegOperands(
MCInst &Inst,
unsigned N)
const {
1441 case 8: Base = AArch64::B0;
break;
1442 case 16: Base = AArch64::H0;
break;
1443 case 32: Base = AArch64::S0;
break;
1444 case 64: Base = AArch64::D0;
break;
1445 case 128: Base = AArch64::Q0;
break;
1452 void addVectorReg64Operands(
MCInst &Inst,
unsigned N)
const {
1453 assert(N == 1 &&
"Invalid number of operands!");
1455 AArch64MCRegisterClasses[AArch64::FPR128RegClassID].
contains(
getReg()));
1459 void addVectorReg128Operands(
MCInst &Inst,
unsigned N)
const {
1460 assert(N == 1 &&
"Invalid number of operands!");
1462 AArch64MCRegisterClasses[AArch64::FPR128RegClassID].
contains(
getReg()));
1466 void addVectorRegLoOperands(
MCInst &Inst,
unsigned N)
const {
1467 assert(N == 1 &&
"Invalid number of operands!");
1471 enum VecListIndexType {
1472 VecListIdx_DReg = 0,
1473 VecListIdx_QReg = 1,
1474 VecListIdx_ZReg = 2,
1477 template <VecListIndexType RegTy,
unsigned NumRegs>
1478 void addVectorListOperands(
MCInst &Inst,
unsigned N)
const {
1479 assert(N == 1 &&
"Invalid number of operands!");
1480 static const unsigned FirstRegs[][5] = {
1482 AArch64::D0, AArch64::D0_D1,
1483 AArch64::D0_D1_D2, AArch64::D0_D1_D2_D3 },
1485 AArch64::Q0, AArch64::Q0_Q1,
1486 AArch64::Q0_Q1_Q2, AArch64::Q0_Q1_Q2_Q3 },
1488 AArch64::Z0, AArch64::Z0_Z1,
1489 AArch64::Z0_Z1_Z2, AArch64::Z0_Z1_Z2_Z3 }
1492 assert((RegTy != VecListIdx_ZReg || NumRegs <= 4) &&
1493 " NumRegs must be <= 4 for ZRegs");
1495 unsigned FirstReg = FirstRegs[(
unsigned)RegTy][NumRegs];
1497 FirstRegs[(
unsigned)RegTy][0]));
1500 void addVectorIndexOperands(
MCInst &Inst,
unsigned N)
const {
1501 assert(N == 1 &&
"Invalid number of operands!");
1505 template <
unsigned ImmIs0,
unsigned ImmIs1>
1506 void addExactFPImmOperands(
MCInst &Inst,
unsigned N)
const {
1507 assert(N == 1 &&
"Invalid number of operands!");
1508 assert(
bool(isExactFPImm<ImmIs0, ImmIs1>()) &&
"Invalid operand");
1512 void addImmOperands(
MCInst &Inst,
unsigned N)
const {
1513 assert(N == 1 &&
"Invalid number of operands!");
1517 addExpr(Inst, getImm());
1520 template <
int Shift>
1521 void addImmWithOptionalShiftOperands(
MCInst &Inst,
unsigned N)
const {
1522 assert(N == 2 &&
"Invalid number of operands!");
1523 if (
auto ShiftedVal = getShiftedVal<Shift>()) {
1526 }
else if (isShiftedImm()) {
1527 addExpr(Inst, getShiftedImmVal());
1530 addExpr(Inst, getImm());
1535 template <
int Shift>
1536 void addImmNegWithOptionalShiftOperands(
MCInst &Inst,
unsigned N)
const {
1537 assert(N == 2 &&
"Invalid number of operands!");
1538 if (
auto ShiftedVal = getShiftedVal<Shift>()) {
1545 void addCondCodeOperands(
MCInst &Inst,
unsigned N)
const {
1546 assert(N == 1 &&
"Invalid number of operands!");
1550 void addAdrpLabelOperands(
MCInst &Inst,
unsigned N)
const {
1551 assert(N == 1 &&
"Invalid number of operands!");
1554 addExpr(Inst, getImm());
1559 void addAdrLabelOperands(
MCInst &Inst,
unsigned N)
const {
1560 addImmOperands(Inst, N);
1564 void addUImm12OffsetOperands(
MCInst &Inst,
unsigned N)
const {
1565 assert(N == 1 &&
"Invalid number of operands!");
1575 void addUImm6Operands(
MCInst &Inst,
unsigned N)
const {
1576 assert(N == 1 &&
"Invalid number of operands!");
1581 template <
int Scale>
1582 void addImmScaledOperands(
MCInst &Inst,
unsigned N)
const {
1583 assert(N == 1 &&
"Invalid number of operands!");
1588 template <
typename T>
1589 void addLogicalImmOperands(
MCInst &Inst,
unsigned N)
const {
1590 assert(N == 1 &&
"Invalid number of operands!");
1592 typename std::make_unsigned<T>::type Val = MCE->
getValue();
1597 template <
typename T>
1598 void addLogicalImmNotOperands(
MCInst &Inst,
unsigned N)
const {
1599 assert(N == 1 &&
"Invalid number of operands!");
1601 typename std::make_unsigned<T>::type Val = ~MCE->
getValue();
1606 void addSIMDImmType10Operands(
MCInst &Inst,
unsigned N)
const {
1607 assert(N == 1 &&
"Invalid number of operands!");
1613 void addBranchTarget26Operands(
MCInst &Inst,
unsigned N)
const {
1617 assert(N == 1 &&
"Invalid number of operands!");
1620 addExpr(Inst, getImm());
1623 assert(MCE &&
"Invalid constant immediate operand!");
1627 void addPCRelLabel19Operands(
MCInst &Inst,
unsigned N)
const {
1631 assert(N == 1 &&
"Invalid number of operands!");
1634 addExpr(Inst, getImm());
1637 assert(MCE &&
"Invalid constant immediate operand!");
1641 void addBranchTarget14Operands(
MCInst &Inst,
unsigned N)
const {
1645 assert(N == 1 &&
"Invalid number of operands!");
1648 addExpr(Inst, getImm());
1651 assert(MCE &&
"Invalid constant immediate operand!");
1655 void addFPImmOperands(
MCInst &Inst,
unsigned N)
const {
1656 assert(N == 1 &&
"Invalid number of operands!");
1661 void addBarrierOperands(
MCInst &Inst,
unsigned N)
const {
1662 assert(N == 1 &&
"Invalid number of operands!");
1666 void addMRSSystemRegisterOperands(
MCInst &Inst,
unsigned N)
const {
1667 assert(N == 1 &&
"Invalid number of operands!");
1672 void addMSRSystemRegisterOperands(
MCInst &Inst,
unsigned N)
const {
1673 assert(N == 1 &&
"Invalid number of operands!");
1678 void addSystemPStateFieldWithImm0_1Operands(
MCInst &Inst,
unsigned N)
const {
1679 assert(N == 1 &&
"Invalid number of operands!");
1684 void addSystemPStateFieldWithImm0_15Operands(
MCInst &Inst,
unsigned N)
const {
1685 assert(N == 1 &&
"Invalid number of operands!");
1690 void addSysCROperands(
MCInst &Inst,
unsigned N)
const {
1691 assert(N == 1 &&
"Invalid number of operands!");
1695 void addPrefetchOperands(
MCInst &Inst,
unsigned N)
const {
1696 assert(N == 1 &&
"Invalid number of operands!");
1700 void addPSBHintOperands(
MCInst &Inst,
unsigned N)
const {
1701 assert(N == 1 &&
"Invalid number of operands!");
1705 void addShifterOperands(
MCInst &Inst,
unsigned N)
const {
1706 assert(N == 1 &&
"Invalid number of operands!");
1712 void addExtendOperands(
MCInst &Inst,
unsigned N)
const {
1713 assert(N == 1 &&
"Invalid number of operands!");
1720 void addExtend64Operands(
MCInst &Inst,
unsigned N)
const {
1721 assert(N == 1 &&
"Invalid number of operands!");
1728 void addMemExtendOperands(
MCInst &Inst,
unsigned N)
const {
1729 assert(N == 2 &&
"Invalid number of operands!");
1740 void addMemExtend8Operands(
MCInst &Inst,
unsigned N)
const {
1741 assert(N == 2 &&
"Invalid number of operands!");
1749 void addMOVZMovAliasOperands(
MCInst &Inst,
unsigned N)
const {
1750 assert(N == 1 &&
"Invalid number of operands!");
1758 void addMOVNMovAliasOperands(
MCInst &Inst,
unsigned N)
const {
1759 assert(N == 1 &&
"Invalid number of operands!");
1766 void addComplexRotationEvenOperands(
MCInst &Inst,
unsigned N)
const {
1767 assert(N == 1 &&
"Invalid number of operands!");
1772 void addComplexRotationOddOperands(
MCInst &Inst,
unsigned N)
const {
1773 assert(N == 1 &&
"Invalid number of operands!");
1780 static std::unique_ptr<AArch64Operand>
1782 auto Op = make_unique<AArch64Operand>(k_Token, Ctx);
1783 Op->Tok.Data = Str.
data();
1784 Op->Tok.Length = Str.
size();
1785 Op->Tok.IsSuffix = IsSuffix;
1791 static std::unique_ptr<AArch64Operand>
1795 unsigned ShiftAmount = 0,
1796 unsigned HasExplicitAmount =
false) {
1797 auto Op = make_unique<AArch64Operand>(k_Register, Ctx);
1798 Op->Reg.RegNum = RegNum;
1800 Op->Reg.ElementWidth = 0;
1801 Op->Reg.EqualityTy = EqTy;
1802 Op->Reg.ShiftExtend.Type = ExtTy;
1803 Op->Reg.ShiftExtend.Amount = ShiftAmount;
1804 Op->Reg.ShiftExtend.HasExplicitAmount = HasExplicitAmount;
1810 static std::unique_ptr<AArch64Operand>
1811 CreateVectorReg(
unsigned RegNum,
RegKind Kind,
unsigned ElementWidth,
1814 unsigned ShiftAmount = 0,
1815 unsigned HasExplicitAmount =
false) {
1816 assert((Kind == RegKind::NeonVector || Kind == RegKind::SVEDataVector ||
1817 Kind == RegKind::SVEPredicateVector) &&
1818 "Invalid vector kind");
1819 auto Op = CreateReg(RegNum, Kind, S, E, Ctx, EqualsReg, ExtTy, ShiftAmount,
1821 Op->Reg.ElementWidth = ElementWidth;
1825 static std::unique_ptr<AArch64Operand>
1826 CreateVectorList(
unsigned RegNum,
unsigned Count,
unsigned NumElements,
1829 auto Op = make_unique<AArch64Operand>(k_VectorList, Ctx);
1830 Op->VectorList.RegNum = RegNum;
1831 Op->VectorList.Count = Count;
1832 Op->VectorList.NumElements = NumElements;
1833 Op->VectorList.ElementWidth = ElementWidth;
1840 static std::unique_ptr<AArch64Operand>
1842 auto Op = make_unique<AArch64Operand>(k_VectorIndex, Ctx);
1843 Op->VectorIndex.Val = Idx;
1849 static std::unique_ptr<AArch64Operand> CreateImm(
const MCExpr *Val,
SMLoc S,
1851 auto Op = make_unique<AArch64Operand>(k_Immediate, Ctx);
1858 static std::unique_ptr<AArch64Operand> CreateShiftedImm(
const MCExpr *Val,
1859 unsigned ShiftAmount,
1862 auto Op = make_unique<AArch64Operand>(k_ShiftedImm, Ctx);
1863 Op->ShiftedImm .Val = Val;
1864 Op->ShiftedImm.ShiftAmount = ShiftAmount;
1870 static std::unique_ptr<AArch64Operand>
1872 auto Op = make_unique<AArch64Operand>(k_CondCode, Ctx);
1873 Op->CondCode.Code =
Code;
1879 static std::unique_ptr<AArch64Operand>
1881 auto Op = make_unique<AArch64Operand>(k_FPImm, Ctx);
1883 Op->FPImm.IsExact = IsExact;
1889 static std::unique_ptr<AArch64Operand> CreateBarrier(
unsigned Val,
1893 auto Op = make_unique<AArch64Operand>(k_Barrier, Ctx);
1894 Op->Barrier.Val = Val;
1895 Op->Barrier.Data = Str.
data();
1896 Op->Barrier.Length = Str.
size();
1902 static std::unique_ptr<AArch64Operand> CreateSysReg(
StringRef Str,
SMLoc S,
1907 auto Op = make_unique<AArch64Operand>(k_SysReg, Ctx);
1908 Op->SysReg.Data = Str.
data();
1909 Op->SysReg.Length = Str.
size();
1910 Op->SysReg.MRSReg = MRSReg;
1911 Op->SysReg.MSRReg = MSRReg;
1912 Op->SysReg.PStateField = PStateField;
1918 static std::unique_ptr<AArch64Operand> CreateSysCR(
unsigned Val,
SMLoc S,
1920 auto Op = make_unique<AArch64Operand>(k_SysCR, Ctx);
1921 Op->SysCRImm.Val = Val;
1927 static std::unique_ptr<AArch64Operand> CreatePrefetch(
unsigned Val,
1931 auto Op = make_unique<AArch64Operand>(k_Prefetch, Ctx);
1932 Op->Prefetch.Val = Val;
1933 Op->Barrier.Data = Str.
data();
1934 Op->Barrier.Length = Str.
size();
1940 static std::unique_ptr<AArch64Operand> CreatePSBHint(
unsigned Val,
1944 auto Op = make_unique<AArch64Operand>(k_PSBHint, Ctx);
1945 Op->PSBHint.Val = Val;
1946 Op->PSBHint.Data = Str.
data();
1947 Op->PSBHint.Length = Str.
size();
1953 static std::unique_ptr<AArch64Operand>
1956 auto Op = make_unique<AArch64Operand>(k_ShiftExtend, Ctx);
1957 Op->ShiftExtend.Type = ShOp;
1958 Op->ShiftExtend.Amount = Val;
1959 Op->ShiftExtend.HasExplicitAmount = HasExplicitAmount;
1971 OS <<
"<fpimm " << getFPImm().bitcastToAPInt().getZExtValue();
1972 if (!getFPImmIsExact())
1979 OS <<
"<barrier " << Name <<
">";
1981 OS <<
"<barrier invalid #" << getBarrier() <<
">";
1987 case k_ShiftedImm: {
1988 unsigned Shift = getShiftedImmShift();
1989 OS <<
"<shiftedimm ";
1990 OS << *getShiftedImmVal();
1995 OS <<
"<condcode " << getCondCode() <<
">";
1997 case k_VectorList: {
1998 OS <<
"<vectorlist ";
1999 unsigned Reg = getVectorListStart();
2000 for (
unsigned i = 0, e = getVectorListCount(); i != e; ++i)
2001 OS << Reg + i <<
" ";
2006 OS <<
"<vectorindex " << getVectorIndex() <<
">";
2009 OS <<
"<sysreg: " << getSysReg() <<
'>';
2015 OS <<
"c" << getSysCR();
2020 OS <<
"<prfop " << Name <<
">";
2022 OS <<
"<prfop invalid #" << getPrefetch() <<
">";
2026 OS << getPSBHintName();
2029 OS <<
"<register " <<
getReg() <<
">";
2030 if (!getShiftExtendAmount() && !hasShiftExtendAmount())
2035 << getShiftExtendAmount();
2036 if (!hasShiftExtendAmount())
2046 static unsigned MatchRegisterName(StringRef Name);
2050 static unsigned MatchNeonVectorRegName(StringRef Name) {
2051 return StringSwitch<unsigned>(Name.lower())
2052 .Case("v0", AArch64::Q0)
2053 .Case("v1", AArch64::Q1)
2054 .Case("v2", AArch64::Q2)
2055 .Case("v3", AArch64::Q3)
2056 .Case("v4", AArch64::Q4)
2057 .Case("v5", AArch64::Q5)
2058 .Case("v6", AArch64::Q6)
2059 .Case("v7", AArch64::Q7)
2060 .Case("v8", AArch64::Q8)
2061 .Case("v9", AArch64::Q9)
2062 .Case("v10", AArch64::Q10)
2063 .Case("v11", AArch64::Q11)
2064 .Case("v12", AArch64::Q12)
2065 .Case("v13", AArch64::Q13)
2066 .Case("v14", AArch64::Q14)
2067 .Case("v15", AArch64::Q15)
2068 .Case("v16", AArch64::Q16)
2069 .Case("v17", AArch64::Q17)
2070 .Case("v18", AArch64::Q18)
2071 .Case("v19", AArch64::Q19)
2072 .Case("v20", AArch64::Q20)
2073 .Case("v21", AArch64::Q21)
2074 .Case("v22", AArch64::Q22)
2075 .Case("v23", AArch64::Q23)
2076 .Case("v24", AArch64::Q24)
2077 .Case("v25", AArch64::Q25)
2078 .Case("v26", AArch64::Q26)
2079 .Case("v27", AArch64::Q27)
2080 .Case("v28", AArch64::Q28)
2081 .Case("v29", AArch64::Q29)
2082 .Case("v30", AArch64::Q30)
2083 .Case("v31", AArch64::Q31)
2091 static Optional<std::pair<int, int>> parseVectorKind(StringRef Suffix,
2092 RegKind VectorKind) {
2093 std::pair<int, int> Res = {-1, -1};
2095 switch (VectorKind) {
2096 case RegKind::NeonVector:
2098 StringSwitch<std::pair<int, int>>(Suffix.lower())
2100 .Case(".1d", {1, 64})
2101 .Case(".1q", {1, 128})
2102 // '.2h
' needed for fp16 scalar pairwise reductions 2103 .Case(".2h", {2, 16}) 2104 .Case(".2s", {2, 32}) 2105 .Case(".2d", {2, 64}) 2106 // '.4b
' is another special case for the ARMv8.2a dot product 2108 .Case(".4b", {4, 8}) 2109 .Case(".4h", {4, 16}) 2110 .Case(".4s", {4, 32}) 2111 .Case(".8b", {8, 8}) 2112 .Case(".8h", {8, 16}) 2113 .Case(".16b", {16, 8}) 2114 // Accept the width neutral ones, too, for verbose syntax. If those 2115 // aren't used in the right places, the token operand won
't match so 2116 // all will work out. 2118 .Case(".h", {0, 16}) 2119 .Case(".s", {0, 32}) 2120 .Case(".d", {0, 64}) 2123 case RegKind::SVEPredicateVector: 2124 case RegKind::SVEDataVector: 2125 Res = StringSwitch<std::pair<int, int>>(Suffix.lower()) 2128 .Case(".h", {0, 16}) 2129 .Case(".s", {0, 32}) 2130 .Case(".d", {0, 64}) 2131 .Case(".q", {0, 128}) 2135 llvm_unreachable("Unsupported RegKind"); 2138 if (Res == std::make_pair(-1, -1)) 2139 return Optional<std::pair<int, int>>(); 2141 return Optional<std::pair<int, int>>(Res); 2144 static bool isValidVectorKind(StringRef Suffix, RegKind VectorKind) { 2145 return parseVectorKind(Suffix, VectorKind).hasValue(); 2148 static unsigned matchSVEDataVectorRegName(StringRef Name) { 2149 return StringSwitch<unsigned>(Name.lower()) 2150 .Case("z0", AArch64::Z0) 2151 .Case("z1", AArch64::Z1) 2152 .Case("z2", AArch64::Z2) 2153 .Case("z3", AArch64::Z3) 2154 .Case("z4", AArch64::Z4) 2155 .Case("z5", AArch64::Z5) 2156 .Case("z6", AArch64::Z6) 2157 .Case("z7", AArch64::Z7) 2158 .Case("z8", AArch64::Z8) 2159 .Case("z9", AArch64::Z9) 2160 .Case("z10", AArch64::Z10) 2161 .Case("z11", AArch64::Z11) 2162 .Case("z12", AArch64::Z12) 2163 .Case("z13", AArch64::Z13) 2164 .Case("z14", AArch64::Z14) 2165 .Case("z15", AArch64::Z15) 2166 .Case("z16", AArch64::Z16) 2167 .Case("z17", AArch64::Z17) 2168 .Case("z18", AArch64::Z18) 2169 .Case("z19", AArch64::Z19) 2170 .Case("z20", AArch64::Z20) 2171 .Case("z21", AArch64::Z21) 2172 .Case("z22", AArch64::Z22) 2173 .Case("z23", AArch64::Z23) 2174 .Case("z24", AArch64::Z24) 2175 .Case("z25", AArch64::Z25) 2176 .Case("z26", AArch64::Z26) 2177 .Case("z27", AArch64::Z27) 2178 .Case("z28", AArch64::Z28) 2179 .Case("z29", AArch64::Z29) 2180 .Case("z30", AArch64::Z30) 2181 .Case("z31", AArch64::Z31) 2185 static unsigned matchSVEPredicateVectorRegName(StringRef Name) { 2186 return StringSwitch<unsigned>(Name.lower()) 2187 .Case("p0", AArch64::P0) 2188 .Case("p1", AArch64::P1) 2189 .Case("p2", AArch64::P2) 2190 .Case("p3", AArch64::P3) 2191 .Case("p4", AArch64::P4) 2192 .Case("p5", AArch64::P5) 2193 .Case("p6", AArch64::P6) 2194 .Case("p7", AArch64::P7) 2195 .Case("p8", AArch64::P8) 2196 .Case("p9", AArch64::P9) 2197 .Case("p10", AArch64::P10) 2198 .Case("p11", AArch64::P11) 2199 .Case("p12", AArch64::P12) 2200 .Case("p13", AArch64::P13) 2201 .Case("p14", AArch64::P14) 2202 .Case("p15", AArch64::P15) 2206 bool AArch64AsmParser::ParseRegister(unsigned &RegNo, SMLoc &StartLoc, 2208 StartLoc = getLoc(); 2209 auto Res = tryParseScalarRegister(RegNo); 2210 EndLoc = SMLoc::getFromPointer(getLoc().getPointer() - 1); 2211 return Res != MatchOperand_Success; 2214 // Matches a register name or register alias previously defined by '.req
' 2215 unsigned AArch64AsmParser::matchRegisterNameAlias(StringRef Name, 2217 unsigned RegNum = 0; 2218 if ((RegNum = matchSVEDataVectorRegName(Name))) 2219 return Kind == RegKind::SVEDataVector ? RegNum : 0; 2221 if ((RegNum = matchSVEPredicateVectorRegName(Name))) 2222 return Kind == RegKind::SVEPredicateVector ? RegNum : 0; 2224 if ((RegNum = MatchNeonVectorRegName(Name))) 2225 return Kind == RegKind::NeonVector ? RegNum : 0; 2227 // The parsed register must be of RegKind Scalar 2228 if ((RegNum = MatchRegisterName(Name))) 2229 return Kind == RegKind::Scalar ? RegNum : 0; 2232 // Handle a few common aliases of registers. 2233 if (auto RegNum = StringSwitch<unsigned>(Name.lower()) 2234 .Case("fp", AArch64::FP) 2235 .Case("lr", AArch64::LR) 2236 .Case("x31", AArch64::XZR) 2237 .Case("w31", AArch64::WZR) 2239 return Kind == RegKind::Scalar ? RegNum : 0; 2241 // Check for aliases registered via .req. Canonicalize to lower case. 2242 // That's more consistent since
register names are
case insensitive, and
2244 auto Entry = RegisterReqs.find(
Name.lower());
2245 if (Entry == RegisterReqs.end())
2249 if (
Kind == Entry->getValue().first)
2250 RegNum = Entry->getValue().second;
2259 AArch64AsmParser::tryParseScalarRegister(
unsigned &RegNum) {
2277 AArch64AsmParser::tryParseSysCROperand(
OperandVector &Operands) {
2282 Error(S,
"Expected cN operand where 0 <= N <= 15");
2287 if (Tok[0] !=
'c' && Tok[0] !=
'C') {
2288 Error(S,
"Expected cN operand where 0 <= N <= 15");
2294 if (BadNum || CRNum > 15) {
2295 Error(S,
"Expected cN operand where 0 <= N <= 15");
2301 AArch64Operand::CreateSysCR(CRNum, S, getLoc(), getContext()));
2306 template <
bool IsSVEPrefetch>
2308 AArch64AsmParser::tryParsePrefetch(
OperandVector &Operands) {
2314 if (IsSVEPrefetch) {
2315 if (
auto Res = AArch64SVEPRFM::lookupSVEPRFMByName(
N))
2317 }
else if (
auto Res = AArch64PRFM::lookupPRFMByName(
N))
2322 auto LookupByEncoding = [](
unsigned E) {
2323 if (IsSVEPrefetch) {
2324 if (
auto Res = AArch64SVEPRFM::lookupSVEPRFMByEncoding(
E))
2326 }
else if (
auto Res = AArch64PRFM::lookupPRFMByEncoding(
E))
2330 unsigned MaxVal = IsSVEPrefetch ? 15 : 31;
2337 if (getParser().parseExpression(ImmVal))
2342 TokError(
"immediate value expected for prefetch operand");
2346 if (prfop > MaxVal) {
2347 TokError(
"prefetch operand out of range, [0," +
utostr(MaxVal) +
2352 auto PRFM = LookupByEncoding(MCE->
getValue());
2353 Operands.
push_back(AArch64Operand::CreatePrefetch(
2354 prfop, PRFM.getValueOr(
""), S, getContext()));
2359 TokError(
"prefetch hint expected");
2363 auto PRFM = LookupByName(Tok.
getString());
2365 TokError(
"prefetch hint expected");
2370 Operands.
push_back(AArch64Operand::CreatePrefetch(
2371 *PRFM, Tok.
getString(), S, getContext()));
2377 AArch64AsmParser::tryParsePSBHint(
OperandVector &Operands) {
2382 TokError(
"invalid operand for instruction");
2386 auto PSB = AArch64PSBHint::lookupPSBByName(Tok.
getString());
2388 TokError(
"invalid operand for instruction");
2393 Operands.
push_back(AArch64Operand::CreatePSBHint(
2394 PSB->Encoding, Tok.
getString(), S, getContext()));
2401 AArch64AsmParser::tryParseAdrpLabel(
OperandVector &Operands) {
2410 if (parseSymbolicImmVal(Expr))
2416 if (classifySymbolRef(Expr, ELFRefKind, DarwinRefKind, Addend)) {
2426 Error(S,
"gotpage label reference not allowed an addend");
2435 Error(S,
"page or gotpage label reference expected");
2444 Operands.
push_back(AArch64Operand::CreateImm(Expr, S, E, getContext()));
2452 AArch64AsmParser::tryParseAdrLabel(
OperandVector &Operands) {
2456 const AsmToken &Tok = getParser().getTok();
2458 if (getParser().parseExpression(Expr))
2462 Operands.
push_back(AArch64Operand::CreateImm(Expr, S, E, getContext()));
2470 template<
bool AddFPZeroAsLiteral>
2485 TokError(
"invalid floating point immediate");
2491 if (Tok.
getIntVal() > 255 || isNegative) {
2492 TokError(
"encoded floating point value out of range");
2498 AArch64Operand::CreateFPImm(F,
true, S, getContext()));
2507 if (AddFPZeroAsLiteral && RealVal.
isPosZero()) {
2509 AArch64Operand::CreateToken(
"#0",
false, S, getContext()));
2511 AArch64Operand::CreateToken(
".0",
false, S, getContext()));
2513 Operands.
push_back(AArch64Operand::CreateFPImm(
2525 AArch64AsmParser::tryParseImmWithOptionalShift(
OperandVector &Operands) {
2536 if (parseSymbolicImmVal(Imm))
2541 AArch64Operand::CreateImm(Imm, S, E, getContext()));
2567 if (ShiftAmount < 0) {
2574 if (ShiftAmount == 0 && Imm != 0) {
2576 Operands.
push_back(AArch64Operand::CreateImm(Imm, S, E, getContext()));
2581 Operands.
push_back(AArch64Operand::CreateShiftedImm(Imm, ShiftAmount,
2582 S, E, getContext()));
2610 getSTI().getFeatureBits()[AArch64::FeatureSVE])
2628 bool AArch64AsmParser::parseCondCode(
OperandVector &Operands,
2629 bool invertCondCode) {
2638 return TokError(
"invalid condition code");
2641 if (invertCondCode) {
2643 return TokError(
"condition codes AL and NV are invalid for this instruction");
2648 AArch64Operand::CreateCondCode(CC, S, getLoc(), getContext()));
2655 AArch64AsmParser::tryParseOptionalShiftExtend(
OperandVector &Operands) {
2689 TokError(
"expected #imm after shift specifier");
2696 AArch64Operand::CreateShiftExtend(ShOp, 0,
false, S, E, getContext()));
2706 Error(E,
"expected integer shift amount");
2711 if (getParser().parseExpression(ImmVal))
2716 Error(E,
"expected constant '#imm' after shift specifier");
2721 Operands.
push_back(AArch64Operand::CreateShiftExtend(
2722 ShOp, MCE->
getValue(),
true, S,
E, getContext()));
2727 if (FBS[AArch64::HasV8_1aOps])
2729 else if (FBS[AArch64::HasV8_2aOps])
2731 else if (FBS[AArch64::HasV8_3aOps])
2733 else if (FBS[AArch64::HasV8_4aOps])
2739 void AArch64AsmParser::createSysAlias(uint16_t Encoding,
OperandVector &Operands,
2741 const uint16_t Op2 = Encoding & 7;
2742 const uint16_t Cm = (Encoding & 0x78) >> 3;
2743 const uint16_t Cn = (Encoding & 0x780) >> 7;
2744 const uint16_t Op1 = (Encoding & 0x3800) >> 11;
2749 AArch64Operand::CreateImm(Expr, S, getLoc(), getContext()));
2751 AArch64Operand::CreateSysCR(Cn, S, getLoc(), getContext()));
2753 AArch64Operand::CreateSysCR(Cm, S, getLoc(), getContext()));
2756 AArch64Operand::CreateImm(Expr, S, getLoc(), getContext()));
2764 return TokError(
"invalid operand");
2768 AArch64Operand::CreateToken(
"sys",
false, NameLoc, getContext()));
2775 if (Mnemonic ==
"ic") {
2778 return TokError(
"invalid operand for IC instruction");
2779 else if (!IC->
haveFeatures(getSTI().getFeatureBits())) {
2780 std::string Str(
"IC " + std::string(IC->
Name) +
" requires ");
2782 return TokError(Str.c_str());
2784 createSysAlias(IC->
Encoding, Operands, S);
2785 }
else if (Mnemonic ==
"dc") {
2788 return TokError(
"invalid operand for DC instruction");
2789 else if (!DC->
haveFeatures(getSTI().getFeatureBits())) {
2790 std::string Str(
"DC " + std::string(DC->
Name) +
" requires ");
2792 return TokError(Str.c_str());
2794 createSysAlias(DC->
Encoding, Operands, S);
2795 }
else if (Mnemonic ==
"at") {
2798 return TokError(
"invalid operand for AT instruction");
2799 else if (!AT->
haveFeatures(getSTI().getFeatureBits())) {
2800 std::string Str(
"AT " + std::string(AT->
Name) +
" requires ");
2802 return TokError(Str.c_str());
2804 createSysAlias(AT->
Encoding, Operands, S);
2805 }
else if (Mnemonic ==
"tlbi") {
2808 return TokError(
"invalid operand for TLBI instruction");
2809 else if (!TLBI->
haveFeatures(getSTI().getFeatureBits())) {
2810 std::string Str(
"TLBI " + std::string(TLBI->
Name) +
" requires ");
2812 return TokError(Str.c_str());
2814 createSysAlias(TLBI->
Encoding, Operands, S);
2820 bool HasRegister =
false;
2825 return TokError(
"expected register operand");
2829 if (ExpectRegister && !HasRegister)
2830 return TokError(
"specified " + Mnemonic +
" op requires a register");
2831 else if (!ExpectRegister && HasRegister)
2832 return TokError(
"specified " + Mnemonic +
" op does not use a register");
2841 AArch64AsmParser::tryParseBarrierOperand(
OperandVector &Operands) {
2846 TokError(
"'csync' operand expected");
2852 SMLoc ExprLoc = getLoc();
2853 if (getParser().parseExpression(ImmVal))
2857 Error(ExprLoc,
"immediate value expected for barrier operand");
2861 Error(ExprLoc,
"barrier operand out of range");
2864 auto DB = AArch64DB::lookupDBByEncoding(MCE->
getValue());
2865 Operands.
push_back(AArch64Operand::CreateBarrier(
2866 MCE->
getValue(), DB ? DB->Name :
"", ExprLoc, getContext()));
2871 TokError(
"invalid operand for instruction");
2875 auto TSB = AArch64TSB::lookupTSBByName(Tok.
getString());
2877 auto DB = AArch64DB::lookupDBByName(Tok.
getString());
2878 if (Mnemonic ==
"isb" && (!DB || DB->Encoding != AArch64DB::sy)) {
2879 TokError(
"'sy' or #imm operand expected");
2882 }
else if (Mnemonic ==
"tsb" && (!TSB || TSB->Encoding != AArch64TSB::csync)) {
2883 TokError(
"'csync' operand expected");
2885 }
else if (!DB && !TSB) {
2886 TokError(
"invalid barrier option name");
2890 Operands.
push_back(AArch64Operand::CreateBarrier(
2891 DB ? DB->Encoding : TSB->Encoding, Tok.
getString(), getLoc(), getContext()));
2907 if (SysReg && SysReg->haveFeatures(getSTI().getFeatureBits())) {
2908 MRSReg = SysReg->
Readable ? SysReg->Encoding : -1;
2909 MSRReg = SysReg->Writeable ? SysReg->Encoding : -1;
2913 auto PState = AArch64PState::lookupPStateByName(Tok.
getString());
2914 unsigned PStateImm = -1;
2915 if (PState && PState->haveFeatures(getSTI().getFeatureBits()))
2916 PStateImm = PState->Encoding;
2919 AArch64Operand::CreateSysReg(Tok.
getString(), getLoc(), MRSReg, MSRReg,
2920 PStateImm, getContext()));
2927 bool AArch64AsmParser::tryParseNeonVectorRegister(
OperandVector &Operands) {
2937 tryParseVectorRegister(Reg, Kind, RegKind::NeonVector);
2945 unsigned ElementWidth = KindRes->second;
2947 AArch64Operand::CreateVectorReg(Reg, RegKind::NeonVector, ElementWidth,
2948 S, getLoc(), getContext()));
2954 AArch64Operand::CreateToken(Kind,
false, S, getContext()));
2960 AArch64AsmParser::tryParseVectorIndex(
OperandVector &Operands) {
2961 SMLoc SIdx = getLoc();
2964 if (getParser().parseExpression(ImmVal))
2968 TokError(
"immediate value expected for vector index");
3000 size_t Start = 0, Next = Name.
find(
'.');
3002 unsigned RegNum = matchRegisterNameAlias(Head, MatchKind);
3008 TokError(
"invalid vector kind qualifier");
3023 AArch64AsmParser::tryParseSVEPredicateVector(
OperandVector &Operands) {
3025 const SMLoc S = getLoc();
3028 auto Res = tryParseVectorRegister(RegNum, Kind, RegKind::SVEPredicateVector);
3032 const auto &KindRes =
parseVectorKind(Kind, RegKind::SVEPredicateVector);
3036 unsigned ElementWidth = KindRes->second;
3037 Operands.
push_back(AArch64Operand::CreateVectorReg(
3038 RegNum, RegKind::SVEPredicateVector, ElementWidth, S,
3039 getLoc(), getContext()));
3047 if (!Kind.
empty()) {
3048 Error(S,
"not expecting size suffix");
3054 AArch64Operand::CreateToken(
"/" ,
false, getLoc(), getContext()));
3060 if (Pred !=
"z" && Pred !=
"m") {
3061 Error(getLoc(),
"expecting 'm' or 'z' predication");
3066 const char *ZM = Pred ==
"z" ?
"z" :
"m";
3068 AArch64Operand::CreateToken(ZM,
false, getLoc(), getContext()));
3075 bool AArch64AsmParser::parseRegister(
OperandVector &Operands) {
3077 if (!tryParseNeonVectorRegister(Operands))
3087 bool AArch64AsmParser::parseSymbolicImmVal(
const MCExpr *&ImmVal) {
3089 bool HasELFModifier =
false;
3093 HasELFModifier =
true;
3096 return TokError(
"expect relocation specifier in operand after ':'");
3140 return TokError(
"expect relocation specifier in operand after ':'");
3144 if (parseToken(
AsmToken::Colon,
"expect ':' after relocation specifier"))
3148 if (getParser().parseExpression(ImmVal))
3157 template <RegKind VectorKind>
3159 AArch64AsmParser::tryParseVectorList(
OperandVector &Operands,
3167 bool NoMatchIsError) {
3168 auto RegTok = Parser.
getTok();
3169 auto ParseRes = tryParseVectorRegister(Reg, Kind, VectorKind);
3179 Error(Loc,
"vector register expected");
3187 auto LCurly = Parser.
getTok();
3192 auto ParseRes = ParseVector(FirstReg, Kind, getLoc(), ExpectMatch);
3202 int64_t PrevReg = FirstReg;
3206 SMLoc Loc = getLoc();
3210 ParseRes = ParseVector(Reg, NextKind, getLoc(),
true);
3215 if (Kind != NextKind) {
3216 Error(Loc,
"mismatched register size suffix");
3220 unsigned Space = (PrevReg <
Reg) ? (Reg - PrevReg) : (Reg + 32 - PrevReg);
3222 if (Space == 0 || Space > 3) {
3223 Error(Loc,
"invalid number of vectors");
3231 SMLoc Loc = getLoc();
3234 ParseRes = ParseVector(Reg, NextKind, getLoc(),
true);
3239 if (Kind != NextKind) {
3240 Error(Loc,
"mismatched register size suffix");
3245 if (getContext().getRegisterInfo()->getEncodingValue(Reg) !=
3246 (getContext().getRegisterInfo()->getEncodingValue(PrevReg) + 1) % 32) {
3247 Error(Loc,
"registers must be sequential");
3260 Error(S,
"invalid number of vectors");
3264 unsigned NumElements = 0;
3265 unsigned ElementWidth = 0;
3266 if (!Kind.
empty()) {
3268 std::tie(NumElements, ElementWidth) = *VK;
3271 Operands.
push_back(AArch64Operand::CreateVectorList(
3272 FirstReg, Count, NumElements, ElementWidth, VectorKind, S, getLoc(),
3279 bool AArch64AsmParser::parseNeonVectorList(
OperandVector &Operands) {
3280 auto ParseRes = tryParseVectorList<RegKind::NeonVector>(Operands,
true);
3288 AArch64AsmParser::tryParseGPR64sp0Operand(
OperandVector &Operands) {
3289 SMLoc StartLoc = getLoc();
3297 Operands.
push_back(AArch64Operand::CreateReg(
3305 Error(getLoc(),
"index must be absent or #0");
3310 if (getParser().parseExpression(ImmVal) || !isa<MCConstantExpr>(ImmVal) ||
3311 cast<MCConstantExpr>(ImmVal)->getValue() != 0) {
3312 Error(getLoc(),
"index must be absent or #0");
3316 Operands.
push_back(AArch64Operand::CreateReg(
3321 template <
bool ParseShiftExtend, RegConstra
intEqualityTy EqTy>
3323 AArch64AsmParser::tryParseGPROperand(
OperandVector &Operands) {
3324 SMLoc StartLoc = getLoc();
3332 if (!ParseShiftExtend || getParser().getTok().isNot(
AsmToken::Comma)) {
3333 Operands.
push_back(AArch64Operand::CreateReg(
3343 Res = tryParseOptionalShiftExtend(ExtOpnd);
3347 auto Ext =
static_cast<AArch64Operand*
>(ExtOpnd.
back().get());
3348 Operands.
push_back(AArch64Operand::CreateReg(
3350 Ext->getShiftExtendType(),
Ext->getShiftExtendAmount(),
3351 Ext->hasShiftExtendAmount()));
3356 bool AArch64AsmParser::parseOptionalMulOperand(
OperandVector &Operands) {
3365 !(NextIsVL || NextIsHash))
3369 AArch64Operand::CreateToken(
"mul",
false, getLoc(), getContext()));
3374 AArch64Operand::CreateToken(
"vl",
false, getLoc(), getContext()));
3386 if (
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal)) {
3387 Operands.
push_back(AArch64Operand::CreateImm(
3394 return Error(getLoc(),
"expected 'vl' or '#<imm>'");
3399 bool AArch64AsmParser::parseOperand(
OperandVector &Operands,
bool isCondCode,
3400 bool invertCondCode) {
3404 MatchOperandParserImpl(Operands, Mnemonic,
true);
3418 switch (getLexer().getKind()) {
3422 if (parseSymbolicImmVal(Expr))
3423 return Error(S,
"invalid operand");
3426 Operands.
push_back(AArch64Operand::CreateImm(Expr, S, E, getContext()));
3431 Operands.
push_back(AArch64Operand::CreateToken(
"[",
false, Loc,
3437 return parseOperand(Operands,
false,
false);
3440 return parseNeonVectorList(Operands);
3444 return parseCondCode(Operands, invertCondCode);
3447 if (!parseRegister(Operands))
3452 if (!parseOptionalMulOperand(Operands))
3465 if (getParser().parseExpression(IdVal))
3468 Operands.
push_back(AArch64Operand::CreateImm(IdVal, S, E, getContext()));
3480 bool isNegative =
false;
3495 uint64_t
IntVal = RealVal.bitcastToAPInt().getZExtValue();
3496 if (Mnemonic !=
"fcmp" && Mnemonic !=
"fcmpe" && Mnemonic !=
"fcmeq" &&
3497 Mnemonic !=
"fcmge" && Mnemonic !=
"fcmgt" && Mnemonic !=
"fcmle" &&
3498 Mnemonic !=
"fcmlt" && Mnemonic !=
"fcmne")
3499 return TokError(
"unexpected floating point literal");
3500 else if (IntVal != 0 || isNegative)
3501 return TokError(
"expected floating-point constant #0.0");
3505 AArch64Operand::CreateToken(
"#0",
false, S, getContext()));
3507 AArch64Operand::CreateToken(
".0",
false, S, getContext()));
3512 if (parseSymbolicImmVal(ImmVal))
3516 Operands.
push_back(AArch64Operand::CreateImm(ImmVal, S, E, getContext()));
3520 SMLoc Loc = getLoc();
3521 if (Mnemonic !=
"ldr")
3522 return TokError(
"unexpected token in operand");
3524 const MCExpr *SubExprVal;
3525 if (getParser().parseExpression(SubExprVal))
3528 if (Operands.
size() < 2 ||
3529 !
static_cast<AArch64Operand &
>(*Operands[1]).isScalarReg())
3530 return Error(Loc,
"Only valid when first operand is register");
3533 AArch64MCRegisterClasses[AArch64::GPR64allRegClassID].contains(
3539 if (isa<MCConstantExpr>(SubExprVal)) {
3540 uint64_t Imm = (cast<MCConstantExpr>(SubExprVal))->getValue();
3541 uint32_t ShiftAmt = 0, MaxShiftAmt = IsXReg ? 48 : 16;
3546 if (ShiftAmt <= MaxShiftAmt && Imm <= 0xFFFF) {
3547 Operands[0] = AArch64Operand::CreateToken(
"movz",
false, Loc, Ctx);
3548 Operands.
push_back(AArch64Operand::CreateImm(
3552 ShiftAmt,
true, S, E, Ctx));
3558 return Error(Loc,
"Immediate too large for register");
3562 getTargetStreamer().addConstantPoolEntry(SubExprVal, IsXReg ? 8 : 4, Loc);
3563 Operands.
push_back(AArch64Operand::CreateImm(CPLoc, S, E, Ctx));
3571 auto &AOp1 =
static_cast<const AArch64Operand&
>(Op1);
3572 auto &AOp2 =
static_cast<const AArch64Operand&
>(Op2);
3573 if (AOp1.getRegEqualityTy() == RegConstraintEqualityTy::EqualsReg &&
3574 AOp2.getRegEqualityTy() == RegConstraintEqualityTy::EqualsReg)
3577 assert(AOp1.isScalarReg() && AOp2.isScalarReg() &&
3578 "Testing equality of non-scalar registers not supported");
3581 if (AOp1.getRegEqualityTy() == EqualsSuperReg)
3583 if (AOp1.getRegEqualityTy() == EqualsSubReg)
3585 if (AOp2.getRegEqualityTy() == EqualsSuperReg)
3587 if (AOp2.getRegEqualityTy() == EqualsSubReg)
3600 .Case(
"beq",
"b.eq")
3601 .
Case(
"bne",
"b.ne")
3602 .
Case(
"bhs",
"b.hs")
3603 .
Case(
"bcs",
"b.cs")
3604 .
Case(
"blo",
"b.lo")
3605 .
Case(
"bcc",
"b.cc")
3606 .
Case(
"bmi",
"b.mi")
3607 .
Case(
"bpl",
"b.pl")
3608 .
Case(
"bvs",
"b.vs")
3609 .
Case(
"bvc",
"b.vc")
3610 .
Case(
"bhi",
"b.hi")
3611 .
Case(
"bls",
"b.ls")
3612 .
Case(
"bge",
"b.ge")
3613 .
Case(
"blt",
"b.lt")
3614 .
Case(
"bgt",
"b.gt")
3615 .
Case(
"ble",
"b.le")
3616 .
Case(
"bal",
"b.al")
3617 .
Case(
"bnv",
"b.nv")
3623 parseDirectiveReq(Name, NameLoc);
3630 size_t Start = 0, Next = Name.
find(
'.');
3634 if (Head ==
"ic" || Head ==
"dc" || Head ==
"at" || Head ==
"tlbi")
3635 return parseSysAlias(Head, NameLoc, Operands);
3638 AArch64Operand::CreateToken(Head,
false, NameLoc, getContext()));
3644 Next = Name.
find(
'.', Start + 1);
3645 Head = Name.
slice(Start + 1, Next);
3651 return Error(SuffixLoc,
"invalid condition code");
3653 AArch64Operand::CreateToken(
".",
true, SuffixLoc, getContext()));
3655 AArch64Operand::CreateCondCode(CC, NameLoc, NameLoc, getContext()));
3661 Next = Name.
find(
'.', Start + 1);
3662 Head = Name.
slice(Start, Next);
3666 AArch64Operand::CreateToken(Head,
true, SuffixLoc, getContext()));
3671 bool condCodeFourthOperand =
3672 (Head ==
"ccmp" || Head ==
"ccmn" || Head ==
"fccmp" ||
3673 Head ==
"fccmpe" || Head ==
"fcsel" || Head ==
"csel" ||
3674 Head ==
"csinc" || Head ==
"csinv" || Head ==
"csneg");
3682 bool condCodeSecondOperand = (Head ==
"cset" || Head ==
"csetm");
3683 bool condCodeThirdOperand =
3684 (Head ==
"cinc" || Head ==
"cinv" || Head ==
"cneg");
3689 if (parseOperand(Operands,
false,
false)) {
3696 if (parseOperand(Operands, (N == 4 && condCodeFourthOperand) ||
3697 (N == 3 && condCodeThirdOperand) ||
3698 (N == 2 && condCodeSecondOperand),
3699 condCodeSecondOperand || condCodeThirdOperand)) {
3715 AArch64Operand::CreateToken(
"]",
false, RLoc, getContext()));
3719 AArch64Operand::CreateToken(
"!",
false, ELoc, getContext()));
3732 assert((ZReg >= AArch64::Z0) && (ZReg <= AArch64::Z31));
3733 return (ZReg == ((Reg - AArch64::B0) + AArch64::Z0)) ||
3734 (ZReg == ((Reg - AArch64::H0) + AArch64::Z0)) ||
3735 (ZReg == ((Reg - AArch64::S0) + AArch64::Z0)) ||
3736 (ZReg == ((Reg - AArch64::D0) + AArch64::Z0)) ||
3737 (ZReg == ((Reg - AArch64::Q0) + AArch64::Z0)) ||
3738 (ZReg == ((Reg - AArch64::Z0) + AArch64::Z0));
3744 bool AArch64AsmParser::validateInstruction(
MCInst &Inst,
SMLoc &IDLoc,
3753 PrefixInfo
Prefix = NextPrefix;
3754 NextPrefix = PrefixInfo::CreateFromInst(Inst, MCID.
TSFlags);
3759 if (Prefix.isActive() &&
3766 return Error(IDLoc,
"instruction is unpredictable when following a" 3767 " movprfx, suggest replacing movprfx with mov");
3771 return Error(Loc[0],
"instruction is unpredictable when following a" 3772 " movprfx writing to a different destination");
3779 return Error(Loc[0],
"instruction is unpredictable when following a" 3780 " movprfx and destination also used as non-destructive" 3784 auto PPRRegClass = AArch64MCRegisterClasses[AArch64::PPRRegClassID];
3785 if (Prefix.isPredicated()) {
3799 return Error(IDLoc,
"instruction is unpredictable when following a" 3800 " predicated movprfx, suggest using unpredicated movprfx");
3804 return Error(IDLoc,
"instruction is unpredictable when following a" 3805 " predicated movprfx using a different general predicate");
3809 return Error(IDLoc,
"instruction is unpredictable when following a" 3810 " predicated movprfx with a different element size");
3818 case AArch64::LDPSWpre:
3819 case AArch64::LDPWpost:
3820 case AArch64::LDPWpre:
3821 case AArch64::LDPXpost:
3822 case AArch64::LDPXpre: {
3827 return Error(Loc[0],
"unpredictable LDP instruction, writeback base " 3828 "is also a destination");
3830 return Error(Loc[1],
"unpredictable LDP instruction, writeback base " 3831 "is also a destination");
3834 case AArch64::LDPDi:
3835 case AArch64::LDPQi:
3836 case AArch64::LDPSi:
3837 case AArch64::LDPSWi:
3838 case AArch64::LDPWi:
3839 case AArch64::LDPXi: {
3843 return Error(Loc[1],
"unpredictable LDP instruction, Rt2==Rt");
3846 case AArch64::LDPDpost:
3847 case AArch64::LDPDpre:
3848 case AArch64::LDPQpost:
3849 case AArch64::LDPQpre:
3850 case AArch64::LDPSpost:
3851 case AArch64::LDPSpre:
3852 case AArch64::LDPSWpost: {
3856 return Error(Loc[1],
"unpredictable LDP instruction, Rt2==Rt");
3859 case AArch64::STPDpost:
3860 case AArch64::STPDpre:
3861 case AArch64::STPQpost:
3862 case AArch64::STPQpre:
3863 case AArch64::STPSpost:
3864 case AArch64::STPSpre:
3865 case AArch64::STPWpost:
3866 case AArch64::STPWpre:
3867 case AArch64::STPXpost:
3868 case AArch64::STPXpre: {
3873 return Error(Loc[0],
"unpredictable STP instruction, writeback base " 3874 "is also a source");
3876 return Error(Loc[1],
"unpredictable STP instruction, writeback base " 3877 "is also a source");
3880 case AArch64::LDRBBpre:
3881 case AArch64::LDRBpre:
3882 case AArch64::LDRHHpre:
3883 case AArch64::LDRHpre:
3884 case AArch64::LDRSBWpre:
3885 case AArch64::LDRSBXpre:
3886 case AArch64::LDRSHWpre:
3887 case AArch64::LDRSHXpre:
3888 case AArch64::LDRSWpre:
3889 case AArch64::LDRWpre:
3890 case AArch64::LDRXpre:
3891 case AArch64::LDRBBpost:
3892 case AArch64::LDRBpost:
3893 case AArch64::LDRHHpost:
3894 case AArch64::LDRHpost:
3895 case AArch64::LDRSBWpost:
3896 case AArch64::LDRSBXpost:
3897 case AArch64::LDRSHWpost:
3898 case AArch64::LDRSHXpost:
3899 case AArch64::LDRSWpost:
3900 case AArch64::LDRWpost:
3901 case AArch64::LDRXpost: {
3905 return Error(Loc[0],
"unpredictable LDR instruction, writeback base " 3906 "is also a source");
3909 case AArch64::STRBBpost:
3910 case AArch64::STRBpost:
3911 case AArch64::STRHHpost:
3912 case AArch64::STRHpost:
3913 case AArch64::STRWpost:
3914 case AArch64::STRXpost:
3915 case AArch64::STRBBpre:
3916 case AArch64::STRBpre:
3917 case AArch64::STRHHpre:
3918 case AArch64::STRHpre:
3919 case AArch64::STRWpre:
3920 case AArch64::STRXpre: {
3924 return Error(Loc[0],
"unpredictable STR instruction, writeback base " 3925 "is also a source");
3928 case AArch64::STXRB:
3929 case AArch64::STXRH:
3930 case AArch64::STXRW:
3931 case AArch64::STXRX:
3932 case AArch64::STLXRB:
3933 case AArch64::STLXRH:
3934 case AArch64::STLXRW:
3935 case AArch64::STLXRX: {
3941 return Error(Loc[0],
3942 "unpredictable STXR instruction, status is also a source");
3945 case AArch64::STXPW:
3946 case AArch64::STXPX:
3947 case AArch64::STLXPW:
3948 case AArch64::STLXPX: {
3955 return Error(Loc[0],
3956 "unpredictable STXP instruction, status is also a source");
3966 case AArch64::ADDSWri:
3967 case AArch64::ADDSXri:
3968 case AArch64::ADDWri:
3969 case AArch64::ADDXri:
3970 case AArch64::SUBSWri:
3971 case AArch64::SUBSXri:
3972 case AArch64::SUBWri:
3973 case AArch64::SUBXri: {
3981 if (classifySymbolRef(Expr, ELFRefKind, DarwinRefKind, Addend)) {
4008 return Error(Loc.
back(),
"invalid immediate expression");
4020 unsigned VariantID = 0);
4022 bool AArch64AsmParser::showMatchError(
SMLoc Loc,
unsigned ErrCode,
4026 case Match_InvalidTiedOperand: {
4028 static_cast<const AArch64Operand &
>(*Operands[ErrorInfo])
4029 .getRegEqualityTy();
4031 case RegConstraintEqualityTy::EqualsSubReg:
4032 return Error(Loc,
"operand must be 64-bit form of destination register");
4033 case RegConstraintEqualityTy::EqualsSuperReg:
4034 return Error(Loc,
"operand must be 32-bit form of destination register");
4035 case RegConstraintEqualityTy::EqualsReg:
4036 return Error(Loc,
"operand must match destination register");
4040 case Match_MissingFeature:
4042 "instruction requires a CPU feature not currently enabled");
4043 case Match_InvalidOperand:
4044 return Error(Loc,
"invalid operand for instruction");
4045 case Match_InvalidSuffix:
4046 return Error(Loc,
"invalid type suffix for instruction");
4047 case Match_InvalidCondCode:
4048 return Error(Loc,
"expected AArch64 condition code");
4049 case Match_AddSubRegExtendSmall:
4051 "expected '[su]xt[bhw]' or 'lsl' with optional integer in range [0, 4]");
4052 case Match_AddSubRegExtendLarge:
4054 "expected 'sxtx' 'uxtx' or 'lsl' with optional integer in range [0, 4]");
4055 case Match_AddSubSecondSource:
4057 "expected compatible register, symbol or integer in range [0, 4095]");
4058 case Match_LogicalSecondSource:
4059 return Error(Loc,
"expected compatible register or logical immediate");
4060 case Match_InvalidMovImm32Shift:
4061 return Error(Loc,
"expected 'lsl' with optional integer 0 or 16");
4062 case Match_InvalidMovImm64Shift:
4063 return Error(Loc,
"expected 'lsl' with optional integer 0, 16, 32 or 48");
4064 case Match_AddSubRegShift32:
4066 "expected 'lsl', 'lsr' or 'asr' with optional integer in range [0, 31]");
4067 case Match_AddSubRegShift64:
4069 "expected 'lsl', 'lsr' or 'asr' with optional integer in range [0, 63]");
4070 case Match_InvalidFPImm:
4072 "expected compatible register or floating-point constant");
4073 case Match_InvalidMemoryIndexedSImm6:
4074 return Error(Loc,
"index must be an integer in range [-32, 31].");
4075 case Match_InvalidMemoryIndexedSImm5:
4076 return Error(Loc,
"index must be an integer in range [-16, 15].");
4077 case Match_InvalidMemoryIndexed1SImm4:
4078 return Error(Loc,
"index must be an integer in range [-8, 7].");
4079 case Match_InvalidMemoryIndexed2SImm4:
4080 return Error(Loc,
"index must be a multiple of 2 in range [-16, 14].");
4081 case Match_InvalidMemoryIndexed3SImm4:
4082 return Error(Loc,
"index must be a multiple of 3 in range [-24, 21].");
4083 case Match_InvalidMemoryIndexed4SImm4:
4084 return Error(Loc,
"index must be a multiple of 4 in range [-32, 28].");
4085 case Match_InvalidMemoryIndexed16SImm4:
4086 return Error(Loc,
"index must be a multiple of 16 in range [-128, 112].");
4087 case Match_InvalidMemoryIndexed1SImm6:
4088 return Error(Loc,
"index must be an integer in range [-32, 31].");
4089 case Match_InvalidMemoryIndexedSImm8:
4090 return Error(Loc,
"index must be an integer in range [-128, 127].");
4091 case Match_InvalidMemoryIndexedSImm9:
4092 return Error(Loc,
"index must be an integer in range [-256, 255].");
4093 case Match_InvalidMemoryIndexed8SImm10:
4094 return Error(Loc,
"index must be a multiple of 8 in range [-4096, 4088].");
4095 case Match_InvalidMemoryIndexed4SImm7:
4096 return Error(Loc,
"index must be a multiple of 4 in range [-256, 252].");
4097 case Match_InvalidMemoryIndexed8SImm7:
4098 return Error(Loc,
"index must be a multiple of 8 in range [-512, 504].");
4099 case Match_InvalidMemoryIndexed16SImm7:
4100 return Error(Loc,
"index must be a multiple of 16 in range [-1024, 1008].");
4101 case Match_InvalidMemoryIndexed8UImm5:
4102 return Error(Loc,
"index must be a multiple of 8 in range [0, 248].");
4103 case Match_InvalidMemoryIndexed4UImm5:
4104 return Error(Loc,
"index must be a multiple of 4 in range [0, 124].");
4105 case Match_InvalidMemoryIndexed2UImm5:
4106 return Error(Loc,
"index must be a multiple of 2 in range [0, 62].");
4107 case Match_InvalidMemoryIndexed8UImm6:
4108 return Error(Loc,
"index must be a multiple of 8 in range [0, 504].");
4109 case Match_InvalidMemoryIndexed4UImm6:
4110 return Error(Loc,
"index must be a multiple of 4 in range [0, 252].");
4111 case Match_InvalidMemoryIndexed2UImm6:
4112 return Error(Loc,
"index must be a multiple of 2 in range [0, 126].");
4113 case Match_InvalidMemoryIndexed1UImm6:
4114 return Error(Loc,
"index must be in range [0, 63].");
4115 case Match_InvalidMemoryWExtend8:
4117 "expected 'uxtw' or 'sxtw' with optional shift of #0");
4118 case Match_InvalidMemoryWExtend16:
4120 "expected 'uxtw' or 'sxtw' with optional shift of #0 or #1");
4121 case Match_InvalidMemoryWExtend32:
4123 "expected 'uxtw' or 'sxtw' with optional shift of #0 or #2");
4124 case Match_InvalidMemoryWExtend64:
4126 "expected 'uxtw' or 'sxtw' with optional shift of #0 or #3");
4127 case Match_InvalidMemoryWExtend128:
4129 "expected 'uxtw' or 'sxtw' with optional shift of #0 or #4");
4130 case Match_InvalidMemoryXExtend8:
4132 "expected 'lsl' or 'sxtx' with optional shift of #0");
4133 case Match_InvalidMemoryXExtend16:
4135 "expected 'lsl' or 'sxtx' with optional shift of #0 or #1");
4136 case Match_InvalidMemoryXExtend32:
4138 "expected 'lsl' or 'sxtx' with optional shift of #0 or #2");
4139 case Match_InvalidMemoryXExtend64:
4141 "expected 'lsl' or 'sxtx' with optional shift of #0 or #3");
4142 case Match_InvalidMemoryXExtend128:
4144 "expected 'lsl' or 'sxtx' with optional shift of #0 or #4");
4145 case Match_InvalidMemoryIndexed1:
4146 return Error(Loc,
"index must be an integer in range [0, 4095].");
4147 case Match_InvalidMemoryIndexed2:
4148 return Error(Loc,
"index must be a multiple of 2 in range [0, 8190].");
4149 case Match_InvalidMemoryIndexed4:
4150 return Error(Loc,
"index must be a multiple of 4 in range [0, 16380].");
4151 case Match_InvalidMemoryIndexed8:
4152 return Error(Loc,
"index must be a multiple of 8 in range [0, 32760].");
4153 case Match_InvalidMemoryIndexed16:
4154 return Error(Loc,
"index must be a multiple of 16 in range [0, 65520].");
4155 case Match_InvalidImm0_1:
4156 return Error(Loc,
"immediate must be an integer in range [0, 1].");
4157 case Match_InvalidImm0_7:
4158 return Error(Loc,
"immediate must be an integer in range [0, 7].");
4159 case Match_InvalidImm0_15:
4160 return Error(Loc,
"immediate must be an integer in range [0, 15].");
4161 case Match_InvalidImm0_31:
4162 return Error(Loc,
"immediate must be an integer in range [0, 31].");
4163 case Match_InvalidImm0_63:
4164 return Error(Loc,
"immediate must be an integer in range [0, 63].");
4165 case Match_InvalidImm0_127:
4166 return Error(Loc,
"immediate must be an integer in range [0, 127].");
4167 case Match_InvalidImm0_255:
4168 return Error(Loc,
"immediate must be an integer in range [0, 255].");
4169 case Match_InvalidImm0_65535:
4170 return Error(Loc,
"immediate must be an integer in range [0, 65535].");
4171 case Match_InvalidImm1_8:
4172 return Error(Loc,
"immediate must be an integer in range [1, 8].");
4173 case Match_InvalidImm1_16:
4174 return Error(Loc,
"immediate must be an integer in range [1, 16].");
4175 case Match_InvalidImm1_32:
4176 return Error(Loc,
"immediate must be an integer in range [1, 32].");
4177 case Match_InvalidImm1_64:
4178 return Error(Loc,
"immediate must be an integer in range [1, 64].");
4179 case Match_InvalidSVEAddSubImm8:
4180 return Error(Loc,
"immediate must be an integer in range [0, 255]" 4181 " with a shift amount of 0");
4182 case Match_InvalidSVEAddSubImm16:
4183 case Match_InvalidSVEAddSubImm32:
4184 case Match_InvalidSVEAddSubImm64:
4185 return Error(Loc,
"immediate must be an integer in range [0, 255] or a " 4186 "multiple of 256 in range [256, 65280]");
4187 case Match_InvalidSVECpyImm8:
4188 return Error(Loc,
"immediate must be an integer in range [-128, 255]" 4189 " with a shift amount of 0");
4190 case Match_InvalidSVECpyImm16:
4191 return Error(Loc,
"immediate must be an integer in range [-128, 127] or a " 4192 "multiple of 256 in range [-32768, 65280]");
4193 case Match_InvalidSVECpyImm32:
4194 case Match_InvalidSVECpyImm64:
4195 return Error(Loc,
"immediate must be an integer in range [-128, 127] or a " 4196 "multiple of 256 in range [-32768, 32512]");
4197 case Match_InvalidIndexRange1_1:
4198 return Error(Loc,
"expected lane specifier '[1]'");
4199 case Match_InvalidIndexRange0_15:
4200 return Error(Loc,
"vector lane must be an integer in range [0, 15].");
4201 case Match_InvalidIndexRange0_7:
4202 return Error(Loc,
"vector lane must be an integer in range [0, 7].");
4203 case Match_InvalidIndexRange0_3:
4204 return Error(Loc,
"vector lane must be an integer in range [0, 3].");
4205 case Match_InvalidIndexRange0_1:
4206 return Error(Loc,
"vector lane must be an integer in range [0, 1].");
4207 case Match_InvalidSVEIndexRange0_63:
4208 return Error(Loc,
"vector lane must be an integer in range [0, 63].");
4209 case Match_InvalidSVEIndexRange0_31:
4210 return Error(Loc,
"vector lane must be an integer in range [0, 31].");
4211 case Match_InvalidSVEIndexRange0_15:
4212 return Error(Loc,
"vector lane must be an integer in range [0, 15].");
4213 case Match_InvalidSVEIndexRange0_7:
4214 return Error(Loc,
"vector lane must be an integer in range [0, 7].");
4215 case Match_InvalidSVEIndexRange0_3:
4216 return Error(Loc,
"vector lane must be an integer in range [0, 3].");
4217 case Match_InvalidLabel:
4218 return Error(Loc,
"expected label or encodable integer pc offset");
4220 return Error(Loc,
"expected readable system register");
4222 return Error(Loc,
"expected writable system register or pstate");
4223 case Match_InvalidComplexRotationEven:
4224 return Error(Loc,
"complex rotation must be 0, 90, 180 or 270.");
4225 case Match_InvalidComplexRotationOdd:
4226 return Error(Loc,
"complex rotation must be 90 or 270.");
4227 case Match_MnemonicFail: {
4229 ((AArch64Operand &)*Operands[0]).
getToken(),
4230 ComputeAvailableFeatures(STI->getFeatureBits()));
4231 return Error(Loc,
"unrecognized instruction mnemonic" + Suggestion);
4233 case Match_InvalidGPR64shifted8:
4234 return Error(Loc,
"register must be x0..x30 or xzr, without shift");
4235 case Match_InvalidGPR64shifted16:
4236 return Error(Loc,
"register must be x0..x30 or xzr, with required shift 'lsl #1'");
4237 case Match_InvalidGPR64shifted32:
4238 return Error(Loc,
"register must be x0..x30 or xzr, with required shift 'lsl #2'");
4239 case Match_InvalidGPR64shifted64:
4240 return Error(Loc,
"register must be x0..x30 or xzr, with required shift 'lsl #3'");
4241 case Match_InvalidGPR64NoXZRshifted8:
4242 return Error(Loc,
"register must be x0..x30 without shift");
4243 case Match_InvalidGPR64NoXZRshifted16:
4244 return Error(Loc,
"register must be x0..x30 with required shift 'lsl #1'");
4245 case Match_InvalidGPR64NoXZRshifted32:
4246 return Error(Loc,
"register must be x0..x30 with required shift 'lsl #2'");
4247 case Match_InvalidGPR64NoXZRshifted64:
4248 return Error(Loc,
"register must be x0..x30 with required shift 'lsl #3'");
4249 case Match_InvalidZPR32UXTW8:
4250 case Match_InvalidZPR32SXTW8:
4251 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].s, (uxtw|sxtw)'");
4252 case Match_InvalidZPR32UXTW16:
4253 case Match_InvalidZPR32SXTW16:
4254 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].s, (uxtw|sxtw) #1'");
4255 case Match_InvalidZPR32UXTW32:
4256 case Match_InvalidZPR32SXTW32:
4257 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].s, (uxtw|sxtw) #2'");
4258 case Match_InvalidZPR32UXTW64:
4259 case Match_InvalidZPR32SXTW64:
4260 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].s, (uxtw|sxtw) #3'");
4261 case Match_InvalidZPR64UXTW8:
4262 case Match_InvalidZPR64SXTW8:
4263 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].d, (uxtw|sxtw)'");
4264 case Match_InvalidZPR64UXTW16:
4265 case Match_InvalidZPR64SXTW16:
4266 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].d, (lsl|uxtw|sxtw) #1'");
4267 case Match_InvalidZPR64UXTW32:
4268 case Match_InvalidZPR64SXTW32:
4269 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].d, (lsl|uxtw|sxtw) #2'");
4270 case Match_InvalidZPR64UXTW64:
4271 case Match_InvalidZPR64SXTW64:
4272 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].d, (lsl|uxtw|sxtw) #3'");
4273 case Match_InvalidZPR32LSL8:
4274 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].s'");
4275 case Match_InvalidZPR32LSL16:
4276 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].s, lsl #1'");
4277 case Match_InvalidZPR32LSL32:
4278 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].s, lsl #2'");
4279 case Match_InvalidZPR32LSL64:
4280 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].s, lsl #3'");
4281 case Match_InvalidZPR64LSL8:
4282 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].d'");
4283 case Match_InvalidZPR64LSL16:
4284 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].d, lsl #1'");
4285 case Match_InvalidZPR64LSL32:
4286 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].d, lsl #2'");
4287 case Match_InvalidZPR64LSL64:
4288 return Error(Loc,
"invalid shift/extend specified, expected 'z[0..31].d, lsl #3'");
4289 case Match_InvalidZPR0:
4290 return Error(Loc,
"expected register without element width sufix");
4291 case Match_InvalidZPR8:
4292 case Match_InvalidZPR16:
4293 case Match_InvalidZPR32:
4294 case Match_InvalidZPR64:
4295 case Match_InvalidZPR128:
4296 return Error(Loc,
"invalid element width");
4297 case Match_InvalidZPR_3b8:
4298 return Error(Loc,
"Invalid restricted vector register, expected z0.b..z7.b");
4299 case Match_InvalidZPR_3b16:
4300 return Error(Loc,
"Invalid restricted vector register, expected z0.h..z7.h");
4301 case Match_InvalidZPR_3b32:
4302 return Error(Loc,
"Invalid restricted vector register, expected z0.s..z7.s");
4303 case Match_InvalidZPR_4b16:
4304 return Error(Loc,
"Invalid restricted vector register, expected z0.h..z15.h");
4305 case Match_InvalidZPR_4b32:
4306 return Error(Loc,
"Invalid restricted vector register, expected z0.s..z15.s");
4307 case Match_InvalidZPR_4b64:
4308 return Error(Loc,
"Invalid restricted vector register, expected z0.d..z15.d");
4309 case Match_InvalidSVEPattern:
4310 return Error(Loc,
"invalid predicate pattern");
4311 case Match_InvalidSVEPredicateAnyReg:
4312 case Match_InvalidSVEPredicateBReg:
4313 case Match_InvalidSVEPredicateHReg:
4314 case Match_InvalidSVEPredicateSReg:
4315 case Match_InvalidSVEPredicateDReg:
4316 return Error(Loc,
"invalid predicate register.");
4317 case Match_InvalidSVEPredicate3bAnyReg:
4318 case Match_InvalidSVEPredicate3bBReg:
4319 case Match_InvalidSVEPredicate3bHReg:
4320 case Match_InvalidSVEPredicate3bSReg:
4321 case Match_InvalidSVEPredicate3bDReg:
4322 return Error(Loc,
"restricted predicate has range [0, 7].");
4323 case Match_InvalidSVEExactFPImmOperandHalfOne:
4324 return Error(Loc,
"Invalid floating point constant, expected 0.5 or 1.0.");
4325 case Match_InvalidSVEExactFPImmOperandHalfTwo:
4326 return Error(Loc,
"Invalid floating point constant, expected 0.5 or 2.0.");
4327 case Match_InvalidSVEExactFPImmOperandZeroOne:
4328 return Error(Loc,
"Invalid floating point constant, expected 0.0 or 1.0.");
4336 bool AArch64AsmParser::MatchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
4339 uint64_t &ErrorInfo,
4340 bool MatchingInlineAsm) {
4341 assert(!Operands.
empty() &&
"Unexpect empty operand list!");
4342 AArch64Operand &
Op =
static_cast<AArch64Operand &
>(*Operands[0]);
4343 assert(Op.isToken() &&
"Leading operand should always be a mnemonic!");
4346 unsigned NumOperands = Operands.
size();
4348 if (NumOperands == 4 && Tok ==
"lsl") {
4349 AArch64Operand &Op2 =
static_cast<AArch64Operand &
>(*Operands[2]);
4350 AArch64Operand &Op3 =
static_cast<AArch64Operand &
>(*Operands[3]);
4351 if (Op2.isScalarReg() && Op3.isImm()) {
4354 uint64_t Op3Val = Op3CE->
getValue();
4355 uint64_t NewOp3Val = 0;
4356 uint64_t NewOp4Val = 0;
4357 if (AArch64MCRegisterClasses[AArch64::GPR32allRegClassID].
contains(
4359 NewOp3Val = (32 - Op3Val) & 0x1f;
4360 NewOp4Val = 31 - Op3Val;
4362 NewOp3Val = (64 - Op3Val) & 0x3f;
4363 NewOp4Val = 63 - Op3Val;
4369 Operands[0] = AArch64Operand::CreateToken(
4370 "ubfm",
false, Op.getStartLoc(), getContext());
4371 Operands.
push_back(AArch64Operand::CreateImm(
4372 NewOp4, Op3.getStartLoc(), Op3.getEndLoc(), getContext()));
4373 Operands[3] = AArch64Operand::CreateImm(NewOp3, Op3.getStartLoc(),
4374 Op3.getEndLoc(), getContext());
4377 }
else if (NumOperands == 4 && Tok ==
"bfc") {
4379 AArch64Operand &Op1 =
static_cast<AArch64Operand &
>(*Operands[1]);
4380 AArch64Operand LSBOp =
static_cast<AArch64Operand &
>(*Operands[2]);
4381 AArch64Operand WidthOp =
static_cast<AArch64Operand &
>(*Operands[3]);
4383 if (Op1.isScalarReg() && LSBOp.isImm() && WidthOp.isImm()) {
4387 if (LSBCE && WidthCE) {
4389 uint64_t Width = WidthCE->getValue();
4391 uint64_t RegWidth = 0;
4392 if (AArch64MCRegisterClasses[AArch64::GPR64allRegClassID].
contains(
4398 if (LSB >= RegWidth)
4399 return Error(LSBOp.getStartLoc(),
4400 "expected integer in range [0, 31]");
4401 if (Width < 1 || Width > RegWidth)
4402 return Error(WidthOp.getStartLoc(),
4403 "expected integer in range [1, 32]");
4407 ImmR = (32 - LSB) & 0x1f;
4409 ImmR = (64 - LSB) & 0x3f;
4411 uint64_t ImmS = Width - 1;
4413 if (ImmR != 0 && ImmS >= ImmR)
4414 return Error(WidthOp.getStartLoc(),
4415 "requested insert overflows register");
4419 Operands[0] = AArch64Operand::CreateToken(
4420 "bfm",
false, Op.getStartLoc(), getContext());
4421 Operands[2] = AArch64Operand::CreateReg(
4424 Operands[3] = AArch64Operand::CreateImm(
4425 ImmRExpr, LSBOp.getStartLoc(), LSBOp.getEndLoc(), getContext());
4426 Operands.emplace_back(
4427 AArch64Operand::CreateImm(ImmSExpr, WidthOp.getStartLoc(),
4428 WidthOp.getEndLoc(), getContext()));
4431 }
else if (NumOperands == 5) {
4434 if (Tok ==
"bfi" || Tok ==
"sbfiz" || Tok ==
"ubfiz") {
4435 AArch64Operand &Op1 =
static_cast<AArch64Operand &
>(*Operands[1]);
4436 AArch64Operand &Op3 =
static_cast<AArch64Operand &
>(*Operands[3]);
4437 AArch64Operand &Op4 =
static_cast<AArch64Operand &
>(*Operands[4]);
4439 if (Op1.isScalarReg() && Op3.isImm() && Op4.isImm()) {
4443 if (Op3CE && Op4CE) {
4444 uint64_t Op3Val = Op3CE->
getValue();
4445 uint64_t Op4Val = Op4CE->getValue();
4447 uint64_t RegWidth = 0;
4448 if (AArch64MCRegisterClasses[AArch64::GPR64allRegClassID].
contains(
4454 if (Op3Val >= RegWidth)
4455 return Error(Op3.getStartLoc(),
4456 "expected integer in range [0, 31]");
4457 if (Op4Val < 1 || Op4Val > RegWidth)
4458 return Error(Op4.getStartLoc(),
4459 "expected integer in range [1, 32]");
4461 uint64_t NewOp3Val = 0;
4463 NewOp3Val = (32 - Op3Val) & 0x1f;
4465 NewOp3Val = (64 - Op3Val) & 0x3f;
4467 uint64_t NewOp4Val = Op4Val - 1;
4469 if (NewOp3Val != 0 && NewOp4Val >= NewOp3Val)
4470 return Error(Op4.getStartLoc(),
4471 "requested insert overflows register");
4477 Operands[3] = AArch64Operand::CreateImm(
4478 NewOp3, Op3.getStartLoc(), Op3.getEndLoc(), getContext());
4479 Operands[4] = AArch64Operand::CreateImm(
4480 NewOp4, Op4.getStartLoc(), Op4.getEndLoc(), getContext());
4482 Operands[0] = AArch64Operand::CreateToken(
4483 "bfm",
false, Op.getStartLoc(), getContext());
4484 else if (Tok ==
"sbfiz")
4485 Operands[0] = AArch64Operand::CreateToken(
4486 "sbfm",
false, Op.getStartLoc(), getContext());
4487 else if (Tok ==
"ubfiz")
4488 Operands[0] = AArch64Operand::CreateToken(
4489 "ubfm",
false, Op.getStartLoc(), getContext());
4497 }
else if (NumOperands == 5 &&
4498 (Tok ==
"bfxil" || Tok ==
"sbfx" || Tok ==
"ubfx")) {
4499 AArch64Operand &Op1 =
static_cast<AArch64Operand &
>(*Operands[1]);
4500 AArch64Operand &Op3 =
static_cast<AArch64Operand &
>(*Operands[3]);
4501 AArch64Operand &Op4 =
static_cast<AArch64Operand &
>(*Operands[4]);
4503 if (Op1.isScalarReg() && Op3.isImm() && Op4.isImm()) {
4507 if (Op3CE && Op4CE) {
4508 uint64_t Op3Val = Op3CE->
getValue();
4509 uint64_t Op4Val = Op4CE->getValue();
4511 uint64_t RegWidth = 0;
4512 if (AArch64MCRegisterClasses[AArch64::GPR64allRegClassID].
contains(
4518 if (Op3Val >= RegWidth)
4519 return Error(Op3.getStartLoc(),
4520 "expected integer in range [0, 31]");
4521 if (Op4Val < 1 || Op4Val > RegWidth)
4522 return Error(Op4.getStartLoc(),
4523 "expected integer in range [1, 32]");
4525 uint64_t NewOp4Val = Op3Val + Op4Val - 1;
4527 if (NewOp4Val >= RegWidth || NewOp4Val < Op3Val)
4528 return Error(Op4.getStartLoc(),
4529 "requested extract overflows register");
4533 Operands[4] = AArch64Operand::CreateImm(
4534 NewOp4, Op4.getStartLoc(), Op4.getEndLoc(), getContext());
4536 Operands[0] = AArch64Operand::CreateToken(
4537 "bfm",
false, Op.getStartLoc(), getContext());
4538 else if (Tok ==
"sbfx")
4539 Operands[0] = AArch64Operand::CreateToken(
4540 "sbfm",
false, Op.getStartLoc(), getContext());
4541 else if (Tok ==
"ubfx")
4542 Operands[0] = AArch64Operand::CreateToken(
4543 "ubfm",
false, Op.getStartLoc(), getContext());
4555 if (getSTI().getFeatureBits()[AArch64::FeatureZCZeroingFPWorkaround] &&
4556 NumOperands == 4 && Tok ==
"movi") {
4557 AArch64Operand &Op1 =
static_cast<AArch64Operand &
>(*Operands[1]);
4558 AArch64Operand &Op2 =
static_cast<AArch64Operand &
>(*Operands[2]);
4559 AArch64Operand &Op3 =
static_cast<AArch64Operand &
>(*Operands[3]);
4560 if ((Op1.isToken() && Op2.isNeonVectorReg() && Op3.isImm()) ||
4561 (Op1.isNeonVectorReg() && Op2.isToken() && Op3.isImm())) {
4562 StringRef Suffix = Op1.isToken() ? Op1.getToken() : Op2.getToken();
4563 if (Suffix.
lower() ==
".2d" &&
4564 cast<MCConstantExpr>(Op3.getImm())->getValue() == 0) {
4565 Warning(IDLoc,
"instruction movi.2d with immediate #0 may not function" 4566 " correctly on this CPU, converting to equivalent movi.16b");
4568 unsigned Idx = Op1.isToken() ? 1 : 2;
4569 Operands[Idx] = AArch64Operand::CreateToken(
".16b",
false, IDLoc,
4578 if (NumOperands == 3 && (Tok ==
"sxtw" || Tok ==
"uxtw")) {
4581 AArch64Operand &Op =
static_cast<AArch64Operand &
>(*Operands[2]);
4582 if (Op.isScalarReg()) {
4585 Op.getStartLoc(), Op.getEndLoc(),
4590 else if (NumOperands == 3 && (Tok ==
"sxtb" || Tok ==
"sxth")) {
4591 AArch64Operand &Op =
static_cast<AArch64Operand &
>(*Operands[1]);
4592 if (Op.isScalarReg() &&
4593 AArch64MCRegisterClasses[AArch64::GPR64allRegClassID].contains(
4597 AArch64Operand &Op =
static_cast<AArch64Operand &
>(*Operands[2]);
4598 if (Op.isScalarReg()) {
4602 Op.getEndLoc(), getContext());
4607 else if (NumOperands == 3 && (Tok ==
"uxtb" || Tok ==
"uxth")) {
4608 AArch64Operand &Op =
static_cast<AArch64Operand &
>(*Operands[1]);
4609 if (Op.isScalarReg() &&
4610 AArch64MCRegisterClasses[AArch64::GPR64allRegClassID].contains(
4614 AArch64Operand &Op =
static_cast<AArch64Operand &
>(*Operands[1]);
4615 if (Op.isScalarReg()) {
4619 Op.getEndLoc(), getContext());
4627 unsigned MatchResult =
4628 MatchInstructionImpl(Operands, Inst, ErrorInfo, MatchingInlineAsm, 1);
4632 if (MatchResult != Match_Success) {
4635 auto ShortFormNEONErrorInfo = ErrorInfo;
4636 auto ShortFormNEONMatchResult = MatchResult;
4639 MatchInstructionImpl(Operands, Inst, ErrorInfo, MatchingInlineAsm, 0);
4644 if (MatchResult == Match_InvalidOperand && ErrorInfo == 1 &&
4645 Operands.
size() > 1 && ((AArch64Operand &)*Operands[1]).isToken() &&
4646 ((AArch64Operand &)*Operands[1]).isTokenSuffix()) {
4647 MatchResult = ShortFormNEONMatchResult;
4648 ErrorInfo = ShortFormNEONErrorInfo;
4652 switch (MatchResult) {
4653 case Match_Success: {
4656 NumOperands = Operands.
size();
4657 for (
unsigned i = 1; i < NumOperands; ++i)
4658 OperandLocs.
push_back(Operands[i]->getStartLoc());
4659 if (validateInstruction(Inst, IDLoc, OperandLocs))
4666 case Match_MissingFeature: {
4667 assert(ErrorInfo &&
"Unknown missing feature!");
4670 std::string Msg =
"instruction requires:";
4672 for (
unsigned i = 0; i < (
sizeof(ErrorInfo)*8-1); ++i) {
4673 if (ErrorInfo & Mask) {
4679 return Error(IDLoc, Msg);
4681 case Match_MnemonicFail:
4682 return showMatchError(IDLoc, MatchResult, ErrorInfo, Operands);
4683 case Match_InvalidOperand: {
4684 SMLoc ErrorLoc = IDLoc;
4686 if (ErrorInfo != ~0ULL) {
4687 if (ErrorInfo >= Operands.
size())
4688 return Error(IDLoc,
"too few operands for instruction",
4689 SMRange(IDLoc, getTok().getLoc()));
4691 ErrorLoc = ((AArch64Operand &)*Operands[ErrorInfo]).getStartLoc();
4692 if (ErrorLoc ==
SMLoc())
4697 if (((AArch64Operand &)*Operands[ErrorInfo]).isToken() &&
4698 ((AArch64Operand &)*Operands[ErrorInfo]).isTokenSuffix())
4699 MatchResult = Match_InvalidSuffix;
4701 return showMatchError(ErrorLoc, MatchResult, ErrorInfo, Operands);
4703 case Match_InvalidTiedOperand:
4704 case Match_InvalidMemoryIndexed1:
4705 case Match_InvalidMemoryIndexed2:
4706 case Match_InvalidMemoryIndexed4:
4707 case Match_InvalidMemoryIndexed8:
4708 case Match_InvalidMemoryIndexed16:
4709 case Match_InvalidCondCode:
4710 case Match_AddSubRegExtendSmall:
4711 case Match_AddSubRegExtendLarge:
4712 case Match_AddSubSecondSource:
4713 case Match_LogicalSecondSource:
4714 case Match_AddSubRegShift32:
4715 case Match_AddSubRegShift64:
4716 case Match_InvalidMovImm32Shift:
4717 case Match_InvalidMovImm64Shift:
4718 case Match_InvalidFPImm:
4719 case Match_InvalidMemoryWExtend8:
4720 case Match_InvalidMemoryWExtend16:
4721 case Match_InvalidMemoryWExtend32:
4722 case Match_InvalidMemoryWExtend64:
4723 case Match_InvalidMemoryWExtend128:
4724 case Match_InvalidMemoryXExtend8:
4725 case Match_InvalidMemoryXExtend16:
4726 case Match_InvalidMemoryXExtend32:
4727 case Match_InvalidMemoryXExtend64:
4728 case Match_InvalidMemoryXExtend128:
4729 case Match_InvalidMemoryIndexed1SImm4:
4730 case Match_InvalidMemoryIndexed2SImm4:
4731 case Match_InvalidMemoryIndexed3SImm4:
4732 case Match_InvalidMemoryIndexed4SImm4:
4733 case Match_InvalidMemoryIndexed1SImm6:
4734 case Match_InvalidMemoryIndexed16SImm4:
4735 case Match_InvalidMemoryIndexed4SImm7:
4736 case Match_InvalidMemoryIndexed8SImm7:
4737 case Match_InvalidMemoryIndexed16SImm7:
4738 case Match_InvalidMemoryIndexed8UImm5:
4739 case Match_InvalidMemoryIndexed4UImm5:
4740 case Match_InvalidMemoryIndexed2UImm5:
4741 case Match_InvalidMemoryIndexed1UImm6:
4742 case Match_InvalidMemoryIndexed2UImm6:
4743 case Match_InvalidMemoryIndexed4UImm6:
4744 case Match_InvalidMemoryIndexed8UImm6:
4745 case Match_InvalidMemoryIndexedSImm6:
4746 case Match_InvalidMemoryIndexedSImm5:
4747 case Match_InvalidMemoryIndexedSImm8:
4748 case Match_InvalidMemoryIndexedSImm9:
4749 case Match_InvalidMemoryIndexed8SImm10:
4750 case Match_InvalidImm0_1:
4751 case Match_InvalidImm0_7:
4752 case Match_InvalidImm0_15:
4753 case Match_InvalidImm0_31:
4754 case Match_InvalidImm0_63:
4755 case Match_InvalidImm0_127:
4756 case Match_InvalidImm0_255:
4757 case Match_InvalidImm0_65535:
4758 case Match_InvalidImm1_8:
4759 case Match_InvalidImm1_16:
4760 case Match_InvalidImm1_32:
4761 case Match_InvalidImm1_64:
4762 case Match_InvalidSVEAddSubImm8:
4763 case Match_InvalidSVEAddSubImm16:
4764 case Match_InvalidSVEAddSubImm32:
4765 case Match_InvalidSVEAddSubImm64:
4766 case Match_InvalidSVECpyImm8:
4767 case Match_InvalidSVECpyImm16:
4768 case Match_InvalidSVECpyImm32:
4769 case Match_InvalidSVECpyImm64:
4770 case Match_InvalidIndexRange1_1:
4771 case Match_InvalidIndexRange0_15:
4772 case Match_InvalidIndexRange0_7:
4773 case Match_InvalidIndexRange0_3:
4774 case Match_InvalidIndexRange0_1:
4775 case Match_InvalidSVEIndexRange0_63:
4776 case Match_InvalidSVEIndexRange0_31:
4777 case Match_InvalidSVEIndexRange0_15:
4778 case Match_InvalidSVEIndexRange0_7:
4779 case Match_InvalidSVEIndexRange0_3:
4780 case Match_InvalidLabel:
4781 case Match_InvalidComplexRotationEven:
4782 case Match_InvalidComplexRotationOdd:
4783 case Match_InvalidGPR64shifted8:
4784 case Match_InvalidGPR64shifted16:
4785 case Match_InvalidGPR64shifted32:
4786 case Match_InvalidGPR64shifted64:
4787 case Match_InvalidGPR64NoXZRshifted8:
4788 case Match_InvalidGPR64NoXZRshifted16:
4789 case Match_InvalidGPR64NoXZRshifted32:
4790 case Match_InvalidGPR64NoXZRshifted64:
4791 case Match_InvalidZPR32UXTW8:
4792 case Match_InvalidZPR32UXTW16:
4793 case Match_InvalidZPR32UXTW32:
4794 case Match_InvalidZPR32UXTW64:
4795 case Match_InvalidZPR32SXTW8:
4796 case Match_InvalidZPR32SXTW16:
4797 case Match_InvalidZPR32SXTW32:
4798 case Match_InvalidZPR32SXTW64:
4799 case Match_InvalidZPR64UXTW8:
4800 case Match_InvalidZPR64SXTW8:
4801 case Match_InvalidZPR64UXTW16:
4802 case Match_InvalidZPR64SXTW16:
4803 case Match_InvalidZPR64UXTW32:
4804 case Match_InvalidZPR64SXTW32:
4805 case Match_InvalidZPR64UXTW64:
4806 case Match_InvalidZPR64SXTW64:
4807 case Match_InvalidZPR32LSL8:
4808 case Match_InvalidZPR32LSL16:
4809 case Match_InvalidZPR32LSL32:
4810 case Match_InvalidZPR32LSL64:
4811 case Match_InvalidZPR64LSL8:
4812 case Match_InvalidZPR64LSL16:
4813 case Match_InvalidZPR64LSL32:
4814 case Match_InvalidZPR64LSL64:
4815 case Match_InvalidZPR0:
4816 case Match_InvalidZPR8:
4817 case Match_InvalidZPR16:
4818 case Match_InvalidZPR32:
4819 case Match_InvalidZPR64:
4820 case Match_InvalidZPR128:
4821 case Match_InvalidZPR_3b8:
4822 case Match_InvalidZPR_3b16:
4823 case Match_InvalidZPR_3b32:
4824 case Match_InvalidZPR_4b16:
4825 case Match_InvalidZPR_4b32:
4826 case Match_InvalidZPR_4b64:
4827 case Match_InvalidSVEPredicateAnyReg:
4828 case Match_InvalidSVEPattern:
4829 case Match_InvalidSVEPredicateBReg:
4830 case Match_InvalidSVEPredicateHReg:
4831 case Match_InvalidSVEPredicateSReg:
4832 case Match_InvalidSVEPredicateDReg:
4833 case Match_InvalidSVEPredicate3bAnyReg:
4834 case Match_InvalidSVEPredicate3bBReg:
4835 case Match_InvalidSVEPredicate3bHReg:
4836 case Match_InvalidSVEPredicate3bSReg:
4837 case Match_InvalidSVEPredicate3bDReg:
4838 case Match_InvalidSVEExactFPImmOperandHalfOne:
4839 case Match_InvalidSVEExactFPImmOperandHalfTwo:
4840 case Match_InvalidSVEExactFPImmOperandZeroOne:
4843 if (ErrorInfo >= Operands.
size())
4844 return Error(IDLoc,
"too few operands for instruction",
SMRange(IDLoc, (*Operands.
back()).getEndLoc()));
4847 SMLoc ErrorLoc = ((AArch64Operand &)*Operands[ErrorInfo]).getStartLoc();
4848 if (ErrorLoc ==
SMLoc())
4850 return showMatchError(ErrorLoc, MatchResult, ErrorInfo, Operands);
4858 bool AArch64AsmParser::ParseDirective(
AsmToken DirectiveID) {
4860 getContext().getObjectFileInfo()->getObjectFileType();
4865 if (IDVal ==
".arch")
4866 parseDirectiveArch(Loc);
4867 else if (IDVal ==
".cpu")
4868 parseDirectiveCPU(Loc);
4869 else if (IDVal ==
".tlsdesccall")
4870 parseDirectiveTLSDescCall(Loc);
4871 else if (IDVal ==
".ltorg" || IDVal ==
".pool")
4872 parseDirectiveLtorg(Loc);
4873 else if (IDVal ==
".unreq")
4874 parseDirectiveUnreq(Loc);
4875 else if (IDVal ==
".inst")
4876 parseDirectiveInst(Loc);
4879 parseDirectiveLOH(IDVal, Loc);
4887 static const struct {
4891 {
"crc", {AArch64::FeatureCRC} },
4892 {
"sm4", {AArch64::FeatureSM4} },
4893 {
"sha3", {AArch64::FeatureSHA3} },
4894 {
"sha2", {AArch64::FeatureSHA2} },
4895 {
"aes", {AArch64::FeatureAES} },
4896 {
"crypto", {AArch64::FeatureCrypto} },
4897 {
"fp", {AArch64::FeatureFPARMv8} },
4898 {
"simd", {AArch64::FeatureNEON} },
4899 {
"ras", {AArch64::FeatureRAS} },
4900 {
"lse", {AArch64::FeatureLSE} },
4911 const bool NoCrypto =
4913 "nocrypto") !=
std::end(RequestedExtensions));
4916 "crypto") !=
std::end(RequestedExtensions));
4918 if (!NoCrypto && Crypto) {
4923 case AArch64::ArchKind::ARMV8_1A:
4924 case AArch64::ArchKind::ARMV8_2A:
4925 case AArch64::ArchKind::ARMV8_3A:
4929 case AArch64::ArchKind::ARMV8_4A:
4936 }
else if (NoCrypto) {
4941 case AArch64::ArchKind::ARMV8_1A:
4942 case AArch64::ArchKind::ARMV8_2A:
4943 case AArch64::ArchKind::ARMV8_3A:
4944 RequestedExtensions.
push_back(
"nosha2");
4947 case AArch64::ArchKind::ARMV8_4A:
4949 RequestedExtensions.
push_back(
"nosha3");
4950 RequestedExtensions.
push_back(
"nosha2");
4959 bool AArch64AsmParser::parseDirectiveArch(
SMLoc L) {
4960 SMLoc ArchLoc = getLoc();
4963 std::tie(Arch, ExtensionString) =
4964 getParser().parseStringToEndOfStatement().
trim().
split(
'+');
4967 if (ID == AArch64::ArchKind::INVALID)
4968 return Error(ArchLoc,
"unknown arch name");
4974 std::vector<StringRef> AArch64Features;
4980 std::vector<std::string> ArchFeatures(AArch64Features.begin(), AArch64Features.end());
4984 if (!ExtensionString.
empty())
4985 ExtensionString.
split(RequestedExtensions,
'+');
4990 for (
auto Name : RequestedExtensions) {
4991 bool EnableFeature =
true;
4994 EnableFeature =
false;
4999 if (Extension.Name != Name)
5002 if (Extension.Features.none())
5006 ? (~Features & Extension.Features)
5007 : ( Features & Extension.Features);
5009 ComputeAvailableFeatures(STI.
ToggleFeature(ToggleFeatures));
5010 setAvailableFeatures(Features);
5023 bool AArch64AsmParser::parseDirectiveCPU(
SMLoc L) {
5024 SMLoc CurLoc = getLoc();
5027 std::tie(CPU, ExtensionString) =
5028 getParser().parseStringToEndOfStatement().
trim().
split(
'+');
5034 if (!ExtensionString.
empty())
5035 ExtensionString.
split(RequestedExtensions,
'+');
5039 if (!getSTI().isCPUStringValid(CPU)) {
5040 Error(CurLoc,
"unknown CPU name");
5051 for (
auto Name : RequestedExtensions) {
5055 bool EnableFeature =
true;
5058 EnableFeature =
false;
5062 bool FoundExtension =
false;
5064 if (Extension.Name != Name)
5067 if (Extension.Features.none())
5071 ? (~Features & Extension.Features)
5072 : ( Features & Extension.Features);
5074 ComputeAvailableFeatures(STI.
ToggleFeature(ToggleFeatures));
5075 setAvailableFeatures(Features);
5076 FoundExtension =
true;
5081 if (!FoundExtension)
5082 Error(CurLoc,
"unsupported architectural extension");
5091 bool AArch64AsmParser::parseDirectiveInst(
SMLoc Loc) {
5093 return Error(Loc,
"expected expression following '.inst' directive");
5095 auto parseOp = [&]() ->
bool {
5098 if (check(getParser().parseExpression(Expr), L,
"expected expression"))
5101 if (check(!Value, L,
"expected constant expression"))
5103 getTargetStreamer().emitInst(Value->
getValue());
5107 if (parseMany(parseOp))
5108 return addErrorSuffix(
" in '.inst' directive");
5114 bool AArch64AsmParser::parseDirectiveTLSDescCall(
SMLoc L) {
5116 if (check(getParser().parseIdentifier(Name), L,
5117 "expected symbol after directive") ||
5121 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
5129 getParser().getStreamer().EmitInstruction(Inst, getSTI());
5135 bool AArch64AsmParser::parseDirectiveLOH(
StringRef IDVal,
SMLoc Loc) {
5139 return TokError(
"expected an identifier or a number in directive");
5142 int64_t
Id = getParser().getTok().getIntVal();
5144 return TokError(
"invalid numeric identifier in directive");
5147 StringRef Name = getTok().getIdentifier();
5153 return TokError(
"invalid identifier in directive");
5161 assert(NbArgs != -1 &&
"Invalid number of arguments");
5164 for (
int Idx = 0; Idx < NbArgs; ++Idx) {
5166 if (getParser().parseIdentifier(Name))
5167 return TokError(
"expected identifier in directive");
5168 Args.
push_back(getContext().getOrCreateSymbol(Name));
5170 if (Idx + 1 == NbArgs)
5173 "unexpected token in '" +
Twine(IDVal) +
"' directive"))
5177 "unexpected token in '" +
Twine(IDVal) +
"' directive"))
5180 getStreamer().EmitLOHDirective((
MCLOHType)Kind, Args);
5186 bool AArch64AsmParser::parseDirectiveLtorg(
SMLoc L) {
5189 getTargetStreamer().emitCurrentConstantPool();
5195 bool AArch64AsmParser::parseDirectiveReq(
StringRef Name,
SMLoc L) {
5198 SMLoc SRegLoc = getLoc();
5205 RegisterKind = RegKind::NeonVector;
5206 ParseRes = tryParseVectorRegister(RegNum, Kind, RegKind::NeonVector);
5212 return Error(SRegLoc,
"vector register without type specifier expected");
5217 RegisterKind = RegKind::SVEDataVector;
5219 tryParseVectorRegister(RegNum, Kind, RegKind::SVEDataVector);
5225 return Error(SRegLoc,
5226 "sve vector register without type specifier expected");
5231 RegisterKind = RegKind::SVEPredicateVector;
5232 ParseRes = tryParseVectorRegister(RegNum, Kind, RegKind::SVEPredicateVector);
5238 return Error(SRegLoc,
5239 "sve predicate register without type specifier expected");
5243 return Error(SRegLoc,
"register name or alias expected");
5247 "unexpected input in .req directive"))
5250 auto pair = std::make_pair(RegisterKind, (
unsigned) RegNum);
5251 if (RegisterReqs.insert(std::make_pair(Name, pair)).first->second != pair)
5252 Warning(L,
"ignoring redefinition of register alias '" + Name +
"'");
5259 bool AArch64AsmParser::parseDirectiveUnreq(
SMLoc L) {
5262 return TokError(
"unexpected input in .unreq directive.");
5266 return addErrorSuffix(
"in '.unreq' directive");
5271 AArch64AsmParser::classifySymbolRef(
const MCExpr *Expr,
5279 if (
const AArch64MCExpr *AE = dyn_cast<AArch64MCExpr>(Expr)) {
5280 ELFRefKind = AE->getKind();
5281 Expr = AE->getSubExpr();
5287 DarwinRefKind = SE->
getKind();
5298 DarwinRefKind = SE->
getKind();
5327 #define GET_REGISTER_MATCHER 5328 #define GET_SUBTARGET_FEATURE_NAME 5329 #define GET_MATCHER_IMPLEMENTATION 5330 #define GET_MNEMONIC_SPELL_CHECKER 5331 #include "AArch64GenAsmMatcher.inc" 5337 AArch64Operand &
Op =
static_cast<AArch64Operand &
>(AsmOp);
5341 int64_t ExpectedVal;
5344 return Match_InvalidOperand;
5386 return Match_InvalidOperand;
5389 return Match_InvalidOperand;
5391 return Match_Success;
5392 return Match_InvalidOperand;
5396 AArch64AsmParser::tryParseGPRSeqPair(
OperandVector &Operands) {
5401 Error(S,
"expected register");
5411 AArch64MCRegisterClasses[AArch64::GPR32RegClassID];
5413 AArch64MCRegisterClasses[AArch64::GPR64RegClassID];
5415 bool isXReg = XRegClass.
contains(FirstReg),
5416 isWReg = WRegClass.
contains(FirstReg);
5417 if (!isXReg && !isWReg) {
5418 Error(S,
"expected first even register of a " 5419 "consecutive same-size even/odd register pair");
5426 if (FirstEncoding & 0x1) {
5427 Error(S,
"expected first even register of a " 5428 "consecutive same-size even/odd register pair");
5433 Error(getLoc(),
"expected comma");
5441 Res = tryParseScalarRegister(SecondReg);
5446 (isXReg && !XRegClass.
contains(SecondReg)) ||
5447 (isWReg && !WRegClass.
contains(SecondReg))) {
5448 Error(E,
"expected second odd register of a " 5449 "consecutive same-size even/odd register pair");
5456 &AArch64MCRegisterClasses[AArch64::XSeqPairsClassRegClassID]);
5459 &AArch64MCRegisterClasses[AArch64::WSeqPairsClassRegClassID]);
5463 getLoc(), getContext()));
5468 template <
bool ParseShiftExtend,
bool ParseSuffix>
5470 AArch64AsmParser::tryParseSVEDataVector(
OperandVector &Operands) {
5471 const SMLoc S = getLoc();
5477 tryParseVectorRegister(RegNum, Kind, RegKind::SVEDataVector);
5482 if (ParseSuffix && Kind.
empty())
5489 unsigned ElementWidth = KindRes->second;
5492 if (!ParseShiftExtend || getParser().getTok().isNot(
AsmToken::Comma)) {
5493 Operands.
push_back(AArch64Operand::CreateVectorReg(
5494 RegNum, RegKind::SVEDataVector, ElementWidth, S, S, getContext()));
5507 Res = tryParseOptionalShiftExtend(ExtOpnd);
5511 auto Ext =
static_cast<AArch64Operand *
>(ExtOpnd.
back().get());
5512 Operands.
push_back(AArch64Operand::CreateVectorReg(
5513 RegNum, RegKind::SVEDataVector, ElementWidth, S,
Ext->getEndLoc(),
5514 getContext(),
Ext->getShiftExtendType(),
Ext->getShiftExtendAmount(),
5515 Ext->hasShiftExtendAmount()));
5521 AArch64AsmParser::tryParseSVEPattern(
OperandVector &Operands) {
5524 SMLoc SS = getLoc();
5545 Pattern = MCE->getValue();
5548 auto Pat = AArch64SVEPredPattern::lookupSVEPREDPATByName(TokE.
getString());
5553 Pattern = Pat->Encoding;
5554 assert(Pattern >= 0 && Pattern < 32);
5559 SS, getLoc(), getContext()));
static bool isReg(const MCInst &MI, unsigned OpNo)
Represents a range in source code.
void push_back(const T &Elt)
const_iterator end(StringRef path)
Get end iterator over path.
Target & getTheAArch64beTarget()
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...
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.
Compute iterated dominance frontiers using a linear time algorithm.
AArch64::ArchKind getCPUArchKind(StringRef CPU)
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.
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.
static CondCode getInvertedCondCode(CondCode Code)
Describe properties that are true of each instruction in the target description file.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Target specific streamer interface.
bool isNot(TokenKind K) const
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
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)
const AsmToken & getTok() const
Get the current AsmToken from the stream.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, bool PrintSchedInfo=false)
Emit the given Instruction into the current section.
return AArch64::GPR64RegClass contains(Reg)
static SMLoc incrementLoc(SMLoc L, int Offset)
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...
opStatus convertFromString(StringRef, roundingMode)
static MCOperand createReg(unsigned Reg)
static ManagedStatic< DebugCounter > DC
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
bool contains(unsigned Reg) const
contains - Return true if the specified register is included in this register class.
const FeatureBitset & getFeatureBits() const
static bool isSVEAddSubImm(int64_t Imm)
Returns true if Imm is valid for ADD/SUB.
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.
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.
Target & getTheARM64Target()
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE R Default(T Value)
static bool isSVECpyImm(int64_t Imm)
Returns true if Imm is valid for CPY/DUP.
static bool isMem(const MachineInstr &MI, unsigned Op)
zlib-gnu style compression
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.
AArch64::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 ...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
int64_t getSExtValue() const
Get sign extended value.
RegisterMCAsmParser - Helper template for registering a target specific assembly parser, for use in the target machine initialization function.
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
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)...
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
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
MCRegisterClass - Base class of TargetRegisterClass.
FeatureBitset getRequiredFeatures() const
Instances of this class represent a single low-level machine instruction.
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.
std::size_t 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...
unsigned getMatchingSuperReg(unsigned 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...
LLVM_NODISCARD StringRef trim(char Char) const
Return string with consecutive Char characters starting from the left and right removed.
static const char * getShiftExtendName(AArch64_AM::ShiftExtendType ST)
getShiftName - Get the string encoding for the shift type.
size_t size() const
size - Get the array size.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
static int MCLOHNameToId(StringRef Name)
Interface to description of machine instruction set.
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.
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.
bool isIntN(unsigned N) const
Check if this APInt has an N-bits unsigned integer value.
virtual unsigned getReg() const =0
Binary assembler expressions.
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.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
int getOperandConstraint(unsigned OpNum, MCOI::OperandConstraint Constraint) const
Returns the value of the specific constraint if it is set.
static 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)
bool isSubRegisterEq(unsigned RegA, unsigned RegB) const
Returns true if RegB is a sub-register of RegA or if RegB == RegA.
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.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
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)
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & Case(StringLiteral S, T Value)
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)
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
uint16_t getEncodingValue(unsigned RegNo) const
Returns the encoding for RegNo.
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
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)
static std::string AArch64MnemonicSpellCheck(StringRef S, uint64_t FBS, unsigned VariantID=0)
bool isSignedIntN(unsigned N) const
Check if this APInt has an N-bits signed integer value.
Opcode getOpcode() const
Get the kind of this binary expression.
LLVM_NODISCARD std::string lower() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static int MCLOHIdToNbArgs(MCLOHType Kind)
const MCRegisterInfo * getRegisterInfo() const
LLVM Value Representation.
const FeatureBitset Features
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
This class implements an extremely fast bulk output stream that can only output to a stream...
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
void addOperand(const MCOperand &Op)
static const struct @349 ExtensionMap[]
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
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t find(char C, size_t From=0) const
Search for the first character C in the string.
static MCOperand createImm(int64_t Val)
bool getArchFeatures(ArchKind AK, std::vector< StringRef > &Features)
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
void LLVMInitializeAArch64AsmParser()
Force static initialization.
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.