22#include <unordered_set>
27#define DEBUG_TYPE "sample-profile-matcher"
30 "Number of functions matched by demangled basename");
36 cl::desc(
"Consider a profile matches a function if the similarity of their "
37 "callee sequences is above the specified percentile."));
41 cl::desc(
"The minimum number of basic blocks required for a function to "
42 "run stale profile call graph matching."));
46 cl::desc(
"The minimum number of call anchors required for a function to "
47 "run stale profile call graph matching."));
52 "Load top-level profiles that the sample reader initially skipped for "
53 "the call-graph matching (only meaningful for extended binary "
63 cl::desc(
"The maximum number of functions in a module, above which salvage "
64 "unused profile will be skipped."));
68 cl::desc(
"The maximum number of callsites in a function, above which stale "
69 "profile matching will be skipped."));
73void SampleProfileMatcher::findIRAnchors(
const Function &
F,
78 auto FindTopLevelInlinedCallsite = [](
const DILocation *DIL) {
79 assert((DIL && DIL->getInlinedAt()) &&
"No inlined callsite");
83 DIL = DIL->getInlinedAt();
84 }
while (DIL->getInlinedAt());
88 StringRef CalleeName = PrevDIL->getSubprogramLinkageName();
89 return std::make_pair(Callsite, FunctionId(CalleeName));
92 auto GetCanonicalCalleeName = [](
const CallBase *CB) {
93 StringRef CalleeName = UnknownIndirectCallee;
94 if (Function *Callee = CB->getCalledFunction())
102 DILocation *DIL =
I.getDebugLoc();
109 if (DIL->getInlinedAt()) {
110 IRAnchors.emplace(FindTopLevelInlinedCallsite(DIL));
113 StringRef CalleeName;
117 CalleeName = GetCanonicalCalleeName(CB);
119 LineLocation Loc = LineLocation(Probe->Id, 0);
120 IRAnchors.emplace(Loc, FunctionId(CalleeName));
130 if (DIL->getInlinedAt()) {
131 IRAnchors.emplace(FindTopLevelInlinedCallsite(DIL));
136 IRAnchors.emplace(Callsite, FunctionId(CalleeName));
143void SampleProfileMatcher::findProfileAnchors(
const FunctionSamples &FS,
145 auto isInvalidLineOffset = [](uint32_t LineOffset) {
146 return LineOffset & 0x8000;
149 auto InsertAnchor = [](
const LineLocation &Loc,
const FunctionId &CalleeName,
151 auto Ret = ProfileAnchors.try_emplace(Loc, CalleeName);
155 Ret.first->second = FunctionId(UnknownIndirectCallee);
159 for (
const auto &
I :
FS.getBodySamples()) {
160 const LineLocation &Loc =
I.first;
163 for (
const auto &
C :
I.second.getCallTargets())
164 InsertAnchor(Loc,
C.first, ProfileAnchors);
167 for (
const auto &
I :
FS.getCallsiteSamples()) {
168 const LineLocation &Loc =
I.first;
171 for (
const auto &
C :
I.second)
172 InsertAnchor(Loc,
C.first, ProfileAnchors);
176bool SampleProfileMatcher::functionHasProfile(
const FunctionId &IRFuncName,
178 FuncWithoutProfile =
nullptr;
179 auto R = FunctionsWithoutProfile.find(IRFuncName);
180 if (R != FunctionsWithoutProfile.end())
181 FuncWithoutProfile =
R->second;
182 return !FuncWithoutProfile;
185bool SampleProfileMatcher::isProfileUnused(
const FunctionId &ProfileFuncName) {
188 return (SymbolMap->find(ProfileFuncName) == SymbolMap->end()) &&
192 (ProbeManager->getDesc(ProfileFuncName.
stringRef()) ==
nullptr));
195bool SampleProfileMatcher::functionMatchesProfile(
197 bool FindMatchedProfileOnly) {
198 if (IRFuncName == ProfileFuncName)
206 if (functionHasProfile(IRFuncName, IRFunc) ||
207 !isProfileUnused(ProfileFuncName))
211 "IR function should be different from profile function to match");
212 return functionMatchesProfile(*IRFunc, ProfileFuncName,
213 FindMatchedProfileOnly);
217SampleProfileMatcher::longestCommonSequence(
const AnchorList &AnchorList1,
219 bool MatchUnusedFunction) {
222 AnchorList1, AnchorList2,
223 [&](
const FunctionId &
A,
const FunctionId &
B) {
224 return functionMatchesProfile(
229 [&](LineLocation
A, LineLocation
B) {
230 MatchedAnchors.try_emplace(
A,
B);
232 return MatchedAnchors;
235void SampleProfileMatcher::matchNonCallsiteLocs(
238 auto UpdateMatching = [&](
const LineLocation &From,
const LineLocation &To) {
241 IRToProfileLocationMap.insert_or_assign(From, To);
243 IRToProfileLocationMap.erase(From);
247 int32_t LocationDelta = 0;
249 for (
const auto &
IR : IRAnchors) {
250 const auto &Loc =
IR.first;
251 bool IsMatchedAnchor =
false;
253 auto R = MatchedAnchors.find(Loc);
254 if (R != MatchedAnchors.end()) {
255 const auto &Candidate =
R->second;
256 UpdateMatching(Loc, Candidate);
258 <<
" is matched from " << Loc <<
" to " << Candidate
260 LocationDelta = Candidate.LineOffset - Loc.
LineOffset;
266 for (
size_t I = (LastMatchedNonAnchors.
size() + 1) / 2;
267 I < LastMatchedNonAnchors.
size();
I++) {
268 const auto &
L = LastMatchedNonAnchors[
I];
269 uint32_t CandidateLineOffset =
L.LineOffset + LocationDelta;
270 LineLocation Candidate(CandidateLineOffset,
L.Discriminator);
271 UpdateMatching(L, Candidate);
273 <<
" to " << Candidate <<
"\n");
276 IsMatchedAnchor =
true;
277 LastMatchedNonAnchors.
clear();
281 if (!IsMatchedAnchor) {
282 uint32_t CandidateLineOffset = Loc.
LineOffset + LocationDelta;
283 LineLocation Candidate(CandidateLineOffset, Loc.
Discriminator);
284 UpdateMatching(Loc, Candidate);
286 << Candidate <<
"\n");
294void SampleProfileMatcher::getFilteredAnchorList(
297 for (
const auto &
I : IRAnchors) {
298 if (
I.second.stringRef().empty())
300 FilteredIRAnchorsList.emplace_back(
I);
303 for (
const auto &
I : ProfileAnchors)
304 FilteredProfileAnchorList.emplace_back(
I);
324void SampleProfileMatcher::runStaleProfileMatching(
327 bool RunCFGMatching,
bool RunCGMatching) {
328 if (!RunCFGMatching && !RunCGMatching)
332 assert(IRToProfileLocationMap.empty() &&
333 "Run stale profile matching only once per function");
337 getFilteredAnchorList(IRAnchors, ProfileAnchors, FilteredIRAnchorsList,
338 FilteredProfileAnchorList);
340 if (FilteredIRAnchorsList.empty() || FilteredProfileAnchorList.empty())
346 <<
" because the number of callsites in the IR is "
347 << FilteredIRAnchorsList.size()
348 <<
" and in the profile is "
349 << FilteredProfileAnchorList.size() <<
"\n");
364 longestCommonSequence(FilteredIRAnchorsList, FilteredProfileAnchorList,
372 matchNonCallsiteLocs(MatchedAnchors, IRAnchors, IRToProfileLocationMap);
375void SampleProfileMatcher::runOnFunction(
Function &
F) {
382 const auto *FSForMatching = getFlattenedSamplesFor(
F);
385 auto R = FuncToProfileNameMap.find(&
F);
386 if (R != FuncToProfileNameMap.end()) {
387 FSForMatching = getFlattenedSamplesFor(
R->second);
392 FSForMatching = Reader.getSamplesFor(
R->second.stringRef());
402 findIRAnchors(
F, IRAnchors);
406 findProfileAnchors(*FSForMatching, ProfileAnchors);
410 recordCallsiteMatchStates(
F, IRAnchors, ProfileAnchors,
nullptr);
417 !ProbeManager->profileIsValid(
F, *FSForMatching);
418 bool RunCFGMatching =
426 F.addFnAttr(
"profile-checksum-mismatch");
430 auto &IRToProfileLocationMap = getIRToProfileLocationMap(*FSForMatching);
431 runStaleProfileMatching(
F, IRAnchors, ProfileAnchors, IRToProfileLocationMap,
432 RunCFGMatching, RunCGMatching);
435 recordCallsiteMatchStates(
F, IRAnchors, ProfileAnchors,
436 &IRToProfileLocationMap);
439void SampleProfileMatcher::recordCallsiteMatchStates(
443 bool IsPostMatch = IRToProfileLocationMap !=
nullptr;
444 auto &CallsiteMatchStates =
447 auto MapIRLocToProfileLoc = [&](
const LineLocation &IRLoc) {
449 if (!IRToProfileLocationMap)
451 const auto &ProfileLoc = IRToProfileLocationMap->find(IRLoc);
452 if (ProfileLoc != IRToProfileLocationMap->end())
453 return ProfileLoc->second;
458 for (
const auto &
I : IRAnchors) {
461 const auto &ProfileLoc = MapIRLocToProfileLoc(
I.first);
462 const auto &IRCalleeId =
I.second;
463 const auto &It = ProfileAnchors.find(ProfileLoc);
464 if (It == ProfileAnchors.end())
466 const auto &ProfCalleeId = It->second;
467 if (IRCalleeId == ProfCalleeId) {
468 auto It = CallsiteMatchStates.find(ProfileLoc);
469 if (It == CallsiteMatchStates.end())
470 CallsiteMatchStates.emplace(ProfileLoc, MatchState::InitialMatch);
471 else if (IsPostMatch) {
472 if (It->second == MatchState::InitialMatch)
473 It->second = MatchState::UnchangedMatch;
474 else if (It->second == MatchState::InitialMismatch)
475 It->second = MatchState::RecoveredMismatch;
482 for (
const auto &
I : ProfileAnchors) {
483 const auto &Loc =
I.first;
484 assert(!
I.second.stringRef().empty() &&
"Callees should not be empty");
485 auto It = CallsiteMatchStates.find(Loc);
486 if (It == CallsiteMatchStates.end())
487 CallsiteMatchStates.emplace(Loc, MatchState::InitialMismatch);
488 else if (IsPostMatch) {
491 if (It->second == MatchState::InitialMismatch)
492 It->second = MatchState::UnchangedMismatch;
493 else if (It->second == MatchState::InitialMatch)
494 It->second = MatchState::RemovedMatch;
499void SampleProfileMatcher::countMismatchedFuncSamples(
const FunctionSamples &FS,
501 const auto *FuncDesc = ProbeManager->getDesc(
FS.getGUID());
506 if (ProbeManager->profileIsHashMismatched(*FuncDesc, FS)) {
508 NumStaleProfileFunc++;
513 MismatchedFunctionSamples +=
FS.getTotalSamples();
522 for (
const auto &
I :
FS.getCallsiteSamples())
523 for (
const auto &CS :
I.second)
524 countMismatchedFuncSamples(CS.second,
false);
527void SampleProfileMatcher::countMismatchedCallsiteSamples(
529 auto It = FuncCallsiteMatchStates.find(
FS.getFuncName());
531 if (It == FuncCallsiteMatchStates.end() || It->second.empty())
533 const auto &CallsiteMatchStates = It->second;
535 auto findMatchState = [&](
const LineLocation &Loc) {
536 auto It = CallsiteMatchStates.find(Loc);
537 if (It == CallsiteMatchStates.end())
538 return MatchState::Unknown;
542 auto AttributeMismatchedSamples = [&](
const enum MatchState &State,
544 if (isMismatchState(State))
545 MismatchedCallsiteSamples += Samples;
546 else if (State == MatchState::RecoveredMismatch)
547 RecoveredCallsiteSamples += Samples;
552 for (
const auto &
I :
FS.getBodySamples())
553 AttributeMismatchedSamples(findMatchState(
I.first),
I.second.getSamples());
556 for (
const auto &
I :
FS.getCallsiteSamples()) {
557 auto State = findMatchState(
I.first);
558 uint64_t CallsiteSamples = 0;
559 for (
const auto &CS :
I.second)
560 CallsiteSamples += CS.second.getTotalSamples();
561 AttributeMismatchedSamples(State, CallsiteSamples);
563 if (isMismatchState(State))
569 for (
const auto &CS :
I.second)
570 countMismatchedCallsiteSamples(CS.second);
574void SampleProfileMatcher::countMismatchCallsites(
const FunctionSamples &FS) {
575 auto It = FuncCallsiteMatchStates.find(
FS.getFuncName());
577 if (It == FuncCallsiteMatchStates.end() || It->second.empty())
579 const auto &MatchStates = It->second;
580 [[maybe_unused]]
bool OnInitialState =
581 isInitialState(MatchStates.begin()->second);
582 for (
const auto &
I : MatchStates) {
583 TotalProfiledCallsites++;
585 (OnInitialState ? isInitialState(
I.second) : isFinalState(
I.second)) &&
586 "Profile matching state is inconsistent");
588 if (isMismatchState(
I.second))
589 NumMismatchedCallsites++;
590 else if (
I.second == MatchState::RecoveredMismatch)
591 NumRecoveredCallsites++;
595void SampleProfileMatcher::countCallGraphRecoveredSamples(
597 std::unordered_set<FunctionId> &CallGraphRecoveredProfiles) {
598 if (CallGraphRecoveredProfiles.count(
FS.getFunction())) {
599 NumCallGraphRecoveredFuncSamples +=
FS.getTotalSamples();
603 for (
const auto &CM :
FS.getCallsiteSamples()) {
604 for (
const auto &CS : CM.second) {
605 countCallGraphRecoveredSamples(CS.second, CallGraphRecoveredProfiles);
610void SampleProfileMatcher::computeAndReportProfileStaleness() {
614 std::unordered_set<FunctionId> CallGraphRecoveredProfiles;
616 for (
const auto &
I : FuncToProfileNameMap) {
617 CallGraphRecoveredProfiles.insert(
I.second);
620 NumCallGraphRecoveredProfiledFunc++;
625 for (
const auto &
F : M) {
632 const auto *
FS = Reader.getSamplesFor(
F);
636 TotalFunctionSamples +=
FS->getTotalSamples();
639 countCallGraphRecoveredSamples(*FS, CallGraphRecoveredProfiles);
643 countMismatchedFuncSamples(*FS,
true);
646 countMismatchCallsites(*FS);
647 countMismatchedCallsiteSamples(*FS);
652 errs() <<
"(" << NumStaleProfileFunc <<
"/" << TotalProfiledFunc
653 <<
") of functions' profile are invalid and ("
654 << MismatchedFunctionSamples <<
"/" << TotalFunctionSamples
655 <<
") of samples are discarded due to function hash mismatch.\n";
658 errs() <<
"(" << NumCallGraphRecoveredProfiledFunc <<
"/"
659 << TotalProfiledFunc <<
") of functions' profile are matched and ("
660 << NumCallGraphRecoveredFuncSamples <<
"/" << TotalFunctionSamples
661 <<
") of samples are reused by call graph matching.\n";
664 errs() <<
"(" << (NumMismatchedCallsites + NumRecoveredCallsites) <<
"/"
665 << TotalProfiledCallsites
666 <<
") of callsites' profile are invalid and ("
667 << (MismatchedCallsiteSamples + RecoveredCallsiteSamples) <<
"/"
668 << TotalFunctionSamples
669 <<
") of samples are discarded due to callsite location mismatch.\n";
670 errs() <<
"(" << NumRecoveredCallsites <<
"/"
671 << (NumRecoveredCallsites + NumMismatchedCallsites)
672 <<
") of callsites and (" << RecoveredCallsiteSamples <<
"/"
673 << (RecoveredCallsiteSamples + MismatchedCallsiteSamples)
674 <<
") of samples are recovered by stale profile matching.\n";
678 LLVMContext &Ctx = M.getContext();
683 ProfStatsVec.
emplace_back(
"NumStaleProfileFunc", NumStaleProfileFunc);
684 ProfStatsVec.
emplace_back(
"TotalProfiledFunc", TotalProfiledFunc);
686 MismatchedFunctionSamples);
687 ProfStatsVec.
emplace_back(
"TotalFunctionSamples", TotalFunctionSamples);
691 ProfStatsVec.
emplace_back(
"NumCallGraphRecoveredProfiledFunc",
692 NumCallGraphRecoveredProfiledFunc);
693 ProfStatsVec.
emplace_back(
"NumCallGraphRecoveredFuncSamples",
694 NumCallGraphRecoveredFuncSamples);
697 ProfStatsVec.
emplace_back(
"NumMismatchedCallsites", NumMismatchedCallsites);
698 ProfStatsVec.
emplace_back(
"NumRecoveredCallsites", NumRecoveredCallsites);
699 ProfStatsVec.
emplace_back(
"TotalProfiledCallsites", TotalProfiledCallsites);
701 MismatchedCallsiteSamples);
703 RecoveredCallsiteSamples);
705 auto *MD = MDB.createLLVMStats(ProfStatsVec);
706 auto *NMD = M.getOrInsertNamedMetadata(
"llvm.stats");
711void SampleProfileMatcher::findFunctionsWithoutProfile() {
715 StringSet<> NamesInProfile;
716 if (
auto NameTable = Reader.getNameTable()) {
717 for (
auto Name : *NameTable)
724 if (
F.isDeclaration())
728 const auto *
FS = getFlattenedSamplesFor(
F);
735 if (NamesInProfile.
count(CanonFName))
740 if (PSL && PSL->contains(CanonFName))
744 <<
" is not in profile or profile symbol list.\n");
745 FunctionsWithoutProfile[FunctionId(CanonFName)] = &
F;
753 auto FunctionName = FName.
str();
754 if (Demangler.partialDemangle(FunctionName.c_str()))
755 return std::string();
756 size_t BaseNameSize = 0;
760 char *BaseNamePtr = Demangler.getFunctionBaseName(
nullptr, &BaseNameSize);
761 std::string Result = (BaseNamePtr && BaseNameSize)
762 ? std::string(BaseNamePtr, BaseNameSize)
767 while (!Result.empty() && (Result.back() ==
' ' || Result.back() ==
'\0'))
772void SampleProfileMatcher::matchFunctionsWithoutProfileByBasename() {
775 auto *NameTable = Reader.getNameTable();
784 StringMap<Function *> OrphansByBaseName;
785 StringSet<> AmbiguousBaseNames;
786 for (
auto &[FuncId, Func] : FunctionsWithoutProfile) {
788 if (BaseName.empty() || AmbiguousBaseNames.
count(BaseName))
793 OrphansByBaseName.
erase(It);
794 AmbiguousBaseNames.
insert(BaseName);
797 if (OrphansByBaseName.
empty())
802 StringMap<FunctionId> CandidateByBaseName;
803 for (
auto &ProfileFuncId : *NameTable) {
804 StringRef ProfName = ProfileFuncId.stringRef();
805 if (ProfName.
empty())
809 if (ProfBaseName.empty())
812 if (OrphansByBaseName.
count(ProfBaseName)) {
813 if (AmbiguousBaseNames.
count(ProfBaseName))
817 CandidateByBaseName.
try_emplace(ProfBaseName, ProfileFuncId);
820 CandidateByBaseName.
erase(It);
821 AmbiguousBaseNames.
insert(ProfBaseName);
826 if (CandidateByBaseName.
empty())
830 DenseSet<StringRef> ToLoad;
831 for (
auto &[BaseName, ProfId] : CandidateByBaseName)
832 ToLoad.
insert(ProfId.stringRef());
835 unsigned MatchCount = 0;
836 SampleProfileMap NewlyLoadedProfiles;
837 for (
auto &[BaseName, ProfId] : CandidateByBaseName) {
838 if (!isProfileUnused(ProfId))
844 FuncToProfileNameMap[OrphanFunc] = ProfId;
845 if (
const auto *FS = Reader.getSamplesFor(ProfId.stringRef()))
849 <<
" (IR) -> " << ProfId <<
" (Profile)"
850 <<
" [basename: " << BaseName <<
"]\n");
855 if (!NewlyLoadedProfiles.empty())
859 NumDirectProfileMatch += MatchCount;
860 LLVM_DEBUG(
dbgs() <<
"Direct basename matching found " << MatchCount
864bool SampleProfileMatcher::functionMatchesProfileHelper(
868 float Similarity = 0.0;
875 if (!IRBaseName.empty() && IRBaseName == ProfBaseName) {
877 << ProfFunc <<
"(Profile) share the same base name: "
878 << IRBaseName <<
".\n");
882 const auto *FSForMatching = getFlattenedSamplesFor(ProfFunc);
889 DenseSet<StringRef> TopLevelFunc({ProfFunc.
stringRef()});
890 if (std::error_code EC = Reader.read(TopLevelFunc))
892 FSForMatching = Reader.getSamplesFor(ProfFunc.
stringRef());
897 SampleProfileMap TempProfiles;
898 TempProfiles.
create(FSForMatching->getFunction()).
merge(*FSForMatching);
901 FSForMatching = getFlattenedSamplesFor(ProfFunc);
905 dbgs() <<
"Read top-level function " << ProfFunc
906 <<
" for call-graph matching\n";
921 const auto *FuncDesc = ProbeManager->getDesc(IRFunc);
923 !ProbeManager->profileIsHashMismatched(*FuncDesc, *FSForMatching)) {
925 <<
"(IR) and " << ProfFunc <<
"(Profile) match.\n");
932 findIRAnchors(IRFunc, IRAnchors);
934 findProfileAnchors(*FSForMatching, ProfileAnchors);
938 getFilteredAnchorList(IRAnchors, ProfileAnchors, FilteredIRAnchorsList,
939 FilteredProfileAnchorList);
952 longestCommonSequence(FilteredIRAnchorsList, FilteredProfileAnchorList,
955 Similarity =
static_cast<float>(MatchedAnchors.size()) /
956 FilteredProfileAnchorList.size();
959 <<
"(IR) and " << ProfFunc <<
"(profile) is "
960 <<
format(
"%.2f", Similarity) <<
"\n");
961 assert((Similarity >= 0 && Similarity <= 1.0) &&
962 "Similarity value should be in [0, 1]");
968bool SampleProfileMatcher::functionMatchesProfile(
Function &IRFunc,
970 bool FindMatchedProfileOnly) {
971 auto R = FuncProfileMatchCache.find({&IRFunc, ProfFunc});
972 if (R != FuncProfileMatchCache.end())
975 if (FindMatchedProfileOnly)
978 bool Matched = functionMatchesProfileHelper(IRFunc, ProfFunc);
979 FuncProfileMatchCache[{&IRFunc, ProfFunc}] = Matched;
981 FuncToProfileNameMap[&IRFunc] = ProfFunc;
983 <<
" matches profile:" << ProfFunc <<
"\n");
989void SampleProfileMatcher::UpdateWithSalvagedProfiles() {
990 DenseSet<StringRef> ProfileSalvagedFuncs;
992 for (
auto &
I : FuncToProfileNameMap) {
993 assert(
I.first &&
"New function is null");
994 FunctionId FuncName(
I.first->getName());
995 ProfileSalvagedFuncs.
insert(
I.second.stringRef());
996 FuncNameToProfNameMap->emplace(FuncName,
I.second);
1000 SymbolMap->erase(FuncName);
1001 [[maybe_unused]]
auto Ret = SymbolMap->emplace(
I.second,
I.first);
1004 dbgs() <<
"Profile Function " <<
I.second
1005 <<
" has already been matched to another IR function.\n";
1013 Reader.read(ProfileSalvagedFuncs);
1014 Reader.setFuncNameToProfNameMap(*FuncNameToProfNameMap);
1026 findFunctionsWithoutProfile();
1027 matchFunctionsWithoutProfileByBasename();
1032 std::vector<Function *> TopDownFunctionList;
1033 TopDownFunctionList.reserve(M.size());
1035 for (
auto *
F : TopDownFunctionList) {
1042 UpdateWithSalvagedProfiles();
1045 distributeIRToProfileLocationMap();
1047 computeAndReportProfileStaleness();
1050void SampleProfileMatcher::distributeIRToProfileLocationMap(
1052 const auto ProfileMappings = FuncMappings.
find(FS.getFuncName());
1053 if (ProfileMappings != FuncMappings.
end()) {
1054 FS.setIRToProfileLocationMap(&(ProfileMappings->second));
1057 for (
auto &Callees :
1059 for (
auto &FS : Callees.second) {
1060 distributeIRToProfileLocationMap(FS.second);
1067void SampleProfileMatcher::distributeIRToProfileLocationMap() {
1068 for (
auto &
I : Reader.getProfiles()) {
1069 distributeIRToProfileLocationMap(
I.second);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
itanium_demangle::ManglingParser< DefaultAllocator > Demangler
Legalize the Machine IR a function s Machine IR
static std::string getDemangledBaseName(ItaniumPartialDemangler &Demangler, StringRef FName)
This file provides the interface for SampleProfileMatcher.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static bool isAvailableExternallyLinkage(LinkageTypes Linkage)
reference emplace_back(ArgTypes &&... Args)
iterator find(StringRef Key)
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
ValueTy lookup(StringRef Key) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
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.
std::string str() const
str - Get the contents as an std::string.
constexpr bool empty() const
empty - Check if the string is empty.
std::pair< typename Base::iterator, bool > insert(StringRef key)
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
std::pair< iterator, bool > insert(const ValueT &V)
This class represents a function that is read from a sample profile.
StringRef stringRef() const
Convert to StringRef.
bool isStringRef() const
Check if this object represents a StringRef, or a hash code.
Representation of the samples collected for a function.
static LLVM_ABI bool ProfileIsCS
static LLVM_ABI bool ProfileIsProbeBased
static StringRef getCanonicalFnName(const Function &F)
Return the canonical name for a function, taking into account suffix elision policy attributes.
static LLVM_ABI bool ProfileIsFS
If this profile uses flow sensitive discriminators.
sampleprof_error merge(const FunctionSamples &Other, uint64_t Weight=1)
Merge the samples in Other into this one.
static LLVM_ABI LineLocation getCallSiteIdentifier(const DILocation *DIL, bool ProfileIsFS=false)
Returns a unique call site identifier for a given debug location of a call instruction.
static LLVM_ABI bool UseMD5
Whether the profile uses MD5 to represent string.
static void flattenProfile(SampleProfileMap &ProfileMap, bool ProfileIsCS=false)
mapped_type & create(const SampleContext &Ctx)
@ C
The default llvm calling convention, compatible with C.
initializer< Ty > init(const Ty &Val)
NodeAddr< FuncNode * > Func
std::map< LineLocation, FunctionSamplesMap > CallsiteSampleMap
std::unordered_map< LineLocation, LineLocation, LineLocationHash > LocToLocMap
This is an optimization pass for GlobalISel generic memory operations.
cl::opt< bool > ReportProfileStaleness("report-profile-staleness", cl::Hidden, cl::init(false), cl::desc("Compute and report stale profile statistical metrics."))
cl::opt< bool > PersistProfileStaleness("persist-profile-staleness", cl::Hidden, cl::init(false), cl::desc("Compute stale profile statistical metrics and write it into the " "native object file(.llvm_stats section)."))
std::map< LineLocation, FunctionId > AnchorMap
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
static cl::opt< bool > LoadFuncProfileforCGMatching("load-func-profile-for-cg-matching", cl::Hidden, cl::init(true), cl::desc("Load top-level profiles that the sample reader initially skipped for " "the call-graph matching (only meaningful for extended binary " "format)"))
static cl::opt< unsigned > SalvageUnusedProfileMaxFunctions("salvage-unused-profile-max-functions", cl::Hidden, cl::init(UINT_MAX), cl::desc("The maximum number of functions in a module, above which salvage " "unused profile will be skipped."))
static void buildTopDownFuncOrder(LazyCallGraph &CG, std::vector< Function * > &FunctionOrderList)
@ ThinLTOPreLink
ThinLTO prelink (summary) phase.
static cl::opt< unsigned > MinCallCountForCGMatching("min-call-count-for-cg-matching", cl::Hidden, cl::init(3), cl::desc("The minimum number of call anchors required for a function to " "run stale profile call graph matching."))
LLVM_ABI std::optional< PseudoProbe > extractProbe(const Instruction &Inst)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static cl::opt< unsigned > MinFuncCountForCGMatching("min-func-count-for-cg-matching", cl::Hidden, cl::init(5), cl::desc("The minimum number of basic blocks required for a function to " "run stale profile call graph matching."))
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
cl::opt< bool > SalvageStaleProfile("salvage-stale-profile", cl::Hidden, cl::init(false), cl::desc("Salvage stale profile by fuzzy matching and use the remapped " "location for sample profile query."))
void longestCommonSequence(AnchorList AnchorList1, AnchorList AnchorList2, llvm::function_ref< bool(const Function &, const Function &)> FunctionMatchesProfile, llvm::function_ref< void(Loc, Loc)> InsertMatching)
std::vector< std::pair< LineLocation, FunctionId > > AnchorList
static bool skipProfileForFunction(const Function &F)
cl::opt< bool > SalvageUnusedProfile("salvage-unused-profile", cl::Hidden, cl::init(false), cl::desc("Salvage unused profile by matching with new " "functions on call graph."))
static cl::opt< unsigned > SalvageStaleProfileMaxCallsites("salvage-stale-profile-max-callsites", cl::Hidden, cl::init(UINT_MAX), cl::desc("The maximum number of callsites in a function, above which stale " "profile matching will be skipped."))
static cl::opt< unsigned > FuncProfileSimilarityThreshold("func-profile-similarity-threshold", cl::Hidden, cl::init(80), cl::desc("Consider a profile matches a function if the similarity of their " "callee sequences is above the specified percentile."))