LLVM 19.0.0git
SampleProfileLoaderBaseUtil.h
Go to the documentation of this file.
1////===- SampleProfileLoadBaseUtil.h - Profile loader util func --*- C++-*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10/// This file provides the utility functions for the sampled PGO loader base
11/// implementation.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_TRANSFORMS_UTILS_SAMPLEPROFILELOADERBASEUTIL_H
16#define LLVM_TRANSFORMS_UTILS_SAMPLEPROFILELOADERBASEUTIL_H
17
18#include "llvm/ADT/DenseMap.h"
21
22namespace llvm {
23using namespace sampleprof;
24
25class ProfileSummaryInfo;
26class Module;
27
28extern cl::opt<unsigned> SampleProfileMaxPropagateIterations;
29extern cl::opt<unsigned> SampleProfileRecordCoverage;
30extern cl::opt<unsigned> SampleProfileSampleCoverage;
31extern cl::opt<bool> NoWarnSampleUnused;
32
33namespace sampleprofutil {
34
36public:
37 bool markSamplesUsed(const FunctionSamples *FS, uint32_t LineOffset,
38 uint32_t Discriminator, uint64_t Samples);
39 unsigned computeCoverage(unsigned Used, unsigned Total) const;
40 unsigned countUsedRecords(const FunctionSamples *FS,
41 ProfileSummaryInfo *PSI) const;
42 unsigned countBodyRecords(const FunctionSamples *FS,
43 ProfileSummaryInfo *PSI) const;
44 uint64_t getTotalUsedSamples() const { return TotalUsedSamples; }
46 ProfileSummaryInfo *PSI) const;
47
48 void clear() {
49 SampleCoverage.clear();
50 TotalUsedSamples = 0;
51 }
52 void setProfAccForSymsInList(bool V) { ProfAccForSymsInList = V; }
53
54private:
55 using BodySampleCoverageMap = std::map<LineLocation, unsigned>;
56 using FunctionSamplesCoverageMap =
58
59 /// Coverage map for sampling records.
60 ///
61 /// This map keeps a record of sampling records that have been matched to
62 /// an IR instruction. This is used to detect some form of staleness in
63 /// profiles (see flag -sample-profile-check-coverage).
64 ///
65 /// Each entry in the map corresponds to a FunctionSamples instance. This is
66 /// another map that counts how many times the sample record at the
67 /// given location has been used.
68 FunctionSamplesCoverageMap SampleCoverage;
69
70 /// Number of samples used from the profile.
71 ///
72 /// When a sampling record is used for the first time, the samples from
73 /// that record are added to this accumulator. Coverage is later computed
74 /// based on the total number of samples available in this function and
75 /// its callsites.
76 ///
77 /// Note that this accumulator tracks samples used from a single function
78 /// and all the inlined callsites. Strictly, we should have a map of counters
79 /// keyed by FunctionSamples pointers, but these stats are cleared after
80 /// every function, so we just need to keep a single counter.
81 uint64_t TotalUsedSamples = 0;
82
83 // For symbol in profile symbol list, whether to regard their profiles
84 // to be accurate. This is passed from the SampleLoader instance.
85 bool ProfAccForSymsInList = false;
86};
87
88/// Return true if the given callsite is hot wrt to hot cutoff threshold.
89bool callsiteIsHot(const FunctionSamples *CallsiteFS, ProfileSummaryInfo *PSI,
90 bool ProfAccForSymsInList);
91
92/// Create a global variable to flag FSDiscriminators are used.
94
95} // end of namespace sampleprofutil
96} // end of namespace llvm
97
98#endif // LLVM_TRANSFORMS_UTILS_SAMPLEPROFILELOADERBASEUTIL_H
This file defines the DenseMap class.
Machine Check Debug Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
Analysis providing profile information.
Representation of the samples collected for a function.
Definition: SampleProf.h:744
unsigned countBodyRecords(const FunctionSamples *FS, ProfileSummaryInfo *PSI) const
Return the number of sample records in the body of this profile.
unsigned countUsedRecords(const FunctionSamples *FS, ProfileSummaryInfo *PSI) const
Return the number of sample records that were applied from this profile.
unsigned computeCoverage(unsigned Used, unsigned Total) const
Return the fraction of sample records used in this profile.
uint64_t countBodySamples(const FunctionSamples *FS, ProfileSummaryInfo *PSI) const
Return the number of samples collected in the body of this profile.
bool markSamplesUsed(const FunctionSamples *FS, uint32_t LineOffset, uint32_t Discriminator, uint64_t Samples)
Mark as used the sample record for the given function samples at (LineOffset, Discriminator).
void createFSDiscriminatorVariable(Module *M)
Create a global variable to flag FSDiscriminators are used.
bool callsiteIsHot(const FunctionSamples *CallsiteFS, ProfileSummaryInfo *PSI, bool ProfAccForSymsInList)
Return true if the given callsite is hot wrt to hot cutoff threshold.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
cl::opt< unsigned > SampleProfileSampleCoverage
cl::opt< unsigned > SampleProfileRecordCoverage
cl::opt< unsigned > SampleProfileMaxPropagateIterations
cl::opt< bool > NoWarnSampleUnused