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