[flang-commits] [flang] [Flang][Driver] Emit module summary for Full LTO (PR #164302)

Tarun Prabhu via flang-commits flang-commits at lists.llvm.org
Tue Oct 21 13:47:44 PDT 2025


================
@@ -1019,24 +1019,40 @@ void CodeGenAction::runOptimizationPipeline(llvm::raw_pwrite_stream &os) {
 
   // Create the pass manager.
   llvm::ModulePassManager mpm;
-  if (opts.PrepareForFatLTO) {
-    // The module summary should be emitted by default for regular LTO
-    // except for ld64 targets.
-    bool emitSummary = opts.PrepareForThinLTO || opts.PrepareForFullLTO ||
-                       triple.getVendor() != llvm::Triple::Apple;
+  // The module summary should be emitted by default for regular LTO
+  // except for ld64 targets.
+  bool emitSummary = (opts.PrepareForThinLTO || opts.PrepareForFullLTO) &&
+                     (triple.getVendor() != llvm::Triple::Apple);
+  if (opts.PrepareForFatLTO)
     mpm = pb.buildFatLTODefaultPipeline(level, opts.PrepareForThinLTO,
                                         emitSummary);
-  } else if (opts.PrepareForFullLTO)
+  else if (opts.PrepareForFullLTO)
     mpm = pb.buildLTOPreLinkDefaultPipeline(level);
   else if (opts.PrepareForThinLTO)
     mpm = pb.buildThinLTOPreLinkDefaultPipeline(level);
   else
     mpm = pb.buildPerModuleDefaultPipeline(level);
 
-  if (action == BackendActionTy::Backend_EmitBC)
-    mpm.addPass(llvm::BitcodeWriterPass(os));
-  else if (action == BackendActionTy::Backend_EmitLL)
-    mpm.addPass(llvm::PrintModulePass(os));
+  if (action == BackendActionTy::Backend_EmitBC ||
+      action == BackendActionTy::Backend_EmitLL || opts.PrepareForFatLTO) {
+    if (opts.PrepareForThinLTO) {
+      // TODO: ThinLTO module summary support is yet to be enabled.
----------------
tarunprabhu wrote:

Does `-flto=thin` imply that module summaries are enabled? If so, it may be a good idea to issue a diagnostic saying that thin-lto support is incomplete. Do you intend to implement module summaries for thin-lto? If that is likely to land relatively soon, it may be ok not to emit a diagnostic.

https://github.com/llvm/llvm-project/pull/164302


More information about the flang-commits mailing list