[llvm] r309478 - Refine the PGOOpt and SamplePGOSupport handling.
Dehao Chen via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 28 21:10:24 PDT 2017
Author: dehao
Date: Fri Jul 28 21:10:24 2017
New Revision: 309478
URL: http://llvm.org/viewvc/llvm-project?rev=309478&view=rev
Log:
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
Modified:
llvm/trunk/include/llvm/Passes/PassBuilder.h
llvm/trunk/lib/Passes/PassBuilder.cpp
llvm/trunk/test/Other/new-pm-thinlto-defaults.ll
Modified: llvm/trunk/include/llvm/Passes/PassBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Passes/PassBuilder.h?rev=309478&r1=309477&r2=309478&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Passes/PassBuilder.h (original)
+++ llvm/trunk/include/llvm/Passes/PassBuilder.h Fri Jul 28 21:10:24 2017
@@ -34,7 +34,12 @@ struct PGOOptions {
bool SamplePGOSupport = false)
: ProfileGenFile(ProfileGenFile), ProfileUseFile(ProfileUseFile),
SampleProfileFile(SampleProfileFile), RunProfileGen(RunProfileGen),
- SamplePGOSupport(SamplePGOSupport || !SampleProfileFile.empty()) {}
+ SamplePGOSupport(SamplePGOSupport || !SampleProfileFile.empty()) {
+ assert((RunProfileGen ||
+ !SampleProfileFile.empty() ||
+ !ProfileUseFile.empty() ||
+ SamplePGOSupport) && "Illegal PGOOptions.");
+ }
std::string ProfileGenFile;
std::string ProfileUseFile;
std::string SampleProfileFile;
Modified: llvm/trunk/lib/Passes/PassBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassBuilder.cpp?rev=309478&r1=309477&r2=309478&view=diff
==============================================================================
--- llvm/trunk/lib/Passes/PassBuilder.cpp (original)
+++ llvm/trunk/lib/Passes/PassBuilder.cpp Fri Jul 28 21:10:24 2017
@@ -535,8 +535,6 @@ PassBuilder::buildModuleSimplificationPi
// Create an early function pass manager to cleanup the output of the
// frontend.
FunctionPassManager EarlyFPM(DebugLogging);
- if (PGOOpt && PGOOpt->SamplePGOSupport)
- EarlyFPM.addPass(AddDiscriminatorsPass());
EarlyFPM.addPass(SimplifyCFGPass());
EarlyFPM.addPass(SROA());
EarlyFPM.addPass(EarlyCSEPass());
@@ -574,18 +572,19 @@ PassBuilder::buildModuleSimplificationPi
// Add all the requested passes for PGO, if requested.
if (PGOOpt) {
- assert(PGOOpt->RunProfileGen || !PGOOpt->SampleProfileFile.empty() ||
- !PGOOpt->ProfileUseFile.empty() || PGOOpt->SamplePGOSupport);
- if (PGOOpt->SampleProfileFile.empty())
+ if (!PGOOpt->ProfileGenFile.empty() || !PGOOpt->ProfileUseFile.empty())
+ // Instrumentation based PGO (gen and use)
addPGOInstrPasses(MPM, DebugLogging, Level, PGOOpt->RunProfileGen,
PGOOpt->ProfileGenFile, PGOOpt->ProfileUseFile);
- else
+ else if (!PGOOpt->SampleProfileFile.empty())
+ // SamplePGO use
MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile));
// Indirect call promotion that promotes intra-module targes only.
// Do not enable it in PrepareForThinLTO phase during sample PGO because
// it changes IR to makes profile annotation in back compile inaccurate.
- if (!PrepareForThinLTO || PGOOpt->SampleProfileFile.empty())
+ if ((!PrepareForThinLTO && !PGOOpt->SampleProfileFile.empty())
+ || !PGOOpt->ProfileUseFile.empty())
MPM.addPass(PGOIndirectCallPromotion(
false, PGOOpt && !PGOOpt->SampleProfileFile.empty()));
}
@@ -779,6 +778,9 @@ PassBuilder::buildPerModuleDefaultPipeli
// Force any function attributes we want the rest of the pipeline to observe.
MPM.addPass(ForceFunctionAttrsPass());
+ if (PGOOpt && PGOOpt->SamplePGOSupport)
+ MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
+
// Add the core simplification pipeline.
MPM.addPass(buildModuleSimplificationPipeline(Level, DebugLogging,
/*PrepareForThinLTO=*/false));
@@ -799,6 +801,9 @@ PassBuilder::buildThinLTOPreLinkDefaultP
// Force any function attributes we want the rest of the pipeline to observe.
MPM.addPass(ForceFunctionAttrsPass());
+ if (PGOOpt && PGOOpt->SamplePGOSupport)
+ MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
+
// If we are planning to perform ThinLTO later, we don't bloat the code with
// unrolling/vectorization/... now. Just simplify the module as much as we
// can.
Modified: llvm/trunk/test/Other/new-pm-thinlto-defaults.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/new-pm-thinlto-defaults.ll?rev=309478&r1=309477&r2=309478&view=diff
==============================================================================
--- llvm/trunk/test/Other/new-pm-thinlto-defaults.ll (original)
+++ llvm/trunk/test/Other/new-pm-thinlto-defaults.ll Fri Jul 28 21:10:24 2017
@@ -10,19 +10,22 @@
; Prelink pipelines:
; RUN: opt -disable-verify -debug-pass-manager \
; RUN: -passes='thinlto-pre-link<O1>,name-anon-globals' -S %s 2>&1 \
-; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O1,CHECK-PRELINK-O,CHECK-PRELINK-O1
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O1,CHECK-PRELINK-O,CHECK-PRELINK-O-NODIS,CHECK-PRELINK-O1
; RUN: opt -disable-verify -debug-pass-manager \
; RUN: -passes='thinlto-pre-link<O2>,name-anon-globals' -S %s 2>&1 \
-; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O2,CHECK-PRELINK-O,CHECK-PRELINK-O2
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O2,CHECK-PRELINK-O,CHECK-PRELINK-O-NODIS,CHECK-PRELINK-O2
; RUN: opt -disable-verify -debug-pass-manager \
; RUN: -passes='thinlto-pre-link<O3>,name-anon-globals' -S %s 2>&1 \
-; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O3,CHECK-PRELINK-O,CHECK-PRELINK-O3
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O3,CHECK-PRELINK-O,CHECK-PRELINK-O-NODIS,CHECK-PRELINK-O3
; RUN: opt -disable-verify -debug-pass-manager \
; RUN: -passes='thinlto-pre-link<Os>,name-anon-globals' -S %s 2>&1 \
-; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-Os,CHECK-PRELINK-O,CHECK-PRELINK-Os
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-Os,CHECK-PRELINK-O,CHECK-PRELINK-O-NODIS,CHECK-PRELINK-Os
; RUN: opt -disable-verify -debug-pass-manager \
; RUN: -passes='thinlto-pre-link<Oz>,name-anon-globals' -S %s 2>&1 \
-; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-Oz,CHECK-PRELINK-O,CHECK-PRELINK-Oz
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-Oz,CHECK-PRELINK-O,CHECK-PRELINK-O-NODIS,CHECK-PRELINK-Oz
+; RUN: opt -disable-verify -debug-pass-manager -new-pm-debug-info-for-profiling \
+; RUN: -passes='thinlto-pre-link<O2>,name-anon-globals' -S %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-DIS,CHECK-O,CHECK-O2,CHECK-PRELINK-O,CHECK-PRELINK-O2
;
; Postlink pipelines:
; RUN: opt -disable-verify -debug-pass-manager \
@@ -40,11 +43,16 @@
; RUN: opt -disable-verify -debug-pass-manager \
; RUN: -passes='thinlto<Oz>' -S %s 2>&1 \
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-Oz,CHECK-POSTLINK-O,CHECK-POSTLINK-Oz
+; RUN: opt -disable-verify -debug-pass-manager -new-pm-debug-info-for-profiling \
+; RUN: -passes='thinlto<O2>' -S %s 2>&1 \
+; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O2,CHECK-POSTLINK-O,CHECK-POSTLINK-O2
;
; CHECK-O: Starting llvm::Module pass manager run.
; CHECK-O-NEXT: Running pass: PassManager<{{.*}}Module{{.*}}>
; CHECK-O-NEXT: Starting llvm::Module pass manager run.
; CHECK-O-NEXT: Running pass: ForceFunctionAttrsPass
+; CHECK-DIS-NEXT: Running pass: ModuleToFunctionPassAdaptor<llvm::AddDiscriminatorsPass>
+; CHECK-DIS-NEXT: Running analysis: InnerAnalysisManagerProxy
; CHECK-POSTLINK-O-NEXT: Running pass: PGOIndirectCallPromotion
; CHECK-POSTLINK-O-NEXT: Running analysis: InnerAnalysisManagerProxy<{{.*}}Function
; CHECK-POSTLINK-O-NEXT: Running analysis: OptimizationRemarkEmitterAnalysis
@@ -53,7 +61,7 @@
; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass
; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
; CHECK-O-NEXT: Running pass: ModuleToFunctionPassAdaptor<{{.*}}PassManager{{.*}}>
-; CHECK-PRELINK-O-NEXT: Running analysis: InnerAnalysisManagerProxy
+; CHECK-PRELINK-O-NODIS-NEXT: Running analysis: InnerAnalysisManagerProxy
; CHECK-O-NEXT: Starting llvm::Function pass manager run.
; CHECK-O-NEXT: Running pass: SimplifyCFGPass
; CHECK-O-NEXT: Running analysis: TargetIRAnalysis
More information about the llvm-commits
mailing list