diff options
Diffstat (limited to 'clang/lib/CodeGen/BackendUtil.cpp')
-rw-r--r-- | clang/lib/CodeGen/BackendUtil.cpp | 75 |
1 files changed, 36 insertions, 39 deletions
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 37ef2bd..29478f68 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -129,8 +129,8 @@ std::string getDefaultProfileGenName() { } class EmitAssemblyHelper { + CompilerInstance &CI; DiagnosticsEngine &Diags; - const HeaderSearchOptions &HSOpts; const CodeGenOptions &CodeGenOpts; const clang::TargetOptions &TargetOpts; const LangOptions &LangOpts; @@ -203,15 +203,11 @@ class EmitAssemblyHelper { } public: - EmitAssemblyHelper(DiagnosticsEngine &_Diags, - const HeaderSearchOptions &HeaderSearchOpts, - const CodeGenOptions &CGOpts, - const clang::TargetOptions &TOpts, - const LangOptions &LOpts, llvm::Module *M, + EmitAssemblyHelper(CompilerInstance &CI, llvm::Module *M, IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) - : Diags(_Diags), HSOpts(HeaderSearchOpts), CodeGenOpts(CGOpts), - TargetOpts(TOpts), LangOpts(LOpts), TheModule(M), VFS(std::move(VFS)), - CodeGenerationTime("codegen", "Code Generation Time"), + : CI(CI), Diags(CI.getDiagnostics()), CodeGenOpts(CI.getCodeGenOpts()), + TargetOpts(CI.getTargetOpts()), LangOpts(CI.getLangOpts()), + TheModule(M), VFS(std::move(VFS)), TargetTriple(TheModule->getTargetTriple()) {} ~EmitAssemblyHelper() { @@ -222,7 +218,7 @@ public: std::unique_ptr<TargetMachine> TM; // Emit output using the new pass manager for the optimization pipeline. - void EmitAssembly(BackendAction Action, std::unique_ptr<raw_pwrite_stream> OS, + void emitAssembly(BackendAction Action, std::unique_ptr<raw_pwrite_stream> OS, BackendConsumer *BC); }; } // namespace @@ -351,12 +347,13 @@ static std::string flattenClangCommandLine(ArrayRef<std::string> Args, return FlatCmdLine; } -static bool initTargetOptions(DiagnosticsEngine &Diags, - llvm::TargetOptions &Options, - const CodeGenOptions &CodeGenOpts, - const clang::TargetOptions &TargetOpts, - const LangOptions &LangOpts, - const HeaderSearchOptions &HSOpts) { +static bool initTargetOptions(const CompilerInstance &CI, + DiagnosticsEngine &Diags, + llvm::TargetOptions &Options) { + const auto &CodeGenOpts = CI.getCodeGenOpts(); + const auto &TargetOpts = CI.getTargetOpts(); + const auto &LangOpts = CI.getLangOpts(); + const auto &HSOpts = CI.getHeaderSearchOpts(); switch (LangOpts.getThreadModel()) { case LangOptions::ThreadModelKind::POSIX: Options.ThreadModel = llvm::ThreadModel::POSIX; @@ -600,8 +597,7 @@ void EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) { CodeGenOptLevel OptLevel = *OptLevelOrNone; llvm::TargetOptions Options; - if (!initTargetOptions(Diags, Options, CodeGenOpts, TargetOpts, LangOpts, - HSOpts)) + if (!initTargetOptions(CI, Diags, Options)) return; TM.reset(TheTarget->createTargetMachine(Triple, TargetOpts.CPU, FeaturesStr, Options, RM, CM, OptLevel)); @@ -1207,7 +1203,7 @@ void EmitAssemblyHelper::RunCodegenPipeline( } } -void EmitAssemblyHelper::EmitAssembly(BackendAction Action, +void EmitAssemblyHelper::emitAssembly(BackendAction Action, std::unique_ptr<raw_pwrite_stream> OS, BackendConsumer *BC) { TimeRegion Region(CodeGenOpts.TimePasses ? &CodeGenerationTime : nullptr); @@ -1234,13 +1230,14 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action, DwoOS->keep(); } -static void runThinLTOBackend( - DiagnosticsEngine &Diags, ModuleSummaryIndex *CombinedIndex, - llvm::Module *M, const HeaderSearchOptions &HeaderOpts, - const CodeGenOptions &CGOpts, const clang::TargetOptions &TOpts, - const LangOptions &LOpts, std::unique_ptr<raw_pwrite_stream> OS, - std::string SampleProfile, std::string ProfileRemapping, - BackendAction Action) { +static void +runThinLTOBackend(CompilerInstance &CI, ModuleSummaryIndex *CombinedIndex, + llvm::Module *M, std::unique_ptr<raw_pwrite_stream> OS, + std::string SampleProfile, std::string ProfileRemapping, + BackendAction Action) { + DiagnosticsEngine &Diags = CI.getDiagnostics(); + const auto &CGOpts = CI.getCodeGenOpts(); + const auto &TOpts = CI.getTargetOpts(); DenseMap<StringRef, DenseMap<GlobalValue::GUID, GlobalValueSummary *>> ModuleToDefinedGVSummaries; CombinedIndex->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries); @@ -1278,7 +1275,7 @@ static void runThinLTOBackend( assert(OptLevelOrNone && "Invalid optimization level!"); Conf.CGOptLevel = *OptLevelOrNone; Conf.OptLevel = CGOpts.OptimizationLevel; - initTargetOptions(Diags, Conf.Options, CGOpts, TOpts, LOpts, HeaderOpts); + initTargetOptions(CI, Diags, Conf.Options); Conf.SampleProfile = std::move(SampleProfile); Conf.PTO.LoopUnrolling = CGOpts.UnrollLoops; // For historical reasons, loop interleaving is set to mirror setting for loop @@ -1341,14 +1338,14 @@ static void runThinLTOBackend( } } -void clang::EmitBackendOutput( - DiagnosticsEngine &Diags, const HeaderSearchOptions &HeaderOpts, - const CodeGenOptions &CGOpts, const clang::TargetOptions &TOpts, - const LangOptions &LOpts, StringRef TDesc, llvm::Module *M, - BackendAction Action, IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS, - std::unique_ptr<raw_pwrite_stream> OS, BackendConsumer *BC) { - +void clang::emitBackendOutput(CompilerInstance &CI, StringRef TDesc, + llvm::Module *M, BackendAction Action, + IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS, + std::unique_ptr<raw_pwrite_stream> OS, + BackendConsumer *BC) { llvm::TimeTraceScope TimeScope("Backend"); + DiagnosticsEngine &Diags = CI.getDiagnostics(); + const auto &CGOpts = CI.getCodeGenOpts(); std::unique_ptr<llvm::Module> EmptyModule; if (!CGOpts.ThinLTOIndexFile.empty()) { @@ -1371,9 +1368,9 @@ void clang::EmitBackendOutput( // of an error). if (CombinedIndex) { if (!CombinedIndex->skipModuleByDistributedBackend()) { - runThinLTOBackend(Diags, CombinedIndex.get(), M, HeaderOpts, CGOpts, - TOpts, LOpts, std::move(OS), CGOpts.SampleProfileFile, - CGOpts.ProfileRemappingFile, Action); + runThinLTOBackend(CI, CombinedIndex.get(), M, std::move(OS), + CGOpts.SampleProfileFile, CGOpts.ProfileRemappingFile, + Action); return; } // Distributed indexing detected that nothing from the module is needed @@ -1388,8 +1385,8 @@ void clang::EmitBackendOutput( } } - EmitAssemblyHelper AsmHelper(Diags, HeaderOpts, CGOpts, TOpts, LOpts, M, VFS); - AsmHelper.EmitAssembly(Action, std::move(OS), BC); + EmitAssemblyHelper AsmHelper(CI, M, VFS); + AsmHelper.emitAssembly(Action, std::move(OS), BC); // Verify clang's TargetInfo DataLayout against the LLVM TargetMachine's // DataLayout. |