LLVM  15.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"
19 #include "llvm/IR/ProfileSummary.h"
23 #include "llvm/Support/Endian.h"
24 #include "llvm/Support/Error.h"
29 #include <algorithm>
30 #include <cassert>
31 #include <cstddef>
32 #include <cstdint>
33 #include <iterator>
34 #include <memory>
35 #include <utility>
36 #include <vector>
37 
38 namespace llvm {
39 
40 class InstrProfReader;
41 
42 /// A file format agnostic iterator over profiling data.
43 template <class record_type = NamedInstrProfRecord,
44  class reader_type = InstrProfReader>
46 public:
47  using iterator_category = std::input_iterator_tag;
48  using value_type = record_type;
49  using difference_type = std::ptrdiff_t;
50  using pointer = value_type *;
51  using reference = value_type &;
52 
53 private:
54  reader_type *Reader = nullptr;
56 
57  void increment() {
58  if (Error E = Reader->readNextRecord(Record)) {
59  // Handle errors in the reader.
61  *this = InstrProfIterator();
62  }
63  }
64 
65 public:
66  InstrProfIterator() = default;
67  InstrProfIterator(reader_type *Reader) : Reader(Reader) { increment(); }
68 
70  increment();
71  return *this;
72  }
73  bool operator==(const InstrProfIterator &RHS) const {
74  return Reader == RHS.Reader;
75  }
76  bool operator!=(const InstrProfIterator &RHS) const {
77  return Reader != RHS.Reader;
78  }
79  value_type &operator*() { return Record; }
80  value_type *operator->() { return &Record; }
81 };
82 
83 /// Base class and interface for reading profiling data of any known instrprof
84 /// format. Provides an iterator over NamedInstrProfRecords.
87  std::string LastErrorMsg;
88 
89 public:
90  InstrProfReader() = default;
91  virtual ~InstrProfReader() = default;
92 
93  /// Read the header. Required before reading first record.
94  virtual Error readHeader() = 0;
95 
96  /// Read a single record.
98 
99  /// Print binary ids on stream OS.
100  virtual Error printBinaryIds(raw_ostream &OS) { return success(); };
101 
102  /// Iterator over profile data.
105 
106  virtual bool isIRLevelProfile() const = 0;
107 
108  virtual bool hasCSIRLevelProfile() const = 0;
109 
110  virtual bool instrEntryBBEnabled() const = 0;
111 
112  /// Return true if we must provide debug info to create PGO profiles.
113  virtual bool useDebugInfoCorrelate() const { return false; }
114 
115  /// Return true if the profile has single byte counters representing coverage.
116  virtual bool hasSingleByteCoverage() const = 0;
117 
118  /// Return true if the profile only instruments function entries.
119  virtual bool functionEntryOnly() const = 0;
120 
121  /// Returns a BitsetEnum describing the attributes of the profile. To check
122  /// individual attributes prefer using the helpers above.
123  virtual InstrProfKind getProfileKind() const = 0;
124 
125  /// Return the PGO symtab. There are three different readers:
126  /// Raw, Text, and Indexed profile readers. The first two types
127  /// of readers are used only by llvm-profdata tool, while the indexed
128  /// profile reader is also used by llvm-cov tool and the compiler (
129  /// backend or frontend). Since creating PGO symtab can create
130  /// significant runtime and memory overhead (as it touches data
131  /// for the whole program), InstrProfSymtab for the indexed profile
132  /// reader should be created on demand and it is recommended to be
133  /// only used for dumping purpose with llvm-proftool, not with the
134  /// compiler.
135  virtual InstrProfSymtab &getSymtab() = 0;
136 
137  /// Compute the sum of counts and return in Sum.
138  void accumulateCounts(CountSumOrPercent &Sum, bool IsCS);
139 
140 protected:
141  std::unique_ptr<InstrProfSymtab> Symtab;
142 
143  /// Set the current error and return same.
144  Error error(instrprof_error Err, const std::string &ErrMsg = "") {
145  LastError = Err;
146  LastErrorMsg = ErrMsg;
147  if (Err == instrprof_error::success)
148  return Error::success();
149  return make_error<InstrProfError>(Err, ErrMsg);
150  }
151 
153  handleAllErrors(std::move(E), [&](const InstrProfError &IPE) {
154  LastError = IPE.get();
155  LastErrorMsg = IPE.getMessage();
156  });
157  return make_error<InstrProfError>(LastError, LastErrorMsg);
158  }
159 
160  /// Clear the current error and return a successful one.
162 
163 public:
164  /// Return true if the reader has finished reading the profile data.
165  bool isEOF() { return LastError == instrprof_error::eof; }
166 
167  /// Return true if the reader encountered an error reading profiling data.
168  bool hasError() { return LastError != instrprof_error::success && !isEOF(); }
169 
170  /// Get the current error.
172  if (hasError())
173  return make_error<InstrProfError>(LastError, LastErrorMsg);
174  return Error::success();
175  }
176 
177  /// Factory method to create an appropriately typed reader for the given
178  /// instrprof file.
180  create(const Twine &Path, const InstrProfCorrelator *Correlator = nullptr);
181 
183  create(std::unique_ptr<MemoryBuffer> Buffer,
184  const InstrProfCorrelator *Correlator = nullptr);
185 };
186 
187 /// Reader for the simple text based instrprof format.
188 ///
189 /// This format is a simple text format that's suitable for test data. Records
190 /// are separated by one or more blank lines, and record fields are separated by
191 /// new lines.
192 ///
193 /// Each record consists of a function name, a function hash, a number of
194 /// counters, and then each counter value, in that order.
196 private:
197  /// The profile data file contents.
198  std::unique_ptr<MemoryBuffer> DataBuffer;
199  /// Iterator over the profile data.
200  line_iterator Line;
201  /// The attributes of the current profile.
203 
204  Error readValueProfileData(InstrProfRecord &Record);
205 
206 public:
207  TextInstrProfReader(std::unique_ptr<MemoryBuffer> DataBuffer_)
208  : DataBuffer(std::move(DataBuffer_)), Line(*DataBuffer, true, '#') {}
209  TextInstrProfReader(const TextInstrProfReader &) = delete;
211 
212  /// Return true if the given buffer is in text instrprof format.
213  static bool hasFormat(const MemoryBuffer &Buffer);
214 
215  bool isIRLevelProfile() const override {
216  return static_cast<bool>(ProfileKind & InstrProfKind::IRInstrumentation);
217  }
218 
219  bool hasCSIRLevelProfile() const override {
220  return static_cast<bool>(ProfileKind & InstrProfKind::ContextSensitive);
221  }
222 
223  bool instrEntryBBEnabled() const override {
224  return static_cast<bool>(ProfileKind &
226  }
227 
228  bool hasSingleByteCoverage() const override {
229  return static_cast<bool>(ProfileKind & InstrProfKind::SingleByteCoverage);
230  }
231 
232  bool functionEntryOnly() const override {
233  return static_cast<bool>(ProfileKind & InstrProfKind::FunctionEntryOnly);
234  }
235 
236  InstrProfKind getProfileKind() const override { return ProfileKind; }
237 
238  /// Read the header.
239  Error readHeader() override;
240 
241  /// Read a single record.
243 
245  assert(Symtab.get());
246  return *Symtab.get();
247  }
248 };
249 
250 /// Reader for the raw instrprof binary format from runtime.
251 ///
252 /// This format is a raw memory dump of the instrumentation-based profiling data
253 /// from the runtime. It has no index.
254 ///
255 /// Templated on the unsigned type whose size matches pointers on the platform
256 /// that wrote the profile.
257 template <class IntPtrT>
259 private:
260  /// The profile data file contents.
261  std::unique_ptr<MemoryBuffer> DataBuffer;
262  /// If available, this hold the ProfileData array used to correlate raw
263  /// instrumentation data to their functions.
264  const InstrProfCorrelatorImpl<IntPtrT> *Correlator;
265  bool ShouldSwapBytes;
266  // The value of the version field of the raw profile data header. The lower 56
267  // bits specifies the format version and the most significant 8 bits specify
268  // the variant types of the profile.
269  uint64_t Version;
270  uint64_t CountersDelta;
271  uint64_t NamesDelta;
273  const RawInstrProf::ProfileData<IntPtrT> *DataEnd;
274  const char *CountersStart;
275  const char *CountersEnd;
276  const char *NamesStart;
277  const char *NamesEnd;
278  // After value profile is all read, this pointer points to
279  // the header of next profile data (if exists)
280  const uint8_t *ValueDataStart;
281  uint32_t ValueKindLast;
282  uint32_t CurValueDataSize;
283 
284  uint64_t BinaryIdsSize;
285  const uint8_t *BinaryIdsStart;
286 
287 public:
288  RawInstrProfReader(std::unique_ptr<MemoryBuffer> DataBuffer,
289  const InstrProfCorrelator *Correlator)
290  : DataBuffer(std::move(DataBuffer)),
291  Correlator(dyn_cast_or_null<const InstrProfCorrelatorImpl<IntPtrT>>(
292  Correlator)) {}
293  RawInstrProfReader(const RawInstrProfReader &) = delete;
295 
296  static bool hasFormat(const MemoryBuffer &DataBuffer);
297  Error readHeader() override;
299  Error printBinaryIds(raw_ostream &OS) override;
300 
301  bool isIRLevelProfile() const override {
302  return (Version & VARIANT_MASK_IR_PROF) != 0;
303  }
304 
305  bool hasCSIRLevelProfile() const override {
306  return (Version & VARIANT_MASK_CSIR_PROF) != 0;
307  }
308 
309  bool instrEntryBBEnabled() const override {
310  return (Version & VARIANT_MASK_INSTR_ENTRY) != 0;
311  }
312 
313  bool useDebugInfoCorrelate() const override {
314  return (Version & VARIANT_MASK_DBG_CORRELATE) != 0;
315  }
316 
317  bool hasSingleByteCoverage() const override {
318  return (Version & VARIANT_MASK_BYTE_COVERAGE) != 0;
319  }
320 
321  bool functionEntryOnly() const override {
322  return (Version & VARIANT_MASK_FUNCTION_ENTRY_ONLY) != 0;
323  }
324 
325  /// Returns a BitsetEnum describing the attributes of the raw instr profile.
326  InstrProfKind getProfileKind() const override;
327 
329  assert(Symtab.get());
330  return *Symtab.get();
331  }
332 
333 private:
334  Error createSymtab(InstrProfSymtab &Symtab);
335  Error readNextHeader(const char *CurrentPos);
336  Error readHeader(const RawInstrProf::Header &Header);
337 
338  template <class IntT> IntT swap(IntT Int) const {
339  return ShouldSwapBytes ? sys::getSwappedBytes(Int) : Int;
340  }
341 
342  support::endianness getDataEndianness() const {
343  support::endianness HostEndian = getHostEndianness();
344  if (!ShouldSwapBytes)
345  return HostEndian;
346  if (HostEndian == support::little)
347  return support::big;
348  else
349  return support::little;
350  }
351 
352  inline uint8_t getNumPaddingBytes(uint64_t SizeInBytes) {
353  return 7 & (sizeof(uint64_t) - SizeInBytes % sizeof(uint64_t));
354  }
355 
356  Error readName(NamedInstrProfRecord &Record);
357  Error readFuncHash(NamedInstrProfRecord &Record);
358  Error readRawCounts(InstrProfRecord &Record);
359  Error readValueProfilingData(InstrProfRecord &Record);
360  bool atEnd() const { return Data == DataEnd; }
361 
362  void advanceData() {
363  // `CountersDelta` is a constant zero when using debug info correlation.
364  if (!Correlator) {
365  // The initial CountersDelta is the in-memory address difference between
366  // the data and counts sections:
367  // start(__llvm_prf_cnts) - start(__llvm_prf_data)
368  // As we advance to the next record, we maintain the correct CountersDelta
369  // with respect to the next record.
370  CountersDelta -= sizeof(*Data);
371  }
372  Data++;
373  ValueDataStart += CurValueDataSize;
374  }
375 
376  const char *getNextHeaderPos() const {
377  assert(atEnd());
378  return (const char *)ValueDataStart;
379  }
380 
381  StringRef getName(uint64_t NameRef) const {
382  return Symtab->getFuncName(swap(NameRef));
383  }
384 
385  int getCounterTypeSize() const {
386  return hasSingleByteCoverage() ? sizeof(uint8_t) : sizeof(uint64_t);
387  }
388 };
389 
392 
393 namespace IndexedInstrProf {
394 
395 enum class HashT : uint32_t;
396 
397 } // end namespace IndexedInstrProf
398 
399 /// Trait for lookups into the on-disk hash table for the binary instrprof
400 /// format.
402  std::vector<NamedInstrProfRecord> DataBuffer;
404  unsigned FormatVersion;
405  // Endianness of the input value profile data.
406  // It should be LE by default, but can be changed
407  // for testing purpose.
408  support::endianness ValueProfDataEndianness = support::little;
409 
410 public:
412  : HashType(HashType), FormatVersion(FormatVersion) {}
413 
415 
420 
421  static bool EqualKey(StringRef A, StringRef B) { return A == B; }
422  static StringRef GetInternalKey(StringRef K) { return K; }
423  static StringRef GetExternalKey(StringRef K) { return K; }
424 
425  hash_value_type ComputeHash(StringRef K);
426 
427  static std::pair<offset_type, offset_type>
428  ReadKeyDataLength(const unsigned char *&D) {
429  using namespace support;
430 
431  offset_type KeyLen = endian::readNext<offset_type, little, unaligned>(D);
432  offset_type DataLen = endian::readNext<offset_type, little, unaligned>(D);
433  return std::make_pair(KeyLen, DataLen);
434  }
435 
436  StringRef ReadKey(const unsigned char *D, offset_type N) {
437  return StringRef((const char *)D, N);
438  }
439 
440  bool readValueProfilingData(const unsigned char *&D,
441  const unsigned char *const End);
442  data_type ReadData(StringRef K, const unsigned char *D, offset_type N);
443 
444  // Used for testing purpose only.
446  ValueProfDataEndianness = Endianness;
447  }
448 };
449 
451  virtual ~InstrProfReaderIndexBase() = default;
452 
453  // Read all the profile records with the same key pointed to the current
454  // iterator.
455  virtual Error getRecords(ArrayRef<NamedInstrProfRecord> &Data) = 0;
456 
457  // Read all the profile records with the key equal to FuncName
458  virtual Error getRecords(StringRef FuncName,
460  virtual void advanceToNextKey() = 0;
461  virtual bool atEnd() const = 0;
462  virtual void setValueProfDataEndianness(support::endianness Endianness) = 0;
463  virtual uint64_t getVersion() const = 0;
464  virtual bool isIRLevelProfile() const = 0;
465  virtual bool hasCSIRLevelProfile() const = 0;
466  virtual bool instrEntryBBEnabled() const = 0;
467  virtual bool hasSingleByteCoverage() const = 0;
468  virtual bool functionEntryOnly() const = 0;
469  virtual InstrProfKind getProfileKind() const = 0;
470  virtual Error populateSymtab(InstrProfSymtab &) = 0;
471 };
472 
473 using OnDiskHashTableImplV3 =
475 
478 using MemProfFrameHashTable =
480 
481 template <typename HashTableImpl>
483 
484 template <typename HashTableImpl>
486 private:
487  std::unique_ptr<HashTableImpl> HashTable;
488  typename HashTableImpl::data_iterator RecordIterator;
489  uint64_t FormatVersion;
490 
491  friend class InstrProfReaderItaniumRemapper<HashTableImpl>;
492 
493 public:
494  InstrProfReaderIndex(const unsigned char *Buckets,
495  const unsigned char *const Payload,
496  const unsigned char *const Base,
498  ~InstrProfReaderIndex() override = default;
499 
500  Error getRecords(ArrayRef<NamedInstrProfRecord> &Data) override;
501  Error getRecords(StringRef FuncName,
503  void advanceToNextKey() override { RecordIterator++; }
504 
505  bool atEnd() const override {
506  return RecordIterator == HashTable->data_end();
507  }
508 
510  HashTable->getInfoObj().setValueProfDataEndianness(Endianness);
511  }
512 
513  uint64_t getVersion() const override { return GET_VERSION(FormatVersion); }
514 
515  bool isIRLevelProfile() const override {
516  return (FormatVersion & VARIANT_MASK_IR_PROF) != 0;
517  }
518 
519  bool hasCSIRLevelProfile() const override {
520  return (FormatVersion & VARIANT_MASK_CSIR_PROF) != 0;
521  }
522 
523  bool instrEntryBBEnabled() const override {
524  return (FormatVersion & VARIANT_MASK_INSTR_ENTRY) != 0;
525  }
526 
527  bool hasSingleByteCoverage() const override {
528  return (FormatVersion & VARIANT_MASK_BYTE_COVERAGE) != 0;
529  }
530 
531  bool functionEntryOnly() const override {
532  return (FormatVersion & VARIANT_MASK_FUNCTION_ENTRY_ONLY) != 0;
533  }
534 
535  InstrProfKind getProfileKind() const override;
536 
538  return Symtab.create(HashTable->keys());
539  }
540 };
541 
542 /// Name matcher supporting fuzzy matching of symbol names to names in profiles.
544 public:
545  virtual ~InstrProfReaderRemapper() = default;
546  virtual Error populateRemappings() { return Error::success(); }
547  virtual Error getRecords(StringRef FuncName,
549 };
550 
551 /// Reader for the indexed binary instrprof format.
553 private:
554  /// The profile data file contents.
555  std::unique_ptr<MemoryBuffer> DataBuffer;
556  /// The profile remapping file contents.
557  std::unique_ptr<MemoryBuffer> RemappingBuffer;
558  /// The index into the profile data.
559  std::unique_ptr<InstrProfReaderIndexBase> Index;
560  /// The profile remapping file contents.
561  std::unique_ptr<InstrProfReaderRemapper> Remapper;
562  /// Profile summary data.
563  std::unique_ptr<ProfileSummary> Summary;
564  /// Context sensitive profile summary data.
565  std::unique_ptr<ProfileSummary> CS_Summary;
566  /// MemProf profile schema (if available).
567  memprof::MemProfSchema Schema;
568  /// MemProf record profile data on-disk indexed via llvm::md5(FunctionName).
569  std::unique_ptr<MemProfRecordHashTable> MemProfRecordTable;
570  /// MemProf frame profile data on-disk indexed via frame id.
571  std::unique_ptr<MemProfFrameHashTable> MemProfFrameTable;
572 
573  // Index to the current record in the record array.
574  unsigned RecordIndex;
575 
576  // Read the profile summary. Return a pointer pointing to one byte past the
577  // end of the summary data if it exists or the input \c Cur.
578  // \c UseCS indicates whether to use the context-sensitive profile summary.
579  const unsigned char *readSummary(IndexedInstrProf::ProfVersion Version,
580  const unsigned char *Cur, bool UseCS);
581 
582 public:
584  std::unique_ptr<MemoryBuffer> DataBuffer,
585  std::unique_ptr<MemoryBuffer> RemappingBuffer = nullptr)
586  : DataBuffer(std::move(DataBuffer)),
587  RemappingBuffer(std::move(RemappingBuffer)), RecordIndex(0) {}
589  IndexedInstrProfReader &operator=(const IndexedInstrProfReader &) = delete;
590 
591  /// Return the profile version.
592  uint64_t getVersion() const { return Index->getVersion(); }
593  bool isIRLevelProfile() const override { return Index->isIRLevelProfile(); }
594  bool hasCSIRLevelProfile() const override {
595  return Index->hasCSIRLevelProfile();
596  }
597 
598  bool instrEntryBBEnabled() const override {
599  return Index->instrEntryBBEnabled();
600  }
601 
602  bool hasSingleByteCoverage() const override {
603  return Index->hasSingleByteCoverage();
604  }
605 
606  bool functionEntryOnly() const override { return Index->functionEntryOnly(); }
607 
608  /// Returns a BitsetEnum describing the attributes of the indexed instr
609  /// profile.
610  InstrProfKind getProfileKind() const override {
611  return Index->getProfileKind();
612  }
613 
614  /// Return true if the given buffer is in an indexed instrprof format.
615  static bool hasFormat(const MemoryBuffer &DataBuffer);
616 
617  /// Read the file header.
618  Error readHeader() override;
619  /// Read a single record.
620  Error readNextRecord(NamedInstrProfRecord &Record) override;
621 
622  /// Return the NamedInstrProfRecord associated with FuncName and FuncHash
623  Expected<InstrProfRecord> getInstrProfRecord(StringRef FuncName,
624  uint64_t FuncHash);
625 
626  /// Return the memprof record for the function identified by
627  /// llvm::md5(Name).
628  Expected<memprof::MemProfRecord> getMemProfRecord(uint64_t FuncNameHash);
629 
630  /// Fill Counts with the profile data for the given function name.
631  Error getFunctionCounts(StringRef FuncName, uint64_t FuncHash,
632  std::vector<uint64_t> &Counts);
633 
634  /// Return the maximum of all known function counts.
635  /// \c UseCS indicates whether to use the context-sensitive count.
637  if (UseCS) {
638  assert(CS_Summary && "No context sensitive profile summary");
639  return CS_Summary->getMaxFunctionCount();
640  } else {
641  assert(Summary && "No profile summary");
642  return Summary->getMaxFunctionCount();
643  }
644  }
645 
646  /// Factory method to create an indexed reader.
648  create(const Twine &Path, const Twine &RemappingPath = "");
649 
651  create(std::unique_ptr<MemoryBuffer> Buffer,
652  std::unique_ptr<MemoryBuffer> RemappingBuffer = nullptr);
653 
654  // Used for testing purpose only.
656  Index->setValueProfDataEndianness(Endianness);
657  }
658 
659  // See description in the base class. This interface is designed
660  // to be used by llvm-profdata (for dumping). Avoid using this when
661  // the client is the compiler.
662  InstrProfSymtab &getSymtab() override;
663 
664  /// Return the profile summary.
665  /// \c UseCS indicates whether to use the context-sensitive summary.
666  ProfileSummary &getSummary(bool UseCS) {
667  if (UseCS) {
668  assert(CS_Summary && "No context sensitive summary");
669  return *(CS_Summary.get());
670  } else {
671  assert(Summary && "No profile summary");
672  return *(Summary.get());
673  }
674  }
675 };
676 
677 } // end namespace llvm
678 
679 #endif // LLVM_PROFILEDATA_INSTRPROFREADER_H
MemoryBuffer.h
llvm::TextInstrProfReader::functionEntryOnly
bool functionEntryOnly() const override
Return true if the profile only instruments function entries.
Definition: InstrProfReader.h:232
llvm::RawInstrProfReader
Reader for the raw instrprof binary format from runtime.
Definition: InstrProfReader.h:258
llvm::IndexedInstrProfReader::getSummary
ProfileSummary & getSummary(bool UseCS)
Return the profile summary.
Definition: InstrProfReader.h:666
llvm::InstrProfReader::success
Error success()
Clear the current error and return a successful one.
Definition: InstrProfReader.h:161
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::InstrProfReaderIndex::atEnd
bool atEnd() const override
Definition: InstrProfReader.h:505
llvm::TextInstrProfReader::instrEntryBBEnabled
bool instrEntryBBEnabled() const override
Definition: InstrProfReader.h:223
llvm::msgpack::Endianness
constexpr support::endianness Endianness
The endianness of all multi-byte encoded values in MessagePack.
Definition: MsgPack.h:24
llvm::IndexedInstrProf::ProfVersion
ProfVersion
Definition: InstrProf.h:998
llvm::InstrProfKind::FunctionEntryInstrumentation
@ FunctionEntryInstrumentation
llvm::InstrProfKind::FunctionEntryOnly
@ FunctionEntryOnly
offset_type
InstrProfLookupTrait::offset_type offset_type
Definition: InstrProfReader.cpp:637
llvm::lltok::Error
@ Error
Definition: LLToken.h:21
llvm::InstrProfIterator::operator==
bool operator==(const InstrProfIterator &RHS) const
Definition: InstrProfReader.h:73
llvm::InstrProfReader::InstrProfReader
InstrProfReader()=default
llvm::TextInstrProfReader::hasSingleByteCoverage
bool hasSingleByteCoverage() const override
Return true if the profile has single byte counters representing coverage.
Definition: InstrProfReader.h:228
llvm::line_iterator
A forward iterator which reads text lines from a buffer.
Definition: LineIterator.h:33
llvm::RawInstrProfReader::instrEntryBBEnabled
bool instrEntryBBEnabled() const override
Definition: InstrProfReader.h:309
llvm::RawInstrProfReader::getProfileKind
InstrProfKind getProfileKind() const override
Returns a BitsetEnum describing the attributes of the raw instr profile.
Definition: InstrProfReader.cpp:317
llvm::RawInstrProfReader::functionEntryOnly
bool functionEntryOnly() const override
Return true if the profile only instruments function entries.
Definition: InstrProfReader.h:321
ProfileSummary.h
StringRef.h
llvm::InstrProfReaderIndex::advanceToNextKey
void advanceToNextKey() override
Definition: InstrProfReader.h:503
llvm::IndexedInstrProfReader::hasSingleByteCoverage
bool hasSingleByteCoverage() const override
Return true if the profile has single byte counters representing coverage.
Definition: InstrProfReader.h:602
llvm::InstrProfReader::readNextRecord
virtual Error readNextRecord(NamedInstrProfRecord &Record)=0
Read a single record.
llvm::SmallVector< Meta, static_cast< int >(Meta::Size)>
llvm::IndexedInstrProf::ComputeHash
uint64_t ComputeHash(StringRef K)
Definition: InstrProf.h:1031
llvm::InstrProfKind::ContextSensitive
@ ContextSensitive
llvm::InstrProfSymtab::create
Error create(object::SectionRef &Section)
Create InstrProfSymtab from an object file section which contains function PGO names.
llvm::InstrProfError::get
instrprof_error get() const
Definition: InstrProf.h:348
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:329
llvm::InstrProfReader::isEOF
bool isEOF()
Return true if the reader has finished reading the profile data.
Definition: InstrProfReader.h:165
Error.h
llvm::InstrProfReader::functionEntryOnly
virtual bool functionEntryOnly() const =0
Return true if the profile only instruments function entries.
SwapByteOrder.h
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1886
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
RHS
Value * RHS
Definition: X86PartialReduction.cpp:76
llvm::InstrProfLookupTrait::GetInternalKey
static StringRef GetInternalKey(StringRef K)
Definition: InstrProfReader.h:422
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::MemoryBuffer
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:50
llvm::InstrProfRecord
Profiling information for a single function.
Definition: InstrProf.h:725
llvm::IndexedInstrProfReader::isIRLevelProfile
bool isIRLevelProfile() const override
Definition: InstrProfReader.h:593
llvm::IndexedInstrProfReader::setValueProfDataEndianness
void setValueProfDataEndianness(support::endianness Endianness)
Definition: InstrProfReader.h:655
llvm::TextInstrProfReader::operator=
TextInstrProfReader & operator=(const TextInstrProfReader &)=delete
llvm::InstrProfCorrelatorImpl
InstrProfCorrelatorImpl - A child of InstrProfCorrelator with a template pointer type so that the Pro...
Definition: InstrProfCorrelator.h:90
llvm::TextInstrProfReader::readHeader
Error readHeader() override
Read the header.
Definition: InstrProfReader.cpp:171
llvm::RawInstrProfReader::hasSingleByteCoverage
bool hasSingleByteCoverage() const override
Return true if the profile has single byte counters representing coverage.
Definition: InstrProfReader.h:317
llvm::IndexedInstrProfReader::getProfileKind
InstrProfKind getProfileKind() const override
Returns a BitsetEnum describing the attributes of the indexed instr profile.
Definition: InstrProfReader.h:610
llvm::InstrProfReader::hasError
bool hasError()
Return true if the reader encountered an error reading profiling data.
Definition: InstrProfReader.h:168
llvm::InstrProfLookupTrait
Trait for lookups into the on-disk hash table for the binary instrprof format.
Definition: InstrProfReader.h:401
llvm::TextInstrProfReader::getSymtab
InstrProfSymtab & getSymtab() override
Return the PGO symtab.
Definition: InstrProfReader.h:244
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::support::little
@ little
Definition: Endian.h:27
llvm::InstrProfLookupTrait::setValueProfDataEndianness
void setValueProfDataEndianness(support::endianness Endianness)
Definition: InstrProfReader.h:445
llvm::InstrProfKind::IRInstrumentation
@ IRInstrumentation
llvm::InstrProfKind::SingleByteCoverage
@ SingleByteCoverage
llvm::InstrProfIterator::operator++
InstrProfIterator & operator++()
Definition: InstrProfReader.h:69
llvm::InstrProfLookupTrait::EqualKey
static bool EqualKey(StringRef A, StringRef B)
Definition: InstrProfReader.h:421
OnDiskHashTable.h
llvm::InstrProfError::getMessage
const std::string & getMessage() const
Definition: InstrProf.h:349
llvm::InstrProfReaderIndex::functionEntryOnly
bool functionEntryOnly() const override
Definition: InstrProfReader.h:531
llvm::RawInstrProfReader::RawInstrProfReader
RawInstrProfReader(std::unique_ptr< MemoryBuffer > DataBuffer, const InstrProfCorrelator *Correlator)
Definition: InstrProfReader.h:288
llvm::InstrProfReader::hasCSIRLevelProfile
virtual bool hasCSIRLevelProfile() const =0
llvm::dwarf::Index
Index
Definition: Dwarf.h:472
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::InstrProfIterator::operator->
value_type * operator->()
Definition: InstrProfReader.h:80
llvm::InstrProfIterator::InstrProfIterator
InstrProfIterator(reader_type *Reader)
Definition: InstrProfReader.h:67
InstrProf.h
LineIterator.h
llvm::InstrProfReaderIndex::setValueProfDataEndianness
void setValueProfDataEndianness(support::endianness Endianness) override
Definition: InstrProfReader.h:509
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:54
llvm::TextInstrProfReader::hasCSIRLevelProfile
bool hasCSIRLevelProfile() const override
Definition: InstrProfReader.h:219
llvm::IndexedInstrProf::Version
const uint64_t Version
Definition: InstrProf.h:1027
llvm::TextInstrProfReader::readNextRecord
Error readNextRecord(NamedInstrProfRecord &Record) override
Read a single record.
Definition: InstrProfReader.cpp:266
llvm::InstrProfLookupTrait::GetExternalKey
static StringRef GetExternalKey(StringRef K)
Definition: InstrProfReader.h:423
llvm::InstrProfReader::Symtab
std::unique_ptr< InstrProfSymtab > Symtab
Definition: InstrProfReader.h:141
llvm::InstrProfError::take
static instrprof_error take(Error E)
Consume an Error and return the raw enum value contained within it.
Definition: InstrProf.h:353
llvm::InstrProfReaderRemapper::populateRemappings
virtual Error populateRemappings()
Definition: InstrProfReader.h:546
llvm::sys::getSwappedBytes
unsigned char getSwappedBytes(unsigned char C)
Definition: SwapByteOrder.h:103
llvm::getHostEndianness
support::endianness getHostEndianness()
Definition: InstrProf.h:962
llvm::InstrProfReaderIndex::isIRLevelProfile
bool isIRLevelProfile() const override
Definition: InstrProfReader.h:515
llvm::InstrProfReader::~InstrProfReader
virtual ~InstrProfReader()=default
uint64_t
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
const
aarch64 promote const
Definition: AArch64PromoteConstant.cpp:232
llvm::IndexedInstrProfReader::getVersion
uint64_t getVersion() const
Return the profile version.
Definition: InstrProfReader.h:592
llvm::IndexedInstrProfReader
Reader for the indexed binary instrprof format.
Definition: InstrProfReader.h:552
llvm::InstrProfError
Definition: InstrProf.h:333
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::InstrProfReader::error
Error error(Error &&E)
Definition: InstrProfReader.h:152
llvm::TextInstrProfReader
Reader for the simple text based instrprof format.
Definition: InstrProfReader.h:195
llvm::CountSumOrPercent
Definition: InstrProf.h:631
llvm::InstrProfIterator::reference
value_type & reference
Definition: InstrProfReader.h:51
llvm::InstrProfReaderIndex::hasSingleByteCoverage
bool hasSingleByteCoverage() const override
Definition: InstrProfReader.h:527
llvm::instrprof_error
instrprof_error
Definition: InstrProf.h:303
llvm::instrprof_error::success
@ success
ArrayRef.h
llvm::ProfileSummary
Definition: ProfileSummary.h:45
llvm::InstrProfReader::isIRLevelProfile
virtual bool isIRLevelProfile() const =0
llvm::InstrProfReaderIndex::hasCSIRLevelProfile
bool hasCSIRLevelProfile() const override
Definition: InstrProfReader.h:519
llvm::InstrProfLookupTrait::InstrProfLookupTrait
InstrProfLookupTrait(IndexedInstrProf::HashT HashType, unsigned FormatVersion)
Definition: InstrProfReader.h:411
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::IndexedInstrProfReader::IndexedInstrProfReader
IndexedInstrProfReader(std::unique_ptr< MemoryBuffer > DataBuffer, std::unique_ptr< MemoryBuffer > RemappingBuffer=nullptr)
Definition: InstrProfReader.h:583
llvm::move
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:1675
llvm::RawInstrProfReader::isIRLevelProfile
bool isIRLevelProfile() const override
Definition: InstrProfReader.h:301
llvm::RawInstrProfReader::hasCSIRLevelProfile
bool hasCSIRLevelProfile() const override
Definition: InstrProfReader.h:305
llvm::Record
Definition: Record.h:1543
llvm::InstrProfReader::printBinaryIds
virtual Error printBinaryIds(raw_ostream &OS)
Print binary ids on stream OS.
Definition: InstrProfReader.h:100
llvm::OnDiskIterableChainedHashTable
Provides lookup and iteration over an on disk hash table.
Definition: OnDiskHashTable.h:431
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::InstrProfReader::useDebugInfoCorrelate
virtual bool useDebugInfoCorrelate() const
Return true if we must provide debug info to create PGO profiles.
Definition: InstrProfReader.h:113
llvm::InstrProfReaderIndex
Definition: InstrProfReader.h:485
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::IndexedInstrProf::HashT
HashT
Definition: InstrProf.h:983
llvm::RawInstrProfReader::operator=
RawInstrProfReader & operator=(const RawInstrProfReader &)=delete
llvm::InstrProfReader::instrEntryBBEnabled
virtual bool instrEntryBBEnabled() const =0
uint32_t
llvm::instrprof_error::eof
@ eof
llvm::IndexedInstrProfReader::hasCSIRLevelProfile
bool hasCSIRLevelProfile() const override
Definition: InstrProfReader.h:594
llvm::RawInstrProfReader::readHeader
Error readHeader() override
Read the header. Required before reading first record.
Definition: InstrProfReader.cpp:332
llvm::InstrProfIterator::pointer
value_type * pointer
Definition: InstrProfReader.h:50
llvm::RawInstrProfReader::hasFormat
static bool hasFormat(const MemoryBuffer &DataBuffer)
Definition: InstrProfReader.cpp:322
llvm::TextInstrProfReader::getProfileKind
InstrProfKind getProfileKind() const override
Returns a BitsetEnum describing the attributes of the profile.
Definition: InstrProfReader.h:236
llvm::InstrProfReaderItaniumRemapper
A remapper that applies remappings based on a symbol remapping file.
Definition: InstrProfReader.h:482
llvm::InstrProfIterator::difference_type
std::ptrdiff_t difference_type
Definition: InstrProfReader.h:49
llvm::InstrProfReader::hasSingleByteCoverage
virtual bool hasSingleByteCoverage() const =0
Return true if the profile has single byte counters representing coverage.
MemProf.h
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
std
Definition: BitVector.h:851
llvm::InstrProfSymtab
A symbol table used for function PGO name look-up with keys (such as pointers, md5hash values) to the...
Definition: InstrProf.h:441
llvm::InstrProfReader::accumulateCounts
void accumulateCounts(CountSumOrPercent &Sum, bool IsCS)
Compute the sum of counts and return in Sum.
Definition: InstrProfReader.cpp:1108
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::RawInstrProfReader::getSymtab
InstrProfSymtab & getSymtab() override
Return the PGO symtab.
Definition: InstrProfReader.h:328
llvm::InstrProfReaderIndex::populateSymtab
Error populateSymtab(InstrProfSymtab &Symtab) override
Definition: InstrProfReader.h:537
llvm::InstrProfReaderRemapper
Name matcher supporting fuzzy matching of symbol names to names in profiles.
Definition: InstrProfReader.h:543
llvm::InstrProfReader::create
static Expected< std::unique_ptr< InstrProfReader > > create(const Twine &Path, const InstrProfCorrelator *Correlator=nullptr)
Factory method to create an appropriately typed reader for the given instrprof file.
Definition: InstrProfReader.cpp:79
llvm::InstrProfReader::readHeader
virtual Error readHeader()=0
Read the header. Required before reading first record.
llvm::RawInstrProfReader::readNextRecord
Error readNextRecord(NamedInstrProfRecord &Record) override
Read a single record.
Definition: InstrProfReader.cpp:547
llvm::IndexedInstrProf::HashType
const HashT HashType
Definition: InstrProf.h:1029
llvm::InstrProfReaderIndexBase
Definition: InstrProfReader.h:450
llvm::InstrProfReaderIndex::instrEntryBBEnabled
bool instrEntryBBEnabled() const override
Definition: InstrProfReader.h:523
llvm::IndexedInstrProfReader::instrEntryBBEnabled
bool instrEntryBBEnabled() const override
Definition: InstrProfReader.h:598
llvm::InstrProfReader::getError
Error getError()
Get the current error.
Definition: InstrProfReader.h:171
llvm::RawInstrProf::ProfileData
Definition: InstrProf.h:1176
llvm::TextInstrProfReader::TextInstrProfReader
TextInstrProfReader(std::unique_ptr< MemoryBuffer > DataBuffer_)
Definition: InstrProfReader.h:207
llvm::RawInstrProfReader::printBinaryIds
Error printBinaryIds(raw_ostream &OS) override
Print binary ids on stream OS.
Definition: InstrProfReader.cpp:579
llvm::InstrProfKind::Unknown
@ Unknown
llvm::IndexedInstrProfReader::functionEntryOnly
bool functionEntryOnly() const override
Return true if the profile only instruments function entries.
Definition: InstrProfReader.h:606
llvm::InstrProfIterator::operator*
value_type & operator*()
Definition: InstrProfReader.h:79
llvm::TextInstrProfReader::hasFormat
static bool hasFormat(const MemoryBuffer &Buffer)
Return true if the given buffer is in text instrprof format.
Definition: InstrProfReader.cpp:158
N
#define N
llvm::TextInstrProfReader::isIRLevelProfile
bool isIRLevelProfile() const override
Definition: InstrProfReader.h:215
llvm::InstrProfReader::end
InstrProfIterator end()
Definition: InstrProfReader.h:104
data_type
InstrProfLookupTrait::data_type data_type
Definition: InstrProfReader.cpp:636
llvm::InstrProfKind
InstrProfKind
An enum describing the attributes of an instrumented profile.
Definition: InstrProf.h:282
support
Reimplement select in terms of SEL *We would really like to support but we need to prove that the add doesn t need to overflow between the two bit chunks *Implement pre post increment support(e.g. PR935) *Implement smarter const ant generation for binops with large immediates. A few ARMv6T2 ops should be pattern matched
Definition: README.txt:10
llvm::InstrProfIterator::value_type
record_type value_type
Definition: InstrProfReader.h:48
llvm::InstrProfLookupTrait::ReadKey
StringRef ReadKey(const unsigned char *D, offset_type N)
Definition: InstrProfReader.h:436
llvm::support::endianness
endianness
Definition: Endian.h:27
llvm::InstrProfCorrelator
InstrProfCorrelator - A base class used to create raw instrumentation data to their functions.
Definition: InstrProfCorrelator.h:30
llvm::NamedInstrProfRecord
Definition: InstrProf.h:882
llvm::InstrProfReaderIndex::getVersion
uint64_t getVersion() const override
Definition: InstrProfReader.h:513
InstrProfCorrelator.h
llvm::InstrProfLookupTrait::ReadKeyDataLength
static std::pair< offset_type, offset_type > ReadKeyDataLength(const unsigned char *&D)
Definition: InstrProfReader.h:428
llvm::InstrProfIterator
A file format agnostic iterator over profiling data.
Definition: InstrProfReader.h:45
llvm::InstrProfReader::getSymtab
virtual InstrProfSymtab & getSymtab()=0
Return the PGO symtab.
llvm::IndexedInstrProfReader::getMaximumFunctionCount
uint64_t getMaximumFunctionCount(bool UseCS)
Return the maximum of all known function counts.
Definition: InstrProfReader.h:636
llvm::RawInstrProf::Header
Definition: InstrProf.h:1185
llvm::InstrProfIterator::iterator_category
std::input_iterator_tag iterator_category
Definition: InstrProfReader.h:47
Endian.h
llvm::InstrProfReader::getProfileKind
virtual InstrProfKind getProfileKind() const =0
Returns a BitsetEnum describing the attributes of the profile.
llvm::InstrProfReader::begin
InstrProfIterator begin()
Iterator over profile data.
Definition: InstrProfReader.h:103
llvm::InstrProfIterator::operator!=
bool operator!=(const InstrProfIterator &RHS) const
Definition: InstrProfReader.h:76
llvm::handleAllErrors
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
llvm::InstrProfIterator::InstrProfIterator
InstrProfIterator()=default
llvm::support::big
@ big
Definition: Endian.h:27
llvm::InstrProfReader
Base class and interface for reading profiling data of any known instrprof format.
Definition: InstrProfReader.h:85
llvm::sampleprof::Base
@ Base
Definition: Discriminator.h:58
llvm::InstrProfReader::error
Error error(instrprof_error Err, const std::string &ErrMsg="")
Set the current error and return same.
Definition: InstrProfReader.h:144
llvm::RawInstrProfReader::useDebugInfoCorrelate
bool useDebugInfoCorrelate() const override
Return true if we must provide debug info to create PGO profiles.
Definition: InstrProfReader.h:313
llvm::dyn_cast_or_null
auto dyn_cast_or_null(const Y &Val)
Definition: Casting.h:756