diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index ecc727d6dd281e..f9a04fb40cc5e6 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -109,6 +109,10 @@ static cl::opt ClSanitizeOnOptimizerEarlyEP( cl::desc("Insert sanitizers on OptimizerEarlyEP."), cl::init(false)); } +static cl::opt NewPMPasses("newpm-passes", cl::Optional, + cl::desc("Specify a custom pre-link pipeline. An empty string specifies the default pipeline."), + cl::init("")); + namespace { // Default filename used for profile generation. @@ -994,7 +998,13 @@ void EmitAssemblyHelper::RunOptimizationPipeline( MPM.addPass(InstrProfiling(*Options, false)); }); - if (CodeGenOpts.OptimizationLevel == 0) { + if (!NewPMPasses.empty()) { + MPM = PB.buildO0DefaultPipeline(Level, IsLTO || IsThinLTO); + if (auto Err = PB.parsePassPipeline(MPM, NewPMPasses)) { + report_fatal_error(Twine("unable to parse pass pipeline description '") + + NewPMPasses + "': " + toString(std::move(Err))); + } + } else if (CodeGenOpts.OptimizationLevel == 0) { MPM = PB.buildO0DefaultPipeline(Level, IsLTO || IsThinLTO); } else if (IsThinLTO) { MPM = PB.buildThinLTOPreLinkDefaultPipeline(Level);