diff options
Diffstat (limited to 'lib/CodeGen/CodeGenAction.cpp')
-rw-r--r-- | lib/CodeGen/CodeGenAction.cpp | 54 |
1 files changed, 33 insertions, 21 deletions
diff --git a/lib/CodeGen/CodeGenAction.cpp b/lib/CodeGen/CodeGenAction.cpp index 6ca69d63cdce7..7ca55070d4a0f 100644 --- a/lib/CodeGen/CodeGenAction.cpp +++ b/lib/CodeGen/CodeGenAction.cpp @@ -126,7 +126,7 @@ namespace clang { Gen(CreateLLVMCodeGen(Diags, InFile, HeaderSearchOpts, PPOpts, CodeGenOpts, C, CoverageInfo)), LinkModules(std::move(LinkModules)) { - llvm::TimePassesIsEnabled = TimePasses; + FrontendTimesIsEnabled = TimePasses; } llvm::Module *getModule() const { return Gen->GetModule(); } std::unique_ptr<llvm::Module> takeModule() { @@ -144,12 +144,12 @@ namespace clang { Context = &Ctx; - if (llvm::TimePassesIsEnabled) + if (FrontendTimesIsEnabled) LLVMIRGeneration.startTimer(); Gen->Initialize(Ctx); - if (llvm::TimePassesIsEnabled) + if (FrontendTimesIsEnabled) LLVMIRGeneration.stopTimer(); } @@ -159,7 +159,7 @@ namespace clang { "LLVM IR generation of declaration"); // Recurse. - if (llvm::TimePassesIsEnabled) { + if (FrontendTimesIsEnabled) { LLVMIRGenerationRefCount += 1; if (LLVMIRGenerationRefCount == 1) LLVMIRGeneration.startTimer(); @@ -167,7 +167,7 @@ namespace clang { Gen->HandleTopLevelDecl(D); - if (llvm::TimePassesIsEnabled) { + if (FrontendTimesIsEnabled) { LLVMIRGenerationRefCount -= 1; if (LLVMIRGenerationRefCount == 0) LLVMIRGeneration.stopTimer(); @@ -180,12 +180,12 @@ namespace clang { PrettyStackTraceDecl CrashInfo(D, SourceLocation(), Context->getSourceManager(), "LLVM IR generation of inline function"); - if (llvm::TimePassesIsEnabled) + if (FrontendTimesIsEnabled) LLVMIRGeneration.startTimer(); Gen->HandleInlineFunctionDefinition(D); - if (llvm::TimePassesIsEnabled) + if (FrontendTimesIsEnabled) LLVMIRGeneration.stopTimer(); } @@ -227,7 +227,7 @@ namespace clang { void HandleTranslationUnit(ASTContext &C) override { { PrettyStackTraceString CrashInfo("Per-file LLVM IR generation"); - if (llvm::TimePassesIsEnabled) { + if (FrontendTimesIsEnabled) { LLVMIRGenerationRefCount += 1; if (LLVMIRGenerationRefCount == 1) LLVMIRGeneration.startTimer(); @@ -235,13 +235,13 @@ namespace clang { Gen->HandleTranslationUnit(C); - if (llvm::TimePassesIsEnabled) { + if (FrontendTimesIsEnabled) { LLVMIRGenerationRefCount -= 1; if (LLVMIRGenerationRefCount == 0) LLVMIRGeneration.stopTimer(); } - IRGenFinished = true; + IRGenFinished = true; } // Silently ignore if we weren't initialized for some reason. @@ -341,17 +341,17 @@ namespace clang { SourceLocation LocCookie); void DiagnosticHandlerImpl(const llvm::DiagnosticInfo &DI); - /// \brief Specialized handler for InlineAsm diagnostic. + /// Specialized handler for InlineAsm diagnostic. /// \return True if the diagnostic has been successfully reported, false /// otherwise. bool InlineAsmDiagHandler(const llvm::DiagnosticInfoInlineAsm &D); - /// \brief Specialized handler for StackSize diagnostic. + /// Specialized handler for StackSize diagnostic. /// \return True if the diagnostic has been successfully reported, false /// otherwise. bool StackSizeDiagHandler(const llvm::DiagnosticInfoStackSize &D); - /// \brief Specialized handler for unsupported backend feature diagnostic. + /// Specialized handler for unsupported backend feature diagnostic. void UnsupportedDiagHandler(const llvm::DiagnosticInfoUnsupported &D); - /// \brief Specialized handlers for optimization remarks. + /// Specialized handlers for optimization remarks. /// Note that these handlers only accept remarks and they always handle /// them. void EmitOptimizationMessage(const llvm::DiagnosticInfoOptimizationBase &D, @@ -697,7 +697,7 @@ void BackendConsumer::OptimizationFailureHandler( EmitOptimizationMessage(D, diag::warn_fe_backend_optimization_failure); } -/// \brief This function is invoked when the backend needs +/// This function is invoked when the backend needs /// to report something to the user. void BackendConsumer::DiagnosticHandlerImpl(const DiagnosticInfo &DI) { unsigned DiagID = diag::err_fe_inline_asm; @@ -846,7 +846,10 @@ GetOutputStream(CompilerInstance &CI, StringRef InFile, BackendAction Action) { std::unique_ptr<ASTConsumer> CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { BackendAction BA = static_cast<BackendAction>(Act); - std::unique_ptr<raw_pwrite_stream> OS = GetOutputStream(CI, InFile, BA); + std::unique_ptr<raw_pwrite_stream> OS = CI.takeOutputStream(); + if (!OS) + OS = GetOutputStream(CI, InFile, BA); + if (BA != Backend_EmitNothing && !OS) return nullptr; @@ -947,12 +950,21 @@ std::unique_ptr<llvm::Module> CodeGenAction::loadModule(MemoryBufferRef MBRef) { return {}; }; - Expected<llvm::BitcodeModule> BMOrErr = FindThinLTOModule(MBRef); - if (!BMOrErr) - return DiagErrors(BMOrErr.takeError()); - + Expected<std::vector<BitcodeModule>> BMsOrErr = getBitcodeModuleList(MBRef); + if (!BMsOrErr) + return DiagErrors(BMsOrErr.takeError()); + BitcodeModule *Bm = FindThinLTOModule(*BMsOrErr); + // We have nothing to do if the file contains no ThinLTO module. This is + // possible if ThinLTO compilation was not able to split module. Content of + // the file was already processed by indexing and will be passed to the + // linker using merged object file. + if (!Bm) { + auto M = llvm::make_unique<llvm::Module>("empty", *VMContext); + M->setTargetTriple(CI.getTargetOpts().Triple); + return M; + } Expected<std::unique_ptr<llvm::Module>> MOrErr = - BMOrErr->parseModule(*VMContext); + Bm->parseModule(*VMContext); if (!MOrErr) return DiagErrors(MOrErr.takeError()); return std::move(*MOrErr); |