12#define DEBUG_TYPE "static-data-profile-info"
38 if (Attrs.hasAttribute(
"bss-section") || Attrs.hasAttribute(
"data-section") ||
39 Attrs.hasAttribute(
"relro-section") ||
40 Attrs.hasAttribute(
"rodata-section"))
51 if (Name.starts_with(
"llvm."))
100 std::optional<StringRef> MaybeSectionPrefix)
const {
101 if (!MaybeSectionPrefix)
104 assert((Prefix ==
"hot" || Prefix ==
"unlikely") &&
105 "Expect section_prefix to be one of hot or unlikely");
114 return Opts.preserve_hot_data_section_prefix ?
"hot" :
"";
120std::optional<uint64_t>
133 auto DbgPrintPrefix = [](
StringRef Prefix) {
134 return Prefix.empty() ?
"<empty>" : Prefix;
147 (
Opts.memprof_annotate_string_literal_section_prefix ||
156 auto HotnessFromDataAccessProf =
162 << DbgPrintPrefix(Prefix)
163 <<
", solely from data access profiles\n");
172 }
else if (HotnessFromDataAccessProf ==
181 dbgs() << GV->getName() <<
" has section prefix "
182 << DbgPrintPrefix(Prefix)
183 <<
", the max from data access profiles as "
184 << DbgPrintPrefix(
hotnessToStr(HotnessFromDataAccessProf))
185 <<
" and PGO counters as "
186 << DbgPrintPrefix(
hotnessToStr(HotnessFromPGO)) <<
"\n");
195static std::unique_ptr<StaticDataProfileInfo>
197 bool EnableDataAccessProf =
false;
199 M.getModuleFlag(
"EnableDataAccessProf")))
200 EnableDataAccessProf = MD->getZExtValue();
202 EnableDataAccessProf);
216 "Static Data Profile Info",
false,
true)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
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.
This is an important class for using LLVM in a threaded context.
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...
const AnalysisOptions & Opts
static LLVM_ABI bool shouldPreserveHotDataSectionPrefix(const LLVMContext &C)
Return -preserve-hot-data-section-prefix.
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.
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 shouldAnnotateStringLiteralSectionPrefix(const LLVMContext &C)
Return -memprof-annotate-string-literal-section-prefix.
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.
const AnalysisOptions & getAnalysisOptions(const LLVMContext &C)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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...