+std::error_code InstrProfReaderIndex::getRecords(
+ StringRef FuncName, ArrayRef<InstrProfRecord> &Data) {
+ auto Iter = Index->find(FuncName);
+ if (Iter == Index->end()) return instrprof_error::unknown_function;
+
+ Data = (*Iter);
+ if (Data.empty()) return instrprof_error::malformed;
+
+ return instrprof_error::success;
+}
+
+std::error_code InstrProfReaderIndex::getRecords(
+ ArrayRef<InstrProfRecord> &Data) {
+ if (atEnd()) return instrprof_error::eof;
+
+ Data = *RecordIterator;
+
+ if (Data.empty()) return instrprof_error::malformed;
+
+ 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) {
+ FormatVersion = Version;
+ Index.reset(IndexType::Create(Buckets, Payload, Base,
+ InstrProfLookupTrait(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()) {
+ 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();
+}
+