15
15
#define LLVM_TRANSFORMS_IPO_SAMPLEPROFILEMATCHER_H
16
16
17
17
#include " llvm/ADT/StringSet.h"
18
+ #include " llvm/Analysis/ProfileSummaryInfo.h"
18
19
#include " llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h"
19
20
20
21
namespace llvm {
21
22
22
23
using AnchorList = std::vector<std::pair<LineLocation, FunctionId>>;
23
24
using AnchorMap = std::map<LineLocation, FunctionId>;
25
+ using FunctionMap = HashKeyMap<std::unordered_map, FunctionId, Function *>;
24
26
25
27
// Sample profile matching - fuzzy match.
26
28
class SampleProfileMatcher {
@@ -58,6 +60,20 @@ class SampleProfileMatcher {
58
60
StringMap<std::unordered_map<LineLocation, MatchState, LineLocationHash>>
59
61
FuncCallsiteMatchStates;
60
62
63
+ struct RenameDecisionCacheHash {
64
+ uint64_t
65
+ operator ()(const std::pair<const Function *, FunctionId> &P) const {
66
+ return hash_combine (P.first , P.second );
67
+ }
68
+ };
69
+ std::unordered_map<std::pair<const Function *, FunctionId>, bool ,
70
+ RenameDecisionCacheHash>
71
+ RenameDecisionCache;
72
+
73
+ FunctionMap *SymbolMap;
74
+
75
+ std::shared_ptr<ProfileSymbolList> PSL;
76
+
61
77
// Profile mismatch statstics:
62
78
uint64_t TotalProfiledFunc = 0 ;
63
79
// Num of checksum-mismatched function.
@@ -80,26 +96,32 @@ class SampleProfileMatcher {
80
96
public:
81
97
SampleProfileMatcher (Module &M, SampleProfileReader &Reader,
82
98
const PseudoProbeManager *ProbeManager,
83
- ThinOrFullLTOPhase LTOPhase)
84
- : M(M), Reader(Reader), ProbeManager(ProbeManager), LTOPhase(LTOPhase){};
85
- void runOnModule ();
99
+ ThinOrFullLTOPhase LTOPhase,
100
+ std::shared_ptr<ProfileSymbolList> PSL)
101
+ : M(M), Reader(Reader), ProbeManager(ProbeManager), LTOPhase(LTOPhase),
102
+ PSL (PSL) {};
103
+ void runOnModule (FunctionMap &SymbolMap);
86
104
void clearMatchingData () {
87
105
// Do not clear FuncMappings, it stores IRLoc to ProfLoc remappings which
88
106
// will be used for sample loader.
89
107
FuncCallsiteMatchStates.clear ();
90
108
}
91
109
92
110
private:
93
- FunctionSamples *getFlattenedSamplesFor (const Function &F) {
94
- StringRef CanonFName = FunctionSamples::getCanonicalFnName (F);
95
- auto It = FlattenedProfiles.find (FunctionId (CanonFName));
111
+ FunctionSamples *getFlattenedSamplesFor (const FunctionId &Fname) {
112
+ auto It = FlattenedProfiles.find (Fname);
96
113
if (It != FlattenedProfiles.end ())
97
114
return &It->second ;
98
115
return nullptr ;
99
116
}
100
- void runOnFunction (Function &F);
101
- void findIRAnchors (const Function &F, AnchorMap &IRAnchors);
102
- void findProfileAnchors (const FunctionSamples &FS, AnchorMap &ProfileAnchors);
117
+ FunctionSamples *getFlattenedSamplesFor (const Function &F) {
118
+ StringRef CanonFName = FunctionSamples::getCanonicalFnName (F);
119
+ return getFlattenedSamplesFor (FunctionId (CanonFName));
120
+ }
121
+ void runBlockLevelMatching (Function &F);
122
+ void findIRAnchors (const Function &F, AnchorMap &IRAnchors) const ;
123
+ void findProfileAnchors (const FunctionSamples &FS,
124
+ AnchorMap &ProfileAnchors) const ;
103
125
// Record the callsite match states for profile staleness report, the result
104
126
// is saved in FuncCallsiteMatchStates.
105
127
void recordCallsiteMatchStates (const Function &F, const AnchorMap &IRAnchors,
@@ -160,6 +182,20 @@ class SampleProfileMatcher {
160
182
void runStaleProfileMatching (const Function &F, const AnchorMap &IRAnchors,
161
183
const AnchorMap &ProfileAnchors,
162
184
LocToLocMap &IRToProfileLocationMap);
185
+ void findIRNewCallees (Function &Caller,
186
+ const StringMap<Function *> &IRNewFunctions,
187
+ std::vector<Function *> &IRNewCallees);
188
+ float checkFunctionSimilarity (const Function &IRFunc,
189
+ const FunctionId &ProfFunc);
190
+ bool functionIsRenamedImpl (const Function &IRFunc,
191
+ const FunctionId &ProfFunc);
192
+ bool functionIsRenamed (const Function &IRFunc, const FunctionId &ProfFunc);
193
+ void
194
+ runFuncRenamingMatchingOnProfile (const StringMap<Function *> &IRNewFunctions,
195
+ FunctionSamples &FS,
196
+ FunctionMap &OldProfToNewSymbolMap);
197
+ void findIRNewFunctions (StringMap<Function *> &IRNewFunctions);
198
+ void runFuncLevelMatching ();
163
199
void reportOrPersistProfileStats ();
164
200
};
165
201
} // end namespace llvm
0 commit comments