Skip to content

[llvm-profgen] Trim tail CR+LF for LBR record line #93210

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 24, 2024

Conversation

HaohaiWen
Copy link
Contributor

@HaohaiWen HaohaiWen commented May 23, 2024

On Windows, perfscript generated by sep contains CR+LF at the end of
LBR records line. This '\r' will be treated as a LBR record when running
llvm-profgen on Linux and then generate warning.

On Windows, perfscript generated by sep contains CR+LF at the end of
LBR records line. This '\r' will be treated as an LBR record and then
generate warning.
@llvmbot llvmbot added the PGO Profile Guided Optimizations label May 23, 2024
@llvmbot
Copy link
Member

llvmbot commented May 23, 2024

@llvm/pr-subscribers-pgo

Author: Haohai Wen (HaohaiWen)

Changes

On Windows, perfscript generated by sep contains CR+LF at the end of
LBR records line. This '\r' will be treated as an LBR record and then
generate warning.


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

1 Files Affected:

  • (modified) llvm/tools/llvm-profgen/PerfReader.cpp (+1-1)
diff --git a/llvm/tools/llvm-profgen/PerfReader.cpp b/llvm/tools/llvm-profgen/PerfReader.cpp
index e9442027aed3f..e63c6d61b3bfc 100644
--- a/llvm/tools/llvm-profgen/PerfReader.cpp
+++ b/llvm/tools/llvm-profgen/PerfReader.cpp
@@ -552,7 +552,7 @@ bool PerfScriptReader::extractLBRStack(TraceStream &TraceIt,
   //                           ... 0x4005c8/0x4005dc/P/-/-/0
   // It's in FIFO order and seperated by whitespace.
   SmallVector<StringRef, 32> Records;
-  TraceIt.getCurrentLine().split(Records, " ", -1, false);
+  TraceIt.getCurrentLine().rtrim().split(Records, " ", -1, false);
   auto WarnInvalidLBR = [](TraceStream &TraceIt) {
     WithColor::warning() << "Invalid address in LBR record at line "
                          << TraceIt.getLineNumber() << ": "

@HaohaiWen HaohaiWen requested a review from williamweixiao May 23, 2024 16:04
@WenleiHe WenleiHe requested review from wlei-llvm and WenleiHe May 23, 2024 17:12
Copy link
Member

@WenleiHe WenleiHe left a comment

Choose a reason for hiding this comment

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

LGTM, might be helpful to have a test case protecting against it since most of us don't have windows environment.

@HaohaiWen
Copy link
Contributor Author

LGTM, might be helpful to have a test case protecting against it since most of us don't have windows environment.

I'm not going to add a test since rtrim() will not do anything bad.
The warning message only prints the whole line:
warning: Invalid address in LBR record at line xxx

The reason is if we run llvm-profgen on Linux with perfscript generated by sep on Windows, StringRef treats '\n' as EOL and '\r' as a normal char so that profgen try to parse '\r' as LBR record.
That would not be problem when running llvm-profgen on Windows.
See

/*implicit*/ constexpr StringRef(const char *Str)

@HaohaiWen HaohaiWen merged commit 8f5a232 into llvm:main May 24, 2024
7 checks passed
@HaohaiWen HaohaiWen deleted the profgen branch May 24, 2024 01:03
@WenleiHe
Copy link
Member

LGTM, might be helpful to have a test case protecting against it since most of us don't have windows environment.

I'm not going to add a test since rtrim() will not do anything bad. The warning message only prints the whole line: warning: Invalid address in LBR record at line xxx

The reason is if we run llvm-profgen on Linux with perfscript generated by sep on Windows, StringRef treats '\n' as EOL and '\r' as a normal char so that profgen try to parse '\r' as LBR record. That would not be problem when running llvm-profgen on Windows. See

/*implicit*/ constexpr StringRef(const char *Str)

It's fine if we don't have test case for this small change. By protecting, what I mean is making sure if someone removes the rtrim later on (likely unintentionally with refactoring etc.), something will fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PGO Profile Guided Optimizations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants