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/SampleProfReader.cpp b/llvm/lib/ProfileData/SampleProfReader.cpp
index 1ea7d2a..d184969 100644
--- a/llvm/lib/ProfileData/SampleProfReader.cpp
+++ b/llvm/lib/ProfileData/SampleProfReader.cpp
@@ -21,13 +21,13 @@
//===----------------------------------------------------------------------===//
#include "llvm/ProfileData/SampleProfReader.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/LEB128.h"
#include "llvm/Support/LineIterator.h"
#include "llvm/Support/MemoryBuffer.h"
-#include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/SmallVector.h"
using namespace llvm::sampleprof;
using namespace llvm;
@@ -293,15 +293,10 @@
std::error_code
SampleProfileReaderBinary::readProfile(FunctionSamples &FProfile) {
- auto Val = readNumber<uint64_t>();
- if (std::error_code EC = Val.getError())
+ auto NumSamples = readNumber<uint64_t>();
+ if (std::error_code EC = NumSamples.getError())
return EC;
- FProfile.addTotalSamples(*Val);
-
- Val = readNumber<uint64_t>();
- if (std::error_code EC = Val.getError())
- return EC;
- FProfile.addHeadSamples(*Val);
+ FProfile.addTotalSamples(*NumSamples);
// Read the samples in the body.
auto NumRecords = readNumber<uint32_t>();
@@ -370,6 +365,10 @@
std::error_code SampleProfileReaderBinary::read() {
while (!at_eof()) {
+ auto NumHeadSamples = readNumber<uint64_t>();
+ if (std::error_code EC = NumHeadSamples.getError())
+ return EC;
+
auto FName(readStringFromTable());
if (std::error_code EC = FName.getError())
return EC;
@@ -377,6 +376,8 @@
Profiles[*FName] = FunctionSamples();
FunctionSamples &FProfile = Profiles[*FName];
+ FProfile.addHeadSamples(*NumHeadSamples);
+
if (std::error_code EC = readProfile(FProfile))
return EC;
}