Skip to content

Commit 967185e

Browse files
Revert "[ctx_prof] Fix the pre-thinlink "use" case (#102511)"
This reverts commit 1a6d60e. Broke some buildbots.
1 parent 1baa6f7 commit 967185e

File tree

5 files changed

+19
-30
lines changed

5 files changed

+19
-30
lines changed

llvm/include/llvm/Transforms/Instrumentation/PGOCtxProfLowering.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ class Type;
1919
class PGOCtxProfLoweringPass : public PassInfoMixin<PGOCtxProfLoweringPass> {
2020
public:
2121
explicit PGOCtxProfLoweringPass() = default;
22-
// True if contextual instrumentation is enabled.
23-
static bool isCtxIRPGOInstrEnabled();
22+
static bool isContextualIRPGOEnabled();
2423

2524
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
2625
};

llvm/lib/Passes/PassBuilderPipelines.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,12 +1173,13 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
11731173
const bool IsMemprofUse = IsPGOPreLink && !PGOOpt->MemoryProfile.empty();
11741174
// We don't want to mix pgo ctx gen and pgo gen; we also don't currently
11751175
// enable ctx profiling from the frontend.
1176-
assert(!(IsPGOInstrGen && PGOCtxProfLoweringPass::isCtxIRPGOInstrEnabled()) &&
1177-
"Enabling both instrumented PGO and contextual instrumentation is not "
1178-
"supported.");
1176+
assert(
1177+
!(IsPGOInstrGen && PGOCtxProfLoweringPass::isContextualIRPGOEnabled()) &&
1178+
"Enabling both instrumented FDO and contextual instrumentation is not "
1179+
"supported.");
11791180
// Enable contextual profiling instrumentation.
11801181
const bool IsCtxProfGen = !IsPGOInstrGen && IsPreLink &&
1181-
PGOCtxProfLoweringPass::isCtxIRPGOInstrEnabled();
1182+
PGOCtxProfLoweringPass::isContextualIRPGOEnabled();
11821183
const bool IsCtxProfUse = !UseCtxProfile.empty() && !PGOOpt &&
11831184
Phase == ThinOrFullLTOPhase::ThinLTOPreLink;
11841185

@@ -1669,10 +1670,8 @@ PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level) {
16691670
// In pre-link, for ctx prof use, we stop here with an instrumented IR. We let
16701671
// thinlto use the contextual info to perform imports; then use the contextual
16711672
// profile in the post-thinlink phase.
1672-
if (!UseCtxProfile.empty() && !PGOOpt) {
1673-
addRequiredLTOPreLinkPasses(MPM);
1673+
if (!UseCtxProfile.empty() && !PGOOpt)
16741674
return MPM;
1675-
}
16761675

16771676
// Run partial inlining pass to partially inline functions that have
16781677
// large bodies.

llvm/lib/Transforms/Instrumentation/PGOCtxProfLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static cl::list<std::string> ContextRoots(
3030
"root of an interesting graph, which will be profiled independently "
3131
"from other similar graphs."));
3232

33-
bool PGOCtxProfLoweringPass::isCtxIRPGOInstrEnabled() {
33+
bool PGOCtxProfLoweringPass::isContextualIRPGOEnabled() {
3434
return !ContextRoots.empty();
3535
}
3636

llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@ static cl::opt<unsigned> PGOFunctionCriticalEdgeThreshold(
321321
" greater than this threshold."));
322322

323323
extern cl::opt<unsigned> MaxNumVTableAnnotations;
324-
extern cl::opt<std::string> UseCtxProfile;
325324

326325
namespace llvm {
327326
// Command line option to turn on CFG dot dump after profile annotation.
@@ -339,20 +338,18 @@ extern cl::opt<bool> EnableVTableProfileUse;
339338
extern cl::opt<InstrProfCorrelator::ProfCorrelatorKind> ProfileCorrelate;
340339
} // namespace llvm
341340

342-
bool shouldInstrumentForCtxProf() {
343-
return PGOCtxProfLoweringPass::isCtxIRPGOInstrEnabled() ||
344-
!UseCtxProfile.empty();
345-
}
346341
bool shouldInstrumentEntryBB() {
347-
return PGOInstrumentEntry || shouldInstrumentForCtxProf();
342+
return PGOInstrumentEntry ||
343+
PGOCtxProfLoweringPass::isContextualIRPGOEnabled();
348344
}
349345

350346
// FIXME(mtrofin): re-enable this for ctx profiling, for non-indirect calls. Ctx
351347
// profiling implicitly captures indirect call cases, but not other values.
352348
// Supporting other values is relatively straight-forward - just another counter
353349
// range within the context.
354350
bool isValueProfilingDisabled() {
355-
return DisableValueProfiling || shouldInstrumentForCtxProf();
351+
return DisableValueProfiling ||
352+
PGOCtxProfLoweringPass::isContextualIRPGOEnabled();
356353
}
357354

358355
// Return a string describing the branch condition that can be
@@ -905,7 +902,7 @@ static void instrumentOneFunc(
905902
unsigned NumCounters =
906903
InstrumentBBs.size() + FuncInfo.SIVisitor.getNumOfSelectInsts();
907904

908-
if (shouldInstrumentForCtxProf()) {
905+
if (PGOCtxProfLoweringPass::isContextualIRPGOEnabled()) {
909906
auto *CSIntrinsic =
910907
Intrinsic::getDeclaration(M, Intrinsic::instrprof_callsite);
911908
// We want to count the instrumentable callsites, then instrument them. This
@@ -1864,7 +1861,7 @@ static bool InstrumentAllFunctions(
18641861
function_ref<BlockFrequencyInfo *(Function &)> LookupBFI, bool IsCS) {
18651862
// For the context-sensitve instrumentation, we should have a separated pass
18661863
// (before LTO/ThinLTO linking) to create these variables.
1867-
if (!IsCS && !shouldInstrumentForCtxProf())
1864+
if (!IsCS && !PGOCtxProfLoweringPass::isContextualIRPGOEnabled())
18681865
createIRLevelProfileFlagVar(M, /*IsCS=*/false);
18691866

18701867
Triple TT(M.getTargetTriple());
@@ -2115,7 +2112,7 @@ static bool annotateAllFunctions(
21152112
bool InstrumentFuncEntry = PGOReader->instrEntryBBEnabled();
21162113
if (PGOInstrumentEntry.getNumOccurrences() > 0)
21172114
InstrumentFuncEntry = PGOInstrumentEntry;
2118-
InstrumentFuncEntry |= shouldInstrumentForCtxProf();
2115+
InstrumentFuncEntry |= PGOCtxProfLoweringPass::isContextualIRPGOEnabled();
21192116

21202117
bool HasSingleByteCoverage = PGOReader->hasSingleByteCoverage();
21212118
for (auto &F : M) {
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals all --version 5
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
22
; There is no profile, but that's OK because the prelink does not care about
33
; the content of the profile, just that we intend to use one.
44
; There is no scenario currently of doing ctx profile use without thinlto.
@@ -7,22 +7,19 @@
77

88
declare void @bar()
99

10-
;.
11-
; CHECK: @__profn_foo = private constant [3 x i8] c"foo"
12-
;.
1310
define void @foo(i32 %a, ptr %fct) {
1411
; CHECK-LABEL: define void @foo(
1512
; CHECK-SAME: i32 [[A:%.*]], ptr [[FCT:%.*]]) local_unnamed_addr {
16-
; CHECK-NEXT: call void @llvm.instrprof.increment(ptr @__profn_foo, i64 728453322856651412, i32 2, i32 0)
1713
; CHECK-NEXT: [[T:%.*]] = icmp eq i32 [[A]], 0
1814
; CHECK-NEXT: br i1 [[T]], label %[[YES:.*]], label %[[NO:.*]]
1915
; CHECK: [[YES]]:
2016
; CHECK-NEXT: call void @llvm.instrprof.increment(ptr @__profn_foo, i64 728453322856651412, i32 2, i32 1)
21-
; CHECK-NEXT: call void @llvm.instrprof.callsite(ptr @__profn_foo, i64 728453322856651412, i32 2, i32 0, ptr [[FCT]])
17+
; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[FCT]] to i64
18+
; CHECK-NEXT: call void @llvm.instrprof.value.profile(ptr @__profn_foo, i64 728453322856651412, i64 [[TMP1]], i32 0, i32 0)
2219
; CHECK-NEXT: call void [[FCT]](i32 0)
2320
; CHECK-NEXT: br label %[[EXIT:.*]]
2421
; CHECK: [[NO]]:
25-
; CHECK-NEXT: call void @llvm.instrprof.callsite(ptr @__profn_foo, i64 728453322856651412, i32 2, i32 1, ptr @bar)
22+
; CHECK-NEXT: call void @llvm.instrprof.increment(ptr @__profn_foo, i64 728453322856651412, i32 2, i32 0)
2623
; CHECK-NEXT: call void @bar()
2724
; CHECK-NEXT: br label %[[EXIT]]
2825
; CHECK: [[EXIT]]:
@@ -39,6 +36,3 @@ no:
3936
exit:
4037
ret void
4138
}
42-
;.
43-
; CHECK: attributes #[[ATTR0:[0-9]+]] = { nounwind }
44-
;.

0 commit comments

Comments
 (0)