14 #ifndef LLVM_PROFILEDATA_INSTRPROFREADER_H 15 #define LLVM_PROFILEDATA_INSTRPROFREADER_H 38 class InstrProfReader;
42 NamedInstrProfRecord> {
69 virtual Error readHeader() = 0;
78 virtual bool isIRLevelProfile()
const = 0;
80 virtual bool hasCSIRLevelProfile()
const = 0;
98 std::unique_ptr<InstrProfSymtab>
Symtab;
105 return make_error<InstrProfError>(Err);
123 return make_error<InstrProfError>(LastError);
132 create(std::unique_ptr<MemoryBuffer> Buffer);
146 std::unique_ptr<MemoryBuffer> DataBuffer;
149 bool IsIRLevelProfile =
false;
150 bool HasCSIRLevelProfile =
false;
156 : DataBuffer(
std::move(DataBuffer_)), Line(*DataBuffer,
true,
'#') {}
168 Error readHeader()
override;
175 return *Symtab.get();
186 template <
class IntPtrT>
190 std::unique_ptr<MemoryBuffer> DataBuffer;
191 bool ShouldSwapBytes;
196 uint64_t CountersDelta;
200 const uint64_t *CountersStart;
201 const char *NamesStart;
205 const uint8_t *ValueDataStart;
211 : DataBuffer(
std::move(DataBuffer)) {}
216 Error readHeader()
override;
220 return (Version & VARIANT_MASK_IR_PROF) != 0;
224 return (Version & VARIANT_MASK_CSIR_PROF) != 0;
229 return *Symtab.get();
234 Error readNextHeader(
const char *CurrentPos);
237 template <
class IntT> IntT
swap(IntT Int)
const {
243 if (!ShouldSwapBytes)
251 inline uint8_t getNumPaddingBytes(uint64_t SizeInBytes) {
252 return 7 & (
sizeof(uint64_t) - SizeInBytes %
sizeof(uint64_t));
259 bool atEnd()
const {
return Data == DataEnd; }
263 ValueDataStart += CurValueDataSize;
266 const char *getNextHeaderPos()
const {
268 return (
const char *)ValueDataStart;
274 ptrdiff_t getCounterOffset(IntPtrT CounterPtr)
const {
275 return (
swap(CounterPtr) - CountersDelta) /
sizeof(uint64_t);
279 return CountersStart +
Offset;
290 namespace IndexedInstrProf {
299 std::vector<NamedInstrProfRecord> DataBuffer;
301 unsigned FormatVersion;
309 : HashType(HashType), FormatVersion(FormatVersion) {}
324 static std::pair<offset_type, offset_type>
326 using namespace support;
328 offset_type KeyLen = endian::readNext<offset_type, little, unaligned>(
D);
329 offset_type DataLen = endian::readNext<offset_type, little, unaligned>(
D);
330 return std::make_pair(KeyLen, DataLen);
337 bool readValueProfilingData(
const unsigned char *&
D,
338 const unsigned char *
const End);
357 virtual void advanceToNextKey() = 0;
358 virtual bool atEnd()
const = 0;
360 virtual uint64_t getVersion()
const = 0;
361 virtual bool isIRLevelProfile()
const = 0;
362 virtual bool hasCSIRLevelProfile()
const = 0;
369 template <
typename HashTableImpl>
372 template <
typename HashTableImpl>
375 std::unique_ptr<HashTableImpl> HashTable;
376 typename HashTableImpl::data_iterator RecordIterator;
377 uint64_t FormatVersion;
383 const unsigned char *
const Payload,
384 const unsigned char *
const Base,
394 return RecordIterator == HashTable->data_end();
398 HashTable->getInfoObj().setValueProfDataEndianness(Endianness);
401 uint64_t
getVersion()
const override {
return GET_VERSION(FormatVersion); }
404 return (FormatVersion & VARIANT_MASK_IR_PROF) != 0;
408 return (FormatVersion & VARIANT_MASK_CSIR_PROF) != 0;
412 return Symtab.
create(HashTable->keys());
429 std::unique_ptr<MemoryBuffer> DataBuffer;
431 std::unique_ptr<MemoryBuffer> RemappingBuffer;
433 std::unique_ptr<InstrProfReaderIndexBase>
Index;
435 std::unique_ptr<InstrProfReaderRemapper> Remapper;
437 std::unique_ptr<ProfileSummary> Summary;
439 std::unique_ptr<ProfileSummary> CS_Summary;
441 unsigned RecordIndex;
447 const unsigned char *Cur,
bool UseCS);
451 std::unique_ptr<MemoryBuffer> DataBuffer,
452 std::unique_ptr<MemoryBuffer> RemappingBuffer =
nullptr)
453 : DataBuffer(
std::move(DataBuffer)),
454 RemappingBuffer(
std::move(RemappingBuffer)), RecordIndex(0) {}
462 return Index->hasCSIRLevelProfile();
469 Error readHeader()
override;
479 std::vector<uint64_t> &Counts);
485 assert(CS_Summary &&
"No context sensitive profile summary");
486 return CS_Summary->getMaxFunctionCount();
488 assert(Summary &&
"No profile summary");
489 return Summary->getMaxFunctionCount();
495 create(
const Twine &Path,
const Twine &RemappingPath =
"");
498 create(std::unique_ptr<MemoryBuffer> Buffer,
499 std::unique_ptr<MemoryBuffer> RemappingBuffer =
nullptr);
503 Index->setValueProfDataEndianness(Endianness);
515 assert(CS_Summary &&
"No context sensitive summary");
516 return *(CS_Summary.get());
518 assert(Summary &&
"No profile summary");
519 return *(Summary.get());
526 #endif // LLVM_PROFILEDATA_INSTRPROFREADER_H A symbol table used for function PGO name look-up with keys (such as pointers, md5hash values) to the...
uint64_t getVersion() const
Return the profile version.
void setValueProfDataEndianness(support::endianness Endianness)
bool isIRLevelProfile() const override
This class represents lattice values for constants.
Defines facilities for reading and writing on-disk hash tables.
static instrprof_error take(Error E)
Consume an Error and return the raw enum value contained within it.
bool hasCSIRLevelProfile() const override
A remapper that applies remappings based on a symbol remapping file.
Error error(instrprof_error Err)
Set the current error and return same.
A forward iterator which reads text lines from a buffer.
constexpr support::endianness Endianness
The endianness of all multi-byte encoded values in MessagePack.
virtual Error populateRemappings()
block Block Frequency true
InstrProfIterator(InstrProfReader *Reader)
virtual ~InstrProfReaderRemapper()
ProfileSummary & getSummary(bool UseCS)
Return the profile summary.
bool operator==(const InstrProfIterator &RHS)
bool isIRLevelProfile() const override
bool operator!=(const InstrProfIterator &RHS)
bool isEOF()
Return true if the reader has finished reading the profile data.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static StringRef getName(Value *V)
Error populateSymtab(InstrProfSymtab &Symtab) override
Tagged union holding either a T or a Error.
void setValueProfDataEndianness(support::endianness Endianness)
bool isIRLevelProfile() const override
StringRef getFuncName(uint64_t FuncNameAddress, size_t NameSize)
Return function's PGO name from the function name's symbol address in the object file.
RawInstrProfReader(std::unique_ptr< MemoryBuffer > DataBuffer)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
static std::pair< offset_type, offset_type > ReadKeyDataLength(const unsigned char *&D)
Reader for the simple text based instrprof format.
bool hasCSIRLevelProfile() const override
StringRef ReadKey(const unsigned char *D, offset_type N)
uint64_t getVersion() const override
InstrProfSymtab & getSymtab() override
Return the PGO symtab.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Base class and interface for reading profiling data of any known instrprof format.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
std::unique_ptr< InstrProfSymtab > Symtab
value_type * operator->()
void advanceToNextKey() override
uint64_t ComputeHash(StringRef K)
bool atEnd() const override
Error create(object::SectionRef &Section)
Create InstrProfSymtab from an object file section which contains function PGO names.
Name matcher supporting fuzzy matching of symbol names to names in profiles.
static ErrorSuccess success()
Create a success value.
Trait for lookups into the on-disk hash table for the binary instrprof format.
uint64_t getMaximumFunctionCount(bool UseCS)
Return the maximum of all known function counts.
A file format agnostic iterator over profiling data.
Reader for the raw instrprof binary format from runtime.
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
This interface provides simple read-only access to a block of memory, and provides simple methods for...
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
bool hasCSIRLevelProfile() const override
unsigned char getSwappedBytes(unsigned char C)
TextInstrProfReader(std::unique_ptr< MemoryBuffer > DataBuffer_)
bool hasCSIRLevelProfile() const override
Profiling information for a single function.
InstrProfIterator begin()
Iterator over profile data.
InstrProfSymtab & getSymtab() override
Return the PGO symtab.
InstrProfIterator & operator++()
bool hasError()
Return true if the reader encountered an error reading profiling data.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static StringRef GetInternalKey(StringRef K)
IndexedInstrProfReader(std::unique_ptr< MemoryBuffer > DataBuffer, std::unique_ptr< MemoryBuffer > RemappingBuffer=nullptr)
InstrProfLookupTrait(IndexedInstrProf::HashT HashType, unsigned FormatVersion)
Error getError()
Get the current error.
static bool EqualKey(StringRef A, StringRef B)
Lightweight error class with error context and mandatory checking.
support::endianness getHostEndianness()
StringRef - Represent a constant reference to a string, i.e.
Reader for the indexed binary instrprof format.
void setValueProfDataEndianness(support::endianness Endianness) override
static StringRef GetExternalKey(StringRef K)
InstrProfIterator()=default
Provides lookup and iteration over an on disk hash table.
bool isIRLevelProfile() const override
Error success()
Clear the current error and return a successful one.