From c2314da1016266767d6373e23171b19308a1e1ad Mon Sep 17 00:00:00 2001 From: wlei Date: Mon, 17 Jun 2024 12:13:05 -0700 Subject: [PATCH] [NFC][SamplePGO] Refactoring getFilteredAnchorList --- .../Transforms/IPO/SampleProfileMatcher.h | 4 +++ .../Transforms/IPO/SampleProfileMatcher.cpp | 26 ++++++++++++------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/llvm/include/llvm/Transforms/IPO/SampleProfileMatcher.h b/llvm/include/llvm/Transforms/IPO/SampleProfileMatcher.h index b6feca5d470355..71a41a99ffc11d 100644 --- a/llvm/include/llvm/Transforms/IPO/SampleProfileMatcher.h +++ b/llvm/include/llvm/Transforms/IPO/SampleProfileMatcher.h @@ -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); diff --git a/llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp b/llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp index 11368e3375bddd..2a4bceb61ecbf0 100644 --- a/llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp +++ b/llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp @@ -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 @@ -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;