LLVM 17.0.0git
|
SampleProfileReaderExtBinaryBase/SampleProfileWriterExtBinaryBase defines the basic structure of the extensible binary format. More...
#include "llvm/ProfileData/SampleProfReader.h"
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. | |
bool | useMD5 () override |
Return whether names in the profile are all MD5 numbers. | |
std::unique_ptr< ProfileSymbolList > | getProfileSymbolList () override |
void | setSkipFlatProf (bool Skip) override |
Don't read profile without context if the flag is set. | |
![]() | |
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. | |
![]() | |
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 (SampleContext FContext, raw_ostream &OS=dbgs()) |
Print the profile for FContext 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. | |
FunctionSamples * | getSamplesFor (const Function &F) |
Return the samples collected for function F . | |
FunctionSamples * | getOrCreateSamplesFor (const Function &F) |
Return the samples collected for function F , create empty FunctionSamples if it doesn't exist. | |
virtual FunctionSamples * | getSamplesFor (StringRef Fname) |
Return the samples collected for function F . | |
SampleProfileMap & | getProfiles () |
Return all the profiles. | |
void | reportError (int64_t LineNumber, const Twine &Msg) const |
Report a parse error message. | |
ProfileSummary & | getSummary () const |
Return the profile summary. | |
MemoryBuffer * | getBuffer () 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. | |
virtual std::unique_ptr< ProfileSymbolList > | getProfileSymbolList () |
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()) |
virtual bool | useMD5 () |
Return whether names in the profile are all MD5 numbers. | |
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. | |
SampleProfileReaderItaniumRemapper * | getRemapper () |
void | setModule (const Module *Mod) |
Protected Member Functions | |
std::error_code | readSecHdrTableEntry (uint32_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 | readMD5NameTable () |
std::error_code | readNameTableSec (bool IsMD5) |
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 |
ErrorOr< StringRef > | readStringFromTable () override |
Read a string indirectly via the name table. | |
ErrorOr< SampleContext > | readSampleContextFromTable () override |
ErrorOr< SampleContextFrames > | readContextFromTable () |
![]() | |
template<typename T > | |
ErrorOr< T > | readNumber () |
Read a numeric value of type T from the profile. | |
template<typename T > | |
ErrorOr< T > | readUnencodedNumber () |
Read a numeric value of type T from the profile. | |
ErrorOr< StringRef > | readString () |
Read a string from the profile. | |
template<typename T > | |
ErrorOr< uint32_t > | readStringIndex (T &Table) |
Read the string index and check whether it overflows the table. | |
bool | at_eof () const |
Return true if we've reached the end of file. | |
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. | |
virtual std::error_code | readNameTable () |
Read the whole name table. | |
virtual ErrorOr< StringRef > | readStringFromTable () |
Read a string indirectly via the name table. | |
virtual ErrorOr< SampleContext > | readSampleContextFromTable () |
![]() | |
void | computeSummary () |
Compute summary for this profile. | |
Protected Attributes | |
std::vector< SecHdrTableEntry > | SecHdrTable |
std::unique_ptr< ProfileSymbolList > | ProfSymList |
DenseMap< SampleContext, uint64_t > | FuncOffsetTable |
The table mapping from function context to the offset of its FunctionSample towards file start. | |
std::unique_ptr< std::vector< std::pair< SampleContext, uint64_t > > > | OrderedFuncOffsets |
Function offset mapping ordered by contexts. | |
DenseSet< StringRef > | FuncsToUse |
The set containing the functions to use when compiling a module. | |
bool | FixedLengthMD5 = false |
Use fixed length MD5 instead of ULEB128 encoding so NameTable doesn't need to be read in up front and can be directly accessed using index. | |
const uint8_t * | MD5NameMemStart = nullptr |
The starting address of NameTable containing fixed length MD5. | |
std::unique_ptr< std::vector< std::string > > | MD5StringBuf |
If MD5 is used in NameTable section, the section saves uint64_t data. | |
std::unique_ptr< const std::vector< SampleContextFrameVector > > | CSNameTable |
CSNameTable is used to save full context vectors. | |
bool | SkipFlatProf = false |
If SkipFlatProf is true, skip the sections with SecFlagFlat flag. | |
bool | FuncOffsetsOrdered = false |
![]() | |
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< StringRef > | NameTable |
Function name table. | |
![]() | |
SampleProfileMap | Profiles |
Map every function to its associated profile. | |
LLVMContext & | Ctx |
LLVM context used to emit diagnostics. | |
std::unique_ptr< MemoryBuffer > | Buffer |
Memory buffer holding the profile file. | |
std::unordered_set< std::string > | MD5NameBuffer |
Extra name buffer holding names created on demand. | |
std::unique_ptr< ProfileSummary > | Summary |
Profile summary information. | |
std::unique_ptr< SampleProfileReaderItaniumRemapper > | Remapper |
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 Module * | M = 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). | |
Additional Inherited Members | |
![]() | |
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 std::unique_ptr< ProfileSummary > | takeSummary (SampleProfileReader &Reader) |
Take ownership of the summary of this reader. | |
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 696 of file SampleProfReader.h.
|
inline |
Definition at line 769 of file SampleProfReader.h.
|
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 786 of file SampleProfReader.cpp.
References F, FuncsToUse, llvm::sampleprof::FunctionSamples::getCanonicalFnName(), and llvm::sampleprof::SampleProfileReader::M.
Referenced by readFuncProfiles().
|
overridevirtual |
Reimplemented from llvm::sampleprof::SampleProfileReader.
Definition at line 1377 of file SampleProfReader.cpp.
References assert(), getFileSize(), getSecFlagsStr(), llvm::sampleprof::getSecName(), and SecHdrTable.
uint64_t SampleProfileReaderExtBinaryBase::getFileSize | ( | ) |
Get the total size of header and all sections.
Definition at line 1314 of file SampleProfReader.cpp.
References SecHdrTable.
Referenced by dumpSectionInfo().
|
inlineoverridevirtual |
Reimplemented from llvm::sampleprof::SampleProfileReader.
Definition at line 789 of file SampleProfReader.h.
References ProfSymList.
Get the total size of all Type
sections.
Definition at line 1305 of file SampleProfReader.cpp.
References SecHdrTable, and Size.
|
protected |
Definition at line 697 of file SampleProfReader.cpp.
References CSNameTable, and llvm::truncated_name_table.
Referenced by readSampleContextFromTable().
|
protected |
Definition at line 1122 of file SampleProfReader.cpp.
References CSNameTable, I, isOffsetLegal(), readStringFromTable(), Size, and llvm::success.
Referenced by readOneSection().
|
protectedpure virtual |
Referenced by readOneSection().
|
protected |
Definition at line 1218 of file SampleProfReader.cpp.
References assert(), llvm::sampleprof::SampleProfileReaderBinary::Data, llvm::sampleprof::SampleProfileReaderBinary::End, llvm::sampleprof::SampleProfileReader::Profiles, readFuncMetadata(), readSampleContextFromTable(), and llvm::success.
Referenced by readFuncMetadata(), and readOneSection().
|
protected |
Definition at line 1162 of file SampleProfReader.cpp.
References Attributes, llvm::sampleprof::SampleProfileReaderBinary::Data, llvm::sampleprof::SampleProfileReaderBinary::End, llvm::sampleprof::FunctionSamples::functionSamplesAt(), llvm::sampleprof::FunctionSamples::getContext(), llvm::sampleprof::SampleProfileReader::ProfileIsCS, llvm::sampleprof::SampleProfileReader::ProfileIsProbeBased, readFuncMetadata(), readSampleContextFromTable(), llvm::sampleprof::SampleContext::setAllAttributes(), llvm::sampleprof::FunctionSamples::setFunctionHash(), and llvm::success.
|
protected |
Definition at line 795 of file SampleProfReader.cpp.
References FuncOffsetsOrdered, FuncOffsetTable, I, llvm::Offset, OrderedFuncOffsets, readSampleContextFromTable(), Size, and llvm::success.
Referenced by readOneSection().
|
protected |
Definition at line 830 of file SampleProfReader.cpp.
References assert(), collectFuncsFromModule(), llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::count(), llvm::sampleprof::SampleProfileReader::CSProfileCount, llvm::sampleprof::SampleProfileReaderBinary::Data, llvm::sampleprof::SampleProfileReaderBinary::End, FuncOffsetTable, FuncsToUse, llvm::GlobalValue::getGUID(), llvm::sampleprof::SampleContext::getName(), llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::insert(), llvm::sampleprof::SampleContext::IsPrefixOf(), llvm::MD5Hash(), Name, OrderedFuncOffsets, llvm::sampleprof::SampleProfileReader::ProfileIsCS, llvm::sampleprof::SampleProfileReader::Profiles, llvm::sampleprof::SampleProfileReaderBinary::readFuncProfile(), llvm::sampleprof::SampleProfileReader::Remapper, llvm::success, and useMD5().
Referenced by readOneSection().
|
overrideprotectedvirtual |
Read and validate the file header.
Reimplemented from llvm::sampleprof::SampleProfileReaderBinary.
Definition at line 1290 of file SampleProfReader.cpp.
References llvm::sampleprof::SampleProfileReader::Buffer, llvm::sampleprof::SampleProfileReaderBinary::Data, llvm::sampleprof::SampleProfileReaderBinary::End, llvm::sampleprof::SampleProfileReaderBinary::readMagicIdent(), readSecHdrTable(), and llvm::success.
|
overridevirtual |
Read sample profiles in extensible format from the associated file.
Reimplemented from llvm::sampleprof::SampleProfileReaderBinary.
Definition at line 968 of file SampleProfReader.cpp.
References llvm::sampleprof::SampleProfileReader::Buffer, llvm::sampleprof::SampleProfileReaderBinary::Data, llvm::sampleprof::SampleProfileReaderBinary::End, llvm::sampleprof::hasSecFlag(), llvm::malformed, readOneSection(), llvm::sampleprof::SecFlagCompress, llvm::sampleprof::SecFlagFlat, SecHdrTable, SkipFlatProf, and llvm::success.
|
protected |
Definition at line 1082 of file SampleProfReader.cpp.
References llvm::sampleprof::SampleProfileReaderBinary::Data, FixedLengthMD5, I, MD5NameMemStart, MD5StringBuf, llvm::sampleprof::SampleProfileReaderBinary::NameTable, Size, and llvm::success.
Referenced by readNameTableSec().
|
protected |
Definition at line 1112 of file SampleProfReader.cpp.
References readMD5NameTable(), and llvm::sampleprof::SampleProfileReaderBinary::readNameTable().
Referenced by readOneSection().
|
protectedvirtual |
Definition at line 721 of file SampleProfReader.cpp.
References assert(), llvm::sampleprof::SampleProfileReaderBinary::Data, llvm::sampleprof::SampleProfileReaderBinary::End, FixedLengthMD5, FuncOffsetsOrdered, llvm::sampleprof::hasSecFlag(), llvm::sampleprof::FunctionSamples::HasUniqSuffix, llvm::sampleprof::FunctionSamples::ProfileIsCS, llvm::sampleprof::SampleProfileReader::ProfileIsCS, llvm::sampleprof::FunctionSamples::ProfileIsFS, llvm::sampleprof::SampleProfileReader::ProfileIsFS, 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().
|
protected |
Definition at line 930 of file SampleProfReader.cpp.
References llvm::sampleprof::SampleProfileReaderBinary::Data, llvm::sampleprof::SampleProfileReaderBinary::End, ProfSymList, and llvm::success.
Referenced by readOneSection().
|
overrideprotectedvirtual |
Reimplemented from llvm::sampleprof::SampleProfileReaderBinary.
Definition at line 707 of file SampleProfReader.cpp.
References llvm::sampleprof::SampleProfileReader::ProfileIsCS, readContextFromTable(), and readStringFromTable().
Referenced by readFuncMetadata(), and readFuncOffsetTable().
|
protected |
Definition at line 1278 of file SampleProfReader.cpp.
References readSecHdrTableEntry(), and llvm::success.
Referenced by readHeader().
|
protected |
Definition at line 1251 of file SampleProfReader.cpp.
References Idx, llvm::Offset, SecHdrTable, Size, and llvm::success.
Referenced by readSecHdrTable().
|
overrideprotectedvirtual |
Read a string indirectly via the name table.
Reimplemented from llvm::sampleprof::SampleProfileReaderBinary.
Definition at line 542 of file SampleProfReader.cpp.
References llvm::sampleprof::SampleProfileReaderBinary::Data, llvm::StringRef::empty(), FixedLengthMD5, Idx, MD5NameMemStart, MD5StringBuf, llvm::sampleprof::SampleProfileReaderBinary::NameTable, llvm::sampleprof::SampleProfileReaderBinary::readStringFromTable(), and llvm::sampleprof::SampleProfileReaderBinary::readStringIndex().
Referenced by readCSNameTableSec(), and readSampleContextFromTable().
|
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 793 of file SampleProfReader.h.
References SkipFlatProf.
|
inlineoverridevirtual |
Return whether names in the profile are all MD5 numbers.
Reimplemented from llvm::sampleprof::SampleProfileReader.
Definition at line 787 of file SampleProfReader.h.
References MD5StringBuf.
Referenced by readFuncProfiles().
|
overrideprotectedpure virtual |
Implements llvm::sampleprof::SampleProfileReaderBinary.
|
protected |
CSNameTable is used to save full context vectors.
This serves as an underlying immutable buffer for all clients.
Definition at line 760 of file SampleProfReader.h.
Referenced by readContextFromTable(), and readCSNameTableSec().
|
protected |
Use fixed length MD5 instead of ULEB128 encoding so NameTable doesn't need to be read in up front and can be directly accessed using index.
Definition at line 745 of file SampleProfReader.h.
Referenced by readMD5NameTable(), readOneSection(), and readStringFromTable().
|
protected |
Definition at line 766 of file SampleProfReader.h.
Referenced by readFuncOffsetTable(), and readOneSection().
|
protected |
The table mapping from function context to the offset of its FunctionSample towards file start.
Definition at line 734 of file SampleProfReader.h.
Referenced by readFuncOffsetTable(), and readFuncProfiles().
The set containing the functions to use when compiling a module.
Definition at line 741 of file SampleProfReader.h.
Referenced by collectFuncsFromModule(), and readFuncProfiles().
|
protected |
The starting address of NameTable containing fixed length MD5.
Definition at line 747 of file SampleProfReader.h.
Referenced by readMD5NameTable(), and readStringFromTable().
|
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 756 of file SampleProfReader.h.
Referenced by readMD5NameTable(), readStringFromTable(), and useMD5().
|
protected |
Function offset mapping ordered by contexts.
Definition at line 738 of file SampleProfReader.h.
Referenced by readFuncOffsetTable(), and readFuncProfiles().
|
protected |
Definition at line 730 of file SampleProfReader.h.
Referenced by getProfileSymbolList(), and readProfileSymbolList().
|
protected |
Definition at line 706 of file SampleProfReader.h.
Referenced by dumpSectionInfo(), getFileSize(), getSectionSize(), readImpl(), and readSecHdrTableEntry().
|
protected |
If SkipFlatProf is true, skip the sections with SecFlagFlat flag.
Definition at line 764 of file SampleProfReader.h.
Referenced by readImpl(), and setSkipFlatProf().