-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[AsmParser][MCA] Fix handling of multi-character comments #147228
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
[AsmParser][MCA] Fix handling of multi-character comments #147228
Conversation
|
@llvm/pr-subscribers-mc Author: Alexander Shaposhnikov (alexander-shaposhnikov) ChangesThis PR adjusts the lexer (following the surrounding style) to make sure the comments are consumed Test plan: ninja check-all Full diff: https://github.com/llvm/llvm-project/pull/147228.diff 3 Files Affected:
diff --git a/llvm/lib/MC/MCParser/AsmLexer.cpp b/llvm/lib/MC/MCParser/AsmLexer.cpp
index 3db9ed3199dd8..968ccf776440b 100644
--- a/llvm/lib/MC/MCParser/AsmLexer.cpp
+++ b/llvm/lib/MC/MCParser/AsmLexer.cpp
@@ -834,8 +834,10 @@ AsmToken AsmLexer::LexToken() {
return LexLineComment();
}
- if (isAtStartOfComment(TokStart))
+ if (isAtStartOfComment(TokStart)) {
+ CurPtr += MAI.getCommentString().size() - 1;
return LexLineComment();
+ }
if (isAtStatementSeparator(TokStart)) {
CurPtr += strlen(MAI.getSeparatorString()) - 1;
diff --git a/llvm/test/MC/AsmParser/preserve-comments-aarch64-linux.s b/llvm/test/MC/AsmParser/preserve-comments-aarch64-linux.s
new file mode 100644
index 0000000000000..acaa90b012008
--- /dev/null
+++ b/llvm/test/MC/AsmParser/preserve-comments-aarch64-linux.s
@@ -0,0 +1,10 @@
+ // REQUIRES: aarch64-registered-target
+ // RUN: llvm-mc -preserve-comments -n -triple aarch64-unknown-linux-gnu < %s > %t
+ // RUN: diff -b %s %t
+
+ .text
+
+foo:
+ // comment here
+ nop
+ // comment here too
diff --git a/llvm/test/tools/llvm-mca/AArch64/Neoverse/llvm-mca-markers.s b/llvm/test/tools/llvm-mca/AArch64/Neoverse/llvm-mca-markers.s
new file mode 100644
index 0000000000000..d5a291b1d7102
--- /dev/null
+++ b/llvm/test/tools/llvm-mca/AArch64/Neoverse/llvm-mca-markers.s
@@ -0,0 +1,36 @@
+# NOTE: Assertions have been autogenerated by utils/update_mca_test_checks.py
+// RUN: llvm-mca -mtriple=aarch64-unknown-linux-gnu -mcpu=neoverse-v2 -iterations=1 -resource-pressure=false < %s | FileCheck %s
+
+.text
+// LLVM-MCA-BEGIN Empty
+// Empty sequence
+// LLVM-MCA-END
+
+ mul x1, x1, x1
+// LLVM-MCA-BEGIN NotEmpty
+ add x0, x0, x1
+// LLVM-MCA-END
+ mul x2, x2, x2
+
+# CHECK: [0] Code Region - NotEmpty
+
+# CHECK: Iterations: 1
+# CHECK-NEXT: Instructions: 1
+# CHECK-NEXT: Total Cycles: 4
+# CHECK-NEXT: Total uOps: 1
+
+# CHECK: Dispatch Width: 6
+# CHECK-NEXT: uOps Per Cycle: 0.25
+# CHECK-NEXT: IPC: 0.25
+# CHECK-NEXT: Block RThroughput: 0.2
+
+# CHECK: Instruction Info:
+# CHECK-NEXT: [1]: #uOps
+# CHECK-NEXT: [2]: Latency
+# CHECK-NEXT: [3]: RThroughput
+# CHECK-NEXT: [4]: MayLoad
+# CHECK-NEXT: [5]: MayStore
+# CHECK-NEXT: [6]: HasSideEffects (U)
+
+# CHECK: [1] [2] [3] [4] [5] [6] Instructions:
+# CHECK-NEXT: 1 1 0.17 add x0, x0, x1
|
22dc9bc to
9495a46
Compare
9f23068 to
8fd6b98
Compare
8fd6b98 to
9954e4c
Compare
|
no, llvm-mc still prints tabs (with -o), i think that's the reason why some other tests contain them as well |
9954e4c to
fe1689b
Compare
fe1689b to
3f489d3
Compare
This PR adjusts the lexer (following the surrounding style) to make sure the comments are consumed
exactly after
CommentString.This enables to feed the output of
clangon aarch64 intollvm-mca(previously broken - the comments//LLVM-MCA-BEGIN and //LLVM-MCA-END were actually ignored (see e.g. https://godbolt.org/z/PEzW7Tvra)).
Test plan: ninja check-all