diff options
author | Xinliang David Li <davidxl@google.com> | 2015-12-01 20:26:26 +0000 |
---|---|---|
committer | Xinliang David Li <davidxl@google.com> | 2015-12-01 20:26:26 +0000 |
commit | d89494bf0312145ad18320eab794b89b300f64e7 (patch) | |
tree | 48816bc815ec93f67a80da29cf83267abe68983b /lib/ProfileData/InstrProfReader.cpp | |
parent | 146c16ca4dd4d3d06dcd78efb95906268fc67509 (diff) |
[PGO] Add support for reading multiple versions of indexed profile format profile data
Profile readers using incompatible on-disk hash table format can now share the same
implementation and interfaces.
Differential Revision: http://reviews.llvm.org/D15100
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254458 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ProfileData/InstrProfReader.cpp')
-rw-r--r-- | lib/ProfileData/InstrProfReader.cpp | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/lib/ProfileData/InstrProfReader.cpp b/lib/ProfileData/InstrProfReader.cpp index e4348b19ac0..cfc96873980 100644 --- a/lib/ProfileData/InstrProfReader.cpp +++ b/lib/ProfileData/InstrProfReader.cpp @@ -441,11 +441,11 @@ data_type InstrProfLookupTrait::ReadData(StringRef K, const unsigned char *D, return DataBuffer; } -std::error_code -InstrProfReaderIndex::getRecords(StringRef FuncName, - ArrayRef<InstrProfRecord> &Data) { - auto Iter = Index->find(FuncName); - if (Iter == Index->end()) +template <typename HashTableImpl> +std::error_code InstrProfReaderIndex<HashTableImpl>::getRecords( + StringRef FuncName, ArrayRef<InstrProfRecord> &Data) { + auto Iter = HashTable->find(FuncName); + if (Iter == HashTable->end()) return instrprof_error::unknown_function; Data = (*Iter); @@ -455,9 +455,11 @@ InstrProfReaderIndex::getRecords(StringRef FuncName, return instrprof_error::success; } -std::error_code InstrProfReaderIndex::getRecords( +template <typename HashTableImpl> +std::error_code InstrProfReaderIndex<HashTableImpl>::getRecords( ArrayRef<InstrProfRecord> &Data) { - if (atEnd()) return instrprof_error::eof; + if (atEnd()) + return instrprof_error::eof; Data = *RecordIterator; @@ -466,25 +468,26 @@ std::error_code InstrProfReaderIndex::getRecords( return instrprof_error::success; } -void InstrProfReaderIndex::Init(const unsigned char *Buckets, - const unsigned char *const Payload, - const unsigned char *const Base, - IndexedInstrProf::HashT HashType, - uint64_t Version) { +template <typename HashTableImpl> +InstrProfReaderIndex<HashTableImpl>::InstrProfReaderIndex( + const unsigned char *Buckets, const unsigned char *const Payload, + const unsigned char *const Base, IndexedInstrProf::HashT HashType, + uint64_t Version) { FormatVersion = Version; - Index.reset(IndexType::Create(Buckets, Payload, Base, - InstrProfLookupTrait(HashType, Version))); + HashTable.reset(HashTableImpl::Create( + Buckets, Payload, Base, + typename HashTableImpl::InfoType(HashType, Version))); // Form the map of hash values to const char* keys in profiling data. std::vector<std::pair<uint64_t, const char *>> HashKeys; - for (auto Key : Index->keys()) { + for (auto Key : HashTable->keys()) { const char *KeyTableRef = StringTable.insertString(Key); HashKeys.push_back(std::make_pair(ComputeHash(HashType, Key), KeyTableRef)); } std::sort(HashKeys.begin(), HashKeys.end(), less_first()); HashKeys.erase(std::unique(HashKeys.begin(), HashKeys.end()), HashKeys.end()); // Set the hash key map for the InstrLookupTrait - Index->getInfoObj().setHashKeys(std::move(HashKeys)); - RecordIterator = Index->data_begin(); + HashTable->getInfoObj().setHashKeys(std::move(HashKeys)); + RecordIterator = HashTable->data_begin(); } bool IndexedInstrProfReader::hasFormat(const MemoryBuffer &DataBuffer) { @@ -532,8 +535,10 @@ std::error_code IndexedInstrProfReader::readHeader() { uint64_t HashOffset = endian::byte_swap<uint64_t, little>(Header->HashOffset); // The rest of the file is an on disk hash table. - Index.Init(Start + HashOffset, Cur, Start, HashType, FormatVersion); - + InstrProfReaderIndexBase *IndexPtr = nullptr; + IndexPtr = new InstrProfReaderIndex<OnDiskHashTableImplV3>( + Start + HashOffset, Cur, Start, HashType, FormatVersion); + Index.reset(IndexPtr); return success(); } @@ -541,7 +546,7 @@ ErrorOr<InstrProfRecord> IndexedInstrProfReader::getInstrProfRecord(StringRef FuncName, uint64_t FuncHash) { ArrayRef<InstrProfRecord> Data; - std::error_code EC = Index.getRecords(FuncName, Data); + std::error_code EC = Index->getRecords(FuncName, Data); if (EC != instrprof_error::success) return EC; // Found it. Look for counters with the right hash. @@ -571,13 +576,13 @@ std::error_code IndexedInstrProfReader::readNextRecord( ArrayRef<InstrProfRecord> Data; - std::error_code EC = Index.getRecords(Data); + std::error_code EC = Index->getRecords(Data); if (EC != instrprof_error::success) return error(EC); Record = Data[RecordIndex++]; if (RecordIndex >= Data.size()) { - Index.advanceToNextKey(); + Index->advanceToNextKey(); RecordIndex = 0; } return success(); |