Skip to content

[AsmParser] Replace starIsStartOfStatement with tokenIsStartOfStatement. #137997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2025

Conversation

nvjle
Copy link
Contributor

@nvjle nvjle commented Apr 30, 2025

Currently MCTargetAsmParser::starIsStartOfStatement checks for * at the start of the statement. There are other (currently) downstream back-ends that need the same treatment for other tokens. Instead of introducing bespoke APIs for each such token, we generalize (and rename) starIsStartOfStatement as tokenIsStartOfStatement which takes the token of interest as an argument.

Update the BPF AsmParser (the only upstream consumer today) to use the new version.

Currently `MCTargetAsmParser::starIsStartOfStatement` checks for `*`
at the start of the statement. There are other (currently) downstream
back-ends that need the same treatment for other tokens. Instead of
introducing bespoke APIs for each such token, we generalize (and rename)
starIsStartOfStatement as tokenIsStartOfStatement which takes the token
of interest as an argument.

Update the BPF AsmParser (the only upstream consumer today) to use the
new version.
@nvjle nvjle requested a review from yonghong-song April 30, 2025 17:09
@llvmbot llvmbot added the mc Machine (object) code label Apr 30, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 30, 2025

@llvm/pr-subscribers-mc

Author: Jason Eckhardt (nvjle)

Changes

Currently MCTargetAsmParser::starIsStartOfStatement checks for * at the start of the statement. There are other (currently) downstream back-ends that need the same treatment for other tokens. Instead of introducing bespoke APIs for each such token, we generalize (and rename) starIsStartOfStatement as tokenIsStartOfStatement which takes the token of interest as an argument.

Update the BPF AsmParser (the only upstream consumer today) to use the new version.


Full diff: https://github.com/llvm/llvm-project/pull/137997.diff

3 Files Affected:

  • (modified) llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h (+4-2)
  • (modified) llvm/lib/MC/MCParser/AsmParser.cpp (+2-4)
  • (modified) llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp (+3-1)
diff --git a/llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h b/llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h
index c7f098be70945..c94ae9442f028 100644
--- a/llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h
+++ b/llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h
@@ -508,8 +508,10 @@ class MCTargetAsmParser : public MCAsmParserExtension {
   virtual bool equalIsAsmAssignment() { return true; };
   // Return whether this start of statement identifier is a label
   virtual bool isLabel(AsmToken &Token) { return true; };
-  // Return whether this parser accept star as start of statement
-  virtual bool starIsStartOfStatement() { return false; };
+  // Return whether this parser accepts the given token as start of statement.
+  virtual bool tokenIsStartOfStatement(AsmToken::TokenKind Token) {
+    return false;
+  }
 
   virtual const MCExpr *applySpecifier(const MCExpr *E, uint32_t,
                                        MCContext &Ctx) {
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index aee1259eeb126..f27a27833858a 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -1769,11 +1769,9 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info,
     // Treat '}' as a valid identifier in this context.
     Lex();
     IDVal = "}";
-  } else if (Lexer.is(AsmToken::Star) &&
-             getTargetParser().starIsStartOfStatement()) {
-    // Accept '*' as a valid start of statement.
+  } else if (getTargetParser().tokenIsStartOfStatement(ID.getKind())) {
     Lex();
-    IDVal = "*";
+    IDVal = ID.getString();
   } else if (parseIdentifier(IDVal)) {
     if (!TheCondState.Ignore) {
       Lex(); // always eat a token
diff --git a/llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp b/llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp
index 494445fa89b5e..2e4819e5ede38 100644
--- a/llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp
+++ b/llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp
@@ -49,7 +49,9 @@ class BPFAsmParser : public MCTargetAsmParser {
   bool equalIsAsmAssignment() override { return false; }
   // "*" is used for dereferencing memory that it will be the start of
   // statement.
-  bool starIsStartOfStatement() override { return true; }
+  bool tokenIsStartOfStatement(AsmToken::TokenKind Token) override {
+    return Token == AsmToken::Star;
+  }
 
 #define GET_ASSEMBLER_HEADER
 #include "BPFGenAsmMatcher.inc"

@nvjle
Copy link
Contributor Author

nvjle commented May 6, 2025

Gentle ping for this tiny patch...

@nvjle nvjle requested a review from MaskRay May 7, 2025 12:47
@nvjle nvjle merged commit d56f23e into llvm:main May 7, 2025
13 checks passed
} else if (Lexer.is(AsmToken::Star) &&
getTargetParser().starIsStartOfStatement()) {
// Accept '*' as a valid start of statement.
} else if (getTargetParser().tokenIsStartOfStatement(ID.getKind())) {
Copy link
Contributor

@s-barannikov s-barannikov May 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LCurly/RCurly should be pushed into the new method as well, they are invalid at the start of a statement on most targets. In-tree exceptions are Hexagon (curlies are used for bundles) and X86 (used for various prefixes such as {evex}).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mc Machine (object) code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants