44 enum class MatchState {
53 UnchangedMismatch = 4,
55 RecoveredMismatch = 5,
89 std::shared_ptr<ProfileSymbolList> PSL;
101 uint64_t MismatchedFunctionSamples = 0;
102 uint64_t MismatchedCallsiteSamples = 0;
103 uint64_t RecoveredCallsiteSamples = 0;
106 uint64_t NumCallGraphRecoveredProfiledFunc = 0;
107 uint64_t NumCallGraphRecoveredFuncSamples = 0;
111 static constexpr const char *UnknownIndirectCallee =
112 "unknown.indirect.callee";
119 std::shared_ptr<ProfileSymbolList> PSL,
121 : M(M), Reader(Reader), CG(CG), ProbeManager(ProbeManager),
122 LTOPhase(LTOPhase), FuncNameToProfNameMap(&FuncNameToProfNameMap),
123 SymbolMap(&
SymMap), PSL(PSL) {};
131 freeContainer(FuncCallsiteMatchStates);
132 freeContainer(FunctionsWithoutProfile);
133 freeContainer(FuncToProfileNameMap);
138 auto It = FlattenedProfiles.
find(Fname);
139 if (It != FlattenedProfiles.end())
143 FunctionSamples *getFlattenedSamplesFor(
const Function &
F) {
145 return getFlattenedSamplesFor(FunctionId(CanonFName));
147 template <
typename T>
inline void freeContainer(
T &
C) {
151 void getFilteredAnchorList(
const AnchorMap &IRAnchors,
157 void findProfileAnchors(
const FunctionSamples &FS,
159 bool anchorsMatch(
const FunctionId &IRAnchor,
160 const FunctionId &ProfileAnchor)
const;
167 bool isMismatchState(
const enum MatchState &State) {
168 return State == MatchState::InitialMismatch ||
169 State == MatchState::UnchangedMismatch ||
170 State == MatchState::RemovedMatch;
173 bool isInitialState(
const enum MatchState &State) {
174 return State == MatchState::InitialMatch ||
175 State == MatchState::InitialMismatch;
178 bool isFinalState(
const enum MatchState &State) {
179 return State == MatchState::UnchangedMatch ||
180 State == MatchState::UnchangedMismatch ||
181 State == MatchState::RecoveredMismatch ||
182 State == MatchState::RemovedMatch;
186 countCallGraphRecoveredSamples(
const FunctionSamples &FS,
187 DenseSet<FunctionId> &MatchedUnusedProfile);
190 void countMismatchedFuncSamples(
const FunctionSamples &FS,
bool IsTopLevel);
192 void countMismatchCallsites(
const FunctionSamples &FS);
195 void countMismatchedCallsiteSamples(
const FunctionSamples &FS);
196 void computeAndReportProfileStaleness();
197 void UpdateWithSalvagedProfiles();
199 LocToLocMap &getIRToProfileLocationMap(
const FunctionSamples &FS) {
200 return FuncMappings[
FS.getFuncName()];
202 void distributeIRToProfileLocationMap();
203 void distributeIRToProfileLocationMap(FunctionSamples &FS);
206 bool MatchUnusedFunction);
207 void matchNonCallsiteLocs(
const LocToLocMap &AnchorMatchings,
213 bool RunCFGMatching,
bool RunCGMatching);
215 bool functionHasProfile(
const FunctionId &IRFuncName,
217 bool isProfileUnused(
const FunctionId &ProfileFuncName);
218 bool functionMatchesProfileHelper(
const Function &IRFunc,
219 const FunctionId &ProfFunc);
223 bool functionMatchesProfile(
const FunctionId &IRFuncName,
224 const FunctionId &ProfileFuncName,
225 bool FindMatchedProfileOnly);
229 bool functionMatchesProfile(
Function &IRFunc,
const FunctionId &ProfFunc,
230 bool FindMatchedProfileOnly);
234 void findFunctionsWithoutProfile();
237 void matchFunctionsWithoutProfileByBasename();
SampleProfileMatcher(Module &M, SampleProfileReader &Reader, LazyCallGraph &CG, const PseudoProbeManager *ProbeManager, ThinOrFullLTOPhase LTOPhase, HashKeyMap< DenseMap, FunctionId, Function * > &SymMap, std::shared_ptr< ProfileSymbolList > PSL, HashKeyMap< DenseMap, FunctionId, FunctionId > &FuncNameToProfNameMap)