aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Wang <wlei@fb.com>2024-04-29 09:27:33 -0700
committerGitHub <noreply@github.com>2024-04-29 09:27:33 -0700
commitb7248d53637fb534d35554f1ddda8e50fe85fa63 (patch)
tree8e77b9e4e046983362d3f8c0e344e689d54a6318
parente441363f7da2da50449917f17ab4ed412f9e7cb3 (diff)
downloadllvm-b7248d53637fb534d35554f1ddda8e50fe85fa63.zip
llvm-b7248d53637fb534d35554f1ddda8e50fe85fa63.tar.gz
llvm-b7248d53637fb534d35554f1ddda8e50fe85fa63.tar.bz2
[PseudoProbe] Add an option to remove pseudo probes after profile annotation (#90293)
This can be used for testing perf overhead of pseudo-probe.
-rw-r--r--llvm/lib/Transforms/IPO/SampleProfile.cpp25
-rw-r--r--llvm/test/Transforms/SampleProfile/pseudo-probe-profile.ll8
2 files changed, 28 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp
index 0b3a693..6cbd138 100644
--- a/llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -252,20 +252,21 @@ static cl::opt<unsigned> PrecentMismatchForStalenessError(
static cl::opt<bool> CallsitePrioritizedInline(
"sample-profile-prioritized-inline", cl::Hidden,
-
cl::desc("Use call site prioritized inlining for sample profile loader."
"Currently only CSSPGO is supported."));
static cl::opt<bool> UsePreInlinerDecision(
"sample-profile-use-preinliner", cl::Hidden,
-
cl::desc("Use the preinliner decisions stored in profile context."));
static cl::opt<bool> AllowRecursiveInline(
"sample-profile-recursive-inline", cl::Hidden,
-
cl::desc("Allow sample loader inliner to inline recursive calls."));
+static cl::opt<bool> RemoveProbeAfterProfileAnnotation(
+ "sample-profile-remove-probe", cl::Hidden, cl::init(false),
+ cl::desc("Remove pseudo-probe after sample profile annotation."));
+
static cl::opt<std::string> ProfileInlineReplayFile(
"sample-profile-inline-replay", cl::init(""), cl::value_desc("filename"),
cl::desc(
@@ -518,6 +519,7 @@ protected:
void generateMDProfMetadata(Function &F);
bool rejectHighStalenessProfile(Module &M, ProfileSummaryInfo *PSI,
const SampleProfileMap &Profiles);
+ void removePseudoProbeInsts(Module &M);
/// Map from function name to Function *. Used to find the function from
/// the function name. If the function name contains suffix, additional
@@ -2127,6 +2129,20 @@ bool SampleProfileLoader::rejectHighStalenessProfile(
return false;
}
+void SampleProfileLoader::removePseudoProbeInsts(Module &M) {
+ for (auto &F : M) {
+ std::vector<Instruction *> InstsToDel;
+ for (auto &BB : F) {
+ for (auto &I : BB) {
+ if (isa<PseudoProbeInst>(&I))
+ InstsToDel.push_back(&I);
+ }
+ }
+ for (auto *I : InstsToDel)
+ I->eraseFromParent();
+ }
+}
+
bool SampleProfileLoader::runOnModule(Module &M, ModuleAnalysisManager *AM,
ProfileSummaryInfo *_PSI,
LazyCallGraph &CG) {
@@ -2196,6 +2212,9 @@ bool SampleProfileLoader::runOnModule(Module &M, ModuleAnalysisManager *AM,
notInlinedCallInfo)
updateProfileCallee(pair.first, pair.second.entryCount);
+ if (RemoveProbeAfterProfileAnnotation && FunctionSamples::ProfileIsProbeBased)
+ removePseudoProbeInsts(M);
+
return retval;
}
diff --git a/llvm/test/Transforms/SampleProfile/pseudo-probe-profile.ll b/llvm/test/Transforms/SampleProfile/pseudo-probe-profile.ll
index 867a49d..7258ffc 100644
--- a/llvm/test/Transforms/SampleProfile/pseudo-probe-profile.ll
+++ b/llvm/test/Transforms/SampleProfile/pseudo-probe-profile.ll
@@ -1,5 +1,9 @@
-; RUN: opt < %s -passes=pseudo-probe,sample-profile -sample-profile-file=%S/Inputs/pseudo-probe-profile.prof -pass-remarks=sample-profile -pass-remarks-output=%t.opt.yaml -sample-profile-use-profi=0 -S | FileCheck %s
-; RUN: FileCheck %s -check-prefix=YAML < %t.opt.yaml
+; RUN: opt < %s -passes=pseudo-probe,sample-profile -sample-profile-file=%S/Inputs/pseudo-probe-profile.prof -pass-remarks=sample-profile -pass-remarks-output=%t.opt.yaml -sample-profile-use-profi=0 -S -o %t
+; RUN: FileCheck %s --input-file %t
+; RUN: FileCheck %s -check-prefix=YAML --input-file %t.opt.yaml
+; RUN: opt < %t -passes=sample-profile -sample-profile-file=%S/Inputs/pseudo-probe-profile.prof -sample-profile-remove-probe -S | FileCheck %s -check-prefix=REMOVE-PROBE
+
+; REMOVE-PROBE-NOT: call void @llvm.pseudoprobe
define dso_local i32 @foo(i32 %x, ptr %f) #0 !dbg !4 {
entry: