r292970 - IRGen: Factor out function clang::FindThinLTOModule. NFCI.
Peter Collingbourne via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 24 11:54:38 PST 2017
Author: pcc
Date: Tue Jan 24 13:54:37 2017
New Revision: 292970
URL: http://llvm.org/viewvc/llvm-project?rev=292970&view=rev
Log:
IRGen: Factor out function clang::FindThinLTOModule. NFCI.
Modified:
cfe/trunk/include/clang/CodeGen/BackendUtil.h
cfe/trunk/lib/CodeGen/BackendUtil.cpp
Modified: cfe/trunk/include/clang/CodeGen/BackendUtil.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/CodeGen/BackendUtil.h?rev=292970&r1=292969&r2=292970&view=diff
==============================================================================
--- cfe/trunk/include/clang/CodeGen/BackendUtil.h (original)
+++ cfe/trunk/include/clang/CodeGen/BackendUtil.h Tue Jan 24 13:54:37 2017
@@ -15,6 +15,8 @@
#include <memory>
namespace llvm {
+ class BitcodeModule;
+ template <typename T> 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<llvm::BitcodeModule>
+ FindThinLTOModule(llvm::MemoryBufferRef MBRef);
}
#endif
Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=292970&r1=292969&r2=292970&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Tue Jan 24 13:54:37 2017
@@ -862,6 +862,23 @@ void EmitAssemblyHelper::EmitAssemblyWit
}
}
+Expected<BitcodeModule> clang::FindThinLTOModule(MemoryBufferRef MBRef) {
+ Expected<std::vector<BitcodeModule>> 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<bool> HasSummary = BM.hasSummary();
+ if (HasSummary && *HasSummary)
+ return BM;
+ }
+
+ return make_error<StringError>("Could not find module summary",
+ inconvertibleErrorCode());
+}
+
static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M,
std::unique_ptr<raw_pwrite_stream> OS,
std::string SampleProfile) {
@@ -899,32 +916,15 @@ static void runThinLTOBackend(ModuleSumm
return;
}
- Expected<std::vector<BitcodeModule>> BMsOrErr =
- getBitcodeModuleList(**MBOrErr);
- if (!BMsOrErr) {
- handleAllErrors(BMsOrErr.takeError(), [&](ErrorInfoBase &EIB) {
+ Expected<BitcodeModule> 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<bool> 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));
}
More information about the cfe-commits
mailing list