From: Peter Collingbourne Date: Tue, 24 Jan 2017 19:54:37 +0000 (+0000) Subject: IRGen: Factor out function clang::FindThinLTOModule. NFCI. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=88a607f9fee70cb5a73c80942c316b1435ff41c5;p=clang IRGen: Factor out function clang::FindThinLTOModule. NFCI. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@292970 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/CodeGen/BackendUtil.h b/include/clang/CodeGen/BackendUtil.h index c6abc6e3f5..bb105cb533 100644 --- a/include/clang/CodeGen/BackendUtil.h +++ b/include/clang/CodeGen/BackendUtil.h @@ -15,6 +15,8 @@ #include namespace llvm { + class BitcodeModule; + template class Expected; class Module; class MemoryBufferRef; } @@ -44,6 +46,9 @@ namespace clang { void EmbedBitcode(llvm::Module *M, const CodeGenOptions &CGOpts, llvm::MemoryBufferRef Buf); + + llvm::Expected + FindThinLTOModule(llvm::MemoryBufferRef MBRef); } #endif diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index 893729b272..77c8b1eca9 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -862,6 +862,23 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager( } } +Expected clang::FindThinLTOModule(MemoryBufferRef MBRef) { + Expected> BMsOrErr = getBitcodeModuleList(MBRef); + if (!BMsOrErr) + return BMsOrErr.takeError(); + + // The bitcode file may contain multiple modules, we want the one with a + // summary. + for (BitcodeModule &BM : *BMsOrErr) { + Expected HasSummary = BM.hasSummary(); + if (HasSummary && *HasSummary) + return BM; + } + + return make_error("Could not find module summary", + inconvertibleErrorCode()); +} + static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M, std::unique_ptr OS, std::string SampleProfile) { @@ -899,32 +916,15 @@ static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M, return; } - Expected> BMsOrErr = - getBitcodeModuleList(**MBOrErr); - if (!BMsOrErr) { - handleAllErrors(BMsOrErr.takeError(), [&](ErrorInfoBase &EIB) { + Expected BMOrErr = FindThinLTOModule(**MBOrErr); + if (!BMOrErr) { + handleAllErrors(BMOrErr.takeError(), [&](ErrorInfoBase &EIB) { errs() << "Error loading imported file '" << I.first() << "': " << EIB.message() << '\n'; }); return; } - - // The bitcode file may contain multiple modules, we want the one with a - // summary. - bool FoundModule = false; - for (BitcodeModule &BM : *BMsOrErr) { - Expected HasSummary = BM.hasSummary(); - if (HasSummary && *HasSummary) { - ModuleMap.insert({I.first(), BM}); - FoundModule = true; - break; - } - } - if (!FoundModule) { - errs() << "Error loading imported file '" << I.first() - << "': Could not find module summary\n"; - return; - } + ModuleMap.insert({I.first(), *BMOrErr}); OwnedImports.push_back(std::move(*MBOrErr)); }