https://github.com/MaskRay created 
https://github.com/llvm/llvm-project/pull/238434

PR #232599 added `PipelineTuningOptions(const cl::LibraryOptionsContext
*);` for per-context library option support. The default ctor passes a
null context, so it and the getters it calls (e.g.
getForgetSCEVInLoopUnroll) read `T::Global` instead of the values parsed
into an LLVMContext.

Make the members whose defaults come from library options std::optional.
PassBuilder sets the unset ones from its LLVMContext. Remove the pointer
parameter ctor from #232599.

LLVMRunPasses now reads these options from the module's context, like
the other PassBuilder options.

LLM-aided

>From 8d2adba5a16a0f8cb5bd3d14f98899f2cbff63d0 Mon Sep 17 00:00:00 2001
From: Fangrui Song <[email protected]>
Date: Sat, 31 Oct 2026 12:20:12 -0700
Subject: [PATCH] [Passes] Make PipelineTuningOptions not read library options

PR #232599 added `PipelineTuningOptions(const cl::LibraryOptionsContext
*);` for per-context library option support. The default ctor passes a
null context, so it and the getters it calls (e.g.
getForgetSCEVInLoopUnroll) read `T::Global` instead of the values parsed
into an LLVMContext.

Make the members whose defaults come from library options std::optional.
PassBuilder sets the unset ones from its LLVMContext. Remove the pointer
parameter ctor from #232599.

LLVMRunPasses now reads these options from the module's context, like
the other PassBuilder options.

LLM-aided
---
 clang/lib/CodeGen/BackendUtil.cpp             |   3 +-
 .../ClangNVLinkWrapper.cpp                    |   1 -
 flang/lib/Frontend/FrontendActions.cpp        |   2 +-
 lld/COFF/LTO.cpp                              |   1 -
 lld/ELF/LTO.cpp                               |   1 -
 lld/MachO/LTO.cpp                             |   1 -
 lld/wasm/LTO.cpp                              |   1 -
 llvm/include/llvm/Analysis/CallGraphSCCPass.h |   2 +-
 llvm/include/llvm/Passes/PassBuilder.h        |  49 ++++----
 llvm/include/llvm/Transforms/Scalar/LICM.h    |  10 +-
 .../llvm/Transforms/Scalar/LoopUnrollPass.h   |   5 +-
 llvm/lib/Analysis/CallGraphSCCPass.cpp        |   5 +-
 llvm/lib/DTLTO/CMakeLists.txt                 |   1 +
 llvm/lib/DTLTO/DTLTO.cpp                      |   5 +-
 llvm/lib/LTO/LTOCodeGenerator.cpp             |   1 -
 llvm/lib/LTO/ThinLTOCodeGenerator.cpp         |   2 +-
 llvm/lib/Passes/PassBuilder.cpp               |   3 +-
 llvm/lib/Passes/PassBuilderPipelines.cpp      | 108 ++++++++++--------
 llvm/lib/Passes/RunCodeGen.cpp                |   3 +-
 llvm/lib/Transforms/Scalar/LICM.cpp           |  10 +-
 llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp |   5 +-
 llvm/tools/gold/gold-plugin.cpp               |   1 -
 llvm/tools/llvm-lto2/llvm-lto2.cpp            |   1 -
 llvm/tools/opt/NewPMDriver.cpp                |   2 +-
 .../gn/secondary/llvm/lib/DTLTO/BUILD.gn      |   1 +
 mlir/lib/ExecutionEngine/OptUtils.cpp         |   2 +-
 .../llvm-project-overlay/llvm/BUILD.bazel     |   1 +
 27 files changed, 109 insertions(+), 118 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index e04934548176f8..f226878f64f6f8 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -910,7 +910,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
   if (TM)
     TM->setPGOOption(PGOOpt);
 
-  PipelineTuningOptions PTO(&LibraryOptions);
+  PipelineTuningOptions PTO;
   PTO.LoopUnrolling = CodeGenOpts.UnrollLoops;
   PTO.LoopInterchange = CodeGenOpts.InterchangeLoops;
   PTO.LoopFusion = CodeGenOpts.FuseLoops;
@@ -1387,7 +1387,6 @@ runThinLTOBackend(CompilerInstance &CI, 
ModuleSummaryIndex *CombinedIndex,
   Conf.SampleProfile = std::move(SampleProfile);
   const cl::LibraryOptionsContext &LibraryOptions =
       M->getContext().getLibraryOptions();
-  Conf.PTO = PipelineTuningOptions(&LibraryOptions);
   Conf.PTO.LoopUnrolling = CGOpts.UnrollLoops;
   Conf.PTO.LoopInterchange = CGOpts.InterchangeLoops;
   Conf.PTO.LoopFusion = CGOpts.FuseLoops;
diff --git a/clang/tools/clang-nvlink-wrapper/ClangNVLinkWrapper.cpp 
b/clang/tools/clang-nvlink-wrapper/ClangNVLinkWrapper.cpp
index 6550902a6a6551..7bd9b007c74087 100644
--- a/clang/tools/clang-nvlink-wrapper/ClangNVLinkWrapper.cpp
+++ b/clang/tools/clang-nvlink-wrapper/ClangNVLinkWrapper.cpp
@@ -376,7 +376,6 @@ createLTO(const cl::LibraryOptionsContext &LibraryOptions,
   const llvm::Triple Triple("nvptx64-nvidia-cuda");
   lto::Config Conf;
   Conf.LibraryOptions = &LibraryOptions;
-  Conf.PTO = PipelineTuningOptions(&LibraryOptions);
   lto::ThinBackend Backend;
   unsigned Jobs = 0;
   if (auto *Arg = Args.getLastArg(OPT_jobs))
diff --git a/flang/lib/Frontend/FrontendActions.cpp 
b/flang/lib/Frontend/FrontendActions.cpp
index 823b437d6e83fc..12047a65fb423f 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -966,7 +966,7 @@ void 
CodeGenAction::runOptimizationPipeline(llvm::raw_pwrite_stream &os) {
   llvm::PassInstrumentationCallbacks pic;
   const llvm::cl::LibraryOptionsContext &libraryOptions =
       llvmModule->getContext().getLibraryOptions();
-  llvm::PipelineTuningOptions pto(&libraryOptions);
+  llvm::PipelineTuningOptions pto;
   std::optional<llvm::PGOOptions> pgoOpt;
 
   if (opts.hasProfileIRInstr()) {
diff --git a/lld/COFF/LTO.cpp b/lld/COFF/LTO.cpp
index 20209019a3e6fe..ed22a2f8206395 100644
--- a/lld/COFF/LTO.cpp
+++ b/lld/COFF/LTO.cpp
@@ -57,7 +57,6 @@ std::string BitcodeCompiler::getThinLTOOutputFile(StringRef 
path) {
 lto::Config BitcodeCompiler::createConfig() {
   lto::Config c;
   c.LibraryOptions = &ctx.config.libraryOptions;
-  c.PTO = PipelineTuningOptions(c.LibraryOptions);
   c.Options = initTargetOptionsFromCodeGenFlags();
   c.Options.EmitAddrsig = true;
   for (StringRef C : ctx.config.mllvmOpts)
diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp
index 0fa5673ed0f25b..7666e2bbb84094 100644
--- a/lld/ELF/LTO.cpp
+++ b/lld/ELF/LTO.cpp
@@ -56,7 +56,6 @@ static std::string getThinLTOOutputFile(Ctx &ctx, StringRef 
modulePath) {
 static lto::Config createConfig(Ctx &ctx) {
   lto::Config c;
   c.LibraryOptions = &ctx.arg.libraryOptions;
-  c.PTO = PipelineTuningOptions(c.LibraryOptions);
 
   // LLD supports the new relocations and address-significance tables.
   c.Options = initTargetOptionsFromCodeGenFlags();
diff --git a/lld/MachO/LTO.cpp b/lld/MachO/LTO.cpp
index 8eb008c990fe6c..d54a74e108e05f 100644
--- a/lld/MachO/LTO.cpp
+++ b/lld/MachO/LTO.cpp
@@ -39,7 +39,6 @@ static std::string getThinLTOOutputFile(StringRef modulePath) 
{
 static lto::Config createConfig() {
   lto::Config c;
   c.LibraryOptions = &config->libraryOptions;
-  c.PTO = PipelineTuningOptions(c.LibraryOptions);
   c.Options = initTargetOptionsFromCodeGenFlags();
   c.Options.EmitAddrsig = config->icfLevel == ICFLevel::safe ||
                           config->icfLevel == ICFLevel::safe_thunks;
diff --git a/lld/wasm/LTO.cpp b/lld/wasm/LTO.cpp
index 8bafd95a258688..774908babc84de 100644
--- a/lld/wasm/LTO.cpp
+++ b/lld/wasm/LTO.cpp
@@ -43,7 +43,6 @@ static std::string getThinLTOOutputFile(StringRef modulePath) 
{
 static lto::Config createConfig() {
   lto::Config c;
   c.LibraryOptions = &ctx.arg.libraryOptions;
-  c.PTO = PipelineTuningOptions(c.LibraryOptions);
   c.Options = initTargetOptionsFromCodeGenFlags();
 
   // Always emit a section per function/data with LTO.
diff --git a/llvm/include/llvm/Analysis/CallGraphSCCPass.h 
b/llvm/include/llvm/Analysis/CallGraphSCCPass.h
index a9042a43fec700..68c0277e9fb63d 100644
--- a/llvm/include/llvm/Analysis/CallGraphSCCPass.h
+++ b/llvm/include/llvm/Analysis/CallGraphSCCPass.h
@@ -35,7 +35,7 @@ namespace cl {
 class LibraryOptionsContext;
 } // namespace cl
 
-LLVM_ABI unsigned getMaxDevirtIterations(const cl::LibraryOptionsContext *);
+LLVM_ABI unsigned getMaxDevirtIterations(const cl::LibraryOptionsContext &);
 
 class LLVM_ABI CallGraphSCCPass : public Pass {
 public:
diff --git a/llvm/include/llvm/Passes/PassBuilder.h 
b/llvm/include/llvm/Passes/PassBuilder.h
index 3512c9c9a9ca29..07882a21a1b857 100644
--- a/llvm/include/llvm/Passes/PassBuilder.h
+++ b/llvm/include/llvm/Passes/PassBuilder.h
@@ -42,18 +42,16 @@ namespace cl {
 class LibraryOptionsContext;
 } // namespace cl
 
-/// Tunable parameters for passes in the default pipelines.
+/// Tunable parameters for passes in the default pipelines. An unset optional
+/// member takes the value of its library option in the PassBuilder's
+/// LLVMContext.
 class PipelineTuningOptions {
 public:
-  /// Constructor sets pipeline tuning defaults based on the global values of
-  /// the library options. Each option can be set in the PassBuilder when using
-  /// a LLVM as a library.
-  PipelineTuningOptions() : PipelineTuningOptions(nullptr) {}
+  LLVM_ABI PipelineTuningOptions();
 
-  /// Reads the defaults from \p LibraryOptions, or their global values if
-  /// null.
-  LLVM_ABI explicit PipelineTuningOptions(
-      const cl::LibraryOptionsContext *LibraryOptions);
+  /// Return a copy whose unset members are set from \p LibraryOptions.
+  [[nodiscard]] LLVM_ABI PipelineTuningOptions
+  resolve(const cl::LibraryOptionsContext &LibraryOptions) const;
 
   /// Tuning option to set loop interleaving on/off, set based on opt level.
   bool LoopInterleaving;
@@ -69,24 +67,22 @@ class PipelineTuningOptions {
   /// Tuning option to enable/disable loop unrolling. Its default value is 
true.
   bool LoopUnrolling;
 
-  /// Tuning option to enable/disable loop interchange. Its default value is
-  /// false.
-  bool LoopInterchange;
+  /// Tuning option to enable/disable loop interchange.
+  std::optional<bool> LoopInterchange;
 
   /// Tuning option to enable/disable loop fusion. Its default value is false.
   bool LoopFusion;
 
-  /// Tuning option to forget all SCEV loops in LoopUnroll. Its default value
-  /// is that of the flag: `-forget-scev-loop-unroll`.
-  bool ForgetAllSCEVInLoopUnroll;
+  /// Tuning option to forget all SCEV loops in LoopUnroll.
+  std::optional<bool> ForgetAllSCEVInLoopUnroll;
 
   /// Tuning option to cap the number of calls to retrive clobbering accesses 
in
   /// MemorySSA, in LICM.
-  unsigned LicmMssaOptCap;
+  std::optional<unsigned> LicmMssaOptCap;
 
   /// Tuning option to disable promotion to scalars in LICM with MemorySSA, if
   /// the number of access is too large.
-  unsigned LicmMssaNoAccForPromotionCap;
+  std::optional<unsigned> LicmMssaNoAccForPromotionCap;
 
   /// Tuning option to enable/disable call graph profile. Its default value is
   /// that of the flag: `-enable-npm-call-graph-profile`.
@@ -95,17 +91,15 @@ class PipelineTuningOptions {
   // Add LTO pipeline tuning option to enable the unified LTO pipeline.
   bool UnifiedLTO;
 
-  /// Tuning option to enable/disable function merging. Its default value is
-  /// false.
-  bool MergeFunctions;
+  /// Tuning option to enable/disable function merging.
+  std::optional<bool> MergeFunctions;
 
   /// Tuning option to override the default inliner threshold.
   int InlinerThreshold;
 
   /// Tuning option to cap how many times the inliner pipeline reruns on an SCC
-  /// after devirtualizing a call. Its default value is that of the flag:
-  /// `-max-devirt-iterations`.
-  unsigned MaxDevirtIterations;
+  /// after devirtualizing a call.
+  std::optional<unsigned> MaxDevirtIterations;
 
   // Experimental option to eagerly invalidate more analyses. This has the
   // potential to decrease max memory usage in exchange for more compile time.
@@ -114,11 +108,10 @@ class PipelineTuningOptions {
   // stale/imprecise but still valid. Currently this invalidates all function
   // analyses after various module->function or cgscc->function adaptors in the
   // default pipelines.
-  bool EagerlyInvalidateAnalyses;
+  std::optional<bool> EagerlyInvalidateAnalyses;
 
   // Tuning option to enable/disable speculative devirtualization.
-  // Its default value is false.
-  bool DevirtualizeSpeculatively;
+  std::optional<bool> DevirtualizeSpeculatively;
 };
 
 enum class PrintPipelinePassesFormat {
@@ -156,8 +149,8 @@ class PassBuilder {
   };
 
   /// The pipelines read the library options of \p Context, which must outlive
-  /// the PassBuilder. If \p PTO is not given, it reads its defaults from
-  /// \p Context.
+  /// the PassBuilder. Unset members of \p PTO, or all of them if \p PTO is not
+  /// given, are set from \p Context.
   LLVM_ABI explicit PassBuilder(
       LLVMContext &Context, TargetMachine *TM = nullptr,
       std::optional<PipelineTuningOptions> PTO = std::nullopt,
diff --git a/llvm/include/llvm/Transforms/Scalar/LICM.h 
b/llvm/include/llvm/Transforms/Scalar/LICM.h
index 7eb460e7b33599..379dbd2152a308 100644
--- a/llvm/include/llvm/Transforms/Scalar/LICM.h
+++ b/llvm/include/llvm/Transforms/Scalar/LICM.h
@@ -45,14 +45,12 @@ namespace cl {
 class LibraryOptionsContext;
 } // namespace cl
 
-/// Returns -licm-mssa-optimization-cap of LibraryOptions, or its global value
-/// if null.
+/// Return -licm-mssa-optimization-cap.
 LLVM_ABI unsigned
-getLicmMssaOptCap(const cl::LibraryOptionsContext *LibraryOptions);
-/// Returns -licm-mssa-max-acc-promotion of LibraryOptions, or its global value
-/// if null.
+getLicmMssaOptCap(const cl::LibraryOptionsContext &LibraryOptions);
+/// Return -licm-mssa-max-acc-promotion.
 LLVM_ABI unsigned getLicmMssaNoAccForPromotionCap(
-    const cl::LibraryOptionsContext *LibraryOptions);
+    const cl::LibraryOptionsContext &LibraryOptions);
 
 struct LICMOptions {
   // Unset means the -licm-mssa-* value of the loop's LLVMContext.
diff --git a/llvm/include/llvm/Transforms/Scalar/LoopUnrollPass.h 
b/llvm/include/llvm/Transforms/Scalar/LoopUnrollPass.h
index 7955d8f79dc5c0..f2e50353b9b42e 100644
--- a/llvm/include/llvm/Transforms/Scalar/LoopUnrollPass.h
+++ b/llvm/include/llvm/Transforms/Scalar/LoopUnrollPass.h
@@ -19,10 +19,9 @@ namespace cl {
 class LibraryOptionsContext;
 } // namespace cl
 
-/// Returns -forget-scev-loop-unroll of LibraryOptions, or its global value if
-/// null.
+/// Return -forget-scev-loop-unroll.
 LLVM_ABI bool
-getForgetSCEVInLoopUnroll(const cl::LibraryOptionsContext *LibraryOptions);
+getForgetSCEVInLoopUnroll(const cl::LibraryOptionsContext &LibraryOptions);
 
 class Function;
 class Loop;
diff --git a/llvm/lib/Analysis/CallGraphSCCPass.cpp 
b/llvm/lib/Analysis/CallGraphSCCPass.cpp
index ba120b245275df..bff6aee0cad972 100644
--- a/llvm/lib/Analysis/CallGraphSCCPass.cpp
+++ b/llvm/lib/Analysis/CallGraphSCCPass.cpp
@@ -44,9 +44,8 @@ using namespace llvm;
 #define DEBUG_TYPE "cgscc-passmgr"
 
 unsigned
-llvm::getMaxDevirtIterations(const cl::LibraryOptionsContext *LibraryOptions) {
-  return cl::LibraryOptionsContext::get<AnalysisOptions>(LibraryOptions)
-      .max_devirt_iterations;
+llvm::getMaxDevirtIterations(const cl::LibraryOptionsContext &LibraryOptions) {
+  return LibraryOptions.get<AnalysisOptions>().max_devirt_iterations;
 }
 
 STATISTIC(MaxSCCIterations, "Maximum CGSCCPassMgr iterations on one SCC");
diff --git a/llvm/lib/DTLTO/CMakeLists.txt b/llvm/lib/DTLTO/CMakeLists.txt
index f40f5709321088..6296e0efd91ff0 100644
--- a/llvm/lib/DTLTO/CMakeLists.txt
+++ b/llvm/lib/DTLTO/CMakeLists.txt
@@ -11,5 +11,6 @@ add_llvm_component_library(LLVMDTLTO
   Core
   LTO
   Object
+  Passes
   Support
   )
diff --git a/llvm/lib/DTLTO/DTLTO.cpp b/llvm/lib/DTLTO/DTLTO.cpp
index 669ba75c80d4b6..0f4ccc4cfe1a04 100644
--- a/llvm/lib/DTLTO/DTLTO.cpp
+++ b/llvm/lib/DTLTO/DTLTO.cpp
@@ -226,7 +226,10 @@ void lto::DTLTO::buildCommonRemoteCompilerOptions() {
     Ops.push_back("-ffunction-sections");
   if (C.Options.DataSections)
     Ops.push_back("-fdata-sections");
-  if (C.PTO.LoopInterchange)
+  // Match what an in-process backend resolves from C.LibraryOptions.
+  cl::LibraryOptionsContext NoLibraryOptions;
+  if (*C.PTO.resolve(C.LibraryOptions ? *C.LibraryOptions : NoLibraryOptions)
+           .LoopInterchange)
     Ops.push_back("-floop-interchange");
 
   if (C.RelocModel == Reloc::PIC_)
diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp 
b/llvm/lib/LTO/LTOCodeGenerator.cpp
index ad58b4fc3cf239..82a089a454dd21 100644
--- a/llvm/lib/LTO/LTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -564,7 +564,6 @@ bool LTOCodeGenerator::optimize() {
   Config.RunCSIRInstr = LTORunCSIRInstr;
   Config.CSIRProfile = LTOCSIRProfile;
   Config.SampleProfile = SampleProfileFile;
-  Config.PTO = PipelineTuningOptions(Config.LibraryOptions);
   Config.PTO.LoopVectorization = Config.OptLevel > 1;
   Config.PTO.SLPVectorization = Config.OptLevel > 1;
 
diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp 
b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
index 13e4c7bb5fc6f6..a2060b003ffa37 100644
--- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
@@ -261,7 +261,7 @@ static void optimizeModule(Module &TheModule, TargetMachine 
&TM,
   PassInstrumentationCallbacks PIC;
   StandardInstrumentations SI(TheModule.getContext(), DebugPassManager);
   SI.registerCallbacks(PIC, &MAM);
-  PipelineTuningOptions PTO(&TheModule.getContext().getLibraryOptions());
+  PipelineTuningOptions PTO;
   PTO.LoopVectorization = true;
   PTO.SLPVectorization = true;
   PassBuilder PB(TheModule.getContext(), &TM, PTO, PGOOpt, &PIC);
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 8db9e561c825e4..3ca89c8d11163f 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -574,7 +574,8 @@ PassBuilder::PassBuilder(LLVMContext &Context, 
TargetMachine *TM,
                          PassInstrumentationCallbacks *PIC,
                          IntrusiveRefCntPtr<vfs::FileSystem> FS)
     : Context(Context), Opts(getPassesOptions(Context)), TM(TM),
-      PTO(PTO ? *PTO : PipelineTuningOptions(&Context.getLibraryOptions())),
+      PTO(PTO.value_or(PipelineTuningOptions())
+              .resolve(Context.getLibraryOptions())),
       PGOOpt(PGOOpt), PIC(PIC), FS(std::move(FS)) {
   if (TM)
     TM->registerPassBuilderCallbacks(*this);
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp 
b/llvm/lib/Passes/PassBuilderPipelines.cpp
index d1229a93ecf275..b815fe6e80113b 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -170,27 +170,35 @@ extern cl::opt<bool> EnableMemProfContextDisambiguation;
 extern cl::opt<bool> EnableProfcheckInPipeline;
 } // namespace llvm
 
-PipelineTuningOptions::PipelineTuningOptions(
-    const cl::LibraryOptionsContext *LibraryOptions) {
-  const PassesOptions &Opts =
-      cl::LibraryOptionsContext::get<PassesOptions>(LibraryOptions);
+PipelineTuningOptions::PipelineTuningOptions() {
   LoopInterleaving = true;
   LoopVectorization = true;
   SLPVectorization = false;
   LoopUnrolling = true;
-  LoopInterchange = Opts.enable_loopinterchange;
   LoopFusion = false;
-  ForgetAllSCEVInLoopUnroll = getForgetSCEVInLoopUnroll(LibraryOptions);
-  LicmMssaOptCap = getLicmMssaOptCap(LibraryOptions);
-  LicmMssaNoAccForPromotionCap =
-      getLicmMssaNoAccForPromotionCap(LibraryOptions);
   CallGraphProfile = true;
   UnifiedLTO = false;
-  MergeFunctions = Opts.enable_merge_functions;
   InlinerThreshold = -1;
-  MaxDevirtIterations = getMaxDevirtIterations(LibraryOptions);
-  EagerlyInvalidateAnalyses = Opts.eagerly_invalidate_analyses;
-  DevirtualizeSpeculatively = Opts.enable_devirtualize_speculatively;
+}
+
+PipelineTuningOptions PipelineTuningOptions::resolve(
+    const cl::LibraryOptionsContext &LibraryOptions) const {
+  const PassesOptions &Opts = LibraryOptions.get<PassesOptions>();
+  PipelineTuningOptions R = *this;
+  R.LoopInterchange = LoopInterchange.value_or(Opts.enable_loopinterchange);
+  R.ForgetAllSCEVInLoopUnroll = ForgetAllSCEVInLoopUnroll.value_or(
+      getForgetSCEVInLoopUnroll(LibraryOptions));
+  R.LicmMssaOptCap = 
LicmMssaOptCap.value_or(getLicmMssaOptCap(LibraryOptions));
+  R.LicmMssaNoAccForPromotionCap = LicmMssaNoAccForPromotionCap.value_or(
+      getLicmMssaNoAccForPromotionCap(LibraryOptions));
+  R.MergeFunctions = MergeFunctions.value_or(Opts.enable_merge_functions);
+  R.MaxDevirtIterations =
+      MaxDevirtIterations.value_or(getMaxDevirtIterations(LibraryOptions));
+  R.EagerlyInvalidateAnalyses =
+      EagerlyInvalidateAnalyses.value_or(Opts.eagerly_invalidate_analyses);
+  R.DevirtualizeSpeculatively = DevirtualizeSpeculatively.value_or(
+      Opts.enable_devirtualize_speculatively);
+  return R;
 }
 
 void PassBuilder::invokePeepholeEPCallbacks(FunctionPassManager &FPM,
@@ -425,13 +433,13 @@ 
PassBuilder::buildO1FunctionSimplificationPipeline(OptimizationLevel Level,
   // will destroy metadata that may not need to be destroyed if run
   // after loop rotation.
   // TODO: Investigate promotion cap for O1.
-  LPM1.addPass(LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap,
+  LPM1.addPass(LICMPass(*PTO.LicmMssaOptCap, *PTO.LicmMssaNoAccForPromotionCap,
                         /*AllowSpeculation=*/false));
 
   LPM1.addPass(
       LoopRotatePass(/*EnableHeaderDuplication=*/true, isLTOPreLink(Phase)));
   // TODO: Investigate promotion cap for O1.
-  LPM1.addPass(LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap,
+  LPM1.addPass(LICMPass(*PTO.LicmMssaOptCap, *PTO.LicmMssaNoAccForPromotionCap,
                         /*AllowSpeculation=*/true));
   LPM1.addPass(SimpleLoopUnswitchPass());
   if (Opts.enable_loop_flatten)
@@ -453,7 +461,7 @@ 
PassBuilder::buildO1FunctionSimplificationPipeline(OptimizationLevel Level,
       PGOOpt->Action != PGOOptions::SampleUse)
     LPM2.addPass(LoopFullUnrollPass(static_cast<int>(Level),
                                     /* OnlyWhenForced= */ !PTO.LoopUnrolling,
-                                    PTO.ForgetAllSCEVInLoopUnroll));
+                                    *PTO.ForgetAllSCEVInLoopUnroll));
 
   invokeLoopOptimizerEndEPCallbacks(LPM2, Level);
 
@@ -599,13 +607,13 @@ 
PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
   // will destroy metadata that may not need to be destroyed if run
   // after loop rotation.
   // TODO: Investigate promotion cap for O1.
-  LPM1.addPass(LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap,
+  LPM1.addPass(LICMPass(*PTO.LicmMssaOptCap, *PTO.LicmMssaNoAccForPromotionCap,
                         /*AllowSpeculation=*/false));
 
   LPM1.addPass(
       LoopRotatePass(/*EnableHeaderDuplication=*/true, isLTOPreLink(Phase)));
   // TODO: Investigate promotion cap for O1.
-  LPM1.addPass(LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap,
+  LPM1.addPass(LICMPass(*PTO.LicmMssaOptCap, *PTO.LicmMssaNoAccForPromotionCap,
                         /*AllowSpeculation=*/true));
   LPM1.addPass(
       SimpleLoopUnswitchPass(/* NonTrivial */ Level == OptimizationLevel::O3));
@@ -635,7 +643,7 @@ 
PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
       PGOOpt->Action != PGOOptions::SampleUse)
     LPM2.addPass(LoopFullUnrollPass(static_cast<int>(Level),
                                     /* OnlyWhenForced= */ !PTO.LoopUnrolling,
-                                    PTO.ForgetAllSCEVInLoopUnroll));
+                                    *PTO.ForgetAllSCEVInLoopUnroll));
 
   invokeLoopOptimizerEndEPCallbacks(LPM2, Level);
 
@@ -699,7 +707,7 @@ 
PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
   FPM.addPass(MoveAutoInitPass());
 
   FPM.addPass(createFunctionToLoopPassAdaptor(
-      LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap,
+      LICMPass(*PTO.LicmMssaOptCap, *PTO.LicmMssaNoAccForPromotionCap,
                /*AllowSpeculation=*/true),
       /*UseMemorySSA=*/true));
 
@@ -756,7 +764,7 @@ void PassBuilder::addPreInlinerPasses(ModulePassManager 
&MPM,
   invokePeepholeEPCallbacks(FPM, Level);
 
   CGPipeline.addPass(createCGSCCToFunctionPassAdaptor(
-      std::move(FPM), PTO.EagerlyInvalidateAnalyses));
+      std::move(FPM), *PTO.EagerlyInvalidateAnalyses));
 
   MPM.addPass(std::move(MIWP));
 
@@ -773,7 +781,7 @@ void PassBuilder::addPostPGOLoopRotation(ModulePassManager 
&MPM,
     MPM.addPass(createModuleToFunctionPassAdaptor(
         createFunctionToLoopPassAdaptor(LoopRotatePass(),
                                         /*UseMemorySSA=*/false),
-        PTO.EagerlyInvalidateAnalyses));
+        *PTO.EagerlyInvalidateAnalyses));
   }
 }
 
@@ -869,7 +877,7 @@ PassBuilder::buildInlinerPipeline(OptimizationLevel Level,
   ModuleInlinerWrapperPass MIWP(IP, Opts.mandatory_inlining_first,
                                 InlineContext{Phase, InlinePass::CGSCCInliner},
                                 Opts.enable_ml_inliner,
-                                PTO.MaxDevirtIterations);
+                                *PTO.MaxDevirtIterations);
 
   // Require the GlobalsAA analysis for the module so we can query it within
   // the CGSCC pipeline.
@@ -926,7 +934,7 @@ PassBuilder::buildInlinerPipeline(OptimizationLevel Level,
   // CGSCC walk.
   MainCGPipeline.addPass(createCGSCCToFunctionPassAdaptor(
       buildFunctionSimplificationPipeline(Level, Phase),
-      PTO.EagerlyInvalidateAnalyses, /*NoRerun=*/true));
+      *PTO.EagerlyInvalidateAnalyses, /*NoRerun=*/true));
 
   // Finally, deduce any function attributes based on the fully simplified
   // function.
@@ -990,7 +998,7 @@ PassBuilder::buildModuleInlinerPipeline(OptimizationLevel 
Level,
 
   MPM.addPass(createModuleToFunctionPassAdaptor(
       buildFunctionSimplificationPipeline(Level, Phase),
-      PTO.EagerlyInvalidateAnalyses));
+      *PTO.EagerlyInvalidateAnalyses));
 
   if (!isThinLTOPreLink(Phase)) {
     MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(
@@ -1064,7 +1072,7 @@ 
PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
     if (Level == OptimizationLevel::O3)
       EarlyFPM.addPass(CallSiteSplittingPass());
     MPM.addPass(createModuleToFunctionPassAdaptor(
-        std::move(EarlyFPM), PTO.EagerlyInvalidateAnalyses));
+        std::move(EarlyFPM), *PTO.EagerlyInvalidateAnalyses));
   }
 
   if (LoadSampleProfile) {
@@ -1126,8 +1134,8 @@ 
PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
   invokePeepholeEPCallbacks(GlobalCleanupPM, Level);
   GlobalCleanupPM.addPass(
       SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(true)));
-  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(GlobalCleanupPM),
-                                                
PTO.EagerlyInvalidateAnalyses));
+  MPM.addPass(createModuleToFunctionPassAdaptor(
+      std::move(GlobalCleanupPM), *PTO.EagerlyInvalidateAnalyses));
 
   // We already asserted this happens in non-FullLTOPostLink earlier.
   const bool IsPreLink = !isThinLTOPostLink(Phase);
@@ -1269,7 +1277,7 @@ void PassBuilder::addVectorPasses(OptimizationLevel Level,
           LoopUnrollAndJamPass(static_cast<int>(Level))));
     FPM.addPass(LoopUnrollPass(LoopUnrollOptions(
         static_cast<int>(Level), /*OnlyWhenForced=*/!PTO.LoopUnrolling,
-        PTO.ForgetAllSCEVInLoopUnroll)));
+        *PTO.ForgetAllSCEVInLoopUnroll)));
     FPM.addPass(WarnMissedTransformationsPass());
     // Now that we are done with loop unrolling, be it either by 
LoopVectorizer,
     // or LoopUnroll passes, some variable-offset GEP's into alloca's could 
have
@@ -1309,7 +1317,7 @@ void PassBuilder::addVectorPasses(OptimizationLevel Level,
     ExtraPasses.addPass(CorrelatedValuePropagationPass());
     ExtraPasses.addPass(InstCombinePass());
     LoopPassManager LPM;
-    LPM.addPass(LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap,
+    LPM.addPass(LICMPass(*PTO.LicmMssaOptCap, 
*PTO.LicmMssaNoAccForPromotionCap,
                          /*AllowSpeculation=*/true));
     LPM.addPass(SimpleLoopUnswitchPass(/* NonTrivial */ Level ==
                                        OptimizationLevel::O3));
@@ -1370,7 +1378,7 @@ void PassBuilder::addVectorPasses(OptimizationLevel Level,
     }
     FPM.addPass(LoopUnrollPass(LoopUnrollOptions(
         static_cast<int>(Level), /*OnlyWhenForced=*/!PTO.LoopUnrolling,
-        PTO.ForgetAllSCEVInLoopUnroll)));
+        *PTO.ForgetAllSCEVInLoopUnroll)));
     FPM.addPass(WarnMissedTransformationsPass());
     // Now that we are done with loop unrolling, be it either by 
LoopVectorizer,
     // or LoopUnroll passes, some variable-offset GEP's into alloca's could 
have
@@ -1400,7 +1408,7 @@ void PassBuilder::addVectorPasses(OptimizationLevel Level,
   //   2. It helps to clean up some loop-invariant code created by the loop
   //      unroll pass when IsFullLTO=false.
   FPM.addPass(createFunctionToLoopPassAdaptor(
-      LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap,
+      LICMPass(*PTO.LicmMssaOptCap, *PTO.LicmMssaNoAccForPromotionCap,
                /*AllowSpeculation=*/true),
       /*UseMemorySSA=*/true));
 
@@ -1484,7 +1492,7 @@ 
PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
         createFunctionToLoopPassAdaptor(LoopVersioningLICMPass()));
     // LoopVersioningLICM pass might increase new LICM opportunities.
     OptimizePM.addPass(createFunctionToLoopPassAdaptor(
-        LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap,
+        LICMPass(*PTO.LicmMssaOptCap, *PTO.LicmMssaNoAccForPromotionCap,
                  /*AllowSpeculation=*/true),
         /*USeMemorySSA=*/true));
   }
@@ -1525,7 +1533,7 @@ 
PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
   //        in the simplification pipeline.
   LPM.addPass(LoopDeletionPass());
 
-  if (PTO.LoopInterchange)
+  if (*PTO.LoopInterchange)
     LPM.addPass(LoopInterchangePass());
 
   OptimizePM.addPass(
@@ -1584,8 +1592,8 @@ 
PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
                           .hoistLoadsStoresWithCondFaulting(true)));
 
   // Add the core optimizing pipeline.
-  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(OptimizePM),
-                                                
PTO.EagerlyInvalidateAnalyses));
+  MPM.addPass(createModuleToFunctionPassAdaptor(
+      std::move(OptimizePM), *PTO.EagerlyInvalidateAnalyses));
 
   // AllocToken transforms heap allocation calls; this needs to run late after
   // other allocation call transformations (such as those in InstCombine).
@@ -1613,7 +1621,7 @@ 
PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
 
   // Merge functions if requested. It has a better chance to merge functions
   // after ConstantMerge folded jump tables.
-  if (PTO.MergeFunctions)
+  if (*PTO.MergeFunctions)
     MPM.addPass(MergeFunctionsPass());
 
   if (PTO.CallGraphProfile && !isLTOPreLink(LTOPhase))
@@ -1625,7 +1633,7 @@ 
PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
 
   // Add devirtualization pass only when LTO is not enabled, as otherwise
   // the pass is already enabled in the LTO pipeline.
-  if (PTO.DevirtualizeSpeculatively && LTOPhase == ThinOrFullLTOPhase::None) {
+  if (*PTO.DevirtualizeSpeculatively && LTOPhase == ThinOrFullLTOPhase::None) {
     // TODO: explore a better pipeline configuration that can improve
     // compilation time overhead.
     // FIXME: move this earlier (lots of pass ordering tests will need fixing)
@@ -1633,7 +1641,7 @@ 
PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
     MPM.addPass(WholeProgramDevirtPass(
         /*ExportSummary*/ nullptr,
         /*ImportSummary*/ nullptr,
-        /*DevirtSpeculatively*/ PTO.DevirtualizeSpeculatively));
+        /*DevirtSpeculatively*/ *PTO.DevirtualizeSpeculatively));
     MPM.addPass(DropTypeTestsPass());
     // Given that the devirtualization creates more opportunities for inlining,
     // we run the Inliner again here to maximize the optimization gain we
@@ -1988,7 +1996,7 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel 
Level,
 
   if (Level >= OptimizationLevel::O2) {
     MPM.addPass(createModuleToFunctionPassAdaptor(
-        CallSiteSplittingPass(), PTO.EagerlyInvalidateAnalyses));
+        CallSiteSplittingPass(), *PTO.EagerlyInvalidateAnalyses));
 
     // Indirect call promotion. This should promote all the targets that are
     // left by the earlier promotion pass that promotes intra-module targets.
@@ -2038,7 +2046,7 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel 
Level,
   // Stop here at -O1.
   if (Level == OptimizationLevel::O1) {
     MPM.addPass(createModuleToFunctionPassAdaptor(
-        LowerConstantIntrinsicsPass(), PTO.EagerlyInvalidateAnalyses));
+        LowerConstantIntrinsicsPass(), *PTO.EagerlyInvalidateAnalyses));
 
     // The LowerTypeTestsPass needs to run to lower type metadata and the
     // type.test intrinsics. The pass does nothing if CFI is disabled.
@@ -2090,8 +2098,8 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel 
Level,
     PeepholeFPM.addPass(AggressiveInstCombinePass());
   invokePeepholeEPCallbacks(PeepholeFPM, Level);
 
-  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(PeepholeFPM),
-                                                
PTO.EagerlyInvalidateAnalyses));
+  MPM.addPass(createModuleToFunctionPassAdaptor(
+      std::move(PeepholeFPM), *PTO.EagerlyInvalidateAnalyses));
 
   // Lower variadic functions for supported targets prior to inlining.
   MPM.addPass(ExpandVariadicsPass(ExpandVariadicsMode::Optimize));
@@ -2161,8 +2169,8 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel 
Level,
       TailCallElimPass(/*UpdateFunctionEntryCount=*/isInstrumentedPGOUse()));
 
   // Run a few AA driver optimizations here and now to cleanup the code.
-  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM),
-                                                
PTO.EagerlyInvalidateAnalyses));
+  MPM.addPass(createModuleToFunctionPassAdaptor(
+      std::move(FPM), *PTO.EagerlyInvalidateAnalyses));
 
   if (Opts.attributor_enable & AttributorRunOption::CGSCC_LIGHT) {
     MPM.addPass(
@@ -2184,7 +2192,7 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel 
Level,
 
   FunctionPassManager MainFPM;
   MainFPM.addPass(createFunctionToLoopPassAdaptor(
-      LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap,
+      LICMPass(*PTO.LicmMssaOptCap, *PTO.LicmMssaNoAccForPromotionCap,
                /*AllowSpeculation=*/true),
       /*USeMemorySSA=*/true));
 
@@ -2231,8 +2239,8 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel 
Level,
 
   invokePeepholeEPCallbacks(MainFPM, Level);
   MainFPM.addPass(JumpThreadingPass());
-  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(MainFPM),
-                                                
PTO.EagerlyInvalidateAnalyses));
+  MPM.addPass(createModuleToFunctionPassAdaptor(
+      std::move(MainFPM), *PTO.EagerlyInvalidateAnalyses));
 
   // Lower type metadata and the type.test intrinsic. This pass supports
   // clang's control flow integrity mechanisms (-fsanitize=cfi*) and needs
@@ -2281,7 +2289,7 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel 
Level,
   // Now that we have optimized the program, discard unreachable functions.
   MPM.addPass(GlobalDCEPass(/*InLTOPostLink=*/true));
 
-  if (PTO.MergeFunctions)
+  if (*PTO.MergeFunctions)
     MPM.addPass(MergeFunctionsPass());
 
   MPM.addPass(RelLookupTableConverterPass());
@@ -2361,7 +2369,7 @@ PassBuilder::buildO0DefaultPipeline(OptimizationLevel 
Level,
   MPM.addPass(AlwaysInlinerPass(
       /*InsertLifetimeIntrinsics=*/false));
 
-  if (PTO.MergeFunctions)
+  if (*PTO.MergeFunctions)
     MPM.addPass(MergeFunctionsPass());
 
   if (Opts.enable_matrix)
diff --git a/llvm/lib/Passes/RunCodeGen.cpp b/llvm/lib/Passes/RunCodeGen.cpp
index 67aecdb6f5494c..cdb8fcd900b901 100644
--- a/llvm/lib/Passes/RunCodeGen.cpp
+++ b/llvm/lib/Passes/RunCodeGen.cpp
@@ -65,8 +65,7 @@ static Error runCodeGenPipelineNewPM(TargetMachine &TM, 
Module &M,
   Opt.DisableVerify = DisableVerify;
   MachineModuleInfo MMI(&TM);
   PassInstrumentationCallbacks PIC;
-  const auto &LibraryOptions = M.getContext().getLibraryOptions();
-  PipelineTuningOptions PTOptions(&LibraryOptions);
+  PipelineTuningOptions PTOptions;
   PassBuilder PB(M.getContext(), &TM, PTOptions, std::nullopt, &PIC, VFS);
   PB.registerModuleAnalyses(MAM);
   PB.registerCGSCCAnalyses(CGAM);
diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp 
b/llvm/lib/Transforms/Scalar/LICM.cpp
index df0f7eda307d31..beacb150e56287 100644
--- a/llvm/lib/Transforms/Scalar/LICM.cpp
+++ b/llvm/lib/Transforms/Scalar/LICM.cpp
@@ -117,15 +117,13 @@ STATISTIC(NumBOAssociationsHoisted, "Number of invariant 
BinaryOp expressions "
                                     "reassociated and hoisted out of the 
loop");
 
 unsigned
-llvm::getLicmMssaOptCap(const cl::LibraryOptionsContext *LibraryOptions) {
-  return cl::LibraryOptionsContext::get<ScalarOptions>(LibraryOptions)
-      .licm_mssa_optimization_cap;
+llvm::getLicmMssaOptCap(const cl::LibraryOptionsContext &LibraryOptions) {
+  return LibraryOptions.get<ScalarOptions>().licm_mssa_optimization_cap;
 }
 
 unsigned llvm::getLicmMssaNoAccForPromotionCap(
-    const cl::LibraryOptionsContext *LibraryOptions) {
-  return cl::LibraryOptionsContext::get<ScalarOptions>(LibraryOptions)
-      .licm_mssa_max_acc_promotion;
+    const cl::LibraryOptionsContext &LibraryOptions) {
+  return LibraryOptions.get<ScalarOptions>().licm_mssa_max_acc_promotion;
 }
 
 static bool inSubLoop(BasicBlock *BB, Loop *CurLoop, LoopInfo *LI);
diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp 
b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
index d21de774096345..a68cd506eecfe3 100644
--- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
@@ -75,9 +75,8 @@ using namespace llvm;
 #define DEBUG_TYPE "loop-unroll"
 
 bool llvm::getForgetSCEVInLoopUnroll(
-    const cl::LibraryOptionsContext *LibraryOptions) {
-  return cl::LibraryOptionsContext::get<ScalarOptions>(LibraryOptions)
-      .forget_scev_loop_unroll;
+    const cl::LibraryOptionsContext &LibraryOptions) {
+  return LibraryOptions.get<ScalarOptions>().forget_scev_loop_unroll;
 }
 
 /// A magic value for use with the Threshold parameter to indicate
diff --git a/llvm/tools/gold/gold-plugin.cpp b/llvm/tools/gold/gold-plugin.cpp
index 17bdac650512cf..844314f9d2a765 100644
--- a/llvm/tools/gold/gold-plugin.cpp
+++ b/llvm/tools/gold/gold-plugin.cpp
@@ -902,7 +902,6 @@ createLTO(const cl::LibraryOptionsContext &LibraryOptions,
   Conf.CGOptLevel = *CGOptLevelOrNone;
   Conf.DisableVerify = options::DisableVerify;
   Conf.OptLevel = options::OptLevel;
-  Conf.PTO = PipelineTuningOptions(&LibraryOptions);
   Conf.PTO.LoopVectorization = options::OptLevel > 1;
   Conf.PTO.SLPVectorization = options::OptLevel > 1;
   Conf.PTO.MergeFunctions = options::merge_functions;
diff --git a/llvm/tools/llvm-lto2/llvm-lto2.cpp 
b/llvm/tools/llvm-lto2/llvm-lto2.cpp
index 8cf21ef909b740..8179d51220595f 100644
--- a/llvm/tools/llvm-lto2/llvm-lto2.cpp
+++ b/llvm/tools/llvm-lto2/llvm-lto2.cpp
@@ -346,7 +346,6 @@ static int run(int argc, char **argv) {
 
   Config Conf;
   Conf.LibraryOptions = &LibraryOptions;
-  Conf.PTO = PipelineTuningOptions(&LibraryOptions);
   if (TimeTrace) {
     Conf.TimeTraceEnabled = TimeTrace;
     Conf.TimeTraceGranularity = TimeTraceGranularity;
diff --git a/llvm/tools/opt/NewPMDriver.cpp b/llvm/tools/opt/NewPMDriver.cpp
index 22899f4eb8ccbb..6803851ae880a3 100644
--- a/llvm/tools/opt/NewPMDriver.cpp
+++ b/llvm/tools/opt/NewPMDriver.cpp
@@ -473,7 +473,7 @@ bool llvm::runPassPipeline(
     Debugify.registerCallbacks(PIC, MAM);
   }
 
-  PipelineTuningOptions PTO(&M.getContext().getLibraryOptions());
+  PipelineTuningOptions PTO;
   // LoopUnrolling defaults on to true and DisableLoopUnrolling is initialized
   // to false above so we shouldn't necessarily need to check whether or not 
the
   // option has been enabled.
diff --git a/llvm/utils/gn/secondary/llvm/lib/DTLTO/BUILD.gn 
b/llvm/utils/gn/secondary/llvm/lib/DTLTO/BUILD.gn
index c3d31f1a9b2853..9effa168803e67 100644
--- a/llvm/utils/gn/secondary/llvm/lib/DTLTO/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/lib/DTLTO/BUILD.gn
@@ -3,6 +3,7 @@ static_library("DTLTO") {
   deps = [
     "//llvm/lib/IR",
     "//llvm/lib/LTO",
+    "//llvm/lib/Passes",
     "//llvm/lib/Support",
   ]
   sources = [
diff --git a/mlir/lib/ExecutionEngine/OptUtils.cpp 
b/mlir/lib/ExecutionEngine/OptUtils.cpp
index 2e2f36a35c1afc..e657366086e232 100644
--- a/mlir/lib/ExecutionEngine/OptUtils.cpp
+++ b/mlir/lib/ExecutionEngine/OptUtils.cpp
@@ -60,7 +60,7 @@ mlir::makeOptimizingTransformer(unsigned optLevel, unsigned 
sizeLevel,
     CGSCCAnalysisManager cgam;
     ModuleAnalysisManager mam;
 
-    PipelineTuningOptions tuningOptions(&m->getContext().getLibraryOptions());
+    PipelineTuningOptions tuningOptions;
     tuningOptions.LoopUnrolling = true;
     tuningOptions.LoopInterleaving = true;
     tuningOptions.LoopVectorization = true;
diff --git a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel 
b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
index 8ab950157e5e2a..4ff41b67343638 100644
--- a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
@@ -4674,6 +4674,7 @@ cc_library(
         ":Core",
         ":LTO",
         ":Object",
+        ":Passes",
         ":Support",
     ],
 )

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to