LLVM  16.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  /// Return the profile version.
107  virtual uint64_t getVersion() const = 0;
108 
109  virtual bool isIRLevelProfile() const = 0;
110 
111  virtual bool hasCSIRLevelProfile() const = 0;
112 
113  virtual bool instrEntryBBEnabled() const = 0;
114 
115  /// Return true if we must provide debug info to create PGO profiles.
116  virtual bool useDebugInfoCorrelate() const { return false; }
117 
118  /// Return true if the profile has single byte counters representing coverage.
119  virtual bool hasSingleByteCoverage() const = 0;
120 
121  /// Return true if the profile only instruments function entries.
122  virtual bool functionEntryOnly() const = 0;
123 
124  /// Return true if profile includes a memory profile.
125  virtual bool hasMemoryProfile() const = 0;
126 
127  /// Returns a BitsetEnum describing the attributes of the profile. To check
128  /// individual attributes prefer using the helpers above.
129  virtual InstrProfKind getProfileKind() const = 0;
130 
131  /// Return the PGO symtab. There are three different readers:
132  /// Raw, Text, and Indexed profile readers. The first two types
133  /// of readers are used only by llvm-profdata tool, while the indexed
134  /// profile reader is also used by llvm-cov tool and the compiler (
135  /// backend or frontend). Since creating PGO symtab can create
136  /// significant runtime and memory overhead (as it touches data
137  /// for the whole program), InstrProfSymtab for the indexed profile
138  /// reader should be created on demand and it is recommended to be
139  /// only used for dumping purpose with llvm-proftool, not with the
140  /// compiler.
141  virtual InstrProfSymtab &getSymtab() = 0;
142 
143  /// Compute the sum of counts and return in Sum.
144  void accumulateCounts(CountSumOrPercent &Sum, bool IsCS);
145 
146 protected:
147  std::unique_ptr<InstrProfSymtab> Symtab;
148 
149  /// Set the current error and return same.
150  Error error(instrprof_error Err, const std::string &ErrMsg = "") {
151  LastError = Err;
152  LastErrorMsg = ErrMsg;
153  if (Err == instrprof_error::success)
154  return Error::success();
155  return make_error<InstrProfError>(Err, ErrMsg);
156  }
157 
159  handleAllErrors(std::move(E), [&](const InstrProfError &IPE) {
160  LastError = IPE.get();
161  LastErrorMsg = IPE.getMessage();
162  });
163  return make_error<InstrProfError>(LastError, LastErrorMsg);
164  }
165 
166  /// Clear the current error and return a successful one.
168 
169 public:
170  /// Return true if the reader has finished reading the profile data.
171  bool isEOF() { return LastError == instrprof_error::eof; }
172 
173  /// Return true if the reader encountered an error reading profiling data.
174  bool hasError() { return LastError != instrprof_error::success && !isEOF(); }
175 
176  /// Get the current error.
178  if (hasError())
179  return make_error<InstrProfError>(LastError, LastErrorMsg);
180  return Error::success();
181  }
182 
183  /// Factory method to create an appropriately typed reader for the given
184  /// instrprof file.
186  create(const Twine &Path, const InstrProfCorrelator *Correlator = nullptr);
187 
189  create(std::unique_ptr<MemoryBuffer> Buffer,
190  const InstrProfCorrelator *Correlator = nullptr);
191 };
192 
193 /// Reader for the simple text based instrprof format.
194 ///
195 /// This format is a simple text format that's suitable for test data. Records
196 /// are separated by one or more blank lines, and record fields are separated by
197 /// new lines.
198 ///
199 /// Each record consists of a function name, a function hash, a number of
200 /// counters, and then each counter value, in that order.
202 private:
203  /// The profile data file contents.
204  std::unique_ptr<MemoryBuffer> DataBuffer;
205  /// Iterator over the profile data.
206  line_iterator Line;
207  /// The attributes of the current profile.
209 
210  Error readValueProfileData(InstrProfRecord &Record);
211 
212 public:
213  TextInstrProfReader(std::unique_ptr<MemoryBuffer> DataBuffer_)
214  : DataBuffer(std::move(DataBuffer_)), Line(*DataBuffer, true, '#') {}
215  TextInstrProfReader(const TextInstrProfReader &) = delete;
217 
218  /// Return true if the given buffer is in text instrprof format.
219  static bool hasFormat(const MemoryBuffer &Buffer);
220 
221  // Text format does not have version, so return 0.
222  uint64_t getVersion() const override { return 0; }
223 
224  bool isIRLevelProfile() const override {
225  return static_cast<bool>(ProfileKind & InstrProfKind::IRInstrumentation);
226  }
227 
228  bool hasCSIRLevelProfile() const override {
229  return static_cast<bool>(ProfileKind & InstrProfKind::ContextSensitive);
230  }
231 
232  bool instrEntryBBEnabled() const override {
233  return static_cast<bool>(ProfileKind &
235  }
236 
237  bool hasSingleByteCoverage() const override {
238  return static_cast<bool>(ProfileKind & InstrProfKind::SingleByteCoverage);
239  }
240 
241  bool functionEntryOnly() const override {
242  return static_cast<bool>(ProfileKind & InstrProfKind::FunctionEntryOnly);
243  }
244 
245  bool hasMemoryProfile() const override {
246  // TODO: Add support for text format memory profiles.
247  return false;
248  }
249 
250  InstrProfKind getProfileKind() const override { return ProfileKind; }
251 
252  /// Read the header.
253  Error readHeader() override;
254 
255  /// Read a single record.
257 
259  assert(Symtab.get());
260  return *Symtab.get();
261  }
262 };
263 
264 /// Reader for the raw instrprof binary format from runtime.
265 ///
266 /// This format is a raw memory dump of the instrumentation-based profiling data
267 /// from the runtime. It has no index.
268 ///
269 /// Templated on the unsigned type whose size matches pointers on the platform
270 /// that wrote the profile.
271 template <class IntPtrT>
273 private:
274  /// The profile data file contents.
275  std::unique_ptr<MemoryBuffer> DataBuffer;
276  /// If available, this hold the ProfileData array used to correlate raw
277  /// instrumentation data to their functions.
278  const InstrProfCorrelatorImpl<IntPtrT> *Correlator;
279  bool ShouldSwapBytes;
280  // The value of the version field of the raw profile data header. The lower 56
281  // bits specifies the format version and the most significant 8 bits specify
282  // the variant types of the profile.
283  uint64_t Version;
284  uint64_t CountersDelta;
285  uint64_t NamesDelta;
287  const RawInstrProf::ProfileData<IntPtrT> *DataEnd;
288  const char *CountersStart;
289  const char *CountersEnd;
290  const char *NamesStart;
291  const char *NamesEnd;
292  // After value profile is all read, this pointer points to
293  // the header of next profile data (if exists)
294  const uint8_t *ValueDataStart;
295  uint32_t ValueKindLast;
296  uint32_t CurValueDataSize;
297 
298  uint64_t BinaryIdsSize;
299  const uint8_t *BinaryIdsStart;
300 
301 public:
302  RawInstrProfReader(std::unique_ptr<MemoryBuffer> DataBuffer,
303  const InstrProfCorrelator *Correlator)
304  : DataBuffer(std::move(DataBuffer)),
305  Correlator(dyn_cast_or_null<const InstrProfCorrelatorImpl<IntPtrT>>(
306  Correlator)) {}
307  RawInstrProfReader(const RawInstrProfReader &) = delete;
309 
310  static bool hasFormat(const MemoryBuffer &DataBuffer);
311  Error readHeader() override;
313  Error printBinaryIds(raw_ostream &OS) override;
314 
315  uint64_t getVersion() const override { return Version; }
316 
317  bool isIRLevelProfile() const override {
318  return (Version & VARIANT_MASK_IR_PROF) != 0;
319  }
320 
321  bool hasCSIRLevelProfile() const override {
322  return (Version & VARIANT_MASK_CSIR_PROF) != 0;
323  }
324 
325  bool instrEntryBBEnabled() const override {
326  return (Version & VARIANT_MASK_INSTR_ENTRY) != 0;
327  }
328 
329  bool useDebugInfoCorrelate() const override {
330  return (Version & VARIANT_MASK_DBG_CORRELATE) != 0;
331  }
332 
333  bool hasSingleByteCoverage() const override {
334  return (Version & VARIANT_MASK_BYTE_COVERAGE) != 0;
335  }
336 
337  bool functionEntryOnly() const override {
338  return (Version & VARIANT_MASK_FUNCTION_ENTRY_ONLY) != 0;
339  }
340 
341  bool hasMemoryProfile() const override {
342  // Memory profiles have a separate raw format, so this should never be set.
343  assert(!(Version & VARIANT_MASK_MEMPROF));
344  return false;
345  }
346 
347  /// Returns a BitsetEnum describing the attributes of the raw instr profile.
348  InstrProfKind getProfileKind() const override;
349 
351  assert(Symtab.get());
352  return *Symtab.get();
353  }
354 
355 private:
356  Error createSymtab(InstrProfSymtab &Symtab);
357  Error readNextHeader(const char *CurrentPos);
358  Error readHeader(const RawInstrProf::Header &Header);
359 
360  template <class IntT> IntT swap(IntT Int) const {
361  return ShouldSwapBytes ? sys::getSwappedBytes(Int) : Int;
362  }
363 
364  support::endianness getDataEndianness() const {
365  support::endianness HostEndian = getHostEndianness();
366  if (!ShouldSwapBytes)
367  return HostEndian;
368  if (HostEndian == support::little)
369  return support::big;
370  else
371  return support::little;
372  }
373 
374  inline uint8_t getNumPaddingBytes(uint64_t SizeInBytes) {
375  return 7 & (sizeof(uint64_t) - SizeInBytes % sizeof(uint64_t));
376  }
377 
378  Error readName(NamedInstrProfRecord &Record);
379  Error readFuncHash(NamedInstrProfRecord &Record);
380  Error readRawCounts(InstrProfRecord &Record);
381  Error readValueProfilingData(InstrProfRecord &Record);
382  bool atEnd() const { return Data == DataEnd; }
383 
384  void advanceData() {
385  // `CountersDelta` is a constant zero when using debug info correlation.
386  if (!Correlator) {
387  // The initial CountersDelta is the in-memory address difference between
388  // the data and counts sections:
389  // start(__llvm_prf_cnts) - start(__llvm_prf_data)
390  // As we advance to the next record, we maintain the correct CountersDelta
391  // with respect to the next record.
392  CountersDelta -= sizeof(*Data);
393  }
394  Data++;
395  ValueDataStart += CurValueDataSize;
396  }
397 
398  const char *getNextHeaderPos() const {
399  assert(atEnd());
400  return (const char *)ValueDataStart;
401  }
402 
403  StringRef getName(uint64_t NameRef) const {
404  return Symtab->getFuncName(swap(NameRef));
405  }
406 
407  int getCounterTypeSize() const {
408  return hasSingleByteCoverage() ? sizeof(uint8_t) : sizeof(uint64_t);
409  }
410 };
411 
414 
415 namespace IndexedInstrProf {
416 
417 enum class HashT : uint32_t;
418 
419 } // end namespace IndexedInstrProf
420 
421 /// Trait for lookups into the on-disk hash table for the binary instrprof
422 /// format.
424  std::vector<NamedInstrProfRecord> DataBuffer;
426  unsigned FormatVersion;
427  // Endianness of the input value profile data.
428  // It should be LE by default, but can be changed
429  // for testing purpose.
430  support::endianness ValueProfDataEndianness = support::little;
431 
432 public:
434  : HashType(HashType), FormatVersion(FormatVersion) {}
435 
437 
442 
443  static bool EqualKey(StringRef A, StringRef B) { return A == B; }
444  static StringRef GetInternalKey(StringRef K) { return K; }
445  static StringRef GetExternalKey(StringRef K) { return K; }
446 
447  hash_value_type ComputeHash(StringRef K);
448 
449  static std::pair<offset_type, offset_type>
450  ReadKeyDataLength(const unsigned char *&D) {
451  using namespace support;
452 
453  offset_type KeyLen = endian::readNext<offset_type, little, unaligned>(D);
454  offset_type DataLen = endian::readNext<offset_type, little, unaligned>(D);
455  return std::make_pair(KeyLen, DataLen);
456  }
457 
458  StringRef ReadKey(const unsigned char *D, offset_type N) {
459  return StringRef((const char *)D, N);
460  }
461 
462  bool readValueProfilingData(const unsigned char *&D,
463  const unsigned char *const End);
464  data_type ReadData(StringRef K, const unsigned char *D, offset_type N);
465 
466  // Used for testing purpose only.
468  ValueProfDataEndianness = Endianness;
469  }
470 };
471 
473  virtual ~InstrProfReaderIndexBase() = default;
474 
475  // Read all the profile records with the same key pointed to the current
476  // iterator.
477  virtual Error getRecords(ArrayRef<NamedInstrProfRecord> &Data) = 0;
478 
479  // Read all the profile records with the key equal to FuncName
480  virtual Error getRecords(StringRef FuncName,
482  virtual void advanceToNextKey() = 0;
483  virtual bool atEnd() const = 0;
484  virtual void setValueProfDataEndianness(support::endianness Endianness) = 0;
485  virtual uint64_t getVersion() const = 0;
486  virtual bool isIRLevelProfile() const = 0;
487  virtual bool hasCSIRLevelProfile() const = 0;
488  virtual bool instrEntryBBEnabled() const = 0;
489  virtual bool hasSingleByteCoverage() const = 0;
490  virtual bool functionEntryOnly() const = 0;
491  virtual bool hasMemoryProfile() const = 0;
492  virtual InstrProfKind getProfileKind() const = 0;
493  virtual Error populateSymtab(InstrProfSymtab &) = 0;
494 };
495 
496 using OnDiskHashTableImplV3 =
498 
501 using MemProfFrameHashTable =
503 
504 template <typename HashTableImpl>
506 
507 template <typename HashTableImpl>
509 private:
510  std::unique_ptr<HashTableImpl> HashTable;
511  typename HashTableImpl::data_iterator RecordIterator;
512  uint64_t FormatVersion;
513 
514  friend class InstrProfReaderItaniumRemapper<HashTableImpl>;
515 
516 public:
517  InstrProfReaderIndex(const unsigned char *Buckets,
518  const unsigned char *const Payload,
519  const unsigned char *const Base,
521  ~InstrProfReaderIndex() override = default;
522 
523  Error getRecords(ArrayRef<NamedInstrProfRecord> &Data) override;
524  Error getRecords(StringRef FuncName,
526  void advanceToNextKey() override { RecordIterator++; }
527 
528  bool atEnd() const override {
529  return RecordIterator == HashTable->data_end();
530  }
531 
533  HashTable->getInfoObj().setValueProfDataEndianness(Endianness);
534  }
535 
536  uint64_t getVersion() const override { return GET_VERSION(FormatVersion); }
537 
538  bool isIRLevelProfile() const override {
539  return (FormatVersion & VARIANT_MASK_IR_PROF) != 0;
540  }
541 
542  bool hasCSIRLevelProfile() const override {
543  return (FormatVersion & VARIANT_MASK_CSIR_PROF) != 0;
544  }
545 
546  bool instrEntryBBEnabled() const override {
547  return (FormatVersion & VARIANT_MASK_INSTR_ENTRY) != 0;
548  }
549 
550  bool hasSingleByteCoverage() const override {
551  return (FormatVersion & VARIANT_MASK_BYTE_COVERAGE) != 0;
552  }
553 
554  bool functionEntryOnly() const override {
555  return (FormatVersion & VARIANT_MASK_FUNCTION_ENTRY_ONLY) != 0;
556  }
557 
558  bool hasMemoryProfile() const override {
559  return (FormatVersion & VARIANT_MASK_MEMPROF) != 0;
560  }
561 
562  InstrProfKind getProfileKind() const override;
563 
565  return Symtab.create(HashTable->keys());
566  }
567 };
568 
569 /// Name matcher supporting fuzzy matching of symbol names to names in profiles.
571 public:
572  virtual ~InstrProfReaderRemapper() = default;
573  virtual Error populateRemappings() { return Error::success(); }
574  virtual Error getRecords(StringRef FuncName,
576 };
577 
578 /// Reader for the indexed binary instrprof format.
580 private:
581  /// The profile data file contents.
582  std::unique_ptr<MemoryBuffer> DataBuffer;
583  /// The profile remapping file contents.
584  std::unique_ptr<MemoryBuffer> RemappingBuffer;
585  /// The index into the profile data.
586  std::unique_ptr<InstrProfReaderIndexBase> Index;
587  /// The profile remapping file contents.
588  std::unique_ptr<InstrProfReaderRemapper> Remapper;
589  /// Profile summary data.
590  std::unique_ptr<ProfileSummary> Summary;
591  /// Context sensitive profile summary data.
592  std::unique_ptr<ProfileSummary> CS_Summary;
593  /// MemProf profile schema (if available).
594  memprof::MemProfSchema Schema;
595  /// MemProf record profile data on-disk indexed via llvm::md5(FunctionName).
596  std::unique_ptr<MemProfRecordHashTable> MemProfRecordTable;
597  /// MemProf frame profile data on-disk indexed via frame id.
598  std::unique_ptr<MemProfFrameHashTable> MemProfFrameTable;
599 
600  // Index to the current record in the record array.
601  unsigned RecordIndex;
602 
603  // Read the profile summary. Return a pointer pointing to one byte past the
604  // end of the summary data if it exists or the input \c Cur.
605  // \c UseCS indicates whether to use the context-sensitive profile summary.
606  const unsigned char *readSummary(IndexedInstrProf::ProfVersion Version,
607  const unsigned char *Cur, bool UseCS);
608 
609 public:
611  std::unique_ptr<MemoryBuffer> DataBuffer,
612  std::unique_ptr<MemoryBuffer> RemappingBuffer = nullptr)
613  : DataBuffer(std::move(DataBuffer)),
614  RemappingBuffer(std::move(RemappingBuffer)), RecordIndex(0) {}
616  IndexedInstrProfReader &operator=(const IndexedInstrProfReader &) = delete;
617 
618  /// Return the profile version.
619  uint64_t getVersion() const override { return Index->getVersion(); }
620  bool isIRLevelProfile() const override { return Index->isIRLevelProfile(); }
621  bool hasCSIRLevelProfile() const override {
622  return Index->hasCSIRLevelProfile();
623  }
624 
625  bool instrEntryBBEnabled() const override {
626  return Index->instrEntryBBEnabled();
627  }
628 
629  bool hasSingleByteCoverage() const override {
630  return Index->hasSingleByteCoverage();
631  }
632 
633  bool functionEntryOnly() const override { return Index->functionEntryOnly(); }
634 
635  bool hasMemoryProfile() const override { return Index->hasMemoryProfile(); }
636 
637  /// Returns a BitsetEnum describing the attributes of the indexed instr
638  /// profile.
639  InstrProfKind getProfileKind() const override {
640  return Index->getProfileKind();
641  }
642 
643  /// Return true if the given buffer is in an indexed instrprof format.
644  static bool hasFormat(const MemoryBuffer &DataBuffer);
645 
646  /// Read the file header.
647  Error readHeader() override;
648  /// Read a single record.
649  Error readNextRecord(NamedInstrProfRecord &Record) override;
650 
651  /// Return the NamedInstrProfRecord associated with FuncName and FuncHash.
652  /// When return a hash_mismatch error and MismatchedFuncSum is not nullptr,
653  /// the sum of all counters in the mismatched function will be set to
654  /// MismatchedFuncSum. If there are multiple instances of mismatched
655  /// functions, MismatchedFuncSum returns the maximum.
657  getInstrProfRecord(StringRef FuncName, uint64_t FuncHash,
658  uint64_t *MismatchedFuncSum = nullptr);
659 
660  /// Return the memprof record for the function identified by
661  /// llvm::md5(Name).
662  Expected<memprof::MemProfRecord> getMemProfRecord(uint64_t FuncNameHash);
663 
664  /// Fill Counts with the profile data for the given function name.
665  Error getFunctionCounts(StringRef FuncName, uint64_t FuncHash,
666  std::vector<uint64_t> &Counts);
667 
668  /// Return the maximum of all known function counts.
669  /// \c UseCS indicates whether to use the context-sensitive count.
671  if (UseCS) {
672  assert(CS_Summary && "No context sensitive profile summary");
673  return CS_Summary->getMaxFunctionCount();
674  } else {
675  assert(Summary && "No profile summary");
676  return Summary->getMaxFunctionCount();
677  }
678  }
679 
680  /// Factory method to create an indexed reader.
682  create(const Twine &Path, const Twine &RemappingPath = "");
683 
685  create(std::unique_ptr<MemoryBuffer> Buffer,
686  std::unique_ptr<MemoryBuffer> RemappingBuffer = nullptr);
687 
688  // Used for testing purpose only.
690  Index->setValueProfDataEndianness(Endianness);
691  }
692 
693  // See description in the base class. This interface is designed
694  // to be used by llvm-profdata (for dumping). Avoid using this when
695  // the client is the compiler.
696  InstrProfSymtab &getSymtab() override;
697 
698  /// Return the profile summary.
699  /// \c UseCS indicates whether to use the context-sensitive summary.
700  ProfileSummary &getSummary(bool UseCS) {
701  if (UseCS) {
702  assert(CS_Summary && "No context sensitive summary");
703  return *(CS_Summary.get());
704  } else {
705  assert(Summary && "No profile summary");
706  return *(Summary.get());
707  }
708  }
709 };
710 
711 } // end namespace llvm
712 
713 #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:241
llvm::IndexedInstrProfReader::getVersion
uint64_t getVersion() const override
Return the profile version.
Definition: InstrProfReader.h:619
llvm::RawInstrProfReader
Reader for the raw instrprof binary format from runtime.
Definition: InstrProfReader.h:272
llvm::IndexedInstrProfReader::getSummary
ProfileSummary & getSummary(bool UseCS)
Return the profile summary.
Definition: InstrProfReader.h:700
llvm::InstrProfReader::success
Error success()
Clear the current error and return a successful one.
Definition: InstrProfReader.h:167
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::InstrProfReaderIndex::atEnd
bool atEnd() const override
Definition: InstrProfReader.h:528
llvm::TextInstrProfReader::instrEntryBBEnabled
bool instrEntryBBEnabled() const override
Definition: InstrProfReader.h:232
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:1027
llvm::InstrProfKind::FunctionEntryInstrumentation
@ FunctionEntryInstrumentation
llvm::InstrProfKind::FunctionEntryOnly
@ FunctionEntryOnly
offset_type
InstrProfLookupTrait::offset_type offset_type
Definition: InstrProfReader.cpp:639
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:237
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:325
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:337
ProfileSummary.h
StringRef.h
llvm::InstrProfReaderIndex::advanceToNextKey
void advanceToNextKey() override
Definition: InstrProfReader.h:526
llvm::IndexedInstrProfReader::hasSingleByteCoverage
bool hasSingleByteCoverage() const override
Return true if the profile has single byte counters representing coverage.
Definition: InstrProfReader.h:629
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:1060
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:353
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:171
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:1793
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:444
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:51
llvm::InstrProfRecord
Profiling information for a single function.
Definition: InstrProf.h:730
llvm::IndexedInstrProfReader::isIRLevelProfile
bool isIRLevelProfile() const override
Definition: InstrProfReader.h:620
llvm::IndexedInstrProfReader::setValueProfDataEndianness
void setValueProfDataEndianness(support::endianness Endianness)
Definition: InstrProfReader.h:689
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:112
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:333
llvm::IndexedInstrProfReader::getProfileKind
InstrProfKind getProfileKind() const override
Returns a BitsetEnum describing the attributes of the indexed instr profile.
Definition: InstrProfReader.h:639
llvm::InstrProfReader::hasError
bool hasError()
Return true if the reader encountered an error reading profiling data.
Definition: InstrProfReader.h:174
llvm::InstrProfLookupTrait
Trait for lookups into the on-disk hash table for the binary instrprof format.
Definition: InstrProfReader.h:423
llvm::TextInstrProfReader::getSymtab
InstrProfSymtab & getSymtab() override
Return the PGO symtab.
Definition: InstrProfReader.h:258
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:467
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:443
OnDiskHashTable.h
llvm::InstrProfError::getMessage
const std::string & getMessage() const
Definition: InstrProf.h:354
llvm::InstrProfReaderIndex::functionEntryOnly
bool functionEntryOnly() const override
Definition: InstrProfReader.h:554
getProfileKind
static ARM::ProfileKind getProfileKind(ARM::ArchKind AK)
Definition: ARMTargetParser.cpp:94
llvm::RawInstrProfReader::RawInstrProfReader
RawInstrProfReader(std::unique_ptr< MemoryBuffer > DataBuffer, const InstrProfCorrelator *Correlator)
Definition: InstrProfReader.h:302
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:532
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::TextInstrProfReader::hasCSIRLevelProfile
bool hasCSIRLevelProfile() const override
Definition: InstrProfReader.h:228
llvm::IndexedInstrProf::Version
const uint64_t Version
Definition: InstrProf.h:1056
llvm::TextInstrProfReader::readNextRecord
Error readNextRecord(NamedInstrProfRecord &Record) override
Read a single record.
Definition: InstrProfReader.cpp:266
llvm::RawInstrProfReader::hasMemoryProfile
bool hasMemoryProfile() const override
Return true if profile includes a memory profile.
Definition: InstrProfReader.h:341
llvm::InstrProfLookupTrait::GetExternalKey
static StringRef GetExternalKey(StringRef K)
Definition: InstrProfReader.h:445
llvm::InstrProfReader::Symtab
std::unique_ptr< InstrProfSymtab > Symtab
Definition: InstrProfReader.h:147
llvm::InstrProfError::take
static instrprof_error take(Error E)
Consume an Error and return the raw enum value contained within it.
Definition: InstrProf.h:358
Int
@ Int
Definition: TargetLibraryInfo.cpp:48
llvm::RawInstrProfReader::getVersion
uint64_t getVersion() const override
Return the profile version.
Definition: InstrProfReader.h:315
llvm::InstrProfReaderRemapper::populateRemappings
virtual Error populateRemappings()
Definition: InstrProfReader.h:573
llvm::sys::getSwappedBytes
unsigned char getSwappedBytes(unsigned char C)
Definition: SwapByteOrder.h:103
llvm::getHostEndianness
support::endianness getHostEndianness()
Definition: InstrProf.h:991
llvm::InstrProfReaderIndex::isIRLevelProfile
bool isIRLevelProfile() const override
Definition: InstrProfReader.h:538
llvm::InstrProfReader::~InstrProfReader
virtual ~InstrProfReader()=default
Index
uint32_t Index
Definition: ELFObjHandler.cpp:83
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
Reader for the indexed binary instrprof format.
Definition: InstrProfReader.h:579
llvm::InstrProfError
Definition: InstrProf.h:338
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:158
llvm::InstrProfReader::hasMemoryProfile
virtual bool hasMemoryProfile() const =0
Return true if profile includes a memory profile.
llvm::TextInstrProfReader
Reader for the simple text based instrprof format.
Definition: InstrProfReader.h:201
llvm::CountSumOrPercent
Definition: InstrProf.h:636
llvm::InstrProfIterator::reference
value_type & reference
Definition: InstrProfReader.h:51
llvm::InstrProfReaderIndex::hasSingleByteCoverage
bool hasSingleByteCoverage() const override
Definition: InstrProfReader.h:550
llvm::instrprof_error
instrprof_error
Definition: InstrProf.h:308
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:542
llvm::InstrProfLookupTrait::InstrProfLookupTrait
InstrProfLookupTrait(IndexedInstrProf::HashT HashType, unsigned FormatVersion)
Definition: InstrProfReader.h:433
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:610
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:1836
llvm::RawInstrProfReader::isIRLevelProfile
bool isIRLevelProfile() const override
Definition: InstrProfReader.h:317
llvm::RawInstrProfReader::hasCSIRLevelProfile
bool hasCSIRLevelProfile() const override
Definition: InstrProfReader.h:321
llvm::Record
Definition: Record.h:1573
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:430
llvm::IndexedInstrProfReader::hasMemoryProfile
bool hasMemoryProfile() const override
Return true if profile includes a memory profile.
Definition: InstrProfReader.h:635
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:116
llvm::InstrProfReaderIndex
Definition: InstrProfReader.h:508
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::IndexedInstrProf::HashT
HashT
Definition: InstrProf.h:1012
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:621
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::getVersion
uint64_t getVersion() const override
Return the profile version.
Definition: InstrProfReader.h:222
llvm::TextInstrProfReader::getProfileKind
InstrProfKind getProfileKind() const override
Returns a BitsetEnum describing the attributes of the profile.
Definition: InstrProfReader.h:250
llvm::InstrProfReaderItaniumRemapper
A remapper that applies remappings based on a symbol remapping file.
Definition: InstrProfReader.h:505
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:81
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:446
llvm::InstrProfReader::accumulateCounts
void accumulateCounts(CountSumOrPercent &Sum, bool IsCS)
Compute the sum of counts and return in Sum.
Definition: InstrProfReader.cpp:1139
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:350
llvm::InstrProfReaderIndex::populateSymtab
Error populateSymtab(InstrProfSymtab &Symtab) override
Definition: InstrProfReader.h:564
llvm::InstrProfReaderRemapper
Name matcher supporting fuzzy matching of symbol names to names in profiles.
Definition: InstrProfReader.h:570
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::TextInstrProfReader::hasMemoryProfile
bool hasMemoryProfile() const override
Return true if profile includes a memory profile.
Definition: InstrProfReader.h:245
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:1058
llvm::InstrProfReaderIndexBase
Definition: InstrProfReader.h:472
llvm::InstrProfReaderIndex::instrEntryBBEnabled
bool instrEntryBBEnabled() const override
Definition: InstrProfReader.h:546
llvm::IndexedInstrProfReader::instrEntryBBEnabled
bool instrEntryBBEnabled() const override
Definition: InstrProfReader.h:625
llvm::InstrProfReader::getError
Error getError()
Get the current error.
Definition: InstrProfReader.h:177
llvm::RawInstrProf::ProfileData
Definition: InstrProf.h:1205
llvm::TextInstrProfReader::TextInstrProfReader
TextInstrProfReader(std::unique_ptr< MemoryBuffer > DataBuffer_)
Definition: InstrProfReader.h:213
llvm::RawInstrProfReader::printBinaryIds
Error printBinaryIds(raw_ostream &OS) override
Print binary ids on stream OS.
Definition: InstrProfReader.cpp:581
llvm::InstrProfKind::Unknown
@ Unknown
llvm::IndexedInstrProfReader::functionEntryOnly
bool functionEntryOnly() const override
Return true if the profile only instruments function entries.
Definition: InstrProfReader.h:633
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:224
llvm::InstrProfReader::end
InstrProfIterator end()
Definition: InstrProfReader.h:104
data_type
InstrProfLookupTrait::data_type data_type
Definition: InstrProfReader.cpp:638
llvm::InstrProfKind
InstrProfKind
An enum describing the attributes of an instrumented profile.
Definition: InstrProf.h:287
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:458
llvm::InstrProfReaderIndex::hasMemoryProfile
bool hasMemoryProfile() const override
Definition: InstrProfReader.h:558
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:31
llvm::NamedInstrProfRecord
Definition: InstrProf.h:911
llvm::InstrProfReaderIndex::getVersion
uint64_t getVersion() const override
Definition: InstrProfReader.h:536
InstrProfCorrelator.h
llvm::InstrProfReader::getVersion
virtual uint64_t getVersion() const =0
Return the profile version.
llvm::InstrProfLookupTrait::ReadKeyDataLength
static std::pair< offset_type, offset_type > ReadKeyDataLength(const unsigned char *&D)
Definition: InstrProfReader.h:450
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:670
llvm::RawInstrProf::Header
Definition: InstrProf.h:1214
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:965
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:150
llvm::RawInstrProfReader::useDebugInfoCorrelate
bool useDebugInfoCorrelate() const override
Return true if we must provide debug info to create PGO profiles.
Definition: InstrProfReader.h:329
llvm::dyn_cast_or_null
auto dyn_cast_or_null(const Y &Val)
Definition: Casting.h:758