[llvm] [PowerPC] Update matchRegisterName() to return MCRegister instead of bool (PR #111186)

Lei Huang via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 7 07:14:05 PDT 2024


https://github.com/lei137 updated https://github.com/llvm/llvm-project/pull/111186

>From 7e2b9b20fe9f091a68610899978735cb03df8216 Mon Sep 17 00:00:00 2001
From: Lei Huang <lei at ca.ibm.com>
Date: Fri, 23 Aug 2024 17:30:27 -0400
Subject: [PATCH 1/4] [PowerPC] Update matchRegisterName() to return MCRegister
 instead of bool

---
 .../Target/PowerPC/AsmParser/PPCAsmParser.cpp | 23 +++++++++----------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp b/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
index 597a976b076a52..d9ad273e0a13b2 100644
--- a/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
+++ b/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
@@ -103,7 +103,7 @@ class PPCAsmParser : public MCTargetAsmParser {
 
   bool isPPC64() const { return IsPPC64; }
 
-  bool matchRegisterName(MCRegister &RegNo, int64_t &IntVal);
+  MCRegister matchRegisterName(int64_t &IntVal);
 
   bool parseRegister(MCRegister &Reg, SMLoc &StartLoc, SMLoc &EndLoc) override;
   ParseStatus tryParseRegister(MCRegister &Reg, SMLoc &StartLoc,
@@ -1291,13 +1291,14 @@ bool PPCAsmParser::matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
   llvm_unreachable("Implement any new match types added!");
 }
 
-bool PPCAsmParser::matchRegisterName(MCRegister &RegNo, int64_t &IntVal) {
+MCRegister PPCAsmParser::matchRegisterName(int64_t &IntVal) {
   if (getParser().getTok().is(AsmToken::Percent))
     getParser().Lex(); // Eat the '%'.
 
   if (!getParser().getTok().is(AsmToken::Identifier))
-    return true;
+    return PPC::NoRegister;
 
+  MCRegister RegNo;
   StringRef Name = getParser().getTok().getString();
   if (Name.equals_insensitive("lr")) {
     RegNo = isPPC64() ? PPC::LR8 : PPC::LR;
@@ -1345,9 +1346,10 @@ bool PPCAsmParser::matchRegisterName(MCRegister &RegNo, int64_t &IntVal) {
              !Name.substr(3).getAsInteger(10, IntVal) && IntVal < 8) {
     RegNo = DMRRegs[IntVal];
   } else
-    return true;
+    return PPC::NoRegister;
+
   getParser().Lex();
-  return false;
+  return RegNo;
 }
 
 bool PPCAsmParser::parseRegister(MCRegister &Reg, SMLoc &StartLoc,
@@ -1362,9 +1364,9 @@ ParseStatus PPCAsmParser::tryParseRegister(MCRegister &Reg, SMLoc &StartLoc,
   const AsmToken &Tok = getParser().getTok();
   StartLoc = Tok.getLoc();
   EndLoc = Tok.getEndLoc();
-  Reg = PPC::NoRegister;
   int64_t IntVal;
-  if (matchRegisterName(Reg, IntVal))
+  Reg = matchRegisterName(IntVal);
+  if (!Reg)
     return ParseStatus::NoMatch;
   return ParseStatus::Success;
 }
@@ -1541,9 +1543,8 @@ bool PPCAsmParser::parseOperand(OperandVector &Operands) {
   // Special handling for register names.  These are interpreted
   // as immediates corresponding to the register number.
   case AsmToken::Percent: {
-    MCRegister RegNo;
     int64_t IntVal;
-    if (matchRegisterName(RegNo, IntVal))
+    if (! matchRegisterName(IntVal))
       return Error(S, "invalid register name");
 
     Operands.push_back(PPCOperand::CreateImm(IntVal, S, E, isPPC64()));
@@ -1627,8 +1628,7 @@ bool PPCAsmParser::parseOperand(OperandVector &Operands) {
     int64_t IntVal;
     switch (getLexer().getKind()) {
     case AsmToken::Percent: {
-      MCRegister RegNo;
-      if (matchRegisterName(RegNo, IntVal))
+      if (! matchRegisterName(IntVal))
         return Error(S, "invalid register name");
       break;
     }
@@ -1875,7 +1875,6 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializePowerPCAsmParser() {
   RegisterMCAsmParser<PPCAsmParser> D(getThePPC64LETarget());
 }
 
-#define GET_REGISTER_MATCHER
 #define GET_MATCHER_IMPLEMENTATION
 #define GET_MNEMONIC_SPELL_CHECKER
 #include "PPCGenAsmMatcher.inc"

>From bd13ac275a33da71c4bfb07a303d475df2494fa9 Mon Sep 17 00:00:00 2001
From: Lei Huang <lei at ca.ibm.com>
Date: Fri, 4 Oct 2024 13:30:57 -0400
Subject: [PATCH 2/4] restore define

---
 llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp b/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
index d9ad273e0a13b2..0f6efda8b3271e 100644
--- a/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
+++ b/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
@@ -1875,6 +1875,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializePowerPCAsmParser() {
   RegisterMCAsmParser<PPCAsmParser> D(getThePPC64LETarget());
 }
 
+#define GET_REGISTER_MATCHER
 #define GET_MATCHER_IMPLEMENTATION
 #define GET_MNEMONIC_SPELL_CHECKER
 #include "PPCGenAsmMatcher.inc"

>From 14ff64c8195a24e875ad904c8668afa36fad1919 Mon Sep 17 00:00:00 2001
From: Lei Huang <lei at ca.ibm.com>
Date: Fri, 4 Oct 2024 13:52:01 -0400
Subject: [PATCH 3/4] fix code format

---
 llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp b/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
index 0f6efda8b3271e..45fb90ba59d8a5 100644
--- a/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
+++ b/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
@@ -1544,7 +1544,7 @@ bool PPCAsmParser::parseOperand(OperandVector &Operands) {
   // as immediates corresponding to the register number.
   case AsmToken::Percent: {
     int64_t IntVal;
-    if (! matchRegisterName(IntVal))
+    if (!matchRegisterName(IntVal))
       return Error(S, "invalid register name");
 
     Operands.push_back(PPCOperand::CreateImm(IntVal, S, E, isPPC64()));
@@ -1628,7 +1628,7 @@ bool PPCAsmParser::parseOperand(OperandVector &Operands) {
     int64_t IntVal;
     switch (getLexer().getKind()) {
     case AsmToken::Percent: {
-      if (! matchRegisterName(IntVal))
+      if (!matchRegisterName(IntVal))
         return Error(S, "invalid register name");
       break;
     }

>From c9a2cbe956485e881b44f818d9c0e2dfa55ffa0d Mon Sep 17 00:00:00 2001
From: Lei Huang <lei at ca.ibm.com>
Date: Mon, 7 Oct 2024 10:13:43 -0400
Subject: [PATCH 4/4] as per review comment

---
 llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp b/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
index 45fb90ba59d8a5..39f2beb799d0b4 100644
--- a/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
+++ b/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
@@ -1296,7 +1296,7 @@ MCRegister PPCAsmParser::matchRegisterName(int64_t &IntVal) {
     getParser().Lex(); // Eat the '%'.
 
   if (!getParser().getTok().is(AsmToken::Identifier))
-    return PPC::NoRegister;
+    return MCRegister();
 
   MCRegister RegNo;
   StringRef Name = getParser().getTok().getString();
@@ -1346,7 +1346,7 @@ MCRegister PPCAsmParser::matchRegisterName(int64_t &IntVal) {
              !Name.substr(3).getAsInteger(10, IntVal) && IntVal < 8) {
     RegNo = DMRRegs[IntVal];
   } else
-    return PPC::NoRegister;
+    return MCRegister();
 
   getParser().Lex();
   return RegNo;



More information about the llvm-commits mailing list