LLVM
8.0.1
|
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... | |
virtual std::error_code | read ()=0 |
Read sample profiles from the associated file. More... | |
void | dumpFunctionProfile (StringRef FName, raw_ostream &OS=dbgs()) |
Print the profile for FName on stream OS . More... | |
virtual void | collectFuncsToUse (const Module &M) |
void | dump (raw_ostream &OS=dbgs()) |
Print all the profiles on stream OS . More... | |
FunctionSamples * | getSamplesFor (const Function &F) |
Return the samples collected for function F . More... | |
virtual FunctionSamples * | getSamplesFor (StringRef Fname) |
Return the samples collected for function F . More... | |
StringMap< FunctionSamples > & | getProfiles () |
Return all the profiles. More... | |
void | reportError (int64_t LineNumber, Twine Msg) const |
Report a parse error message. More... | |
ProfileSummary & | getSummary () |
Return the profile summary. More... | |
SampleProfileFormat | getFormat () |
Return the profile format. More... | |
Static Public Member Functions | |
static ErrorOr< std::unique_ptr< SampleProfileReader > > | create (const Twine &Filename, LLVMContext &C) |
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) |
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 | |
StringMap< FunctionSamples > | 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::unique_ptr< ProfileSummary > | Summary |
Profile summary information. More... | |
SampleProfileFormat | Format = SPF_None |
The format of sample. 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 266 of file SampleProfReader.h.
|
inline |
Definition at line 268 of file SampleProfReader.h.
References llvm::dbgs(), dumpFunctionProfile(), read(), readHeader(), and ~SampleProfileReader().
|
virtualdefault |
Referenced by SampleProfileReader().
|
inlinevirtual |
Reimplemented in llvm::sampleprof::SampleProfileReaderCompactBinary.
Definition at line 283 of file SampleProfReader.h.
References llvm::dbgs(), and dump().
Referenced by llvm::sampleprof::SampleProfileReaderCompactBinary::SampleProfileReaderCompactBinary().
|
protected |
Compute summary for this profile.
Definition at line 1032 of file SampleProfReader.cpp.
References llvm::SampleProfileSummaryBuilder::addRecord(), llvm::ProfileSummaryBuilder::DefaultCutoffs, llvm::SampleProfileSummaryBuilder::getSummary(), I, Profiles, and Summary.
Referenced by llvm::sampleprof::SampleProfileReaderText::read(), llvm::sampleprof::SampleProfileReaderGCC::readFunctionProfiles(), and takeSummary().
|
static |
Create a sample profile reader appropriate to the file format.
Create a sample profile reader based on the format of the input file.
Filename | The file to open. |
C | The LLVM context to use to emit diagnostics. |
Definition at line 974 of file SampleProfReader.cpp.
References C, and setupMemoryBuffer().
Referenced by reportError(), and llvm::sampleprof::SampleProfileReaderItaniumRemapper::SampleProfileReaderItaniumRemapper().
|
static |
Create a sample profile reader from the supplied memory buffer.
Create a sample profile reader based on the format of the input data.
B | The memory buffer to create the reader from (assumes ownership). |
C | The LLVM context to use to emit diagnostics. |
Definition at line 1010 of file SampleProfReader.cpp.
References llvm::sampleprof::FunctionSamples::Format, llvm::sampleprof::SampleProfileReaderText::hasFormat(), llvm::sampleprof::SampleProfileReaderRawBinary::hasFormat(), llvm::sampleprof::SampleProfileReaderCompactBinary::hasFormat(), llvm::sampleprof::SampleProfileReaderGCC::hasFormat(), 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 57 of file SampleProfReader.cpp.
References dumpFunctionProfile(), I, and Profiles.
Referenced by collectFuncsToUse().
void SampleProfileReader::dumpFunctionProfile | ( | StringRef | FName, |
raw_ostream & | OS = dbgs() |
||
) |
Print the profile for FName
on stream OS
.
Dump the function profile for FName
.
FName | Name of the function to print. |
OS | Stream to emit the output to. |
Definition at line 51 of file SampleProfReader.cpp.
References Profiles.
Referenced by dump(), and SampleProfileReader().
|
inline |
Return the profile format.
Definition at line 327 of file SampleProfReader.h.
References Format.
Referenced by getSamplesFor(), and llvm::sampleprof::SampleProfileReaderItaniumRemapper::read().
|
inline |
Return all the profiles.
Definition at line 307 of file SampleProfReader.h.
References Profiles.
Referenced by llvm::sampleprof::SampleProfileReaderItaniumRemapper::read().
|
inline |
Return the samples collected for function F
.
Definition at line 289 of file SampleProfReader.h.
References llvm::Value::getName(), and llvm::StringRef::split().
Referenced by llvm::sampleprof::SampleProfileReaderItaniumRemapper::getSamplesFor(), and llvm::sampleprof::SampleProfileReaderItaniumRemapper::readHeader().
|
inlinevirtual |
Return the samples collected for function F
.
Reimplemented in llvm::sampleprof::SampleProfileReaderItaniumRemapper.
Definition at line 297 of file SampleProfReader.h.
References getFormat(), llvm::sampleprof::getRepInFormat(), and Profiles.
|
inline |
|
pure virtual |
Read sample profiles from the associated file.
Implemented in llvm::sampleprof::SampleProfileReaderItaniumRemapper, llvm::sampleprof::SampleProfileReaderGCC, llvm::sampleprof::SampleProfileReaderCompactBinary, llvm::sampleprof::SampleProfileReaderBinary, and llvm::sampleprof::SampleProfileReaderText.
Referenced by llvm::sampleprof::SampleProfileReaderText::readHeader(), llvm::sampleprof::SampleProfileReaderItaniumRemapper::readHeader(), SampleProfileReader(), llvm::sampleprof::SampleProfileReaderBinary::SampleProfileReaderBinary(), llvm::sampleprof::SampleProfileReaderCompactBinary::SampleProfileReaderCompactBinary(), and llvm::sampleprof::SampleProfileReaderGCC::SampleProfileReaderGCC().
|
pure virtual |
Read and validate the file header.
Implemented in llvm::sampleprof::SampleProfileReaderItaniumRemapper, llvm::sampleprof::SampleProfileReaderGCC, llvm::sampleprof::SampleProfileReaderBinary, and llvm::sampleprof::SampleProfileReaderText.
Referenced by SampleProfileReader(), llvm::sampleprof::SampleProfileReaderBinary::SampleProfileReaderBinary(), and llvm::sampleprof::SampleProfileReaderGCC::SampleProfileReaderGCC().
|
inline |
Report a parse error message.
Definition at line 310 of file SampleProfReader.h.
References B, Buffer, C, create(), Ctx, and llvm::LLVMContext::diagnose().
Referenced by llvm::sampleprof::SampleProfileReaderText::read(), llvm::sampleprof::SampleProfileReaderItaniumRemapper::read(), and llvm::sampleprof::SampleProfileReaderGCC::readNumber().
|
inlinestaticprotected |
Take ownership of the summary of this reader.
Definition at line 348 of file SampleProfReader.h.
References computeSummary(), and Summary.
Referenced by llvm::sampleprof::SampleProfileReaderItaniumRemapper::SampleProfileReaderItaniumRemapper().
|
protected |
Memory buffer holding the profile file.
Definition at line 341 of file SampleProfReader.h.
Referenced by llvm::sampleprof::SampleProfileReaderText::read(), llvm::sampleprof::SampleProfileReaderCompactBinary::read(), llvm::sampleprof::SampleProfileReaderItaniumRemapper::read(), llvm::sampleprof::SampleProfileReaderText::readHeader(), llvm::sampleprof::SampleProfileReaderBinary::readHeader(), reportError(), llvm::sampleprof::SampleProfileReaderCompactBinary::SampleProfileReaderCompactBinary(), llvm::sampleprof::SampleProfileReaderGCC::SampleProfileReaderGCC(), llvm::sampleprof::SampleProfileReaderRawBinary::SampleProfileReaderRawBinary(), and setupMemoryBuffer().
|
protected |
LLVM context used to emit diagnostics.
Definition at line 338 of file SampleProfReader.h.
Referenced by llvm::sampleprof::SampleProfileReaderItaniumRemapper::read(), and reportError().
|
protected |
|
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 335 of file SampleProfReader.h.
Referenced by computeSummary(), dump(), dumpFunctionProfile(), getProfiles(), getSamplesFor(), llvm::sampleprof::SampleProfileReaderText::read(), llvm::sampleprof::SampleProfileReaderBinary::readFuncProfile(), llvm::sampleprof::SampleProfileReaderGCC::readOneFunctionProfile(), and llvm::sampleprof::SampleProfileReaderItaniumRemapper::SampleProfileReaderItaniumRemapper().
|
protected |
Profile summary information.
Definition at line 344 of file SampleProfReader.h.
Referenced by llvm::sampleprof::SampleProfileReaderCompactBinary::collectFuncsToUse(), computeSummary(), getSummary(), llvm::sampleprof::SampleProfileReaderItaniumRemapper::SampleProfileReaderItaniumRemapper(), and takeSummary().