LLVM  14.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]
Collaboration diagram for llvm::sampleprof::SampleProfileReaderExtBinaryBase:
Collaboration 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. More...
 
uint64_t getSectionSize (SecType Type)
 Get the total size of all Type sections. More...
 
uint64_t getFileSize ()
 Get the total size of header and all sections. More...
 
virtual bool dumpSectionInfo (raw_ostream &OS=dbgs()) override
 
bool collectFuncsFromModule () override
 Collect functions with definitions in Module M. More...
 
virtual bool useMD5 () override
 Return whether names in the profile are all MD5 numbers. More...
 
virtual std::unique_ptr< ProfileSymbolListgetProfileSymbolList () override
 
virtual void setSkipFlatProf (bool Skip) override
 Don't read profile without context if the flag is set. More...
 
- Public Member Functions inherited from llvm::sampleprof::SampleProfileReaderBinary
 SampleProfileReaderBinary (std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_None)
 
virtual std::vector< StringRef > * getNameTable () override
 It includes all the names that have samples either in outline instance or inline instance. More...
 
- Public Member Functions inherited from llvm::sampleprof::SampleProfileReader
 SampleProfileReader (std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_None)
 
virtual ~SampleProfileReader ()=default
 
void setDiscriminatorMaskedBitFrom (FSDiscriminatorPass P)
 Set the bits for FS discriminators. More...
 
uint32_t getDiscriminatorMask () const
 Get the bitmask the discriminators: For FS profiles, return the bit mask for this pass. More...
 
std::error_code read ()
 The interface to read sample profiles from the associated file. More...
 
void dumpFunctionProfile (SampleContext FContext, raw_ostream &OS=dbgs())
 Print the profile for FContext on stream OS. More...
 
void dump (raw_ostream &OS=dbgs())
 Print all the profiles on stream OS. More...
 
FunctionSamplesgetSamplesFor (const Function &F)
 Return the samples collected for function F. More...
 
FunctionSamplesgetOrCreateSamplesFor (const Function &F)
 Return the samples collected for function F, create empty FunctionSamples if it doesn't exist. More...
 
virtual FunctionSamplesgetSamplesFor (StringRef Fname)
 Return the samples collected for function F. More...
 
SampleProfileMapgetProfiles ()
 Return all the profiles. More...
 
void reportError (int64_t LineNumber, const Twine &Msg) const
 Report a parse error message. More...
 
ProfileSummarygetSummary () const
 Return the profile summary. More...
 
MemoryBuffergetBuffer () const
 
SampleProfileFormat getFormat () const
 Return the profile format. More...
 
bool profileIsProbeBased () const
 Whether input profile is based on pseudo probes. More...
 
bool profileIsCS () const
 Whether input profile is fully context-sensitive. More...
 
virtual bool hasUniqSuffix ()
 Return whether any name in the profile contains ".__uniq." suffix. More...
 
SampleProfileReaderItaniumRemappergetRemapper ()
 
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 readFuncOffsetTable ()
 
std::error_code readFuncProfiles ()
 
std::error_code readMD5NameTable ()
 
std::error_code readNameTableSec (bool IsMD5)
 
std::error_code readCSNameTableSec ()
 
std::error_code readProfileSymbolList ()
 
virtual std::error_code readHeader () override
 Read and validate the file header. More...
 
virtual 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
 
virtual ErrorOr< StringRefreadStringFromTable () override
 Read a string indirectly via the name table. More...
 
virtual ErrorOr< SampleContextreadSampleContextFromTable () override
 
ErrorOr< SampleContextFramesreadContextFromTable ()
 
- Protected Member Functions inherited from llvm::sampleprof::SampleProfileReaderBinary
template<typename T >
ErrorOr< TreadNumber ()
 Read a numeric value of type T from the profile. More...
 
template<typename T >
ErrorOr< TreadUnencodedNumber ()
 Read a numeric value of type T from the profile. More...
 
ErrorOr< StringRefreadString ()
 Read a string from the profile. More...
 
template<typename T >
ErrorOr< uint32_treadStringIndex (T &Table)
 Read the string index and check whether it overflows the table. More...
 
bool at_eof () const
 Return true if we've reached the end of file. More...
 
std::error_code readFuncProfile (const uint8_t *Start)
 Read the next function profile instance. More...
 
std::error_code readProfile (FunctionSamples &FProfile)
 Read the contents of the given profile instance. More...
 
std::error_code readMagicIdent ()
 Read the contents of Magic number and Version number. More...
 
std::error_code readSummary ()
 Read profile summary. More...
 
virtual std::error_code readNameTable ()
 Read the whole name table. More...
 
- Protected Member Functions inherited from llvm::sampleprof::SampleProfileReader
void computeSummary ()
 Compute summary for this profile. More...
 

Protected Attributes

std::vector< SecHdrTableEntrySecHdrTable
 
std::unique_ptr< ProfileSymbolListProfSymList
 
DenseMap< SampleContext, uint64_tFuncOffsetTable
 The table mapping from function context to the offset of its FunctionSample towards file start. More...
 
std::unique_ptr< std::vector< std::pair< SampleContext, uint64_t > > > OrderedFuncOffsets
 Function offset mapping ordered by contexts. More...
 
DenseSet< StringRefFuncsToUse
 The set containing the functions to use when compiling a module. More...
 
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. More...
 
const uint8_t * MD5NameMemStart = nullptr
 The starting address of NameTable containing fixed length MD5. More...
 
std::unique_ptr< std::vector< std::string > > MD5StringBuf
 If MD5 is used in NameTable section, the section saves uint64_t data. More...
 
std::unique_ptr< const std::vector< SampleContextFrameVector > > CSNameTable
 CSNameTable is used to save full context vectors. More...
 
bool SkipFlatProf = false
 If SkipFlatProf is true, skip the sections with SecFlagFlat flag. More...
 
bool FuncOffsetsOrdered = false
 
- Protected Attributes inherited from llvm::sampleprof::SampleProfileReaderBinary
const uint8_t * Data = nullptr
 Points to the current location in the buffer. More...
 
const uint8_t * End = nullptr
 Points to the end of the buffer. More...
 
std::vector< StringRefNameTable
 Function name table. More...
 
- Protected Attributes inherited from llvm::sampleprof::SampleProfileReader
SampleProfileMap Profiles
 Map every function to its associated profile. More...
 
LLVMContextCtx
 LLVM context used to emit diagnostics. More...
 
std::unique_ptr< MemoryBufferBuffer
 Memory buffer holding the profile file. More...
 
std::unordered_set< std::string > MD5NameBuffer
 Extra name buffer holding names created on demand. More...
 
std::unique_ptr< ProfileSummarySummary
 Profile summary information. More...
 
std::unique_ptr< SampleProfileReaderItaniumRemapperRemapper
 
bool ProfileIsProbeBased = false
 Whether samples are collected based on pseudo probes. More...
 
bool ProfileIsCS = false
 Whether function profiles are context-sensitive. More...
 
uint32_t CSProfileCount = 0
 Number of context-sensitive profiles. More...
 
bool ProfileIsFS = false
 Whether the function profiles use FS discriminators. More...
 
SampleProfileFormat Format = SPF_None
 The format of sample. More...
 
const ModuleM = nullptr
 The current module being compiled if SampleProfileReader is used by compiler. More...
 
uint32_t MaskedBitFrom = 31
 Zero out the discriminator bits higher than bit MaskedBitFrom (0 based). More...
 

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

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 686 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 757 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 704 of file SampleProfReader.cpp.

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

◆ dumpSectionInfo()

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

Reimplemented from llvm::sampleprof::SampleProfileReader.

Definition at line 1242 of file SampleProfReader.cpp.

◆ getFileSize()

uint64_t SampleProfileReaderExtBinaryBase::getFileSize ( )

Get the total size of header and all sections.

Definition at line 1187 of file SampleProfReader.cpp.

◆ getProfileSymbolList()

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

Reimplemented from llvm::sampleprof::SampleProfileReader.

Definition at line 777 of file SampleProfReader.h.

References move, and ProfSymList.

◆ getSectionSize()

uint64_t SampleProfileReaderExtBinaryBase::getSectionSize ( SecType  Type)

Get the total size of all Type sections.

Definition at line 1178 of file SampleProfReader.cpp.

References llvm::Check::Size.

◆ readContextFromTable()

ErrorOr< SampleContextFrames > SampleProfileReaderExtBinaryBase::readContextFromTable ( )
protected

Definition at line 617 of file SampleProfReader.cpp.

References llvm::truncated_name_table.

◆ readCSNameTableSec()

std::error_code SampleProfileReaderExtBinaryBase::readCSNameTableSec ( )
protected

◆ readCustomSection()

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

◆ readFuncMetadata()

std::error_code SampleProfileReaderExtBinaryBase::readFuncMetadata ( bool  ProfileHasAttribute)
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

Read sample profiles in extensible format from the associated file.

Reimplemented from llvm::sampleprof::SampleProfileReaderBinary.

Definition at line 888 of file SampleProfReader.cpp.

References llvm::sampleprof::SampleProfileReader::Buffer.

◆ readMD5NameTable()

std::error_code SampleProfileReaderExtBinaryBase::readMD5NameTable ( )
protected

◆ readNameTableSec()

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

◆ readOneSection()

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

Definition at line 641 of file SampleProfReader.cpp.

◆ readProfileSymbolList()

std::error_code SampleProfileReaderExtBinaryBase::readProfileSymbolList ( )
protected

◆ readSampleContextFromTable()

ErrorOr< SampleContext > SampleProfileReaderExtBinaryBase::readSampleContextFromTable ( )
overrideprotectedvirtual

◆ readSecHdrTable()

std::error_code SampleProfileReaderExtBinaryBase::readSecHdrTable ( )
protected

Definition at line 1151 of file SampleProfReader.cpp.

References i, and llvm::success.

◆ readSecHdrTableEntry()

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

Definition at line 1124 of file SampleProfReader.cpp.

◆ readStringFromTable()

ErrorOr< StringRef > SampleProfileReaderExtBinaryBase::readStringFromTable ( )
overrideprotectedvirtual

◆ setSkipFlatProf()

virtual 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 781 of file SampleProfReader.h.

References SkipFlatProf.

◆ useMD5()

virtual bool llvm::sampleprof::SampleProfileReaderExtBinaryBase::useMD5 ( )
inlineoverridevirtual

Return whether names in the profile are all MD5 numbers.

Reimplemented from llvm::sampleprof::SampleProfileReader.

Definition at line 775 of file SampleProfReader.h.

References MD5StringBuf.

◆ verifySPMagic()

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

Member Data Documentation

◆ CSNameTable

std::unique_ptr<const std::vector<SampleContextFrameVector> > llvm::sampleprof::SampleProfileReaderExtBinaryBase::CSNameTable
protected

CSNameTable is used to save full context vectors.

This serves as an underlying immutable buffer for all clients.

Definition at line 748 of file SampleProfReader.h.

◆ FixedLengthMD5

bool llvm::sampleprof::SampleProfileReaderExtBinaryBase::FixedLengthMD5 = false
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 733 of file SampleProfReader.h.

◆ FuncOffsetsOrdered

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

Definition at line 754 of file SampleProfReader.h.

◆ FuncOffsetTable

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

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

Definition at line 722 of file SampleProfReader.h.

◆ FuncsToUse

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

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

Definition at line 729 of file SampleProfReader.h.

◆ MD5NameMemStart

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

The starting address of NameTable containing fixed length MD5.

Definition at line 735 of file SampleProfReader.h.

◆ MD5StringBuf

std::unique_ptr<std::vector<std::string> > llvm::sampleprof::SampleProfileReaderExtBinaryBase::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 744 of file SampleProfReader.h.

Referenced by useMD5().

◆ OrderedFuncOffsets

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

Function offset mapping ordered by contexts.

Definition at line 726 of file SampleProfReader.h.

◆ ProfSymList

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

Definition at line 718 of file SampleProfReader.h.

Referenced by getProfileSymbolList().

◆ SecHdrTable

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

Definition at line 696 of file SampleProfReader.h.

◆ SkipFlatProf

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

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

Definition at line 752 of file SampleProfReader.h.

Referenced by setSkipFlatProf().


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