[PATCH] D150049: [RISCV] Simplify matchRegisterNameHelper interface. NFC

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat May 6 12:53:05 PDT 2023


craig.topper created this revision.
craig.topper added reviewers: asb, luismarques, kito-cheng, VincentWu.
Herald added subscribers: jobnoorman, luke, vkmr, frasercrmck, evandro, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya, arichardson.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added subscribers: pcwang-thead, eopXD, MaskRay.
Herald added a project: LLVM.

This previously returned a bool to indicate success or failure and
returns a register through an output parameter.

Some callers used the bool to check for success. Some callers checked
for RISCV::NoRegister.

To make everything uniform, return the MCRegister directly and update
all callers to use MCRegister::isValid().


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150049

Files:
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp


Index: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
===================================================================
--- llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -1441,11 +1441,10 @@
 
 // Attempts to match Name as a register (either using the default name or
 // alternative ABI names), setting RegNo to the matching register. Upon
-// failure, returns true and sets RegNo to 0. If IsRVE then registers
-// x16-x31 will be rejected.
-static bool matchRegisterNameHelper(bool IsRVE, MCRegister &RegNo,
-                                    StringRef Name) {
-  RegNo = MatchRegisterName(Name);
+// failure, returns a non-valid MCRegister. If IsRVE, then registers x16-x31
+// will be // rejected.
+static MCRegister matchRegisterNameHelper(bool IsRVE, StringRef Name) {
+  MCRegister RegNo = MatchRegisterName(Name);
   // The 16-/32- and 64-bit FPRs have the same asm name. Check that the initial
   // match always matches the 64-bit variant, and not the 16/32-bit one.
   assert(!(RegNo >= RISCV::F0_H && RegNo <= RISCV::F31_H));
@@ -1453,11 +1452,11 @@
   // The default FPR register class is based on the tablegen enum ordering.
   static_assert(RISCV::F0_D < RISCV::F0_H, "FPR matching must be updated");
   static_assert(RISCV::F0_D < RISCV::F0_F, "FPR matching must be updated");
-  if (RegNo == RISCV::NoRegister)
+  if (!RegNo.isValid())
     RegNo = MatchRegisterAltName(Name);
   if (IsRVE && RegNo >= RISCV::X16 && RegNo <= RISCV::X31)
-    RegNo = RISCV::NoRegister;
-  return RegNo == RISCV::NoRegister;
+    RegNo = MCRegister();
+  return RegNo;
 }
 
 bool RISCVAsmParser::parseRegister(MCRegister &RegNo, SMLoc &StartLoc,
@@ -1473,10 +1472,10 @@
   const AsmToken &Tok = getParser().getTok();
   StartLoc = Tok.getLoc();
   EndLoc = Tok.getEndLoc();
-  RegNo = 0;
   StringRef Name = getLexer().getTok().getIdentifier();
 
-  if (matchRegisterNameHelper(isRVE(), (MCRegister &)RegNo, Name))
+  RegNo = matchRegisterNameHelper(isRVE(), Name);
+  if (!RegNo.isValid())
     return MatchOperand_NoMatch;
 
   getParser().Lex(); // Eat identifier token.
@@ -1508,10 +1507,9 @@
     return MatchOperand_NoMatch;
   case AsmToken::Identifier:
     StringRef Name = getLexer().getTok().getIdentifier();
-    MCRegister RegNo;
-    matchRegisterNameHelper(isRVE(), RegNo, Name);
+    MCRegister RegNo = matchRegisterNameHelper(isRVE(), Name);
 
-    if (RegNo == RISCV::NoRegister) {
+    if (!RegNo.isValid()) {
       if (HadParens)
         getLexer().UnLex(LParen);
       return MatchOperand_NoMatch;
@@ -2050,10 +2048,9 @@
     Error(getLoc(), "expected '.t' suffix");
     return MatchOperand_ParseFail;
   }
-  MCRegister RegNo;
-  matchRegisterNameHelper(isRVE(), RegNo, Name);
+  MCRegister RegNo = matchRegisterNameHelper(isRVE(), Name);
 
-  if (RegNo == RISCV::NoRegister)
+  if (!RegNo.isValid())
     return MatchOperand_NoMatch;
   if (RegNo != RISCV::V0)
     return MatchOperand_NoMatch;
@@ -2069,10 +2066,9 @@
     return MatchOperand_NoMatch;
 
   StringRef Name = getLexer().getTok().getIdentifier();
-  MCRegister RegNo;
-  matchRegisterNameHelper(isRVE(), RegNo, Name);
+  MCRegister RegNo = matchRegisterNameHelper(isRVE(), Name);
 
-  if (RegNo == RISCV::NoRegister)
+  if (!RegNo.isValid())
     return MatchOperand_NoMatch;
   SMLoc S = getLoc();
   SMLoc E = SMLoc::getFromPointer(S.getPointer() + Name.size());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150049.520120.patch
Type: text/x-patch
Size: 3426 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230506/3c0e92e9/attachment.bin>


More information about the llvm-commits mailing list