LLVM 19.0.0git
Public Member Functions | Static Public Member Functions | List of all members
llvm::IndexedInstrProfReader Class Reference

Reader for the indexed binary instrprof format. More...

#include "llvm/ProfileData/InstrProfReader.h"

Inheritance diagram for llvm::IndexedInstrProfReader:
Inheritance graph
[legend]

Public Member Functions

 IndexedInstrProfReader (std::unique_ptr< MemoryBuffer > DataBuffer, std::unique_ptr< MemoryBuffer > RemappingBuffer=nullptr)
 
 IndexedInstrProfReader (const IndexedInstrProfReader &)=delete
 
IndexedInstrProfReaderoperator= (const IndexedInstrProfReader &)=delete
 
uint64_t getVersion () const override
 Return the profile version.
 
bool isIRLevelProfile () const override
 
bool hasCSIRLevelProfile () const override
 
bool instrEntryBBEnabled () const override
 
bool hasSingleByteCoverage () const override
 Return true if the profile has single byte counters representing coverage.
 
bool functionEntryOnly () const override
 Return true if the profile only instruments function entries.
 
bool hasMemoryProfile () const override
 Return true if profile includes a memory profile.
 
bool hasTemporalProfile () const override
 Return true if this has a temporal profile.
 
InstrProfKind getProfileKind () const override
 Returns a BitsetEnum describing the attributes of the indexed instr profile.
 
Error readHeader () override
 Read the file header.
 
Error readNextRecord (NamedInstrProfRecord &Record) override
 Read a single record.
 
Expected< InstrProfRecordgetInstrProfRecord (StringRef FuncName, uint64_t FuncHash, StringRef DeprecatedFuncName="", uint64_t *MismatchedFuncSum=nullptr)
 Return the NamedInstrProfRecord associated with FuncName and FuncHash.
 
Expected< memprof::MemProfRecordgetMemProfRecord (uint64_t FuncNameHash)
 Return the memprof record for the function identified by llvm::md5(Name).
 
Error getFunctionCounts (StringRef FuncName, uint64_t FuncHash, std::vector< uint64_t > &Counts)
 Fill Counts with the profile data for the given function name.
 
Error getFunctionBitmap (StringRef FuncName, uint64_t FuncHash, BitVector &Bitmap)
 Fill Bitmap with the profile data for the given function name.
 
uint64_t getMaximumFunctionCount (bool UseCS)
 Return the maximum of all known function counts.
 
void setValueProfDataEndianness (llvm::endianness Endianness)
 
InstrProfSymtabgetSymtab () override
 Return the PGO symtab.
 
ProfileSummarygetSummary (bool UseCS)
 Return the profile summary.
 
Error readBinaryIds (std::vector< llvm::object::BuildID > &BinaryIds) override
 Read a list of binary ids.
 
Error printBinaryIds (raw_ostream &OS) override
 Print binary ids.
 
- Public Member Functions inherited from llvm::InstrProfReader
 InstrProfReader ()=default
 
virtual ~InstrProfReader ()=default
 
virtual Error readHeader ()=0
 Read the header. Required before reading first record.
 
virtual Error readNextRecord (NamedInstrProfRecord &Record)=0
 Read a single record.
 
virtual Error readBinaryIds (std::vector< llvm::object::BuildID > &BinaryIds)
 Read a list of binary ids.
 
virtual Error printBinaryIds (raw_ostream &OS)
 Print binary ids.
 
InstrProfIterator begin ()
 Iterator over profile data.
 
InstrProfIterator end ()
 
virtual uint64_t getVersion () const =0
 Return the profile version.
 
virtual bool isIRLevelProfile () const =0
 
virtual bool hasCSIRLevelProfile () const =0
 
virtual bool instrEntryBBEnabled () const =0
 
virtual bool hasSingleByteCoverage () const =0
 Return true if the profile has single byte counters representing coverage.
 
virtual bool functionEntryOnly () const =0
 Return true if the profile only instruments function entries.
 
virtual bool hasMemoryProfile () const =0
 Return true if profile includes a memory profile.
 
virtual bool hasTemporalProfile () const =0
 Return true if this has a temporal profile.
 
virtual InstrProfKind getProfileKind () const =0
 Returns a BitsetEnum describing the attributes of the profile.
 
virtual InstrProfSymtabgetSymtab ()=0
 Return the PGO symtab.
 
void accumulateCounts (CountSumOrPercent &Sum, bool IsCS)
 Compute the sum of counts and return in Sum.
 
bool isEOF ()
 Return true if the reader has finished reading the profile data.
 
bool hasError ()
 Return true if the reader encountered an error reading profiling data.
 
Error getError ()
 Get the current error.
 
virtual SmallVector< TemporalProfTraceTy > & getTemporalProfTraces (std::optional< uint64_t > Weight={})
 
uint64_t getTemporalProfTraceStreamSize ()
 

Static Public Member Functions

static bool hasFormat (const MemoryBuffer &DataBuffer)
 Return true if the given buffer is in an indexed instrprof format.
 
static Expected< std::unique_ptr< IndexedInstrProfReader > > create (const Twine &Path, vfs::FileSystem &FS, const Twine &RemappingPath="")
 Factory method to create an indexed reader.
 
static Expected< std::unique_ptr< IndexedInstrProfReader > > create (std::unique_ptr< MemoryBuffer > Buffer, std::unique_ptr< MemoryBuffer > RemappingBuffer=nullptr)
 
- Static Public Member Functions inherited from llvm::InstrProfReader
static Expected< std::unique_ptr< InstrProfReader > > create (const Twine &Path, vfs::FileSystem &FS, const InstrProfCorrelator *Correlator=nullptr, std::function< void(Error)> Warn=nullptr)
 Factory method to create an appropriately typed reader for the given instrprof file.
 
static Expected< std::unique_ptr< InstrProfReader > > create (std::unique_ptr< MemoryBuffer > Buffer, const InstrProfCorrelator *Correlator=nullptr, std::function< void(Error)> Warn=nullptr)
 

Additional Inherited Members

- Protected Member Functions inherited from llvm::InstrProfReader
Error error (instrprof_error Err, const std::string &ErrMsg="")
 Set the current error and return same.
 
Error error (Error &&E)
 
Error success ()
 Clear the current error and return a successful one.
 
- Protected Attributes inherited from llvm::InstrProfReader
std::unique_ptr< InstrProfSymtabSymtab
 
SmallVector< TemporalProfTraceTyTemporalProfTraces
 A list of temporal profile traces.
 
uint64_t TemporalProfTraceStreamSize = 0
 The total number of temporal profile traces seen.
 

Detailed Description

Reader for the indexed binary instrprof format.

Definition at line 643 of file InstrProfReader.h.

Constructor & Destructor Documentation

◆ IndexedInstrProfReader() [1/2]

llvm::IndexedInstrProfReader::IndexedInstrProfReader ( std::unique_ptr< MemoryBuffer DataBuffer,
std::unique_ptr< MemoryBuffer RemappingBuffer = nullptr 
)
inline

Definition at line 687 of file InstrProfReader.h.

◆ IndexedInstrProfReader() [2/2]

llvm::IndexedInstrProfReader::IndexedInstrProfReader ( const IndexedInstrProfReader )
delete

Member Function Documentation

◆ create() [1/2]

Expected< std::unique_ptr< IndexedInstrProfReader > > IndexedInstrProfReader::create ( const Twine Path,
vfs::FileSystem FS,
const Twine RemappingPath = "" 
)
static

Factory method to create an indexed reader.

Definition at line 196 of file InstrProfReader.cpp.

References create(), E, setupMemoryBuffer(), and llvm::Twine::str().

Referenced by annotateAllFunctions(), create(), llvm::coverage::CoverageMapping::load(), and llvm::MemProfUsePass::run().

◆ create() [2/2]

Expected< std::unique_ptr< IndexedInstrProfReader > > IndexedInstrProfReader::create ( std::unique_ptr< MemoryBuffer Buffer,
std::unique_ptr< MemoryBuffer RemappingBuffer = nullptr 
)
static

Definition at line 218 of file InstrProfReader.cpp.

References llvm::bad_magic, E, hasFormat(), and initializeReader().

◆ functionEntryOnly()

bool llvm::IndexedInstrProfReader::functionEntryOnly ( ) const
inlineoverridevirtual

Return true if the profile only instruments function entries.

Implements llvm::InstrProfReader.

Definition at line 710 of file InstrProfReader.h.

◆ getFunctionBitmap()

Error IndexedInstrProfReader::getFunctionBitmap ( StringRef  FuncName,
uint64_t  FuncHash,
BitVector Bitmap 
)

◆ getFunctionCounts()

Error IndexedInstrProfReader::getFunctionCounts ( StringRef  FuncName,
uint64_t  FuncHash,
std::vector< uint64_t > &  Counts 
)

Fill Counts with the profile data for the given function name.

Definition at line 1467 of file InstrProfReader.cpp.

References E, error, getInstrProfRecord(), and llvm::InstrProfReader::success().

◆ getInstrProfRecord()

Expected< InstrProfRecord > IndexedInstrProfReader::getInstrProfRecord ( StringRef  FuncName,
uint64_t  FuncHash,
StringRef  DeprecatedFuncName = "",
uint64_t MismatchedFuncSum = nullptr 
)

Return the NamedInstrProfRecord associated with FuncName and FuncHash.

When return a hash_mismatch error and MismatchedFuncSum is not nullptr, the sum of all counters in the mismatched function will be set to MismatchedFuncSum. If there are multiple instances of mismatched functions, MismatchedFuncSum returns the maximum. If FuncName is not found, try to lookup DeprecatedFuncName to handle profiles built by older compilers.

Definition at line 1372 of file InstrProfReader.cpp.

References llvm::Data, error, llvm::handleErrors(), llvm::NamedInstrProfRecord::hasCSFlagInHash(), llvm::hash_mismatch, I, if(), llvm::Error::success(), and llvm::unknown_function.

Referenced by getFunctionBitmap(), and getFunctionCounts().

◆ getMaximumFunctionCount()

uint64_t llvm::IndexedInstrProfReader::getMaximumFunctionCount ( bool  UseCS)
inline

Return the maximum of all known function counts.

UseCS indicates whether to use the context-sensitive count.

Definition at line 758 of file InstrProfReader.h.

References assert().

◆ getMemProfRecord()

Expected< memprof::MemProfRecord > IndexedInstrProfReader::getMemProfRecord ( uint64_t  FuncNameHash)

Return the memprof record for the function identified by llvm::md5(Name).

Definition at line 1431 of file InstrProfReader.cpp.

References llvm::hash_mismatch, llvm::invalid_prof, and llvm::unknown_function.

◆ getProfileKind()

InstrProfKind llvm::IndexedInstrProfReader::getProfileKind ( ) const
inlineoverridevirtual

Returns a BitsetEnum describing the attributes of the indexed instr profile.

Implements llvm::InstrProfReader.

Definition at line 720 of file InstrProfReader.h.

◆ getSummary()

ProfileSummary & llvm::IndexedInstrProfReader::getSummary ( bool  UseCS)
inline

Return the profile summary.

UseCS indicates whether to use the context-sensitive summary.

Definition at line 789 of file InstrProfReader.h.

References assert().

◆ getSymtab()

InstrProfSymtab & IndexedInstrProfReader::getSymtab ( )
overridevirtual

Return the PGO symtab.

There are three different readers: Raw, Text, and Indexed profile readers. The first two types of readers are used only by llvm-profdata tool, while the indexed profile reader is also used by llvm-cov tool and the compiler ( backend or frontend). Since creating PGO symtab can create significant runtime and memory overhead (as it touches data for the whole program), InstrProfSymtab for the indexed profile reader should be created on demand and it is recommended to be only used for dumping purpose with llvm-proftool, not with the compiler.

Implements llvm::InstrProfReader.

Definition at line 1358 of file InstrProfReader.cpp.

References llvm::consumeError(), E, error, llvm::InstrProfReader::Symtab, and llvm::InstrProfError::take().

◆ getVersion()

uint64_t llvm::IndexedInstrProfReader::getVersion ( ) const
inlineoverridevirtual

Return the profile version.

Implements llvm::InstrProfReader.

Definition at line 696 of file InstrProfReader.h.

◆ hasCSIRLevelProfile()

bool llvm::IndexedInstrProfReader::hasCSIRLevelProfile ( ) const
inlineoverridevirtual

Implements llvm::InstrProfReader.

Definition at line 698 of file InstrProfReader.h.

◆ hasFormat()

bool IndexedInstrProfReader::hasFormat ( const MemoryBuffer DataBuffer)
static

Return true if the given buffer is in an indexed instrprof format.

Definition at line 1124 of file InstrProfReader.cpp.

References llvm::MemoryBuffer::getBufferSize(), llvm::MemoryBuffer::getBufferStart(), and llvm::IndexedInstrProf::Magic.

Referenced by llvm::InstrProfReader::create(), and create().

◆ hasMemoryProfile()

bool llvm::IndexedInstrProfReader::hasMemoryProfile ( ) const
inlineoverridevirtual

Return true if profile includes a memory profile.

Implements llvm::InstrProfReader.

Definition at line 712 of file InstrProfReader.h.

◆ hasSingleByteCoverage()

bool llvm::IndexedInstrProfReader::hasSingleByteCoverage ( ) const
inlineoverridevirtual

Return true if the profile has single byte counters representing coverage.

Implements llvm::InstrProfReader.

Definition at line 706 of file InstrProfReader.h.

◆ hasTemporalProfile()

bool llvm::IndexedInstrProfReader::hasTemporalProfile ( ) const
inlineoverridevirtual

Return true if this has a temporal profile.

Implements llvm::InstrProfReader.

Definition at line 714 of file InstrProfReader.h.

◆ instrEntryBBEnabled()

bool llvm::IndexedInstrProfReader::instrEntryBBEnabled ( ) const
inlineoverridevirtual

Implements llvm::InstrProfReader.

Definition at line 702 of file InstrProfReader.h.

◆ isIRLevelProfile()

bool llvm::IndexedInstrProfReader::isIRLevelProfile ( ) const
inlineoverridevirtual

Implements llvm::InstrProfReader.

Definition at line 697 of file InstrProfReader.h.

◆ operator=()

IndexedInstrProfReader & llvm::IndexedInstrProfReader::operator= ( const IndexedInstrProfReader )
delete

◆ printBinaryIds()

Error IndexedInstrProfReader::printBinaryIds ( raw_ostream OS)
overridevirtual

Print binary ids.

Reimplemented from llvm::InstrProfReader.

Definition at line 1526 of file InstrProfReader.cpp.

References E, OS, printBinaryIdsInternal(), readBinaryIds(), and llvm::Error::success().

◆ readBinaryIds()

Error IndexedInstrProfReader::readBinaryIds ( std::vector< llvm::object::BuildID > &  BinaryIds)
overridevirtual

Read a list of binary ids.

Reimplemented from llvm::InstrProfReader.

Definition at line 1520 of file InstrProfReader.cpp.

References llvm::little, and readBinaryIdsInternal().

Referenced by llvm::coverage::CoverageMapping::load(), and printBinaryIds().

◆ readHeader()

Error IndexedInstrProfReader::readHeader ( )
overridevirtual

◆ readNextRecord()

Error IndexedInstrProfReader::readNextRecord ( NamedInstrProfRecord Record)
overridevirtual

Read a single record.

Implements llvm::InstrProfReader.

Definition at line 1505 of file InstrProfReader.cpp.

References llvm::Data, E, error, and llvm::InstrProfReader::success().

◆ setValueProfDataEndianness()

void llvm::IndexedInstrProfReader::setValueProfDataEndianness ( llvm::endianness  Endianness)
inline

Definition at line 778 of file InstrProfReader.h.


The documentation for this class was generated from the following files: