11#define DEBUG_TYPE "static-data-profile-info"
21 "memprof-annotate-string-literal-section-prefix",
cl::init(
false),
23 cl::desc(
"If true, annotate the string literal data section prefix"));
35 if (Attrs.hasAttribute(
"bss-section") || Attrs.hasAttribute(
"data-section") ||
36 Attrs.hasAttribute(
"relro-section") ||
37 Attrs.hasAttribute(
"rodata-section"))
48 if (Name.starts_with(
"llvm."))
97 std::optional<StringRef> MaybeSectionPrefix)
const {
98 if (!MaybeSectionPrefix)
101 assert((Prefix ==
"hot" || Prefix ==
"unlikely") &&
102 "Expect section_prefix to be one of hot or unlikely");
117std::optional<uint64_t>
130 auto DbgPrintPrefix = [](
StringRef Prefix) {
131 return Prefix.empty() ?
"<empty>" : Prefix;
153 auto HotnessFromDataAccessProf =
159 << DbgPrintPrefix(Prefix)
160 <<
", solely from data access profiles\n");
169 }
else if (HotnessFromDataAccessProf ==
178 dbgs() << GV->getName() <<
" has section prefix "
179 << DbgPrintPrefix(Prefix)
180 <<
", the max from data access profiles as "
181 << DbgPrintPrefix(
hotnessToStr(HotnessFromDataAccessProf))
182 <<
" and PGO counters as "
183 << DbgPrintPrefix(
hotnessToStr(HotnessFromPGO)) <<
"\n");
192static std::unique_ptr<StaticDataProfileInfo>
194 bool EnableDataAccessProf =
false;
196 M.getModuleFlag(
"EnableDataAccessProf")))
197 EnableDataAccessProf = MD->getZExtValue();
198 return std::make_unique<StaticDataProfileInfo>(EnableDataAccessProf);
212 "Static Data Profile Info",
false,
true)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
static std::unique_ptr< StaticDataProfileInfo > computeStaticDataProfileInfo(Module &M)
This is an important base class in LLVM.
bool hasSection() const
Check if this global has a custom object file section.
bool isDeclarationForLinker() const
AttributeSet getAttributes() const
Return the attribute set for this global.
ImmutablePass class - This class is used to provide information that does not need to be run.
A Module instance is used to store all the information related to an LLVM module.
Analysis providing profile information.
LLVM_ABI bool isColdCount(uint64_t C) const
Returns true if count C is considered cold.
LLVM_ABI bool isHotCount(uint64_t C) const
Returns true if count C is considered hot.
Result run(Module &M, ModuleAnalysisManager &)
This wraps the StaticDataProfileInfo object as an immutable pass, for a backend pass to operate on.
bool doFinalization(Module &M) override
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
bool doInitialization(Module &M) override
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
LLVM_ABI std::optional< uint64_t > getConstantProfileCount(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.
StaticDataHotness
Use signed enums for enum value comparison, and make 'LukewarmOrUnknown' as 0 so any accidentally uni...
bool EnableDataAccessProf
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,...
LLVM_ABI StringRef getConstantSectionPrefix(const Constant *C, const ProfileSummaryInfo *PSI) const
Given a constant C, returns a section prefix.
LLVM_ABI StaticDataHotness getSectionHotnessUsingDataAccessProfile(std::optional< StringRef > SectionPrefix) const
Return the hotness based on section prefix SectionPrefix.
DenseMap< const Constant *, uint64_t > ConstantProfileCounts
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.
Represent a constant reference to a string, i.e.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
initializer< Ty > init(const Ty &Val)
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract_or_null(Y &&MD)
Extract a Value from Metadata, allowing null.
LLVM_ABI AnnotationKind getAnnotationKind(const GlobalVariable &GV)
Returns the annotation kind of the global variable GV.
LLVM_ABI bool IsAnnotationOK(const GlobalVariable &GV)
Returns true if the annotation kind of the global variable GV is AnnotationOK.
static bool hasExplicitSectionName(const GlobalVariable &GVar)
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
uint64_t getInstrMaxCountValue()
Return the max count value. We reserver a few large values for special use.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
cl::opt< bool > AnnotateStringLiteralSectionPrefix("memprof-annotate-string-literal-section-prefix", cl::init(false), cl::Hidden, cl::desc("If true, annotate the string literal data section prefix"))
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
std::enable_if_t< std::is_unsigned_v< T >, T > SaturatingAdd(T X, T Y, bool *ResultOverflowed=nullptr)
Add two unsigned integers, X and Y, of type T.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
A special type used by analysis passes to provide an address that identifies that particular analysis...