aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ProfileData/SampleProfReader.cpp
diff options
context:
space:
mode:
authorDiego Novillo <dnovillo@google.com>2015-10-13 22:48:46 +0000
committerDiego Novillo <dnovillo@google.com>2015-10-13 22:48:46 +0000
commit760c5a8f45cc265950990a58dc27de901dc86155 (patch)
tree31d1556b19606a3e9aa555eb96d2cc5dc5382787 /llvm/lib/ProfileData/SampleProfReader.cpp
parent973e0506398fa04476b0d5dfd0336beb156502c9 (diff)
downloadllvm-760c5a8f45cc265950990a58dc27de901dc86155.zip
llvm-760c5a8f45cc265950990a58dc27de901dc86155.tar.gz
llvm-760c5a8f45cc265950990a58dc27de901dc86155.tar.bz2
Sample profiles - Add a name table to the binary encoding.
Binary encoded profiles used to encode all function names inline at every reference. This is clearly suboptimal in terms of space. This patch fixes this by adding a name table to the header of the file. llvm-svn: 250241
Diffstat (limited to 'llvm/lib/ProfileData/SampleProfReader.cpp')
-rw-r--r--llvm/lib/ProfileData/SampleProfReader.cpp28
1 files changed, 25 insertions, 3 deletions
diff --git a/llvm/lib/ProfileData/SampleProfReader.cpp b/llvm/lib/ProfileData/SampleProfReader.cpp
index c620d4c..a058274 100644
--- a/llvm/lib/ProfileData/SampleProfReader.cpp
+++ b/llvm/lib/ProfileData/SampleProfReader.cpp
@@ -378,6 +378,16 @@ ErrorOr<StringRef> SampleProfileReaderBinary::readString() {
return Str;
}
+ErrorOr<StringRef> SampleProfileReaderBinary::readStringFromTable() {
+ std::error_code EC;
+ auto Idx = readNumber<unsigned>();
+ if (std::error_code EC = Idx.getError())
+ return EC;
+ if (*Idx >= NameTable.size())
+ return sampleprof_error::truncated_name_table;
+ return NameTable[*Idx];
+}
+
std::error_code
SampleProfileReaderBinary::readProfile(FunctionSamples &FProfile) {
auto Val = readNumber<unsigned>();
@@ -413,7 +423,7 @@ SampleProfileReaderBinary::readProfile(FunctionSamples &FProfile) {
return EC;
for (unsigned J = 0; J < *NumCalls; ++J) {
- auto CalledFunction(readString());
+ auto CalledFunction(readStringFromTable());
if (std::error_code EC = CalledFunction.getError())
return EC;
@@ -442,7 +452,7 @@ SampleProfileReaderBinary::readProfile(FunctionSamples &FProfile) {
if (std::error_code EC = Discriminator.getError())
return EC;
- auto FName(readString());
+ auto FName(readStringFromTable());
if (std::error_code EC = FName.getError())
return EC;
@@ -457,7 +467,7 @@ SampleProfileReaderBinary::readProfile(FunctionSamples &FProfile) {
std::error_code SampleProfileReaderBinary::read() {
while (!at_eof()) {
- auto FName(readString());
+ auto FName(readStringFromTable());
if (std::error_code EC = FName.getError())
return EC;
@@ -489,6 +499,18 @@ std::error_code SampleProfileReaderBinary::readHeader() {
else if (*Version != SPVersion())
return sampleprof_error::unsupported_version;
+ // Read the name table.
+ auto Size = readNumber<size_t>();
+ if (std::error_code EC = Size.getError())
+ return EC;
+ NameTable.reserve(*Size);
+ for (size_t I = 0; I < *Size; ++I) {
+ auto Name(readString());
+ if (std::error_code EC = Name.getError())
+ return EC;
+ NameTable.push_back(*Name);
+ }
+
return sampleprof_error::success;
}