class SampleProfileReader

Declaration

class SampleProfileReader { /* full declaration omitted */ };

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: * A list of functions included in the profile (mangled names). * For each function F: 1. The total number of samples collected in F. 2. The samples collected at each line in F. To provide some protection against source code shuffling, line numbers should be relative to the start of the function. 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.

Declared at: llvm/include/llvm/ProfileData/SampleProfReader.h:321

Member Variables

protected StringMap<llvm::sampleprof::FunctionSamples> Profiles
The profile of every function executed at runtime is collected in the structure FunctionSamples. This maps function objects to their corresponding profiles.
protected llvm::LLVMContext& Ctx
LLVM context used to emit diagnostics.
protected std::unique_ptr<MemoryBuffer> Buffer
Memory buffer holding the profile file.
protected std::unique_ptr<ProfileSummary> Summary
Profile summary information.
protected std::unique_ptr< SampleProfileReaderItaniumRemapper> Remapper
protected llvm::sampleprof::SampleProfileFormat Format = SPF_None

Method Overview

  • public SampleProfileReader(std::unique_ptr<MemoryBuffer> B, llvm::LLVMContext & C, llvm::sampleprof::SampleProfileFormat Format = SPF_None)
  • public virtual void collectFuncsFrom(const llvm::Module & M)
  • protected void computeSummary()
  • public static ErrorOr<std::unique_ptr<SampleProfileReader>> create(std::unique_ptr<MemoryBuffer> & B, llvm::LLVMContext & C, const std::string RemapFilename = "")
  • public static ErrorOr<std::unique_ptr<SampleProfileReader>> create(const std::string Filename, llvm::LLVMContext & C, const std::string RemapFilename = "")
  • public void dump(llvm::raw_ostream & OS = dbgs())
  • public void dumpFunctionProfile(llvm::StringRef FName, llvm::raw_ostream & OS = dbgs())
  • public virtual bool dumpSectionInfo(llvm::raw_ostream & OS = dbgs())
  • public llvm::MemoryBuffer * getBuffer() const
  • public llvm::sampleprof::SampleProfileFormat getFormat() const
  • public virtual std::vector<StringRef> * getNameTable()
  • public llvm::sampleprof::FunctionSamples * getOrCreateSamplesFor(const llvm::Function & F)
  • public virtual std::unique_ptr<ProfileSymbolList> getProfileSymbolList()
  • public StringMap<llvm::sampleprof::FunctionSamples> & getProfiles()
  • public virtual llvm::sampleprof::FunctionSamples * getSamplesFor(llvm::StringRef Fname)
  • public llvm::sampleprof::FunctionSamples * getSamplesFor(const llvm::Function & F)
  • public llvm::ProfileSummary & getSummary() const
  • public std::error_code read()
  • public virtual std::error_code readHeader()
  • public virtual std::error_code readImpl()
  • public void reportError(int64_t LineNumber, llvm::Twine Msg) const
  • protected static std::unique_ptr<ProfileSummary> takeSummary(llvm::sampleprof::SampleProfileReader & Reader)
  • public virtual ~SampleProfileReader()

Methods

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

Declared at: llvm/include/llvm/ProfileData/SampleProfReader.h:323

Parameters

std::unique_ptr<MemoryBuffer> B
llvm::LLVMContext& C
llvm::sampleprof::SampleProfileFormat Format = SPF_None

virtual void collectFuncsFrom(
    const llvm::Module& M)

Declared at: llvm/include/llvm/ProfileData/SampleProfReader.h:347

Parameters

const llvm::Module& M

void computeSummary()

Description

Compute summary for this profile.

Declared at: llvm/include/llvm/ProfileData/SampleProfReader.h:446

static ErrorOr<
    std::unique_ptr<SampleProfileReader>>
create(std::unique_ptr<MemoryBuffer>& B,
       llvm::LLVMContext& C,
       const std::string RemapFilename = "")

Description

Create a sample profile reader from the supplied memory buffer. Create a remapper underlying if RemapFilename is not empty.

Declared at: llvm/include/llvm/ProfileData/SampleProfReader.h:402

Parameters

std::unique_ptr<MemoryBuffer>& B
llvm::LLVMContext& C
const std::string RemapFilename = ""

static ErrorOr<
    std::unique_ptr<SampleProfileReader>>
create(const std::string Filename,
       llvm::LLVMContext& C,
       const std::string RemapFilename = "")

Description

Create a sample profile reader appropriate to the file format. Create a remapper underlying if RemapFilename is not empty.

Declared at: llvm/include/llvm/ProfileData/SampleProfReader.h:396

Parameters

const std::string Filename
llvm::LLVMContext& C
const std::string RemapFilename = ""

void dump(llvm::raw_ostream& OS = dbgs())

Description

Print all the profiles on stream \p OS.

Declared at: llvm/include/llvm/ProfileData/SampleProfReader.h:350

Parameters

llvm::raw_ostream& OS = dbgs()

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

Description

Print the profile for \p FName on stream \p OS.

Declared at: llvm/include/llvm/ProfileData/SampleProfReader.h:345

Parameters

llvm::StringRef FName
llvm::raw_ostream& OS = dbgs()

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

Declared at: llvm/include/llvm/ProfileData/SampleProfReader.h:420

Parameters

llvm::raw_ostream& OS = dbgs()

llvm::MemoryBuffer* getBuffer() const

Declared at: llvm/include/llvm/ProfileData/SampleProfReader.h:408

llvm::sampleprof::SampleProfileFormat getFormat()
    const

Description

Return the profile format.

Declared at: llvm/include/llvm/ProfileData/SampleProfReader.h:411

virtual std::vector<StringRef>* getNameTable()

Description

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

Declared at: llvm/include/llvm/ProfileData/SampleProfReader.h:419

llvm::sampleprof::FunctionSamples*
getOrCreateSamplesFor(const llvm::Function& F)

Description

Return the samples collected for function \p F, create empty FunctionSamples if it doesn't exist.

Declared at: llvm/include/llvm/ProfileData/SampleProfReader.h:363

Parameters

const llvm::Function& F

virtual std::unique_ptr<ProfileSymbolList>
getProfileSymbolList()

Declared at: llvm/include/llvm/ProfileData/SampleProfReader.h:413

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

Description

Return all the profiles.

Declared at: llvm/include/llvm/ProfileData/SampleProfReader.h:385

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

Description

Return the samples collected for function \p F.

Declared at: llvm/include/llvm/ProfileData/SampleProfReader.h:371

Parameters

llvm::StringRef Fname

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

Description

Return the samples collected for function \p F.

Declared at: llvm/include/llvm/ProfileData/SampleProfReader.h:353

Parameters

const llvm::Function& F

llvm::ProfileSummary& getSummary() const

Description

Return the profile summary.

Declared at: llvm/include/llvm/ProfileData/SampleProfReader.h:406

std::error_code read()

Description

The interface to read sample profiles from the associated file.

Declared at: llvm/include/llvm/ProfileData/SampleProfReader.h:333

virtual std::error_code readHeader()

Description

Read and validate the file header.

Declared at: llvm/include/llvm/ProfileData/SampleProfReader.h:330

virtual std::error_code readImpl()

Description

The implementaion to read sample profiles from the associated file.

Declared at: llvm/include/llvm/ProfileData/SampleProfReader.h:342

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

Description

Report a parse error message.

Declared at: llvm/include/llvm/ProfileData/SampleProfReader.h:388

Parameters

int64_t LineNumber
llvm::Twine Msg

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

Description

Take ownership of the summary of this reader.

Declared at: llvm/include/llvm/ProfileData/SampleProfReader.h:441

Parameters

llvm::sampleprof::SampleProfileReader& Reader

virtual ~SampleProfileReader()

Declared at: llvm/include/llvm/ProfileData/SampleProfReader.h:327