14#ifndef LLVM_TRANSFORMS_IPO_SAMPLEPROFILEMATCHER_H
15#define LLVM_TRANSFORMS_IPO_SAMPLEPROFILEMATCHER_H
35 enum class MatchState {
44 UnchangedMismatch = 4,
46 RecoveredMismatch = 5,
56 FuncCallsiteMatchStates;
68 uint64_t MismatchedFunctionSamples = 0;
69 uint64_t MismatchedCallsiteSamples = 0;
70 uint64_t RecoveredCallsiteSamples = 0;
74 static constexpr const char *UnknownIndirectCallee =
75 "unknown.indirect.callee";
81 : M(M), Reader(Reader), ProbeManager(ProbeManager), LTOPhase(LTOPhase){};
86 FuncCallsiteMatchStates.
clear();
93 if (It != FlattenedProfiles.end())
97 void runOnFunction(Function &
F);
98 void findIRAnchors(
const Function &
F,
99 std::map<LineLocation, StringRef> &IRAnchors);
100 void findProfileAnchors(
101 const FunctionSamples &FS,
102 std::map<LineLocation, std::unordered_set<FunctionId>> &ProfileAnchors);
105 void recordCallsiteMatchStates(
106 const Function &
F,
const std::map<LineLocation, StringRef> &IRAnchors,
107 const std::map<LineLocation, std::unordered_set<FunctionId>>
111 bool isMismatchState(
const enum MatchState &State) {
112 return State == MatchState::InitialMismatch ||
113 State == MatchState::UnchangedMismatch ||
114 State == MatchState::RemovedMatch;
117 bool isInitialState(
const enum MatchState &State) {
118 return State == MatchState::InitialMatch ||
119 State == MatchState::InitialMismatch;
122 bool isFinalState(
const enum MatchState &State) {
123 return State == MatchState::UnchangedMatch ||
124 State == MatchState::UnchangedMismatch ||
125 State == MatchState::RecoveredMismatch ||
126 State == MatchState::RemovedMatch;
131 void countMismatchedFuncSamples(
const FunctionSamples &FS,
bool IsTopLevel);
133 void countMismatchCallsites(
const FunctionSamples &FS);
136 void countMismatchedCallsiteSamples(
const FunctionSamples &FS);
137 void computeAndReportProfileStaleness();
139 LocToLocMap &getIRToProfileLocationMap(
const Function &
F) {
142 return Ret.first->second;
144 void distributeIRToProfileLocationMap();
145 void distributeIRToProfileLocationMap(FunctionSamples &FS);
146 void runStaleProfileMatching(
147 const Function &
F,
const std::map<LineLocation, StringRef> &IRAnchors,
148 const std::map<LineLocation, std::unordered_set<FunctionId>>
151 void reportOrPersistProfileStats();
This file provides the interface for the sampled PGO profile loader base implementation.
StringSet - A set-like wrapper for the StringMap.
A Module instance is used to store all the information related to an LLVM module.
SampleProfileMatcher(Module &M, SampleProfileReader &Reader, const PseudoProbeManager *ProbeManager, ThinOrFullLTOPhase LTOPhase)
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
std::pair< iterator, bool > try_emplace(StringRef Key, ArgsTy &&...Args)
Emplace a new element for the specified key into the map if the key isn't already in the map.
StringRef - Represent a constant reference to a string, i.e.
This class represents a function that is read from a sample profile.
Representation of the samples collected for a function.
static StringRef getCanonicalFnName(const Function &F)
Return the canonical name for a function, taking into account suffix elision policy attributes.
This class provides operator overloads to the map container using MD5 as the key type,...
iterator find(const SampleContext &Ctx)
Sample-based profile reader.
std::unordered_map< LineLocation, LineLocation, LineLocationHash > LocToLocMap
This is an optimization pass for GlobalISel generic memory operations.
ThinOrFullLTOPhase
This enumerates the LLVM full LTO or ThinLTO optimization phases.