@@ -617,11 +617,8 @@ void SampleProfileMatcher::computeAndReportProfileStaleness() {
617
617
}
618
618
}
619
619
620
- // Find functions that don't show in the profile or profile symbol list, which
621
- // are supposed to be new functions. We use them as the targets for renaming
622
- // matching.
623
620
void SampleProfileMatcher::findNewIRFunctions (
624
- StringMap<Function *> &newIRFunctions ) {
621
+ StringMap<Function *> &NewIRFunctions ) {
625
622
// TODO: Support MD5 profile.
626
623
if (FunctionSamples::UseMD5)
627
624
return ;
@@ -655,12 +652,12 @@ void SampleProfileMatcher::findNewIRFunctions(
655
652
656
653
LLVM_DEBUG (dbgs () << " Function " << CanonFName
657
654
<< " is not in profile or symbol list table.\n " );
658
- newIRFunctions [CanonFName] = &F;
655
+ NewIRFunctions [CanonFName] = &F;
659
656
}
660
657
}
661
658
662
659
void SampleProfileMatcher::findNewIRCallees (
663
- Function &Caller, const StringMap<Function *> &newIRFunctions ,
660
+ Function &Caller, const StringMap<Function *> &NewIRFunctions ,
664
661
std::vector<Function *> &NewIRCallees) {
665
662
for (auto &BB : Caller) {
666
663
for (auto &I : BB) {
@@ -672,17 +669,12 @@ void SampleProfileMatcher::findNewIRCallees(
672
669
continue ;
673
670
StringRef CalleeName =
674
671
FunctionSamples::getCanonicalFnName (Callee->getName ());
675
- if (newIRFunctions .count (CalleeName))
672
+ if (NewIRFunctions .count (CalleeName))
676
673
NewIRCallees.push_back (Callee);
677
674
}
678
675
}
679
676
}
680
677
681
- // Find the function using the profile name. If the function is not found but
682
- // the NewIRCallees is provided, try to match the function profile with all
683
- // functions in NewIRCallees and return the matched function.
684
- // The return pair includes the function pointer and a bool value indicating
685
- // whether the function is new(matched).
686
678
std::pair<Function *, bool > SampleProfileMatcher::findOrMatchFunction (
687
679
const FunctionId &ProfCallee, FunctionMap &OldProfToNewSymbolMap,
688
680
const std::vector<Function *> &NewIRCallees = std::vector<Function *>()) {
@@ -703,8 +695,6 @@ std::pair<Function *, bool> SampleProfileMatcher::findOrMatchFunction(
703
695
return {nullptr , false };
704
696
}
705
697
706
- // Determine if the function matches profile by computing a similarity ratio
707
- // between two callsite anchors sequences extracted from function and profile.
708
698
bool SampleProfileMatcher::functionMatchesProfileHelper (
709
699
const Function &IRFunc, const FunctionId &ProfFunc) {
710
700
// The value is in the range [0, 1]. The bigger the value is, the more similar
@@ -713,7 +703,7 @@ bool SampleProfileMatcher::functionMatchesProfileHelper(
713
703
714
704
const auto *FSFlattened = getFlattenedSamplesFor (ProfFunc);
715
705
assert (FSFlattened && " Flattened profile sample is null" );
716
- // Similarity check may not be reiable if the function is tiny, we use the
706
+ // Similarity check may not be reliable if the function is tiny, we use the
717
707
// number of basic block as a proxy for the function complexity and skip the
718
708
// matching if it's too small.
719
709
if (IRFunc.size () < MinBBForCGMatching ||
@@ -778,7 +768,7 @@ bool SampleProfileMatcher::functionMatchesProfile(const Function &IRFunc,
778
768
// Match profile for new function on the profiled call-graph edge to limit the
779
769
// matching scope.
780
770
void SampleProfileMatcher::matchProfileForNewFunctions (
781
- const StringMap<Function *> &newIRFunctions , FunctionSamples &CallerFS,
771
+ const StringMap<Function *> &NewIRFunctions , FunctionSamples &CallerFS,
782
772
FunctionMap &OldProfToNewSymbolMap) {
783
773
// Find the new candidate callees from IR in the current caller scope.
784
774
std::vector<Function *> NewIRCallees;
@@ -788,7 +778,7 @@ void SampleProfileMatcher::matchProfileForNewFunctions(
788
778
// No callees for external function, skip the rename matching.
789
779
if (IRCaller->isDeclaration ())
790
780
return ;
791
- findNewIRCallees (*IRCaller, newIRFunctions , NewIRCallees);
781
+ findNewIRCallees (*IRCaller, NewIRFunctions , NewIRCallees);
792
782
}
793
783
794
784
// Match non-inline callees.
@@ -842,7 +832,7 @@ void SampleProfileMatcher::matchProfileForNewFunctions(
842
832
// Note that even there is no renaming in the current scope, there could
843
833
// be renaming in deeper callee scope, we need to traverse all the callee
844
834
// profiles.
845
- matchProfileForNewFunctions (newIRFunctions , CalleeFS,
835
+ matchProfileForNewFunctions (NewIRFunctions , CalleeFS,
846
836
OldProfToNewSymbolMap);
847
837
}
848
838
@@ -880,9 +870,9 @@ void SampleProfileMatcher::runCallGraphMatching() {
880
870
assert (FunctionProfileNameMap.empty () &&
881
871
" FunctionProfileNameMap is not empty before the call graph matching" );
882
872
883
- StringMap<Function *> newIRFunctions ;
884
- findNewIRFunctions (newIRFunctions );
885
- if (newIRFunctions .empty ())
873
+ StringMap<Function *> NewIRFunctions ;
874
+ findNewIRFunctions (NewIRFunctions );
875
+ if (NewIRFunctions .empty ())
886
876
return ;
887
877
888
878
// The new functions found by the renaming matching. Save them into a map
@@ -891,23 +881,23 @@ void SampleProfileMatcher::runCallGraphMatching() {
891
881
FunctionMap OldProfToNewSymbolMap;
892
882
// Sort the profiles to make the matching order deterministic.
893
883
for (auto *P : sortFuncProfiles (Reader.getProfiles ()))
894
- matchProfileForNewFunctions (newIRFunctions , *P, OldProfToNewSymbolMap);
884
+ matchProfileForNewFunctions (NewIRFunctions , *P, OldProfToNewSymbolMap);
895
885
886
+ FunctionProfileNameMap.clear ();
887
+ if (OldProfToNewSymbolMap.empty ())
888
+ return ;
896
889
// Update all the data generated by the old profile.
897
- if (!OldProfToNewSymbolMap.empty ()) {
898
- // Add the new function to the SymbolMap, which will be used in
899
- // SampleLoader.
900
- for (auto &I : OldProfToNewSymbolMap) {
901
- assert (I.second && " New function is null" );
902
- SymbolMap->emplace (FunctionId (I.second ->getName ()), I.second );
903
- }
904
-
905
- // Re-flatten the profiles after the renaming.
906
- FlattenedProfiles.clear ();
907
- ProfileConverter::flattenProfile (Reader.getProfiles (), FlattenedProfiles,
908
- FunctionSamples::ProfileIsCS);
890
+ // Add the new function to the SymbolMap, which will be used in
891
+ // SampleLoader.
892
+ for (auto &I : OldProfToNewSymbolMap) {
893
+ assert (I.second && " New function is null" );
894
+ SymbolMap->emplace (FunctionId (I.second ->getName ()), I.second );
909
895
}
910
- FunctionProfileNameMap.clear ();
896
+
897
+ // Re-flatten the profiles after the renaming.
898
+ FlattenedProfiles.clear ();
899
+ ProfileConverter::flattenProfile (Reader.getProfiles (), FlattenedProfiles,
900
+ FunctionSamples::ProfileIsCS);
911
901
}
912
902
913
903
void SampleProfileMatcher::runOnFunction (Function &F) {
0 commit comments