aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ProfileData/SampleProfReader.cpp
diff options
context:
space:
mode:
authorDiego Novillo <dnovillo@google.com>2015-10-09 17:54:24 +0000
committerDiego Novillo <dnovillo@google.com>2015-10-09 17:54:24 +0000
commita7f1e8ef830e2b8e17fc9eee67ed2454ab9b5041 (patch)
tree3d160022dd8aeee9e681c995350148945de5bfa1 /llvm/lib/ProfileData/SampleProfReader.cpp
parent26c6e641591a0f93746038f938ecb00e600ddf1d (diff)
downloadllvm-a7f1e8ef830e2b8e17fc9eee67ed2454ab9b5041.zip
llvm-a7f1e8ef830e2b8e17fc9eee67ed2454ab9b5041.tar.gz
llvm-a7f1e8ef830e2b8e17fc9eee67ed2454ab9b5041.tar.bz2
Add inline stack streaming to binary sample profiles.
With this patch we can now read and write inline stacks in sample profiles to the binary encoded profiles. In a subsequent patch, I will add a string table to the binary encoding. Right now function names are emitted as strings every time we find them. This is too bloated and will produce large files in applications with lots of inlining. llvm-svn: 249861
Diffstat (limited to 'llvm/lib/ProfileData/SampleProfReader.cpp')
-rw-r--r--llvm/lib/ProfileData/SampleProfReader.cpp112
1 files changed, 72 insertions, 40 deletions
diff --git a/llvm/lib/ProfileData/SampleProfReader.cpp b/llvm/lib/ProfileData/SampleProfReader.cpp
index 6d7d182..c620d4c 100644
--- a/llvm/lib/ProfileData/SampleProfReader.cpp
+++ b/llvm/lib/ProfileData/SampleProfReader.cpp
@@ -378,62 +378,94 @@ ErrorOr<StringRef> SampleProfileReaderBinary::readString() {
return Str;
}
-std::error_code SampleProfileReaderBinary::read() {
- while (!at_eof()) {
- auto FName(readString());
- if (std::error_code EC = FName.getError())
- return EC;
+std::error_code
+SampleProfileReaderBinary::readProfile(FunctionSamples &FProfile) {
+ auto Val = readNumber<unsigned>();
+ if (std::error_code EC = Val.getError())
+ return EC;
+ FProfile.addTotalSamples(*Val);
- Profiles[*FName] = FunctionSamples();
- FunctionSamples &FProfile = Profiles[*FName];
+ Val = readNumber<unsigned>();
+ if (std::error_code EC = Val.getError())
+ return EC;
+ FProfile.addHeadSamples(*Val);
+
+ // Read the samples in the body.
+ auto NumRecords = readNumber<unsigned>();
+ if (std::error_code EC = NumRecords.getError())
+ return EC;
- auto Val = readNumber<unsigned>();
- if (std::error_code EC = Val.getError())
+ for (unsigned I = 0; I < *NumRecords; ++I) {
+ auto LineOffset = readNumber<uint64_t>();
+ if (std::error_code EC = LineOffset.getError())
return EC;
- FProfile.addTotalSamples(*Val);
- Val = readNumber<unsigned>();
- if (std::error_code EC = Val.getError())
+ auto Discriminator = readNumber<uint64_t>();
+ if (std::error_code EC = Discriminator.getError())
return EC;
- FProfile.addHeadSamples(*Val);
- // Read the samples in the body.
- auto NumRecords = readNumber<unsigned>();
- if (std::error_code EC = NumRecords.getError())
+ auto NumSamples = readNumber<uint64_t>();
+ if (std::error_code EC = NumSamples.getError())
return EC;
- for (unsigned I = 0; I < *NumRecords; ++I) {
- auto LineOffset = readNumber<uint64_t>();
- if (std::error_code EC = LineOffset.getError())
- return EC;
- auto Discriminator = readNumber<uint64_t>();
- if (std::error_code EC = Discriminator.getError())
- return EC;
+ auto NumCalls = readNumber<unsigned>();
+ if (std::error_code EC = NumCalls.getError())
+ return EC;
- auto NumSamples = readNumber<uint64_t>();
- if (std::error_code EC = NumSamples.getError())
+ for (unsigned J = 0; J < *NumCalls; ++J) {
+ auto CalledFunction(readString());
+ if (std::error_code EC = CalledFunction.getError())
return EC;
- auto NumCalls = readNumber<unsigned>();
- if (std::error_code EC = NumCalls.getError())
+ auto CalledFunctionSamples = readNumber<uint64_t>();
+ if (std::error_code EC = CalledFunctionSamples.getError())
return EC;
- for (unsigned J = 0; J < *NumCalls; ++J) {
- auto CalledFunction(readString());
- if (std::error_code EC = CalledFunction.getError())
- return EC;
+ FProfile.addCalledTargetSamples(*LineOffset, *Discriminator,
+ *CalledFunction, *CalledFunctionSamples);
+ }
- auto CalledFunctionSamples = readNumber<uint64_t>();
- if (std::error_code EC = CalledFunctionSamples.getError())
- return EC;
+ FProfile.addBodySamples(*LineOffset, *Discriminator, *NumSamples);
+ }
- FProfile.addCalledTargetSamples(*LineOffset, *Discriminator,
- *CalledFunction,
- *CalledFunctionSamples);
- }
+ // Read all the samples for inlined function calls.
+ auto NumCallsites = readNumber<unsigned>();
+ if (std::error_code EC = NumCallsites.getError())
+ return EC;
- FProfile.addBodySamples(*LineOffset, *Discriminator, *NumSamples);
- }
+ for (unsigned J = 0; J < *NumCallsites; ++J) {
+ auto LineOffset = readNumber<uint64_t>();
+ if (std::error_code EC = LineOffset.getError())
+ return EC;
+
+ auto Discriminator = readNumber<uint64_t>();
+ if (std::error_code EC = Discriminator.getError())
+ return EC;
+
+ auto FName(readString());
+ if (std::error_code EC = FName.getError())
+ return EC;
+
+ FunctionSamples &CalleeProfile = FProfile.functionSamplesAt(
+ CallsiteLocation(*LineOffset, *Discriminator, *FName));
+ if (std::error_code EC = readProfile(CalleeProfile))
+ return EC;
+ }
+
+ return sampleprof_error::success;
+}
+
+std::error_code SampleProfileReaderBinary::read() {
+ while (!at_eof()) {
+ auto FName(readString());
+ if (std::error_code EC = FName.getError())
+ return EC;
+
+ Profiles[*FName] = FunctionSamples();
+ FunctionSamples &FProfile = Profiles[*FName];
+
+ if (std::error_code EC = readProfile(FProfile))
+ return EC;
}
return sampleprof_error::success;