r293209 - IRGen: When loading the main module in the distributed ThinLTO backend, look for the module containing the summary.

Peter Collingbourne via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 26 13:09:48 PST 2017


Author: pcc
Date: Thu Jan 26 15:09:48 2017
New Revision: 293209

URL: http://llvm.org/viewvc/llvm-project?rev=293209&view=rev
Log:
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

Added:
    cfe/trunk/test/CodeGen/thinlto-multi-module.ll
Modified:
    cfe/trunk/lib/CodeGen/CodeGenAction.cpp
    cfe/trunk/test/CMakeLists.txt

Modified: cfe/trunk/lib/CodeGen/CodeGenAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenAction.cpp?rev=293209&r1=293208&r2=293209&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenAction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenAction.cpp Thu Jan 26 15:09:48 2017
@@ -860,10 +860,31 @@ std::unique_ptr<llvm::Module> CodeGenAct
   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;

Modified: cfe/trunk/test/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CMakeLists.txt?rev=293209&r1=293208&r2=293209&view=diff
==============================================================================
--- cfe/trunk/test/CMakeLists.txt (original)
+++ cfe/trunk/test/CMakeLists.txt Thu Jan 26 15:09:48 2017
@@ -86,6 +86,7 @@ if( NOT CLANG_BUILT_STANDALONE )
     FileCheck count not
     llc
     llvm-bcanalyzer
+    llvm-cat
     llvm-dis
     llvm-nm
     llvm-objdump

Added: cfe/trunk/test/CodeGen/thinlto-multi-module.ll
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/thinlto-multi-module.ll?rev=293209&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/thinlto-multi-module.ll (added)
+++ cfe/trunk/test/CodeGen/thinlto-multi-module.ll Thu Jan 26 15:09:48 2017
@@ -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
+}




More information about the cfe-commits mailing list