LLVM  14.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"
21 #include "llvm/Support/Endian.h"
22 #include "llvm/Support/Error.h"
27 #include <algorithm>
28 #include <cassert>
29 #include <cstddef>
30 #include <cstdint>
31 #include <iterator>
32 #include <memory>
33 #include <utility>
34 #include <vector>
35 
36 namespace llvm {
37 
38 class InstrProfReader;
39 
40 /// A file format agnostic iterator over profiling data.
42 public:
43  using iterator_category = std::input_iterator_tag;
45  using difference_type = std::ptrdiff_t;
46  using pointer = value_type *;
47  using reference = value_type &;
48 
49 private:
50  InstrProfReader *Reader = nullptr;
52 
53  void Increment();
54 
55 public:
56  InstrProfIterator() = default;
57  InstrProfIterator(InstrProfReader *Reader) : Reader(Reader) { Increment(); }
58 
59  InstrProfIterator &operator++() { Increment(); return *this; }
60  bool operator==(const InstrProfIterator &RHS) const {
61  return Reader == RHS.Reader;
62  }
63  bool operator!=(const InstrProfIterator &RHS) const {
64  return Reader != RHS.Reader;
65  }
66  value_type &operator*() { return Record; }
67  value_type *operator->() { return &Record; }
68 };
69 
70 /// Base class and interface for reading profiling data of any known instrprof
71 /// format. Provides an iterator over NamedInstrProfRecords.
74  std::string LastErrorMsg;
75 
76 public:
77  InstrProfReader() = default;
78  virtual ~InstrProfReader() = default;
79 
80  /// Read the header. Required before reading first record.
81  virtual Error readHeader() = 0;
82 
83  /// Read a single record.
85 
86  /// Print binary ids on stream OS.
87  virtual Error printBinaryIds(raw_ostream &OS) { return success(); };
88 
89  /// Iterator over profile data.
92 
93  virtual bool isIRLevelProfile() const = 0;
94 
95  virtual bool hasCSIRLevelProfile() const = 0;
96 
97  virtual bool instrEntryBBEnabled() const = 0;
98 
99  /// Return the PGO symtab. There are three different readers:
100  /// Raw, Text, and Indexed profile readers. The first two types
101  /// of readers are used only by llvm-profdata tool, while the indexed
102  /// profile reader is also used by llvm-cov tool and the compiler (
103  /// backend or frontend). Since creating PGO symtab can create
104  /// significant runtime and memory overhead (as it touches data
105  /// for the whole program), InstrProfSymtab for the indexed profile
106  /// reader should be created on demand and it is recommended to be
107  /// only used for dumping purpose with llvm-proftool, not with the
108  /// compiler.
109  virtual InstrProfSymtab &getSymtab() = 0;
110 
111  /// Compute the sum of counts and return in Sum.
112  void accumulateCounts(CountSumOrPercent &Sum, bool IsCS);
113 
114 protected:
115  std::unique_ptr<InstrProfSymtab> Symtab;
116 
117  /// Set the current error and return same.
118  Error error(instrprof_error Err, const std::string &ErrMsg = "") {
119  LastError = Err;
120  LastErrorMsg = ErrMsg;
121  if (Err == instrprof_error::success)
122  return Error::success();
123  return make_error<InstrProfError>(Err, ErrMsg);
124  }
125 
127  handleAllErrors(std::move(E), [&](const InstrProfError &IPE) {
128  LastError = IPE.get();
129  LastErrorMsg = IPE.getMessage();
130  });
131  return make_error<InstrProfError>(LastError, LastErrorMsg);
132  }
133 
134  /// Clear the current error and return a successful one.
136 
137 public:
138  /// Return true if the reader has finished reading the profile data.
139  bool isEOF() { return LastError == instrprof_error::eof; }
140 
141  /// Return true if the reader encountered an error reading profiling data.
142  bool hasError() { return LastError != instrprof_error::success && !isEOF(); }
143 
144  /// Get the current error.
146  if (hasError())
147  return make_error<InstrProfError>(LastError, LastErrorMsg);
148  return Error::success();
149  }
150 
151  /// Factory method to create an appropriately typed reader for the given
152  /// instrprof file.
154 
156  create(std::unique_ptr<MemoryBuffer> Buffer);
157 };
158 
159 /// Reader for the simple text based instrprof format.
160 ///
161 /// This format is a simple text format that's suitable for test data. Records
162 /// are separated by one or more blank lines, and record fields are separated by
163 /// new lines.
164 ///
165 /// Each record consists of a function name, a function hash, a number of
166 /// counters, and then each counter value, in that order.
168 private:
169  /// The profile data file contents.
170  std::unique_ptr<MemoryBuffer> DataBuffer;
171  /// Iterator over the profile data.
172  line_iterator Line;
173  bool IsIRLevelProfile = false;
174  bool HasCSIRLevelProfile = false;
175  bool InstrEntryBBEnabled = false;
176 
177  Error readValueProfileData(InstrProfRecord &Record);
178 
179 public:
180  TextInstrProfReader(std::unique_ptr<MemoryBuffer> DataBuffer_)
181  : DataBuffer(std::move(DataBuffer_)), Line(*DataBuffer, true, '#') {}
182  TextInstrProfReader(const TextInstrProfReader &) = delete;
184 
185  /// Return true if the given buffer is in text instrprof format.
186  static bool hasFormat(const MemoryBuffer &Buffer);
187 
188  bool isIRLevelProfile() const override { return IsIRLevelProfile; }
189 
190  bool hasCSIRLevelProfile() const override { return HasCSIRLevelProfile; }
191 
192  bool instrEntryBBEnabled() const override { return InstrEntryBBEnabled; }
193 
194  /// Read the header.
195  Error readHeader() override;
196 
197  /// Read a single record.
199 
201  assert(Symtab.get());
202  return *Symtab.get();
203  }
204 };
205 
206 /// Reader for the raw instrprof binary format from runtime.
207 ///
208 /// This format is a raw memory dump of the instrumentation-based profiling data
209 /// from the runtime. It has no index.
210 ///
211 /// Templated on the unsigned type whose size matches pointers on the platform
212 /// that wrote the profile.
213 template <class IntPtrT>
215 private:
216  /// The profile data file contents.
217  std::unique_ptr<MemoryBuffer> DataBuffer;
218  bool ShouldSwapBytes;
219  // The value of the version field of the raw profile data header. The lower 56
220  // bits specifies the format version and the most significant 8 bits specify
221  // the variant types of the profile.
222  uint64_t Version;
223  uint64_t CountersDelta;
224  uint64_t NamesDelta;
226  const RawInstrProf::ProfileData<IntPtrT> *DataEnd;
227  const uint64_t *CountersStart;
228  const char *NamesStart;
229  uint64_t NamesSize;
230  // After value profile is all read, this pointer points to
231  // the header of next profile data (if exists)
232  const uint8_t *ValueDataStart;
233  uint32_t ValueKindLast;
234  uint32_t CurValueDataSize;
235 
236  uint64_t BinaryIdsSize;
237  const uint8_t *BinaryIdsStart;
238 
239 public:
240  RawInstrProfReader(std::unique_ptr<MemoryBuffer> DataBuffer)
241  : DataBuffer(std::move(DataBuffer)) {}
242  RawInstrProfReader(const RawInstrProfReader &) = delete;
244 
245  static bool hasFormat(const MemoryBuffer &DataBuffer);
246  Error readHeader() override;
248  Error printBinaryIds(raw_ostream &OS) override;
249 
250  bool isIRLevelProfile() const override {
251  return (Version & VARIANT_MASK_IR_PROF) != 0;
252  }
253 
254  bool hasCSIRLevelProfile() const override {
255  return (Version & VARIANT_MASK_CSIR_PROF) != 0;
256  }
257 
258  bool instrEntryBBEnabled() const override {
259  return (Version & VARIANT_MASK_INSTR_ENTRY) != 0;
260  }
261 
263  assert(Symtab.get());
264  return *Symtab.get();
265  }
266 
267 private:
268  Error createSymtab(InstrProfSymtab &Symtab);
269  Error readNextHeader(const char *CurrentPos);
270  Error readHeader(const RawInstrProf::Header &Header);
271 
272  template <class IntT> IntT swap(IntT Int) const {
273  return ShouldSwapBytes ? sys::getSwappedBytes(Int) : Int;
274  }
275 
276  support::endianness getDataEndianness() const {
277  support::endianness HostEndian = getHostEndianness();
278  if (!ShouldSwapBytes)
279  return HostEndian;
280  if (HostEndian == support::little)
281  return support::big;
282  else
283  return support::little;
284  }
285 
286  inline uint8_t getNumPaddingBytes(uint64_t SizeInBytes) {
287  return 7 & (sizeof(uint64_t) - SizeInBytes % sizeof(uint64_t));
288  }
289 
290  Error readName(NamedInstrProfRecord &Record);
291  Error readFuncHash(NamedInstrProfRecord &Record);
292  Error readRawCounts(InstrProfRecord &Record);
293  Error readValueProfilingData(InstrProfRecord &Record);
294  bool atEnd() const { return Data == DataEnd; }
295 
296  void advanceData() {
297  Data++;
298  ValueDataStart += CurValueDataSize;
299  }
300 
301  const char *getNextHeaderPos() const {
302  assert(atEnd());
303  return (const char *)ValueDataStart;
304  }
305 
306  /// Get the offset of \p CounterPtr from the start of the counters section of
307  /// the profile. The offset has units of "number of counters", i.e. increasing
308  /// the offset by 1 corresponds to an increase in the *byte offset* by 8.
309  ptrdiff_t getCounterOffset(IntPtrT CounterPtr) const {
310  return (swap(CounterPtr) - CountersDelta) / sizeof(uint64_t);
311  }
312 
313  const uint64_t *getCounter(ptrdiff_t Offset) const {
314  return CountersStart + Offset;
315  }
316 
317  StringRef getName(uint64_t NameRef) const {
318  return Symtab->getFuncName(swap(NameRef));
319  }
320 };
321 
324 
325 namespace IndexedInstrProf {
326 
327 enum class HashT : uint32_t;
328 
329 } // end namespace IndexedInstrProf
330 
331 /// Trait for lookups into the on-disk hash table for the binary instrprof
332 /// format.
334  std::vector<NamedInstrProfRecord> DataBuffer;
336  unsigned FormatVersion;
337  // Endianness of the input value profile data.
338  // It should be LE by default, but can be changed
339  // for testing purpose.
340  support::endianness ValueProfDataEndianness = support::little;
341 
342 public:
344  : HashType(HashType), FormatVersion(FormatVersion) {}
345 
347 
352 
353  static bool EqualKey(StringRef A, StringRef B) { return A == B; }
354  static StringRef GetInternalKey(StringRef K) { return K; }
355  static StringRef GetExternalKey(StringRef K) { return K; }
356 
357  hash_value_type ComputeHash(StringRef K);
358 
359  static std::pair<offset_type, offset_type>
360  ReadKeyDataLength(const unsigned char *&D) {
361  using namespace support;
362 
363  offset_type KeyLen = endian::readNext<offset_type, little, unaligned>(D);
364  offset_type DataLen = endian::readNext<offset_type, little, unaligned>(D);
365  return std::make_pair(KeyLen, DataLen);
366  }
367 
368  StringRef ReadKey(const unsigned char *D, offset_type N) {
369  return StringRef((const char *)D, N);
370  }
371 
372  bool readValueProfilingData(const unsigned char *&D,
373  const unsigned char *const End);
374  data_type ReadData(StringRef K, const unsigned char *D, offset_type N);
375 
376  // Used for testing purpose only.
378  ValueProfDataEndianness = Endianness;
379  }
380 };
381 
383  virtual ~InstrProfReaderIndexBase() = default;
384 
385  // Read all the profile records with the same key pointed to the current
386  // iterator.
387  virtual Error getRecords(ArrayRef<NamedInstrProfRecord> &Data) = 0;
388 
389  // Read all the profile records with the key equal to FuncName
390  virtual Error getRecords(StringRef FuncName,
392  virtual void advanceToNextKey() = 0;
393  virtual bool atEnd() const = 0;
394  virtual void setValueProfDataEndianness(support::endianness Endianness) = 0;
395  virtual uint64_t getVersion() const = 0;
396  virtual bool isIRLevelProfile() const = 0;
397  virtual bool hasCSIRLevelProfile() const = 0;
398  virtual bool instrEntryBBEnabled() const = 0;
399  virtual Error populateSymtab(InstrProfSymtab &) = 0;
400 };
401 
402 using OnDiskHashTableImplV3 =
404 
405 template <typename HashTableImpl>
407 
408 template <typename HashTableImpl>
410 private:
411  std::unique_ptr<HashTableImpl> HashTable;
412  typename HashTableImpl::data_iterator RecordIterator;
413  uint64_t FormatVersion;
414 
415  friend class InstrProfReaderItaniumRemapper<HashTableImpl>;
416 
417 public:
418  InstrProfReaderIndex(const unsigned char *Buckets,
419  const unsigned char *const Payload,
420  const unsigned char *const Base,
422  ~InstrProfReaderIndex() override = default;
423 
424  Error getRecords(ArrayRef<NamedInstrProfRecord> &Data) override;
425  Error getRecords(StringRef FuncName,
427  void advanceToNextKey() override { RecordIterator++; }
428 
429  bool atEnd() const override {
430  return RecordIterator == HashTable->data_end();
431  }
432 
434  HashTable->getInfoObj().setValueProfDataEndianness(Endianness);
435  }
436 
437  uint64_t getVersion() const override { return GET_VERSION(FormatVersion); }
438 
439  bool isIRLevelProfile() const override {
440  return (FormatVersion & VARIANT_MASK_IR_PROF) != 0;
441  }
442 
443  bool hasCSIRLevelProfile() const override {
444  return (FormatVersion & VARIANT_MASK_CSIR_PROF) != 0;
445  }
446 
447  bool instrEntryBBEnabled() const override {
448  return (FormatVersion & VARIANT_MASK_INSTR_ENTRY) != 0;
449  }
450 
452  return Symtab.create(HashTable->keys());
453  }
454 };
455 
456 /// Name matcher supporting fuzzy matching of symbol names to names in profiles.
458 public:
460  virtual Error populateRemappings() { return Error::success(); }
461  virtual Error getRecords(StringRef FuncName,
463 };
464 
465 /// Reader for the indexed binary instrprof format.
467 private:
468  /// The profile data file contents.
469  std::unique_ptr<MemoryBuffer> DataBuffer;
470  /// The profile remapping file contents.
471  std::unique_ptr<MemoryBuffer> RemappingBuffer;
472  /// The index into the profile data.
473  std::unique_ptr<InstrProfReaderIndexBase> Index;
474  /// The profile remapping file contents.
475  std::unique_ptr<InstrProfReaderRemapper> Remapper;
476  /// Profile summary data.
477  std::unique_ptr<ProfileSummary> Summary;
478  /// Context sensitive profile summary data.
479  std::unique_ptr<ProfileSummary> CS_Summary;
480  // Index to the current record in the record array.
481  unsigned RecordIndex;
482 
483  // Read the profile summary. Return a pointer pointing to one byte past the
484  // end of the summary data if it exists or the input \c Cur.
485  // \c UseCS indicates whether to use the context-sensitive profile summary.
486  const unsigned char *readSummary(IndexedInstrProf::ProfVersion Version,
487  const unsigned char *Cur, bool UseCS);
488 
489 public:
491  std::unique_ptr<MemoryBuffer> DataBuffer,
492  std::unique_ptr<MemoryBuffer> RemappingBuffer = nullptr)
493  : DataBuffer(std::move(DataBuffer)),
494  RemappingBuffer(std::move(RemappingBuffer)), RecordIndex(0) {}
496  IndexedInstrProfReader &operator=(const IndexedInstrProfReader &) = delete;
497 
498  /// Return the profile version.
499  uint64_t getVersion() const { return Index->getVersion(); }
500  bool isIRLevelProfile() const override { return Index->isIRLevelProfile(); }
501  bool hasCSIRLevelProfile() const override {
502  return Index->hasCSIRLevelProfile();
503  }
504 
505  bool instrEntryBBEnabled() const override {
506  return Index->instrEntryBBEnabled();
507  }
508 
509  /// Return true if the given buffer is in an indexed instrprof format.
510  static bool hasFormat(const MemoryBuffer &DataBuffer);
511 
512  /// Read the file header.
513  Error readHeader() override;
514  /// Read a single record.
515  Error readNextRecord(NamedInstrProfRecord &Record) override;
516 
517  /// Return the NamedInstrProfRecord associated with FuncName and FuncHash
518  Expected<InstrProfRecord> getInstrProfRecord(StringRef FuncName,
519  uint64_t FuncHash);
520 
521  /// Fill Counts with the profile data for the given function name.
522  Error getFunctionCounts(StringRef FuncName, uint64_t FuncHash,
523  std::vector<uint64_t> &Counts);
524 
525  /// Return the maximum of all known function counts.
526  /// \c UseCS indicates whether to use the context-sensitive count.
528  if (UseCS) {
529  assert(CS_Summary && "No context sensitive profile summary");
530  return CS_Summary->getMaxFunctionCount();
531  } else {
532  assert(Summary && "No profile summary");
533  return Summary->getMaxFunctionCount();
534  }
535  }
536 
537  /// Factory method to create an indexed reader.
539  create(const Twine &Path, const Twine &RemappingPath = "");
540 
542  create(std::unique_ptr<MemoryBuffer> Buffer,
543  std::unique_ptr<MemoryBuffer> RemappingBuffer = nullptr);
544 
545  // Used for testing purpose only.
547  Index->setValueProfDataEndianness(Endianness);
548  }
549 
550  // See description in the base class. This interface is designed
551  // to be used by llvm-profdata (for dumping). Avoid using this when
552  // the client is the compiler.
553  InstrProfSymtab &getSymtab() override;
554 
555  /// Return the profile summary.
556  /// \c UseCS indicates whether to use the context-sensitive summary.
557  ProfileSummary &getSummary(bool UseCS) {
558  if (UseCS) {
559  assert(CS_Summary && "No context sensitive summary");
560  return *(CS_Summary.get());
561  } else {
562  assert(Summary && "No profile summary");
563  return *(Summary.get());
564  }
565  }
566 };
567 
568 } // end namespace llvm
569 
570 #endif // LLVM_PROFILEDATA_INSTRPROFREADER_H
llvm::RawInstrProfReader::RawInstrProfReader
RawInstrProfReader(std::unique_ptr< MemoryBuffer > DataBuffer)
Definition: InstrProfReader.h:240
MemoryBuffer.h
llvm::RawInstrProfReader
Reader for the raw instrprof binary format from runtime.
Definition: InstrProfReader.h:214
llvm::IndexedInstrProfReader::getSummary
ProfileSummary & getSummary(bool UseCS)
Return the profile summary.
Definition: InstrProfReader.h:557
llvm::InstrProfReader::success
Error success()
Clear the current error and return a successful one.
Definition: InstrProfReader.h:135
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::InstrProfReaderIndex::atEnd
bool atEnd() const override
Definition: InstrProfReader.h:429
llvm::TextInstrProfReader::instrEntryBBEnabled
bool instrEntryBBEnabled() const override
Definition: InstrProfReader.h:192
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:968
offset_type
InstrProfLookupTrait::offset_type offset_type
Definition: InstrProfReader.cpp:614
llvm::lltok::Error
@ Error
Definition: LLToken.h:21
llvm::InstrProfReader::InstrProfReader
InstrProfReader()=default
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:258
ProfileSummary.h
StringRef.h
llvm::InstrProfReaderIndex::advanceToNextKey
void advanceToNextKey() override
Definition: InstrProfReader.h:427
llvm::InstrProfReader::readNextRecord
virtual Error readNextRecord(NamedInstrProfRecord &Record)=0
Read a single record.
llvm::IndexedInstrProf::ComputeHash
uint64_t ComputeHash(StringRef K)
Definition: InstrProf.h:999
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:324
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
llvm::InstrProfReader::isEOF
bool isEOF()
Return true if the reader has finished reading the profile data.
Definition: InstrProfReader.h:139
Error.h
SwapByteOrder.h
llvm::InstrProfIterator::InstrProfIterator
InstrProfIterator(InstrProfReader *Reader)
Definition: InstrProfReader.h:57
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::InstrProfLookupTrait::GetInternalKey
static StringRef GetInternalKey(StringRef K)
Definition: InstrProfReader.h:354
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:695
llvm::IndexedInstrProfReader::isIRLevelProfile
bool isIRLevelProfile() const override
Definition: InstrProfReader.h:500
llvm::IndexedInstrProfReader::setValueProfDataEndianness
void setValueProfDataEndianness(support::endianness Endianness)
Definition: InstrProfReader.h:546
llvm::TextInstrProfReader::operator=
TextInstrProfReader & operator=(const TextInstrProfReader &)=delete
llvm::TextInstrProfReader::readHeader
Error readHeader() override
Read the header.
Definition: InstrProfReader.cpp:152
llvm::InstrProfReader::hasError
bool hasError()
Return true if the reader encountered an error reading profiling data.
Definition: InstrProfReader.h:142
llvm::InstrProfLookupTrait
Trait for lookups into the on-disk hash table for the binary instrprof format.
Definition: InstrProfReader.h:333
ptrdiff_t
llvm::TextInstrProfReader::getSymtab
InstrProfSymtab & getSymtab() override
Return the PGO symtab.
Definition: InstrProfReader.h:200
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:377
llvm::InstrProfLookupTrait::EqualKey
static bool EqualKey(StringRef A, StringRef B)
Definition: InstrProfReader.h:353
llvm::InstrProfIterator::operator!=
bool operator!=(const InstrProfIterator &RHS) const
Definition: InstrProfReader.h:63
OnDiskHashTable.h
llvm::InstrProfError::getMessage
const std::string & getMessage() const
Definition: InstrProf.h:325
llvm::InstrProfReader::hasCSIRLevelProfile
virtual bool hasCSIRLevelProfile() const =0
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
InstrProf.h
LineIterator.h
llvm::InstrProfReaderIndex::setValueProfDataEndianness
void setValueProfDataEndianness(support::endianness Endianness) override
Definition: InstrProfReader.h:433
llvm::InstrProfIterator::operator*
value_type & operator*()
Definition: InstrProfReader.h:66
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:190
llvm::IndexedInstrProf::Version
const uint64_t Version
Definition: InstrProf.h:995
llvm::TextInstrProfReader::readNextRecord
Error readNextRecord(NamedInstrProfRecord &Record) override
Read a single record.
Definition: InstrProfReader.cpp:253
llvm::InstrProfLookupTrait::GetExternalKey
static StringRef GetExternalKey(StringRef K)
Definition: InstrProfReader.h:355
llvm::InstrProfReader::Symtab
std::unique_ptr< InstrProfSymtab > Symtab
Definition: InstrProfReader.h:115
llvm::InstrProfReaderRemapper::populateRemappings
virtual Error populateRemappings()
Definition: InstrProfReader.h:460
llvm::sys::getSwappedBytes
unsigned char getSwappedBytes(unsigned char C)
Definition: SwapByteOrder.h:103
llvm::getHostEndianness
support::endianness getHostEndianness()
Definition: InstrProf.h:932
llvm::InstrProfIterator::iterator_category
std::input_iterator_tag iterator_category
Definition: InstrProfReader.h:43
llvm::InstrProfIterator::operator++
InstrProfIterator & operator++()
Definition: InstrProfReader.h:59
llvm::InstrProfReaderIndex::isIRLevelProfile
bool isIRLevelProfile() const override
Definition: InstrProfReader.h:439
llvm::InstrProfReader::~InstrProfReader
virtual ~InstrProfReader()=default
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
uint64_t
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
llvm::IndexedInstrProfReader::getVersion
uint64_t getVersion() const
Return the profile version.
Definition: InstrProfReader.h:499
llvm::IndexedInstrProfReader
Reader for the indexed binary instrprof format.
Definition: InstrProfReader.h:466
llvm::InstrProfError
Definition: InstrProf.h:309
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::InstrProfIterator::difference_type
std::ptrdiff_t difference_type
Definition: InstrProfReader.h:45
llvm::InstrProfReader::error
Error error(Error &&E)
Definition: InstrProfReader.h:126
llvm::InstrProfReaderRemapper::~InstrProfReaderRemapper
virtual ~InstrProfReaderRemapper()
Definition: InstrProfReader.h:459
llvm::TextInstrProfReader
Reader for the simple text based instrprof format.
Definition: InstrProfReader.h:167
llvm::CountSumOrPercent
Definition: InstrProf.h:601
llvm::instrprof_error
instrprof_error
Definition: InstrProf.h:282
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:443
llvm::InstrProfLookupTrait::InstrProfLookupTrait
InstrProfLookupTrait(IndexedInstrProf::HashT HashType, unsigned FormatVersion)
Definition: InstrProfReader.h:343
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:490
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:1639
llvm::RawInstrProfReader::isIRLevelProfile
bool isIRLevelProfile() const override
Definition: InstrProfReader.h:250
llvm::RawInstrProfReader::hasCSIRLevelProfile
bool hasCSIRLevelProfile() const override
Definition: InstrProfReader.h:254
llvm::Record
Definition: Record.h:1486
llvm::InstrProfReader::printBinaryIds
virtual Error printBinaryIds(raw_ostream &OS)
Print binary ids on stream OS.
Definition: InstrProfReader.h:87
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::InstrProfReaderIndex
Definition: InstrProfReader.h:409
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm::IndexedInstrProf::HashT
HashT
Definition: InstrProf.h:953
llvm::RawInstrProfReader::operator=
RawInstrProfReader & operator=(const RawInstrProfReader &)=delete
llvm::InstrProfReader::instrEntryBBEnabled
virtual bool instrEntryBBEnabled() const =0
llvm::InstrProfIterator::operator->
value_type * operator->()
Definition: InstrProfReader.h:67
uint32_t
llvm::instrprof_error::eof
@ eof
llvm::IndexedInstrProfReader::hasCSIRLevelProfile
bool hasCSIRLevelProfile() const override
Definition: InstrProfReader.h:501
llvm::RawInstrProfReader::readHeader
Error readHeader() override
Read the header. Required before reading first record.
Definition: InstrProfReader.cpp:314
llvm::RawInstrProfReader::hasFormat
static bool hasFormat(const MemoryBuffer &DataBuffer)
Definition: InstrProfReader.cpp:304
llvm::InstrProfReaderItaniumRemapper
A remapper that applies remappings based on a symbol remapping file.
Definition: InstrProfReader.h:406
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
std
Definition: BitVector.h:838
llvm::InstrProfSymtab
A symbol table used for function PGO name look-up with keys (such as pointers, md5hash values) to the...
Definition: InstrProf.h:417
llvm::InstrProfReader::accumulateCounts
void accumulateCounts(CountSumOrPercent &Sum, bool IsCS)
Compute the sum of counts and return in Sum.
Definition: InstrProfReader.cpp:1015
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::RawInstrProfReader::getSymtab
InstrProfSymtab & getSymtab() override
Return the PGO symtab.
Definition: InstrProfReader.h:262
llvm::InstrProfReaderIndex::populateSymtab
Error populateSymtab(InstrProfSymtab &Symtab) override
Definition: InstrProfReader.h:451
llvm::InstrProfReaderRemapper
Name matcher supporting fuzzy matching of symbol names to names in profiles.
Definition: InstrProfReader.h:457
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:524
llvm::IndexedInstrProf::HashType
const HashT HashType
Definition: InstrProf.h:997
llvm::InstrProfReaderIndexBase
Definition: InstrProfReader.h:382
llvm::InstrProfReaderIndex::instrEntryBBEnabled
bool instrEntryBBEnabled() const override
Definition: InstrProfReader.h:447
llvm::IndexedInstrProfReader::instrEntryBBEnabled
bool instrEntryBBEnabled() const override
Definition: InstrProfReader.h:505
llvm::InstrProfReader::getError
Error getError()
Get the current error.
Definition: InstrProfReader.h:145
llvm::RawInstrProf::ProfileData
Definition: InstrProf.h:1129
llvm::TextInstrProfReader::TextInstrProfReader
TextInstrProfReader(std::unique_ptr< MemoryBuffer > DataBuffer_)
Definition: InstrProfReader.h:180
llvm::RawInstrProfReader::printBinaryIds
Error printBinaryIds(raw_ostream &OS) override
Print binary ids on stream OS.
Definition: InstrProfReader.cpp:556
llvm::TextInstrProfReader::hasFormat
static bool hasFormat(const MemoryBuffer &Buffer)
Return true if the given buffer is in text instrprof format.
Definition: InstrProfReader.cpp:139
N
#define N
llvm::TextInstrProfReader::isIRLevelProfile
bool isIRLevelProfile() const override
Definition: InstrProfReader.h:188
llvm::InstrProfReader::end
InstrProfIterator end()
Definition: InstrProfReader.h:91
data_type
InstrProfLookupTrait::data_type data_type
Definition: InstrProfReader.cpp:613
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::InstrProfLookupTrait::ReadKey
StringRef ReadKey(const unsigned char *D, offset_type N)
Definition: InstrProfReader.h:368
llvm::support::endianness
endianness
Definition: Endian.h:27
llvm::NamedInstrProfRecord
Definition: InstrProf.h:852
llvm::InstrProfReaderIndex::getVersion
uint64_t getVersion() const override
Definition: InstrProfReader.h:437
llvm::InstrProfLookupTrait::ReadKeyDataLength
static std::pair< offset_type, offset_type > ReadKeyDataLength(const unsigned char *&D)
Definition: InstrProfReader.h:360
llvm::InstrProfIterator
A file format agnostic iterator over profiling data.
Definition: InstrProfReader.h:41
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:527
llvm::RawInstrProf::Header
Definition: InstrProf.h:1138
Endian.h
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1883
llvm::InstrProfReader::create
static Expected< std::unique_ptr< InstrProfReader > > create(const Twine &Path)
Factory method to create an appropriately typed reader for the given instrprof file.
Definition: InstrProfReader.cpp:55
llvm::InstrProfReader::begin
InstrProfIterator begin()
Iterator over profile data.
Definition: InstrProfReader.h:90
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:968
llvm::support::big
@ big
Definition: Endian.h:27
llvm::InstrProfIterator::operator==
bool operator==(const InstrProfIterator &RHS) const
Definition: InstrProfReader.h:60
llvm::InstrProfReader
Base class and interface for reading profiling data of any known instrprof format.
Definition: InstrProfReader.h:72
llvm::sampleprof::Base
@ Base
Definition: Discriminator.h:58
llvm::InstrProfIterator::InstrProfIterator
InstrProfIterator()=default
llvm::InstrProfReader::error
Error error(instrprof_error Err, const std::string &ErrMsg="")
Set the current error and return same.
Definition: InstrProfReader.h:118