Index: llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp =================================================================== --- llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp +++ llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp @@ -107,20 +107,6 @@ cl::opt EnableHotColdSplit("hot-cold-split", cl::init(false), cl::Hidden, cl::desc("Enable hot-cold splitting pass")); - -static cl::opt RunPGOInstrGen( - "profile-generate", cl::init(false), cl::Hidden, - cl::desc("Enable PGO instrumentation.")); - -static cl::opt - PGOOutputFile("profile-generate-file", cl::init(""), cl::Hidden, - cl::desc("Specify the path of profile data file.")); - -static cl::opt RunPGOInstrUse( - "profile-use", cl::init(""), cl::Hidden, cl::value_desc("filename"), - cl::desc("Enable use phase of PGO instrumentation and specify the path " - "of profile data file")); - static cl::opt UseLoopVersioningLICM( "enable-loop-versioning-licm", cl::init(false), cl::Hidden, cl::desc("Enable the experimental Loop Versioning LICM pass")); @@ -175,9 +161,10 @@ VerifyOutput = false; MergeFunctions = false; PrepareForLTO = false; - EnablePGOInstrGen = RunPGOInstrGen; - PGOInstrGen = PGOOutputFile; - PGOInstrUse = RunPGOInstrUse; + EnablePGOInstrGen = false; + PGOInstrGen = false; + PGOInstrUse = ""; + PGOSampleUse = ""; PrepareForThinLTO = EnablePrepareForThinLTO; PerformThinLTO = false; DivergentTarget = false; Index: llvm/trunk/test/Other/new-pm-pgo.ll =================================================================== --- llvm/trunk/test/Other/new-pm-pgo.ll +++ llvm/trunk/test/Other/new-pm-pgo.ll @@ -1,11 +1,11 @@ -; RUN: opt -debug-pass-manager -passes='default' -pgo-kind=new-pm-pgo-instr-gen-pipeline -profile-file='temp' %s 2>&1 |FileCheck %s --check-prefixes=GEN +; RUN: opt -debug-pass-manager -passes='default' -pgo-kind=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' -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' -pgo-kind=new-pm-pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-pgo.prof' %s 2>&1 \ +; RUN: opt -debug-pass-manager -passes='default' -pgo-kind=pgo-instr-use-pipeline -profile-file='%t.profdata' %s 2>&1 |FileCheck %s --check-prefixes=USE +; RUN: opt -debug-pass-manager -passes='default' -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-pgo.prof' %s 2>&1 \ ; RUN: |FileCheck %s --check-prefixes=SAMPLE_USE,SAMPLE_USE_O -; RUN: opt -debug-pass-manager -passes='thinlto-pre-link' -pgo-kind=new-pm-pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-pgo.prof' %s 2>&1 \ +; RUN: opt -debug-pass-manager -passes='thinlto-pre-link' -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-pgo.prof' %s 2>&1 \ ; RUN: |FileCheck %s --check-prefixes=SAMPLE_USE,SAMPLE_USE_PRE_LINK -; RUN: opt -debug-pass-manager -passes='thinlto' -pgo-kind=new-pm-pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-pgo.prof' %s 2>&1 \ +; RUN: opt -debug-pass-manager -passes='thinlto' -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-pgo.prof' %s 2>&1 \ ; RUN: |FileCheck %s --check-prefixes=SAMPLE_USE,SAMPLE_USE_POST_LINK ; RUN: opt -debug-pass-manager -passes='default' -new-pm-debug-info-for-profiling %s 2>&1 |FileCheck %s --check-prefixes=SAMPLE_GEN ; Index: llvm/trunk/test/Transforms/PGOProfile/preinline.ll =================================================================== --- llvm/trunk/test/Transforms/PGOProfile/preinline.ll +++ llvm/trunk/test/Transforms/PGOProfile/preinline.ll @@ -1,5 +1,5 @@ -; RUN: opt < %s -O2 -profile-generate -S | FileCheck %s --check-prefix=GEN -; RUN: opt < %s -O2 -profile-generate -profile-generate-file=default.profraw -S | FileCheck %s --check-prefix=GEN +; RUN: opt < %s -O2 -pgo-kind=pgo-instr-gen-pipeline -S | FileCheck %s --check-prefix=GEN +; RUN: opt < %s -O2 -pgo-kind=pgo-instr-gen-pipeline -profile-file=default.profraw -S | FileCheck %s --check-prefix=GEN target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" Index: llvm/trunk/test/Transforms/SampleProfile/function_metadata.ll =================================================================== --- llvm/trunk/test/Transforms/SampleProfile/function_metadata.ll +++ llvm/trunk/test/Transforms/SampleProfile/function_metadata.ll @@ -1,5 +1,5 @@ -; RUN: opt < %s -passes='thinlto-pre-link' -pgo-kind=new-pm-pgo-sample-use-pipeline -profile-file=%S/Inputs/function_metadata.prof -S | FileCheck %s -; RUN: opt < %s -passes='thinlto-pre-link' -pgo-kind=new-pm-pgo-sample-use-pipeline -profile-file=%S/Inputs/function_metadata.compact.afdo -S | FileCheck %s +; RUN: opt < %s -passes='thinlto-pre-link' -pgo-kind=pgo-sample-use-pipeline -profile-file=%S/Inputs/function_metadata.prof -S | FileCheck %s +; RUN: opt < %s -passes='thinlto-pre-link' -pgo-kind=pgo-sample-use-pipeline -profile-file=%S/Inputs/function_metadata.compact.afdo -S | FileCheck %s ; Tests whether the functions in the inline stack are added to the ; function_entry_count metadata. Index: llvm/trunk/tools/opt/NewPMDriver.h =================================================================== --- llvm/trunk/tools/opt/NewPMDriver.h +++ llvm/trunk/tools/opt/NewPMDriver.h @@ -40,6 +40,12 @@ VK_VerifyInAndOut, VK_VerifyEachPass }; +enum PGOKind { + NoPGO, + InstrGen, + InstrUse, + SampleUse +}; } /// Driver function to run the new pass manager over a module. Index: llvm/trunk/tools/opt/NewPMDriver.cpp =================================================================== --- llvm/trunk/tools/opt/NewPMDriver.cpp +++ llvm/trunk/tools/opt/NewPMDriver.cpp @@ -101,19 +101,8 @@ "the OptimizerLast extension point into default pipelines"), cl::Hidden); -enum PGOKind { NoPGO, InstrGen, InstrUse, SampleUse }; -static cl::opt 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 ProfileFile( - "profile-file", cl::desc("Path to the profile."), cl::Hidden); +extern cl::opt PGOKindFlag; +extern cl::opt ProfileFile; static cl::opt ProfileRemappingFile("profile-remapping-file", cl::desc("Path to the profile remapping file."), Index: llvm/trunk/tools/opt/opt.cpp =================================================================== --- llvm/trunk/tools/opt/opt.cpp +++ llvm/trunk/tools/opt/opt.cpp @@ -275,6 +275,19 @@ cl::desc("YAML output filename for pass remarks"), cl::value_desc("filename")); +cl::opt + 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, "pgo-instr-gen-pipeline", + "Instrument the IR to generate profile."), + clEnumValN(InstrUse, "pgo-instr-use-pipeline", + "Use instrumented profile to guide PGO."), + clEnumValN(SampleUse, "pgo-sample-use-pipeline", + "Use sampled profile to guide PGO."))); +cl::opt ProfileFile("profile-file", + cl::desc("Path to the profile."), cl::Hidden); + class OptCustomPassManager : public legacy::PassManager { DebugifyStatsMap DIStatsMap; @@ -369,6 +382,21 @@ if (Coroutines) addCoroutinePassesToExtensionPoints(Builder); + switch (PGOKindFlag) { + case InstrGen: + Builder.EnablePGOInstrGen = true; + Builder.PGOInstrGen = ProfileFile; + break; + case InstrUse: + Builder.PGOInstrUse = ProfileFile; + break; + case SampleUse: + Builder.PGOSampleUse = ProfileFile; + break; + default: + break; + } + Builder.populateFunctionPassManager(FPM); Builder.populateModulePassManager(MPM); }