32 const IPOOptions &Opts;
34 bool SalvageStaleProfile;
35 bool SalvageUnusedProfile;
50 enum class MatchState {
59 UnchangedMismatch = 4,
61 RecoveredMismatch = 5,
95 std::shared_ptr<ProfileSymbolList> PSL;
101 uint64_t TotalProfiledCallsites = 0;
102 uint64_t NumMismatchedCallsites = 0;
107 uint64_t MismatchedFunctionSamples = 0;
108 uint64_t MismatchedCallsiteSamples = 0;
109 uint64_t RecoveredCallsiteSamples = 0;
112 uint64_t NumCallGraphRecoveredProfiledFunc = 0;
113 uint64_t NumCallGraphRecoveredFuncSamples = 0;
117 static constexpr const char *UnknownIndirectCallee =
118 "unknown.indirect.callee";
126 std::shared_ptr<ProfileSymbolList> PSL,
128 bool SalvageStaleProfile,
bool SalvageUnusedProfile)
129 : Opts(Opts), SalvageStaleProfile(SalvageStaleProfile),
130 SalvageUnusedProfile(SalvageUnusedProfile), M(M), Reader(Reader),
131 CG(CG), ProbeManager(ProbeManager), LTOPhase(LTOPhase),
132 FuncNameToProfNameMap(&FuncNameToProfNameMap), SymbolMap(&
SymMap),
141 freeContainer(FuncCallsiteMatchStates);
142 freeContainer(FunctionsWithoutProfile);
143 freeContainer(FuncToProfileNameMap);
148 auto It = FlattenedProfiles.
find(Fname);
149 if (It != FlattenedProfiles.end())
153 FunctionSamples *getFlattenedSamplesFor(
const Function &
F) {
155 return getFlattenedSamplesFor(FunctionId(CanonFName));
157 template <
typename T>
inline void freeContainer(
T &
C) {
161 void getFilteredAnchorList(
const AnchorMap &IRAnchors,
167 void findProfileAnchors(
const FunctionSamples &FS,
169 bool anchorsMatch(
const FunctionId &IRAnchor,
170 const FunctionId &ProfileAnchor)
const;
177 bool isMismatchState(
const enum MatchState &State) {
178 return State == MatchState::InitialMismatch ||
179 State == MatchState::UnchangedMismatch ||
180 State == MatchState::RemovedMatch;
183 bool isInitialState(
const enum MatchState &State) {
184 return State == MatchState::InitialMatch ||
185 State == MatchState::InitialMismatch;
188 bool isFinalState(
const enum MatchState &State) {
189 return State == MatchState::UnchangedMatch ||
190 State == MatchState::UnchangedMismatch ||
191 State == MatchState::RecoveredMismatch ||
192 State == MatchState::RemovedMatch;
196 countCallGraphRecoveredSamples(
const FunctionSamples &FS,
197 DenseSet<FunctionId> &MatchedUnusedProfile);
200 void countMismatchedFuncSamples(
const FunctionSamples &FS,
bool IsTopLevel);
202 void countMismatchCallsites(
const FunctionSamples &FS);
205 void countMismatchedCallsiteSamples(
const FunctionSamples &FS);
206 void computeAndReportProfileStaleness();
207 void UpdateWithSalvagedProfiles();
209 LocToLocMap &getIRToProfileLocationMap(
const FunctionSamples &FS) {
210 return FuncMappings[
FS.getFuncName()];
212 void distributeIRToProfileLocationMap();
213 void distributeIRToProfileLocationMap(FunctionSamples &FS);
216 bool MatchUnusedFunction);
217 void matchNonCallsiteLocs(
const LocToLocMap &AnchorMatchings,
223 bool RunCFGMatching,
bool RunCGMatching);
225 bool functionHasProfile(
const FunctionId &IRFuncName,
227 bool isProfileUnused(
const FunctionId &ProfileFuncName);
228 bool functionMatchesProfileHelper(
const Function &IRFunc,
229 const FunctionId &ProfFunc);
233 bool functionMatchesProfile(
const FunctionId &IRFuncName,
234 const FunctionId &ProfileFuncName,
235 bool FindMatchedProfileOnly);
239 bool functionMatchesProfile(
Function &IRFunc,
const FunctionId &ProfFunc,
240 bool FindMatchedProfileOnly);
244 void findFunctionsWithoutProfile();
247 void matchFunctionsWithoutProfileByBasename();
SampleProfileMatcher(const IPOOptions &Opts, 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, bool SalvageStaleProfile, bool SalvageUnusedProfile)