[llvm] 967185e - Revert "[ctx_prof] Fix the pre-thinlink "use" case (#102511)"
Aiden Grossman via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 8 14:15:03 PDT 2024
Author: Aiden Grossman
Date: 2024-08-08T21:14:56Z
New Revision: 967185eeb85abb77bd6b6cdd2b026d5c54b7d4f3
URL: https://github.com/llvm/llvm-project/commit/967185eeb85abb77bd6b6cdd2b026d5c54b7d4f3
DIFF: https://github.com/llvm/llvm-project/commit/967185eeb85abb77bd6b6cdd2b026d5c54b7d4f3.diff
LOG: Revert "[ctx_prof] Fix the pre-thinlink "use" case (#102511)"
This reverts commit 1a6d60e0162b3ef767c87c95512dd453bf4f4746.
Broke some buildbots.
Added:
Modified:
llvm/include/llvm/Transforms/Instrumentation/PGOCtxProfLowering.h
llvm/lib/Passes/PassBuilderPipelines.cpp
llvm/lib/Transforms/Instrumentation/PGOCtxProfLowering.cpp
llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
llvm/test/Transforms/PGOProfile/ctx-prof-use-prelink.ll
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/Instrumentation/PGOCtxProfLowering.h b/llvm/include/llvm/Transforms/Instrumentation/PGOCtxProfLowering.h
index f127d16b8de124..5256aff56205ba 100644
--- a/llvm/include/llvm/Transforms/Instrumentation/PGOCtxProfLowering.h
+++ b/llvm/include/llvm/Transforms/Instrumentation/PGOCtxProfLowering.h
@@ -19,8 +19,7 @@ class Type;
class PGOCtxProfLoweringPass : public PassInfoMixin<PGOCtxProfLoweringPass> {
public:
explicit PGOCtxProfLoweringPass() = default;
- // True if contextual instrumentation is enabled.
- static bool isCtxIRPGOInstrEnabled();
+ static bool isContextualIRPGOEnabled();
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
};
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 67f3464f745a16..c175ee89809849 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -1173,12 +1173,13 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
const bool IsMemprofUse = IsPGOPreLink && !PGOOpt->MemoryProfile.empty();
// We don't want to mix pgo ctx gen and pgo gen; we also don't currently
// enable ctx profiling from the frontend.
- assert(!(IsPGOInstrGen && PGOCtxProfLoweringPass::isCtxIRPGOInstrEnabled()) &&
- "Enabling both instrumented PGO and contextual instrumentation is not "
- "supported.");
+ assert(
+ !(IsPGOInstrGen && PGOCtxProfLoweringPass::isContextualIRPGOEnabled()) &&
+ "Enabling both instrumented FDO and contextual instrumentation is not "
+ "supported.");
// Enable contextual profiling instrumentation.
const bool IsCtxProfGen = !IsPGOInstrGen && IsPreLink &&
- PGOCtxProfLoweringPass::isCtxIRPGOInstrEnabled();
+ PGOCtxProfLoweringPass::isContextualIRPGOEnabled();
const bool IsCtxProfUse = !UseCtxProfile.empty() && !PGOOpt &&
Phase == ThinOrFullLTOPhase::ThinLTOPreLink;
@@ -1669,10 +1670,8 @@ PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level) {
// In pre-link, for ctx prof use, we stop here with an instrumented IR. We let
// thinlto use the contextual info to perform imports; then use the contextual
// profile in the post-thinlink phase.
- if (!UseCtxProfile.empty() && !PGOOpt) {
- addRequiredLTOPreLinkPasses(MPM);
+ if (!UseCtxProfile.empty() && !PGOOpt)
return MPM;
- }
// Run partial inlining pass to partially inline functions that have
// large bodies.
diff --git a/llvm/lib/Transforms/Instrumentation/PGOCtxProfLowering.cpp b/llvm/lib/Transforms/Instrumentation/PGOCtxProfLowering.cpp
index d6ba12465bb328..de1d4d2381c06e 100644
--- a/llvm/lib/Transforms/Instrumentation/PGOCtxProfLowering.cpp
+++ b/llvm/lib/Transforms/Instrumentation/PGOCtxProfLowering.cpp
@@ -30,7 +30,7 @@ static cl::list<std::string> ContextRoots(
"root of an interesting graph, which will be profiled independently "
"from other similar graphs."));
-bool PGOCtxProfLoweringPass::isCtxIRPGOInstrEnabled() {
+bool PGOCtxProfLoweringPass::isContextualIRPGOEnabled() {
return !ContextRoots.empty();
}
diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
index 41618194d12ed7..1ce8f58c1aa140 100644
--- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -321,7 +321,6 @@ static cl::opt<unsigned> PGOFunctionCriticalEdgeThreshold(
" greater than this threshold."));
extern cl::opt<unsigned> MaxNumVTableAnnotations;
-extern cl::opt<std::string> UseCtxProfile;
namespace llvm {
// Command line option to turn on CFG dot dump after profile annotation.
@@ -339,12 +338,9 @@ extern cl::opt<bool> EnableVTableProfileUse;
extern cl::opt<InstrProfCorrelator::ProfCorrelatorKind> ProfileCorrelate;
} // namespace llvm
-bool shouldInstrumentForCtxProf() {
- return PGOCtxProfLoweringPass::isCtxIRPGOInstrEnabled() ||
- !UseCtxProfile.empty();
-}
bool shouldInstrumentEntryBB() {
- return PGOInstrumentEntry || shouldInstrumentForCtxProf();
+ return PGOInstrumentEntry ||
+ PGOCtxProfLoweringPass::isContextualIRPGOEnabled();
}
// FIXME(mtrofin): re-enable this for ctx profiling, for non-indirect calls. Ctx
@@ -352,7 +348,8 @@ bool shouldInstrumentEntryBB() {
// Supporting other values is relatively straight-forward - just another counter
// range within the context.
bool isValueProfilingDisabled() {
- return DisableValueProfiling || shouldInstrumentForCtxProf();
+ return DisableValueProfiling ||
+ PGOCtxProfLoweringPass::isContextualIRPGOEnabled();
}
// Return a string describing the branch condition that can be
@@ -905,7 +902,7 @@ static void instrumentOneFunc(
unsigned NumCounters =
InstrumentBBs.size() + FuncInfo.SIVisitor.getNumOfSelectInsts();
- if (shouldInstrumentForCtxProf()) {
+ if (PGOCtxProfLoweringPass::isContextualIRPGOEnabled()) {
auto *CSIntrinsic =
Intrinsic::getDeclaration(M, Intrinsic::instrprof_callsite);
// We want to count the instrumentable callsites, then instrument them. This
@@ -1864,7 +1861,7 @@ static bool InstrumentAllFunctions(
function_ref<BlockFrequencyInfo *(Function &)> LookupBFI, bool IsCS) {
// For the context-sensitve instrumentation, we should have a separated pass
// (before LTO/ThinLTO linking) to create these variables.
- if (!IsCS && !shouldInstrumentForCtxProf())
+ if (!IsCS && !PGOCtxProfLoweringPass::isContextualIRPGOEnabled())
createIRLevelProfileFlagVar(M, /*IsCS=*/false);
Triple TT(M.getTargetTriple());
@@ -2115,7 +2112,7 @@ static bool annotateAllFunctions(
bool InstrumentFuncEntry = PGOReader->instrEntryBBEnabled();
if (PGOInstrumentEntry.getNumOccurrences() > 0)
InstrumentFuncEntry = PGOInstrumentEntry;
- InstrumentFuncEntry |= shouldInstrumentForCtxProf();
+ InstrumentFuncEntry |= PGOCtxProfLoweringPass::isContextualIRPGOEnabled();
bool HasSingleByteCoverage = PGOReader->hasSingleByteCoverage();
for (auto &F : M) {
diff --git a/llvm/test/Transforms/PGOProfile/ctx-prof-use-prelink.ll b/llvm/test/Transforms/PGOProfile/ctx-prof-use-prelink.ll
index 18ac2f92aa39d4..b50a815be5abf5 100644
--- a/llvm/test/Transforms/PGOProfile/ctx-prof-use-prelink.ll
+++ b/llvm/test/Transforms/PGOProfile/ctx-prof-use-prelink.ll
@@ -1,4 +1,4 @@
-; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals all --version 5
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; There is no profile, but that's OK because the prelink does not care about
; the content of the profile, just that we intend to use one.
; There is no scenario currently of doing ctx profile use without thinlto.
@@ -7,22 +7,19 @@
declare void @bar()
-;.
-; CHECK: @__profn_foo = private constant [3 x i8] c"foo"
-;.
define void @foo(i32 %a, ptr %fct) {
; CHECK-LABEL: define void @foo(
; CHECK-SAME: i32 [[A:%.*]], ptr [[FCT:%.*]]) local_unnamed_addr {
-; CHECK-NEXT: call void @llvm.instrprof.increment(ptr @__profn_foo, i64 728453322856651412, i32 2, i32 0)
; CHECK-NEXT: [[T:%.*]] = icmp eq i32 [[A]], 0
; CHECK-NEXT: br i1 [[T]], label %[[YES:.*]], label %[[NO:.*]]
; CHECK: [[YES]]:
; CHECK-NEXT: call void @llvm.instrprof.increment(ptr @__profn_foo, i64 728453322856651412, i32 2, i32 1)
-; CHECK-NEXT: call void @llvm.instrprof.callsite(ptr @__profn_foo, i64 728453322856651412, i32 2, i32 0, ptr [[FCT]])
+; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[FCT]] to i64
+; CHECK-NEXT: call void @llvm.instrprof.value.profile(ptr @__profn_foo, i64 728453322856651412, i64 [[TMP1]], i32 0, i32 0)
; CHECK-NEXT: call void [[FCT]](i32 0)
; CHECK-NEXT: br label %[[EXIT:.*]]
; CHECK: [[NO]]:
-; CHECK-NEXT: call void @llvm.instrprof.callsite(ptr @__profn_foo, i64 728453322856651412, i32 2, i32 1, ptr @bar)
+; CHECK-NEXT: call void @llvm.instrprof.increment(ptr @__profn_foo, i64 728453322856651412, i32 2, i32 0)
; CHECK-NEXT: call void @bar()
; CHECK-NEXT: br label %[[EXIT]]
; CHECK: [[EXIT]]:
@@ -39,6 +36,3 @@ no:
exit:
ret void
}
-;.
-; CHECK: attributes #[[ATTR0:[0-9]+]] = { nounwind }
-;.
More information about the llvm-commits
mailing list