Index: test/Transforms/PGOProfile/preinline.ll =================================================================== --- test/Transforms/PGOProfile/preinline.ll +++ test/Transforms/PGOProfile/preinline.ll @@ -1,5 +1,9 @@ ; 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 -passes='default' -new-pm-profile-generate -S | FileCheck %s --check-prefix=GEN +; RUN: opt < %s -passes='default' -new-pm-profile-generate-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: tools/opt/NewPMDriver.cpp =================================================================== --- tools/opt/NewPMDriver.cpp +++ tools/opt/NewPMDriver.cpp @@ -47,6 +47,22 @@ "pipeline for handling managed aliasing queries"), cl::Hidden); +static cl::opt + RunProfileGen("new-pm-profile-generate", cl::init(false), cl::Hidden, + cl::desc("Enable generating an instrumentation-based profile " + "with the new pass manager.")); + +static cl::opt ProfileGenFile( + "new-pm-profile-generate-file", cl::init(""), cl::Hidden, + cl::value_desc("filename"), + cl::desc("Enable generating an instrumentation-based profile with the new " + "pass manager and write it to the specified file.")); + +static cl::opt ProfileUseFile( + "new-pm-profile-use", cl::init(""), cl::Hidden, cl::value_desc("filename"), + cl::desc("Enable using an instrumentation-based profile with the new " + "pass manager and the given file.")); + bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM, tool_output_file *Out, StringRef PassPipeline, OutputKind OK, @@ -54,7 +70,23 @@ bool ShouldPreserveAssemblyUseListOrder, bool ShouldPreserveBitcodeUseListOrder, bool EmitSummaryIndex, bool EmitModuleHash) { - PassBuilder PB(TM); + // Handle any PGO options. + Optional PGOOpts = None; + if (RunProfileGen || !ProfileGenFile.empty()) { + if (!ProfileUseFile.empty()) { + errs() << Arg0 << ": cannot generate and use a profile in the same invocation.\n"; + return false; + } + + PGOOpts = PGOOptions(); + PGOOpts->ProfileGenFile = ProfileGenFile; + PGOOpts->RunProfileGen = true; + } else if (!ProfileUseFile.empty()) { + PGOOpts = PGOOptions(); + PGOOpts->ProfileUseFile = ProfileUseFile; + } + + PassBuilder PB(TM, PGOOpts); // Specially handle the alias analysis manager so that we can register // a custom pipeline of AA passes with it.