LLVM: llvm::sampleprof::SampleProfileReader Class Reference (original) (raw)

Sample-based profile reader. More...

#include "[llvm/ProfileData/SampleProfReader.h](SampleProfReader%5F8h%5Fsource.html)"

Public Member Functions
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.
std::error_code read (const DenseSet< StringRef > &FuncsToUse)
Read sample profiles for the given functions.
virtual std::error_code readImpl ()=0
The implementaion to read sample profiles from the associated file.
LLVM_ABI 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.
LLVM_ABI void dump (raw_ostream &OS=dbgs())
Print all the profiles on stream OS.
LLVM_ABI 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 * 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.
bool profileIsFS () const
Whether input profile is flow-sensitive.
virtual std::unique_ptr< ProfileSymbolList > getProfileSymbolList ()
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.
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)
void setFuncNameToProfNameMap (const HashKeyMap< std::unordered_map, FunctionId, FunctionId > &FPMap)
Protected Member Functions
LLVM_ABI void computeSummary ()
Compute summary for this profile.
virtual std::error_code read (const DenseSet< StringRef > &FuncsToUse, SampleProfileMap &Profiles)
Read sample profiles for the given functions and write them to the given profile map.
Protected Attributes
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::unique_ptr< ProfileSummary > Summary
Profile summary information.
std::unique_ptr< SampleProfileReaderItaniumRemapper > Remapper
const HashKeyMap< std::unordered_map, FunctionId, FunctionId > * FuncNameToProfNameMap = nullptr
std::unordered_map< uint64_t, std::pair< const uint8_t *, const uint8_t * > > FuncMetadataIndex
std::pair< const uint8_t *, const uint8_t * > ProfileSecRange
bool ProfileHasAttribute = false
Whether the profile has attribute metadata.
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.
bool ReadVTableProf = false
If true, the profile has vtable profiles and reader should decode them to parse profiles correctly.
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).
bool ProfileIsMD5 = false
Whether the profile uses MD5 for Sample Contexts and function names.
bool SkipFlatProf = false
If SkipFlatProf is true, skip functions marked with !Flat in text mode or sections with SecFlagFlat flag in ExtBinary mode.

Sample-based profile reader.

Each profile contains sample counts for all the functions executed. Inside each function, statements are annotated with the collected samples on all the instructions associated with that statement.

For this to produce meaningful data, the program needs to be compiled with some debug information (at minimum, line numbers: -gline-tables-only). Otherwise, it will be impossible to match IR instructions to the line numbers collected by the profiler.

From the profile file, we are interested in collecting the following information:

The reader supports two file formats: text and binary. The text format is useful for debugging and testing, while the binary format is more compact and I/O efficient. They can both be used interchangeably.

Definition at line 346 of file SampleProfReader.h.

Definition at line 348 of file SampleProfReader.h.

References B(), Buffer, llvm::CallingConv::C, Ctx, Format, llvm::move(), Profiles, and llvm::sampleprof::SPF_None.

Referenced by llvm::sampleprof::SampleProfileReaderBinary::SampleProfileReaderBinary(), llvm::sampleprof::SampleProfileReaderGCC::SampleProfileReaderGCC(), llvm::sampleprof::SampleProfileReaderText::SampleProfileReaderText(), and takeSummary().

~SampleProfileReader()

virtual llvm::sampleprof::SampleProfileReader::~SampleProfileReader ( ) virtualdefault

collectFuncsFromModule()

virtual bool llvm::sampleprof::SampleProfileReader::collectFuncsFromModule ( ) inlinevirtual

computeSummary()

void SampleProfileReader::computeSummary ( ) protected

create() [1/2]

create() [2/2]

dump()

dumpFunctionProfile()

Print the profile for [FunctionSamples](classllvm%5F1%5F1sampleprof%5F1%5F1FunctionSamples.html "Representation of the samples collected for a function.") on stream OS.

Dump the function profile for FName.

Parameters

FContext Name + context of the function to print.
OS Stream to emit the output to.

Definition at line 64 of file SampleProfReader.cpp.

Referenced by dump().

dumpJson()

dumpSectionInfo()

virtual bool llvm::sampleprof::SampleProfileReader::dumpSectionInfo ( raw_ostream & OS = dbgs()) inlinevirtual

getBuffer()

MemoryBuffer * llvm::sampleprof::SampleProfileReader::getBuffer ( ) const inline

getDiscriminatorMask()

uint32_t llvm::sampleprof::SampleProfileReader::getDiscriminatorMask ( ) const inline

getFormat()

getNameTable()

virtual std::vector< FunctionId > * llvm::sampleprof::SampleProfileReader::getNameTable ( ) inlinevirtual

getProfiles()

SampleProfileMap & llvm::sampleprof::SampleProfileReader::getProfiles ( ) inline

getProfileSymbolList()

virtual std::unique_ptr< ProfileSymbolList > llvm::sampleprof::SampleProfileReader::getProfileSymbolList ( ) inlinevirtual

getRemapper()

getSamplesFor() [1/2]

getSamplesFor() [2/2]

getSummary()

ProfileSummary & llvm::sampleprof::SampleProfileReader::getSummary ( ) const inline

hasUniqSuffix()

virtual bool llvm::sampleprof::SampleProfileReader::hasUniqSuffix ( ) inlinevirtual

Return whether any name in the profile contains ".__uniq." suffix.

Definition at line 513 of file SampleProfReader.h.

profileIsCS()

bool llvm::sampleprof::SampleProfileReader::profileIsCS ( ) const inline

profileIsFS()

bool llvm::sampleprof::SampleProfileReader::profileIsFS ( ) const inline

profileIsPreInlined()

bool llvm::sampleprof::SampleProfileReader::profileIsPreInlined ( ) const inline

profileIsProbeBased()

bool llvm::sampleprof::SampleProfileReader::profileIsProbeBased ( ) const inline

read() [1/3]

std::error_code llvm::sampleprof::SampleProfileReader::read ( ) inline

read() [2/3]

std::error_code llvm::sampleprof::SampleProfileReader::read ( const DenseSet< StringRef > & FuncsToUse) inline

read() [3/3]

Read sample profiles for the given functions and write them to the given profile map.

Currently it's only used for extended binary format to load the profiles on-demand.

Definition at line 553 of file SampleProfReader.h.

References llvm::not_implemented, and Profiles.

readHeader()

virtual std::error_code llvm::sampleprof::SampleProfileReader::readHeader ( ) pure virtual

readImpl()

virtual std::error_code llvm::sampleprof::SampleProfileReader::readImpl ( ) pure virtual

reportError()

void llvm::sampleprof::SampleProfileReader::reportError ( int64_t LineNumber, const Twine & Msg ) const inline

setDiscriminatorMaskedBitFrom()

void llvm::sampleprof::SampleProfileReader::setDiscriminatorMaskedBitFrom ( FSDiscriminatorPass P) inline

setFuncNameToProfNameMap()

setModule()

void llvm::sampleprof::SampleProfileReader::setModule ( const Module * Mod) inline

setProfileUseMD5()

virtual void llvm::sampleprof::SampleProfileReader::setProfileUseMD5 ( ) inlinevirtual

setSkipFlatProf()

void llvm::sampleprof::SampleProfileReader::setSkipFlatProf ( bool Skip) inline

takeSummary()

useMD5()

bool llvm::sampleprof::SampleProfileReader::useMD5 ( ) const inline

Buffer

std::unique_ptr<MemoryBuffer> llvm::sampleprof::SampleProfileReader::Buffer protected

Memory buffer holding the profile file.

Definition at line 536 of file SampleProfReader.h.

Referenced by getBuffer(), llvm::sampleprof::SampleProfileReaderExtBinary::hasFormat(), llvm::sampleprof::SampleProfileReaderGCC::hasFormat(), llvm::sampleprof::SampleProfileReaderRawBinary::hasFormat(), llvm::sampleprof::SampleProfileReaderText::hasFormat(), llvm::sampleprof::SampleProfileReaderBinary::readHeader(), llvm::sampleprof::SampleProfileReaderExtBinaryBase::readHeader(), llvm::sampleprof::SampleProfileReaderExtBinaryBase::readImpl(), llvm::sampleprof::SampleProfileReaderText::readImpl(), llvm::sampleprof::SampleProfileReaderBinary::readVTableTypeCountMap(), reportError(), SampleProfileReader(), and llvm::sampleprof::SampleProfileReaderGCC::SampleProfileReaderGCC().

CSProfileCount

uint32_t llvm::sampleprof::SampleProfileReader::CSProfileCount = 0 protected

Ctx

LLVMContext& llvm::sampleprof::SampleProfileReader::Ctx protected

Format

FuncMetadataIndex

FuncNameToProfNameMap

M

const Module* llvm::sampleprof::SampleProfileReader::M = nullptr protected

MaskedBitFrom

uint32_t llvm::sampleprof::SampleProfileReader::MaskedBitFrom = 31 protected

ProfileHasAttribute

bool llvm::sampleprof::SampleProfileReader::ProfileHasAttribute = false protected

ProfileIsCS

bool llvm::sampleprof::SampleProfileReader::ProfileIsCS = false protected

Whether function profiles are context-sensitive flat profiles.

Definition at line 580 of file SampleProfReader.h.

Referenced by profileIsCS(), llvm::sampleprof::SampleProfileReaderExtBinaryBase::readCSNameTableSec(), llvm::sampleprof::SampleProfileReaderExtBinaryBase::readFuncMetadata(), llvm::sampleprof::SampleProfileReaderExtBinaryBase::readFuncProfiles(), llvm::sampleprof::SampleProfileReaderExtBinaryBase::readFuncProfiles(), llvm::sampleprof::SampleProfileReaderText::readImpl(), llvm::sampleprof::SampleProfileReaderBinary::readNameTable(), llvm::sampleprof::SampleProfileReaderExtBinaryBase::readNameTableSec(), llvm::sampleprof::SampleProfileReaderExtBinaryBase::readOneSection(), llvm::sampleprof::SampleProfileReaderBinary::readSampleContextFromTable(), and llvm::sampleprof::SampleProfileReaderExtBinaryBase::useFuncOffsetList().

ProfileIsFS

bool llvm::sampleprof::SampleProfileReader::ProfileIsFS = false protected

ProfileIsMD5

bool llvm::sampleprof::SampleProfileReader::ProfileIsMD5 = false protected

ProfileIsPreInlined

bool llvm::sampleprof::SampleProfileReader::ProfileIsPreInlined = false protected

ProfileIsProbeBased

bool llvm::sampleprof::SampleProfileReader::ProfileIsProbeBased = false protected

Profiles

Map every function to its associated profile.

The profile of every function executed at runtime is collected in the structure FunctionSamples. This maps function objects to their corresponding profiles.

Definition at line 530 of file SampleProfReader.h.

Referenced by computeSummary(), dump(), dumpJson(), getProfiles(), getSamplesFor(), read(), read(), llvm::sampleprof::SampleProfileReaderExtBinaryBase::readFuncMetadata(), llvm::sampleprof::SampleProfileReaderExtBinaryBase::readFuncMetadata(), llvm::sampleprof::SampleProfileReaderBinary::readFuncProfile(), llvm::sampleprof::SampleProfileReaderBinary::readFuncProfile(), llvm::sampleprof::SampleProfileReaderExtBinaryBase::readFuncProfiles(), llvm::sampleprof::SampleProfileReaderExtBinaryBase::readFuncProfiles(), llvm::sampleprof::SampleProfileReaderText::readImpl(), llvm::sampleprof::SampleProfileReaderGCC::readOneFunctionProfile(), and SampleProfileReader().

ProfileSecRange

ReadVTableProf

bool llvm::sampleprof::SampleProfileReader::ReadVTableProf = false protected

Remapper

SkipFlatProf

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

Summary

std::unique_ptr<ProfileSummary> llvm::sampleprof::SampleProfileReader::Summary protected

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