[llvm-profgen][NFC] Factor out parseAddress#191594
Merged
aaupov merged 6 commits intoMay 1, 2026
Merged
Conversation
Created using spr 1.3.4
Created using spr 1.3.4 [skip ci]
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
Member
|
@llvm/pr-subscribers-pgo Author: Amir Ayupov (aaupov) ChangesReplace Full diff: https://github.com/llvm/llvm-project/pull/191594.diff 1 Files Affected:
diff --git a/llvm/tools/llvm-profgen/PerfReader.cpp b/llvm/tools/llvm-profgen/PerfReader.cpp
index bbfde1256f2cc..0d90a77fca185 100644
--- a/llvm/tools/llvm-profgen/PerfReader.cpp
+++ b/llvm/tools/llvm-profgen/PerfReader.cpp
@@ -656,6 +656,13 @@ void HybridPerfReader::unwindSamples() {
"frame to match.");
}
+/// Parse a hex address from \p Str.
+static bool parseAddress(StringRef Str, uint64_t &Addr, bool HasPrefix) {
+ if (Str.consume_front("0x") != HasPrefix)
+ return false;
+ return Str.getAsInteger(16, Addr);
+}
+
bool PerfScriptReader::extractLBRStack(TraceStream &TraceIt,
SmallVectorImpl<LBREntry> &LBRStack) {
// The raw format of LBR stack is like:
@@ -674,7 +681,7 @@ bool PerfScriptReader::extractLBRStack(TraceStream &TraceIt,
size_t Index = 0;
uint64_t LeadingAddr;
if (!Records.empty() && !Records[0].contains('/')) {
- if (Records[0].getAsInteger(16, LeadingAddr)) {
+ if (parseAddress(Records[0], LeadingAddr, false)) {
WarnInvalidLBR(TraceIt);
TraceIt.advance();
return false;
@@ -696,8 +703,8 @@ bool PerfScriptReader::extractLBRStack(TraceStream &TraceIt,
uint64_t Dst;
// Stop at broken LBR records.
- if (Addresses.size() < 2 || Addresses[0].substr(2).getAsInteger(16, Src) ||
- Addresses[1].substr(2).getAsInteger(16, Dst)) {
+ if (Addresses.size() < 2 || parseAddress(Addresses[0], Src, true) ||
+ parseAddress(Addresses[1], Dst, true)) {
WarnInvalidLBR(TraceIt);
break;
}
@@ -733,7 +740,7 @@ bool PerfScriptReader::extractCallstack(TraceStream &TraceIt,
while (!TraceIt.isAtEoF() && !TraceIt.getCurrentLine().starts_with(" 0x")) {
StringRef FrameStr = TraceIt.getCurrentLine().ltrim();
uint64_t FrameAddr = 0;
- if (FrameStr.getAsInteger(16, FrameAddr)) {
+ if (parseAddress(FrameStr, FrameAddr, false)) {
// We might parse a non-perf sample line like empty line and comments,
// skip it
TraceIt.advance();
@@ -1201,7 +1208,7 @@ PerfContent PerfScriptReader::checkPerfScriptType(StringRef FileName) {
// Detect sample with call stack
int32_t Count = 0;
while (!TraceIt.isAtEoF() &&
- !TraceIt.getCurrentLine().ltrim().getAsInteger(16, FrameAddr)) {
+ !parseAddress(TraceIt.getCurrentLine().ltrim(), FrameAddr, false)) {
Count++;
TraceIt.advance();
}
|
aaupov
commented
Apr 11, 2026
HighW4y2H3ll
approved these changes
Apr 17, 2026
Member
HighW4y2H3ll
left a comment
There was a problem hiding this comment.
LGTM! Thanks for cleanning up the Address parsing!
Created using spr 1.3.4 [skip ci]
enferex
pushed a commit
to enferex/llvm-project
that referenced
this pull request
May 5, 2026
Replace `StringRef::getAsInteger(16)` calls with explicit `parseAddress` to make it easier to support buildid-prefixed addresses in a follow-up (llvm#190863).
moar55
pushed a commit
to moar55/llvm-project
that referenced
this pull request
May 12, 2026
Replace `StringRef::getAsInteger(16)` calls with explicit `parseAddress` to make it easier to support buildid-prefixed addresses in a follow-up (llvm#190863).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace
StringRef::getAsInteger(16)calls with explicitparseAddresstomake it easier to support buildid-prefixed addresses in a follow-up (#190863).