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:342

Member Variables

protected llvm::sampleprof::SampleProfileMap 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::unordered_set<std::string> MD5NameBuffer
Extra name buffer holding names created on demand. This should only be needed for md5 profiles.
protected std::unique_ptr<ProfileSummary> Summary
Profile summary information.
protected std::unique_ptr< SampleProfileReaderItaniumRemapper> Remapper
protected bool ProfileIsProbeBased = false
protected bool ProfileIsCS = false
Whether function profiles are context-sensitive flat profiles.
protected bool ProfileIsPreInlined = false
Whether function profile contains ShouldBeInlined contexts.
protected uint32_t CSProfileCount = 0
Number of context-sensitive profiles.
protected bool ProfileIsFS = false
Whether the function profiles use FS discriminators.
protected llvm::sampleprof::SampleProfileFormat Format = SPF_None
protected const llvm::Module* M = nullptr
protected uint32_t MaskedBitFrom = 31
Zero out the discriminator bits higher than bit MaskedBitFrom (0 based). The default is to keep all the bits.

Method Overview

  • public SampleProfileReader(std::unique_ptr<MemoryBuffer> B, llvm::LLVMContext & C, llvm::sampleprof::SampleProfileFormat Format = SPF_None)
  • public virtual bool collectFuncsFromModule()
  • protected void computeSummary()
  • public static ErrorOr<std::unique_ptr<SampleProfileReader>> create(std::unique_ptr<MemoryBuffer> & B, llvm::LLVMContext & C, llvm::sampleprof::FSDiscriminatorPass P = FSDiscriminatorPass::Base, const std::string RemapFilename = "")
  • public static ErrorOr<std::unique_ptr<SampleProfileReader>> create(const std::string Filename, llvm::LLVMContext & C, llvm::sampleprof::FSDiscriminatorPass P = FSDiscriminatorPass::Base, const std::string RemapFilename = "")
  • public void dump(llvm::raw_ostream & OS = dbgs())
  • public void dumpFunctionProfile(llvm::sampleprof::SampleContext FContext, llvm::raw_ostream & OS = dbgs())
  • public virtual bool dumpSectionInfo(llvm::raw_ostream & OS = dbgs())
  • public llvm::MemoryBuffer * getBuffer() const
  • public uint32_t getDiscriminatorMask() 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 llvm::sampleprof::SampleProfileMap & getProfiles()
  • public llvm::sampleprof::SampleProfileReaderItaniumRemapper * getRemapper()
  • public llvm::sampleprof::FunctionSamples * getSamplesFor(const llvm::Function & F)
  • public virtual llvm::sampleprof::FunctionSamples * getSamplesFor(llvm::StringRef Fname)
  • public llvm::ProfileSummary & getSummary() const
  • public virtual bool hasUniqSuffix()
  • public bool profileIsCS() const
  • public bool profileIsPreInlined() const
  • public bool profileIsProbeBased() const
  • public std::error_code read()
  • public virtual std::error_code readHeader()
  • public virtual std::error_code readImpl()
  • public void reportError(int64_t LineNumber, const llvm::Twine & Msg) const
  • public void setDiscriminatorMaskedBitFrom(llvm::sampleprof::FSDiscriminatorPass P)
  • public void setModule(const llvm::Module * Mod)
  • public virtual void setSkipFlatProf(bool Skip)
  • protected static std::unique_ptr<ProfileSummary> takeSummary(llvm::sampleprof::SampleProfileReader & Reader)
  • public virtual bool useMD5()
  • 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:344

Parameters

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

virtual bool collectFuncsFromModule()

Description

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.

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

void computeSummary()

Description

Compute summary for this profile.

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

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

Description

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

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

Parameters

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

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

Description

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

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

Parameters

const std::string Filename
llvm::LLVMContext& C
llvm::sampleprof::FSDiscriminatorPass P = FSDiscriminatorPass::Base
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:392

Parameters

llvm::raw_ostream& OS = dbgs()

void dumpFunctionProfile(
    llvm::sampleprof::SampleContext FContext,
    llvm::raw_ostream& OS = dbgs())

Description

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

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

Parameters

llvm::sampleprof::SampleContext FContext
llvm::raw_ostream& OS = dbgs()

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

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

Parameters

llvm::raw_ostream& OS = dbgs()

llvm::MemoryBuffer* getBuffer() const

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

uint32_t getDiscriminatorMask() const

Description

Get the bitmask the discriminators: For FS profiles, return the bit mask for this pass. For non FS profiles, return (unsigned) -1.

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

llvm::sampleprof::SampleProfileFormat getFormat()
    const

Description

Return the profile format.

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

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:485

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:405

Parameters

const llvm::Function& F

virtual std::unique_ptr<ProfileSymbolList>
getProfileSymbolList()

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

llvm::sampleprof::SampleProfileMap& getProfiles()

Description

Return all the profiles.

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

llvm::sampleprof::
    SampleProfileReaderItaniumRemapper*
    getRemapper()

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

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:395

Parameters

const llvm::Function& F

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:420

Parameters

llvm::StringRef Fname

llvm::ProfileSummary& getSummary() const

Description

Return the profile summary.

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

virtual bool hasUniqSuffix()

Description

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

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

bool profileIsCS() const

Description

Whether input profile is fully context-sensitive.

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

bool profileIsPreInlined() const

Description

Whether input profile contains ShouldBeInlined contexts.

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

bool profileIsProbeBased() const

Description

Whether input profile is based on pseudo probes.

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

std::error_code read()

Description

The interface to read sample profiles from the associated file.

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

virtual std::error_code readHeader()

Description

Read and validate the file header.

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

virtual std::error_code readImpl()

Description

The implementaion to read sample profiles from the associated file.

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

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

Description

Report a parse error message.

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

Parameters

int64_t LineNumber
const llvm::Twine& Msg

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

Description

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.

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

Parameters

llvm::sampleprof::FSDiscriminatorPass P

void setModule(const llvm::Module* Mod)

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

Parameters

const llvm::Module* Mod

virtual void setSkipFlatProf(bool Skip)

Description

Don't read profile without context if the flag is set. This is only meaningful for ExtBinary format.

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

Parameters

bool Skip

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:524

Parameters

llvm::sampleprof::SampleProfileReader& Reader

virtual bool useMD5()

Description

Return whether names in the profile are all MD5 numbers.

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

virtual ~SampleProfileReader()

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