LLVM 20.0.0git
Public Member Functions | Friends | List of all members
llvm::sampleprof::FunctionId Class Reference

This class represents a function that is read from a sample profile. More...

#include "llvm/ProfileData/FunctionId.h"

Public Member Functions

 FunctionId ()=default
 
 FunctionId (StringRef Str)
 Constructor from a StringRef.
 
 FunctionId (uint64_t HashCode)
 Constructor from a hash code.
 
bool equals (const FunctionId &Other) const
 Check for equality.
 
int compare (const FunctionId &Other) const
 Total order comparison.
 
std::string str () const
 Convert to a string, usually for output purpose.
 
StringRef stringRef () const
 Convert to StringRef.
 
uint64_t getHashCode () const
 Get hash code of this object.
 
bool empty () const
 
bool isStringRef () const
 Check if this object represents a StringRef, or a hash code.
 

Friends

raw_ostreamoperator<< (raw_ostream &OS, const FunctionId &Obj)
 

Detailed Description

This class represents a function that is read from a sample profile.

It comes with two forms: a string or a hash code. The latter form is the 64-bit MD5 of the function name for efficient storage supported by ExtBinary profile format, and when reading the profile, this class can represent it without converting it to a string first. When representing a hash code, we utilize the LengthOrHashCode field to store it, and Name is set to null. When representing a string, it is same as StringRef.

Definition at line 36 of file FunctionId.h.

Constructor & Destructor Documentation

◆ FunctionId() [1/3]

llvm::sampleprof::FunctionId::FunctionId ( )
default

◆ FunctionId() [2/3]

llvm::sampleprof::FunctionId::FunctionId ( StringRef  Str)
inlineexplicit

Constructor from a StringRef.

Definition at line 62 of file FunctionId.h.

References llvm::size().

◆ FunctionId() [3/3]

llvm::sampleprof::FunctionId::FunctionId ( uint64_t  HashCode)
inlineexplicit

Constructor from a hash code.

Definition at line 67 of file FunctionId.h.

References assert().

Member Function Documentation

◆ compare()

int llvm::sampleprof::FunctionId::compare ( const FunctionId Other) const
inline

Total order comparison.

If both FunctionId are StringRef, this is the same as StringRef::compare. If one of them is StringRef, it is considered greater than the hash code FunctionId. Otherwise this is the the same as comparing their int values.

Definition at line 85 of file FunctionId.h.

References llvm::Other.

◆ empty()

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

◆ equals()

bool llvm::sampleprof::FunctionId::equals ( const FunctionId Other) const
inline

Check for equality.

Similar to StringRef::equals, but will also cover for the case where one or both are hash codes. Comparing their int values are sufficient. A hash code FunctionId is considered not equal to a StringRef FunctionId regardless of actual contents.

Definition at line 76 of file FunctionId.h.

References llvm::Other.

◆ getHashCode()

uint64_t llvm::sampleprof::FunctionId::getHashCode ( ) const
inline

Get hash code of this object.

Returns this object's hash code if it is already representing one, otherwise returns the MD5 of its string content. Note that it is not the same as std::hash because we want to keep the consistency that the same sample profile function in string form or MD5 form has the same hash code.

Definition at line 123 of file FunctionId.h.

References llvm::sampleprof::MD5Hash().

Referenced by llvm::sampleprof::FunctionSamples::getGUID(), llvm::sampleprof::SampleContextFrame::getHashCode(), llvm::sampleprof::SampleContext::getHashCode(), llvm::DenseMapInfo< sampleprof::FunctionId, void >::getHashValue(), llvm::sampleprof::hash_value(), llvm::sampleprof::MD5Hash(), std::hash< llvm::sampleprof::FunctionId >::operator()(), llvm::sampleprof::SampleProfileReaderExtBinaryBase::readFuncProfiles(), and llvm::sampleprof::SampleProfileReaderBinary::readNameTable().

◆ isStringRef()

bool llvm::sampleprof::FunctionId::isStringRef ( ) const
inline

Check if this object represents a StringRef, or a hash code.

Definition at line 132 of file FunctionId.h.

◆ str()

std::string llvm::sampleprof::FunctionId::str ( ) const
inline

Convert to a string, usually for output purpose.

Use caution on return value's lifetime when converting to StringRef.

Definition at line 97 of file FunctionId.h.

Referenced by dumpFunctionProfileJson(), llvm::sampleprof::SampleContext::toString(), and llvm::sampleprof::SampleContextFrame::toString().

◆ stringRef()

StringRef llvm::sampleprof::FunctionId::stringRef ( ) const
inline

Convert to StringRef.

This is only allowed when it is known this object is representing a StringRef, not a hash code. Calling this function on a hash code is considered an error.

Definition at line 108 of file FunctionId.h.

References assert().

Referenced by llvm::sampleprof::SampleProfileReaderExtBinaryBase::readFuncProfiles().

Friends And Related Function Documentation

◆ operator<<

raw_ostream & operator<< ( raw_ostream OS,
const FunctionId Obj 
)
friend

Definition at line 159 of file FunctionId.h.


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