Skip to content

Commit b7248d5

Browse files
authored
[PseudoProbe] Add an option to remove pseudo probes after profile annotation (#90293)
This can be used for testing perf overhead of pseudo-probe.
1 parent e441363 commit b7248d5

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

llvm/lib/Transforms/IPO/SampleProfile.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,20 +252,21 @@ static cl::opt<unsigned> PrecentMismatchForStalenessError(
252252

253253
static cl::opt<bool> CallsitePrioritizedInline(
254254
"sample-profile-prioritized-inline", cl::Hidden,
255-
256255
cl::desc("Use call site prioritized inlining for sample profile loader."
257256
"Currently only CSSPGO is supported."));
258257

259258
static cl::opt<bool> UsePreInlinerDecision(
260259
"sample-profile-use-preinliner", cl::Hidden,
261-
262260
cl::desc("Use the preinliner decisions stored in profile context."));
263261

264262
static cl::opt<bool> AllowRecursiveInline(
265263
"sample-profile-recursive-inline", cl::Hidden,
266-
267264
cl::desc("Allow sample loader inliner to inline recursive calls."));
268265

266+
static cl::opt<bool> RemoveProbeAfterProfileAnnotation(
267+
"sample-profile-remove-probe", cl::Hidden, cl::init(false),
268+
cl::desc("Remove pseudo-probe after sample profile annotation."));
269+
269270
static cl::opt<std::string> ProfileInlineReplayFile(
270271
"sample-profile-inline-replay", cl::init(""), cl::value_desc("filename"),
271272
cl::desc(
@@ -518,6 +519,7 @@ class SampleProfileLoader final : public SampleProfileLoaderBaseImpl<Function> {
518519
void generateMDProfMetadata(Function &F);
519520
bool rejectHighStalenessProfile(Module &M, ProfileSummaryInfo *PSI,
520521
const SampleProfileMap &Profiles);
522+
void removePseudoProbeInsts(Module &M);
521523

522524
/// Map from function name to Function *. Used to find the function from
523525
/// the function name. If the function name contains suffix, additional
@@ -2127,6 +2129,20 @@ bool SampleProfileLoader::rejectHighStalenessProfile(
21272129
return false;
21282130
}
21292131

2132+
void SampleProfileLoader::removePseudoProbeInsts(Module &M) {
2133+
for (auto &F : M) {
2134+
std::vector<Instruction *> InstsToDel;
2135+
for (auto &BB : F) {
2136+
for (auto &I : BB) {
2137+
if (isa<PseudoProbeInst>(&I))
2138+
InstsToDel.push_back(&I);
2139+
}
2140+
}
2141+
for (auto *I : InstsToDel)
2142+
I->eraseFromParent();
2143+
}
2144+
}
2145+
21302146
bool SampleProfileLoader::runOnModule(Module &M, ModuleAnalysisManager *AM,
21312147
ProfileSummaryInfo *_PSI,
21322148
LazyCallGraph &CG) {
@@ -2196,6 +2212,9 @@ bool SampleProfileLoader::runOnModule(Module &M, ModuleAnalysisManager *AM,
21962212
notInlinedCallInfo)
21972213
updateProfileCallee(pair.first, pair.second.entryCount);
21982214

2215+
if (RemoveProbeAfterProfileAnnotation && FunctionSamples::ProfileIsProbeBased)
2216+
removePseudoProbeInsts(M);
2217+
21992218
return retval;
22002219
}
22012220

llvm/test/Transforms/SampleProfile/pseudo-probe-profile.ll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
; 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
2-
; RUN: FileCheck %s -check-prefix=YAML < %t.opt.yaml
1+
; 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
2+
; RUN: FileCheck %s --input-file %t
3+
; RUN: FileCheck %s -check-prefix=YAML --input-file %t.opt.yaml
4+
; 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
5+
6+
; REMOVE-PROBE-NOT: call void @llvm.pseudoprobe
37

48
define dso_local i32 @foo(i32 %x, ptr %f) #0 !dbg !4 {
59
entry:

0 commit comments

Comments
 (0)