summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2017-01-26 21:09:48 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2017-01-26 21:09:48 +0000
commitf5d1712189a2c4858425cf35f8ed597645af48cc (patch)
treeff87e9d9438847c52bc177735616403d29ca9c1d /clang
parentb0d96d327e09d0ac13b34078e7413709f4815b2d (diff)
downloadbcm5719-llvm-f5d1712189a2c4858425cf35f8ed597645af48cc.tar.gz
bcm5719-llvm-f5d1712189a2c4858425cf35f8ed597645af48cc.zip
IRGen: When loading the main module in the distributed ThinLTO backend, look for the module containing the summary.
Differential Revision: https://reviews.llvm.org/D29067 llvm-svn: 293209
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/CodeGen/CodeGenAction.cpp25
-rw-r--r--clang/test/CMakeLists.txt1
-rw-r--r--clang/test/CodeGen/thinlto-multi-module.ll20
3 files changed, 44 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp
index 27b0d0b673f..3828c5e1701 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -860,10 +860,31 @@ std::unique_ptr<llvm::Module> CodeGenAction::loadModule(MemoryBufferRef MBRef) {
SourceManager &SM = CI.getSourceManager();
// For ThinLTO backend invocations, ensure that the context
- // merges types based on ODR identifiers.
- if (!CI.getCodeGenOpts().ThinLTOIndexFile.empty())
+ // merges types based on ODR identifiers. We also need to read
+ // the correct module out of a multi-module bitcode file.
+ if (!CI.getCodeGenOpts().ThinLTOIndexFile.empty()) {
VMContext->enableDebugTypeODRUniquing();
+ auto DiagErrors = [&](Error E) -> std::unique_ptr<llvm::Module> {
+ unsigned DiagID =
+ CI.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, "%0");
+ handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
+ CI.getDiagnostics().Report(DiagID) << EIB.message();
+ });
+ return {};
+ };
+
+ Expected<llvm::BitcodeModule> BMOrErr = FindThinLTOModule(MBRef);
+ if (!BMOrErr)
+ return DiagErrors(BMOrErr.takeError());
+
+ Expected<std::unique_ptr<llvm::Module>> MOrErr =
+ BMOrErr->parseModule(*VMContext);
+ if (!MOrErr)
+ return DiagErrors(MOrErr.takeError());
+ return std::move(*MOrErr);
+ }
+
llvm::SMDiagnostic Err;
if (std::unique_ptr<llvm::Module> M = parseIR(MBRef, Err, *VMContext))
return M;
diff --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt
index 050addcb4fd..0fd8f57f92a 100644
--- a/clang/test/CMakeLists.txt
+++ b/clang/test/CMakeLists.txt
@@ -86,6 +86,7 @@ if( NOT CLANG_BUILT_STANDALONE )
FileCheck count not
llc
llvm-bcanalyzer
+ llvm-cat
llvm-dis
llvm-nm
llvm-objdump
diff --git a/clang/test/CodeGen/thinlto-multi-module.ll b/clang/test/CodeGen/thinlto-multi-module.ll
new file mode 100644
index 00000000000..072c47379b4
--- /dev/null
+++ b/clang/test/CodeGen/thinlto-multi-module.ll
@@ -0,0 +1,20 @@
+; RUN: opt -module-summary -o %t1.o %s
+; RUN: llvm-lto -thinlto -o %t %t1.o
+
+; RUN: opt -o %t2.o %S/Inputs/thinlto_backend.ll
+; RUN: llvm-cat -b -o %t1cat.o %t1.o %t2.o
+; RUN: cp %t1cat.o %t1.o
+; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t3.o -x ir %t1.o -c -fthinlto-index=%t.thinlto.bc
+; RUN: llvm-nm %t3.o | FileCheck --check-prefix=CHECK-OBJ %s
+; CHECK-OBJ: T f1
+; CHECK-OBJ: U f2
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+declare void @f2()
+
+define void @f1() {
+ call void @f2()
+ ret void
+}
OpenPOWER on IntegriCloud