LLVM 20.0.0git
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
llvm::sampleprof::SampleRecord Class Reference

Representation of a single sample record. More...

#include "llvm/ProfileData/SampleProf.h"

Classes

struct  CallTargetComparator
 

Public Types

using CallTarget = std::pair< FunctionId, uint64_t >
 
using SortedCallTargetSet = std::set< CallTarget, CallTargetComparator >
 
using CallTargetMap = std::unordered_map< FunctionId, uint64_t >
 

Public Member Functions

 SampleRecord ()=default
 
sampleprof_error addSamples (uint64_t S, uint64_t Weight=1)
 Increment the number of samples for this record by S.
 
uint64_t removeSamples (uint64_t S)
 Decrease the number of samples for this record by S.
 
sampleprof_error addCalledTarget (FunctionId F, uint64_t S, uint64_t Weight=1)
 Add called function F with samples S.
 
uint64_t removeCalledTarget (FunctionId F)
 Remove called function from the call target map.
 
bool hasCalls () const
 Return true if this sample record contains function calls.
 
uint64_t getSamples () const
 
const CallTargetMapgetCallTargets () const
 
const SortedCallTargetSet getSortedCallTargets () const
 
uint64_t getCallTargetSum () const
 
sampleprof_error merge (const SampleRecord &Other, uint64_t Weight=1)
 Merge the samples in Other into this record.
 
void print (raw_ostream &OS, unsigned Indent) const
 Print the sample record to the stream OS indented by Indent.
 
void dump () const
 
bool operator== (const SampleRecord &Other) const
 
bool operator!= (const SampleRecord &Other) const
 

Static Public Member Functions

static const SortedCallTargetSet sortCallTargets (const CallTargetMap &Targets)
 Sort call targets in descending order of call frequency.
 
static const CallTargetMap adjustCallTargets (const CallTargetMap &Targets, float DistributionFactor)
 Prorate call targets by a distribution factor.
 

Detailed Description

Representation of a single sample record.

A sample record is represented by a positive integer value, which indicates how frequently was the associated line location executed.

Additionally, if the associated location contains a function call, the record will hold a list of all the possible called targets. For direct calls, this will be the exact function being invoked. For indirect calls (function pointers, virtual table dispatch), this will be a list of one or more functions.

Definition at line 325 of file SampleProf.h.

Member Typedef Documentation

◆ CallTarget

Definition at line 327 of file SampleProf.h.

◆ CallTargetMap

Definition at line 338 of file SampleProf.h.

◆ SortedCallTargetSet

Definition at line 337 of file SampleProf.h.

Constructor & Destructor Documentation

◆ SampleRecord()

llvm::sampleprof::SampleRecord::SampleRecord ( )
default

Member Function Documentation

◆ addCalledTarget()

sampleprof_error llvm::sampleprof::SampleRecord::addCalledTarget ( FunctionId  F,
uint64_t  S,
uint64_t  Weight = 1 
)
inline

Add called function F with samples S.

Optionally scale sample count S by Weight.

Sample counts accumulate using saturating arithmetic, to avoid wrapping around unsigned integers.

Definition at line 367 of file SampleProf.h.

References llvm::counter_overflow, F, llvm::SaturatingMultiplyAdd(), and llvm::success.

Referenced by merge().

◆ addSamples()

sampleprof_error llvm::sampleprof::SampleRecord::addSamples ( uint64_t  S,
uint64_t  Weight = 1 
)
inline

Increment the number of samples for this record by S.

Optionally scale sample count S by Weight.

Sample counts accumulate using saturating arithmetic, to avoid wrapping around unsigned integers.

Definition at line 346 of file SampleProf.h.

References llvm::counter_overflow, llvm::SaturatingMultiplyAdd(), and llvm::success.

Referenced by merge().

◆ adjustCallTargets()

static const CallTargetMap llvm::sampleprof::SampleRecord::adjustCallTargets ( const CallTargetMap Targets,
float  DistributionFactor 
)
inlinestatic

Prorate call targets by a distribution factor.

Definition at line 416 of file SampleProf.h.

◆ dump()

LLVM_DUMP_METHOD void SampleRecord::dump ( ) const

Definition at line 145 of file SampleProf.cpp.

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

◆ getCallTargets()

const CallTargetMap & llvm::sampleprof::SampleRecord::getCallTargets ( ) const
inline

◆ getCallTargetSum()

uint64_t llvm::sampleprof::SampleRecord::getCallTargetSum ( ) const
inline

Definition at line 398 of file SampleProf.h.

References I.

◆ getSamples()

uint64_t llvm::sampleprof::SampleRecord::getSamples ( ) const
inline

◆ getSortedCallTargets()

const SortedCallTargetSet llvm::sampleprof::SampleRecord::getSortedCallTargets ( ) const
inline

◆ hasCalls()

bool llvm::sampleprof::SampleRecord::hasCalls ( ) const
inline

Return true if this sample record contains function calls.

Definition at line 390 of file SampleProf.h.

Referenced by print().

◆ merge()

sampleprof_error SampleRecord::merge ( const SampleRecord Other,
uint64_t  Weight = 1 
)

Merge the samples in Other into this record.

Optionally scale sample counts by Weight.

Definition at line 119 of file SampleProf.cpp.

References addCalledTarget(), addSamples(), I, llvm::mergeSampleProfErrors(), and llvm::Other.

◆ operator!=()

bool llvm::sampleprof::SampleRecord::operator!= ( const SampleRecord Other) const
inline

Definition at line 435 of file SampleProf.h.

References llvm::Other.

◆ operator==()

bool llvm::sampleprof::SampleRecord::operator== ( const SampleRecord Other) const
inline

Definition at line 431 of file SampleProf.h.

References llvm::Other.

◆ print()

void SampleRecord::print ( raw_ostream OS,
unsigned  Indent 
) const

Print the sample record to the stream OS indented by Indent.

Definition at line 134 of file SampleProf.cpp.

References getSortedCallTargets(), hasCalls(), I, and OS.

Referenced by dump(), and llvm::sampleprof::operator<<().

◆ removeCalledTarget()

uint64_t llvm::sampleprof::SampleRecord::removeCalledTarget ( FunctionId  F)
inline

Remove called function from the call target map.

Return the target sample count of the called function.

Definition at line 379 of file SampleProf.h.

References F, and I.

◆ removeSamples()

uint64_t llvm::sampleprof::SampleRecord::removeSamples ( uint64_t  S)
inline

Decrease the number of samples for this record by S.

Return the amout of samples actually decreased.

Definition at line 355 of file SampleProf.h.

◆ sortCallTargets()

static const SortedCallTargetSet llvm::sampleprof::SampleRecord::sortCallTargets ( const CallTargetMap Targets)
inlinestatic

Sort call targets in descending order of call frequency.

Definition at line 407 of file SampleProf.h.

Referenced by getSortedCallTargets(), and GetSortedValueDataFromCallTargets().


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