LLVM 24.0.0git
StaticDataProfileInfo.h
Go to the documentation of this file.
1#ifndef LLVM_ANALYSIS_STATICDATAPROFILEINFO_H
2#define LLVM_ANALYSIS_STATICDATAPROFILEINFO_H
3
4#include "llvm/ADT/DenseMap.h"
5#include "llvm/ADT/DenseSet.h"
7#include "llvm/IR/Analysis.h"
8#include "llvm/IR/Constant.h"
10#include "llvm/Pass.h"
12#include <memory>
13
14namespace llvm {
15
16struct AnalysisOptions;
17
18namespace memprof {
19/// Return -memprof-annotate-string-literal-section-prefix.
21
22// Represents the eligibility status of a global variable for section prefix
23// annotation. Other than AnnotationOk, each enum value indicates a specific
24// reason for ineligibility.
31/// Returns the annotation kind of the global variable \p GV.
33
34/// Returns true if the annotation kind of the global variable \p GV is
35/// AnnotationOK.
37} // namespace memprof
38
39/// A class that holds the constants that represent static data and their
40/// profile information and provides methods to operate on them.
42public:
43 /// A constant is tracked only if the following conditions are met.
44 /// 1) It has local (i.e., private or internal) linkage.
45 // 2) Its data kind is one of {.rodata, .data, .bss, .data.rel.ro}.
46 // 3) It's eligible for section prefix annotation. See `AnnotationKind`
47 // above for ineligible reasons.
49
50 /// Keeps track of the constants that are seen at least once without profile
51 /// counts.
53
54 /// If \p C has a count, return it. Otherwise, return std::nullopt.
55 LLVM_ABI std::optional<uint64_t>
57
58 /// Use signed enums for enum value comparison, and make 'LukewarmOrUnknown'
59 /// as 0 so any accidentally uninitialized value will default to unknown.
60 enum class StaticDataHotness : int8_t {
61 Cold = -1,
63 Hot = 1,
64 };
65
66 /// Return the hotness of the constant \p C based on its profile count \p
67 /// Count.
69 const Constant *C, const ProfileSummaryInfo *PSI, uint64_t Count) const;
70
71 /// Return the hotness based on section prefix \p SectionPrefix.
73 std::optional<StringRef> SectionPrefix) const;
74
75 /// Return the string representation of the hotness enum \p Hotness.
77
78 const AnalysisOptions &Opts;
80
81public:
84
85 /// Return -preserve-hot-data-section-prefix.
87
88 /// If \p Count is not nullopt, add it to the profile count of the constant \p
89 /// C in a saturating way, and clamp the count to \p getInstrMaxCountValue if
90 /// the result exceeds it. Otherwise, mark the constant as having no profile
91 /// count.
93 std::optional<uint64_t> Count);
94
95 /// Given a constant \p C, returns a section prefix.
96 /// If \p C is a global variable, the section prefix is the bigger one
97 /// between its existing section prefix and its use profile count. Otherwise,
98 /// the section prefix is based on its use profile count.
100 const Constant *C, const ProfileSummaryInfo *PSI) const;
101};
102
103/// This wraps the StaticDataProfileInfo object as an immutable pass, for a
104/// backend pass to operate on.
106public:
107 static char ID;
109 bool doInitialization(Module &M) override;
110 bool doFinalization(Module &M) override;
111
114 return *Info;
115 }
116
117 /// This pass provides StaticDataProfileInfo for reads/writes but does not
118 /// modify \p M or other analysis. All analysis are preserved.
119 void getAnalysisUsage(AnalysisUsage &AU) const override {
120 AU.setPreservesAll();
121 }
122
123private:
124 std::unique_ptr<StaticDataProfileInfo> Info;
125};
126
128 : public AnalysisInfoMixin<StaticDataProfileInfoAnalysis> {
129public:
131
132 class Result {
133 std::unique_ptr<StaticDataProfileInfo> HeldInfo;
134 Result(std::unique_ptr<StaticDataProfileInfo> &&Info)
135 : HeldInfo(std::move(Info)) {}
137
138 public:
140 return *HeldInfo;
141 }
142
144 ModuleAnalysisManager::Invalidator &) {
145 return false;
146 }
147 };
148
149 Result run(Module &M, ModuleAnalysisManager &);
150};
151
152} // namespace llvm
153
154#endif // LLVM_ANALYSIS_STATICDATAPROFILEINFO_H
uint64_t uint64_t
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#define LLVM_ABI
Definition Compiler.h:211
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
This header defines various interfaces for pass management in LLVM.
Represent the analysis usage information of a pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
This is an important base class in LLVM.
Definition Constant.h:44
Implements a dense probed hash-table based set.
Definition DenseSet.h:281
ImmutablePass(char &pid)
Definition Pass.h:285
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
Analysis providing profile information.
bool invalidate(Module &, const PreservedAnalyses &, ModuleAnalysisManager::Invalidator &)
bool doFinalization(Module &M) override
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
const StaticDataProfileInfo & getStaticDataProfileInfo() const
void getAnalysisUsage(AnalysisUsage &AU) const override
This pass provides StaticDataProfileInfo for reads/writes but does not modify M or other analysis.
bool doInitialization(Module &M) override
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
StaticDataProfileInfo & getStaticDataProfileInfo()
A class that holds the constants that represent static data and their profile information and provide...
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.
StaticDataProfileInfo(const AnalysisOptions &Opts, bool EnableDataAccessProf)
StaticDataHotness
Use signed enums for enum value comparison, and make 'LukewarmOrUnknown' as 0 so any accidentally uni...
static LLVM_ABI bool shouldPreserveHotDataSectionPrefix(const LLVMContext &C)
Return -preserve-hot-data-section-prefix.
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.
Definition StringRef.h:56
Pass manager infrastructure for declaring and invalidating analyses.
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.
This is an optimization pass for GlobalISel generic memory operations.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
Definition InstrProf.h:145
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
A CRTP mix-in that provides informational APIs needed for analysis passes.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29