aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ProfileData/InstrProfReader.cpp
diff options
context:
space:
mode:
authorXinliang David Li <davidxl@google.com>2015-11-10 00:24:45 +0000
committerXinliang David Li <davidxl@google.com>2015-11-10 00:24:45 +0000
commitee4158957b6547ed180fb470d91c1ce22fffc06e (patch)
tree5c2f1d9cdd1e0ee9bdbfb95749471ac7212cd4b9 /llvm/lib/ProfileData/InstrProfReader.cpp
parent9d3e4f66513b760727df19df12380cb77e94435d (diff)
downloadllvm-ee4158957b6547ed180fb470d91c1ce22fffc06e.zip
llvm-ee4158957b6547ed180fb470d91c1ce22fffc06e.tar.gz
llvm-ee4158957b6547ed180fb470d91c1ce22fffc06e.tar.bz2
[PGO] Make indexed value profile data more compact
- Make indexed value profile data more compact by peeling out the per-site value count field into its own smaller sized array. - Introduced formal data structure definitions to specify value profile data layout in indexed format. Previously the layout of the data is only assumed in the client code (scattered in three different places : size computation, EmitData, and ReadData - The new data structure serves as a central place for layout documentation. - Add interfaces to force BE output for value profile data (testing purpose) - Add byte swap unit tests Differential Revision: http://reviews.llvm.org/D14401 llvm-svn: 252563
Diffstat (limited to 'llvm/lib/ProfileData/InstrProfReader.cpp')
-rw-r--r--llvm/lib/ProfileData/InstrProfReader.cpp47
1 files changed, 6 insertions, 41 deletions
diff --git a/llvm/lib/ProfileData/InstrProfReader.cpp b/llvm/lib/ProfileData/InstrProfReader.cpp
index 66fd961..b968e6b 100644
--- a/llvm/lib/ProfileData/InstrProfReader.cpp
+++ b/llvm/lib/ProfileData/InstrProfReader.cpp
@@ -298,51 +298,16 @@ typedef InstrProfLookupTrait::offset_type offset_type;
bool InstrProfLookupTrait::ReadValueProfilingData(
const unsigned char *&D, const unsigned char *const End) {
+ ErrorOr<std::unique_ptr<IndexedInstrProf::ValueProfData>> VDataPtrOrErr =
+ IndexedInstrProf::ValueProfData::getValueProfData(
+ D, End, ValueProfDataEndianness);
- using namespace support;
- // Read number of value kinds with value sites.
- if (D + sizeof(uint64_t) > End)
+ if (VDataPtrOrErr.getError())
return false;
- uint64_t ValueKindCount = endian::readNext<uint64_t, little, unaligned>(D);
-
- InstrProfRecord &ProfRecord = DataBuffer.back();
- for (uint32_t Kind = 0; Kind < ValueKindCount; ++Kind) {
-
- // Read value kind and number of value sites for kind.
- if (D + 2 * sizeof(uint64_t) > End)
- return false;
-
- uint64_t ValueKind = endian::readNext<uint64_t, little, unaligned>(D);
- uint64_t ValueSiteCount = endian::readNext<uint64_t, little, unaligned>(D);
- ProfRecord.reserveSites(ValueKind, ValueSiteCount);
+ VDataPtrOrErr.get()->deserializeTo(DataBuffer.back(), &HashKeys);
+ D += VDataPtrOrErr.get()->TotalSize;
- for (uint64_t VSite = 0; VSite < ValueSiteCount; ++VSite) {
- // Read number of value data pairs at value site.
- if (D + sizeof(uint64_t) > End)
- return false;
-
- uint64_t ValueDataCount =
- endian::readNext<uint64_t, little, unaligned>(D);
-
- // Check if there are as many ValueDataPairs as ValueDataCount in memory.
- if (D + (ValueDataCount << 1) * sizeof(uint64_t) > End)
- return false;
-
- std::unique_ptr<InstrProfValueData[]> VDataPtr(
- ValueDataCount == 0 ? nullptr
- : new InstrProfValueData[ValueDataCount]);
-
- for (uint64_t VCount = 0; VCount < ValueDataCount; ++VCount) {
- VDataPtr[VCount].Value =
- endian::readNext<uint64_t, little, unaligned>(D);
- VDataPtr[VCount].Count =
- endian::readNext<uint64_t, little, unaligned>(D);
- }
- ProfRecord.addValueData(ValueKind, VSite, VDataPtr.get(), ValueDataCount,
- &HashKeys);
- }
- }
return true;
}