LLVM 18.0.0git
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
llvm::sampleprof::SampleProfileReaderBinary Class Referenceabstract

#include "llvm/ProfileData/SampleProfReader.h"

Inheritance diagram for llvm::sampleprof::SampleProfileReaderBinary:
Inheritance graph
[legend]

Public Member Functions

 SampleProfileReaderBinary (std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_None)
 
std::error_code readHeader () override
 Read and validate the file header.
 
std::error_code readImpl () override
 Read sample profiles from the associated file.
 
std::vector< StringRef > * getNameTable () override
 It includes all the names that have samples either in outline instance or inline instance.
 
- Public Member Functions inherited from llvm::sampleprof::SampleProfileReader
 SampleProfileReader (std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_None)
 
virtual ~SampleProfileReader ()=default
 
virtual std::error_code readHeader ()=0
 Read and validate the file header.
 
void setDiscriminatorMaskedBitFrom (FSDiscriminatorPass P)
 Set the bits for FS discriminators.
 
uint32_t getDiscriminatorMask () const
 Get the bitmask the discriminators: For FS profiles, return the bit mask for this pass.
 
std::error_code read ()
 The interface to read sample profiles from the associated file.
 
virtual std::error_code readImpl ()=0
 The implementaion to read sample profiles from the associated file.
 
void dumpFunctionProfile (const FunctionSamples &FS, raw_ostream &OS=dbgs())
 Print the profile for FunctionSamples on stream OS.
 
virtual bool collectFuncsFromModule ()
 Collect functions with definitions in Module M.
 
void dump (raw_ostream &OS=dbgs())
 Print all the profiles on stream OS.
 
void dumpJson (raw_ostream &OS=dbgs())
 Print all the profiles on stream OS in the JSON format.
 
FunctionSamplesgetSamplesFor (const Function &F)
 Return the samples collected for function F.
 
FunctionSamplesgetSamplesFor (StringRef Fname)
 Return the samples collected for function F.
 
SampleProfileMapgetProfiles ()
 Return all the profiles.
 
void reportError (int64_t LineNumber, const Twine &Msg) const
 Report a parse error message.
 
ProfileSummarygetSummary () const
 Return the profile summary.
 
MemoryBuffergetBuffer () const
 
SampleProfileFormat getFormat () const
 Return the profile format.
 
bool profileIsProbeBased () const
 Whether input profile is based on pseudo probes.
 
bool profileIsCS () const
 Whether input profile is fully context-sensitive.
 
bool profileIsPreInlined () const
 Whether input profile contains ShouldBeInlined contexts.
 
bool profileIsFS () const
 Whether input profile is flow-sensitive.
 
virtual std::unique_ptr< ProfileSymbolListgetProfileSymbolList ()
 
virtual std::vector< StringRef > * getNameTable ()
 It includes all the names that have samples either in outline instance or inline instance.
 
virtual bool dumpSectionInfo (raw_ostream &OS=dbgs())
 
bool useMD5 () const
 Return whether names in the profile are all MD5 numbers.
 
virtual void setProfileUseMD5 ()
 Force the profile to use MD5 in Sample contexts, even if function names are present.
 
virtual void setSkipFlatProf (bool Skip)
 Don't read profile without context if the flag is set.
 
virtual bool hasUniqSuffix ()
 Return whether any name in the profile contains ".__uniq." suffix.
 
SampleProfileReaderItaniumRemappergetRemapper ()
 
void setModule (const Module *Mod)
 

Protected Member Functions

template<typename T >
ErrorOr< TreadNumber ()
 Read a numeric value of type T from the profile.
 
template<typename T >
ErrorOr< TreadUnencodedNumber ()
 Read a numeric value of type T from the profile.
 
ErrorOr< StringRefreadString ()
 Read a string from the profile.
 
template<typename T >
ErrorOr< size_t > readStringIndex (T &Table)
 Read the string index and check whether it overflows the table.
 
std::error_code readFuncProfile (const uint8_t *Start)
 Read the next function profile instance.
 
std::error_code readProfile (FunctionSamples &FProfile)
 Read the contents of the given profile instance.
 
std::error_code readMagicIdent ()
 Read the contents of Magic number and Version number.
 
std::error_code readSummary ()
 Read profile summary.
 
std::error_code readNameTable ()
 Read the whole name table.
 
ErrorOr< StringRefreadStringFromTable (size_t *RetIdx=nullptr)
 Read a string indirectly via the name table. Optionally return the index.
 
ErrorOr< SampleContextFramesreadContextFromTable (size_t *RetIdx=nullptr)
 Read a context indirectly via the CSNameTable.
 
ErrorOr< std::pair< SampleContext, uint64_t > > readSampleContextFromTable ()
 Read a context indirectly via the CSNameTable if the profile has context, otherwise same as readStringFromTable, also return its hash value.
 
- Protected Member Functions inherited from llvm::sampleprof::SampleProfileReader
void computeSummary ()
 Compute summary for this profile.
 

Protected Attributes

const uint8_t * Data = nullptr
 Points to the current location in the buffer.
 
const uint8_t * End = nullptr
 Points to the end of the buffer.
 
std::vector< StringRefNameTable
 Function name table.
 
std::vector< std::string > MD5StringBuf
 If MD5 is used in NameTable section, the section saves uint64_t data.
 
const uint8_t * MD5NameMemStart = nullptr
 The starting address of fixed length MD5 name table section.
 
std::vector< SampleContextFrameVectorCSNameTable
 CSNameTable is used to save full context vectors.
 
std::vector< uint64_tMD5SampleContextTable
 Table to cache MD5 values of sample contexts corresponding to readSampleContextFromTable(), used to index into Profiles or FuncOffsetTable.
 
const uint64_tMD5SampleContextStart = nullptr
 The starting address of the table of MD5 values of sample contexts.
 
- Protected Attributes inherited from llvm::sampleprof::SampleProfileReader
SampleProfileMap Profiles
 Map every function to its associated profile.
 
LLVMContextCtx
 LLVM context used to emit diagnostics.
 
std::unique_ptr< MemoryBufferBuffer
 Memory buffer holding the profile file.
 
std::unordered_set< std::string > MD5NameBuffer
 Extra name buffer holding names created on demand.
 
std::unique_ptr< ProfileSummarySummary
 Profile summary information.
 
std::unique_ptr< SampleProfileReaderItaniumRemapperRemapper
 
bool ProfileIsProbeBased = false
 Whether samples are collected based on pseudo probes.
 
bool ProfileIsCS = false
 Whether function profiles are context-sensitive flat profiles.
 
bool ProfileIsPreInlined = false
 Whether function profile contains ShouldBeInlined contexts.
 
uint32_t CSProfileCount = 0
 Number of context-sensitive profiles.
 
bool ProfileIsFS = false
 Whether the function profiles use FS discriminators.
 
SampleProfileFormat Format = SPF_None
 The format of sample.
 
const ModuleM = nullptr
 The current module being compiled if SampleProfileReader is used by compiler.
 
uint32_t MaskedBitFrom = 31
 Zero out the discriminator bits higher than bit MaskedBitFrom (0 based).
 
bool ProfileIsMD5 = false
 Whether the profile uses MD5 for Sample Contexts and function names.
 

Additional Inherited Members

- Static Public Member Functions inherited from llvm::sampleprof::SampleProfileReader
static ErrorOr< std::unique_ptr< SampleProfileReader > > create (const std::string Filename, LLVMContext &C, vfs::FileSystem &FS, FSDiscriminatorPass P=FSDiscriminatorPass::Base, const std::string RemapFilename="")
 Create a sample profile reader appropriate to the file format.
 
static ErrorOr< std::unique_ptr< SampleProfileReader > > create (std::unique_ptr< MemoryBuffer > &B, LLVMContext &C, vfs::FileSystem &FS, FSDiscriminatorPass P=FSDiscriminatorPass::Base, const std::string RemapFilename="")
 Create a sample profile reader from the supplied memory buffer.
 
- Static Protected Member Functions inherited from llvm::sampleprof::SampleProfileReader
static std::unique_ptr< ProfileSummarytakeSummary (SampleProfileReader &Reader)
 Take ownership of the summary of this reader.
 

Detailed Description

Definition at line 584 of file SampleProfReader.h.

Constructor & Destructor Documentation

◆ SampleProfileReaderBinary()

llvm::sampleprof::SampleProfileReaderBinary::SampleProfileReaderBinary ( std::unique_ptr< MemoryBuffer B,
LLVMContext C,
SampleProfileFormat  Format = SPF_None 
)
inline

Definition at line 586 of file SampleProfReader.h.

Member Function Documentation

◆ getNameTable()

std::vector< StringRef > * llvm::sampleprof::SampleProfileReaderBinary::getNameTable ( )
inlineoverridevirtual

It includes all the names that have samples either in outline instance or inline instance.

Reimplemented from llvm::sampleprof::SampleProfileReader.

Definition at line 598 of file SampleProfReader.h.

References NameTable.

◆ readContextFromTable()

ErrorOr< SampleContextFrames > SampleProfileReaderBinary::readContextFromTable ( size_t *  RetIdx = nullptr)
protected

Read a context indirectly via the CSNameTable.

Optionally return the index.

Definition at line 551 of file SampleProfReader.cpp.

References CSNameTable, and llvm::truncated_name_table.

Referenced by readSampleContextFromTable().

◆ readFuncProfile()

std::error_code SampleProfileReaderBinary::readFuncProfile ( const uint8_t *  Start)
protected

◆ readHeader()

std::error_code SampleProfileReaderBinary::readHeader ( )
overridevirtual

◆ readImpl()

std::error_code SampleProfileReaderBinary::readImpl ( )
overridevirtual

◆ readMagicIdent()

std::error_code SampleProfileReaderBinary::readMagicIdent ( )
protected

Read the contents of Magic number and Version number.

Definition at line 1431 of file SampleProfReader.cpp.

References llvm::sampleprof::SPVersion(), llvm::success, and llvm::unsupported_version.

Referenced by readHeader(), and llvm::sampleprof::SampleProfileReaderExtBinaryBase::readHeader().

◆ readNameTable()

std::error_code SampleProfileReaderBinary::readNameTable ( )
protected

◆ readNumber()

template<typename T >
ErrorOr< T > SampleProfileReaderBinary::readNumber
protected

Read a numeric value of type T from the profile.

If an error occurs during decoding, a diagnostic message is emitted and EC is set.

Returns
the read value.

Definition at line 466 of file SampleProfReader.cpp.

References Data, llvm::decodeULEB128(), End, llvm::malformed, llvm::sampleprof::SampleProfileReader::reportError(), llvm::success, and llvm::truncated.

◆ readProfile()

std::error_code SampleProfileReaderBinary::readProfile ( FunctionSamples FProfile)
protected

◆ readSampleContextFromTable()

ErrorOr< std::pair< SampleContext, uint64_t > > SampleProfileReaderBinary::readSampleContextFromTable ( )
protected

◆ readString()

ErrorOr< StringRef > SampleProfileReaderBinary::readString ( )
protected

Read a string from the profile.

If an error occurs during decoding, a diagnostic message is emitted and EC is set.

Returns
the read value.

Definition at line 487 of file SampleProfReader.cpp.

References Data, End, llvm::sampleprof::SampleProfileReader::reportError(), and llvm::truncated.

Referenced by readNameTable().

◆ readStringFromTable()

ErrorOr< StringRef > SampleProfileReaderBinary::readStringFromTable ( size_t *  RetIdx = nullptr)
protected

Read a string indirectly via the name table. Optionally return the index.

Definition at line 527 of file SampleProfReader.cpp.

References assert(), llvm::StringRef::data(), Idx, MD5NameMemStart, MD5StringBuf, NameTable, and readStringIndex().

Referenced by llvm::sampleprof::SampleProfileReaderExtBinaryBase::readCSNameTableSec(), readProfile(), and readSampleContextFromTable().

◆ readStringIndex()

template<typename T >
ErrorOr< size_t > SampleProfileReaderBinary::readStringIndex ( T Table)
inlineprotected

Read the string index and check whether it overflows the table.

Definition at line 516 of file SampleProfReader.cpp.

References Idx, and llvm::truncated_name_table.

Referenced by readStringFromTable().

◆ readSummary()

std::error_code SampleProfileReaderBinary::readSummary ( )
protected

◆ readUnencodedNumber()

template<typename T >
ErrorOr< T > SampleProfileReaderBinary::readUnencodedNumber
protected

Read a numeric value of type T from the profile.

The value is saved without encoded.

Definition at line 501 of file SampleProfReader.cpp.

References Data, End, llvm::sampleprof::SampleProfileReader::reportError(), and llvm::truncated.

Member Data Documentation

◆ CSNameTable

std::vector<SampleContextFrameVector> llvm::sampleprof::SampleProfileReaderBinary::CSNameTable
protected

CSNameTable is used to save full context vectors.

It is the backing buffer for SampleContextFrames.

Definition at line 673 of file SampleProfReader.h.

Referenced by readContextFromTable(), and llvm::sampleprof::SampleProfileReaderExtBinaryBase::readCSNameTableSec().

◆ Data

const uint8_t* llvm::sampleprof::SampleProfileReaderBinary::Data = nullptr
protected

◆ End

const uint8_t* llvm::sampleprof::SampleProfileReaderBinary::End = nullptr
protected

◆ MD5NameMemStart

const uint8_t* llvm::sampleprof::SampleProfileReaderBinary::MD5NameMemStart = nullptr
protected

The starting address of fixed length MD5 name table section.

Definition at line 669 of file SampleProfReader.h.

Referenced by llvm::sampleprof::SampleProfileReaderExtBinaryBase::readNameTableSec(), and readStringFromTable().

◆ MD5SampleContextStart

const uint64_t* llvm::sampleprof::SampleProfileReaderBinary::MD5SampleContextStart = nullptr
protected

The starting address of the table of MD5 values of sample contexts.

For fixed length MD5 non-CS profile it is same as MD5NameMemStart because hashes of non-CS contexts are already in the profile. Otherwise it points to the start of MD5SampleContextTable.

Definition at line 684 of file SampleProfReader.h.

Referenced by llvm::sampleprof::SampleProfileReaderExtBinaryBase::readCSNameTableSec(), readNameTable(), llvm::sampleprof::SampleProfileReaderExtBinaryBase::readNameTableSec(), and readSampleContextFromTable().

◆ MD5SampleContextTable

std::vector<uint64_t> llvm::sampleprof::SampleProfileReaderBinary::MD5SampleContextTable
protected

Table to cache MD5 values of sample contexts corresponding to readSampleContextFromTable(), used to index into Profiles or FuncOffsetTable.

Definition at line 678 of file SampleProfReader.h.

Referenced by llvm::sampleprof::SampleProfileReaderExtBinaryBase::readCSNameTableSec(), readNameTable(), llvm::sampleprof::SampleProfileReaderExtBinaryBase::readNameTableSec(), and readSampleContextFromTable().

◆ MD5StringBuf

std::vector<std::string> llvm::sampleprof::SampleProfileReaderBinary::MD5StringBuf
protected

If MD5 is used in NameTable section, the section saves uint64_t data.

The uint64_t data has to be converted to a string and then the string will be used to initialize StringRef in NameTable. Note NameTable contains StringRef so it needs another buffer to own the string data. MD5StringBuf serves as the string buffer that is referenced by NameTable (vector of StringRef). We make sure the lifetime of MD5StringBuf is not shorter than that of NameTable.

Definition at line 666 of file SampleProfReader.h.

Referenced by readNameTable(), llvm::sampleprof::SampleProfileReaderExtBinaryBase::readNameTableSec(), and readStringFromTable().

◆ NameTable

std::vector<StringRef> llvm::sampleprof::SampleProfileReaderBinary::NameTable
protected

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