Skip to content

Commit 75fd23b

Browse files
committed
[ctx_prof] Insert the ctx prof flattener after the module inliner
1 parent 0c3c448 commit 75fd23b

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

llvm/lib/Passes/PassBuilderPipelines.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,11 @@ PassBuilder::buildModuleInlinerPipeline(OptimizationLevel Level,
10171017
IP.EnableDeferral = false;
10181018

10191019
MPM.addPass(ModuleInlinerPass(IP, UseInlineAdvisor, Phase));
1020+
if (!UseCtxProfile.empty()) {
1021+
MPM.addPass(GlobalOptPass());
1022+
MPM.addPass(GlobalDCEPass());
1023+
MPM.addPass(PGOCtxProfFlatteningPass());
1024+
}
10201025

10211026
MPM.addPass(createModuleToFunctionPassAdaptor(
10221027
buildFunctionSimplificationPipeline(Level, Phase),
@@ -1744,11 +1749,14 @@ ModulePassManager PassBuilder::buildThinLTODefaultPipeline(
17441749
MPM.addPass(GlobalDCEPass());
17451750
return MPM;
17461751
}
1747-
1748-
// Add the core simplification pipeline.
1749-
MPM.addPass(buildModuleSimplificationPipeline(
1750-
Level, ThinOrFullLTOPhase::ThinLTOPostLink));
1751-
1752+
if (!UseCtxProfile.empty()) {
1753+
MPM.addPass(
1754+
buildModuleInlinerPipeline(Level, ThinOrFullLTOPhase::ThinLTOPostLink));
1755+
} else {
1756+
// Add the core simplification pipeline.
1757+
MPM.addPass(buildModuleSimplificationPipeline(
1758+
Level, ThinOrFullLTOPhase::ThinLTOPostLink));
1759+
}
17521760
// Now add the optimization pipeline.
17531761
MPM.addPass(buildModuleOptimizationPipeline(
17541762
Level, ThinOrFullLTOPhase::ThinLTOPostLink));

llvm/lib/Transforms/IPO/ModuleInliner.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,10 @@ PreservedAnalyses ModuleInlinerPass::run(Module &M,
241241
// the post-inline cleanup and the next DevirtSCCRepeatedPass
242242
// iteration because the next iteration may not happen and we may
243243
// miss inlining it.
244-
if (tryPromoteCall(*ICB))
245-
NewCallee = ICB->getCalledFunction();
244+
// FIXME: enable for ctxprof.
245+
if (!CtxProf)
246+
if (tryPromoteCall(*ICB))
247+
NewCallee = ICB->getCalledFunction();
246248
}
247249
if (NewCallee)
248250
if (!NewCallee->isDeclaration())

llvm/test/Analysis/CtxProfAnalysis/inline.ll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@
3131
; CHECK-NEXT: %call2 = call i32 @a(i32 %x) #1
3232
; CHECK-NEXT: br label %exit
3333

34+
; Make sure the postlink thinlto pipeline is aware of ctxprof
35+
; RUN: opt -passes='thinlto<O2>' -use-ctx-profile=%t/profile.ctxprofdata \
36+
; RUN: %t/module.ll -S -o - | FileCheck %s --check-prefix=PIPELINE
37+
38+
; PIPELINE-LABEL: define i32 @entrypoint
39+
; PIPELINE-SAME: !prof ![[ENTRYPOINT_COUNT:[0-9]+]]
40+
; PIPELINE-LABEL: loop.i:
41+
; PIPELINE: br i1 %cond.i, label %loop.i, label %exit, !prof ![[LOOP_BW_INL:[0-9]+]]
42+
; PIPELINE-LABEL: define i32 @a
43+
; PIPELINE-LABEL: loop:
44+
; PIPELINE: br i1 %cond, label %loop, label %exit, !prof ![[LOOP_BW_ORIG:[0-9]+]]
45+
46+
; PIPELINE: ![[ENTRYPOINT_COUNT]] = !{!"function_entry_count", i64 10}
47+
; These are the weights of the inlined @a, where the counters were 2, 100 (2 for entry, 100 for loop)
48+
; PIPELINE: ![[LOOP_BW_INL]] = !{!"branch_weights", i32 98, i32 2}
49+
; These are the weights of the un-inlined @a, where the counters were 8, 500 (8 for entry, 500 for loop)
50+
; PIPELINE: ![[LOOP_BW_ORIG]] = !{!"branch_weights", i32 492, i32 8}
3451

3552
;--- module.ll
3653
define i32 @entrypoint(i32 %x) !guid !0 {

llvm/test/Other/opt-hot-cold-split.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
; RUN: opt -mtriple=x86_64-- -hot-cold-split=true -passes='lto-pre-link<Os>' -debug-pass-manager < %s -o /dev/null 2>&1 | FileCheck %s -check-prefix=LTO-PRELINK-Os
33
; RUN: opt -mtriple=x86_64-- -hot-cold-split=true -passes='thinlto-pre-link<Os>' -debug-pass-manager < %s -o /dev/null 2>&1 | FileCheck %s -check-prefix=THINLTO-PRELINK-Os
44
; RUN: opt -mtriple=x86_64-- -hot-cold-split=true -passes='lto<Os>' -debug-pass-manager < %s -o /dev/null 2>&1 | FileCheck %s -check-prefix=LTO-POSTLINK-Os
5-
; RUN: opt -mtriple=x86_64-- -hot-cold-split=true -passes='thinlto<Os>' -debug-pass-manager < %s -o /dev/null 2>&1 | FileCheck %s -check-prefix=THINLTO-POSTLINK-Os
5+
; RUN: opt -mtriple=x86_64-- -hot-cold-split=true -LINK-Os
66

77
; REQUIRES: asserts
88

0 commit comments

Comments
 (0)