15 #ifndef LLVM_PROFILEDATA_INSTRPROFREADER_H 16 #define LLVM_PROFILEDATA_INSTRPROFREADER_H 39 class InstrProfReader;
43 NamedInstrProfRecord> {
70 virtual Error readHeader() = 0;
79 virtual bool isIRLevelProfile()
const = 0;
94 std::unique_ptr<InstrProfSymtab>
Symtab;
101 return make_error<InstrProfError>(Err);
119 return make_error<InstrProfError>(LastError);
128 create(std::unique_ptr<MemoryBuffer> Buffer);
142 std::unique_ptr<MemoryBuffer> DataBuffer;
145 bool IsIRLevelProfile =
false;
151 : DataBuffer(
std::move(DataBuffer_)), Line(*DataBuffer,
true,
'#') {}
161 Error readHeader()
override;
168 return *Symtab.get();
179 template <
class IntPtrT>
183 std::unique_ptr<MemoryBuffer> DataBuffer;
184 bool ShouldSwapBytes;
189 uint64_t CountersDelta;
193 const uint64_t *CountersStart;
194 const char *NamesStart;
198 const uint8_t *ValueDataStart;
204 : DataBuffer(
std::move(DataBuffer)) {}
209 Error readHeader()
override;
213 return (Version & VARIANT_MASK_IR_PROF) != 0;
218 return *Symtab.get();
223 Error readNextHeader(
const char *CurrentPos);
226 template <
class IntT> IntT
swap(IntT Int)
const {
232 if (!ShouldSwapBytes)
240 inline uint8_t getNumPaddingBytes(uint64_t SizeInBytes) {
241 return 7 & (
sizeof(uint64_t) - SizeInBytes %
sizeof(uint64_t));
248 bool atEnd()
const {
return Data == DataEnd; }
252 ValueDataStart += CurValueDataSize;
255 const char *getNextHeaderPos()
const {
257 return (
const char *)ValueDataStart;
260 const uint64_t *getCounter(IntPtrT CounterPtr)
const {
262 return CountersStart +
Offset;
273 namespace IndexedInstrProf {
282 std::vector<NamedInstrProfRecord> DataBuffer;
284 unsigned FormatVersion;
292 : HashType(HashType), FormatVersion(FormatVersion) {}
307 static std::pair<offset_type, offset_type>
309 using namespace support;
311 offset_type KeyLen = endian::readNext<offset_type, little, unaligned>(
D);
312 offset_type DataLen = endian::readNext<offset_type, little, unaligned>(
D);
313 return std::make_pair(KeyLen, DataLen);
320 bool readValueProfilingData(
const unsigned char *&
D,
321 const unsigned char *
const End);
340 virtual void advanceToNextKey() = 0;
341 virtual bool atEnd()
const = 0;
343 virtual uint64_t getVersion()
const = 0;
344 virtual bool isIRLevelProfile()
const = 0;
351 template <
typename HashTableImpl>
354 template <
typename HashTableImpl>
357 std::unique_ptr<HashTableImpl> HashTable;
358 typename HashTableImpl::data_iterator RecordIterator;
359 uint64_t FormatVersion;
365 const unsigned char *
const Payload,
366 const unsigned char *
const Base,
376 return RecordIterator == HashTable->data_end();
380 HashTable->getInfoObj().setValueProfDataEndianness(Endianness);
383 uint64_t
getVersion()
const override {
return GET_VERSION(FormatVersion); }
386 return (FormatVersion & VARIANT_MASK_IR_PROF) != 0;
390 return Symtab.
create(HashTable->keys());
407 std::unique_ptr<MemoryBuffer> DataBuffer;
409 std::unique_ptr<MemoryBuffer> RemappingBuffer;
411 std::unique_ptr<InstrProfReaderIndexBase>
Index;
413 std::unique_ptr<InstrProfReaderRemapper> Remapper;
415 std::unique_ptr<ProfileSummary> Summary;
417 unsigned RecordIndex;
422 const unsigned char *Cur);
426 std::unique_ptr<MemoryBuffer> DataBuffer,
427 std::unique_ptr<MemoryBuffer> RemappingBuffer =
nullptr)
428 : DataBuffer(
std::move(DataBuffer)),
429 RemappingBuffer(
std::move(RemappingBuffer)), RecordIndex(0) {}
441 Error readHeader()
override;
451 std::vector<uint64_t> &Counts);
458 create(
const Twine &Path,
const Twine &RemappingPath =
"");
461 create(std::unique_ptr<MemoryBuffer> Buffer,
462 std::unique_ptr<MemoryBuffer> RemappingBuffer =
nullptr);
466 Index->setValueProfDataEndianness(Endianness);
478 #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.
A remapper that applies remappings based on a symbol remapping file.
Error error(instrprof_error Err)
Set the current error and return same.
uint64_t getMaximumFunctionCount()
Return the maximum of all known function counts.
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()
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.
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.
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.
unsigned char getSwappedBytes(unsigned char C)
TextInstrProfReader(std::unique_ptr< MemoryBuffer > DataBuffer_)
Profiling information for a single function.
InstrProfIterator begin()
Iterator over profile data.
InstrProfSymtab & getSymtab() override
Return the PGO symtab.
ProfileSummary & getSummary()
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.