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()) &&
191 (ProbeManager->getDesc(ProfileFuncName.
stringRef()) ==
nullptr));
194bool SampleProfileMatcher::functionMatchesProfile(
196 bool FindMatchedProfileOnly) {
197 if (IRFuncName == ProfileFuncName)
205 if (functionHasProfile(IRFuncName, IRFunc) ||
206 !isProfileUnused(ProfileFuncName))
210 "IR function should be different from profile function to match");
211 return functionMatchesProfile(*IRFunc, ProfileFuncName,
212 FindMatchedProfileOnly);
216SampleProfileMatcher::longestCommonSequence(
const AnchorList &AnchorList1,
218 bool MatchUnusedFunction) {
221 AnchorList1, AnchorList2,
222 [&](
const FunctionId &
A,
const FunctionId &
B) {
223 return functionMatchesProfile(
228 [&](LineLocation
A, LineLocation
B) {
229 MatchedAnchors.try_emplace(
A,
B);
231 return MatchedAnchors;
234void SampleProfileMatcher::matchNonCallsiteLocs(
237 auto InsertMatching = [&](
const LineLocation &From,
const LineLocation &To) {
240 IRToProfileLocationMap.insert({From, To});
244 int32_t LocationDelta = 0;
246 for (
const auto &
IR : IRAnchors) {
247 const auto &Loc =
IR.first;
248 bool IsMatchedAnchor =
false;
250 auto R = MatchedAnchors.find(Loc);
251 if (R != MatchedAnchors.end()) {
252 const auto &Candidate =
R->second;
253 InsertMatching(Loc, Candidate);
255 <<
" is matched from " << Loc <<
" to " << Candidate
257 LocationDelta = Candidate.LineOffset - Loc.
LineOffset;
263 for (
size_t I = (LastMatchedNonAnchors.
size() + 1) / 2;
264 I < LastMatchedNonAnchors.
size();
I++) {
265 const auto &
L = LastMatchedNonAnchors[
I];
266 uint32_t CandidateLineOffset =
L.LineOffset + LocationDelta;
267 LineLocation Candidate(CandidateLineOffset,
L.Discriminator);
268 InsertMatching(L, Candidate);
270 <<
" to " << Candidate <<
"\n");
273 IsMatchedAnchor =
true;
274 LastMatchedNonAnchors.
clear();
278 if (!IsMatchedAnchor) {
279 uint32_t CandidateLineOffset = Loc.
LineOffset + LocationDelta;
280 LineLocation Candidate(CandidateLineOffset, Loc.
Discriminator);
281 InsertMatching(Loc, Candidate);
283 << Candidate <<
"\n");
291void SampleProfileMatcher::getFilteredAnchorList(
294 for (
const auto &
I : IRAnchors) {
295 if (
I.second.stringRef().empty())
297 FilteredIRAnchorsList.emplace_back(
I);
300 for (
const auto &
I : ProfileAnchors)
301 FilteredProfileAnchorList.emplace_back(
I);
321void SampleProfileMatcher::runStaleProfileMatching(
324 bool RunCFGMatching,
bool RunCGMatching) {
325 if (!RunCFGMatching && !RunCGMatching)
329 assert(IRToProfileLocationMap.empty() &&
330 "Run stale profile matching only once per function");
334 getFilteredAnchorList(IRAnchors, ProfileAnchors, FilteredIRAnchorsList,
335 FilteredProfileAnchorList);
337 if (FilteredIRAnchorsList.empty() || FilteredProfileAnchorList.empty())
343 <<
" because the number of callsites in the IR is "
344 << FilteredIRAnchorsList.size()
345 <<
" and in the profile is "
346 << FilteredProfileAnchorList.size() <<
"\n");
361 longestCommonSequence(FilteredIRAnchorsList, FilteredProfileAnchorList,
369 matchNonCallsiteLocs(MatchedAnchors, IRAnchors, IRToProfileLocationMap);
372void SampleProfileMatcher::runOnFunction(
Function &
F) {
379 const auto *FSForMatching = getFlattenedSamplesFor(
F);
382 auto R = FuncToProfileNameMap.find(&
F);
383 if (R != FuncToProfileNameMap.end()) {
384 FSForMatching = getFlattenedSamplesFor(
R->second);
389 FSForMatching = Reader.getSamplesFor(
R->second.stringRef());
399 findIRAnchors(
F, IRAnchors);
403 findProfileAnchors(*FSForMatching, ProfileAnchors);
407 recordCallsiteMatchStates(
F, IRAnchors, ProfileAnchors,
nullptr);
414 !ProbeManager->profileIsValid(
F, *FSForMatching);
415 bool RunCFGMatching =
423 F.addFnAttr(
"profile-checksum-mismatch");
427 auto &IRToProfileLocationMap = getIRToProfileLocationMap(
F);
428 runStaleProfileMatching(
F, IRAnchors, ProfileAnchors, IRToProfileLocationMap,
429 RunCFGMatching, RunCGMatching);
432 recordCallsiteMatchStates(
F, IRAnchors, ProfileAnchors,
433 &IRToProfileLocationMap);
436void SampleProfileMatcher::recordCallsiteMatchStates(
440 bool IsPostMatch = IRToProfileLocationMap !=
nullptr;
441 auto &CallsiteMatchStates =
444 auto MapIRLocToProfileLoc = [&](
const LineLocation &IRLoc) {
446 if (!IRToProfileLocationMap)
448 const auto &ProfileLoc = IRToProfileLocationMap->find(IRLoc);
449 if (ProfileLoc != IRToProfileLocationMap->end())
450 return ProfileLoc->second;
455 for (
const auto &
I : IRAnchors) {
458 const auto &ProfileLoc = MapIRLocToProfileLoc(
I.first);
459 const auto &IRCalleeId =
I.second;
460 const auto &It = ProfileAnchors.find(ProfileLoc);
461 if (It == ProfileAnchors.end())
463 const auto &ProfCalleeId = It->second;
464 if (IRCalleeId == ProfCalleeId) {
465 auto It = CallsiteMatchStates.find(ProfileLoc);
466 if (It == CallsiteMatchStates.end())
467 CallsiteMatchStates.emplace(ProfileLoc, MatchState::InitialMatch);
468 else if (IsPostMatch) {
469 if (It->second == MatchState::InitialMatch)
470 It->second = MatchState::UnchangedMatch;
471 else if (It->second == MatchState::InitialMismatch)
472 It->second = MatchState::RecoveredMismatch;
479 for (
const auto &
I : ProfileAnchors) {
480 const auto &Loc =
I.first;
481 assert(!
I.second.stringRef().empty() &&
"Callees should not be empty");
482 auto It = CallsiteMatchStates.find(Loc);
483 if (It == CallsiteMatchStates.end())
484 CallsiteMatchStates.emplace(Loc, MatchState::InitialMismatch);
485 else if (IsPostMatch) {
488 if (It->second == MatchState::InitialMismatch)
489 It->second = MatchState::UnchangedMismatch;
490 else if (It->second == MatchState::InitialMatch)
491 It->second = MatchState::RemovedMatch;
496void SampleProfileMatcher::countMismatchedFuncSamples(
const FunctionSamples &FS,
498 const auto *FuncDesc = ProbeManager->getDesc(
FS.getGUID());
503 if (ProbeManager->profileIsHashMismatched(*FuncDesc, FS)) {
505 NumStaleProfileFunc++;
510 MismatchedFunctionSamples +=
FS.getTotalSamples();
519 for (
const auto &
I :
FS.getCallsiteSamples())
520 for (
const auto &CS :
I.second)
521 countMismatchedFuncSamples(CS.second,
false);
524void SampleProfileMatcher::countMismatchedCallsiteSamples(
526 auto It = FuncCallsiteMatchStates.find(
FS.getFuncName());
528 if (It == FuncCallsiteMatchStates.end() || It->second.empty())
530 const auto &CallsiteMatchStates = It->second;
532 auto findMatchState = [&](
const LineLocation &Loc) {
533 auto It = CallsiteMatchStates.find(Loc);
534 if (It == CallsiteMatchStates.end())
535 return MatchState::Unknown;
539 auto AttributeMismatchedSamples = [&](
const enum MatchState &State,
541 if (isMismatchState(State))
542 MismatchedCallsiteSamples += Samples;
543 else if (State == MatchState::RecoveredMismatch)
544 RecoveredCallsiteSamples += Samples;
549 for (
const auto &
I :
FS.getBodySamples())
550 AttributeMismatchedSamples(findMatchState(
I.first),
I.second.getSamples());
553 for (
const auto &
I :
FS.getCallsiteSamples()) {
554 auto State = findMatchState(
I.first);
555 uint64_t CallsiteSamples = 0;
556 for (
const auto &CS :
I.second)
557 CallsiteSamples += CS.second.getTotalSamples();
558 AttributeMismatchedSamples(State, CallsiteSamples);
560 if (isMismatchState(State))
566 for (
const auto &CS :
I.second)
567 countMismatchedCallsiteSamples(CS.second);
571void SampleProfileMatcher::countMismatchCallsites(
const FunctionSamples &FS) {
572 auto It = FuncCallsiteMatchStates.find(
FS.getFuncName());
574 if (It == FuncCallsiteMatchStates.end() || It->second.empty())
576 const auto &MatchStates = It->second;
577 [[maybe_unused]]
bool OnInitialState =
578 isInitialState(MatchStates.begin()->second);
579 for (
const auto &
I : MatchStates) {
580 TotalProfiledCallsites++;
582 (OnInitialState ? isInitialState(
I.second) : isFinalState(
I.second)) &&
583 "Profile matching state is inconsistent");
585 if (isMismatchState(
I.second))
586 NumMismatchedCallsites++;
587 else if (
I.second == MatchState::RecoveredMismatch)
588 NumRecoveredCallsites++;
592void SampleProfileMatcher::countCallGraphRecoveredSamples(
594 std::unordered_set<FunctionId> &CallGraphRecoveredProfiles) {
595 if (CallGraphRecoveredProfiles.count(
FS.getFunction())) {
596 NumCallGraphRecoveredFuncSamples +=
FS.getTotalSamples();
600 for (
const auto &CM :
FS.getCallsiteSamples()) {
601 for (
const auto &CS : CM.second) {
602 countCallGraphRecoveredSamples(CS.second, CallGraphRecoveredProfiles);
607void SampleProfileMatcher::computeAndReportProfileStaleness() {
611 std::unordered_set<FunctionId> CallGraphRecoveredProfiles;
613 for (
const auto &
I : FuncToProfileNameMap) {
614 CallGraphRecoveredProfiles.insert(
I.second);
617 NumCallGraphRecoveredProfiledFunc++;
622 for (
const auto &
F : M) {
629 const auto *
FS = Reader.getSamplesFor(
F);
633 TotalFunctionSamples +=
FS->getTotalSamples();
636 countCallGraphRecoveredSamples(*FS, CallGraphRecoveredProfiles);
640 countMismatchedFuncSamples(*FS,
true);
643 countMismatchCallsites(*FS);
644 countMismatchedCallsiteSamples(*FS);
649 errs() <<
"(" << NumStaleProfileFunc <<
"/" << TotalProfiledFunc
650 <<
") of functions' profile are invalid and ("
651 << MismatchedFunctionSamples <<
"/" << TotalFunctionSamples
652 <<
") of samples are discarded due to function hash mismatch.\n";
655 errs() <<
"(" << NumCallGraphRecoveredProfiledFunc <<
"/"
656 << TotalProfiledFunc <<
") of functions' profile are matched and ("
657 << NumCallGraphRecoveredFuncSamples <<
"/" << TotalFunctionSamples
658 <<
") of samples are reused by call graph matching.\n";
661 errs() <<
"(" << (NumMismatchedCallsites + NumRecoveredCallsites) <<
"/"
662 << TotalProfiledCallsites
663 <<
") of callsites' profile are invalid and ("
664 << (MismatchedCallsiteSamples + RecoveredCallsiteSamples) <<
"/"
665 << TotalFunctionSamples
666 <<
") of samples are discarded due to callsite location mismatch.\n";
667 errs() <<
"(" << NumRecoveredCallsites <<
"/"
668 << (NumRecoveredCallsites + NumMismatchedCallsites)
669 <<
") of callsites and (" << RecoveredCallsiteSamples <<
"/"
670 << (RecoveredCallsiteSamples + MismatchedCallsiteSamples)
671 <<
") of samples are recovered by stale profile matching.\n";
675 LLVMContext &Ctx = M.getContext();
680 ProfStatsVec.
emplace_back(
"NumStaleProfileFunc", NumStaleProfileFunc);
681 ProfStatsVec.
emplace_back(
"TotalProfiledFunc", TotalProfiledFunc);
683 MismatchedFunctionSamples);
684 ProfStatsVec.
emplace_back(
"TotalFunctionSamples", TotalFunctionSamples);
688 ProfStatsVec.
emplace_back(
"NumCallGraphRecoveredProfiledFunc",
689 NumCallGraphRecoveredProfiledFunc);
690 ProfStatsVec.
emplace_back(
"NumCallGraphRecoveredFuncSamples",
691 NumCallGraphRecoveredFuncSamples);
694 ProfStatsVec.
emplace_back(
"NumMismatchedCallsites", NumMismatchedCallsites);
695 ProfStatsVec.
emplace_back(
"NumRecoveredCallsites", NumRecoveredCallsites);
696 ProfStatsVec.
emplace_back(
"TotalProfiledCallsites", TotalProfiledCallsites);
698 MismatchedCallsiteSamples);
700 RecoveredCallsiteSamples);
702 auto *MD = MDB.createLLVMStats(ProfStatsVec);
703 auto *NMD = M.getOrInsertNamedMetadata(
"llvm.stats");
708void SampleProfileMatcher::findFunctionsWithoutProfile() {
712 StringSet<> NamesInProfile;
713 if (
auto NameTable = Reader.getNameTable()) {
714 for (
auto Name : *NameTable)
721 if (
F.isDeclaration())
725 const auto *
FS = getFlattenedSamplesFor(
F);
732 if (NamesInProfile.
count(CanonFName))
737 if (PSL && PSL->contains(CanonFName))
741 <<
" is not in profile or profile symbol list.\n");
742 FunctionsWithoutProfile[FunctionId(CanonFName)] = &
F;
750 auto FunctionName = FName.
str();
751 if (Demangler.partialDemangle(FunctionName.c_str()))
752 return std::string();
753 size_t BaseNameSize = 0;
757 char *BaseNamePtr = Demangler.getFunctionBaseName(
nullptr, &BaseNameSize);
758 std::string Result = (BaseNamePtr && BaseNameSize)
759 ? std::string(BaseNamePtr, BaseNameSize)
764 while (!Result.empty() && (Result.back() ==
' ' || Result.back() ==
'\0'))
769void SampleProfileMatcher::matchFunctionsWithoutProfileByBasename() {
772 auto *NameTable = Reader.getNameTable();
781 StringMap<Function *> OrphansByBaseName;
782 StringSet<> AmbiguousBaseNames;
783 for (
auto &[FuncId, Func] : FunctionsWithoutProfile) {
785 if (BaseName.empty() || AmbiguousBaseNames.
count(BaseName))
790 OrphansByBaseName.
erase(It);
791 AmbiguousBaseNames.
insert(BaseName);
794 if (OrphansByBaseName.
empty())
802 StringMap<FunctionId> CandidateByBaseName;
803 for (
auto &ProfileFuncId : *NameTable) {
804 StringRef ProfName = ProfileFuncId.stringRef();
805 if (ProfName.
empty())
807 for (
auto &[BaseName,
_] : OrphansByBaseName) {
808 if (AmbiguousBaseNames.
count(BaseName) || !ProfName.
contains(BaseName))
811 if (ProfBaseName != BaseName)
814 CandidateByBaseName.
try_emplace(BaseName, ProfileFuncId);
817 CandidateByBaseName.
erase(It);
818 AmbiguousBaseNames.
insert(BaseName);
823 if (CandidateByBaseName.
empty())
827 DenseSet<StringRef> ToLoad;
828 for (
auto &[BaseName, ProfId] : CandidateByBaseName)
829 ToLoad.
insert(ProfId.stringRef());
832 unsigned MatchCount = 0;
833 SampleProfileMap NewlyLoadedProfiles;
834 for (
auto &[BaseName, ProfId] : CandidateByBaseName) {
835 if (!isProfileUnused(ProfId))
837 Function *OrphanFunc = OrphansByBaseName.lookup(BaseName);
841 FuncToProfileNameMap[OrphanFunc] = ProfId;
842 if (
const auto *FS = Reader.getSamplesFor(ProfId.stringRef()))
846 <<
" (IR) -> " << ProfId <<
" (Profile)"
847 <<
" [basename: " << BaseName <<
"]\n");
852 if (!NewlyLoadedProfiles.empty())
856 NumDirectProfileMatch += MatchCount;
857 LLVM_DEBUG(
dbgs() <<
"Direct basename matching found " << MatchCount
861bool SampleProfileMatcher::functionMatchesProfileHelper(
865 float Similarity = 0.0;
872 if (!IRBaseName.empty() && IRBaseName == ProfBaseName) {
874 << ProfFunc <<
"(Profile) share the same base name: "
875 << IRBaseName <<
".\n");
879 const auto *FSForMatching = getFlattenedSamplesFor(ProfFunc);
886 DenseSet<StringRef> TopLevelFunc({ProfFunc.
stringRef()});
887 if (std::error_code EC = Reader.read(TopLevelFunc))
889 FSForMatching = Reader.getSamplesFor(ProfFunc.
stringRef());
894 SampleProfileMap TempProfiles;
895 TempProfiles.
create(FSForMatching->getFunction()).
merge(*FSForMatching);
898 FSForMatching = getFlattenedSamplesFor(ProfFunc);
902 dbgs() <<
"Read top-level function " << ProfFunc
903 <<
" for call-graph matching\n";
918 const auto *FuncDesc = ProbeManager->getDesc(IRFunc);
920 !ProbeManager->profileIsHashMismatched(*FuncDesc, *FSForMatching)) {
922 <<
"(IR) and " << ProfFunc <<
"(Profile) match.\n");
929 findIRAnchors(IRFunc, IRAnchors);
931 findProfileAnchors(*FSForMatching, ProfileAnchors);
935 getFilteredAnchorList(IRAnchors, ProfileAnchors, FilteredIRAnchorsList,
936 FilteredProfileAnchorList);
949 longestCommonSequence(FilteredIRAnchorsList, FilteredProfileAnchorList,
952 Similarity =
static_cast<float>(MatchedAnchors.size()) /
953 FilteredProfileAnchorList.size();
956 <<
"(IR) and " << ProfFunc <<
"(profile) is "
957 <<
format(
"%.2f", Similarity) <<
"\n");
958 assert((Similarity >= 0 && Similarity <= 1.0) &&
959 "Similarity value should be in [0, 1]");
965bool SampleProfileMatcher::functionMatchesProfile(
Function &IRFunc,
967 bool FindMatchedProfileOnly) {
968 auto R = FuncProfileMatchCache.find({&IRFunc, ProfFunc});
969 if (R != FuncProfileMatchCache.end())
972 if (FindMatchedProfileOnly)
975 bool Matched = functionMatchesProfileHelper(IRFunc, ProfFunc);
976 FuncProfileMatchCache[{&IRFunc, ProfFunc}] = Matched;
978 FuncToProfileNameMap[&IRFunc] = ProfFunc;
980 <<
" matches profile:" << ProfFunc <<
"\n");
986void SampleProfileMatcher::UpdateWithSalvagedProfiles() {
987 DenseSet<StringRef> ProfileSalvagedFuncs;
989 for (
auto &
I : FuncToProfileNameMap) {
990 assert(
I.first &&
"New function is null");
991 FunctionId FuncName(
I.first->getName());
992 ProfileSalvagedFuncs.
insert(
I.second.stringRef());
993 FuncNameToProfNameMap->emplace(FuncName,
I.second);
997 SymbolMap->erase(FuncName);
998 auto Ret = SymbolMap->emplace(
I.second,
I.first);
1001 dbgs() <<
"Profile Function " <<
I.second
1002 <<
" has already been matched to another IR function.\n";
1010 Reader.read(ProfileSalvagedFuncs);
1011 Reader.setFuncNameToProfNameMap(*FuncNameToProfNameMap);
1023 findFunctionsWithoutProfile();
1024 matchFunctionsWithoutProfileByBasename();
1029 std::vector<Function *> TopDownFunctionList;
1030 TopDownFunctionList.reserve(M.size());
1032 for (
auto *
F : TopDownFunctionList) {
1039 UpdateWithSalvagedProfiles();
1042 distributeIRToProfileLocationMap();
1044 computeAndReportProfileStaleness();
1047void SampleProfileMatcher::distributeIRToProfileLocationMap(
1049 const auto ProfileMappings = FuncMappings.
find(FS.getFuncName());
1050 if (ProfileMappings != FuncMappings.
end()) {
1051 FS.setIRToProfileLocationMap(&(ProfileMappings->second));
1054 for (
auto &Callees :
1056 for (
auto &FS : Callees.second) {
1057 distributeIRToProfileLocationMap(FS.second);
1064void SampleProfileMatcher::distributeIRToProfileLocationMap() {
1065 for (
auto &
I : Reader.getProfiles()) {
1066 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.
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.
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
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."))