42 enum class MatchState {
51 UnchangedMismatch = 4,
53 RecoveredMismatch = 5,
63 FuncCallsiteMatchStates;
65 struct FuncToProfileNameMapHash {
67 operator()(
const std::pair<const Function *, FunctionId> &
P)
const {
74 std::unordered_map<std::pair<const Function *, FunctionId>,
bool,
75 FuncToProfileNameMapHash>
76 FuncProfileMatchCache;
94 FunctionsWithoutProfile;
97 std::shared_ptr<ProfileSymbolList> PSL;
103 uint64_t TotalProfiledCallsites = 0;
104 uint64_t NumMismatchedCallsites = 0;
109 uint64_t MismatchedFunctionSamples = 0;
110 uint64_t MismatchedCallsiteSamples = 0;
111 uint64_t RecoveredCallsiteSamples = 0;
114 uint64_t NumCallGraphRecoveredProfiledFunc = 0;
115 uint64_t NumCallGraphRecoveredFuncSamples = 0;
119 static constexpr const char *UnknownIndirectCallee =
120 "unknown.indirect.callee";
127 std::shared_ptr<ProfileSymbolList> PSL,
129 &FuncNameToProfNameMap)
130 : M(M), Reader(Reader), CG(CG), ProbeManager(ProbeManager),
131 LTOPhase(LTOPhase), FuncNameToProfNameMap(&FuncNameToProfNameMap),
132 SymbolMap(&
SymMap), PSL(PSL) {};
140 freeContainer(FuncCallsiteMatchStates);
141 freeContainer(FunctionsWithoutProfile);
142 freeContainer(FuncToProfileNameMap);
147 auto It = FlattenedProfiles.
find(Fname);
148 if (It != FlattenedProfiles.end())
152 FunctionSamples *getFlattenedSamplesFor(
const Function &
F) {
154 return getFlattenedSamplesFor(FunctionId(CanonFName));
156 template <
typename T>
inline void freeContainer(
T &
C) {
160 void getFilteredAnchorList(
const AnchorMap &IRAnchors,
164 void runOnFunction(Function &
F);
165 void findIRAnchors(
const Function &
F,
AnchorMap &IRAnchors)
const;
166 void findProfileAnchors(
const FunctionSamples &FS,
170 void recordCallsiteMatchStates(
const Function &
F,
const AnchorMap &IRAnchors,
174 bool isMismatchState(
const enum MatchState &State) {
175 return State == MatchState::InitialMismatch ||
176 State == MatchState::UnchangedMismatch ||
177 State == MatchState::RemovedMatch;
180 bool isInitialState(
const enum MatchState &State) {
181 return State == MatchState::InitialMatch ||
182 State == MatchState::InitialMismatch;
185 bool isFinalState(
const enum MatchState &State) {
186 return State == MatchState::UnchangedMatch ||
187 State == MatchState::UnchangedMismatch ||
188 State == MatchState::RecoveredMismatch ||
189 State == MatchState::RemovedMatch;
192 void countCallGraphRecoveredSamples(
193 const FunctionSamples &FS,
194 std::unordered_set<FunctionId> &MatchedUnusedProfile);
197 void countMismatchedFuncSamples(
const FunctionSamples &FS,
bool IsTopLevel);
199 void countMismatchCallsites(
const FunctionSamples &FS);
202 void countMismatchedCallsiteSamples(
const FunctionSamples &FS);
203 void computeAndReportProfileStaleness();
204 void UpdateWithSalvagedProfiles();
206 LocToLocMap &getIRToProfileLocationMap(
const Function &
F) {
209 void distributeIRToProfileLocationMap();
210 void distributeIRToProfileLocationMap(FunctionSamples &FS);
213 bool MatchUnusedFunction);
214 void matchNonCallsiteLocs(
const LocToLocMap &AnchorMatchings,
217 void runStaleProfileMatching(
const Function &
F,
const AnchorMap &IRAnchors,
220 bool RunCFGMatching,
bool RunCGMatching);
222 bool functionHasProfile(
const FunctionId &IRFuncName,
223 Function *&FuncWithoutProfile);
224 bool isProfileUnused(
const FunctionId &ProfileFuncName);
225 bool functionMatchesProfileHelper(
const Function &IRFunc,
226 const FunctionId &ProfFunc);
230 bool functionMatchesProfile(
const FunctionId &IRFuncName,
231 const FunctionId &ProfileFuncName,
232 bool FindMatchedProfileOnly);
236 bool functionMatchesProfile(Function &IRFunc,
const FunctionId &ProfFunc,
237 bool FindMatchedProfileOnly);
241 void findFunctionsWithoutProfile();
244 void matchFunctionsWithoutProfileByBasename();
245 void reportOrPersistProfileStats();
SampleProfileMatcher(Module &M, SampleProfileReader &Reader, LazyCallGraph &CG, const PseudoProbeManager *ProbeManager, ThinOrFullLTOPhase LTOPhase, HashKeyMap< std::unordered_map, FunctionId, Function * > &SymMap, std::shared_ptr< ProfileSymbolList > PSL, HashKeyMap< std::unordered_map, FunctionId, FunctionId > &FuncNameToProfNameMap)