Skip to content

Commit

Permalink
[clang] Simplify BackendConsumer after llvm#69371
Browse files Browse the repository at this point in the history
  • Loading branch information
MaskRay committed Jan 9, 2025
1 parent b30f9d7 commit 6dd1315
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 47 deletions.
16 changes: 4 additions & 12 deletions clang/lib/CodeGen/BackendConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,10 @@ class BackendConsumer : public ASTConsumer {
public:
BackendConsumer(const CompilerInstance &CI, BackendAction Action,
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
const std::string &InFile,
SmallVector<LinkModule, 4> LinkModules,
std::unique_ptr<raw_pwrite_stream> OS, llvm::LLVMContext &C,
CoverageSourceInfo *CoverageInfo = nullptr);

// This constructor is used in installing an empty BackendConsumer
// to use the clang diagnostic handler for IR input files. It avoids
// initializing the OS field.
BackendConsumer(const CompilerInstance &CI, BackendAction Action,
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
llvm::Module *Module, SmallVector<LinkModule, 4> LinkModules,
llvm::LLVMContext &C);
llvm::LLVMContext &C, SmallVector<LinkModule, 4> LinkModules,
StringRef InFile, std::unique_ptr<raw_pwrite_stream> OS,
CoverageSourceInfo *CoverageInfo,
llvm::Module *CurLinkModule = nullptr);

llvm::Module *getModule() const;
std::unique_ptr<llvm::Module> takeModule();
Expand Down
47 changes: 12 additions & 35 deletions clang/lib/CodeGen/CodeGenAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,44 +105,20 @@ static void reportOptRecordError(Error E, DiagnosticsEngine &Diags,
});
}

BackendConsumer::BackendConsumer(const CompilerInstance &CI,
BackendAction Action,
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
const std::string &InFile,
SmallVector<LinkModule, 4> LinkModules,
std::unique_ptr<raw_pwrite_stream> OS,
LLVMContext &C,
CoverageSourceInfo *CoverageInfo)
BackendConsumer::BackendConsumer(
const CompilerInstance &CI, BackendAction Action,
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS, LLVMContext &C,
SmallVector<LinkModule, 4> LinkModules, StringRef InFile,
std::unique_ptr<raw_pwrite_stream> OS, CoverageSourceInfo *CoverageInfo,
llvm::Module *CurLinkModule)
: Diags(CI.getDiagnostics()), HeaderSearchOpts(CI.getHeaderSearchOpts()),
CodeGenOpts(CI.getCodeGenOpts()), TargetOpts(CI.getTargetOpts()),
LangOpts(CI.getLangOpts()), AsmOutStream(std::move(OS)), FS(VFS),
LLVMIRGeneration("irgen", "LLVM IR Generation Time"), Action(Action),
Gen(CreateLLVMCodeGen(Diags, InFile, std::move(VFS),
CI.getHeaderSearchOpts(), CI.getPreprocessorOpts(),
CI.getCodeGenOpts(), C, CoverageInfo)),
LinkModules(std::move(LinkModules)) {
TimerIsEnabled = CodeGenOpts.TimePasses;
llvm::TimePassesIsEnabled = CodeGenOpts.TimePasses;
llvm::TimePassesPerRun = CodeGenOpts.TimePassesPerRun;
}

// This constructor is used in installing an empty BackendConsumer
// to use the clang diagnostic handler for IR input files. It avoids
// initializing the OS field.
BackendConsumer::BackendConsumer(const CompilerInstance &CI,
BackendAction Action,
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
llvm::Module *Module,
SmallVector<LinkModule, 4> LinkModules,
LLVMContext &C)
: Diags(CI.getDiagnostics()), HeaderSearchOpts(CI.getHeaderSearchOpts()),
CodeGenOpts(CI.getCodeGenOpts()), TargetOpts(CI.getTargetOpts()),
LangOpts(CI.getLangOpts()), FS(VFS),
LLVMIRGeneration("irgen", "LLVM IR Generation Time"), Action(Action),
Gen(CreateLLVMCodeGen(Diags, "", std::move(VFS), CI.getHeaderSearchOpts(),
CI.getPreprocessorOpts(), CI.getCodeGenOpts(), C,
nullptr)),
LinkModules(std::move(LinkModules)), CurLinkModule(Module) {
LinkModules(std::move(LinkModules)), CurLinkModule(CurLinkModule) {
TimerIsEnabled = CodeGenOpts.TimePasses;
llvm::TimePassesIsEnabled = CodeGenOpts.TimePasses;
llvm::TimePassesPerRun = CodeGenOpts.TimePassesPerRun;
Expand Down Expand Up @@ -1008,8 +984,8 @@ CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
CI.getPreprocessor());

std::unique_ptr<BackendConsumer> Result(new BackendConsumer(
CI, BA, &CI.getVirtualFileSystem(), std::string(InFile),
std::move(LinkModules), std::move(OS), *VMContext, CoverageInfo));
CI, BA, &CI.getVirtualFileSystem(), *VMContext, std::move(LinkModules),
InFile, std::move(OS), CoverageInfo));
BEConsumer = Result.get();

// Enable generating macro debug info only when debug info is not disabled and
Expand Down Expand Up @@ -1177,8 +1153,9 @@ void CodeGenAction::ExecuteAction() {

// Set clang diagnostic handler. To do this we need to create a fake
// BackendConsumer.
BackendConsumer Result(CI, BA, &CI.getVirtualFileSystem(), TheModule.get(),
std::move(LinkModules), *VMContext);
BackendConsumer Result(CI, BA, &CI.getVirtualFileSystem(), *VMContext,
std::move(LinkModules), "", nullptr, nullptr,
TheModule.get());

// Link in each pending link module.
if (!CodeGenOpts.LinkBitcodePostopt && Result.LinkInModules(&*TheModule))
Expand Down

0 comments on commit 6dd1315

Please sign in to comment.