Skip to content

Commit

Permalink
[NFC][SamplePGO] Refactoring getFilteredAnchorList
Browse files Browse the repository at this point in the history
  • Loading branch information
wlei-llvm committed Jun 17, 2024
1 parent c22d391 commit c2314da
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
4 changes: 4 additions & 0 deletions llvm/include/llvm/Transforms/IPO/SampleProfileMatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ class SampleProfileMatcher {
return &It->second;
return nullptr;
}
void getFilteredAnchorList(const AnchorMap &IRAnchors,
const AnchorMap &ProfileAnchors,
AnchorList &FilteredIRAnchorsList,
AnchorList &FilteredProfileAnchorList);
void runOnFunction(Function &F);
void findIRAnchors(const Function &F, AnchorMap &IRAnchors);
void findProfileAnchors(const FunctionSamples &FS, AnchorMap &ProfileAnchors);
Expand Down
26 changes: 17 additions & 9 deletions llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,21 @@ void SampleProfileMatcher::matchNonCallsiteLocs(
}
}

// Filter the non-call locations from IRAnchors and ProfileAnchors and write
// them into a list for random access later.
void SampleProfileMatcher::getFilteredAnchorList(
const AnchorMap &IRAnchors, const AnchorMap &ProfileAnchors,
AnchorList &FilteredIRAnchorsList, AnchorList &FilteredProfileAnchorList) {
for (const auto &I : IRAnchors) {
if (I.second.stringRef().empty())
continue;
FilteredIRAnchorsList.emplace_back(I);
}

for (const auto &I : ProfileAnchors)
FilteredProfileAnchorList.emplace_back(I);
}

// Call target name anchor based profile fuzzy matching.
// Input:
// For IR locations, the anchor is the callee name of direct callsite; For
Expand All @@ -292,16 +307,9 @@ void SampleProfileMatcher::runStaleProfileMatching(
"Run stale profile matching only once per function");

AnchorList FilteredProfileAnchorList;
for (const auto &I : ProfileAnchors)
FilteredProfileAnchorList.emplace_back(I);

AnchorList FilteredIRAnchorsList;
// Filter the non-callsite from IRAnchors.
for (const auto &I : IRAnchors) {
if (I.second.stringRef().empty())
continue;
FilteredIRAnchorsList.emplace_back(I);
}
getFilteredAnchorList(IRAnchors, ProfileAnchors, FilteredIRAnchorsList,
FilteredProfileAnchorList);

if (FilteredIRAnchorsList.empty() || FilteredProfileAnchorList.empty())
return;
Expand Down

0 comments on commit c2314da

Please sign in to comment.