summaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp')
-rw-r--r--llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp b/llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp
index d7613bce4c52..11368e3375bd 100644
--- a/llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp
@@ -14,6 +14,7 @@
#include "llvm/Transforms/IPO/SampleProfileMatcher.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/MDBuilder.h"
+#include "llvm/Support/CommandLine.h"
using namespace llvm;
using namespace sampleprof;
@@ -24,6 +25,11 @@ extern cl::opt<bool> SalvageStaleProfile;
extern cl::opt<bool> PersistProfileStaleness;
extern cl::opt<bool> ReportProfileStaleness;
+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."));
+
void SampleProfileMatcher::findIRAnchors(const Function &F,
AnchorMap &IRAnchors) {
// For inlined code, recover the original callsite and callee by finding the
@@ -300,6 +306,16 @@ void SampleProfileMatcher::runStaleProfileMatching(
if (FilteredIRAnchorsList.empty() || FilteredProfileAnchorList.empty())
return;
+ if (FilteredIRAnchorsList.size() > SalvageStaleProfileMaxCallsites ||
+ FilteredProfileAnchorList.size() > SalvageStaleProfileMaxCallsites) {
+ LLVM_DEBUG(dbgs() << "Skip stale profile matching for " << F.getName()
+ << " because the number of callsites in the IR is "
+ << FilteredIRAnchorsList.size()
+ << " and in the profile is "
+ << FilteredProfileAnchorList.size() << "\n");
+ return;
+ }
+
// Match the callsite anchors by finding the longest common subsequence
// between IR and profile. Note that we need to use IR anchor as base(A side)
// to align with the order of IRToProfileLocationMap.