LLVM 22.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/Constant.h"
8#include "llvm/Pass.h"
10
11namespace llvm {
12
13namespace memprof {
14// Represents the eligibility status of a global variable for section prefix
15// annotation. Other than AnnotationOk, each enum value indicates a specific
16// reason for ineligibility.
23/// Returns the annotation kind of the global variable \p GV.
25
26/// Returns true if the annotation kind of the global variable \p GV is
27/// AnnotationOK.
28bool IsAnnotationOK(const GlobalVariable &GV);
29} // namespace memprof
30
31/// A class that holds the constants that represent static data and their
32/// profile information and provides methods to operate on them.
34public:
35 /// A constant is tracked only if the following conditions are met.
36 /// 1) It has local (i.e., private or internal) linkage.
37 // 2) Its data kind is one of {.rodata, .data, .bss, .data.rel.ro}.
38 // 3) It's eligible for section prefix annotation. See `AnnotationKind`
39 // above for ineligible reasons.
41
42 /// Keeps track of the constants that are seen at least once without profile
43 /// counts.
45
46 /// If \p C has a count, return it. Otherwise, return std::nullopt.
47 LLVM_ABI std::optional<uint64_t>
49
50 /// Use signed enums for enum value comparison, and make 'LukewarmOrUnknown'
51 /// as 0 so any accidentally uninitialized value will default to unknown.
52 enum class StaticDataHotness : int8_t {
53 Cold = -1,
55 Hot = 1,
56 };
57
58 /// Return the hotness of the constant \p C based on its profile count \p
59 /// Count.
61 const Constant *C, const ProfileSummaryInfo *PSI, uint64_t Count) const;
62
63 /// Return the hotness based on section prefix \p SectionPrefix.
65 std::optional<StringRef> SectionPrefix) const;
66
67 /// Return the string representation of the hotness enum \p Hotness.
69
71
72public:
75
76 /// If \p Count is not nullopt, add it to the profile count of the constant \p
77 /// C in a saturating way, and clamp the count to \p getInstrMaxCountValue if
78 /// the result exceeds it. Otherwise, mark the constant as having no profile
79 /// count.
81 std::optional<uint64_t> Count);
82
83 /// Given a constant \p C, returns a section prefix.
84 /// If \p C is a global variable, the section prefix is the bigger one
85 /// between its existing section prefix and its use profile count. Otherwise,
86 /// the section prefix is based on its use profile count.
88 const Constant *C, const ProfileSummaryInfo *PSI) const;
89};
90
91/// This wraps the StaticDataProfileInfo object as an immutable pass, for a
92/// backend pass to operate on.
94public:
95 static char ID;
97 bool doInitialization(Module &M) override;
98 bool doFinalization(Module &M) override;
99
102 return *Info;
103 }
104
105 /// This pass provides StaticDataProfileInfo for reads/writes but does not
106 /// modify \p M or other analysis. All analysis are preserved.
107 void getAnalysisUsage(AnalysisUsage &AU) const override {
108 AU.setPreservesAll();
109 }
110
111private:
112 std::unique_ptr<StaticDataProfileInfo> Info;
113};
114
115} // namespace llvm
116
117#endif // LLVM_ANALYSIS_STATICDATAPROFILEINFO_H
Analysis containing CSE Info
Definition CSEInfo.cpp:27
#define LLVM_ABI
Definition Compiler.h:213
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
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:279
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
Analysis providing profile information.
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.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
AnnotationKind getAnnotationKind(const GlobalVariable &GV)
Returns the annotation kind of the global variable GV.
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.
FunctionAddr VTableAddr Count
Definition InstrProf.h:139