Skip to content

Commit ce0842c

Browse files
committedJul 29, 2017
Refine the PGOOpt and SamplePGOSupport handling.
Summary: Now that SamplePGOSupport is part of PGOOpt, there are several places that need tweaking: 1. AddDiscriminator pass should *not* be invoked at ThinLTOBackend (as it's already invoked in the PreLink phase) 2. addPGOInstrPasses should only be invoked when either ProfileGenFile or ProfileUseFile is non-empty. 3. SampleProfileLoaderPass should only be invoked when SampleProfileFile is non-empty. 4. PGOIndirectCallPromotion should only be invoked in ProfileUse phase, or in ThinLTOBackend of SamplePGO. Reviewers: chandlerc, tejohnson, davidxl Reviewed By: chandlerc Subscribers: sanjoy, mehdi_amini, eraman, llvm-commits Differential Revision: https://reviews.llvm.org/D36040 llvm-svn: 309478
1 parent 503fd44 commit ce0842c

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed
 

‎llvm/include/llvm/Passes/PassBuilder.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ struct PGOOptions {
3434
bool SamplePGOSupport = false)
3535
: ProfileGenFile(ProfileGenFile), ProfileUseFile(ProfileUseFile),
3636
SampleProfileFile(SampleProfileFile), RunProfileGen(RunProfileGen),
37-
SamplePGOSupport(SamplePGOSupport || !SampleProfileFile.empty()) {}
37+
SamplePGOSupport(SamplePGOSupport || !SampleProfileFile.empty()) {
38+
assert((RunProfileGen ||
39+
!SampleProfileFile.empty() ||
40+
!ProfileUseFile.empty() ||
41+
SamplePGOSupport) && "Illegal PGOOptions.");
42+
}
3843
std::string ProfileGenFile;
3944
std::string ProfileUseFile;
4045
std::string SampleProfileFile;

‎llvm/lib/Passes/PassBuilder.cpp

+12-7
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,6 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
535535
// Create an early function pass manager to cleanup the output of the
536536
// frontend.
537537
FunctionPassManager EarlyFPM(DebugLogging);
538-
if (PGOOpt && PGOOpt->SamplePGOSupport)
539-
EarlyFPM.addPass(AddDiscriminatorsPass());
540538
EarlyFPM.addPass(SimplifyCFGPass());
541539
EarlyFPM.addPass(SROA());
542540
EarlyFPM.addPass(EarlyCSEPass());
@@ -574,18 +572,19 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
574572

575573
// Add all the requested passes for PGO, if requested.
576574
if (PGOOpt) {
577-
assert(PGOOpt->RunProfileGen || !PGOOpt->SampleProfileFile.empty() ||
578-
!PGOOpt->ProfileUseFile.empty() || PGOOpt->SamplePGOSupport);
579-
if (PGOOpt->SampleProfileFile.empty())
575+
if (!PGOOpt->ProfileGenFile.empty() || !PGOOpt->ProfileUseFile.empty())
576+
// Instrumentation based PGO (gen and use)
580577
addPGOInstrPasses(MPM, DebugLogging, Level, PGOOpt->RunProfileGen,
581578
PGOOpt->ProfileGenFile, PGOOpt->ProfileUseFile);
582-
else
579+
else if (!PGOOpt->SampleProfileFile.empty())
580+
// SamplePGO use
583581
MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile));
584582

585583
// Indirect call promotion that promotes intra-module targes only.
586584
// Do not enable it in PrepareForThinLTO phase during sample PGO because
587585
// it changes IR to makes profile annotation in back compile inaccurate.
588-
if (!PrepareForThinLTO || PGOOpt->SampleProfileFile.empty())
586+
if ((!PrepareForThinLTO && !PGOOpt->SampleProfileFile.empty())
587+
|| !PGOOpt->ProfileUseFile.empty())
589588
MPM.addPass(PGOIndirectCallPromotion(
590589
false, PGOOpt && !PGOOpt->SampleProfileFile.empty()));
591590
}
@@ -779,6 +778,9 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
779778
// Force any function attributes we want the rest of the pipeline to observe.
780779
MPM.addPass(ForceFunctionAttrsPass());
781780

781+
if (PGOOpt && PGOOpt->SamplePGOSupport)
782+
MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
783+
782784
// Add the core simplification pipeline.
783785
MPM.addPass(buildModuleSimplificationPipeline(Level, DebugLogging,
784786
/*PrepareForThinLTO=*/false));
@@ -799,6 +801,9 @@ PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level,
799801
// Force any function attributes we want the rest of the pipeline to observe.
800802
MPM.addPass(ForceFunctionAttrsPass());
801803

804+
if (PGOOpt && PGOOpt->SamplePGOSupport)
805+
MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
806+
802807
// If we are planning to perform ThinLTO later, we don't bloat the code with
803808
// unrolling/vectorization/... now. Just simplify the module as much as we
804809
// can.

‎llvm/test/Other/new-pm-thinlto-defaults.ll

+14-6
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,22 @@
1010
; Prelink pipelines:
1111
; RUN: opt -disable-verify -debug-pass-manager \
1212
; RUN: -passes='thinlto-pre-link<O1>,name-anon-globals' -S %s 2>&1 \
13-
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O1,CHECK-PRELINK-O,CHECK-PRELINK-O1
13+
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O1,CHECK-PRELINK-O,CHECK-PRELINK-O-NODIS,CHECK-PRELINK-O1
1414
; RUN: opt -disable-verify -debug-pass-manager \
1515
; RUN: -passes='thinlto-pre-link<O2>,name-anon-globals' -S %s 2>&1 \
16-
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O2,CHECK-PRELINK-O,CHECK-PRELINK-O2
16+
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O2,CHECK-PRELINK-O,CHECK-PRELINK-O-NODIS,CHECK-PRELINK-O2
1717
; RUN: opt -disable-verify -debug-pass-manager \
1818
; RUN: -passes='thinlto-pre-link<O3>,name-anon-globals' -S %s 2>&1 \
19-
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O3,CHECK-PRELINK-O,CHECK-PRELINK-O3
19+
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O3,CHECK-PRELINK-O,CHECK-PRELINK-O-NODIS,CHECK-PRELINK-O3
2020
; RUN: opt -disable-verify -debug-pass-manager \
2121
; RUN: -passes='thinlto-pre-link<Os>,name-anon-globals' -S %s 2>&1 \
22-
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-Os,CHECK-PRELINK-O,CHECK-PRELINK-Os
22+
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-Os,CHECK-PRELINK-O,CHECK-PRELINK-O-NODIS,CHECK-PRELINK-Os
2323
; RUN: opt -disable-verify -debug-pass-manager \
2424
; RUN: -passes='thinlto-pre-link<Oz>,name-anon-globals' -S %s 2>&1 \
25-
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-Oz,CHECK-PRELINK-O,CHECK-PRELINK-Oz
25+
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-Oz,CHECK-PRELINK-O,CHECK-PRELINK-O-NODIS,CHECK-PRELINK-Oz
26+
; RUN: opt -disable-verify -debug-pass-manager -new-pm-debug-info-for-profiling \
27+
; RUN: -passes='thinlto-pre-link<O2>,name-anon-globals' -S %s 2>&1 \
28+
; RUN: | FileCheck %s --check-prefixes=CHECK-DIS,CHECK-O,CHECK-O2,CHECK-PRELINK-O,CHECK-PRELINK-O2
2629
;
2730
; Postlink pipelines:
2831
; RUN: opt -disable-verify -debug-pass-manager \
@@ -40,11 +43,16 @@
4043
; RUN: opt -disable-verify -debug-pass-manager \
4144
; RUN: -passes='thinlto<Oz>' -S %s 2>&1 \
4245
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-Oz,CHECK-POSTLINK-O,CHECK-POSTLINK-Oz
46+
; RUN: opt -disable-verify -debug-pass-manager -new-pm-debug-info-for-profiling \
47+
; RUN: -passes='thinlto<O2>' -S %s 2>&1 \
48+
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O2,CHECK-POSTLINK-O,CHECK-POSTLINK-O2
4349
;
4450
; CHECK-O: Starting llvm::Module pass manager run.
4551
; CHECK-O-NEXT: Running pass: PassManager<{{.*}}Module{{.*}}>
4652
; CHECK-O-NEXT: Starting llvm::Module pass manager run.
4753
; CHECK-O-NEXT: Running pass: ForceFunctionAttrsPass
54+
; CHECK-DIS-NEXT: Running pass: ModuleToFunctionPassAdaptor<llvm::AddDiscriminatorsPass>
55+
; CHECK-DIS-NEXT: Running analysis: InnerAnalysisManagerProxy
4856
; CHECK-POSTLINK-O-NEXT: Running pass: PGOIndirectCallPromotion
4957
; CHECK-POSTLINK-O-NEXT: Running analysis: InnerAnalysisManagerProxy<{{.*}}Function
5058
; CHECK-POSTLINK-O-NEXT: Running analysis: OptimizationRemarkEmitterAnalysis
@@ -53,7 +61,7 @@
5361
; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass
5462
; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
5563
; CHECK-O-NEXT: Running pass: ModuleToFunctionPassAdaptor<{{.*}}PassManager{{.*}}>
56-
; CHECK-PRELINK-O-NEXT: Running analysis: InnerAnalysisManagerProxy
64+
; CHECK-PRELINK-O-NODIS-NEXT: Running analysis: InnerAnalysisManagerProxy
5765
; CHECK-O-NEXT: Starting llvm::Function pass manager run.
5866
; CHECK-O-NEXT: Running pass: SimplifyCFGPass
5967
; CHECK-O-NEXT: Running analysis: TargetIRAnalysis

0 commit comments

Comments
 (0)
Please sign in to comment.