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/SampleProf.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/SampleProf.cpp')
-rw-r--r-- | llvm/lib/ProfileData/SampleProf.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/llvm/lib/ProfileData/SampleProf.cpp b/llvm/lib/ProfileData/SampleProf.cpp index 0c47df3..60c1393 100644 --- a/llvm/lib/ProfileData/SampleProf.cpp +++ b/llvm/lib/ProfileData/SampleProf.cpp @@ -91,6 +91,8 @@ class SampleProfErrorCategoryType : public std::error_category { return "Zlib is unavailable"; case sampleprof_error::hash_mismatch: return "Function hash mismatch"; + case sampleprof_error::illegal_line_offset: + return "Illegal line offset in sample profile data"; } llvm_unreachable("A value of sampleprof_error has no message."); } @@ -150,7 +152,7 @@ std::error_code SampleRecord::serialize( LLVM_DUMP_METHOD void LineLocation::dump() const { print(dbgs()); } #endif -void LineLocation::serialize(raw_ostream &OS) { +void LineLocation::serialize(raw_ostream &OS) const { encodeULEB128(LineOffset, OS); encodeULEB128(Discriminator, OS); } @@ -203,12 +205,14 @@ void FunctionSamples::print(raw_ostream &OS, unsigned Indent) const { OS << "Samples collected in inlined callsites {\n"; SampleSorter<LineLocation, FunctionSamplesMap> SortedCallsiteSamples( CallsiteSamples); - for (const auto &CS : SortedCallsiteSamples.get()) { - for (const auto &FS : CS->second) { + for (const auto *Element : SortedCallsiteSamples.get()) { + // Element is a pointer to a pair of LineLocation and FunctionSamplesMap. + const auto &[Loc, FunctionSampleMap] = *Element; + for (const FunctionSamples &FuncSample : + llvm::make_second_range(FunctionSampleMap)) { OS.indent(Indent + 2); - OS << CS->first << ": inlined callee: " << FS.second.getFunction() - << ": "; - FS.second.print(OS, Indent + 4); + OS << Loc << ": inlined callee: " << FuncSample.getFunction() << ": "; + FuncSample.print(OS, Indent + 4); } } OS.indent(Indent); |