From 6dd1315cf0cfa87c2ace2e7263ba505c4b38df3d Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 8 Jan 2025 22:05:54 -0800 Subject: [PATCH] [clang] Simplify BackendConsumer after #69371 --- clang/lib/CodeGen/BackendConsumer.h | 16 +++------- clang/lib/CodeGen/CodeGenAction.cpp | 47 ++++++++--------------------- 2 files changed, 16 insertions(+), 47 deletions(-) diff --git a/clang/lib/CodeGen/BackendConsumer.h b/clang/lib/CodeGen/BackendConsumer.h index 5284e8bc0ea5b3..d932a78f469b95 100644 --- a/clang/lib/CodeGen/BackendConsumer.h +++ b/clang/lib/CodeGen/BackendConsumer.h @@ -72,18 +72,10 @@ class BackendConsumer : public ASTConsumer { public: BackendConsumer(const CompilerInstance &CI, BackendAction Action, IntrusiveRefCntPtr VFS, - const std::string &InFile, - SmallVector LinkModules, - std::unique_ptr 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 VFS, - llvm::Module *Module, SmallVector LinkModules, - llvm::LLVMContext &C); + llvm::LLVMContext &C, SmallVector LinkModules, + StringRef InFile, std::unique_ptr OS, + CoverageSourceInfo *CoverageInfo, + llvm::Module *CurLinkModule = nullptr); llvm::Module *getModule() const; std::unique_ptr takeModule(); diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index 07b50571fddbe7..f63cb9b082d5bf 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -105,14 +105,12 @@ static void reportOptRecordError(Error E, DiagnosticsEngine &Diags, }); } -BackendConsumer::BackendConsumer(const CompilerInstance &CI, - BackendAction Action, - IntrusiveRefCntPtr VFS, - const std::string &InFile, - SmallVector LinkModules, - std::unique_ptr OS, - LLVMContext &C, - CoverageSourceInfo *CoverageInfo) +BackendConsumer::BackendConsumer( + const CompilerInstance &CI, BackendAction Action, + IntrusiveRefCntPtr VFS, LLVMContext &C, + SmallVector LinkModules, StringRef InFile, + std::unique_ptr 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), @@ -120,29 +118,7 @@ BackendConsumer::BackendConsumer(const CompilerInstance &CI, 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 VFS, - llvm::Module *Module, - SmallVector 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; @@ -1008,8 +984,8 @@ CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { CI.getPreprocessor()); std::unique_ptr 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 @@ -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))