Skip to content
Snippets Groups Projects
Commit cfc17356 authored by Peter Collingbourne's avatar Peter Collingbourne
Browse files

LTO: Add support for multi-module bitcode files.

Differential Revision: https://reviews.llvm.org/D27313

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@289621 91177308-0d34-0410-b5e6-96231b3b80d8
parent 993e3aa6
No related branches found
No related tags found
No related merge requests found
......@@ -753,7 +753,7 @@ static void runThinLTOBackend(const CodeGenOptions &CGOpts, Module *M,
ImportList);
std::vector<std::unique_ptr<llvm::MemoryBuffer>> OwnedImports;
MapVector<llvm::StringRef, llvm::MemoryBufferRef> ModuleMap;
MapVector<llvm::StringRef, llvm::BitcodeModule> ModuleMap;
for (auto &I : ImportList) {
ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> MBOrErr =
......@@ -763,7 +763,34 @@ static void runThinLTOBackend(const CodeGenOptions &CGOpts, Module *M,
<< "': " << MBOrErr.getError().message() << "\n";
return;
}
ModuleMap[I.first()] = (*MBOrErr)->getMemBufferRef();
Expected<std::vector<BitcodeModule>> BMsOrErr =
getBitcodeModuleList(**MBOrErr);
if (!BMsOrErr) {
handleAllErrors(BMsOrErr.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;
}
OwnedImports.push_back(std::move(*MBOrErr));
}
auto AddStream = [&](size_t Task) {
......
......@@ -9,8 +9,8 @@
; CHECK-WARNING: error: invalid argument '-fthinlto-index={{.*}}' only allowed with '-x ir'
; Ensure we get expected error for missing index file
; RUN: %clang -O2 -o %t3.o -x ir %t1.o -c -fthinlto-index=bad.thinlto.bc 2>&1 | FileCheck %s -check-prefix=CHECK-ERROR
; CHECK-ERROR: Error loading index file 'bad.thinlto.bc'
; RUN: %clang -O2 -o %t4.o -x ir %t1.o -c -fthinlto-index=bad.thinlto.bc 2>&1 | FileCheck %s -check-prefix=CHECK-ERROR1
; CHECK-ERROR1: Error loading index file 'bad.thinlto.bc'
; Ensure f2 was imported
; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t3.o -x ir %t1.o -c -fthinlto-index=%t.thinlto.bc
......@@ -18,6 +18,11 @@
; CHECK-OBJ: T f1
; CHECK-OBJ-NOT: U f2
; Ensure we get expected error for input files without summaries
; RUN: opt -o %t2.o %s
; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t3.o -x ir %t1.o -c -fthinlto-index=%t.thinlto.bc
; CHECK-ERROR2: Error loading imported file '{{.*}}': Could not find module summary
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment