[flang-commits] [clang] [flang] [llvm] [Passes] Make runCodeGenPipeline take raw_pwrite_stream for DwoOS (PR #235339)
via flang-commits
flang-commits at lists.llvm.org
Sat Oct 24 11:32:20 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-driver
Author: Aiden Grossman (boomanaiden154)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/235339.diff
4 Files Affected:
- (modified) clang/lib/CodeGen/BackendUtil.cpp (+2-1)
- (modified) flang/lib/Frontend/FrontendActions.cpp (+2-2)
- (modified) llvm/include/llvm/Passes/RunCodeGen.h (+3-3)
- (modified) llvm/lib/Passes/RunCodeGen.cpp (+6-9)
``````````diff
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) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/235339
More information about the flang-commits
mailing list