LLVM: include/llvm/Analysis/ProfileSummaryInfo.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef LLVM_ANALYSIS_PROFILESUMMARYINFO_H

15#define LLVM_ANALYSIS_PROFILESUMMARYINFO_H

16

25#include

26#include

27

28namespace llvm {

31

32

33

34

35

36

37

38

39

40

41

43private:

45 std::unique_ptr Summary;

46 void computeThresholds();

47

48 std::optional<uint64_t> HotCountThreshold, ColdCountThreshold;

49

50

51

52 std::optional HasHugeWorkingSetSize;

53

54

55

56 std::optional HasLargeWorkingSetSize;

57

58 std::optional<uint64_t> computeThreshold(int PercentileCutoff) const;

59

60

62

63public:

66

67

68

70

71

73

74

79

80

85

86

91

92

93

94

95

96

97

99 ModuleAnalysisManager::Invalidator &) {

100 return false;

101 }

102

103

104 LLVM_ABI std::optional<uint64_t>

106 bool AllowSynthetic = false) const;

107

109

111

113

114

115

118 return false;

119 std::optionalFunction::ProfileCount FunctionCount = getEntryCount(F);

120

121

122

123 return FunctionCount && isHotCount(FunctionCount->getCount());

124 }

125

126

127 template <typename FuncT, typename BFIT>

130 return false;

131 if (auto FunctionCount = getEntryCount(F))

132 if (isHotCount(FunctionCount->getCount()))

133 return true;

134

135 if (auto TotalCallCount = getTotalCallCount(F))

137 return true;

138

139 for (const auto &BB : *F)

141 return true;

142 return false;

143 }

144

146

147 template <typename FuncT, typename BFIT>

150 return false;

151 if (auto FunctionCount = getEntryCount(F))

152 if (isColdCount(FunctionCount->getCount()))

153 return false;

154

155 if (auto TotalCallCount = getTotalCallCount(F))

157 return false;

158

159 for (const auto &BB : *F)

161 return false;

162 return true;

163 }

164

166

167

168 template <typename FuncT, typename BFIT>

170 const FuncT *F, BFIT &BFI) const {

171 return isFunctionHotOrColdInCallGraphNthPercentile<true, FuncT, BFIT>(

173 }

174

175

176 template <typename FuncT, typename BFIT>

178 const FuncT *F, BFIT &BFI) const {

179 return isFunctionHotOrColdInCallGraphNthPercentile<false, FuncT, BFIT>(

181 }

182

184

186

187

188

189

191

192

193

194

197

198

199 template <typename BBType, typename BFIT>

200 bool isHotBlock(const BBType *BB, BFIT *BFI) const {

201 auto Count = BFI->getBlockProfileCount(BB);

203 }

204

205

206 template <typename BBType, typename BFIT>

207 bool isColdBlock(const BBType *BB, BFIT *BFI) const {

208 auto Count = BFI->getBlockProfileCount(BB);

210 }

211

212 template

214 auto Count = BFI->getProfileCountFromFreq(BlockFreq);

216 }

217

218 template <typename BBType, typename BFIT>

220 BFIT *BFI) const {

221 return isHotOrColdBlockNthPercentile<true, BBType, BFIT>(PercentileCutoff,

222 BB, BFI);

223 }

224

225 template

227 BFIT *BFI) const {

228 return isHotOrColdBlockNthPercentile<true, BFIT>(PercentileCutoff,

229 BlockFreq, BFI);

230 }

231

232

233

234

235

236 template <typename BBType, typename BFIT>

238 BFIT *BFI) const {

239 return isHotOrColdBlockNthPercentile<false, BBType, BFIT>(PercentileCutoff,

240 BB, BFI);

241 }

242 template

244 BFIT *BFI) const {

245 return isHotOrColdBlockNthPercentile<false, BFIT>(PercentileCutoff,

246 BlockFreq, BFI);

247 }

248

251

254

255

257

258

260

262 return HotCountThreshold.value_or(0);

263 }

264

266 return ColdCountThreshold.value_or(0);

267 }

268

269private:

270 template

271 std::optional<uint64_t> getTotalCallCount(const FuncT *F) const {

272 return std::nullopt;

273 }

274

275 template <bool isHot, typename FuncT, typename BFIT>

276 bool isFunctionHotOrColdInCallGraphNthPercentile(int PercentileCutoff,

277 const FuncT *F,

278 BFIT &FI) const {

280 return false;

281 if (auto FunctionCount = getEntryCount(F)) {

282 if (isHot &&

284 return true;

286 FunctionCount->getCount()))

287 return false;

288 }

289 if (auto TotalCallCount = getTotalCallCount(F)) {

291 return true;

292 if (!isHot &&

294 return false;

295 }

296 for (const auto &BB : *F) {

298 return true;

300 return false;

301 }

302 return !isHot;

303 }

304

305 template

306 bool isHotOrColdCountNthPercentile(int PercentileCutoff, uint64_t C) const;

307

308 template <bool isHot, typename BBType, typename BFIT>

309 bool isHotOrColdBlockNthPercentile(int PercentileCutoff, const BBType *BB,

310 BFIT *BFI) const {

311 auto Count = BFI->getBlockProfileCount(BB);

312 if (isHot)

314 else

316 }

317

318 template <bool isHot, typename BFIT>

320 BlockFrequency BlockFreq,

321 BFIT *BFI) const {

322 auto Count = BFI->getProfileCountFromFreq(BlockFreq);

323 if (isHot)

325 else

327 }

328

329 template

330 std::optionalFunction::ProfileCount getEntryCount(const FuncT *F) const {

331 return F->getEntryCount();

332 }

333};

334

335template <>

336inline std::optional<uint64_t>

337ProfileSummaryInfo::getTotalCallCount(const Function *F) const {

339 return std::nullopt;

340 uint64_t TotalCallCount = 0;

341 for (const auto &BB : *F)

342 for (const auto &I : BB)

345 TotalCallCount += *CallCount;

346 return TotalCallCount;

347}

348

349

350

351

352template <>

353std::optionalFunction::ProfileCount

354ProfileSummaryInfo::getEntryCount(

356

357

359 std::unique_ptr PSI;

360

361public:

364

367

368 bool doInitialization(Module &M) override;

369 bool doFinalization(Module &M) override;

373};

374

375

378public:

380

382

383private:

386};

387

388

390 : public PassInfoMixin {

392

393public:

397};

398

399}

400

401#endif

This file defines the DenseMap class.

This header defines various interfaces for pass management in LLVM.

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)

Represent the analysis usage information of a pass.

void setPreservesAll()

Set by analyses that do not transform their input at all.

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

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

This class represents a function call, abstracting a target machine's calling convention.

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.

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

Definition ProfileSummaryInfo.h:377

ProfileSummaryInfo Result

Definition ProfileSummaryInfo.h:379

LLVM_ABI Result run(Module &M, ModuleAnalysisManager &)

ProfileSummaryInfoWrapperPass()

static char ID

Definition ProfileSummaryInfo.h:362

void getAnalysisUsage(AnalysisUsage &AU) const override

getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...

Definition ProfileSummaryInfo.h:370

ProfileSummaryInfo & getPSI()

Definition ProfileSummaryInfo.h:365

const ProfileSummaryInfo & getPSI() const

Definition ProfileSummaryInfo.h:366

Analysis providing profile information.

Definition ProfileSummaryInfo.h:42

bool hasCSInstrumentationProfile() const

Returns true if module M has context sensitive instrumentation profile.

Definition ProfileSummaryInfo.h:87

LLVM_ABI uint64_t getOrCompColdCountThreshold() const

Returns ColdCountThreshold if set.

bool hasProfileSummary() const

Returns true if profile summary is available.

Definition ProfileSummaryInfo.h:72

bool isHotBlockNthPercentile(int PercentileCutoff, const BBType *BB, BFIT *BFI) const

Definition ProfileSummaryInfo.h:219

bool isFunctionColdInCallGraph(const FuncT *F, BFIT &BFI) const

Returns true if F contains only cold code.

Definition ProfileSummaryInfo.h:148

LLVM_ABI bool isFunctionHotnessUnknown(const Function &F) const

Returns true if the hotness of F is unknown.

bool hasInstrumentationProfile() const

Returns true if module M has instrumentation profile.

Definition ProfileSummaryInfo.h:81

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

Returns the profile count for CallInst.

bool isFunctionColdInCallGraphNthPercentile(int PercentileCutoff, const FuncT *F, BFIT &BFI) const

Returns true if F contains cold code with regard to a given cold percentile cutoff value.

Definition ProfileSummaryInfo.h:177

bool hasSampleProfile() const

Returns true if module M has sample profile.

Definition ProfileSummaryInfo.h:75

bool isFunctionEntryHot(const FuncT *F) const

Returns true if F has hot function entry.

Definition ProfileSummaryInfo.h:116

bool isColdBlock(const BBType *BB, BFIT *BFI) const

Returns true if BasicBlock BB is considered cold.

Definition ProfileSummaryInfo.h:207

LLVM_ABI bool isColdCount(uint64_t C) const

Returns true if count C is considered cold.

bool isFunctionHotInCallGraphNthPercentile(int PercentileCutoff, const FuncT *F, BFIT &BFI) const

Returns true if F contains hot code with regard to a given hot percentile cutoff value.

Definition ProfileSummaryInfo.h:169

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.

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

If a summary is provided as argument, use that.

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.

uint64_t getColdCountThreshold() const

Returns ColdCountThreshold if set.

Definition ProfileSummaryInfo.h:265

bool isFunctionHotInCallGraph(const FuncT *F, BFIT &BFI) const

Returns true if F contains hot code.

Definition ProfileSummaryInfo.h:128

bool isColdBlock(BlockFrequency BlockFreq, const BFIT *BFI) const

Definition ProfileSummaryInfo.h:213

LLVM_ABI bool hasPartialSampleProfile() const

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

LLVM_ABI bool hasLargeWorkingSetSize() const

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

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

Returns true if call site CB is considered cold.

ProfileSummaryInfo(ProfileSummaryInfo &&Arg)=default

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

Returns true if the call site CB is considered hot.

ProfileSummaryInfo(const Module &M)

Definition ProfileSummaryInfo.h:64

uint64_t getHotCountThreshold() const

Returns HotCountThreshold if set.

Definition ProfileSummaryInfo.h:261

bool isHotBlock(const BBType *BB, BFIT *BFI) const

Returns true if BasicBlock BB is considered hot.

Definition ProfileSummaryInfo.h:200

bool isColdBlockNthPercentile(int PercentileCutoff, BlockFrequency BlockFreq, BFIT *BFI) const

Definition ProfileSummaryInfo.h:243

LLVM_ABI bool isHotCount(uint64_t C) const

Returns true if count C is considered hot.

LLVM_ABI bool hasHugeWorkingSetSize() const

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

bool isColdBlockNthPercentile(int PercentileCutoff, const BBType *BB, BFIT *BFI) const

Returns true if BasicBlock BB is considered cold with regard to a given cold percentile cutoff value.

Definition ProfileSummaryInfo.h:237

LLVM_ABI uint64_t getOrCompHotCountThreshold() const

Returns HotCountThreshold if set.

bool isHotBlockNthPercentile(int PercentileCutoff, BlockFrequency BlockFreq, BFIT *BFI) const

Definition ProfileSummaryInfo.h:226

bool invalidate(Module &, const PreservedAnalyses &, ModuleAnalysisManager::Invalidator &)

Handle the invalidation of this information.

Definition ProfileSummaryInfo.h:98

LLVM_ABI bool isFunctionEntryCold(const Function *F) const

Returns true if F has cold function entry.

static bool isRequired()

Definition ProfileSummaryInfo.h:396

ProfileSummaryPrinterPass(raw_ostream &OS)

Definition ProfileSummaryInfo.h:394

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

This class implements an extremely fast bulk output stream that can only output to a stream.

@ C

The default llvm calling convention, compatible with C.

This is an optimization pass for GlobalISel generic memory operations.

FunctionAddr VTableAddr Count

bool isa(const From &Val)

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

decltype(auto) cast(const From &Val)

cast - Return the argument parameter cast to the specified type.

AnalysisManager< Module > ModuleAnalysisManager

Convenience typedef for the Module analysis manager.

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

A CRTP mix-in to automatically provide informational APIs needed for passes.