@@ -88,7 +88,7 @@ class AArch64AsmParser : public MCTargetAsmParser {
8888 StringRef Mnemonic; // /< Instruction mnemonic.
8989
9090 // Map of register aliases registers via the .req directive.
91- StringMap<std::pair<RegKind, unsigned >> RegisterReqs;
91+ StringMap<std::pair<RegKind, MCRegister >> RegisterReqs;
9292
9393 class PrefixInfo {
9494 public:
@@ -165,7 +165,7 @@ class AArch64AsmParser : public MCTargetAsmParser {
165165 AArch64CC::CondCode parseCondCodeString (StringRef Cond,
166166 std::string &Suggestion);
167167 bool parseCondCode (OperandVector &Operands, bool invertCondCode);
168- unsigned matchRegisterNameAlias (StringRef Name, RegKind Kind);
168+ MCRegister matchRegisterNameAlias (StringRef Name, RegKind Kind);
169169 bool parseRegister (OperandVector &Operands);
170170 bool parseSymbolicImmVal (const MCExpr *&ImmVal);
171171 bool parseNeonVectorList (OperandVector &Operands);
@@ -391,7 +391,7 @@ class AArch64Operand : public MCParsedAsmOperand {
391391 };
392392
393393 struct RegOp {
394- unsigned RegNum ;
394+ MCRegister Reg ;
395395 RegKind Kind;
396396 int ElementWidth;
397397
@@ -417,7 +417,7 @@ class AArch64Operand : public MCParsedAsmOperand {
417417 };
418418
419419 struct MatrixRegOp {
420- unsigned RegNum ;
420+ MCRegister Reg ;
421421 unsigned ElementWidth;
422422 MatrixKind Kind;
423423 };
@@ -427,7 +427,7 @@ class AArch64Operand : public MCParsedAsmOperand {
427427 };
428428
429429 struct VectorListOp {
430- unsigned RegNum ;
430+ MCRegister Reg ;
431431 unsigned Count;
432432 unsigned Stride;
433433 unsigned NumElements;
@@ -688,12 +688,12 @@ class AArch64Operand : public MCParsedAsmOperand {
688688
689689 MCRegister getReg () const override {
690690 assert (Kind == k_Register && " Invalid access!" );
691- return Reg.RegNum ;
691+ return Reg.Reg ;
692692 }
693693
694694 unsigned getMatrixReg () const {
695695 assert (Kind == k_MatrixRegister && " Invalid access!" );
696- return MatrixReg.RegNum ;
696+ return MatrixReg.Reg ;
697697 }
698698
699699 unsigned getMatrixElementWidth () const {
@@ -718,7 +718,7 @@ class AArch64Operand : public MCParsedAsmOperand {
718718
719719 unsigned getVectorListStart () const {
720720 assert (Kind == k_VectorList && " Invalid access!" );
721- return VectorList.RegNum ;
721+ return VectorList.Reg ;
722722 }
723723
724724 unsigned getVectorListCount () const {
@@ -1264,15 +1264,15 @@ class AArch64Operand : public MCParsedAsmOperand {
12641264 bool isNeonVectorRegLo () const {
12651265 return Kind == k_Register && Reg.Kind == RegKind::NeonVector &&
12661266 (AArch64MCRegisterClasses[AArch64::FPR128_loRegClassID].contains (
1267- Reg.RegNum ) ||
1267+ Reg.Reg ) ||
12681268 AArch64MCRegisterClasses[AArch64::FPR64_loRegClassID].contains (
1269- Reg.RegNum ));
1269+ Reg.Reg ));
12701270 }
12711271
12721272 bool isNeonVectorReg0to7 () const {
12731273 return Kind == k_Register && Reg.Kind == RegKind::NeonVector &&
12741274 (AArch64MCRegisterClasses[AArch64::FPR128_0to7RegClassID].contains (
1275- Reg.RegNum ));
1275+ Reg.Reg ));
12761276 }
12771277
12781278 bool isMatrix () const { return Kind == k_MatrixRegister; }
@@ -1401,34 +1401,34 @@ class AArch64Operand : public MCParsedAsmOperand {
14011401
14021402 bool isGPR32as64 () const {
14031403 return Kind == k_Register && Reg.Kind == RegKind::Scalar &&
1404- AArch64MCRegisterClasses[AArch64::GPR64RegClassID].contains (Reg.RegNum );
1404+ AArch64MCRegisterClasses[AArch64::GPR64RegClassID].contains (Reg.Reg );
14051405 }
14061406
14071407 bool isGPR64as32 () const {
14081408 return Kind == k_Register && Reg.Kind == RegKind::Scalar &&
1409- AArch64MCRegisterClasses[AArch64::GPR32RegClassID].contains (Reg.RegNum );
1409+ AArch64MCRegisterClasses[AArch64::GPR32RegClassID].contains (Reg.Reg );
14101410 }
14111411
14121412 bool isGPR64x8 () const {
14131413 return Kind == k_Register && Reg.Kind == RegKind::Scalar &&
14141414 AArch64MCRegisterClasses[AArch64::GPR64x8ClassRegClassID].contains (
1415- Reg.RegNum );
1415+ Reg.Reg );
14161416 }
14171417
14181418 bool isWSeqPair () const {
14191419 return Kind == k_Register && Reg.Kind == RegKind::Scalar &&
14201420 AArch64MCRegisterClasses[AArch64::WSeqPairsClassRegClassID].contains (
1421- Reg.RegNum );
1421+ Reg.Reg );
14221422 }
14231423
14241424 bool isXSeqPair () const {
14251425 return Kind == k_Register && Reg.Kind == RegKind::Scalar &&
14261426 AArch64MCRegisterClasses[AArch64::XSeqPairsClassRegClassID].contains (
1427- Reg.RegNum );
1427+ Reg.Reg );
14281428 }
14291429
14301430 bool isSyspXzrPair () const {
1431- return isGPR64<AArch64::GPR64RegClassID>() && Reg.RegNum == AArch64::XZR;
1431+ return isGPR64<AArch64::GPR64RegClassID>() && Reg.Reg == AArch64::XZR;
14321432 }
14331433
14341434 template <int64_t Angle, int64_t Remainder>
@@ -1495,7 +1495,7 @@ class AArch64Operand : public MCParsedAsmOperand {
14951495 isTypedVectorList<VectorKind, NumRegs, NumElements, ElementWidth>();
14961496 if (!Res)
14971497 return DiagnosticPredicate::NoMatch;
1498- if (!AArch64MCRegisterClasses[RegClass].contains (VectorList.RegNum ))
1498+ if (!AArch64MCRegisterClasses[RegClass].contains (VectorList.Reg ))
14991499 return DiagnosticPredicate::NearMatch;
15001500 return DiagnosticPredicate::Match;
15011501 }
@@ -1507,9 +1507,9 @@ class AArch64Operand : public MCParsedAsmOperand {
15071507 ElementWidth, Stride>();
15081508 if (!Res)
15091509 return DiagnosticPredicate::NoMatch;
1510- if ((VectorList.RegNum < (AArch64::Z0 + Stride)) ||
1511- ((VectorList.RegNum >= AArch64::Z16) &&
1512- (VectorList.RegNum < (AArch64::Z16 + Stride))))
1510+ if ((VectorList.Reg < (AArch64::Z0 + Stride)) ||
1511+ ((VectorList.Reg >= AArch64::Z16) &&
1512+ (VectorList.Reg < (AArch64::Z16 + Stride))))
15131513 return DiagnosticPredicate::Match;
15141514 return DiagnosticPredicate::NoMatch;
15151515 }
@@ -1841,7 +1841,7 @@ class AArch64Operand : public MCParsedAsmOperand {
18411841
18421842 void addPPRorPNRRegOperands (MCInst &Inst, unsigned N) const {
18431843 assert (N == 1 && " Invalid number of operands!" );
1844- unsigned Reg = getReg ();
1844+ MCRegister Reg = getReg ();
18451845 // Normalise to PPR
18461846 if (Reg >= AArch64::PN0 && Reg <= AArch64::PN15)
18471847 Reg = Reg - AArch64::PN0 + AArch64::P0;
@@ -2336,13 +2336,12 @@ class AArch64Operand : public MCParsedAsmOperand {
23362336 }
23372337
23382338 static std::unique_ptr<AArch64Operand>
2339- CreateReg (unsigned RegNum , RegKind Kind, SMLoc S, SMLoc E, MCContext &Ctx,
2339+ CreateReg (MCRegister Reg , RegKind Kind, SMLoc S, SMLoc E, MCContext &Ctx,
23402340 RegConstraintEqualityTy EqTy = RegConstraintEqualityTy::EqualsReg,
23412341 AArch64_AM::ShiftExtendType ExtTy = AArch64_AM::LSL,
2342- unsigned ShiftAmount = 0 ,
2343- unsigned HasExplicitAmount = false ) {
2342+ unsigned ShiftAmount = 0 , unsigned HasExplicitAmount = false ) {
23442343 auto Op = std::make_unique<AArch64Operand>(k_Register, Ctx);
2345- Op->Reg .RegNum = RegNum ;
2344+ Op->Reg .Reg = Reg ;
23462345 Op->Reg .Kind = Kind;
23472346 Op->Reg .ElementWidth = 0 ;
23482347 Op->Reg .EqualityTy = EqTy;
@@ -2354,28 +2353,26 @@ class AArch64Operand : public MCParsedAsmOperand {
23542353 return Op;
23552354 }
23562355
2357- static std::unique_ptr<AArch64Operand>
2358- CreateVectorReg (unsigned RegNum, RegKind Kind, unsigned ElementWidth,
2359- SMLoc S, SMLoc E, MCContext &Ctx,
2360- AArch64_AM::ShiftExtendType ExtTy = AArch64_AM::LSL,
2361- unsigned ShiftAmount = 0 ,
2362- unsigned HasExplicitAmount = false ) {
2356+ static std::unique_ptr<AArch64Operand> CreateVectorReg (
2357+ MCRegister Reg, RegKind Kind, unsigned ElementWidth, SMLoc S, SMLoc E,
2358+ MCContext &Ctx, AArch64_AM::ShiftExtendType ExtTy = AArch64_AM::LSL,
2359+ unsigned ShiftAmount = 0 , unsigned HasExplicitAmount = false ) {
23632360 assert ((Kind == RegKind::NeonVector || Kind == RegKind::SVEDataVector ||
23642361 Kind == RegKind::SVEPredicateVector ||
23652362 Kind == RegKind::SVEPredicateAsCounter) &&
23662363 " Invalid vector kind" );
2367- auto Op = CreateReg (RegNum , Kind, S, E, Ctx, EqualsReg, ExtTy, ShiftAmount,
2364+ auto Op = CreateReg (Reg , Kind, S, E, Ctx, EqualsReg, ExtTy, ShiftAmount,
23682365 HasExplicitAmount);
23692366 Op->Reg .ElementWidth = ElementWidth;
23702367 return Op;
23712368 }
23722369
23732370 static std::unique_ptr<AArch64Operand>
2374- CreateVectorList (unsigned RegNum , unsigned Count, unsigned Stride,
2371+ CreateVectorList (MCRegister Reg , unsigned Count, unsigned Stride,
23752372 unsigned NumElements, unsigned ElementWidth,
23762373 RegKind RegisterKind, SMLoc S, SMLoc E, MCContext &Ctx) {
23772374 auto Op = std::make_unique<AArch64Operand>(k_VectorList, Ctx);
2378- Op->VectorList .RegNum = RegNum ;
2375+ Op->VectorList .Reg = Reg ;
23792376 Op->VectorList .Count = Count;
23802377 Op->VectorList .Stride = Stride;
23812378 Op->VectorList .NumElements = NumElements;
@@ -2586,10 +2583,10 @@ class AArch64Operand : public MCParsedAsmOperand {
25862583 }
25872584
25882585 static std::unique_ptr<AArch64Operand>
2589- CreateMatrixRegister (unsigned RegNum , unsigned ElementWidth, MatrixKind Kind,
2586+ CreateMatrixRegister (MCRegister Reg , unsigned ElementWidth, MatrixKind Kind,
25902587 SMLoc S, SMLoc E, MCContext &Ctx) {
25912588 auto Op = std::make_unique<AArch64Operand>(k_MatrixRegister, Ctx);
2592- Op->MatrixReg .RegNum = RegNum ;
2589+ Op->MatrixReg .Reg = Reg ;
25932590 Op->MatrixReg .ElementWidth = ElementWidth;
25942591 Op->MatrixReg .Kind = Kind;
25952592 Op->StartLoc = S;
@@ -2715,7 +2712,7 @@ void AArch64Operand::print(raw_ostream &OS, const MCAsmInfo &MAI) const {
27152712 break ;
27162713 }
27172714 case k_Register:
2718- OS << " <register " << getReg () << " >" ;
2715+ OS << " <register " << getReg (). id () << " >" ;
27192716 if (!getShiftExtendAmount () && !hasShiftExtendAmount ())
27202717 break ;
27212718 [[fallthrough]];
@@ -3048,53 +3045,53 @@ ParseStatus AArch64AsmParser::tryParseRegister(MCRegister &Reg, SMLoc &StartLoc,
30483045}
30493046
30503047// Matches a register name or register alias previously defined by '.req'
3051- unsigned AArch64AsmParser::matchRegisterNameAlias (StringRef Name,
3052- RegKind Kind) {
3053- unsigned RegNum = 0 ;
3054- if ((RegNum = matchSVEDataVectorRegName (Name)))
3055- return Kind == RegKind::SVEDataVector ? RegNum : 0 ;
3048+ MCRegister AArch64AsmParser::matchRegisterNameAlias (StringRef Name,
3049+ RegKind Kind) {
3050+ MCRegister Reg = MCRegister () ;
3051+ if ((Reg = matchSVEDataVectorRegName (Name)))
3052+ return Kind == RegKind::SVEDataVector ? Reg : MCRegister () ;
30563053
3057- if ((RegNum = matchSVEPredicateVectorRegName (Name)))
3058- return Kind == RegKind::SVEPredicateVector ? RegNum : 0 ;
3054+ if ((Reg = matchSVEPredicateVectorRegName (Name)))
3055+ return Kind == RegKind::SVEPredicateVector ? Reg : MCRegister () ;
30593056
3060- if ((RegNum = matchSVEPredicateAsCounterRegName (Name)))
3061- return Kind == RegKind::SVEPredicateAsCounter ? RegNum : 0 ;
3057+ if ((Reg = matchSVEPredicateAsCounterRegName (Name)))
3058+ return Kind == RegKind::SVEPredicateAsCounter ? Reg : MCRegister () ;
30623059
3063- if ((RegNum = MatchNeonVectorRegName (Name)))
3064- return Kind == RegKind::NeonVector ? RegNum : 0 ;
3060+ if ((Reg = MatchNeonVectorRegName (Name)))
3061+ return Kind == RegKind::NeonVector ? Reg : MCRegister () ;
30653062
3066- if ((RegNum = matchMatrixRegName (Name)))
3067- return Kind == RegKind::Matrix ? RegNum : 0 ;
3063+ if ((Reg = matchMatrixRegName (Name)))
3064+ return Kind == RegKind::Matrix ? Reg : MCRegister () ;
30683065
3069- if (Name.equals_insensitive (" zt0" ))
3066+ if (Name.equals_insensitive (" zt0" ))
30703067 return Kind == RegKind::LookupTable ? unsigned (AArch64::ZT0) : 0 ;
30713068
30723069 // The parsed register must be of RegKind Scalar
3073- if ((RegNum = MatchRegisterName (Name)))
3074- return (Kind == RegKind::Scalar) ? RegNum : 0 ;
3070+ if ((Reg = MatchRegisterName (Name)))
3071+ return (Kind == RegKind::Scalar) ? Reg : MCRegister () ;
30753072
3076- if (!RegNum ) {
3073+ if (!Reg ) {
30773074 // Handle a few common aliases of registers.
3078- if (auto RegNum = StringSwitch<unsigned >(Name.lower ())
3079- .Case (" fp" , AArch64::FP)
3080- .Case (" lr" , AArch64::LR)
3081- .Case (" x31" , AArch64::XZR)
3082- .Case (" w31" , AArch64::WZR)
3083- .Default (0 ))
3084- return Kind == RegKind::Scalar ? RegNum : 0 ;
3075+ if (MCRegister Reg = StringSwitch<unsigned >(Name.lower ())
3076+ .Case (" fp" , AArch64::FP)
3077+ .Case (" lr" , AArch64::LR)
3078+ .Case (" x31" , AArch64::XZR)
3079+ .Case (" w31" , AArch64::WZR)
3080+ .Default (0 ))
3081+ return Kind == RegKind::Scalar ? Reg : MCRegister () ;
30853082
30863083 // Check for aliases registered via .req. Canonicalize to lower case.
30873084 // That's more consistent since register names are case insensitive, and
30883085 // it's how the original entry was passed in from MC/MCParser/AsmParser.
30893086 auto Entry = RegisterReqs.find (Name.lower ());
30903087 if (Entry == RegisterReqs.end ())
3091- return 0 ;
3088+ return MCRegister () ;
30923089
3093- // set RegNum if the match is the right kind of register
3090+ // set Reg if the match is the right kind of register
30943091 if (Kind == Entry->getValue ().first )
3095- RegNum = Entry->getValue ().second ;
3092+ Reg = Entry->getValue ().second ;
30963093 }
3097- return RegNum ;
3094+ return Reg ;
30983095}
30993096
31003097unsigned AArch64AsmParser::getNumRegsForRegKind (RegKind K) {
@@ -3122,8 +3119,8 @@ ParseStatus AArch64AsmParser::tryParseScalarRegister(MCRegister &RegNum) {
31223119 return ParseStatus::NoMatch;
31233120
31243121 std::string lowerCase = Tok.getString ().lower ();
3125- unsigned Reg = matchRegisterNameAlias (lowerCase, RegKind::Scalar);
3126- if (Reg == 0 )
3122+ MCRegister Reg = matchRegisterNameAlias (lowerCase, RegKind::Scalar);
3123+ if (! Reg)
31273124 return ParseStatus::NoMatch;
31283125
31293126 RegNum = Reg;
@@ -3667,7 +3664,7 @@ ParseStatus AArch64AsmParser::tryParseMatrixRegister(OperandVector &Operands) {
36673664 }
36683665
36693666 // Try to parse matrix register.
3670- unsigned Reg = matchRegisterNameAlias (Name, RegKind::Matrix);
3667+ MCRegister Reg = matchRegisterNameAlias (Name, RegKind::Matrix);
36713668 if (!Reg)
36723669 return ParseStatus::NoMatch;
36733670
@@ -4130,12 +4127,12 @@ bool AArch64AsmParser::parseSyslAlias(StringRef Name, SMLoc NameLoc,
41304127 SMLoc startLoc = getLoc ();
41314128 const AsmToken ®Tok = getTok ();
41324129 StringRef reg = regTok.getString ();
4133- unsigned RegNum = matchRegisterNameAlias (reg.lower (), RegKind::Scalar);
4134- if (!RegNum )
4130+ MCRegister Reg = matchRegisterNameAlias (reg.lower (), RegKind::Scalar);
4131+ if (!Reg )
41354132 return TokError (" expected register operand" );
41364133
41374134 Operands.push_back (AArch64Operand::CreateReg (
4138- RegNum , RegKind::Scalar, startLoc, getLoc (), getContext (), EqualsReg));
4135+ Reg , RegKind::Scalar, startLoc, getLoc (), getContext (), EqualsReg));
41394136
41404137 Lex (); // Eat token
41414138 if (parseToken (AsmToken::Comma))
@@ -4453,7 +4450,7 @@ ParseStatus AArch64AsmParser::tryParseVectorRegister(MCRegister &Reg,
44534450 // a '.'.
44544451 size_t Start = 0 , Next = Name.find (' .' );
44554452 StringRef Head = Name.slice (Start, Next);
4456- unsigned RegNum = matchRegisterNameAlias (Head, MatchKind);
4453+ MCRegister RegNum = matchRegisterNameAlias (Head, MatchKind);
44574454
44584455 if (RegNum) {
44594456 if (Next != StringRef::npos) {
@@ -4937,13 +4934,13 @@ ParseStatus AArch64AsmParser::tryParseZTOperand(OperandVector &Operands) {
49374934 const AsmToken &Tok = getTok ();
49384935 std::string Name = Tok.getString ().lower ();
49394936
4940- unsigned RegNum = matchRegisterNameAlias (Name, RegKind::LookupTable);
4937+ MCRegister Reg = matchRegisterNameAlias (Name, RegKind::LookupTable);
49414938
4942- if (RegNum == 0 )
4939+ if (!Reg )
49434940 return ParseStatus::NoMatch;
49444941
49454942 Operands.push_back (AArch64Operand::CreateReg (
4946- RegNum , RegKind::LookupTable, StartLoc, getLoc (), getContext ()));
4943+ Reg , RegKind::LookupTable, StartLoc, getLoc (), getContext ()));
49474944 Lex (); // Eat register.
49484945
49494946 // Check if register is followed by an index
@@ -7651,7 +7648,7 @@ bool AArch64AsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
76517648 if (parseEOL ())
76527649 return true ;
76537650
7654- auto pair = std::make_pair (RegisterKind, ( unsigned ) RegNum);
7651+ auto pair = std::make_pair (RegisterKind, RegNum);
76557652 if (RegisterReqs.insert (std::make_pair (Name, pair)).first ->second != pair)
76567653 Warning (L, " ignoring redefinition of register alias '" + Name + " '" );
76577654
0 commit comments