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

1

2

3

4

5

6

7

8

9

10

11

12

13

24#include

25using namespace llvm;

26

27namespace llvm {

28

31 cl::desc("Specify the current profile is used as a partial profile."));

32

34 "scale-partial-sample-profile-working-set-size", cl::Hidden, cl::init(true),

36 "If true, scale the working set size of the partial sample profile "

37 "by the partial profile ratio to reflect the size of the program "

38 "being compiled."));

39

41 "partial-sample-profile-working-set-size-scale-factor", cl::Hidden,

43 cl::desc("The scale factor used to scale the working set size of the "

44 "partial sample profile along with the partial profile ratio. "

45 "This includes the factor of the profile counter per block "

46 "and the factor to scale the working set size to use the same "

47 "shared thresholds as PGO."));

48

49}

50

51

52

53

54

57 Summary.swap(Other);

58 return;

59 }

61 return;

62

63 auto *SummaryMD = M->getProfileSummary( true);

64 if (SummaryMD)

66

68

69 SummaryMD = M->getProfileSummary( false);

70 if (SummaryMD)

72 }

74 return;

75 computeThresholds();

76}

77

81 "We can only get profile count for call/invoke instruction.");

83

84

85

86

88 if (Call.extractProfTotalWeight(TotalCount))

89 return TotalCount;

90 return std::nullopt;

91 }

92 if (BFI)

94 return std::nullopt;

95}

96

99 return F.getEntryCount();

100}

101

102

103

104

106 if (F)

107 return false;

108 if (F->hasFnAttribute(Attribute::Cold))

109 return true;

111 return false;

112 auto FunctionCount = F->getEntryCount();

113

114

115

116 return FunctionCount && isColdCount(FunctionCount->getCount());

117}

118

119

120void ProfileSummaryInfo::computeThresholds() {

121 auto &DetailedSummary = Summary->getDetailedSummary();

124 HotCountThreshold =

128

129

130

131

134 (*ColdCountThreshold)--;

135 else

136 (*HotCountThreshold)++;

137 }

139 "Cold count threshold should be less than hot count threshold!");

141 HasHugeWorkingSetSize =

143 HasLargeWorkingSetSize =

145 } else {

146

147

148 double PartialProfileRatio = Summary->getPartialProfileRatio();

149 uint64_t ScaledHotEntryNumCounts =

150 static_cast<uint64_t>(HotEntry.NumCounts * PartialProfileRatio *

152 HasHugeWorkingSetSize =

154 HasLargeWorkingSetSize =

156 }

157}

158

159std::optional<uint64_t>

160ProfileSummaryInfo::computeThreshold(int PercentileCutoff) const {

162 return std::nullopt;

164 if (!Inserted)

165 return Iter->second;

166 auto &DetailedSummary = Summary->getDetailedSummary();

172}

173

175 return HasHugeWorkingSetSize && *HasHugeWorkingSetSize;

176}

177

179 return HasLargeWorkingSetSize && *HasLargeWorkingSetSize;

180}

181

183 return HotCountThreshold && C >= *HotCountThreshold;

184}

185

187 return ColdCountThreshold && C <= *ColdCountThreshold;

188}

189

190template

191bool ProfileSummaryInfo::isHotOrColdCountNthPercentile(int PercentileCutoff,

194 if (isHot)

196 else

198}

199

204

209

211 return HotCountThreshold.value_or(UINT64_MAX);

212}

213

215 return ColdCountThreshold.value_or(0);

216}

217

223

227 if (C)

229

230

231

233}

234

240

242 "Profile summary info", false, true)

243

246

251

253 PSI.reset();

254 return false;

255}

256

262

266

267 OS << "Functions in " << M.getName() << " with hot/cold annotations: \n";

268 for (auto &F : M) {

269 OS << F.getName();

271 OS << " :hot entry ";

273 OS << " :cold entry ";

274 OS << "\n";

275 }

277}

278

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

static cl::opt< unsigned > CountThreshold("hexagon-cext-threshold", cl::init(3), cl::Hidden, cl::desc("Minimum number of extenders to trigger replacement"))

Module.h This file contains the declarations for the Module class.

static cl::opt< unsigned > ColdCountThreshold("mfs-count-threshold", cl::desc("Minimum number of times a block must be executed to be retained."), cl::init(1), cl::Hidden)

static cl::opt< unsigned > PercentileCutoff("mfs-psi-cutoff", cl::desc("Percentile profile summary cutoff used to " "determine cold blocks. Unused if set to zero."), cl::init(999950), cl::Hidden)

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

PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)

Get the result of an analysis pass for a given IR unit.

BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...

LLVM_ABI std::optional< uint64_t > getBlockProfileCount(const BasicBlock *BB, bool AllowSynthetic=false) const

Returns the estimated profile count of BB.

Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...

LLVM_ABI Function * getCaller()

Helper to get the caller (the parent function).

bool hasProfileData(bool IncludeSynthetic=false) const

Return true if the function is annotated with profile data.

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.

A set of analyses that are preserved following a run of a transformation pass.

static PreservedAnalyses all()

Construct a special preserved set that preserves all passes.

An analysis pass based on the new PM to deliver ProfileSummaryInfo.

LLVM_ABI Result run(Module &M, ModuleAnalysisManager &)

Definition ProfileSummaryInfo.cpp:258

static LLVM_ABI const ProfileSummaryEntry & getEntryForPercentile(const SummaryEntryVector &DS, uint64_t Percentile)

Find the summary entry for a desired percentile of counts.

static LLVM_ABI uint64_t getHotCountThreshold(const SummaryEntryVector &DS)

static LLVM_ABI uint64_t getColdCountThreshold(const SummaryEntryVector &DS)

An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo.

bool doFinalization(Module &M) override

doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...

Definition ProfileSummaryInfo.cpp:252

bool doInitialization(Module &M) override

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

Definition ProfileSummaryInfo.cpp:247

Analysis providing profile information.

LLVM_ABI uint64_t getOrCompColdCountThreshold() const

Returns ColdCountThreshold if set.

Definition ProfileSummaryInfo.cpp:214

bool hasProfileSummary() const

Returns true if profile summary is available.

LLVM_ABI bool isFunctionHotnessUnknown(const Function &F) const

Returns true if the hotness of F is unknown.

Definition ProfileSummaryInfo.cpp:97

LLVM_ABI std::optional< uint64_t > getProfileCount(const CallBase &CallInst, BlockFrequencyInfo *BFI, bool AllowSynthetic=false) const

Returns the profile count for CallInst.

Definition ProfileSummaryInfo.cpp:78

bool hasSampleProfile() const

Returns true if module M has sample profile.

bool isFunctionEntryHot(const FuncT *F) const

Returns true if F has hot function entry.

LLVM_ABI bool isColdCount(uint64_t C) const

Returns true if count C is considered cold.

Definition ProfileSummaryInfo.cpp:186

LLVM_ABI bool isColdCountNthPercentile(int PercentileCutoff, uint64_t C) const

Returns true if count C is considered cold with regard to a given cold percentile cutoff value.

Definition ProfileSummaryInfo.cpp:205

LLVM_ABI void refresh(std::unique_ptr< ProfileSummary > &&Other=nullptr)

If a summary is provided as argument, use that.

Definition ProfileSummaryInfo.cpp:55

LLVM_ABI bool isHotCountNthPercentile(int PercentileCutoff, uint64_t C) const

Returns true if count C is considered hot with regard to a given hot percentile cutoff value.

Definition ProfileSummaryInfo.cpp:200

LLVM_ABI bool hasPartialSampleProfile() const

Returns true if module M has partial-profile sample profile.

Definition ProfileSummaryInfo.cpp:235

LLVM_ABI bool hasLargeWorkingSetSize() const

Returns true if the working set size of the code is considered large.

Definition ProfileSummaryInfo.cpp:178

LLVM_ABI bool isColdCallSite(const CallBase &CB, BlockFrequencyInfo *BFI) const

Returns true if call site CB is considered cold.

Definition ProfileSummaryInfo.cpp:224

LLVM_ABI bool isHotCallSite(const CallBase &CB, BlockFrequencyInfo *BFI) const

Returns true if the call site CB is considered hot.

Definition ProfileSummaryInfo.cpp:218

LLVM_ABI bool isHotCount(uint64_t C) const

Returns true if count C is considered hot.

Definition ProfileSummaryInfo.cpp:182

LLVM_ABI bool hasHugeWorkingSetSize() const

Returns true if the working set size of the code is considered huge.

Definition ProfileSummaryInfo.cpp:174

LLVM_ABI uint64_t getOrCompHotCountThreshold() const

Returns HotCountThreshold if set.

Definition ProfileSummaryInfo.cpp:210

LLVM_ABI bool isFunctionEntryCold(const Function *F) const

Returns true if F has cold function entry.

Definition ProfileSummaryInfo.cpp:105

LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)

Definition ProfileSummaryInfo.cpp:263

static LLVM_ABI ProfileSummary * getFromMD(Metadata *MD)

Construct profile summary from metdata.

unsigned ID

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

@ C

The default llvm calling convention, compatible with C.

initializer< Ty > init(const Ty &Val)

This is an optimization pass for GlobalISel generic memory operations.

static cl::opt< double > PartialSampleProfileWorkingSetSizeScaleFactor("partial-sample-profile-working-set-size-scale-factor", cl::Hidden, cl::init(0.008), cl::desc("The scale factor used to scale the working set size of the " "partial sample profile along with the partial profile ratio. " "This includes the factor of the profile counter per block " "and the factor to scale the working set size to use the same " "shared thresholds as PGO."))

LLVM_ABI cl::opt< bool > ScalePartialSampleProfileWorkingSetSize

bool isa(const From &Val)

isa - Return true if the parameter to the template is an instance of one of the template type argu...

LLVM_ABI cl::opt< unsigned > ProfileSummaryLargeWorkingSetSizeThreshold

static cl::opt< bool > PartialProfile("partial-profile", cl::Hidden, cl::init(false), cl::desc("Specify the current profile is used as a partial profile."))

LLVM_ABI cl::opt< int > ProfileSummaryCutoffHot

LLVM_ABI cl::opt< unsigned > ProfileSummaryHugeWorkingSetSizeThreshold

AnalysisManager< Module > ModuleAnalysisManager

Convenience typedef for the Module analysis manager.

A special type used by analysis passes to provide an address that identifies that particular analysis...