[flang-commits] [clang] [flang] [llvm] [Passes] Make runCodeGenPipeline take raw_pwrite_stream for DwoOS (PR #235339)

Aiden Grossman via flang-commits flang-commits at lists.llvm.org
Sat Oct 24 11:31:44 PDT 2026


https://github.com/boomanaiden154 created https://github.com/llvm/llvm-project/pull/235339

The std::unique_ptr reference was mostly cargo-culting from clang/flang that does not necessarily make sense for other frontends (case study right now is rustc). Change to a raw_pwrite_stream given that makes more sense internally and gives frontends more flexibility.

>From 6cad0551e4f6e7b01dfd276dc6b4eae9083ca545 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Sat, 24 Oct 2026 18:30:04 +0000
Subject: [PATCH] [Passes] Make runCodeGenPipeline take raw_pwrite_stream for
 DwoOS

The std::unique_ptr reference was mostly cargo-culting from clang/flang
that does not necessarily make sense for other frontends (case study
right now is rustc). Change to a raw_pwrite_stream given that makes more
sense internally and gives frontends more flexibility.
---
 clang/lib/CodeGen/BackendUtil.cpp      |  3 ++-
 flang/lib/Frontend/FrontendActions.cpp |  4 ++--
 llvm/include/llvm/Passes/RunCodeGen.h  |  6 +++---
 llvm/lib/Passes/RunCodeGen.cpp         | 15 ++++++---------
 4 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 8331ad64df3dff..fe1454026f569d 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1282,7 +1282,8 @@ void EmitAssemblyHelper::RunCodegenPipeline(
 
   TimeCodegenPasses([&]() {
     Error CodeGenError = runCodeGenPipeline(
-        *TM, *TheModule, *OS, DwoOS, CGFT, !CodeGenOpts.VerifyModule,
+        *TM, *TheModule, *OS, DwoOS ? &DwoOS->os() : nullptr, CGFT,
+        !CodeGenOpts.VerifyModule,
         /*DisableSimplifyLibCalls=*/false, CI.getVirtualFileSystemPtr());
     if (CodeGenError)
       Diags.Report(diag::err_fe_unable_to_interface_with_target);
diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index 8ebcafa9426aa1..9191f22b7024e8 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -937,8 +937,8 @@ static void generateMachineCodeOrAssemblyImpl(
       return;
     }
   }
-  llvm::Error codeGenError =
-      runCodeGenPipeline(tm, llvmModule, os, dwoOS, cgft);
+  llvm::Error codeGenError = runCodeGenPipeline(
+      tm, llvmModule, os, dwoOS ? &dwoOS->os() : nullptr, cgft);
   if (codeGenError) {
     unsigned diagID =
         diags.getCustomDiagID(clang::DiagnosticsEngine::Error,
diff --git a/llvm/include/llvm/Passes/RunCodeGen.h b/llvm/include/llvm/Passes/RunCodeGen.h
index 39f06746817c8f..87db2562b7acae 100644
--- a/llvm/include/llvm/Passes/RunCodeGen.h
+++ b/llvm/include/llvm/Passes/RunCodeGen.h
@@ -10,16 +10,16 @@
 #define LLVM_PASSES_RUN_CODEGEN_H
 
 #include "llvm/IR/Module.h"
-#include "llvm/Support/ToolOutputFile.h"
 #include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetMachine.h"
 
 namespace llvm {
 
 LLVM_ABI Error runCodeGenPipeline(
     TargetMachine &TM, Module &M, raw_pwrite_stream &OS,
-    std::unique_ptr<ToolOutputFile> &DwoOS, CodeGenFileType CGFT,
-    bool DisableVerify = true, bool DisableSimplifyLibCalls = false,
+    raw_pwrite_stream *DwoOS, CodeGenFileType CGFT, bool DisableVerify = true,
+    bool DisableSimplifyLibCalls = false,
     IntrusiveRefCntPtr<vfs::FileSystem> VFS = vfs::getRealFileSystem());
 
 } // namespace llvm
diff --git a/llvm/lib/Passes/RunCodeGen.cpp b/llvm/lib/Passes/RunCodeGen.cpp
index 7dd4a02c778ca6..9d47115caadbea 100644
--- a/llvm/lib/Passes/RunCodeGen.cpp
+++ b/llvm/lib/Passes/RunCodeGen.cpp
@@ -28,7 +28,7 @@ using namespace llvm;
 
 static Error runCodeGenPipelineLegacy(TargetMachine &TM, Module &M,
                                       raw_pwrite_stream &OS,
-                                      std::unique_ptr<ToolOutputFile> &DwoOS,
+                                      raw_pwrite_stream *DwoOS,
                                       CodeGenFileType CGFT, bool DisableVerify,
                                       bool DisableSimplifyLibCalls) {
   legacy::PassManager CodeGenPasses;
@@ -44,8 +44,7 @@ static Error runCodeGenPipelineLegacy(TargetMachine &TM, Module &M,
   CodeGenPasses.add(
       new RuntimeLibraryInfoWrapper(Options.MCOptions.ABIName, Options.VecLib));
 
-  if (TM.addPassesToEmitFile(CodeGenPasses, OS, DwoOS ? &DwoOS->os() : nullptr,
-                             CGFT, DisableVerify))
+  if (TM.addPassesToEmitFile(CodeGenPasses, OS, DwoOS, CGFT, DisableVerify))
     return createStringError("Failed to construct CodeGen pipeline");
   CodeGenPasses.run(M);
 
@@ -54,7 +53,7 @@ static Error runCodeGenPipelineLegacy(TargetMachine &TM, Module &M,
 
 static Error runCodeGenPipelineNewPM(TargetMachine &TM, Module &M,
                                      raw_pwrite_stream &OS,
-                                     std::unique_ptr<ToolOutputFile> &DwoOS,
+                                     raw_pwrite_stream *DwoOS,
                                      CodeGenFileType CGFT, bool DisableVerify,
                                      IntrusiveRefCntPtr<vfs::FileSystem> VFS) {
   ModulePassManager MPM;
@@ -79,9 +78,8 @@ static Error runCodeGenPipelineNewPM(TargetMachine &TM, Module &M,
 
   MAM.registerPass([&] { return MachineModuleAnalysis(MMI); });
 
-  Error BuildPipelineError =
-      TM.buildCodeGenPipeline(MPM, MAM, OS, DwoOS ? &DwoOS->os() : nullptr,
-                              CGFT, Opt, MMI.getContext(), &PIC);
+  Error BuildPipelineError = TM.buildCodeGenPipeline(
+      MPM, MAM, OS, DwoOS, CGFT, Opt, MMI.getContext(), &PIC);
   if (BuildPipelineError)
     return BuildPipelineError;
 
@@ -90,8 +88,7 @@ static Error runCodeGenPipelineNewPM(TargetMachine &TM, Module &M,
 }
 
 Error llvm::runCodeGenPipeline(TargetMachine &TM, Module &M,
-                               raw_pwrite_stream &OS,
-                               std::unique_ptr<ToolOutputFile> &DwoOS,
+                               raw_pwrite_stream &OS, raw_pwrite_stream *DwoOS,
                                CodeGenFileType CGFT, bool DisableVerify,
                                bool DisableSimplifyLibCalls,
                                IntrusiveRefCntPtr<vfs::FileSystem> VFS) {



More information about the flang-commits mailing list