@@ -150,22 +150,25 @@ static void printBinaryIdsInternal(raw_ostream &OS,
150150 }
151151}
152152
153- Expected<std::unique_ptr<InstrProfReader>>
154- InstrProfReader::create (const Twine &Path, vfs::FileSystem &FS,
155- const InstrProfCorrelator *Correlator,
156- std::function<void (Error)> Warn) {
153+ Expected<std::unique_ptr<InstrProfReader>> InstrProfReader::create (
154+ const Twine &Path, vfs::FileSystem &FS,
155+ const InstrProfCorrelator *Correlator,
156+ const object::BuildIDFetcher *BIDFetcher,
157+ const InstrProfCorrelator::ProfCorrelatorKind BIDFetcherCorrelatorKind,
158+ std::function<void (Error)> Warn) {
157159 // Set up the buffer to read.
158160 auto BufferOrError = setupMemoryBuffer (Path, FS);
159161 if (Error E = BufferOrError.takeError ())
160162 return std::move (E);
161163 return InstrProfReader::create (std::move (BufferOrError.get ()), Correlator,
162- Warn);
164+ BIDFetcher, BIDFetcherCorrelatorKind, Warn);
163165}
164166
165- Expected<std::unique_ptr<InstrProfReader>>
166- InstrProfReader::create (std::unique_ptr<MemoryBuffer> Buffer,
167- const InstrProfCorrelator *Correlator,
168- std::function<void (Error)> Warn) {
167+ Expected<std::unique_ptr<InstrProfReader>> InstrProfReader::create (
168+ std::unique_ptr<MemoryBuffer> Buffer, const InstrProfCorrelator *Correlator,
169+ const object::BuildIDFetcher *BIDFetcher,
170+ const InstrProfCorrelator::ProfCorrelatorKind BIDFetcherCorrelatorKind,
171+ std::function<void (Error)> Warn) {
169172 if (Buffer->getBufferSize () == 0 )
170173 return make_error<InstrProfError>(instrprof_error::empty_raw_profile);
171174
@@ -174,9 +177,13 @@ InstrProfReader::create(std::unique_ptr<MemoryBuffer> Buffer,
174177 if (IndexedInstrProfReader::hasFormat (*Buffer))
175178 Result.reset (new IndexedInstrProfReader (std::move (Buffer)));
176179 else if (RawInstrProfReader64::hasFormat (*Buffer))
177- Result.reset (new RawInstrProfReader64 (std::move (Buffer), Correlator, Warn));
180+ Result.reset (new RawInstrProfReader64 (std::move (Buffer), Correlator,
181+ BIDFetcher, BIDFetcherCorrelatorKind,
182+ Warn));
178183 else if (RawInstrProfReader32::hasFormat (*Buffer))
179- Result.reset (new RawInstrProfReader32 (std::move (Buffer), Correlator, Warn));
184+ Result.reset (new RawInstrProfReader32 (std::move (Buffer), Correlator,
185+ BIDFetcher, BIDFetcherCorrelatorKind,
186+ Warn));
180187 else if (TextInstrProfReader::hasFormat (*Buffer))
181188 Result.reset (new TextInstrProfReader (std::move (Buffer)));
182189 else
@@ -633,6 +640,19 @@ Error RawInstrProfReader<IntPtrT>::readHeader(
633640 if (Start + ValueDataOffset > DataBuffer->getBufferEnd ())
634641 return error (instrprof_error::bad_header);
635642
643+ if (BIDFetcher) {
644+ std::vector<object::BuildID> BinaryIDs;
645+ if (Error E = readBinaryIds (BinaryIDs))
646+ return E;
647+ if (auto E = InstrProfCorrelator::get (" " , BIDFetcherCorrelatorKind,
648+ BIDFetcher, BinaryIDs)
649+ .moveInto (BIDFetcherCorrelator)) {
650+ return E;
651+ }
652+ if (auto Err = BIDFetcherCorrelator->correlateProfileData (0 ))
653+ return Err;
654+ }
655+
636656 if (Correlator) {
637657 // These sizes in the raw file are zero because we constructed them in the
638658 // Correlator.
@@ -643,6 +663,14 @@ Error RawInstrProfReader<IntPtrT>::readHeader(
643663 DataEnd = Data + Correlator->getDataSize ();
644664 NamesStart = Correlator->getNamesPointer ();
645665 NamesEnd = NamesStart + Correlator->getNamesSize ();
666+ } else if (BIDFetcherCorrelator) {
667+ InstrProfCorrelatorImpl<IntPtrT> *BIDFetcherCorrelatorImpl =
668+ dyn_cast_or_null<InstrProfCorrelatorImpl<IntPtrT>>(
669+ BIDFetcherCorrelator.get ());
670+ Data = BIDFetcherCorrelatorImpl->getDataPointer ();
671+ DataEnd = Data + BIDFetcherCorrelatorImpl->getDataSize ();
672+ NamesStart = BIDFetcherCorrelatorImpl->getNamesPointer ();
673+ NamesEnd = NamesStart + BIDFetcherCorrelatorImpl->getNamesSize ();
646674 } else {
647675 Data = reinterpret_cast <const RawInstrProf::ProfileData<IntPtrT> *>(
648676 Start + DataOffset);
0 commit comments