LLVM 22.0.0git
llvm::sampleprof Namespace Reference

Classes

class  DefaultFunctionPruningStrategy
class  FunctionId
 This class represents a function that is read from a sample profile. More...
class  FunctionPruningStrategy
 When writing a profile with size limit, user may want to use a different strategy to reduce function count other than dropping functions with fewest samples first. More...
class  FunctionSamples
 Representation of the samples collected for a function. More...
class  HashKeyMap
 This class is a wrapper to associative container MapT<KeyT, ValueT> using the hash value of the original key as the new key. More...
struct  LineLocation
 Represents the relative location of an instruction. More...
struct  LineLocationHash
class  ProfileConverter
 Helper class for profile conversion. More...
class  ProfiledCallGraph
struct  ProfiledCallGraphEdge
struct  ProfiledCallGraphNode
class  ProfileSymbolList
 ProfileSymbolList records the list of function symbols shown up in the binary used to generate the profile. More...
class  SampleContext
struct  SampleContextFrame
struct  SampleContextFrameHash
class  SampleContextTrimmer
 SampleContextTrimmer impelements helper functions to trim, merge cold context profiles. More...
class  SampleProfileMap
 This class provides operator overloads to the map container using MD5 as the key type, so that existing code can still work in most cases using SampleContext as key. More...
class  SampleProfileReader
 Sample-based profile reader. More...
class  SampleProfileReaderBinary
class  SampleProfileReaderExtBinary
class  SampleProfileReaderExtBinaryBase
 SampleProfileReaderExtBinaryBase/SampleProfileWriterExtBinaryBase defines the basic structure of the extensible binary format. More...
class  SampleProfileReaderGCC
class  SampleProfileReaderItaniumRemapper
 SampleProfileReaderItaniumRemapper remaps the profile data from a sample profile data reader, by applying a provided set of equivalences between components of the symbol names in the profile. More...
class  SampleProfileReaderRawBinary
class  SampleProfileReaderText
class  SampleProfileWriter
 Sample-based profile writer. Base class. More...
class  SampleProfileWriterBinary
 Sample-based profile writer (binary format). More...
class  SampleProfileWriterExtBinary
class  SampleProfileWriterExtBinaryBase
class  SampleProfileWriterRawBinary
class  SampleProfileWriterText
 Sample-based profile writer (text format). More...
class  SampleRecord
 Representation of a single sample record. More...
class  SampleSorter
 Sort a LocationT->SampleT map by LocationT. More...
struct  SecHdrTableEntry

Typedefs

using TypeCountMap = std::map<FunctionId, uint64_t>
 Key represents type of a C++ polymorphic class type by its vtable and value represents its counter.
using SampleContextFrameVector = SmallVector<SampleContextFrame, 1>
using SampleContextFrames = ArrayRef<SampleContextFrame>
using BodySampleMap = std::map<LineLocation, SampleRecord>
using FunctionSamplesMap = std::map<FunctionId, FunctionSamples>
using CallsiteSampleMap = std::map<LineLocation, FunctionSamplesMap>
using CallsiteTypeMap = std::map<LineLocation, TypeCountMap>
using LocToLocMap
using NameFunctionSamples = std::pair<hash_code, const FunctionSamples *>
using InlineCallStack = SmallVector<FunctionSamples *, 10>

Enumerations

enum  SampleProfileFormat {
  SPF_None = 0 , SPF_Text = 0x1 , SPF_Compact_Binary = 0x2 , SPF_GCC = 0x3 ,
  SPF_Ext_Binary = 0x4 , SPF_Binary = 0xff
}
enum  SampleProfileLayout { SPL_None = 0 , SPL_Nest = 0x1 , SPL_Flat = 0x2 }
enum  SecType {
  SecInValid = 0 , SecProfSummary = 1 , SecNameTable = 2 , SecProfileSymbolList = 3 ,
  SecFuncOffsetTable = 4 , SecFuncMetadata = 5 , SecCSNameTable = 6 , SecFuncProfileFirst = 32 ,
  SecLBRProfile = SecFuncProfileFirst
}
enum class  SecCommonFlags : uint32_t { SecFlagInValid = 0 , SecFlagCompress = (1 << 0) , SecFlagFlat = (1 << 1) }
enum class  SecNameTableFlags : uint32_t { SecFlagInValid = 0 , SecFlagMD5Name = (1 << 0) , SecFlagFixedLengthMD5 = (1 << 1) , SecFlagUniqSuffix = (1 << 2) }
enum class  SecProfSummaryFlags : uint32_t {
  SecFlagInValid = 0 , SecFlagPartial = (1 << 0) , SecFlagFullContext = (1 << 1) , SecFlagFSDiscriminator = (1 << 2) ,
  SecFlagIsPreInlined = (1 << 4) , SecFlagHasVTableTypeProf = (1 << 5)
}
enum class  SecFuncMetadataFlags : uint32_t { SecFlagInvalid = 0 , SecFlagIsProbeBased = (1 << 0) , SecFlagHasAttribute = (1 << 1) }
enum class  SecFuncOffsetFlags : uint32_t { SecFlagInvalid = 0 , SecFlagOrdered = (1 << 0) }
enum  ContextStateMask {
  UnknownContext = 0x0 , RawContext = 0x1 , SyntheticContext = 0x2 , InlinedContext = 0x4 ,
  MergedContext = 0x8
}
enum  ContextAttributeMask { ContextNone = 0x0 , ContextWasInlined = 0x1 , ContextShouldBeInlined = 0x2 , ContextDuplicatedIntoBase }
enum  HistType {
  HIST_TYPE_INTERVAL , HIST_TYPE_POW2 , HIST_TYPE_SINGLE_VALUE , HIST_TYPE_CONST_DELTA ,
  HIST_TYPE_INDIR_CALL , HIST_TYPE_AVERAGE , HIST_TYPE_IOR , HIST_TYPE_INDIR_CALL_TOPN
}
enum  SectionLayout { DefaultLayout , CtxSplitLayout , NumOfLayout }
enum  FSDiscriminatorPass {
  Base = 0 , Pass0 = 0 , Pass1 = 1 , Pass2 = 2 ,
  Pass3 = 3 , Pass4 = 4 , PassLast = 4
}

Functions

bool operator== (const FunctionId &LHS, const FunctionId &RHS)
bool operator!= (const FunctionId &LHS, const FunctionId &RHS)
bool operator< (const FunctionId &LHS, const FunctionId &RHS)
bool operator<= (const FunctionId &LHS, const FunctionId &RHS)
bool operator> (const FunctionId &LHS, const FunctionId &RHS)
bool operator>= (const FunctionId &LHS, const FunctionId &RHS)
raw_ostreamoperator<< (raw_ostream &OS, const FunctionId &Obj)
uint64_t MD5Hash (const FunctionId &Obj)
uint64_t hash_value (const FunctionId &Obj)
static uint64_t SPMagic (SampleProfileFormat Format=SPF_Binary)
static uint64_t SPVersion ()
static std::string getSecName (SecType Type)
template<class SecFlagType>
static void verifySecFlag (SecType Type, SecFlagType Flag)
template<class SecFlagType>
static void addSecFlag (SecHdrTableEntry &Entry, SecFlagType Flag)
template<class SecFlagType>
static void removeSecFlag (SecHdrTableEntry &Entry, SecFlagType Flag)
template<class SecFlagType>
static bool hasSecFlag (const SecHdrTableEntry &Entry, SecFlagType Flag)
LLVM_ABI raw_ostreamoperator<< (raw_ostream &OS, const LineLocation &Loc)
std::error_code serializeTypeMap (const TypeCountMap &Map, const MapVector< FunctionId, uint32_t > &NameTable, raw_ostream &OS)
 Write Map to the output stream.
LLVM_ABI raw_ostreamoperator<< (raw_ostream &OS, const SampleRecord &Sample)
static hash_code hash_value (const SampleContextFrame &arg)
static hash_code hash_value (const SampleContext &Context)
raw_ostreamoperator<< (raw_ostream &OS, const SampleContext &Context)
static FunctionId getRepInFormat (StringRef Name)
 Get the proper representation of a string according to whether the current Format uses MD5 to represent the string.
LLVM_ABI raw_ostreamoperator<< (raw_ostream &OS, const FunctionSamples &FS)
LLVM_ABI void sortFuncProfiles (const SampleProfileMap &ProfileMap, std::vector< NameFunctionSamples > &SortedProfiles)

Variables

constexpr char kVTableProfPrefix [] = "vtables "
const std::array< SmallVector< SecHdrTableEntry, 8 >, NumOfLayoutExtBinaryHdrLayoutTable

Typedef Documentation

◆ BodySampleMap

Definition at line 763 of file SampleProf.h.

◆ CallsiteSampleMap

◆ CallsiteTypeMap

Definition at line 768 of file SampleProf.h.

◆ FunctionSamplesMap

Definition at line 766 of file SampleProf.h.

◆ InlineCallStack

◆ LocToLocMap

Initial value:
std::unordered_map<LineLocation, LineLocation, LineLocationHash>

Definition at line 769 of file SampleProf.h.

◆ NameFunctionSamples

Definition at line 1471 of file SampleProf.h.

◆ SampleContextFrames

◆ SampleContextFrameVector

◆ TypeCountMap

Key represents type of a C++ polymorphic class type by its vtable and value represents its counter.

TODO: The class name FunctionId should be renamed to SymbolId in a refactor change.

Definition at line 330 of file SampleProf.h.

Enumeration Type Documentation

◆ ContextAttributeMask

Enumerator
ContextNone 
ContextWasInlined 
ContextShouldBeInlined 
ContextDuplicatedIntoBase 

Definition at line 487 of file SampleProf.h.

◆ ContextStateMask

Enumerator
UnknownContext 
RawContext 
SyntheticContext 
InlinedContext 
MergedContext 

Definition at line 478 of file SampleProf.h.

◆ FSDiscriminatorPass

Enumerator
Base 
Pass0 
Pass1 
Pass2 
Pass3 
Pass4 
PassLast 

Definition at line 57 of file Discriminator.h.

◆ HistType

Enumerator
HIST_TYPE_INTERVAL 
HIST_TYPE_POW2 
HIST_TYPE_SINGLE_VALUE 
HIST_TYPE_CONST_DELTA 
HIST_TYPE_INDIR_CALL 
HIST_TYPE_AVERAGE 
HIST_TYPE_IOR 
HIST_TYPE_INDIR_CALL_TOPN 

Definition at line 886 of file SampleProfReader.h.

◆ SampleProfileFormat

Enumerator
SPF_None 
SPF_Text 
SPF_Compact_Binary 
SPF_GCC 
SPF_Ext_Binary 
SPF_Binary 

Definition at line 96 of file SampleProf.h.

◆ SampleProfileLayout

Enumerator
SPL_None 
SPL_Nest 
SPL_Flat 

Definition at line 105 of file SampleProf.h.

◆ SecCommonFlags

Enumerator
SecFlagInValid 
SecFlagCompress 
SecFlagFlat 

Definition at line 174 of file SampleProf.h.

◆ SecFuncMetadataFlags

Enumerator
SecFlagInvalid 
SecFlagIsProbeBased 
SecFlagHasAttribute 

Definition at line 214 of file SampleProf.h.

◆ SecFuncOffsetFlags

Enumerator
SecFlagInvalid 
SecFlagOrdered 

Definition at line 220 of file SampleProf.h.

◆ SecNameTableFlags

Enumerator
SecFlagInValid 
SecFlagMD5Name 
SecFlagFixedLengthMD5 
SecFlagUniqSuffix 

Definition at line 184 of file SampleProf.h.

◆ SecProfSummaryFlags

Enumerator
SecFlagInValid 
SecFlagPartial 

SecFlagPartial means the profile is for common/shared code.

The common profile is usually merged from profiles collected from running other targets.

SecFlagFullContext 

SecFlagContext means this is context-sensitive flat profile for CSSPGO.

SecFlagFSDiscriminator 

SecFlagFSDiscriminator means this profile uses flow-sensitive discriminators.

SecFlagIsPreInlined 

SecFlagIsPreInlined means this profile contains ShouldBeInlined contexts thus this is CS preinliner computed.

SecFlagHasVTableTypeProf 

SecFlagHasVTableTypeProf means this profile contains vtable type profiles.

Definition at line 194 of file SampleProf.h.

◆ SectionLayout

Enumerator
DefaultLayout 
CtxSplitLayout 
NumOfLayout 

Definition at line 30 of file SampleProfWriter.h.

◆ SecType

Enumerator
SecInValid 
SecProfSummary 
SecNameTable 
SecProfileSymbolList 
SecFuncOffsetTable 
SecFuncMetadata 
SecCSNameTable 
SecFuncProfileFirst 
SecLBRProfile 

Definition at line 123 of file SampleProf.h.

Function Documentation

◆ addSecFlag()

template<class SecFlagType>
void llvm::sampleprof::addSecFlag ( SecHdrTableEntry & Entry,
SecFlagType Flag )
inlinestatic

◆ getRepInFormat()

◆ getSecName()

std::string llvm::sampleprof::getSecName ( SecType Type)
inlinestatic

◆ hash_value() [1/3]

◆ hash_value() [2/3]

hash_code llvm::sampleprof::hash_value ( const SampleContext & Context)
inlinestatic

Definition at line 752 of file SampleProf.h.

◆ hash_value() [3/3]

hash_code llvm::sampleprof::hash_value ( const SampleContextFrame & arg)
inlinestatic

Definition at line 531 of file SampleProf.h.

References llvm::sampleprof::SampleContextFrame::getHashCode().

◆ hasSecFlag()

◆ MD5Hash()

◆ operator!=()

bool llvm::sampleprof::operator!= ( const FunctionId & LHS,
const FunctionId & RHS )
inline

Definition at line 139 of file FunctionId.h.

References LHS, and RHS.

◆ operator<()

bool llvm::sampleprof::operator< ( const FunctionId & LHS,
const FunctionId & RHS )
inline

Definition at line 143 of file FunctionId.h.

References LHS, and RHS.

◆ operator<<() [1/5]

raw_ostream & llvm::sampleprof::operator<< ( raw_ostream & OS,
const FunctionId & Obj )
inline

Definition at line 159 of file FunctionId.h.

◆ operator<<() [2/5]

raw_ostream & llvm::sampleprof::operator<< ( raw_ostream & OS,
const FunctionSamples & FS )

Definition at line 265 of file SampleProf.cpp.

◆ operator<<() [3/5]

raw_ostream & llvm::sampleprof::operator<< ( raw_ostream & OS,
const LineLocation & Loc )

Definition at line 132 of file SampleProf.cpp.

◆ operator<<() [4/5]

raw_ostream & llvm::sampleprof::operator<< ( raw_ostream & OS,
const SampleContext & Context )
inline

Definition at line 756 of file SampleProf.h.

◆ operator<<() [5/5]

raw_ostream & llvm::sampleprof::operator<< ( raw_ostream & OS,
const SampleRecord & Sample )

Definition at line 193 of file SampleProf.cpp.

References llvm::sampleprof::SampleRecord::print().

◆ operator<=()

bool llvm::sampleprof::operator<= ( const FunctionId & LHS,
const FunctionId & RHS )
inline

Definition at line 147 of file FunctionId.h.

References LHS, and RHS.

◆ operator==()

bool llvm::sampleprof::operator== ( const FunctionId & LHS,
const FunctionId & RHS )
inline

Definition at line 135 of file FunctionId.h.

References LHS, and RHS.

◆ operator>()

bool llvm::sampleprof::operator> ( const FunctionId & LHS,
const FunctionId & RHS )
inline

Definition at line 151 of file FunctionId.h.

References LHS, and RHS.

◆ operator>=()

bool llvm::sampleprof::operator>= ( const FunctionId & LHS,
const FunctionId & RHS )
inline

Definition at line 155 of file FunctionId.h.

References LHS, and RHS.

◆ removeSecFlag()

template<class SecFlagType>
void llvm::sampleprof::removeSecFlag ( SecHdrTableEntry & Entry,
SecFlagType Flag )
inlinestatic

Definition at line 264 of file SampleProf.h.

References verifySecFlag().

◆ serializeTypeMap()

std::error_code llvm::sampleprof::serializeTypeMap ( const TypeCountMap & Map,
const MapVector< FunctionId, uint32_t > & NameTable,
raw_ostream & OS )

Write Map to the output stream.

Keys are linearized using NameTable and written as ULEB128. Values are written as ULEB128 as well.

Definition at line 52 of file SampleProf.cpp.

References llvm::encodeULEB128(), llvm::MapVector< KeyT, ValueT, MapType, VectorType >::end(), llvm::MapVector< KeyT, ValueT, MapType, VectorType >::find(), llvm::success, and llvm::truncated_name_table.

Referenced by llvm::sampleprof::SampleProfileWriterBinary::writeCallsiteVTableProf().

◆ sortFuncProfiles()

◆ SPMagic()

◆ SPVersion()

uint64_t llvm::sampleprof::SPVersion ( )
inlinestatic

◆ verifySecFlag()

template<class SecFlagType>
void llvm::sampleprof::verifySecFlag ( SecType Type,
SecFlagType Flag )
inlinestatic

Variable Documentation

◆ ExtBinaryHdrLayoutTable

const std::array<SmallVector<SecHdrTableEntry, 8>, NumOfLayout> llvm::sampleprof::ExtBinaryHdrLayoutTable
Initial value:
= {
{SecNameTable, 0, 0, 0, 0},
{SecCSNameTable, 0, 0, 0, 0},
{SecFuncOffsetTable, 0, 0, 0, 0},
{SecLBRProfile, 0, 0, 0, 0},
{SecProfileSymbolList, 0, 0, 0, 0},
{SecFuncMetadata, 0, 0, 0, 0}}),
{SecNameTable, 0, 0, 0, 0},
{SecFuncOffsetTable, 0, 0, 0, 0},
{SecLBRProfile, 0, 0, 0, 0},
{SecFuncOffsetTable, 0, 0, 0, 0},
{SecLBRProfile, 0, 0, 0, 0},
{SecProfileSymbolList, 0, 0, 0, 0},
{SecFuncMetadata, 0, 0, 0, 0}}),
}
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...

Definition at line 245 of file SampleProfWriter.h.

Referenced by llvm::sampleprof::SampleProfileWriterExtBinaryBase::resetSecLayout().

◆ kVTableProfPrefix

char llvm::sampleprof::kVTableProfPrefix[] = "vtables "
constexpr