LLVM  8.0.1
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
llvm::sampleprof::FunctionSamples Class Reference

Representation of the samples collected for a function. More...

#include "llvm/ProfileData/SampleProf.h"

Collaboration diagram for llvm::sampleprof::FunctionSamples:
Collaboration graph
[legend]

Classes

class  GUIDToFuncNameMapper
 

Public Member Functions

 FunctionSamples ()=default
 
void print (raw_ostream &OS=dbgs(), unsigned Indent=0) const
 Print the samples collected for a function on stream OS. More...
 
void dump () const
 
sampleprof_error addTotalSamples (uint64_t Num, uint64_t Weight=1)
 
sampleprof_error addHeadSamples (uint64_t Num, uint64_t Weight=1)
 
sampleprof_error addBodySamples (uint32_t LineOffset, uint32_t Discriminator, uint64_t Num, uint64_t Weight=1)
 
sampleprof_error addCalledTargetSamples (uint32_t LineOffset, uint32_t Discriminator, StringRef FName, uint64_t Num, uint64_t Weight=1)
 
ErrorOr< uint64_t > findSamplesAt (uint32_t LineOffset, uint32_t Discriminator) const
 Return the number of samples collected at the given location. More...
 
ErrorOr< SampleRecord::CallTargetMapfindCallTargetMapAt (uint32_t LineOffset, uint32_t Discriminator) const
 Returns the call target map collected at a given location. More...
 
FunctionSamplesMapfunctionSamplesAt (const LineLocation &Loc)
 Return the function samples at the given callsite location. More...
 
const FunctionSamplesMapfindFunctionSamplesMapAt (const LineLocation &Loc) const
 Returns the FunctionSamplesMap at the given Loc. More...
 
const FunctionSamplesfindFunctionSamplesAt (const LineLocation &Loc, StringRef CalleeName) const
 Returns a pointer to FunctionSamples at the given callsite location Loc with callee CalleeName. More...
 
bool empty () const
 
uint64_t getTotalSamples () const
 Return the total number of samples collected inside the function. More...
 
uint64_t getHeadSamples () const
 Return the total number of branch samples that have the function as the branch target. More...
 
uint64_t getEntrySamples () const
 Return the sample count of the first instruction of the function. More...
 
const BodySampleMapgetBodySamples () const
 Return all the samples collected in the body of the function. More...
 
const CallsiteSampleMapgetCallsiteSamples () const
 Return all the callsite samples collected in the body of the function. More...
 
sampleprof_error merge (const FunctionSamples &Other, uint64_t Weight=1)
 Merge the samples in Other into this one. More...
 
void findInlinedFunctions (DenseSet< GlobalValue::GUID > &S, const Module *M, uint64_t Threshold) const
 Recursively traverses all children, if the total sample count of the corresponding function is no less than Threshold, add its corresponding GUID to S. More...
 
void setName (StringRef FunctionName)
 Set the name of the function. More...
 
StringRef getName () const
 Return the function name. More...
 
StringRef getFuncNameInModule (const Module *M) const
 Return the original function name if it exists in Module M. More...
 
StringRef getNameInModule (StringRef Name, const Module *M) const
 Translate Name into its original name in Module. More...
 
const FunctionSamplesfindFunctionSamples (const DILocation *DIL) const
 Get the FunctionSamples of the inline instance where DIL originates from. More...
 

Static Public Member Functions

static unsigned getOffset (const DILocation *DIL)
 Returns the line offset to the start line of the subprogram. More...
 
static uint64_t getGUID (StringRef Name)
 

Static Public Attributes

static SampleProfileFormat Format
 
static DenseMap< uint64_t, StringRefGUIDToFuncNameMap
 GUIDToFuncNameMap saves the mapping from GUID to the symbol name, for all the function symbols defined or declared in CurrentModule. More...
 
static ModuleCurrentModule
 

Detailed 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.

Definition at line 217 of file SampleProf.h.

Constructor & Destructor Documentation

◆ FunctionSamples()

llvm::sampleprof::FunctionSamples::FunctionSamples ( )
default

Member Function Documentation

◆ addBodySamples()

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

◆ addCalledTargetSamples()

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

◆ addHeadSamples()

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

◆ addTotalSamples()

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

◆ dump()

LLVM_DUMP_METHOD void FunctionSamples::dump ( ) const

Definition at line 192 of file SampleProf.cpp.

References llvm::dbgs(), and print().

◆ empty()

bool llvm::sampleprof::FunctionSamples::empty ( ) const
inline

Definition at line 318 of file SampleProf.h.

◆ findCallTargetMapAt()

ErrorOr<SampleRecord::CallTargetMap> llvm::sampleprof::FunctionSamples::findCallTargetMapAt ( uint32_t  LineOffset,
uint32_t  Discriminator 
) const
inline

Returns the call target map collected at a given location.

Each location is specified by LineOffset and Discriminator. If the location is not found in profile, return error.

Definition at line 270 of file SampleProf.h.

Referenced by callsiteIsHot(), and SortCallTargets().

◆ findFunctionSamples()

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

Get the FunctionSamples of the inline instance where DIL originates from.

The FunctionSamples of the instruction (Machine or IR) associated to 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.

Returns
the FunctionSamples pointer to the inlined instance.

Definition at line 171 of file SampleProf.cpp.

References assert(), findFunctionSamplesAt(), first, llvm::DILocation::getBaseDiscriminator(), llvm::getOffset(), llvm::SmallVectorTemplateBase< T >::push_back(), second, and llvm::SmallVectorBase::size().

◆ findFunctionSamplesAt()

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

Returns a pointer to FunctionSamples at the given callsite location Loc with callee CalleeName.

If no callsite can be found, relax the restriction to return the FunctionSamples at callsite location Loc with the maximum total sample count.

Definition at line 295 of file SampleProf.h.

References for(), llvm::Format, and llvm::sampleprof::getRepInFormat().

Referenced by callsiteIsHot(), and findFunctionSamples().

◆ findFunctionSamplesMapAt()

const FunctionSamplesMap* llvm::sampleprof::FunctionSamples::findFunctionSamplesMapAt ( const LineLocation Loc) const
inline

Returns the FunctionSamplesMap at the given Loc.

Definition at line 284 of file SampleProf.h.

Referenced by callsiteIsHot().

◆ findInlinedFunctions()

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

Recursively traverses all children, if the total sample count of the corresponding function is no less than Threshold, add its corresponding GUID to S.

Also traverse the BodySamples to add hot CallTarget's GUID to S.

Definition at line 383 of file SampleProf.h.

References Callee, llvm::Module::getFunction(), getGUID(), llvm::Function::getSubprogram(), llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, ValueInfoT, detail::DenseSetPair< ValueT > >, ValueInfoT >::insert(), Name, and Threshold.

Referenced by callsiteIsHot().

◆ findSamplesAt()

ErrorOr<uint64_t> llvm::sampleprof::FunctionSamples::findSamplesAt ( uint32_t  LineOffset,
uint32_t  Discriminator 
) const
inline

Return the number of samples collected at the given location.

Each location is specified by LineOffset and Discriminator. If the location is not found in profile, return error.

Definition at line 257 of file SampleProf.h.

Referenced by callsiteIsHot().

◆ functionSamplesAt()

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

Return the function samples at the given callsite location.

Definition at line 278 of file SampleProf.h.

Referenced by llvm::sampleprof::SampleProfileReaderGCC::readOneFunctionProfile(), and llvm::sampleprof::SampleProfileReaderBinary::readProfile().

◆ getBodySamples()

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

◆ getCallsiteSamples()

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

◆ getEntrySamples()

uint64_t llvm::sampleprof::FunctionSamples::getEntrySamples ( ) const
inline

Return the sample count of the first instruction of the function.

The function can be either a standalone symbol or an inlined function.

Definition at line 332 of file SampleProf.h.

References T.

Referenced by callsiteIsHot().

◆ getFuncNameInModule()

StringRef llvm::sampleprof::FunctionSamples::getFuncNameInModule ( const Module M) const
inline

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

Definition at line 410 of file SampleProf.h.

References Name.

Referenced by callsiteIsHot().

◆ getGUID()

static uint64_t llvm::sampleprof::FunctionSamples::getGUID ( StringRef  Name)
inlinestatic

◆ getHeadSamples()

uint64_t llvm::sampleprof::FunctionSamples::getHeadSamples ( ) const
inline

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.

Definition at line 328 of file SampleProf.h.

Referenced by llvm::SampleProfileSummaryBuilder::addRecord(), merge(), llvm::sampleprof::SampleProfileWriterText::write(), llvm::sampleprof::SampleProfileWriterBinary::write(), and llvm::sampleprof::SampleProfileWriterCompactBinary::write().

◆ getName()

StringRef llvm::sampleprof::FunctionSamples::getName ( ) const
inline

◆ getNameInModule()

StringRef llvm::sampleprof::FunctionSamples::getNameInModule ( StringRef  Name,
const Module M 
) const
inline

Translate Name into its original name in Module.

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

Definition at line 420 of file SampleProf.h.

References llvm::StringRef::data(), llvm::Format, llvm::getOffset(), llvm_unreachable, Name, and llvm::sampleprof::SPF_Compact_Binary.

◆ getOffset()

unsigned FunctionSamples::getOffset ( const DILocation DIL)
static

Returns the line offset to the start line of the subprogram.

We assume that a single function will not exceed 65535 LOC.

Definition at line 165 of file SampleProf.cpp.

Referenced by callsiteIsHot(), and SortCallTargets().

◆ getTotalSamples()

uint64_t llvm::sampleprof::FunctionSamples::getTotalSamples ( ) const
inline

◆ merge()

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

Merge the samples in Other into this one.

Optionally scale samples by Weight.

Definition at line 360 of file SampleProf.h.

References getBodySamples(), getCallsiteSamples(), getHeadSamples(), getName(), getTotalSamples(), I, llvm::MergeResult(), Name, and llvm::success.

◆ print()

void FunctionSamples::print ( raw_ostream OS = dbgs(),
unsigned  Indent = 0 
) const

Print the samples collected for a function on stream OS.

Definition at line 123 of file SampleProf.cpp.

References llvm::sampleprof::SampleSorter< LocationT, SampleT >::get(), llvm::raw_ostream::indent(), and SI.

Referenced by llvm::sampleprof::operator<<().

◆ setName()

void llvm::sampleprof::FunctionSamples::setName ( StringRef  FunctionName)
inline

Member Data Documentation

◆ CurrentModule

Module * llvm::sampleprof::FunctionSamples::CurrentModule
static

Definition at line 451 of file SampleProf.h.

◆ Format

SampleProfileFormat llvm::sampleprof::FunctionSamples::Format
static

Definition at line 447 of file SampleProf.h.

Referenced by llvm::sampleprof::SampleProfileReader::create().

◆ GUIDToFuncNameMap

DenseMap< uint64_t, StringRef > llvm::sampleprof::FunctionSamples::GUIDToFuncNameMap
static

GUIDToFuncNameMap saves the mapping from GUID to the symbol name, for all the function symbols defined or declared in CurrentModule.

Definition at line 450 of file SampleProf.h.


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