LLVM 22.0.0git
StaticDataProfileInfo.cpp
Go to the documentation of this file.
3#include "llvm/IR/Constant.h"
7
8using namespace llvm;
10 const Constant *C, std::optional<uint64_t> Count) {
11 if (!Count) {
13 return;
14 }
15 uint64_t &OriginalCount = ConstantProfileCounts[C];
16 OriginalCount = llvm::SaturatingAdd(*Count, OriginalCount);
17 // Clamp the count to getInstrMaxCountValue. InstrFDO reserves a few
18 // large values for special use.
19 if (OriginalCount > getInstrMaxCountValue())
20 OriginalCount = getInstrMaxCountValue();
21}
22
23std::optional<uint64_t>
25 auto I = ConstantProfileCounts.find(C);
26 if (I == ConstantProfileCounts.end())
27 return std::nullopt;
28 return I->second;
29}
30
32 const Constant *C, const ProfileSummaryInfo *PSI) const {
33 auto Count = getConstantProfileCount(C);
34 if (!Count)
35 return "";
36 // The accummulated counter shows the constant is hot. Return 'hot' whether
37 // this variable is seen by unprofiled functions or not.
38 if (PSI->isHotCount(*Count))
39 return "hot";
40 // The constant is not hot, and seen by unprofiled functions. We don't want to
41 // assign it to unlikely sections, even if the counter says 'cold'. So return
42 // an empty prefix before checking whether the counter is cold.
43 if (ConstantWithoutCounts.count(C))
44 return "";
45 // The accummulated counter shows the constant is cold. Return 'unlikely'.
46 if (PSI->isColdCount(*Count))
47 return "unlikely";
48 // The counter says lukewarm. Return an empty prefix.
49 return "";
50}
51
53 Info.reset(new StaticDataProfileInfo());
54 return false;
55}
56
58 Info.reset();
59 return false;
60}
61
63 "Static Data Profile Info", false, true)
64
66 : ImmutablePass(ID) {}
67
#define I(x, y, z)
Definition: MD5.cpp:58
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:56
This is an important base class in LLVM.
Definition: Constant.h:43
ImmutablePass class - This class is used to provide information that does not need to be run.
Definition: Pass.h:285
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
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.
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 ...
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 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
Return a section prefix for the constant C based on its profile count.
DenseMap< const Constant *, uint64_t > ConstantProfileCounts
Accummulate the profile count of a constant that will be lowered to static data sections.
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
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
uint64_t getInstrMaxCountValue()
Return the max count value. We reserver a few large values for special use.
Definition: InstrProf.h:98
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.
Definition: MathExtras.h:614