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

SampleProfileReaderExtBinaryBase/SampleProfileWriterExtBinaryBase defines the basic structure of the extensible binary format. More...

#include "llvm/ProfileData/SampleProfReader.h"

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

Public Member Functions

 SampleProfileReaderExtBinaryBase (std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format)
 
std::error_code readImpl () override
 Read sample profiles in extensible format from the associated file.
 
uint64_t getSectionSize (SecType Type)
 Get the total size of all Type sections.
 
uint64_t getFileSize ()
 Get the total size of header and all sections.
 
bool dumpSectionInfo (raw_ostream &OS=dbgs()) override
 
bool collectFuncsFromModule () override
 Collect functions with definitions in Module M.
 
std::unique_ptr< ProfileSymbolListgetProfileSymbolList () override
 
void setSkipFlatProf (bool Skip) override
 Don't read profile without context if the flag is set.
 
- Public Member Functions inherited from llvm::sampleprof::SampleProfileReaderBinary
 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< FunctionId > * 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< FunctionId > * 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

std::error_code readSecHdrTableEntry (uint64_t Idx)
 
std::error_code readSecHdrTable ()
 
std::error_code readFuncMetadata (bool ProfileHasAttribute)
 
std::error_code readFuncMetadata (bool ProfileHasAttribute, FunctionSamples *FProfile)
 
std::error_code readFuncOffsetTable ()
 
std::error_code readFuncProfiles ()
 
std::error_code readNameTableSec (bool IsMD5, bool FixedLengthMD5)
 
std::error_code readCSNameTableSec ()
 
std::error_code readProfileSymbolList ()
 
std::error_code readHeader () override
 Read and validate the file header.
 
std::error_code verifySPMagic (uint64_t Magic) override=0
 
virtual std::error_code readOneSection (const uint8_t *Start, uint64_t Size, const SecHdrTableEntry &Entry)
 
virtual std::error_code readCustomSection (const SecHdrTableEntry &Entry)=0
 
bool useFuncOffsetList () const
 Determine which container readFuncOffsetTable() should populate, the list FuncOffsetList or the map FuncOffsetTable.
 
- Protected Member Functions inherited from llvm::sampleprof::SampleProfileReaderBinary
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< FunctionIdreadStringFromTable (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

std::vector< SecHdrTableEntrySecHdrTable
 
std::unique_ptr< ProfileSymbolListProfSymList
 
DenseMap< hash_code, uint64_tFuncOffsetTable
 The table mapping from a function context's MD5 to the offset of its FunctionSample towards file start.
 
std::vector< std::pair< SampleContext, uint64_t > > FuncOffsetList
 The list version of FuncOffsetTable.
 
DenseSet< StringRefFuncsToUse
 The set containing the functions to use when compiling a module.
 
bool SkipFlatProf = false
 If SkipFlatProf is true, skip the sections with SecFlagFlat flag.
 
- Protected Attributes inherited from llvm::sampleprof::SampleProfileReaderBinary
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< FunctionIdNameTable
 Function name table.
 
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::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

SampleProfileReaderExtBinaryBase/SampleProfileWriterExtBinaryBase defines the basic structure of the extensible binary format.

The format is organized in sections except the magic and version number at the beginning. There is a section table before all the sections, and each entry in the table describes the entry type, start, size and attributes. The format in each section is defined by the section itself.

It is easy to add a new section while maintaining the backward compatibility of the profile. Nothing extra needs to be done. If we want to extend an existing section, like add cache misses information in addition to the sample count in the profile body, we can add a new section with the extension and retire the existing section, and we could choose to keep the parser of the old section if we want the reader to be able to read both new and old format profile.

SampleProfileReaderExtBinary/SampleProfileWriterExtBinary define the commonly used sections of a profile in extensible binary format. It is possible to define other types of profile inherited from SampleProfileReaderExtBinaryBase/SampleProfileWriterExtBinaryBase.

Definition at line 709 of file SampleProfReader.h.

Constructor & Destructor Documentation

◆ SampleProfileReaderExtBinaryBase()

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

Definition at line 762 of file SampleProfReader.h.

Member Function Documentation

◆ collectFuncsFromModule()

bool SampleProfileReaderExtBinaryBase::collectFuncsFromModule ( )
overridevirtual

Collect functions with definitions in Module M.

Return true if the reader has been given a module.

Reimplemented from llvm::sampleprof::SampleProfileReader.

Definition at line 794 of file SampleProfReader.cpp.

References F, FuncsToUse, llvm::sampleprof::FunctionSamples::getCanonicalFnName(), and llvm::sampleprof::SampleProfileReader::M.

Referenced by readFuncProfiles().

◆ dumpSectionInfo()

bool SampleProfileReaderExtBinaryBase::dumpSectionInfo ( raw_ostream OS = dbgs())
overridevirtual

◆ getFileSize()

uint64_t SampleProfileReaderExtBinaryBase::getFileSize ( )

Get the total size of header and all sections.

Definition at line 1331 of file SampleProfReader.cpp.

References SecHdrTable.

Referenced by dumpSectionInfo().

◆ getProfileSymbolList()

std::unique_ptr< ProfileSymbolList > llvm::sampleprof::SampleProfileReaderExtBinaryBase::getProfileSymbolList ( )
inlineoverridevirtual

Reimplemented from llvm::sampleprof::SampleProfileReader.

Definition at line 779 of file SampleProfReader.h.

References ProfSymList.

◆ getSectionSize()

uint64_t SampleProfileReaderExtBinaryBase::getSectionSize ( SecType  Type)

Get the total size of all Type sections.

Definition at line 1322 of file SampleProfReader.cpp.

References SecHdrTable, and Size.

◆ readCSNameTableSec()

std::error_code SampleProfileReaderExtBinaryBase::readCSNameTableSec ( )
protected

◆ readCustomSection()

virtual std::error_code llvm::sampleprof::SampleProfileReaderExtBinaryBase::readCustomSection ( const SecHdrTableEntry Entry)
protectedpure virtual

Referenced by readOneSection().

◆ readFuncMetadata() [1/2]

std::error_code SampleProfileReaderExtBinaryBase::readFuncMetadata ( bool  ProfileHasAttribute)
protected

◆ readFuncMetadata() [2/2]

std::error_code SampleProfileReaderExtBinaryBase::readFuncMetadata ( bool  ProfileHasAttribute,
FunctionSamples FProfile 
)
protected

◆ readFuncOffsetTable()

std::error_code SampleProfileReaderExtBinaryBase::readFuncOffsetTable ( )
protected

◆ readFuncProfiles()

std::error_code SampleProfileReaderExtBinaryBase::readFuncProfiles ( )
protected

◆ readHeader()

std::error_code SampleProfileReaderExtBinaryBase::readHeader ( )
overrideprotectedvirtual

◆ readImpl()

std::error_code SampleProfileReaderExtBinaryBase::readImpl ( )
overridevirtual

◆ readNameTableSec()

std::error_code SampleProfileReaderExtBinaryBase::readNameTableSec ( bool  IsMD5,
bool  FixedLengthMD5 
)
protected

◆ readOneSection()

std::error_code SampleProfileReaderExtBinaryBase::readOneSection ( const uint8_t *  Start,
uint64_t  Size,
const SecHdrTableEntry Entry 
)
protectedvirtual

Definition at line 691 of file SampleProfReader.cpp.

References assert(), llvm::sampleprof::SampleProfileReaderBinary::Data, llvm::sampleprof::SampleProfileReaderBinary::End, llvm::sampleprof::hasSecFlag(), llvm::sampleprof::FunctionSamples::HasUniqSuffix, llvm::sampleprof::SampleProfileReader::M, llvm::sampleprof::FunctionSamples::ProfileIsCS, llvm::sampleprof::SampleProfileReader::ProfileIsCS, llvm::sampleprof::FunctionSamples::ProfileIsFS, llvm::sampleprof::SampleProfileReader::ProfileIsFS, llvm::sampleprof::SampleProfileReader::ProfileIsMD5, llvm::sampleprof::FunctionSamples::ProfileIsPreInlined, llvm::sampleprof::SampleProfileReader::ProfileIsPreInlined, llvm::sampleprof::FunctionSamples::ProfileIsProbeBased, llvm::sampleprof::SampleProfileReader::ProfileIsProbeBased, readCSNameTableSec(), readCustomSection(), readFuncMetadata(), readFuncOffsetTable(), readFuncProfiles(), readNameTableSec(), readProfileSymbolList(), llvm::sampleprof::SampleProfileReaderBinary::readSummary(), llvm::sampleprof::SecCSNameTable, llvm::sampleprof::SecFlagFixedLengthMD5, llvm::sampleprof::SecFlagFSDiscriminator, llvm::sampleprof::SecFlagFullContext, llvm::sampleprof::SecFlagHasAttribute, llvm::sampleprof::SecFlagIsPreInlined, llvm::sampleprof::SecFlagIsProbeBased, llvm::sampleprof::SecFlagMD5Name, llvm::sampleprof::SecFlagOrdered, llvm::sampleprof::SecFlagPartial, llvm::sampleprof::SecFlagUniqSuffix, llvm::sampleprof::SecFuncMetadata, llvm::sampleprof::SecFuncOffsetTable, llvm::sampleprof::SecLBRProfile, llvm::sampleprof::SecNameTable, llvm::sampleprof::SecProfileSymbolList, llvm::sampleprof::SecProfSummary, Size, llvm::success, and llvm::sampleprof::SampleProfileReader::Summary.

Referenced by readImpl().

◆ readProfileSymbolList()

std::error_code SampleProfileReaderExtBinaryBase::readProfileSymbolList ( )
protected

◆ readSecHdrTable()

std::error_code SampleProfileReaderExtBinaryBase::readSecHdrTable ( )
protected

Definition at line 1295 of file SampleProfReader.cpp.

References readSecHdrTableEntry(), and llvm::success.

Referenced by readHeader().

◆ readSecHdrTableEntry()

std::error_code SampleProfileReaderExtBinaryBase::readSecHdrTableEntry ( uint64_t  Idx)
protected

Definition at line 1268 of file SampleProfReader.cpp.

References Idx, llvm::Offset, SecHdrTable, Size, and llvm::success.

Referenced by readSecHdrTable().

◆ setSkipFlatProf()

void llvm::sampleprof::SampleProfileReaderExtBinaryBase::setSkipFlatProf ( bool  Skip)
inlineoverridevirtual

Don't read profile without context if the flag is set.

This is only meaningful for ExtBinary format.

Reimplemented from llvm::sampleprof::SampleProfileReader.

Definition at line 783 of file SampleProfReader.h.

References SkipFlatProf.

◆ useFuncOffsetList()

bool SampleProfileReaderExtBinaryBase::useFuncOffsetList ( ) const
protected

Determine which container readFuncOffsetTable() should populate, the list FuncOffsetList or the map FuncOffsetTable.

Definition at line 765 of file SampleProfReader.cpp.

References llvm::sampleprof::SampleProfileReader::ProfileIsCS, llvm::sampleprof::SampleProfileReader::Remapper, and llvm::sampleprof::SampleProfileReader::useMD5().

Referenced by readFuncOffsetTable(), and readFuncProfiles().

◆ verifySPMagic()

std::error_code llvm::sampleprof::SampleProfileReaderExtBinaryBase::verifySPMagic ( uint64_t  Magic)
overrideprotectedpure virtual

Member Data Documentation

◆ FuncOffsetList

std::vector<std::pair<SampleContext, uint64_t> > llvm::sampleprof::SampleProfileReaderExtBinaryBase::FuncOffsetList
protected

The list version of FuncOffsetTable.

This is used if every entry is being accessed.

Definition at line 752 of file SampleProfReader.h.

Referenced by readFuncOffsetTable(), and readFuncProfiles().

◆ FuncOffsetTable

DenseMap<hash_code, uint64_t> llvm::sampleprof::SampleProfileReaderExtBinaryBase::FuncOffsetTable
protected

The table mapping from a function context's MD5 to the offset of its FunctionSample towards file start.

At most one of FuncOffsetTable and FuncOffsetList is populated.

Definition at line 748 of file SampleProfReader.h.

Referenced by readFuncOffsetTable(), and readFuncProfiles().

◆ FuncsToUse

DenseSet<StringRef> llvm::sampleprof::SampleProfileReaderExtBinaryBase::FuncsToUse
protected

The set containing the functions to use when compiling a module.

Definition at line 755 of file SampleProfReader.h.

Referenced by collectFuncsFromModule(), and readFuncProfiles().

◆ ProfSymList

std::unique_ptr<ProfileSymbolList> llvm::sampleprof::SampleProfileReaderExtBinaryBase::ProfSymList
protected

Definition at line 743 of file SampleProfReader.h.

Referenced by getProfileSymbolList(), and readProfileSymbolList().

◆ SecHdrTable

std::vector<SecHdrTableEntry> llvm::sampleprof::SampleProfileReaderExtBinaryBase::SecHdrTable
protected

◆ SkipFlatProf

bool llvm::sampleprof::SampleProfileReaderExtBinaryBase::SkipFlatProf = false
protected

If SkipFlatProf is true, skip the sections with SecFlagFlat flag.

Definition at line 759 of file SampleProfReader.h.

Referenced by readImpl(), and setSkipFlatProf().


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