[flang-commits] [flang] 25385ba - [Passes] Make runCodeGenPipeline take raw_pwrite_stream for DwoOS (#235339)
via flang-commits
flang-commits at lists.llvm.org
Sat Oct 24 15:25:52 PDT 2026
Author: Aiden Grossman
Date: 2026-10-24T22:25:45Z
New Revision: 25385baacc635c7159644f612dcee0cd3ff88451
URL: https://github.com/llvm/llvm-project/commit/25385baacc635c7159644f612dcee0cd3ff88451
DIFF: https://github.com/llvm/llvm-project/commit/25385baacc635c7159644f612dcee0cd3ff88451.diff
LOG: [Passes] Make runCodeGenPipeline take raw_pwrite_stream for DwoOS (#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.
Added:
Modified:
clang/lib/CodeGen/BackendUtil.cpp
flang/lib/Frontend/FrontendActions.cpp
llvm/include/llvm/Passes/RunCodeGen.h
llvm/lib/Passes/RunCodeGen.cpp
Removed:
################################################################################
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..67aecdb6f5494c 100644
--- a/llvm/lib/Passes/RunCodeGen.cpp
+++ b/llvm/lib/Passes/RunCodeGen.cpp
@@ -20,7 +20,6 @@
#include "llvm/Passes/PassBuilder.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/Error.h"
-#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/CGPassBuilderOption.h"
@@ -28,7 +27,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 +43,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 +52,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 +77,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 +87,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