Sample profiles - Re-arrange binary format to emit head samples only on top functions.
The number of samples collected at the head of a function only make
sense for top-level functions (i.e., those actually called as opposed to
being inlined inside another).
Head samples essentially count the time spent inside the function's
prologue. This clearly doesn't make sense for inlined functions, so we
were always emitting 0 in those.
llvm-svn: 250539
diff --git a/llvm/lib/ProfileData/SampleProfWriter.cpp b/llvm/lib/ProfileData/SampleProfWriter.cpp
index daf3783..a6e3cab 100644
--- a/llvm/lib/ProfileData/SampleProfWriter.cpp
+++ b/llvm/lib/ProfileData/SampleProfWriter.cpp
@@ -122,19 +122,15 @@
return sampleprof_error::success;
}
-/// \brief Write samples to a binary file.
-///
-/// \returns true if the samples were written successfully, false otherwise.
-std::error_code SampleProfileWriterBinary::write(StringRef FName,
- const FunctionSamples &S) {
+std::error_code SampleProfileWriterBinary::writeBody(StringRef FName,
+ const FunctionSamples &S) {
if (std::error_code EC = writeNameIdx(FName))
return EC;
encodeULEB128(S.getTotalSamples(), OS);
- encodeULEB128(S.getHeadSamples(), OS);
- encodeULEB128(S.getBodySamples().size(), OS);
// Emit all the body samples.
+ encodeULEB128(S.getBodySamples().size(), OS);
for (const auto &I : S.getBodySamples()) {
LineLocation Loc = I.first;
const SampleRecord &Sample = I.second;
@@ -158,13 +154,22 @@
const FunctionSamples &CalleeSamples = J.second;
encodeULEB128(Loc.LineOffset, OS);
encodeULEB128(Loc.Discriminator, OS);
- if (std::error_code EC = write(Loc.CalleeName, CalleeSamples))
+ if (std::error_code EC = writeBody(Loc.CalleeName, CalleeSamples))
return EC;
}
return sampleprof_error::success;
}
+/// \brief Write samples of a top-level function to a binary file.
+///
+/// \returns true if the samples were written successfully, false otherwise.
+std::error_code SampleProfileWriterBinary::write(StringRef FName,
+ const FunctionSamples &S) {
+ encodeULEB128(S.getHeadSamples(), OS);
+ return writeBody(FName, S);
+}
+
/// \brief Create a sample profile writer based on the specified format.
///
/// \param Filename The file to create.