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
16namespace memprof {
17// Represents the eligibility status of a global variable for section prefix
18// annotation. Other than AnnotationOk, each enum value indicates a specific
19// reason for ineligibility.
26/// Returns the annotation kind of the global variable \p GV.
28
29/// Returns true if the annotation kind of the global variable \p GV is
30/// AnnotationOK.
32} // namespace memprof
33
34/// A class that holds the constants that represent static data and their
35/// profile information and provides methods to operate on them.
37public:
38 /// A constant is tracked only if the following conditions are met.
39 /// 1) It has local (i.e., private or internal) linkage.
40 // 2) Its data kind is one of {.rodata, .data, .bss, .data.rel.ro}.
41 // 3) It's eligible for section prefix annotation. See `AnnotationKind`
42 // above for ineligible reasons.
44
45 /// Keeps track of the constants that are seen at least once without profile
46 /// counts.
48
49 /// If \p C has a count, return it. Otherwise, return std::nullopt.
50 LLVM_ABI std::optional<uint64_t>
52
53 /// Use signed enums for enum value comparison, and make 'LukewarmOrUnknown'
54 /// as 0 so any accidentally uninitialized value will default to unknown.
55 enum class StaticDataHotness : int8_t {
56 Cold = -1,
58 Hot = 1,
59 };
60
61 /// Return the hotness of the constant \p C based on its profile count \p
62 /// Count.
64 const Constant *C, const ProfileSummaryInfo *PSI, uint64_t Count) const;
65
66 /// Return the hotness based on section prefix \p SectionPrefix.
68 std::optional<StringRef> SectionPrefix) const;
69
70 /// Return the string representation of the hotness enum \p Hotness.
72
74
75public:
78
79 /// If \p Count is not nullopt, add it to the profile count of the constant \p
80 /// C in a saturating way, and clamp the count to \p getInstrMaxCountValue if
81 /// the result exceeds it. Otherwise, mark the constant as having no profile
82 /// count.
84 std::optional<uint64_t> Count);
85
86 /// Given a constant \p C, returns a section prefix.
87 /// If \p C is a global variable, the section prefix is the bigger one
88 /// between its existing section prefix and its use profile count. Otherwise,
89 /// the section prefix is based on its use profile count.
91 const Constant *C, const ProfileSummaryInfo *PSI) const;
92};
93
94/// This wraps the StaticDataProfileInfo object as an immutable pass, for a
95/// backend pass to operate on.
97public:
98 static char ID;
100 bool doInitialization(Module &M) override;
101 bool doFinalization(Module &M) override;
102
105 return *Info;
106 }
107
108 /// This pass provides StaticDataProfileInfo for reads/writes but does not
109 /// modify \p M or other analysis. All analysis are preserved.
110 void getAnalysisUsage(AnalysisUsage &AU) const override {
111 AU.setPreservesAll();
112 }
113
114private:
115 std::unique_ptr<StaticDataProfileInfo> Info;
116};
117
119 : public AnalysisInfoMixin<StaticDataProfileInfoAnalysis> {
120public:
122
123 class Result {
124 std::unique_ptr<StaticDataProfileInfo> HeldInfo;
125 Result(std::unique_ptr<StaticDataProfileInfo> &&Info)
126 : HeldInfo(std::move(Info)) {}
128
129 public:
131 return *HeldInfo;
132 }
133
135 ModuleAnalysisManager::Invalidator &) {
136 return false;
137 }
138 };
139
140 Result run(Module &M, ModuleAnalysisManager &);
141};
142
143} // namespace llvm
144
145#endif // LLVM_ANALYSIS_STATICDATAPROFILEINFO_H
#define LLVM_ABI
Definition Compiler.h:215
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:43
Implements a dense probed hash-table based set.
Definition DenseSet.h:281
ImmutablePass(char &pid)
Definition Pass.h:287
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
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.
StaticDataHotness
Use signed enums for enum value comparison, and make 'LukewarmOrUnknown' as 0 so any accidentally uni...
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.
StaticDataProfileInfo(bool EnableDataAccessProf)
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.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
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.
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