Skip to content

Commit 4946db1

Browse files
[AsmParser][MCA] Fix handling of multi-character comments (#147228)
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 `clang` on aarch64 into `llvm-mca` (previously broken - the comments //LLVM-MCA-BEGIN and //LLVM-MCA-END were actually ignored) Test plan: ninja check-all
1 parent 556c846 commit 4946db1

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

llvm/lib/MC/MCParser/AsmLexer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,8 +834,10 @@ AsmToken AsmLexer::LexToken() {
834834
return LexLineComment();
835835
}
836836

837-
if (isAtStartOfComment(TokStart))
837+
if (isAtStartOfComment(TokStart)) {
838+
CurPtr += MAI.getCommentString().size() - 1;
838839
return LexLineComment();
840+
}
839841

840842
if (isAtStatementSeparator(TokStart)) {
841843
CurPtr += strlen(MAI.getSeparatorString()) - 1;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// REQUIRES: aarch64-registered-target
2+
// llvm-mc prints leading tabs, formatting of this test follows preserve-comments.s
3+
// RUN: llvm-mc -preserve-comments -n -triple aarch64-unknown-linux-gnu %s -o %t
4+
// RUN: diff -b %s %t
5+
6+
.text
7+
8+
foo:
9+
// comment here
10+
nop
11+
// comment here too
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mca_test_checks.py
2+
// RUN: llvm-mca -mtriple=aarch64-unknown-linux-gnu -mcpu=neoverse-v2 -iterations=1 -resource-pressure=false < %s | FileCheck %s
3+
4+
.text
5+
// LLVM-MCA-BEGIN Empty
6+
// Empty sequence
7+
// LLVM-MCA-END
8+
9+
mul x1, x1, x1
10+
// LLVM-MCA-BEGIN NotEmpty
11+
add x0, x0, x1
12+
// LLVM-MCA-END
13+
mul x2, x2, x2
14+
15+
# CHECK: [0] Code Region - NotEmpty
16+
17+
# CHECK: Iterations: 1
18+
# CHECK-NEXT: Instructions: 1
19+
# CHECK-NEXT: Total Cycles: 4
20+
# CHECK-NEXT: Total uOps: 1
21+
22+
# CHECK: Dispatch Width: 6
23+
# CHECK-NEXT: uOps Per Cycle: 0.25
24+
# CHECK-NEXT: IPC: 0.25
25+
# CHECK-NEXT: Block RThroughput: 0.2
26+
27+
# CHECK: Instruction Info:
28+
# CHECK-NEXT: [1]: #uOps
29+
# CHECK-NEXT: [2]: Latency
30+
# CHECK-NEXT: [3]: RThroughput
31+
# CHECK-NEXT: [4]: MayLoad
32+
# CHECK-NEXT: [5]: MayStore
33+
# CHECK-NEXT: [6]: HasSideEffects (U)
34+
35+
# CHECK: [1] [2] [3] [4] [5] [6] Instructions:
36+
# CHECK-NEXT: 1 1 0.17 add x0, x0, x1

0 commit comments

Comments
 (0)