LLVM 22.0.0git
llvm::StaticDataProfileInfo Class Reference

A class that holds the constants that represent static data and their profile information and provides methods to operate on them. More...

#include "llvm/Analysis/StaticDataProfileInfo.h"

Public Types

enum class  StaticDataHotness : int8_t { Cold = -1 , LukewarmOrUnknown = 0 , Hot = 1 }
 Use signed enums for enum value comparison, and make 'LukewarmOrUnknown' as 0 so any accidentally uninitialized value will default to unknown. More...

Public Member Functions

LLVM_ABI std::optional< uint64_tgetConstantProfileCount (const Constant *C) const
 If C has a count, return it. Otherwise, return std::nullopt.
LLVM_ABI StaticDataHotness getConstantHotnessUsingProfileCount (const Constant *C, const ProfileSummaryInfo *PSI, uint64_t Count) const
 Return the hotness of the constant C based on its profile count Count.
LLVM_ABI StringRef hotnessToStr (StaticDataHotness Hotness) const
 Return the string representation of the hotness enum Hotness.
 StaticDataProfileInfo ()=default
LLVM_ABI void addConstantProfileCount (const Constant *C, std::optional< uint64_t > Count)
 If Count is not nullopt, add it to the profile count of the constant C in a saturating way, and clamp the count to getInstrMaxCountValue if the result exceeds it.
LLVM_ABI StringRef getConstantSectionPrefix (const Constant *C, const ProfileSummaryInfo *PSI) const
 Return a section prefix for the constant C based on its profile count.

Public Attributes

DenseMap< const Constant *, uint64_tConstantProfileCounts
 A constant is tracked only if the following conditions are met.
DenseSet< const Constant * > ConstantWithoutCounts
 Keeps track of the constants that are seen at least once without profile counts.

Detailed Description

A class that holds the constants that represent static data and their profile information and provides methods to operate on them.

Definition at line 33 of file StaticDataProfileInfo.h.

Member Enumeration Documentation

◆ StaticDataHotness

Use signed enums for enum value comparison, and make 'LukewarmOrUnknown' as 0 so any accidentally uninitialized value will default to unknown.

Enumerator
Cold 
LukewarmOrUnknown 
Hot 

Definition at line 52 of file StaticDataProfileInfo.h.

Constructor & Destructor Documentation

◆ StaticDataProfileInfo()

llvm::StaticDataProfileInfo::StaticDataProfileInfo ( )
default

Member Function Documentation

◆ addConstantProfileCount()

void StaticDataProfileInfo::addConstantProfileCount ( const Constant * C,
std::optional< uint64_t > Count )

If Count is not nullopt, add it to the profile count of the constant C in a saturating way, and clamp the count to getInstrMaxCountValue if the result exceeds it.

Otherwise, mark the constant as having no profile count.

Definition at line 49 of file StaticDataProfileInfo.cpp.

References llvm::CallingConv::C, ConstantProfileCounts, ConstantWithoutCounts, llvm::Count, llvm::getInstrMaxCountValue(), and llvm::SaturatingAdd().

◆ getConstantHotnessUsingProfileCount()

StaticDataProfileInfo::StaticDataHotness StaticDataProfileInfo::getConstantHotnessUsingProfileCount ( const Constant * C,
const ProfileSummaryInfo * PSI,
uint64_t Count ) const

Return the hotness of the constant C based on its profile count Count.

Definition at line 64 of file StaticDataProfileInfo.cpp.

References llvm::CallingConv::C, Cold, ConstantWithoutCounts, llvm::Count, Hot, llvm::ProfileSummaryInfo::isColdCount(), llvm::ProfileSummaryInfo::isHotCount(), and LukewarmOrUnknown.

Referenced by getConstantSectionPrefix().

◆ getConstantProfileCount()

std::optional< uint64_t > StaticDataProfileInfo::getConstantProfileCount ( const Constant * C) const

If C has a count, return it. Otherwise, return std::nullopt.

Definition at line 94 of file StaticDataProfileInfo.cpp.

References llvm::CallingConv::C, ConstantProfileCounts, and I.

Referenced by getConstantSectionPrefix().

◆ getConstantSectionPrefix()

StringRef StaticDataProfileInfo::getConstantSectionPrefix ( const Constant * C,
const ProfileSummaryInfo * PSI ) const

Return a section prefix for the constant C based on its profile count.

  • If a constant doesn't have a counter, return an empty string.
  • Otherwise,
    • If it has a hot count, return "hot".
    • If it is seen by unprofiled function, return an empty string.
    • If it has a cold count, return "unlikely".
    • Otherwise (e.g. it's used by lukewarm functions), return an empty string.

Definition at line 101 of file StaticDataProfileInfo.cpp.

References llvm::CallingConv::C, llvm::Count, getConstantHotnessUsingProfileCount(), getConstantProfileCount(), and hotnessToStr().

◆ hotnessToStr()

StringRef StaticDataProfileInfo::hotnessToStr ( StaticDataHotness Hotness) const

Return the string representation of the hotness enum Hotness.

Definition at line 82 of file StaticDataProfileInfo.cpp.

References Cold, and Hot.

Referenced by getConstantSectionPrefix().

Member Data Documentation

◆ ConstantProfileCounts

DenseMap<const Constant *, uint64_t> llvm::StaticDataProfileInfo::ConstantProfileCounts

A constant is tracked only if the following conditions are met.

1) It has local (i.e., private or internal) linkage.

Definition at line 40 of file StaticDataProfileInfo.h.

Referenced by addConstantProfileCount(), and getConstantProfileCount().

◆ ConstantWithoutCounts

DenseSet<const Constant *> llvm::StaticDataProfileInfo::ConstantWithoutCounts

Keeps track of the constants that are seen at least once without profile counts.

Definition at line 44 of file StaticDataProfileInfo.h.

Referenced by addConstantProfileCount(), and getConstantHotnessUsingProfileCount().


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