class FunctionSamples

Declaration

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

Description

Representation of the samples collected for a function. This data structure contains all the collected samples for the body of a function. Each sample corresponds to a LineLocation instance within the body of the function.

Declared at: llvm/include/llvm/ProfileData/SampleProf.h:300

Member Variables

public DenseMap<uint64_t, llvm::StringRef>* GUIDToFuncNameMap = nullptr
GUIDToFuncNameMap saves the mapping from GUID to the symbol name, for all the function symbols defined or declared in current module.
public static llvm::sampleprof::SampleProfileFormat Format

Method Overview

  • public FunctionSamples()
  • public llvm::sampleprof_error addBodySamples(uint32_t LineOffset, uint32_t Discriminator, uint64_t Num, uint64_t Weight = 1)
  • public llvm::sampleprof_error addCalledTargetSamples(uint32_t LineOffset, uint32_t Discriminator, llvm::StringRef FName, uint64_t Num, uint64_t Weight = 1)
  • public llvm::sampleprof_error addHeadSamples(uint64_t Num, uint64_t Weight = 1)
  • public llvm::sampleprof_error addTotalSamples(uint64_t Num, uint64_t Weight = 1)
  • public void dump() const
  • public bool empty() const
  • public ErrorOr<SampleRecord::CallTargetMap> findCallTargetMapAt(uint32_t LineOffset, uint32_t Discriminator) const
  • public const llvm::sampleprof::FunctionSamples * findFunctionSamples(const llvm::DILocation * DIL) const
  • public const llvm::sampleprof::FunctionSamples * findFunctionSamplesAt(const llvm::sampleprof::LineLocation & Loc, llvm::StringRef CalleeName) const
  • public const llvm::sampleprof::FunctionSamplesMap * findFunctionSamplesMapAt(const llvm::sampleprof::LineLocation & Loc) const
  • public void findInlinedFunctions(DenseSet<GlobalValue::GUID> & S, const llvm::Module * M, uint64_t Threshold) const
  • public ErrorOr<uint64_t> findSamplesAt(uint32_t LineOffset, uint32_t Discriminator) const
  • public llvm::sampleprof::FunctionSamplesMap & functionSamplesAt(const llvm::sampleprof::LineLocation & Loc)
  • public const llvm::sampleprof::BodySampleMap & getBodySamples() const
  • public const llvm::sampleprof::CallsiteSampleMap & getCallsiteSamples() const
  • public static llvm::StringRef getCanonicalFnName(const llvm::Function & F)
  • public uint64_t getEntrySamples() const
  • public llvm::StringRef getFuncNameInModule(const llvm::Module * M) const
  • public static uint64_t getGUID(llvm::StringRef Name)
  • public uint64_t getHeadSamples() const
  • public llvm::StringRef getName() const
  • public llvm::StringRef getNameInModule(llvm::StringRef Name, const llvm::Module * M) const
  • public static unsigned int getOffset(const llvm::DILocation * DIL)
  • public uint64_t getTotalSamples() const
  • public llvm::sampleprof_error merge(const llvm::sampleprof::FunctionSamples & Other, uint64_t Weight = 1)
  • public void print(llvm::raw_ostream & OS = dbgs(), unsigned int Indent = 0) const
  • public void setName(llvm::StringRef FunctionName)

Methods

FunctionSamples()

Declared at: llvm/include/llvm/ProfileData/SampleProf.h:302

llvm::sampleprof_error addBodySamples(
    uint32_t LineOffset,
    uint32_t Discriminator,
    uint64_t Num,
    uint64_t Weight = 1)

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

Parameters

uint32_t LineOffset
uint32_t Discriminator
uint64_t Num
uint64_t Weight = 1

llvm::sampleprof_error addCalledTargetSamples(
    uint32_t LineOffset,
    uint32_t Discriminator,
    llvm::StringRef FName,
    uint64_t Num,
    uint64_t Weight = 1)

Declared at: llvm/include/llvm/ProfileData/SampleProf.h:329

Parameters

uint32_t LineOffset
uint32_t Discriminator
llvm::StringRef FName
uint64_t Num
uint64_t Weight = 1

llvm::sampleprof_error addHeadSamples(
    uint64_t Num,
    uint64_t Weight = 1)

Declared at: llvm/include/llvm/ProfileData/SampleProf.h:315

Parameters

uint64_t Num
uint64_t Weight = 1

llvm::sampleprof_error addTotalSamples(
    uint64_t Num,
    uint64_t Weight = 1)

Declared at: llvm/include/llvm/ProfileData/SampleProf.h:307

Parameters

uint64_t Num
uint64_t Weight = 1

void dump() const

Declared at: llvm/include/llvm/ProfileData/SampleProf.h:305

bool empty() const

Declared at: llvm/include/llvm/ProfileData/SampleProf.h:404

ErrorOr<SampleRecord::CallTargetMap>
findCallTargetMapAt(uint32_t LineOffset,
                    uint32_t Discriminator) const

Description

Returns the call target map collected at a given location. Each location is specified by \p LineOffset and \p Discriminator. If the location is not found in profile, return error.

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

Parameters

uint32_t LineOffset
uint32_t Discriminator

const llvm::sampleprof::FunctionSamples*
findFunctionSamples(
    const llvm::DILocation* DIL) const

Description

Get the FunctionSamples of the inline instance where DIL originates from. The FunctionSamples of the instruction (Machine or IR) associated to\p DIL is the inlined instance in which that instruction is coming from. We traverse the inline stack of that instruction, and match it with the tree nodes in the profile.

Declared at: llvm/include/llvm/ProfileData/SampleProf.h:558

Parameters

const llvm::DILocation* DIL

Returns

the FunctionSamples pointer to the inlined instance.

const llvm::sampleprof::FunctionSamples*
findFunctionSamplesAt(
    const llvm::sampleprof::LineLocation& Loc,
    llvm::StringRef CalleeName) const

Description

Returns a pointer to FunctionSamples at the given callsite location \p Loc with callee \p CalleeName. If no callsite can be found, relax the restriction to return the FunctionSamples at callsite location \p Loc with the maximum total sample count.

Declared at: llvm/include/llvm/ProfileData/SampleProf.h:378

Parameters

const llvm::sampleprof::LineLocation& Loc
llvm::StringRef CalleeName

const llvm::sampleprof::FunctionSamplesMap*
findFunctionSamplesMapAt(
    const llvm::sampleprof::LineLocation& Loc)
    const

Description

Returns the FunctionSamplesMap at the given \p Loc.

Declared at: llvm/include/llvm/ProfileData/SampleProf.h:367

Parameters

const llvm::sampleprof::LineLocation& Loc

void findInlinedFunctions(
    DenseSet<GlobalValue::GUID>& S,
    const llvm::Module* M,
    uint64_t Threshold) const

Description

Recursively traverses all children, if the total sample count of the corresponding function is no less than \p Threshold, add its corresponding GUID to \p S. Also traverse the BodySamples to add hot CallTarget's GUID to \p S.

Declared at: llvm/include/llvm/ProfileData/SampleProf.h:469

Parameters

DenseSet<GlobalValue::GUID>& S
const llvm::Module* M
uint64_t Threshold

ErrorOr<uint64_t> findSamplesAt(
    uint32_t LineOffset,
    uint32_t Discriminator) const

Description

Return the number of samples collected at the given location. Each location is specified by \p LineOffset and \p Discriminator. If the location is not found in profile, return error.

Declared at: llvm/include/llvm/ProfileData/SampleProf.h:340

Parameters

uint32_t LineOffset
uint32_t Discriminator

llvm::sampleprof::FunctionSamplesMap&
functionSamplesAt(
    const llvm::sampleprof::LineLocation& Loc)

Description

Return the function samples at the given callsite location.

Declared at: llvm/include/llvm/ProfileData/SampleProf.h:361

Parameters

const llvm::sampleprof::LineLocation& Loc

const llvm::sampleprof::BodySampleMap&
getBodySamples() const

Description

Return all the samples collected in the body of the function.

Declared at: llvm/include/llvm/ProfileData/SampleProf.h:437

const llvm::sampleprof::CallsiteSampleMap&
getCallsiteSamples() const

Description

Return all the callsite samples collected in the body of the function.

Declared at: llvm/include/llvm/ProfileData/SampleProf.h:440

static llvm::StringRef getCanonicalFnName(
    const llvm::Function& F)

Description

Return the canonical name for a function, taking into account suffix elision policy attributes.

Declared at: llvm/include/llvm/ProfileData/SampleProf.h:502

Parameters

const llvm::Function& F

uint64_t getEntrySamples() const

Description

Return the sample count of the first instruction of the function. The function can be either a standalone symbol or an inlined function.

Declared at: llvm/include/llvm/ProfileData/SampleProf.h:418

llvm::StringRef getFuncNameInModule(
    const llvm::Module* M) const

Description

Return the original function name if it exists in Module \p M.

Declared at: llvm/include/llvm/ProfileData/SampleProf.h:496

Parameters

const llvm::Module* M

static uint64_t getGUID(llvm::StringRef Name)

Declared at: llvm/include/llvm/ProfileData/SampleProf.h:569

Parameters

llvm::StringRef Name

uint64_t getHeadSamples() const

Description

Return the total number of branch samples that have the function as the branch target. This should be equivalent to the sample of the first instruction of the symbol. But as we directly get this info for raw profile without referring to potentially inaccurate debug info, this gives more accurate profile data and is preferred for standalone symbols.

Declared at: llvm/include/llvm/ProfileData/SampleProf.h:414

llvm::StringRef getName() const

Description

Return the function name.

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

llvm::StringRef getNameInModule(
    llvm::StringRef Name,
    const llvm::Module* M) const

Description

Translate \p Name into its original name in Module. When the Format is not SPF_Compact_Binary, \p Name needs no translation. When the Format is SPF_Compact_Binary, \p Name in current FunctionSamples is actually GUID of the original function name. getNameInModule will translate \p Name in current FunctionSamples into its original name. If the original name doesn't exist in \p M, return empty StringRef.

Declared at: llvm/include/llvm/ProfileData/SampleProf.h:534

Parameters

llvm::StringRef Name
const llvm::Module* M

static unsigned int getOffset(
    const llvm::DILocation* DIL)

Description

Returns the line offset to the start line of the subprogram. We assume that a single function will not exceed 65535 LOC.

Declared at: llvm/include/llvm/ProfileData/SampleProf.h:547

Parameters

const llvm::DILocation* DIL

uint64_t getTotalSamples() const

Description

Return the total number of samples collected inside the function.

Declared at: llvm/include/llvm/ProfileData/SampleProf.h:407

llvm::sampleprof_error merge(
    const llvm::sampleprof::FunctionSamples&
        Other,
    uint64_t Weight = 1)

Description

Merge the samples in \p Other into this one. Optionally scale samples by \p Weight.

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

Parameters

const llvm::sampleprof::FunctionSamples& Other
uint64_t Weight = 1

void print(llvm::raw_ostream& OS = dbgs(),
           unsigned int Indent = 0) const

Declared at: llvm/include/llvm/ProfileData/SampleProf.h:304

Parameters

llvm::raw_ostream& OS = dbgs()
unsigned int Indent = 0

void setName(llvm::StringRef FunctionName)

Description

Set the name of the function.

Declared at: llvm/include/llvm/ProfileData/SampleProf.h:490

Parameters

llvm::StringRef FunctionName