LLVM: llvm::sampleprof::FunctionSamples Class Reference (original) (raw)

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

#include "[llvm/ProfileData/SampleProf.h](SampleProf%5F8h%5Fsource.html)"

Public Member Functions
FunctionSamples ()=default
LLVM_ABI void print (raw_ostream &OS=dbgs(), unsigned Indent=0) const
Print the samples collected for a function on stream OS.
LLVM_ABI void dump () const
sampleprof_error addTotalSamples (uint64_t Num, uint64_t Weight=1)
void removeTotalSamples (uint64_t Num)
void setTotalSamples (uint64_t Num)
void setHeadSamples (uint64_t Num)
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, FunctionId Func, uint64_t Num, uint64_t Weight=1)
sampleprof_error addSampleRecord (LineLocation Location, const SampleRecord &SampleRecord, uint64_t Weight=1)
uint64_t removeCalledTargetAndBodySample (uint32_t LineOffset, uint32_t Discriminator, FunctionId Func)
void removeAllCallsiteSamples ()
void updateCallsiteSamples ()
void updateTotalSamples ()
void setContextSynthetic ()
void setContextAttribute (ContextAttributeMask Attr)
const LineLocation & mapIRLocToProfileLoc (const LineLocation &IRLoc) const
ErrorOr< uint64_t > findSamplesAt (uint32_t LineOffset, uint32_t Discriminator) const
Return the number of samples collected at the given location.
ErrorOr< const SampleRecord::CallTargetMap & > findCallTargetMapAt (uint32_t LineOffset, uint32_t Discriminator) const
Returns the call target map collected at a given location.
ErrorOr< const SampleRecord::CallTargetMap & > findCallTargetMapAt (const LineLocation &CallSite) const
Returns the call target map collected at a given location specified by CallSite.
FunctionSamplesMap & functionSamplesAt (const LineLocation &Loc)
Return the function samples at the given callsite location.
const FunctionSamplesMap * findFunctionSamplesMapAt (const LineLocation &Loc) const
Returns the FunctionSamplesMap at the given Loc.
const TypeCountMap * findCallsiteTypeSamplesAt (const LineLocation &Loc) const
Returns the TypeCountMap for inlined callsites at the given Loc.
LLVM_ABI const FunctionSamples * findFunctionSamplesAt (const LineLocation &Loc, StringRef CalleeName, SampleProfileReaderItaniumRemapper *Remapper, const HashKeyMap< std::unordered_map, FunctionId, FunctionId > *FuncNameToProfNameMap=nullptr) const
Returns a pointer to FunctionSamples at the given callsite location Loc with callee CalleeName.
bool empty () const
uint64_t getTotalSamples () const
Return the total number of samples collected inside the function.
uint64_t getHeadSamples () const
For top-level functions, return the total number of branch samples that have the function as the branch target (or 0 otherwise).
uint64_t getHeadSamplesEstimate () const
Return an estimate of the sample count of the function entry basic block.
const BodySampleMap & getBodySamples () const
Return all the samples collected in the body of the function.
const CallsiteSampleMap & getCallsiteSamples () const
Return all the callsite samples collected in the body of the function.
const CallsiteTypeMap & getCallsiteTypeCounts () const
Returns vtable access samples for the C++ types collected in this function.
TypeCountMap & getTypeSamplesAt (const LineLocation &Loc)
Returns the vtable access samples for the C++ types for Loc.
sampleprof_error addTypeSamplesAt (const LineLocation &Loc, FunctionId Type, uint64_t Count)
At location Loc, add a type sample for the given Type with Count.
template<typename T>
sampleprof_error addCallsiteVTableTypeProfAt (const LineLocation &Loc, const T &Other, uint64_t Weight=1)
Scale Other sample counts by Weight and add the scaled result to the type samples for Loc.
uint64_t getMaxCountInside (bool SkipCallSite=false) const
Return the maximum of sample counts in a function body.
sampleprof_error merge (const FunctionSamples &Other, uint64_t Weight=1)
Merge the samples in Other into this one.
void findInlinedFunctions (DenseSet< GlobalValue::GUID > &S, const HashKeyMap< std::unordered_map, FunctionId, Function * > &SymbolMap, 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.
void setFunction (FunctionId NewFunctionID)
Set the name of the function.
FunctionId getFunction () const
Return the function name.
StringRef getFuncName () const
Return the original function name.
void setFunctionHash (uint64_t Hash)
uint64_t getFunctionHash () const
void setIRToProfileLocationMap (const LocToLocMap *LTLM)
StringRef getFuncName (FunctionId Func) const
Translate Func into its original name.
LLVM_ABI const FunctionSamples * findFunctionSamples (const DILocation *DIL, SampleProfileReaderItaniumRemapper *Remapper=nullptr, const HashKeyMap< std::unordered_map, FunctionId, FunctionId > *FuncNameToProfNameMap=nullptr) const
Get the FunctionSamples of the inline instance where DIL originates from.
SampleContext & getContext () const
void setContext (const SampleContext &FContext)
uint64_t getGUID () const
Return the GUID of the context's name.
LLVM_ABI void findAllNames (DenseSet< FunctionId > &NameSet) const
bool operator== (const FunctionSamples &Other) const
bool operator!= (const FunctionSamples &Other) const
Static Public Member Functions
static StringRef getCanonicalFnName (const Function &F)
Return the canonical name for a function, taking into account suffix elision policy attributes.
static StringRef getCanonicalFnName (StringRef FnName, StringRef Attr="selected")
static StringRef getCanonicalFnName (StringRef FnName, ArrayRef< StringRef > Suffixes, StringRef Attr="selected")
static LLVM_ABI unsigned getOffset (const DILocation *DIL)
Returns the line offset to the start line of the subprogram.
static LLVM_ABI LineLocation getCallSiteIdentifier (const DILocation *DIL, bool ProfileIsFS=false)
Returns a unique call site identifier for a given debug location of a call instruction.
static uint64_t getCallSiteHash (FunctionId Callee, const LineLocation &Callsite)
Returns a unique hash code for a combination of a callsite location and the callee function name.
Public Attributes
DenseMap< uint64_t, StringRef > * GUIDToFuncNameMap = nullptr
GUIDToFuncNameMap saves the mapping from GUID to the symbol name, for all the function symbols defined or declared in current module.
Static Public Attributes
static constexpr const char * LLVMSuffix = ".llvm."
Name suffixes which canonicalization should handle to avoid profile mismatch.
static constexpr const char * PartSuffix = ".part."
static constexpr const char * UniqSuffix = ".__uniq."
static LLVM_ABI bool ProfileIsProbeBased = false
static LLVM_ABI bool ProfileIsCS = false
static LLVM_ABI bool ProfileIsPreInlined = false
static LLVM_ABI bool UseMD5 = false
Whether the profile uses MD5 to represent string.
static LLVM_ABI bool HasUniqSuffix = true
Whether the profile contains any ".__uniq." suffix in a name.
static LLVM_ABI bool ProfileIsFS = false
If this profile uses flow sensitive discriminators.

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 777 of file SampleProf.h.

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

addBodySamples()

addCalledTargetSamples()

addCallsiteVTableTypeProfAt()

addHeadSamples()

addSampleRecord()

addTotalSamples()

addTypeSamplesAt()

dump()

empty()

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

findAllNames()

findCallsiteTypeSamplesAt()

findCallTargetMapAt() [1/2]

Returns the call target map collected at a given location specified by CallSite.

If the location is not found in profile, return error.

Definition at line 941 of file SampleProf.h.

References mapIRLocToProfileLoc().

findCallTargetMapAt() [2/2]

findFunctionSamples()

findFunctionSamplesAt()

Returns a pointer to FunctionSamples at the given callsite location [Loc](namespacellvm%5F1%5F1Loc.html) with callee CalleeName.

If no callsite can be found, relax the restriction to return the FunctionSamples at callsite location [Loc](namespacellvm%5F1%5F1Loc.html) with the maximum total sample count. If Remapper or FuncNameToProfNameMap is not nullptr, use them to find FunctionSamples with equivalent name as CalleeName.

Definition at line 351 of file SampleProf.cpp.

References llvm::StringRef::empty(), llvm::sampleprof::HashKeyMap< MapT, KeyT, ValueT, MapTArgs >::find(), FunctionSamples(), getCanonicalFnName(), llvm::sampleprof::getRepInFormat(), I, llvm::sampleprof::SampleProfileReaderItaniumRemapper::lookUpNameInProfile(), and mapIRLocToProfileLoc().

findFunctionSamplesMapAt()

findInlinedFunctions()

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 1151 of file SampleProf.h.

References F, getFunction(), getGUID(), llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::insert(), and llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::lookup().

findSamplesAt()

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 917 of file SampleProf.h.

References mapIRLocToProfileLoc().

functionSamplesAt()

getBodySamples()

getCallSiteHash()

getCallSiteIdentifier()

getCallsiteSamples()

getCallsiteTypeCounts()

getCanonicalFnName() [1/3]

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

Definition at line 1200 of file SampleProf.h.

References F, and getCanonicalFnName().

Referenced by llvm::sampleprof::SampleProfileReaderExtBinaryBase::collectFuncsFromModule(), findFunctionSamplesAt(), llvm::SampleContextTracker::getAllContextSamplesFor(), llvm::SampleContextTracker::getBaseSamplesFor(), llvm::SampleContextTracker::getCalleeContextSamplesFor(), getCanonicalFnName(), getCanonicalFnName(), llvm::PseudoProbeManager::getDesc(), llvm::memprof::getGUID(), and llvm::sampleprof::SampleProfileReader::getSamplesFor().

getCanonicalFnName() [2/3]

getCanonicalFnName() [3/3]

getContext()

SampleContext & llvm::sampleprof::FunctionSamples::getContext ( ) const inline

Definition at line 1308 of file SampleProf.h.

Referenced by llvm::SampleContextTracker::getContextSamplesFor(), llvm::SampleContextTracker::markContextSamplesInlined(), llvm::SampleContextTracker::populateFuncToCtxtMap(), llvm::sampleprof::ProfileConverter::ProfileConverter(), llvm::SampleContextTracker::promoteMergeContextSamplesTree(), llvm::sampleprof::SampleProfileReaderExtBinaryBase::readFuncMetadata(), llvm::sampleprof::SampleProfileReaderText::readImpl(), llvm::sampleprof::SampleProfileWriterBinary::writeBody(), llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeFuncMetadata(), llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeSample(), and llvm::sampleprof::SampleProfileWriterText::writeSample().

getFuncName() [1/2]

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

getFuncName() [2/2]

Translate Func into its original name.

When profile doesn't use MD5, Func needs no translation. When profile uses MD5, Func in current FunctionSamples is actually GUID of the original function name. getFuncName will translate Func in current FunctionSamples into its original name by looking up in the function map GUIDToFuncNameMap. If the original name doesn't exist in the map, return empty StringRef.

Definition at line 1256 of file SampleProf.h.

References assert(), GUIDToFuncNameMap, and UseMD5.

getFunction()

FunctionId llvm::sampleprof::FunctionSamples::getFunction ( ) const inline

getFunctionHash()

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

getGUID()

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

getHeadSamples()

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

getHeadSamplesEstimate()

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

getMaxCountInside()

uint64_t llvm::sampleprof::FunctionSamples::getMaxCountInside ( bool SkipCallSite = false) const inline

Return the maximum of sample counts in a function body.

When SkipCallSite is false, which is the default, the return count includes samples in the inlined functions. When SkipCallSite is true, the return count only considers the body samples.

Definition at line 1090 of file SampleProf.h.

References llvm::CallingConv::C, F, getBodySamples(), and getCallsiteSamples().

getOffset()

getTotalSamples()

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

getTypeSamplesAt()

mapIRLocToProfileLoc()

merge()

Merge the samples in Other into this one.

Optionally scale samples by Weight.

Definition at line 1104 of file SampleProf.h.

References addCallsiteVTableTypeProfAt(), addHeadSamples(), addTotalSamples(), FunctionSamples(), functionSamplesAt(), GUIDToFuncNameMap, llvm::hash_mismatch, I, merge(), llvm::mergeSampleProfErrors(), llvm::Other, and llvm::success.

Referenced by llvm::SampleContextTracker::createContextLessProfileMap(), merge(), and llvm::sampleprof::SampleContextTrimmer::trimAndMergeColdContextProfiles().

operator!=()

operator==()

print()

removeAllCallsiteSamples()

void llvm::sampleprof::FunctionSamples::removeAllCallsiteSamples ( ) inline

removeCalledTargetAndBodySample()

removeTotalSamples()

void llvm::sampleprof::FunctionSamples::removeTotalSamples ( uint64_t Num) inline

setContext()

void llvm::sampleprof::FunctionSamples::setContext ( const SampleContext & FContext) inline

setContextAttribute()

setContextSynthetic()

void llvm::sampleprof::FunctionSamples::setContextSynthetic ( ) inline

setFunction()

void llvm::sampleprof::FunctionSamples::setFunction ( FunctionId NewFunctionID) inline

setFunctionHash()

void llvm::sampleprof::FunctionSamples::setFunctionHash ( uint64_t Hash) inline

setHeadSamples()

void llvm::sampleprof::FunctionSamples::setHeadSamples ( uint64_t Num) inline

setIRToProfileLocationMap()

void llvm::sampleprof::FunctionSamples::setIRToProfileLocationMap ( const LocToLocMap * LTLM) inline

setTotalSamples()

void llvm::sampleprof::FunctionSamples::setTotalSamples ( uint64_t Num) inline

updateCallsiteSamples()

void llvm::sampleprof::FunctionSamples::updateCallsiteSamples ( ) inline

updateTotalSamples()

void llvm::sampleprof::FunctionSamples::updateTotalSamples ( ) inline

GUIDToFuncNameMap

HasUniqSuffix

bool llvm::sampleprof::FunctionSamples::HasUniqSuffix = true static

LLVMSuffix

const char* llvm::sampleprof::FunctionSamples::LLVMSuffix = ".llvm." staticconstexpr

PartSuffix

const char* llvm::sampleprof::FunctionSamples::PartSuffix = ".part." staticconstexpr

ProfileIsCS

bool llvm::sampleprof::FunctionSamples::ProfileIsCS = false static

Definition at line 1304 of file SampleProf.h.

Referenced by llvm::SampleProfileSummaryBuilder::computeSummaryForProfiles(), llvm::sampleprof::SampleProfileWriter::create(), getHeadSamplesEstimate(), llvm::sampleprof::ProfiledCallGraph::ProfiledCallGraph(), llvm::sampleprof::SampleProfileReaderText::readImpl(), llvm::sampleprof::SampleProfileReaderExtBinaryBase::readOneSection(), llvm::SampleProfileMatcher::runOnModule(), llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeFuncMetadata(), llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeFuncMetadata(), llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeFuncOffsetTable(), llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeOneSection(), and llvm::sampleprof::SampleProfileWriterText::writeSample().

ProfileIsFS

bool llvm::sampleprof::FunctionSamples::ProfileIsFS = false static

ProfileIsPreInlined

bool llvm::sampleprof::FunctionSamples::ProfileIsPreInlined = false static

ProfileIsProbeBased

bool llvm::sampleprof::FunctionSamples::ProfileIsProbeBased = false static

Definition at line 1302 of file SampleProf.h.

Referenced by llvm::sampleprof::SampleProfileWriter::create(), getCallSiteIdentifier(), llvm::MIRProfileLoader::getInstWeight(), llvm::SampleProfileLoaderBaseImpl< FT >::getInstWeight(), llvm::SampleProfileLoaderBaseImpl< FT >::getProbeWeight(), llvm::sampleprof::SampleProfileReaderText::readImpl(), llvm::sampleprof::SampleProfileReaderExtBinaryBase::readOneSection(), llvm::MIRProfileLoader::runOnFunction(), llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeFuncMetadata(), llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeFuncMetadata(), llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeOneSection(), and llvm::sampleprof::SampleProfileWriterText::writeSample().

UniqSuffix

const char* llvm::sampleprof::FunctionSamples::UniqSuffix = ".__uniq." staticconstexpr

UseMD5

bool llvm::sampleprof::FunctionSamples::UseMD5 = false static

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