LLVM
17.0.0git
|
Sample-based profile reader. More...
#include "llvm/ProfileData/SampleProfReader.h"
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. More... | |
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... | |
virtual std::error_code | readImpl ()=0 |
The implementaion 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... | |
virtual bool | collectFuncsFromModule () |
Collect functions with definitions in Module M. More... | |
void | dump (raw_ostream &OS=dbgs()) |
Print all the profiles on stream OS . More... | |
void | dumpJson (raw_ostream &OS=dbgs()) |
Print all the profiles on stream OS in the JSON format. More... | |
FunctionSamples * | getSamplesFor (const Function &F) |
Return the samples collected for function F . More... | |
FunctionSamples * | getOrCreateSamplesFor (const Function &F) |
Return the samples collected for function F , create empty FunctionSamples if it doesn't exist. More... | |
virtual FunctionSamples * | getSamplesFor (StringRef Fname) |
Return the samples collected for function F . More... | |
SampleProfileMap & | getProfiles () |
Return all the profiles. More... | |
void | reportError (int64_t LineNumber, const Twine &Msg) const |
Report a parse error message. More... | |
ProfileSummary & | getSummary () const |
Return the profile summary. More... | |
MemoryBuffer * | getBuffer () 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... | |
bool | profileIsPreInlined () const |
Whether input profile contains ShouldBeInlined contexts. More... | |
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. More... | |
virtual bool | dumpSectionInfo (raw_ostream &OS=dbgs()) |
virtual bool | useMD5 () |
Return whether names in the profile are all MD5 numbers. More... | |
virtual void | setSkipFlatProf (bool Skip) |
Don't read profile without context if the flag is set. More... | |
virtual bool | hasUniqSuffix () |
Return whether any name in the profile contains ".__uniq." suffix. More... | |
SampleProfileReaderItaniumRemapper * | getRemapper () |
void | setModule (const Module *Mod) |
Static Public Member Functions | |
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... | |
Protected Member Functions | |
void | computeSummary () |
Compute summary for this profile. More... | |
Static Protected Member Functions | |
static std::unique_ptr< ProfileSummary > | takeSummary (SampleProfileReader &Reader) |
Take ownership of the summary of this reader. More... | |
Protected Attributes | |
SampleProfileMap | Profiles |
Map every function to its associated profile. More... | |
LLVMContext & | Ctx |
LLVM context used to emit diagnostics. More... | |
std::unique_ptr< MemoryBuffer > | Buffer |
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< ProfileSummary > | Summary |
Profile summary information. More... | |
std::unique_ptr< SampleProfileReaderItaniumRemapper > | Remapper |
bool | ProfileIsProbeBased = false |
Whether samples are collected based on pseudo probes. More... | |
bool | ProfileIsCS = false |
Whether function profiles are context-sensitive flat profiles. More... | |
bool | ProfileIsPreInlined = false |
Whether function profile contains ShouldBeInlined contexts. 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 Module * | M = 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... | |
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 342 of file SampleProfReader.h.
|
inline |
Definition at line 344 of file SampleProfReader.h.
|
virtualdefault |
|
inlinevirtual |
Collect functions with definitions in Module M.
For reader which support loading function profiles on demand, return true when the reader has been given a module. Always return false for reader which doesn't support loading function profiles on demand.
Reimplemented in llvm::sampleprof::SampleProfileReaderCompactBinary, and llvm::sampleprof::SampleProfileReaderExtBinaryBase.
Definition at line 389 of file SampleProfReader.h.
Referenced by llvm::sampleprof::SampleProfileReaderExtBinaryBase::readFuncProfiles(), and llvm::sampleprof::SampleProfileReaderCompactBinary::readImpl().
|
protected |
Compute summary for this profile.
Definition at line 1964 of file SampleProfReader.cpp.
References Builder, llvm::ProfileSummaryBuilder::DefaultCutoffs, Profiles, and Summary.
Referenced by llvm::sampleprof::SampleProfileReaderGCC::readFunctionProfiles(), and llvm::sampleprof::SampleProfileReaderText::readImpl().
|
static |
Create a sample profile reader appropriate to the file format.
Create a sample profile reader based on the format of the input file.
Create a remapper underlying if RemapFilename is not empty. Parameter P specifies the FSDiscriminatorPass.
Filename | The file to open. |
C | The LLVM context to use to emit diagnostics. |
P | The FSDiscriminatorPass. |
RemapFilename | The file used for profile remapping. |
Definition at line 1855 of file SampleProfReader.cpp.
References P, and setupMemoryBuffer().
Referenced by llvm::sampleprof::SampleProfileReaderItaniumRemapper::create(), and llvm::MIRProfileLoader::doInitialization().
|
static |
Create a sample profile reader from the supplied memory buffer.
Create a sample profile reader based on the format of the input data.
Create a remapper underlying if RemapFilename is not empty. Parameter P specifies the FSDiscriminatorPass.
B | The memory buffer to create the reader from (assumes ownership). |
C | The LLVM context to use to emit diagnostics. |
P | The FSDiscriminatorPass. |
RemapFilename | The file used for profile remapping. |
Definition at line 1925 of file SampleProfReader.cpp.
References B, llvm::sampleprof::SampleProfileReaderItaniumRemapper::create(), llvm::sampleprof::SampleProfileReaderText::hasFormat(), llvm::sampleprof::SampleProfileReaderRawBinary::hasFormat(), llvm::sampleprof::SampleProfileReaderExtBinary::hasFormat(), llvm::sampleprof::SampleProfileReaderCompactBinary::hasFormat(), llvm::sampleprof::SampleProfileReaderGCC::hasFormat(), move, llvm::AMDGPU::SendMsg::Msg, P, and llvm::unrecognized_format.
void SampleProfileReader::dump | ( | raw_ostream & | OS = dbgs() | ) |
Print all the profiles on stream OS
.
Dump all the function profiles found on stream OS
.
Definition at line 69 of file SampleProfReader.cpp.
References dumpFunctionProfile(), I, Profiles, and llvm::sampleprof::sortFuncProfiles().
void SampleProfileReader::dumpFunctionProfile | ( | SampleContext | FContext, |
raw_ostream & | OS = dbgs() |
||
) |
Print the profile for FContext
on stream OS
.
Dump the function profile for FName
.
FContext | Name + context of the function to print. |
OS | Stream to emit the output to. |
Definition at line 63 of file SampleProfReader.cpp.
References Profiles, and llvm::sampleprof::SampleContext::toString().
Referenced by dump().
void SampleProfileReader::dumpJson | ( | raw_ostream & | OS = dbgs() | ) |
Print all the profiles on stream OS
in the JSON format.
Dump all the function profiles found on stream OS
in the JSON format.
Definition at line 136 of file SampleProfReader.cpp.
References llvm::json::OStream::arrayBegin(), llvm::json::OStream::arrayEnd(), dumpFunctionProfileJson(), F, Profiles, and llvm::sampleprof::sortFuncProfiles().
|
inlinevirtual |
Reimplemented in llvm::sampleprof::SampleProfileReaderExtBinaryBase.
Definition at line 489 of file SampleProfReader.h.
|
inline |
Definition at line 468 of file SampleProfReader.h.
References Buffer.
|
inline |
Get the bitmask the discriminators: For FS profiles, return the bit mask for this pass.
For non FS profiles, return (unsigned) -1.
Definition at line 362 of file SampleProfReader.h.
References assert(), llvm::getN1Bits(), MaskedBitFrom, and ProfileIsFS.
Referenced by llvm::sampleprof::SampleProfileReaderText::readImpl(), and llvm::sampleprof::SampleProfileReaderBinary::readProfile().
|
inline |
|
inlinevirtual |
It includes all the names that have samples either in outline instance or inline instance.
Reimplemented in llvm::sampleprof::SampleProfileReaderBinary.
Definition at line 488 of file SampleProfReader.h.
|
inline |
Return the samples collected for function F
, create empty FunctionSamples if it doesn't exist.
Definition at line 408 of file SampleProfReader.h.
References assert(), F, llvm::sampleprof::FunctionSamples::getCanonicalFnName(), llvm::sampleprof::getRepInFormat(), MD5NameBuffer, Profiles, and useMD5().
|
inline |
|
inlinevirtual |
Reimplemented in llvm::sampleprof::SampleProfileReaderExtBinaryBase.
Definition at line 482 of file SampleProfReader.h.
|
inline |
Definition at line 500 of file SampleProfReader.h.
References Remapper.
|
inline |
Return the samples collected for function F
.
Definition at line 398 of file SampleProfReader.h.
References F, and llvm::sampleprof::FunctionSamples::getCanonicalFnName().
|
inlinevirtual |
Return the samples collected for function F
.
Definition at line 423 of file SampleProfReader.h.
References llvm::sampleprof::getRepInFormat(), Profiles, Remapper, and useMD5().
|
inline |
|
inlinevirtual |
Return whether any name in the profile contains ".__uniq." suffix.
Definition at line 498 of file SampleProfReader.h.
|
inline |
Whether input profile is fully context-sensitive.
Definition at line 477 of file SampleProfReader.h.
References ProfileIsCS.
|
inline |
Whether input profile contains ShouldBeInlined contexts.
Definition at line 480 of file SampleProfReader.h.
References ProfileIsPreInlined.
|
inline |
Whether input profile is based on pseudo probes.
Definition at line 474 of file SampleProfReader.h.
References ProfileIsProbeBased.
|
inline |
The interface to read sample profiles from the associated file.
Definition at line 370 of file SampleProfReader.h.
References Ctx, readImpl(), Remapper, llvm::success, useMD5(), and llvm::sampleprof::FunctionSamples::UseMD5.
|
pure virtual |
Read and validate the file header.
Implemented in llvm::sampleprof::SampleProfileReaderGCC, llvm::sampleprof::SampleProfileReaderExtBinaryBase, llvm::sampleprof::SampleProfileReaderBinary, and llvm::sampleprof::SampleProfileReaderText.
|
pure virtual |
The implementaion to read sample profiles from the associated file.
Implemented in llvm::sampleprof::SampleProfileReaderGCC, llvm::sampleprof::SampleProfileReaderCompactBinary, llvm::sampleprof::SampleProfileReaderExtBinaryBase, llvm::sampleprof::SampleProfileReaderBinary, and llvm::sampleprof::SampleProfileReaderText.
Referenced by read().
|
inline |
Report a parse error message.
Definition at line 444 of file SampleProfReader.h.
References Buffer, Ctx, llvm::LLVMContext::diagnose(), and llvm::AMDGPU::SendMsg::Msg.
Referenced by llvm::sampleprof::SampleProfileReaderText::readImpl(), llvm::sampleprof::SampleProfileReaderBinary::readNumber(), llvm::sampleprof::SampleProfileReaderGCC::readNumber(), llvm::sampleprof::SampleProfileReaderBinary::readString(), and llvm::sampleprof::SampleProfileReaderBinary::readUnencodedNumber().
|
inline |
Set the bits for FS discriminators.
Parameter Pass specify the sequence number, Pass == i is for the i-th round of adding FS discriminators. Pass == 0 is for using base discriminators.
Definition at line 356 of file SampleProfReader.h.
References llvm::getFSPassBitEnd(), MaskedBitFrom, and P.
Definition at line 502 of file SampleProfReader.h.
|
inlinevirtual |
Don't read profile without context if the flag is set.
This is only meaningful for ExtBinary format.
Reimplemented in llvm::sampleprof::SampleProfileReaderExtBinaryBase.
Definition at line 496 of file SampleProfReader.h.
|
inlinestaticprotected |
Take ownership of the summary of this reader.
Definition at line 527 of file SampleProfReader.h.
|
inlinevirtual |
Return whether names in the profile are all MD5 numbers.
Reimplemented in llvm::sampleprof::SampleProfileReaderCompactBinary, and llvm::sampleprof::SampleProfileReaderExtBinaryBase.
Definition at line 492 of file SampleProfReader.h.
Referenced by getOrCreateSamplesFor(), getSamplesFor(), read(), and llvm::sampleprof::SampleProfileReaderExtBinaryBase::readFuncProfiles().
|
protected |
Memory buffer holding the profile file.
Definition at line 516 of file SampleProfReader.h.
Referenced by getBuffer(), llvm::sampleprof::SampleProfileReaderText::hasFormat(), llvm::sampleprof::SampleProfileReaderRawBinary::hasFormat(), llvm::sampleprof::SampleProfileReaderExtBinary::hasFormat(), llvm::sampleprof::SampleProfileReaderCompactBinary::hasFormat(), llvm::sampleprof::SampleProfileReaderGCC::hasFormat(), llvm::sampleprof::SampleProfileReaderBinary::readHeader(), llvm::sampleprof::SampleProfileReaderExtBinaryBase::readHeader(), llvm::sampleprof::SampleProfileReaderText::readImpl(), llvm::sampleprof::SampleProfileReaderExtBinaryBase::readImpl(), llvm::sampleprof::SampleProfileReaderCompactBinary::readImpl(), reportError(), and setupMemoryBuffer().
|
protected |
Number of context-sensitive profiles.
Definition at line 546 of file SampleProfReader.h.
Referenced by llvm::sampleprof::SampleProfileReaderBinary::readFuncProfile(), llvm::sampleprof::SampleProfileReaderExtBinaryBase::readFuncProfiles(), and llvm::sampleprof::SampleProfileReaderText::readImpl().
|
protected |
LLVM context used to emit diagnostics.
Definition at line 513 of file SampleProfReader.h.
Referenced by llvm::sampleprof::SampleProfileReaderItaniumRemapper::applyRemapping(), read(), and reportError().
|
protected |
The current module being compiled if SampleProfileReader is used by compiler.
If SampleProfileReader is used by other tools which are not compiler, M is usually nullptr.
Definition at line 557 of file SampleProfReader.h.
Referenced by llvm::sampleprof::SampleProfileReaderExtBinaryBase::collectFuncsFromModule(), llvm::sampleprof::SampleProfileReaderCompactBinary::collectFuncsFromModule(), and setModule().
|
protected |
Zero out the discriminator bits higher than bit MaskedBitFrom (0 based).
The default is to keep all the bits.
Definition at line 561 of file SampleProfReader.h.
Referenced by getDiscriminatorMask(), and setDiscriminatorMaskedBitFrom().
|
protected |
Extra name buffer holding names created on demand.
This should only be needed for md5 profiles.
Definition at line 520 of file SampleProfReader.h.
Referenced by getOrCreateSamplesFor().
|
protected |
Whether function profiles are context-sensitive flat profiles.
Definition at line 540 of file SampleProfReader.h.
Referenced by profileIsCS(), llvm::sampleprof::SampleProfileReaderExtBinaryBase::readFuncMetadata(), llvm::sampleprof::SampleProfileReaderExtBinaryBase::readFuncProfiles(), llvm::sampleprof::SampleProfileReaderText::readImpl(), and llvm::sampleprof::SampleProfileReaderExtBinaryBase::readSampleContextFromTable().
|
protected |
Whether the function profiles use FS discriminators.
Definition at line 549 of file SampleProfReader.h.
Referenced by getDiscriminatorMask(), llvm::sampleprof::SampleProfileReaderText::readImpl(), llvm::sampleprof::SampleProfileReaderBinary::readImpl(), and llvm::sampleprof::SampleProfileReaderCompactBinary::readImpl().
|
protected |
Whether function profile contains ShouldBeInlined contexts.
Definition at line 543 of file SampleProfReader.h.
Referenced by profileIsPreInlined(), and llvm::sampleprof::SampleProfileReaderText::readImpl().
|
protected |
Whether samples are collected based on pseudo probes.
Definition at line 537 of file SampleProfReader.h.
Referenced by profileIsProbeBased(), llvm::sampleprof::SampleProfileReaderExtBinaryBase::readFuncMetadata(), and llvm::sampleprof::SampleProfileReaderText::readImpl().
|
protected |
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 510 of file SampleProfReader.h.
Referenced by computeSummary(), dump(), dumpFunctionProfile(), dumpJson(), getOrCreateSamplesFor(), getProfiles(), getSamplesFor(), llvm::sampleprof::SampleProfileReaderExtBinaryBase::readFuncMetadata(), llvm::sampleprof::SampleProfileReaderBinary::readFuncProfile(), llvm::sampleprof::SampleProfileReaderExtBinaryBase::readFuncProfiles(), llvm::sampleprof::SampleProfileReaderText::readImpl(), and llvm::sampleprof::SampleProfileReaderGCC::readOneFunctionProfile().
|
protected |
Definition at line 534 of file SampleProfReader.h.
Referenced by getRemapper(), getSamplesFor(), read(), and llvm::sampleprof::SampleProfileReaderExtBinaryBase::readFuncProfiles().
|
protected |
Profile summary information.
Definition at line 523 of file SampleProfReader.h.
Referenced by computeSummary(), getSummary(), and takeSummary().