LLVM 17.0.0git
InstrProfReader.h
Go to the documentation of this file.
1//===- InstrProfReader.h - Instrumented profiling readers -------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains support for reading profiling data for instrumentation
10// based PGO and coverage.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_PROFILEDATA_INSTRPROFREADER_H
15#define LLVM_PROFILEDATA_INSTRPROFREADER_H
16
17#include "llvm/ADT/ArrayRef.h"
18#include "llvm/ADT/StringRef.h"
20#include "llvm/Object/BuildID.h"
24#include "llvm/Support/Endian.h"
25#include "llvm/Support/Error.h"
31#include <algorithm>
32#include <cassert>
33#include <cstddef>
34#include <cstdint>
35#include <iterator>
36#include <memory>
37#include <utility>
38#include <vector>
39
40namespace llvm {
41
42class InstrProfReader;
43
44namespace vfs {
45class FileSystem;
46} // namespace vfs
47
48/// A file format agnostic iterator over profiling data.
49template <class record_type = NamedInstrProfRecord,
50 class reader_type = InstrProfReader>
52public:
53 using iterator_category = std::input_iterator_tag;
54 using value_type = record_type;
55 using difference_type = std::ptrdiff_t;
58
59private:
60 reader_type *Reader = nullptr;
62
63 void increment() {
64 if (Error E = Reader->readNextRecord(Record)) {
65 // Handle errors in the reader.
66 InstrProfError::take(std::move(E));
67 *this = InstrProfIterator();
68 }
69 }
70
71public:
72 InstrProfIterator() = default;
73 InstrProfIterator(reader_type *Reader) : Reader(Reader) { increment(); }
74
76 increment();
77 return *this;
78 }
79 bool operator==(const InstrProfIterator &RHS) const {
80 return Reader == RHS.Reader;
81 }
82 bool operator!=(const InstrProfIterator &RHS) const {
83 return Reader != RHS.Reader;
84 }
87};
88
89/// Base class and interface for reading profiling data of any known instrprof
90/// format. Provides an iterator over NamedInstrProfRecords.
93 std::string LastErrorMsg;
94
95public:
96 InstrProfReader() = default;
97 virtual ~InstrProfReader() = default;
98
99 /// Read the header. Required before reading first record.
100 virtual Error readHeader() = 0;
101
102 /// Read a single record.
104
105 /// Read a list of binary ids.
106 virtual Error readBinaryIds(std::vector<llvm::object::BuildID> &BinaryIds) {
107 return success();
108 }
109
110 /// Print binary ids.
111 virtual Error printBinaryIds(raw_ostream &OS) { return success(); };
112
113 /// Iterator over profile data.
116
117 /// Return the profile version.
118 virtual uint64_t getVersion() const = 0;
119
120 virtual bool isIRLevelProfile() const = 0;
121
122 virtual bool hasCSIRLevelProfile() const = 0;
123
124 virtual bool instrEntryBBEnabled() const = 0;
125
126 /// Return true if we must provide debug info to create PGO profiles.
127 virtual bool useDebugInfoCorrelate() const { return false; }
128
129 /// Return true if the profile has single byte counters representing coverage.
130 virtual bool hasSingleByteCoverage() const = 0;
131
132 /// Return true if the profile only instruments function entries.
133 virtual bool functionEntryOnly() const = 0;
134
135 /// Return true if profile includes a memory profile.
136 virtual bool hasMemoryProfile() const = 0;
137
138 /// Returns a BitsetEnum describing the attributes of the profile. To check
139 /// individual attributes prefer using the helpers above.
140 virtual InstrProfKind getProfileKind() const = 0;
141
142 /// Return the PGO symtab. There are three different readers:
143 /// Raw, Text, and Indexed profile readers. The first two types
144 /// of readers are used only by llvm-profdata tool, while the indexed
145 /// profile reader is also used by llvm-cov tool and the compiler (
146 /// backend or frontend). Since creating PGO symtab can create
147 /// significant runtime and memory overhead (as it touches data
148 /// for the whole program), InstrProfSymtab for the indexed profile
149 /// reader should be created on demand and it is recommended to be
150 /// only used for dumping purpose with llvm-proftool, not with the
151 /// compiler.
153
154 /// Compute the sum of counts and return in Sum.
155 void accumulateCounts(CountSumOrPercent &Sum, bool IsCS);
156
157protected:
158 std::unique_ptr<InstrProfSymtab> Symtab;
159
160 /// Set the current error and return same.
161 Error error(instrprof_error Err, const std::string &ErrMsg = "") {
162 LastError = Err;
163 LastErrorMsg = ErrMsg;
164 if (Err == instrprof_error::success)
165 return Error::success();
166 return make_error<InstrProfError>(Err, ErrMsg);
167 }
168
170 handleAllErrors(std::move(E), [&](const InstrProfError &IPE) {
171 LastError = IPE.get();
172 LastErrorMsg = IPE.getMessage();
173 });
174 return make_error<InstrProfError>(LastError, LastErrorMsg);
175 }
176
177 /// Clear the current error and return a successful one.
179
180public:
181 /// Return true if the reader has finished reading the profile data.
182 bool isEOF() { return LastError == instrprof_error::eof; }
183
184 /// Return true if the reader encountered an error reading profiling data.
185 bool hasError() { return LastError != instrprof_error::success && !isEOF(); }
186
187 /// Get the current error.
189 if (hasError())
190 return make_error<InstrProfError>(LastError, LastErrorMsg);
191 return Error::success();
192 }
193
194 /// Factory method to create an appropriately typed reader for the given
195 /// instrprof file.
197 create(const Twine &Path, vfs::FileSystem &FS,
198 const InstrProfCorrelator *Correlator = nullptr);
199
201 create(std::unique_ptr<MemoryBuffer> Buffer,
202 const InstrProfCorrelator *Correlator = nullptr);
203};
204
205/// Reader for the simple text based instrprof format.
206///
207/// This format is a simple text format that's suitable for test data. Records
208/// are separated by one or more blank lines, and record fields are separated by
209/// new lines.
210///
211/// Each record consists of a function name, a function hash, a number of
212/// counters, and then each counter value, in that order.
214private:
215 /// The profile data file contents.
216 std::unique_ptr<MemoryBuffer> DataBuffer;
217 /// Iterator over the profile data.
218 line_iterator Line;
219 /// The attributes of the current profile.
221
222 Error readValueProfileData(InstrProfRecord &Record);
223
224public:
225 TextInstrProfReader(std::unique_ptr<MemoryBuffer> DataBuffer_)
226 : DataBuffer(std::move(DataBuffer_)), Line(*DataBuffer, true, '#') {}
229
230 /// Return true if the given buffer is in text instrprof format.
231 static bool hasFormat(const MemoryBuffer &Buffer);
232
233 // Text format does not have version, so return 0.
234 uint64_t getVersion() const override { return 0; }
235
236 bool isIRLevelProfile() const override {
237 return static_cast<bool>(ProfileKind & InstrProfKind::IRInstrumentation);
238 }
239
240 bool hasCSIRLevelProfile() const override {
241 return static_cast<bool>(ProfileKind & InstrProfKind::ContextSensitive);
242 }
243
244 bool instrEntryBBEnabled() const override {
245 return static_cast<bool>(ProfileKind &
247 }
248
249 bool hasSingleByteCoverage() const override {
250 return static_cast<bool>(ProfileKind & InstrProfKind::SingleByteCoverage);
251 }
252
253 bool functionEntryOnly() const override {
254 return static_cast<bool>(ProfileKind & InstrProfKind::FunctionEntryOnly);
255 }
256
257 bool hasMemoryProfile() const override {
258 // TODO: Add support for text format memory profiles.
259 return false;
260 }
261
262 InstrProfKind getProfileKind() const override { return ProfileKind; }
263
264 /// Read the header.
265 Error readHeader() override;
266
267 /// Read a single record.
269
271 assert(Symtab);
272 return *Symtab;
273 }
274};
275
276/// Reader for the raw instrprof binary format from runtime.
277///
278/// This format is a raw memory dump of the instrumentation-based profiling data
279/// from the runtime. It has no index.
280///
281/// Templated on the unsigned type whose size matches pointers on the platform
282/// that wrote the profile.
283template <class IntPtrT>
285private:
286 /// The profile data file contents.
287 std::unique_ptr<MemoryBuffer> DataBuffer;
288 /// If available, this hold the ProfileData array used to correlate raw
289 /// instrumentation data to their functions.
290 const InstrProfCorrelatorImpl<IntPtrT> *Correlator;
291 bool ShouldSwapBytes;
292 // The value of the version field of the raw profile data header. The lower 56
293 // bits specifies the format version and the most significant 8 bits specify
294 // the variant types of the profile.
295 uint64_t Version;
296 uint64_t CountersDelta;
297 uint64_t NamesDelta;
300 const char *CountersStart;
301 const char *CountersEnd;
302 const char *NamesStart;
303 const char *NamesEnd;
304 // After value profile is all read, this pointer points to
305 // the header of next profile data (if exists)
306 const uint8_t *ValueDataStart;
307 uint32_t ValueKindLast;
308 uint32_t CurValueDataSize;
309
310 /// Total size of binary ids.
311 uint64_t BinaryIdsSize{0};
312 /// Start address of binary id length and data pairs.
313 const uint8_t *BinaryIdsStart;
314
315public:
316 RawInstrProfReader(std::unique_ptr<MemoryBuffer> DataBuffer,
317 const InstrProfCorrelator *Correlator)
318 : DataBuffer(std::move(DataBuffer)),
320 Correlator)) {}
323
324 static bool hasFormat(const MemoryBuffer &DataBuffer);
325 Error readHeader() override;
327 Error readBinaryIds(std::vector<llvm::object::BuildID> &BinaryIds) override;
328 Error printBinaryIds(raw_ostream &OS) override;
329
330 uint64_t getVersion() const override { return Version; }
331
332 bool isIRLevelProfile() const override {
333 return (Version & VARIANT_MASK_IR_PROF) != 0;
334 }
335
336 bool hasCSIRLevelProfile() const override {
337 return (Version & VARIANT_MASK_CSIR_PROF) != 0;
338 }
339
340 bool instrEntryBBEnabled() const override {
341 return (Version & VARIANT_MASK_INSTR_ENTRY) != 0;
342 }
343
344 bool useDebugInfoCorrelate() const override {
345 return (Version & VARIANT_MASK_DBG_CORRELATE) != 0;
346 }
347
348 bool hasSingleByteCoverage() const override {
349 return (Version & VARIANT_MASK_BYTE_COVERAGE) != 0;
350 }
351
352 bool functionEntryOnly() const override {
353 return (Version & VARIANT_MASK_FUNCTION_ENTRY_ONLY) != 0;
354 }
355
356 bool hasMemoryProfile() const override {
357 // Memory profiles have a separate raw format, so this should never be set.
358 assert(!(Version & VARIANT_MASK_MEMPROF));
359 return false;
360 }
361
362 /// Returns a BitsetEnum describing the attributes of the raw instr profile.
363 InstrProfKind getProfileKind() const override;
364
366 assert(Symtab.get());
367 return *Symtab.get();
368 }
369
370private:
371 Error createSymtab(InstrProfSymtab &Symtab);
372 Error readNextHeader(const char *CurrentPos);
374
375 template <class IntT> IntT swap(IntT Int) const {
376 return ShouldSwapBytes ? sys::getSwappedBytes(Int) : Int;
377 }
378
379 support::endianness getDataEndianness() const {
381 if (!ShouldSwapBytes)
382 return HostEndian;
383 if (HostEndian == support::little)
384 return support::big;
385 else
386 return support::little;
387 }
388
389 inline uint8_t getNumPaddingBytes(uint64_t SizeInBytes) {
390 return 7 & (sizeof(uint64_t) - SizeInBytes % sizeof(uint64_t));
391 }
392
393 Error readName(NamedInstrProfRecord &Record);
394 Error readFuncHash(NamedInstrProfRecord &Record);
395 Error readRawCounts(InstrProfRecord &Record);
396 Error readValueProfilingData(InstrProfRecord &Record);
397 bool atEnd() const { return Data == DataEnd; }
398
399 void advanceData() {
400 // `CountersDelta` is a constant zero when using debug info correlation.
401 if (!Correlator) {
402 // The initial CountersDelta is the in-memory address difference between
403 // the data and counts sections:
404 // start(__llvm_prf_cnts) - start(__llvm_prf_data)
405 // As we advance to the next record, we maintain the correct CountersDelta
406 // with respect to the next record.
407 CountersDelta -= sizeof(*Data);
408 }
409 Data++;
410 ValueDataStart += CurValueDataSize;
411 }
412
413 const char *getNextHeaderPos() const {
414 assert(atEnd());
415 return (const char *)ValueDataStart;
416 }
417
418 StringRef getName(uint64_t NameRef) const {
419 return Symtab->getFuncName(swap(NameRef));
420 }
421
422 int getCounterTypeSize() const {
423 return hasSingleByteCoverage() ? sizeof(uint8_t) : sizeof(uint64_t);
424 }
425};
426
429
430namespace IndexedInstrProf {
431
432enum class HashT : uint32_t;
433
434} // end namespace IndexedInstrProf
435
436/// Trait for lookups into the on-disk hash table for the binary instrprof
437/// format.
439 std::vector<NamedInstrProfRecord> DataBuffer;
441 unsigned FormatVersion;
442 // Endianness of the input value profile data.
443 // It should be LE by default, but can be changed
444 // for testing purpose.
445 support::endianness ValueProfDataEndianness = support::little;
446
447public:
448 InstrProfLookupTrait(IndexedInstrProf::HashT HashType, unsigned FormatVersion)
449 : HashType(HashType), FormatVersion(FormatVersion) {}
450
452
457
458 static bool EqualKey(StringRef A, StringRef B) { return A == B; }
459 static StringRef GetInternalKey(StringRef K) { return K; }
460 static StringRef GetExternalKey(StringRef K) { return K; }
461
463
464 static std::pair<offset_type, offset_type>
465 ReadKeyDataLength(const unsigned char *&D) {
466 using namespace support;
467
468 offset_type KeyLen = endian::readNext<offset_type, little, unaligned>(D);
469 offset_type DataLen = endian::readNext<offset_type, little, unaligned>(D);
470 return std::make_pair(KeyLen, DataLen);
471 }
472
473 StringRef ReadKey(const unsigned char *D, offset_type N) {
474 return StringRef((const char *)D, N);
475 }
476
477 bool readValueProfilingData(const unsigned char *&D,
478 const unsigned char *const End);
479 data_type ReadData(StringRef K, const unsigned char *D, offset_type N);
480
481 // Used for testing purpose only.
483 ValueProfDataEndianness = Endianness;
484 }
485};
486
488 virtual ~InstrProfReaderIndexBase() = default;
489
490 // Read all the profile records with the same key pointed to the current
491 // iterator.
493
494 // Read all the profile records with the key equal to FuncName
495 virtual Error getRecords(StringRef FuncName,
497 virtual void advanceToNextKey() = 0;
498 virtual bool atEnd() const = 0;
500 virtual uint64_t getVersion() const = 0;
501 virtual bool isIRLevelProfile() const = 0;
502 virtual bool hasCSIRLevelProfile() const = 0;
503 virtual bool instrEntryBBEnabled() const = 0;
504 virtual bool hasSingleByteCoverage() const = 0;
505 virtual bool functionEntryOnly() const = 0;
506 virtual bool hasMemoryProfile() const = 0;
507 virtual InstrProfKind getProfileKind() const = 0;
509};
510
513
518
519template <typename HashTableImpl>
521
522template <typename HashTableImpl>
524private:
525 std::unique_ptr<HashTableImpl> HashTable;
526 typename HashTableImpl::data_iterator RecordIterator;
527 uint64_t FormatVersion;
528
529 friend class InstrProfReaderItaniumRemapper<HashTableImpl>;
530
531public:
532 InstrProfReaderIndex(const unsigned char *Buckets,
533 const unsigned char *const Payload,
534 const unsigned char *const Base,
535 IndexedInstrProf::HashT HashType, uint64_t Version);
536 ~InstrProfReaderIndex() override = default;
537
539 Error getRecords(StringRef FuncName,
541 void advanceToNextKey() override { RecordIterator++; }
542
543 bool atEnd() const override {
544 return RecordIterator == HashTable->data_end();
545 }
546
548 HashTable->getInfoObj().setValueProfDataEndianness(Endianness);
549 }
550
551 uint64_t getVersion() const override { return GET_VERSION(FormatVersion); }
552
553 bool isIRLevelProfile() const override {
554 return (FormatVersion & VARIANT_MASK_IR_PROF) != 0;
555 }
556
557 bool hasCSIRLevelProfile() const override {
558 return (FormatVersion & VARIANT_MASK_CSIR_PROF) != 0;
559 }
560
561 bool instrEntryBBEnabled() const override {
562 return (FormatVersion & VARIANT_MASK_INSTR_ENTRY) != 0;
563 }
564
565 bool hasSingleByteCoverage() const override {
566 return (FormatVersion & VARIANT_MASK_BYTE_COVERAGE) != 0;
567 }
568
569 bool functionEntryOnly() const override {
570 return (FormatVersion & VARIANT_MASK_FUNCTION_ENTRY_ONLY) != 0;
571 }
572
573 bool hasMemoryProfile() const override {
574 return (FormatVersion & VARIANT_MASK_MEMPROF) != 0;
575 }
576
577 InstrProfKind getProfileKind() const override;
578
580 return Symtab.create(HashTable->keys());
581 }
582};
583
584/// Name matcher supporting fuzzy matching of symbol names to names in profiles.
586public:
587 virtual ~InstrProfReaderRemapper() = default;
589 virtual Error getRecords(StringRef FuncName,
591};
592
593/// Reader for the indexed binary instrprof format.
595private:
596 /// The profile data file contents.
597 std::unique_ptr<MemoryBuffer> DataBuffer;
598 /// The profile remapping file contents.
599 std::unique_ptr<MemoryBuffer> RemappingBuffer;
600 /// The index into the profile data.
601 std::unique_ptr<InstrProfReaderIndexBase> Index;
602 /// The profile remapping file contents.
603 std::unique_ptr<InstrProfReaderRemapper> Remapper;
604 /// Profile summary data.
605 std::unique_ptr<ProfileSummary> Summary;
606 /// Context sensitive profile summary data.
607 std::unique_ptr<ProfileSummary> CS_Summary;
608 /// MemProf profile schema (if available).
610 /// MemProf record profile data on-disk indexed via llvm::md5(FunctionName).
611 std::unique_ptr<MemProfRecordHashTable> MemProfRecordTable;
612 /// MemProf frame profile data on-disk indexed via frame id.
613 std::unique_ptr<MemProfFrameHashTable> MemProfFrameTable;
614 /// Total size of binary ids.
615 uint64_t BinaryIdsSize{0};
616 /// Start address of binary id length and data pairs.
617 const uint8_t *BinaryIdsStart = nullptr;
618
619 // Index to the current record in the record array.
620 unsigned RecordIndex;
621
622 // Read the profile summary. Return a pointer pointing to one byte past the
623 // end of the summary data if it exists or the input \c Cur.
624 // \c UseCS indicates whether to use the context-sensitive profile summary.
625 const unsigned char *readSummary(IndexedInstrProf::ProfVersion Version,
626 const unsigned char *Cur, bool UseCS);
627
628public:
630 std::unique_ptr<MemoryBuffer> DataBuffer,
631 std::unique_ptr<MemoryBuffer> RemappingBuffer = nullptr)
632 : DataBuffer(std::move(DataBuffer)),
633 RemappingBuffer(std::move(RemappingBuffer)), RecordIndex(0) {}
636
637 /// Return the profile version.
638 uint64_t getVersion() const override { return Index->getVersion(); }
639 bool isIRLevelProfile() const override { return Index->isIRLevelProfile(); }
640 bool hasCSIRLevelProfile() const override {
641 return Index->hasCSIRLevelProfile();
642 }
643
644 bool instrEntryBBEnabled() const override {
645 return Index->instrEntryBBEnabled();
646 }
647
648 bool hasSingleByteCoverage() const override {
649 return Index->hasSingleByteCoverage();
650 }
651
652 bool functionEntryOnly() const override { return Index->functionEntryOnly(); }
653
654 bool hasMemoryProfile() const override { return Index->hasMemoryProfile(); }
655
656 /// Returns a BitsetEnum describing the attributes of the indexed instr
657 /// profile.
658 InstrProfKind getProfileKind() const override {
659 return Index->getProfileKind();
660 }
661
662 /// Return true if the given buffer is in an indexed instrprof format.
663 static bool hasFormat(const MemoryBuffer &DataBuffer);
664
665 /// Read the file header.
666 Error readHeader() override;
667 /// Read a single record.
669
670 /// Return the NamedInstrProfRecord associated with FuncName and FuncHash.
671 /// When return a hash_mismatch error and MismatchedFuncSum is not nullptr,
672 /// the sum of all counters in the mismatched function will be set to
673 /// MismatchedFuncSum. If there are multiple instances of mismatched
674 /// functions, MismatchedFuncSum returns the maximum.
676 getInstrProfRecord(StringRef FuncName, uint64_t FuncHash,
677 uint64_t *MismatchedFuncSum = nullptr);
678
679 /// Return the memprof record for the function identified by
680 /// llvm::md5(Name).
682
683 /// Fill Counts with the profile data for the given function name.
684 Error getFunctionCounts(StringRef FuncName, uint64_t FuncHash,
685 std::vector<uint64_t> &Counts);
686
687 /// Return the maximum of all known function counts.
688 /// \c UseCS indicates whether to use the context-sensitive count.
690 if (UseCS) {
691 assert(CS_Summary && "No context sensitive profile summary");
692 return CS_Summary->getMaxFunctionCount();
693 } else {
694 assert(Summary && "No profile summary");
695 return Summary->getMaxFunctionCount();
696 }
697 }
698
699 /// Factory method to create an indexed reader.
701 create(const Twine &Path, vfs::FileSystem &FS,
702 const Twine &RemappingPath = "");
703
705 create(std::unique_ptr<MemoryBuffer> Buffer,
706 std::unique_ptr<MemoryBuffer> RemappingBuffer = nullptr);
707
708 // Used for testing purpose only.
710 Index->setValueProfDataEndianness(Endianness);
711 }
712
713 // See description in the base class. This interface is designed
714 // to be used by llvm-profdata (for dumping). Avoid using this when
715 // the client is the compiler.
716 InstrProfSymtab &getSymtab() override;
717
718 /// Return the profile summary.
719 /// \c UseCS indicates whether to use the context-sensitive summary.
721 if (UseCS) {
722 assert(CS_Summary && "No context sensitive summary");
723 return *CS_Summary;
724 } else {
725 assert(Summary && "No profile summary");
726 return *Summary;
727 }
728 }
729
730 Error readBinaryIds(std::vector<llvm::object::BuildID> &BinaryIds) override;
731 Error printBinaryIds(raw_ostream &OS) override;
732};
733
734} // end namespace llvm
735
736#endif // LLVM_PROFILEDATA_INSTRPROFREADER_H
aarch64 promote const
basic Basic Alias true
This file declares a library for handling Build IDs and using them to find debug info.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
InstrProfLookupTrait::offset_type offset_type
InstrProfLookupTrait::data_type data_type
Defines facilities for reading and writing on-disk hash tables.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
#define error(X)
Value * RHS
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
static ErrorSuccess success()
Create a success value.
Definition: Error.h:330
Tagged union holding either a T or a Error.
Definition: Error.h:470
Reader for the indexed binary instrprof format.
uint64_t getVersion() const override
Return the profile version.
Error readNextRecord(NamedInstrProfRecord &Record) override
Read a single record.
static Expected< std::unique_ptr< IndexedInstrProfReader > > create(const Twine &Path, vfs::FileSystem &FS, const Twine &RemappingPath="")
Factory method to create an indexed reader.
IndexedInstrProfReader(const IndexedInstrProfReader &)=delete
Expected< memprof::MemProfRecord > getMemProfRecord(uint64_t FuncNameHash)
Return the memprof record for the function identified by llvm::md5(Name).
Error readHeader() override
Read the file header.
Error printBinaryIds(raw_ostream &OS) override
Print binary ids.
void setValueProfDataEndianness(support::endianness Endianness)
bool hasSingleByteCoverage() const override
Return true if the profile has single byte counters representing coverage.
Expected< InstrProfRecord > getInstrProfRecord(StringRef FuncName, uint64_t FuncHash, uint64_t *MismatchedFuncSum=nullptr)
Return the NamedInstrProfRecord associated with FuncName and FuncHash.
InstrProfSymtab & getSymtab() override
Return the PGO symtab.
ProfileSummary & getSummary(bool UseCS)
Return the profile summary.
static bool hasFormat(const MemoryBuffer &DataBuffer)
Return true if the given buffer is in an indexed instrprof format.
bool hasMemoryProfile() const override
Return true if profile includes a memory profile.
bool functionEntryOnly() const override
Return true if the profile only instruments function entries.
uint64_t getMaximumFunctionCount(bool UseCS)
Return the maximum of all known function counts.
Error getFunctionCounts(StringRef FuncName, uint64_t FuncHash, std::vector< uint64_t > &Counts)
Fill Counts with the profile data for the given function name.
InstrProfKind getProfileKind() const override
Returns a BitsetEnum describing the attributes of the indexed instr profile.
IndexedInstrProfReader(std::unique_ptr< MemoryBuffer > DataBuffer, std::unique_ptr< MemoryBuffer > RemappingBuffer=nullptr)
Error readBinaryIds(std::vector< llvm::object::BuildID > &BinaryIds) override
Read a list of binary ids.
bool hasCSIRLevelProfile() const override
IndexedInstrProfReader & operator=(const IndexedInstrProfReader &)=delete
bool instrEntryBBEnabled() const override
bool isIRLevelProfile() const override
InstrProfCorrelatorImpl - A child of InstrProfCorrelator with a template pointer type so that the Pro...
InstrProfCorrelator - A base class used to create raw instrumentation data to their functions.
const std::string & getMessage() const
Definition: InstrProf.h:354
instrprof_error get() const
Definition: InstrProf.h:353
static instrprof_error take(Error E)
Consume an Error and return the raw enum value contained within it.
Definition: InstrProf.h:358
A file format agnostic iterator over profiling data.
bool operator==(const InstrProfIterator &RHS) const
value_type & operator*()
InstrProfIterator(reader_type *Reader)
InstrProfIterator & operator++()
bool operator!=(const InstrProfIterator &RHS) const
value_type * operator->()
std::ptrdiff_t difference_type
std::input_iterator_tag iterator_category
Trait for lookups into the on-disk hash table for the binary instrprof format.
InstrProfLookupTrait(IndexedInstrProf::HashT HashType, unsigned FormatVersion)
void setValueProfDataEndianness(support::endianness Endianness)
StringRef ReadKey(const unsigned char *D, offset_type N)
static std::pair< offset_type, offset_type > ReadKeyDataLength(const unsigned char *&D)
static StringRef GetExternalKey(StringRef K)
data_type ReadData(StringRef K, const unsigned char *D, offset_type N)
bool readValueProfilingData(const unsigned char *&D, const unsigned char *const End)
hash_value_type ComputeHash(StringRef K)
static bool EqualKey(StringRef A, StringRef B)
static StringRef GetInternalKey(StringRef K)
Error populateSymtab(InstrProfSymtab &Symtab) override
bool hasSingleByteCoverage() const override
void advanceToNextKey() override
bool hasCSIRLevelProfile() const override
InstrProfKind getProfileKind() const override
Error getRecords(ArrayRef< NamedInstrProfRecord > &Data) override
bool functionEntryOnly() const override
~InstrProfReaderIndex() override=default
uint64_t getVersion() const override
bool isIRLevelProfile() const override
bool hasMemoryProfile() const override
bool instrEntryBBEnabled() const override
void setValueProfDataEndianness(support::endianness Endianness) override
bool atEnd() const override
A remapper that applies remappings based on a symbol remapping file.
Name matcher supporting fuzzy matching of symbol names to names in profiles.
virtual Error getRecords(StringRef FuncName, ArrayRef< NamedInstrProfRecord > &Data)=0
virtual ~InstrProfReaderRemapper()=default
Base class and interface for reading profiling data of any known instrprof format.
InstrProfIterator begin()
Iterator over profile data.
virtual bool instrEntryBBEnabled() const =0
virtual Error readNextRecord(NamedInstrProfRecord &Record)=0
Read a single record.
static Expected< std::unique_ptr< InstrProfReader > > create(const Twine &Path, vfs::FileSystem &FS, const InstrProfCorrelator *Correlator=nullptr)
Factory method to create an appropriately typed reader for the given instrprof file.
Error error(Error &&E)
InstrProfIterator end()
virtual Error readBinaryIds(std::vector< llvm::object::BuildID > &BinaryIds)
Read a list of binary ids.
virtual bool functionEntryOnly() const =0
Return true if the profile only instruments function entries.
std::unique_ptr< InstrProfSymtab > Symtab
Error getError()
Get the current error.
virtual InstrProfSymtab & getSymtab()=0
Return the PGO symtab.
virtual bool hasSingleByteCoverage() const =0
Return true if the profile has single byte counters representing coverage.
Error success()
Clear the current error and return a successful one.
bool hasError()
Return true if the reader encountered an error reading profiling data.
virtual InstrProfKind getProfileKind() const =0
Returns a BitsetEnum describing the attributes of the profile.
virtual Error printBinaryIds(raw_ostream &OS)
Print binary ids.
virtual bool useDebugInfoCorrelate() const
Return true if we must provide debug info to create PGO profiles.
virtual uint64_t getVersion() const =0
Return the profile version.
virtual bool hasMemoryProfile() const =0
Return true if profile includes a memory profile.
virtual bool hasCSIRLevelProfile() const =0
virtual bool isIRLevelProfile() const =0
virtual ~InstrProfReader()=default
virtual Error readHeader()=0
Read the header. Required before reading first record.
Error error(instrprof_error Err, const std::string &ErrMsg="")
Set the current error and return same.
void accumulateCounts(CountSumOrPercent &Sum, bool IsCS)
Compute the sum of counts and return in Sum.
bool isEOF()
Return true if the reader has finished reading the profile data.
A symbol table used for function PGO name look-up with keys (such as pointers, md5hash values) to the...
Definition: InstrProf.h:446
Error create(object::SectionRef &Section)
Create InstrProfSymtab from an object file section which contains function PGO names.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:51
Provides lookup and iteration over an on disk hash table.
Reader for the raw instrprof binary format from runtime.
bool functionEntryOnly() const override
Return true if the profile only instruments function entries.
Error readHeader() override
Read the header. Required before reading first record.
Error readNextRecord(NamedInstrProfRecord &Record) override
Read a single record.
Error printBinaryIds(raw_ostream &OS) override
Print binary ids.
static bool hasFormat(const MemoryBuffer &DataBuffer)
RawInstrProfReader & operator=(const RawInstrProfReader &)=delete
bool hasSingleByteCoverage() const override
Return true if the profile has single byte counters representing coverage.
bool useDebugInfoCorrelate() const override
Return true if we must provide debug info to create PGO profiles.
bool isIRLevelProfile() const override
InstrProfKind getProfileKind() const override
Returns a BitsetEnum describing the attributes of the raw instr profile.
bool hasMemoryProfile() const override
Return true if profile includes a memory profile.
InstrProfSymtab & getSymtab() override
Return the PGO symtab.
Error readBinaryIds(std::vector< llvm::object::BuildID > &BinaryIds) override
Read a list of binary ids.
bool instrEntryBBEnabled() const override
RawInstrProfReader(std::unique_ptr< MemoryBuffer > DataBuffer, const InstrProfCorrelator *Correlator)
uint64_t getVersion() const override
Return the profile version.
RawInstrProfReader(const RawInstrProfReader &)=delete
bool hasCSIRLevelProfile() const override
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Reader for the simple text based instrprof format.
bool isIRLevelProfile() const override
uint64_t getVersion() const override
Return the profile version.
static bool hasFormat(const MemoryBuffer &Buffer)
Return true if the given buffer is in text instrprof format.
TextInstrProfReader(std::unique_ptr< MemoryBuffer > DataBuffer_)
bool hasSingleByteCoverage() const override
Return true if the profile has single byte counters representing coverage.
Error readNextRecord(NamedInstrProfRecord &Record) override
Read a single record.
TextInstrProfReader(const TextInstrProfReader &)=delete
bool hasMemoryProfile() const override
Return true if profile includes a memory profile.
bool hasCSIRLevelProfile() const override
InstrProfSymtab & getSymtab() override
Return the PGO symtab.
bool instrEntryBBEnabled() const override
bool functionEntryOnly() const override
Return true if the profile only instruments function entries.
InstrProfKind getProfileKind() const override
Returns a BitsetEnum describing the attributes of the profile.
Error readHeader() override
Read the header.
TextInstrProfReader & operator=(const TextInstrProfReader &)=delete
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
A forward iterator which reads text lines from a buffer.
Definition: LineIterator.h:33
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
The virtual file system interface.
unsigned char getSwappedBytes(unsigned char C)
Definition: SwapByteOrder.h:69
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
Definition: Error.h:966
auto dyn_cast_or_null(const Y &Val)
Definition: Casting.h:761
support::endianness getHostEndianness()
Definition: InstrProf.h:991
instrprof_error
Definition: InstrProf.h:308
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1862
InstrProfKind
An enum describing the attributes of an instrumented profile.
Definition: InstrProf.h:287
Definition: BitVector.h:851
#define N
virtual Error populateSymtab(InstrProfSymtab &)=0
virtual Error getRecords(ArrayRef< NamedInstrProfRecord > &Data)=0
virtual ~InstrProfReaderIndexBase()=default
virtual InstrProfKind getProfileKind() const =0
virtual bool isIRLevelProfile() const =0
virtual void advanceToNextKey()=0
virtual bool hasMemoryProfile() const =0
virtual bool hasCSIRLevelProfile() const =0
virtual uint64_t getVersion() const =0
virtual bool atEnd() const =0
virtual bool instrEntryBBEnabled() const =0
virtual Error getRecords(StringRef FuncName, ArrayRef< NamedInstrProfRecord > &Data)=0
virtual void setValueProfDataEndianness(support::endianness Endianness)=0
virtual bool functionEntryOnly() const =0
virtual bool hasSingleByteCoverage() const =0
Profiling information for a single function.
Definition: InstrProf.h:730