14#ifndef LLVM_TRANSFORMS_IPO_SAMPLEPROFILEMATCHER_H
15#define LLVM_TRANSFORMS_IPO_SAMPLEPROFILEMATCHER_H
22using AnchorList = std::vector<std::pair<LineLocation, FunctionId>>;
23using AnchorMap = std::map<LineLocation, FunctionId>;
38 enum class MatchState {
47 UnchangedMismatch = 4,
49 RecoveredMismatch = 5,
59 FuncCallsiteMatchStates;
71 uint64_t MismatchedFunctionSamples = 0;
72 uint64_t MismatchedCallsiteSamples = 0;
73 uint64_t RecoveredCallsiteSamples = 0;
77 static constexpr const char *UnknownIndirectCallee =
78 "unknown.indirect.callee";
84 : M(M), Reader(Reader), ProbeManager(ProbeManager), LTOPhase(LTOPhase){};
89 FuncCallsiteMatchStates.
clear();
96 if (It != FlattenedProfiles.end())
100 void runOnFunction(Function &
F);
101 void findIRAnchors(
const Function &
F,
AnchorMap &IRAnchors);
102 void findProfileAnchors(
const FunctionSamples &FS,
AnchorMap &ProfileAnchors);
105 void recordCallsiteMatchStates(
const Function &
F,
const AnchorMap &IRAnchors,
109 bool isMismatchState(
const enum MatchState &State) {
110 return State == MatchState::InitialMismatch ||
111 State == MatchState::UnchangedMismatch ||
112 State == MatchState::RemovedMatch;
115 bool isInitialState(
const enum MatchState &State) {
116 return State == MatchState::InitialMatch ||
117 State == MatchState::InitialMismatch;
120 bool isFinalState(
const enum MatchState &State) {
121 return State == MatchState::UnchangedMatch ||
122 State == MatchState::UnchangedMismatch ||
123 State == MatchState::RecoveredMismatch ||
124 State == MatchState::RemovedMatch;
129 void countMismatchedFuncSamples(
const FunctionSamples &FS,
bool IsTopLevel);
131 void countMismatchCallsites(
const FunctionSamples &FS);
134 void countMismatchedCallsiteSamples(
const FunctionSamples &FS);
135 void computeAndReportProfileStaleness();
137 LocToLocMap &getIRToProfileLocationMap(
const Function &
F) {
140 return Ret.first->second;
142 void distributeIRToProfileLocationMap();
143 void distributeIRToProfileLocationMap(FunctionSamples &FS);
155 longestCommonSequence(
const AnchorList &IRCallsiteAnchors,
156 const AnchorList &ProfileCallsiteAnchors)
const;
157 void matchNonCallsiteLocs(
const LocToLocMap &AnchorMatchings,
160 void runStaleProfileMatching(
const Function &
F,
const AnchorMap &IRAnchors,
163 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.
std::vector< std::pair< LineLocation, FunctionId > > AnchorList
std::map< LineLocation, FunctionId > AnchorMap
ThinOrFullLTOPhase
This enumerates the LLVM full LTO or ThinLTO optimization phases.