LLVM 22.0.0git
llvm::InstrProfSymtab Class Reference

A symbol table used for function [IR]PGO name look-up with keys (such as pointers, md5hash values) to the function. More...

#include "llvm/ProfileData/InstrProf.h"

Public Types

using AddrHashMap = std::vector<std::pair<uint64_t, uint64_t>>

Public Member Functions

 InstrProfSymtab ()
 InstrProfSymtab (const InstrProfSymtab &)=delete
InstrProfSymtaboperator= (const InstrProfSymtab &)=delete
 InstrProfSymtab (InstrProfSymtab &&)=delete
InstrProfSymtaboperator= (InstrProfSymtab &&)=delete
LLVM_ABI Error create (object::SectionRef &Section)
 Create InstrProfSymtab from an object file section which contains function PGO names.
LLVM_ABI Error create (StringRef NameStrings)
 NameStrings is a string composed of one of more sub-strings encoded in the format described in collectPGOFuncNameStrings.
LLVM_ABI Error create (StringRef FuncNameStrings, StringRef VTableNameStrings)
 Initialize symtab states with function names and vtable names.
LLVM_ABI Error initVTableNamesFromCompressedStrings (StringRef CompressedVTableNames)
 Initialize 'this' with the set of vtable names encoded in CompressedVTableNames.
Error create (StringRef D, uint64_t BaseAddr)
 This interface is used by reader of CoverageMapping test format.
LLVM_ABI Error create (Module &M, bool InLTO=false, bool AddCanonical=true)
 A wrapper interface to populate the PGO symtab with functions decls from module M.
template<typename NameIterRange>
Error create (const NameIterRange &IterRange)
 Create InstrProfSymtab from a set of names iteratable from IterRange.
template<typename FuncNameIterRange, typename VTableNameIterRange>
Error create (const FuncNameIterRange &FuncIterRange, const VTableNameIterRange &VTableIterRange)
 Create InstrProfSymtab from a set of function names and vtable names iteratable from IterRange.
Error addSymbolName (StringRef SymbolName)
Error addFuncName (StringRef FuncName)
 The method name is kept since there are many callers.
Error addVTableName (StringRef VTableName)
 Adds VTableName as a known symbol, and inserts it to a map that tracks all vtable names.
const std::vector< std::pair< uint64_t, Function * > > & getIDToNameMap () const
const StringSetgetVTableNames () const
void mapAddress (uint64_t Addr, uint64_t MD5Val)
 Map a function address to its name's MD5 hash.
void mapVTableAddress (uint64_t StartAddr, uint64_t EndAddr, uint64_t MD5Val)
 Map the address range (i.e., [start_address, end_address)) of a variable to its names' MD5 hash.
LLVM_ABI uint64_t getFunctionHashFromAddress (uint64_t Address) const
 Return a function's hash, or 0, if the function isn't in this SymTab.
LLVM_ABI uint64_t getVTableHashFromAddress (uint64_t Address) const
 Return a vtable's hash, or 0 if the vtable doesn't exist in this SymTab.
LLVM_ABI StringRef getFuncName (uint64_t FuncNameAddress, size_t NameSize) const
 Return function's PGO name from the function name's symbol address in the object file.
StringRef getFuncOrVarName (uint64_t ValMD5Hash) const
 Return name of functions or global variables from the name's md5 hash value.
StringRef getFuncOrVarNameIfDefined (uint64_t ValMD5Hash) const
 Just like getFuncOrVarName, except that it will return literal string 'External Symbol' if the function or global variable is external to this symbol table.
FunctiongetFunction (uint64_t FuncMD5Hash) const
 Return function from the name's md5 hash. Return nullptr if not found.
GlobalVariablegetGlobalVariable (uint64_t MD5Hash) const
 Return the global variable corresponding to md5 hash.
StringRef getNameData () const
 Return the name section data.
LLVM_ABI void dumpNames (raw_ostream &OS) const
 Dump the symbols in this table.

Static Public Member Functions

static LLVM_ABI StringRef getCanonicalName (StringRef PGOName)
static bool isExternalSymbol (const StringRef &Symbol)
 True if Symbol is the value used to represent external symbols.

Detailed Description

A symbol table used for function [IR]PGO name look-up with keys (such as pointers, md5hash values) to the function.

A function's [IR]PGO name or name's md5hash are used in retrieving the profile data of the function. See getIRPGOFuncName() and getPGOFuncName methods for details how [IR]PGO name is formed.

Definition at line 506 of file InstrProf.h.

Member Typedef Documentation

◆ AddrHashMap

using llvm::InstrProfSymtab::AddrHashMap = std::vector<std::pair<uint64_t, uint64_t>>

Definition at line 508 of file InstrProf.h.

Constructor & Destructor Documentation

◆ InstrProfSymtab() [1/3]

llvm::InstrProfSymtab::InstrProfSymtab ( )
inline

Definition at line 577 of file InstrProf.h.

Referenced by InstrProfSymtab(), InstrProfSymtab(), operator=(), and operator=().

◆ InstrProfSymtab() [2/3]

llvm::InstrProfSymtab::InstrProfSymtab ( const InstrProfSymtab & )
delete

References InstrProfSymtab().

◆ InstrProfSymtab() [3/3]

llvm::InstrProfSymtab::InstrProfSymtab ( InstrProfSymtab && )
delete

References InstrProfSymtab().

Member Function Documentation

◆ addFuncName()

Error llvm::InstrProfSymtab::addFuncName ( StringRef FuncName)
inline

The method name is kept since there are many callers.

It just forwards to 'addSymbolName'.

Definition at line 654 of file InstrProf.h.

References addSymbolName().

Referenced by create(), create(), create(), create(), and llvm::InstrProfWriter::writeText().

◆ addSymbolName()

Error llvm::InstrProfSymtab::addSymbolName ( StringRef SymbolName)
inline

◆ addVTableName()

Error llvm::InstrProfSymtab::addVTableName ( StringRef VTableName)
inline

Adds VTableName as a known symbol, and inserts it to a map that tracks all vtable names.

Definition at line 658 of file InstrProf.h.

References addSymbolName(), E(), and llvm::Error::success().

Referenced by create(), create(), initVTableNamesFromCompressedStrings(), and llvm::InstrProfWriter::writeText().

◆ create() [1/7]

template<typename FuncNameIterRange, typename VTableNameIterRange>
Error llvm::InstrProfSymtab::create ( const FuncNameIterRange & FuncIterRange,
const VTableNameIterRange & VTableIterRange )

Create InstrProfSymtab from a set of function names and vtable names iteratable from IterRange.

This interface is used by IndexedProfReader.

Definition at line 744 of file InstrProf.h.

References addFuncName(), addVTableName(), E(), and llvm::Error::success().

◆ create() [2/7]

template<typename NameIterRange>
Error llvm::InstrProfSymtab::create ( const NameIterRange & IterRange)

Create InstrProfSymtab from a set of names iteratable from IterRange.

This interface is used by IndexedProfReader.

Definition at line 734 of file InstrProf.h.

References addFuncName(), E(), and llvm::Error::success().

◆ create() [3/7]

Error llvm::InstrProfSymtab::create ( Module & M,
bool InLTO = false,
bool AddCanonical = true )

A wrapper interface to populate the PGO symtab with functions decls from module M.

This interface is used by transformation passes such as indirect function call promotion. Variable InLTO indicates if this is called from LTO optimization passes. A canonical name, removing non-__uniq suffixes, is added if AddCanonical is true.

Definition at line 528 of file InstrProf.cpp.

References F, G, llvm::getIRPGOFuncName(), llvm::getPGOFuncName(), llvm::getPGOName(), and llvm::Error::success().

◆ create() [4/7]

Error InstrProfSymtab::create ( object::SectionRef & Section)

Create InstrProfSymtab from an object file section which contains function PGO names.

When section may contain raw string data or string data in compressed form. This method only initialize the symtab with reference to the data and the section base address. The decompression will be delayed until before it is used. See also create(StringRef) method.

Definition at line 509 of file CoverageMappingReader.cpp.

References shouldSkipSectionFirstByte(), llvm::Error::success(), and llvm::Expected< T >::takeError().

Referenced by loadBinaryFormat(), loadTestingFormat(), llvm::InstrProfReaderIndex< HashTableImpl >::populateSymtab(), promoteIndirectCalls(), llvm::JumpTableToSwitchPass::run(), and runCGProfilePass().

◆ create() [5/7]

Error llvm::InstrProfSymtab::create ( StringRef D,
uint64_t BaseAddr )
inline

This interface is used by reader of CoverageMapping test format.

Definition at line 727 of file InstrProf.h.

References D(), and llvm::Error::success().

◆ create() [6/7]

Error llvm::InstrProfSymtab::create ( StringRef FuncNameStrings,
StringRef VTableNameStrings )

Initialize symtab states with function names and vtable names.

FuncNameStrings is a string composed of one or more encoded function name strings, and VTableNameStrings composes of one or more encoded vtable names. This interface is solely used by raw profile reader.

Definition at line 624 of file InstrProf.cpp.

References addFuncName(), addVTableName(), and llvm::readAndDecodeStrings().

◆ create() [7/7]

Error llvm::InstrProfSymtab::create ( StringRef NameStrings)

NameStrings is a string composed of one of more sub-strings encoded in the format described in collectPGOFuncNameStrings.

This method is a wrapper to readAndDecodeStrings method.

Definition at line 619 of file InstrProf.cpp.

References addFuncName(), and llvm::readAndDecodeStrings().

◆ dumpNames()

void llvm::InstrProfSymtab::dumpNames ( raw_ostream & OS) const

Dump the symbols in this table.

Definition at line 707 of file InstrProf.cpp.

References llvm::sort().

◆ getCanonicalName()

StringRef llvm::InstrProfSymtab::getCanonicalName ( StringRef PGOName)
static

Definition at line 640 of file InstrProf.cpp.

Referenced by llvm::memprof::getCanonicalName().

◆ getFuncName()

StringRef InstrProfSymtab::getFuncName ( uint64_t FuncNameAddress,
size_t NameSize ) const

Return function's PGO name from the function name's symbol address in the object file.

If an error occurs, return an empty string.

Definition at line 522 of file CoverageMappingReader.cpp.

References llvm::Offset, and Size.

◆ getFuncOrVarName()

StringRef llvm::InstrProfSymtab::getFuncOrVarName ( uint64_t ValMD5Hash) const
inline

Return name of functions or global variables from the name's md5 hash value.

If not found, return an empty string.

Definition at line 778 of file InstrProf.h.

References LHS, llvm::lower_bound(), llvm::sampleprof::MD5Hash(), and RHS.

Referenced by llvm::coverage::accessors::getFuncNameViaRef(), getFuncOrVarNameIfDefined(), and llvm::InstrProfWriter::writeTextTemporalProfTraceData().

◆ getFuncOrVarNameIfDefined()

StringRef llvm::InstrProfSymtab::getFuncOrVarNameIfDefined ( uint64_t ValMD5Hash) const
inline

Just like getFuncOrVarName, except that it will return literal string 'External Symbol' if the function or global variable is external to this symbol table.

Definition at line 771 of file InstrProf.h.

References getFuncOrVarName(), and llvm::sampleprof::MD5Hash().

Referenced by llvm::InstrProfWriter::writeRecordInText().

◆ getFunction()

Function * llvm::InstrProfSymtab::getFunction ( uint64_t FuncMD5Hash) const
inline

Return function from the name's md5 hash. Return nullptr if not found.

Definition at line 788 of file InstrProf.h.

References LHS, llvm::lower_bound(), and RHS.

Referenced by runCGProfilePass().

◆ getFunctionHashFromAddress()

uint64_t llvm::InstrProfSymtab::getFunctionHashFromAddress ( uint64_t Address) const

Return a function's hash, or 0, if the function isn't in this SymTab.

Definition at line 693 of file InstrProf.cpp.

References A(), and llvm::partition_point().

◆ getGlobalVariable()

GlobalVariable * llvm::InstrProfSymtab::getGlobalVariable ( uint64_t MD5Hash) const
inline

Return the global variable corresponding to md5 hash.

Return nullptr if not found.

Definition at line 798 of file InstrProf.h.

References llvm::sampleprof::MD5Hash().

◆ getIDToNameMap()

const std::vector< std::pair< uint64_t, Function * > > & llvm::InstrProfSymtab::getIDToNameMap ( ) const
inline

Definition at line 668 of file InstrProf.h.

Referenced by llvm::JumpTableToSwitchPass::run().

◆ getNameData()

StringRef llvm::InstrProfSymtab::getNameData ( ) const
inline

Return the name section data.

Definition at line 721 of file InstrProf.h.

◆ getVTableHashFromAddress()

uint64_t llvm::InstrProfSymtab::getVTableHashFromAddress ( uint64_t Address) const

Return a vtable's hash, or 0 if the vtable doesn't exist in this SymTab.

Definition at line 687 of file InstrProf.cpp.

◆ getVTableNames()

const StringSet & llvm::InstrProfSymtab::getVTableNames ( ) const
inline

Definition at line 672 of file InstrProf.h.

◆ initVTableNamesFromCompressedStrings()

Error llvm::InstrProfSymtab::initVTableNamesFromCompressedStrings ( StringRef CompressedVTableNames)

Initialize 'this' with the set of vtable names encoded in CompressedVTableNames.

Definition at line 634 of file InstrProf.cpp.

References addVTableName(), and llvm::readAndDecodeStrings().

◆ isExternalSymbol()

bool llvm::InstrProfSymtab::isExternalSymbol ( const StringRef & Symbol)
inlinestatic

True if Symbol is the value used to represent external symbols.

Definition at line 709 of file InstrProf.h.

◆ mapAddress()

void llvm::InstrProfSymtab::mapAddress ( uint64_t Addr,
uint64_t MD5Val )
inline

Map a function address to its name's MD5 hash.

This interface is only used by the raw profiler reader.

Definition at line 676 of file InstrProf.h.

◆ mapVTableAddress()

void llvm::InstrProfSymtab::mapVTableAddress ( uint64_t StartAddr,
uint64_t EndAddr,
uint64_t MD5Val )
inline

Map the address range (i.e., [start_address, end_address)) of a variable to its names' MD5 hash.

This interface is only used by the raw profile reader.

Definition at line 683 of file InstrProf.h.

◆ operator=() [1/2]

InstrProfSymtab & llvm::InstrProfSymtab::operator= ( const InstrProfSymtab & )
delete

References InstrProfSymtab().

◆ operator=() [2/2]

InstrProfSymtab & llvm::InstrProfSymtab::operator= ( InstrProfSymtab && )
delete

References D(), InstrProfSymtab(), and LLVM_ABI.


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