LLVM  10.0.0svn
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
llvm::sampleprof::SampleProfileReader Class Referenceabstract

Sample-based profile reader. More...

#include "llvm/ProfileData/SampleProfReader.h"

Inheritance diagram for llvm::sampleprof::SampleProfileReader:
Inheritance graph
Collaboration diagram for llvm::sampleprof::SampleProfileReader:
Collaboration graph

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 collectFuncsFrom (const Module &M)
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...
virtual FunctionSamplesgetSamplesFor (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...
ProfileSummarygetSummary ()
 Return the profile summary. More...
SampleProfileFormat getFormat ()
 Return the profile format. More...
virtual std::unique_ptr< ProfileSymbolListgetProfileSymbolList ()
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())

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< ProfileSummarytakeSummary (SampleProfileReader &Reader)
 Take ownership of the summary of this reader. More...

Protected Attributes

StringMap< FunctionSamplesProfiles
 Map every function to its associated profile. More...
 LLVM context used to emit diagnostics. More...
std::unique_ptr< MemoryBufferBuffer
 Memory buffer holding the profile file. More...
std::unique_ptr< ProfileSummarySummary
 Profile summary information. More...
SampleProfileFormat Format = SPF_None
 The format of sample. More...

Detailed Description

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

Constructor & Destructor Documentation

◆ SampleProfileReader()

llvm::sampleprof::SampleProfileReader::SampleProfileReader ( std::unique_ptr< MemoryBuffer B,
LLVMContext C,
SampleProfileFormat  Format = SPF_None 

◆ ~SampleProfileReader()

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

Referenced by SampleProfileReader().

Member Function Documentation

◆ collectFuncsFrom()

virtual void llvm::sampleprof::SampleProfileReader::collectFuncsFrom ( const Module M)

◆ computeSummary()

void SampleProfileReader::computeSummary ( )

◆ create() [1/2]

ErrorOr< std::unique_ptr< SampleProfileReader > > SampleProfileReader::create ( const Twine Filename,
LLVMContext C 

Create a sample profile reader appropriate to the file format.

Create a sample profile reader based on the format of the input file.

FilenameThe file to open.
CThe LLVM context to use to emit diagnostics.
an error code indicating the status of the created reader.

Definition at line 1263 of file SampleProfReader.cpp.

References C, and setupMemoryBuffer().

Referenced by reportError(), and llvm::sampleprof::SampleProfileReaderItaniumRemapper::SampleProfileReaderItaniumRemapper().

◆ create() [2/2]

ErrorOr< std::unique_ptr< SampleProfileReader > > SampleProfileReader::create ( std::unique_ptr< MemoryBuffer > &  B,
LLVMContext C 

Create a sample profile reader from the supplied memory buffer.

Create a sample profile reader based on the format of the input data.

BThe memory buffer to create the reader from (assumes ownership).
CThe LLVM context to use to emit diagnostics.
an error code indicating the status of the created reader.

Definition at line 1299 of file SampleProfReader.cpp.

References llvm::sampleprof::FunctionSamples::Format, llvm::sampleprof::SampleProfileReaderText::hasFormat(), llvm::sampleprof::SampleProfileReaderRawBinary::hasFormat(), llvm::sampleprof::SampleProfileReaderExtBinary::hasFormat(), llvm::sampleprof::SampleProfileReaderCompactBinary::hasFormat(), llvm::sampleprof::SampleProfileReaderGCC::hasFormat(), and llvm::unrecognized_format.

◆ dump()

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 collectFuncsFrom().

◆ dumpFunctionProfile()

void SampleProfileReader::dumpFunctionProfile ( StringRef  FName,
raw_ostream OS = dbgs() 

Print the profile for FName on stream OS.

Dump the function profile for FName.

FNameName of the function to print.
OSStream to emit the output to.

Definition at line 51 of file SampleProfReader.cpp.

References Profiles.

Referenced by dump(), and SampleProfileReader().

◆ dumpSectionInfo()

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

◆ getFormat()

SampleProfileFormat llvm::sampleprof::SampleProfileReader::getFormat ( )

Return the profile format.

Definition at line 327 of file SampleProfReader.h.

References Format.

Referenced by getSamplesFor(), and llvm::sampleprof::SampleProfileReaderItaniumRemapper::read().

◆ getNameTable()

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

It includes all the names that have samples either in outline instance or inline instance.

Reimplemented in llvm::sampleprof::SampleProfileReaderBinary.

Definition at line 335 of file SampleProfReader.h.

◆ getProfiles()

StringMap<FunctionSamples>& llvm::sampleprof::SampleProfileReader::getProfiles ( )

Return all the profiles.

Definition at line 307 of file SampleProfReader.h.

References Profiles.

Referenced by llvm::createSampleProfileLoaderPass(), and llvm::sampleprof::SampleProfileReaderItaniumRemapper::read().

◆ getProfileSymbolList()

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

Reimplemented in llvm::sampleprof::SampleProfileReaderExtBinary.

Definition at line 329 of file SampleProfReader.h.

◆ getSamplesFor() [1/2]

FunctionSamples* llvm::sampleprof::SampleProfileReader::getSamplesFor ( const Function F)

◆ getSamplesFor() [2/2]

virtual FunctionSamples* llvm::sampleprof::SampleProfileReader::getSamplesFor ( StringRef  Fname)

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.

◆ getSummary()

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

Return the profile summary.

Definition at line 324 of file SampleProfReader.h.

References Summary.

Referenced by llvm::createSampleProfileLoaderPass().

◆ read()

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

◆ readHeader()

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

◆ reportError()

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

◆ takeSummary()

static std::unique_ptr<ProfileSummary> llvm::sampleprof::SampleProfileReader::takeSummary ( SampleProfileReader Reader)

Take ownership of the summary of this reader.

Definition at line 357 of file SampleProfReader.h.

References computeSummary(), and Summary.

Referenced by llvm::sampleprof::SampleProfileReaderItaniumRemapper::SampleProfileReaderItaniumRemapper().

Member Data Documentation

◆ Buffer

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

◆ Ctx

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

LLVM context used to emit diagnostics.

Definition at line 347 of file SampleProfReader.h.

Referenced by llvm::sampleprof::SampleProfileReaderItaniumRemapper::read(), and reportError().

◆ Format

SampleProfileFormat llvm::sampleprof::SampleProfileReader::Format = SPF_None

The format of sample.

Definition at line 365 of file SampleProfReader.h.

Referenced by getFormat().

◆ Profiles

StringMap<FunctionSamples> llvm::sampleprof::SampleProfileReader::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 336 of file SampleProfReader.h.

Referenced by computeSummary(), dump(), dumpFunctionProfile(), getProfiles(), getSamplesFor(), llvm::sampleprof::SampleProfileReaderText::read(), llvm::sampleprof::SampleProfileReaderGCC::readOneFunctionProfile(), and llvm::sampleprof::SampleProfileReaderItaniumRemapper::SampleProfileReaderItaniumRemapper().

◆ Summary

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

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