================ @@ -2205,93 +2230,141 @@ void SampleProfileMatcher::countMismatchedSamples(const FunctionSamples &FS) { countMismatchedSamples(CS.second); } -void SampleProfileMatcher::countProfileMismatches( - const Function &F, const FunctionSamples &FS, - const std::map<LineLocation, StringRef> &IRAnchors, +void ProfileMatchStats::countMismatchedCallsites( + const Function &F, const std::map<LineLocation, StringRef> &IRAnchors, + const std::map<LineLocation, std::unordered_set<FunctionId>> + &ProfileAnchors, + const LocToLocMap &IRToProfileLocationMap) { + auto &MismatchedCallsites = + FuncMismatchedCallsites[FunctionSamples::getCanonicalFnName(F.getName())]; + + auto MapIRLocToProfileLoc = [&](const LineLocation &IRLoc) { + const auto &ProfileLoc = IRToProfileLocationMap.find(IRLoc); + if (ProfileLoc != IRToProfileLocationMap.end()) + return ProfileLoc->second; + else + return IRLoc; + }; + + std::set<LineLocation> MatchedCallsites; + for (const auto &I : IRAnchors) { + // In post-match, use the matching result to remap the current IR callsite. + const auto &Loc = MapIRLocToProfileLoc(I.first); + const auto &IRCalleeName = I.second; + const auto &It = ProfileAnchors.find(Loc); + if (It == ProfileAnchors.end()) + continue; + const auto &Callees = It->second; + + // Since indirect call does not have CalleeName, check conservatively if + // callsite in the profile is a callsite location. This is to reduce num of + // false positive since otherwise all the indirect call samples will be + // reported as mismatching. + if (IRCalleeName == SampleProfileMatcher::UnknownIndirectCallee) + MatchedCallsites.insert(Loc); + else if (Callees.count(getRepInFormat(IRCalleeName))) ---------------- WenleiHe wrote:
Add comment explain why we don't expect exactly one callee in profile when there is only one callee in IR. https://github.com/llvm/llvm-project/pull/79090 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits