diff options
author | Dehao Chen <dehao@google.com> | 2017-07-26 02:00:43 +0000 |
---|---|---|
committer | Dehao Chen <dehao@google.com> | 2017-07-26 02:00:43 +0000 |
commit | 7b05a2712a673fe7032189a142f299ded3885491 (patch) | |
tree | 0bc4774c723f8b85eac86199c7797c1256777bb6 | |
parent | 557a0b3a9eb727bdedb2b6ebf0908ae311330092 (diff) | |
download | llvm-7b05a2712a673fe7032189a142f299ded3885491.zip llvm-7b05a2712a673fe7032189a142f299ded3885491.tar.gz llvm-7b05a2712a673fe7032189a142f299ded3885491.tar.bz2 |
Add test coverage for new PM PGOOpt handling.
Summary: This patch adds flags and tests to cover the PGOOpt handling logic in new PM.
Reviewers: chandlerc, davide
Reviewed By: chandlerc
Subscribers: sanjoy, llvm-commits
Differential Revision: https://reviews.llvm.org/D35807
llvm-svn: 309076
-rw-r--r-- | llvm/include/llvm/Passes/PassBuilder.h | 12 | ||||
-rw-r--r-- | llvm/test/Other/Inputs/new-pm-pgo.prof | 1 | ||||
-rw-r--r-- | llvm/test/Other/Inputs/new-pm-pgo.proftext | 1 | ||||
-rw-r--r-- | llvm/test/Other/new-pm-pgo.ll | 12 | ||||
-rw-r--r-- | llvm/tools/opt/NewPMDriver.cpp | 30 |
5 files changed, 51 insertions, 5 deletions
diff --git a/llvm/include/llvm/Passes/PassBuilder.h b/llvm/include/llvm/Passes/PassBuilder.h index 33433f6..156fc9c 100644 --- a/llvm/include/llvm/Passes/PassBuilder.h +++ b/llvm/include/llvm/Passes/PassBuilder.h @@ -29,10 +29,14 @@ class TargetMachine; /// A struct capturing PGO tunables. struct PGOOptions { - std::string ProfileGenFile = ""; - std::string ProfileUseFile = ""; - std::string SampleProfileFile = ""; - bool RunProfileGen = false; + PGOOptions(std::string ProfileGenFile = "", std::string ProfileUseFile = "", + std::string SampleProfileFile = "", bool RunProfileGen = false) + : ProfileGenFile(ProfileGenFile), ProfileUseFile(ProfileUseFile), + SampleProfileFile(SampleProfileFile), RunProfileGen(RunProfileGen) {} + std::string ProfileGenFile; + std::string ProfileUseFile; + std::string SampleProfileFile; + bool RunProfileGen; }; /// \brief This class provides access to building LLVM's passes. diff --git a/llvm/test/Other/Inputs/new-pm-pgo.prof b/llvm/test/Other/Inputs/new-pm-pgo.prof new file mode 100644 index 0000000..4642cb9 --- /dev/null +++ b/llvm/test/Other/Inputs/new-pm-pgo.prof @@ -0,0 +1 @@ +foo:0:0 diff --git a/llvm/test/Other/Inputs/new-pm-pgo.proftext b/llvm/test/Other/Inputs/new-pm-pgo.proftext new file mode 100644 index 0000000..04a7c1c --- /dev/null +++ b/llvm/test/Other/Inputs/new-pm-pgo.proftext @@ -0,0 +1 @@ +:ir diff --git a/llvm/test/Other/new-pm-pgo.ll b/llvm/test/Other/new-pm-pgo.ll new file mode 100644 index 0000000..2388019 --- /dev/null +++ b/llvm/test/Other/new-pm-pgo.ll @@ -0,0 +1,12 @@ +; RUN: opt -debug-pass-manager -passes='default<O2>' -pgo-kind=new-pm-pgo-instr-gen-pipeline -profile-file='temp' %s 2>&1 |FileCheck %s --check-prefixes=GEN +; RUN: llvm-profdata merge %S/Inputs/new-pm-pgo.proftext -o %t.profdata +; RUN: opt -debug-pass-manager -passes='default<O2>' -pgo-kind=new-pm-pgo-instr-use-pipeline -profile-file='%t.profdata' %s 2>&1 |FileCheck %s --check-prefixes=USE +; RUN: opt -debug-pass-manager -passes='default<O2>' -pgo-kind=new-pm-pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-pgo.prof' %s 2>&1 |FileCheck %s --check-prefixes=SAMPLE_USE +; +; GEN: Running pass: PGOInstrumentationGen +; USE: Running pass: PGOInstrumentationUse +; SAMPLE_USE: Running pass: SampleProfileLoaderPass + +define void @foo() { + ret void +} diff --git a/llvm/tools/opt/NewPMDriver.cpp b/llvm/tools/opt/NewPMDriver.cpp index 94242d7..3445b7a 100644 --- a/llvm/tools/opt/NewPMDriver.cpp +++ b/llvm/tools/opt/NewPMDriver.cpp @@ -81,6 +81,19 @@ static cl::opt<std::string> VectorizerStartEPPipeline( cl::desc("A textual description of the function pass pipeline inserted at " "the VectorizerStart extension point into default pipelines"), cl::Hidden); +enum PGOKind { NoPGO, InstrGen, InstrUse, SampleUse }; +static cl::opt<PGOKind> PGOKindFlag( + "pgo-kind", cl::init(NoPGO), cl::Hidden, + cl::desc("The kind of profile guided optimization"), + cl::values(clEnumValN(NoPGO, "nopgo", "Do not use PGO."), + clEnumValN(InstrGen, "new-pm-pgo-instr-gen-pipeline", + "Instrument the IR to generate profile."), + clEnumValN(InstrUse, "new-pm-pgo-instr-use-pipeline", + "Use instrumented profile to guide PGO."), + clEnumValN(SampleUse, "new-pm-pgo-sample-use-pipeline", + "Use sampled profile to guide PGO."))); +static cl::opt<std::string> ProfileFile( + "profile-file", cl::desc("Path to the profile."), cl::Hidden); /// @}} template <typename PassManagerT> @@ -153,7 +166,22 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM, bool ShouldPreserveBitcodeUseListOrder, bool EmitSummaryIndex, bool EmitModuleHash) { bool VerifyEachPass = VK == VK_VerifyEachPass; - PassBuilder PB(TM); + + Optional<PGOOptions> P; + switch (PGOKindFlag) { + case InstrGen: + P = PGOOptions(ProfileFile, "", "", true); + break; + case InstrUse: + P = PGOOptions("", ProfileFile, "", false); + break; + case SampleUse: + P = PGOOptions("", "", ProfileFile, false); + break; + case NoPGO: + P = None; + } + PassBuilder PB(TM, P); registerEPCallbacks(PB, VerifyEachPass, DebugPM); // Specially handle the alias analysis manager so that we can register |