LLVM: lib/Analysis/StaticDataProfileInfo.cpp Source File (original) (raw)

9

10#define DEBUG_TYPE "static-data-profile-info"

11

12using namespace llvm;

13

14namespace llvm {

16

17

18

19

20

23 return true;

24

26 if (Attrs.hasAttribute("bss-section") || Attrs.hasAttribute("data-section") ||

27 Attrs.hasAttribute("relro-section") ||

28 Attrs.hasAttribute("rodata-section"))

29 return true;

30 return false;

31}

32

36

37

39 if (Name.starts_with("llvm."))

41

45}

46

50}

51}

52

57 return;

58 }

61

62

65}

66

85

88 std::optional MaybeSectionPrefix) const {

89 if (!MaybeSectionPrefix)

91 StringRef Prefix = *MaybeSectionPrefix;

92 assert((Prefix == "hot" || Prefix == "unlikely") &&

93 "Expect section_prefix to be one of hot or unlikely");

95}

96

98 switch (Hotness) {

100 return "unlikely";

102 return "hot";

103 default:

104 return "";

105 }

106}

107

108std::optional<uint64_t>

112 return std::nullopt;

113 return I->second;

114}

115

119

120#ifndef NDEBUG

121 auto DbgPrintPrefix = [](StringRef Prefix) {

122 return Prefix.empty() ? "" : Prefix;

123 };

124#endif

125

127

128

131 !GV->getName().starts_with(".str")) {

132 auto HotnessFromDataAccessProf =

134

137 LLVM_DEBUG(dbgs() << GV->getName() << " has section prefix "

138 << DbgPrintPrefix(Prefix)

139 << ", solely from data access profiles\n");

140 return Prefix;

141 }

142

143

144

150 } else if (HotnessFromDataAccessProf ==

154 } else {

156 }

159 dbgs() << GV->getName() << " has section prefix "

160 << DbgPrintPrefix(Prefix)

161 << ", the max from data access profiles as "

162 << DbgPrintPrefix(hotnessToStr(HotnessFromDataAccessProf))

163 << " and PGO counters as "

164 << DbgPrintPrefix(hotnessToStr(HotnessFromPGO)) << "\n");

165 return Prefix;

166 }

167 }

169 return "";

171}

172

174 bool EnableDataAccessProf = false;

176 M.getModuleFlag("EnableDataAccessProf")))

177 EnableDataAccessProf = MD->getZExtValue();

179 return false;

180}

181

183 Info.reset();

184 return false;

185}

186

188 "Static Data Profile Info", false, true)

189

192

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

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.

#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)

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.

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.

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...

Definition StaticDataProfileInfo.cpp:182

bool doInitialization(Module &M) override

doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...

Definition StaticDataProfileInfo.cpp:173

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.

Definition StaticDataProfileInfo.cpp:109

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.

Definition StaticDataProfileInfo.cpp:68

LLVM_ABI StringRef hotnessToStr(StaticDataHotness Hotness) const

Return the string representation of the hotness enum Hotness.

Definition StaticDataProfileInfo.cpp:97

StaticDataHotness

Use signed enums for enum value comparison, and make 'LukewarmOrUnknown' as 0 so any accidentally uni...

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,...

Definition StaticDataProfileInfo.cpp:53

LLVM_ABI StringRef getConstantSectionPrefix(const Constant *C, const ProfileSummaryInfo *PSI) const

Given a constant C, returns a section prefix.

Definition StaticDataProfileInfo.cpp:116

LLVM_ABI StaticDataHotness getSectionHotnessUsingDataAccessProfile(std::optional< StringRef > SectionPrefix) const

Return the hotness based on section prefix SectionPrefix.

Definition StaticDataProfileInfo.cpp:87

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.

LLVM_ABI StringRef getName() const

Return a constant reference to the value's name.

unsigned ID

LLVM IR allows to use arbitrary numbers as calling convention identifiers.

@ C

The default llvm calling convention, compatible with C.

std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract_or_null(Y &&MD)

Extract a Value from Metadata, allowing null.

AnnotationKind getAnnotationKind(const GlobalVariable &GV)

Returns the annotation kind of the global variable GV.

Definition StaticDataProfileInfo.cpp:33

bool IsAnnotationOK(const GlobalVariable &GV)

Returns true if the annotation kind of the global variable GV is AnnotationOK.

Definition StaticDataProfileInfo.cpp:47

static bool hasExplicitSectionName(const GlobalVariable &GVar)

Definition StaticDataProfileInfo.cpp:21

This is an optimization pass for GlobalISel generic memory operations.

decltype(auto) dyn_cast(const From &Val)

dyn_cast - 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.

LLVM_ABI raw_ostream & dbgs()

dbgs() - This returns a reference to a raw_ostream for debugging messages.

FunctionAddr 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.