diff options
author | Mingming Liu <mingmingl@google.com> | 2025-07-09 16:48:17 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-09 16:48:17 -0700 |
commit | 20daa73a0962efd22cee3bbf327ee35b22add39d (patch) | |
tree | 07e7ce94582c84a5cdd58dde9c46bdf6f1565779 /llvm/lib/ProfileData/SampleProfWriter.cpp | |
parent | cd65f8bf17ecfc9896fd9913905f182ad7ce1446 (diff) | |
download | llvm-20daa73a0962efd22cee3bbf327ee35b22add39d.zip llvm-20daa73a0962efd22cee3bbf327ee35b22add39d.tar.gz llvm-20daa73a0962efd22cee3bbf327ee35b22add39d.tar.bz2 |
[NFC]Codestyle changes for SampleFDO library (#147840)
* Introduce an error code for illegal_line_offset in sampleprof_error
namespace, and use it for line offset parsing error.
* Add `const` for `LineLocation::serialize`.
* Use structured binding, make_first/second_range in loops.
I'm working on a [sample-profile format
change](https://github.com/llvm/llvm-project/compare/users/mingmingl-llvm/samplefdo-profile-format)
to extend SampleFDO profile with vtable profiles. And this change splits
the non-functional changes.
Diffstat (limited to 'llvm/lib/ProfileData/SampleProfWriter.cpp')
-rw-r--r-- | llvm/lib/ProfileData/SampleProfWriter.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/llvm/lib/ProfileData/SampleProfWriter.cpp b/llvm/lib/ProfileData/SampleProfWriter.cpp index 71d2f52..9173a0f 100644 --- a/llvm/lib/ProfileData/SampleProfWriter.cpp +++ b/llvm/lib/ProfileData/SampleProfWriter.cpp @@ -592,16 +592,18 @@ std::error_code SampleProfileWriterText::writeSample(const FunctionSamples &S) { SampleSorter<LineLocation, FunctionSamplesMap> SortedCallsiteSamples( S.getCallsiteSamples()); Indent += 1; - for (const auto &I : SortedCallsiteSamples.get()) - for (const auto &FS : I->second) { - LineLocation Loc = I->first; - const FunctionSamples &CalleeSamples = FS.second; + for (const auto *Element : SortedCallsiteSamples.get()) { + // Element is a pointer to a pair of LineLocation and FunctionSamplesMap. + const auto &[Loc, FunctionSamplesMap] = *Element; + for (const FunctionSamples &CalleeSamples : + make_second_range(FunctionSamplesMap)) { OS.indent(Indent); Loc.print(OS); OS << ": "; if (std::error_code EC = writeSample(CalleeSamples)) return EC; } + } Indent -= 1; if (FunctionSamples::ProfileIsProbeBased) { @@ -836,12 +838,11 @@ std::error_code SampleProfileWriterBinary::writeBody(const FunctionSamples &S) { for (const auto &J : S.getCallsiteSamples()) NumCallsites += J.second.size(); encodeULEB128(NumCallsites, OS); - for (const auto &J : S.getCallsiteSamples()) - for (const auto &FS : J.second) { - LineLocation Loc = J.first; - const FunctionSamples &CalleeSamples = FS.second; + for (const auto &[Loc, CalleeFunctionSampleMap] : S.getCallsiteSamples()) + for (const auto &FunctionSample : + llvm::make_second_range(CalleeFunctionSampleMap)) { Loc.serialize(OS); - if (std::error_code EC = writeBody(CalleeSamples)) + if (std::error_code EC = writeBody(FunctionSample)) return EC; } |