r347887 - [ThinLTO] Allow importing of multiple symbols with same GUID

Teresa Johnson via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 29 09:03:00 PST 2018


Author: tejohnson
Date: Thu Nov 29 09:02:59 2018
New Revision: 347887

URL: http://llvm.org/viewvc/llvm-project?rev=347887&view=rev
Log:
[ThinLTO] Allow importing of multiple symbols with same GUID

Summary:
The is the clang side of the fix in D55047, to handle the case where
two different modules have local variables with the same GUID because
they had the same source file name at compilation time. Allow multiple
symbols with the same GUID to be imported, and test that this case works
with the distributed backend path.

Depends on D55047.

Reviewers: evgeny777

Subscribers: mehdi_amini, inglorion, eraman, steven_wu, dexonsmith, cfe-commits

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

Added:
    cfe/trunk/test/CodeGen/Inputs/thinlto_backend_local_name_conflict1.ll
    cfe/trunk/test/CodeGen/Inputs/thinlto_backend_local_name_conflict2.ll
    cfe/trunk/test/CodeGen/thinlto_backend_local_name_conflict.ll
Modified:
    cfe/trunk/lib/CodeGen/BackendUtil.cpp

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=347887&r1=347886&r2=347887&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Thu Nov 29 09:02:59 2018
@@ -1155,15 +1155,14 @@ static void runThinLTOBackend(ModuleSumm
       continue;
 
     auto GUID = GlobalList.first;
-    assert(GlobalList.second.SummaryList.size() == 1 &&
-           "Expected individual combined index to have one summary per GUID");
-    auto &Summary = GlobalList.second.SummaryList[0];
-    // Skip the summaries for the importing module. These are included to
-    // e.g. record required linkage changes.
-    if (Summary->modulePath() == M->getModuleIdentifier())
-      continue;
-    // Add an entry to provoke importing by thinBackend.
-    ImportList[Summary->modulePath()].insert(GUID);
+    for (auto &Summary : GlobalList.second.SummaryList) {
+      // Skip the summaries for the importing module. These are included to
+      // e.g. record required linkage changes.
+      if (Summary->modulePath() == M->getModuleIdentifier())
+        continue;
+      // Add an entry to provoke importing by thinBackend.
+      ImportList[Summary->modulePath()].insert(GUID);
+    }
   }
 
   std::vector<std::unique_ptr<llvm::MemoryBuffer>> OwnedImports;

Added: cfe/trunk/test/CodeGen/Inputs/thinlto_backend_local_name_conflict1.ll
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/Inputs/thinlto_backend_local_name_conflict1.ll?rev=347887&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/Inputs/thinlto_backend_local_name_conflict1.ll (added)
+++ cfe/trunk/test/CodeGen/Inputs/thinlto_backend_local_name_conflict1.ll Thu Nov 29 09:02:59 2018
@@ -0,0 +1,13 @@
+; ModuleID = 'local_name_conflict_var.o'
+source_filename = "local_name_conflict_var.c"
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at baz = internal global i32 10, align 4
+
+; Function Attrs: noinline nounwind uwtable
+define i32 @a() {
+entry:
+  %0 = load i32, i32* @baz, align 4
+  ret i32 %0
+}

Added: cfe/trunk/test/CodeGen/Inputs/thinlto_backend_local_name_conflict2.ll
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/Inputs/thinlto_backend_local_name_conflict2.ll?rev=347887&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/Inputs/thinlto_backend_local_name_conflict2.ll (added)
+++ cfe/trunk/test/CodeGen/Inputs/thinlto_backend_local_name_conflict2.ll Thu Nov 29 09:02:59 2018
@@ -0,0 +1,13 @@
+; ModuleID = 'local_name_conflict_var.o'
+source_filename = "local_name_conflict_var.c"
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at baz = internal global i32 10, align 4
+
+; Function Attrs: noinline nounwind uwtable
+define i32 @b() {
+entry:
+  %0 = load i32, i32* @baz, align 4
+  ret i32 %0
+}

Added: cfe/trunk/test/CodeGen/thinlto_backend_local_name_conflict.ll
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/thinlto_backend_local_name_conflict.ll?rev=347887&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/thinlto_backend_local_name_conflict.ll (added)
+++ cfe/trunk/test/CodeGen/thinlto_backend_local_name_conflict.ll Thu Nov 29 09:02:59 2018
@@ -0,0 +1,34 @@
+; Test handling when two files with the same source file name contain
+; static read only variables with the same name (which will have the same GUID
+; in the combined index).
+
+; Do setup work for all below tests: generate bitcode and combined index
+; RUN: opt -module-summary -module-hash %s -o %t.bc
+; RUN: opt -module-summary -module-hash %p/Inputs/thinlto_backend_local_name_conflict1.ll -o %t2.bc
+; RUN: opt -module-summary -module-hash %p/Inputs/thinlto_backend_local_name_conflict2.ll -o %t3.bc
+; RUN: llvm-lto -thinlto-action=thinlink -o %t4.bc %t.bc %t2.bc %t3.bc
+; RUN: llvm-lto -thinlto-action=distributedindexes -exported-symbol=main -thinlto-index=%t4.bc %t.bc
+
+; This module will import a() and b() which should cause the read only copy
+; of baz from each of those modules to be imported. Check that the both are
+; imported as local copies.
+; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t4.o -x ir %t.bc -c -fthinlto-index=%t.bc.thinlto.bc -save-temps=obj
+; RUN: llvm-dis %t.s.3.import.bc -o - | FileCheck --check-prefix=IMPORT %s
+; IMPORT: @baz.llvm.{{.*}} = internal global i32 10
+; IMPORT: @baz.llvm.{{.*}} = internal global i32 10
+
+; ModuleID = 'local_name_conflict_var_main.o'
+source_filename = "local_name_conflict_var_main.c"
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; Function Attrs: noinline nounwind uwtable
+define i32 @main() {
+entry:
+  %call1 = call i32 (...) @a()
+  %call2 = call i32 (...) @b()
+  ret i32 0
+}
+
+declare i32 @a(...)
+declare i32 @b(...)




More information about the cfe-commits mailing list