summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2017-01-06 23:38:41 +0000
committerTeresa Johnson <tejohnson@google.com>2017-01-06 23:38:41 +0000
commit9006d5265136429e81eb9310f2c91892fded06d3 (patch)
tree2037ac7a1153fa2a287ecaad07066213b2b4231f
parentcffeb54fc989c348b7d1f74c8808edd366cf02ce (diff)
downloadbcm5719-llvm-9006d5265136429e81eb9310f2c91892fded06d3.tar.gz
bcm5719-llvm-9006d5265136429e81eb9310f2c91892fded06d3.zip
[ThinLTO] Handle conflicting local names gracefully
Summary: r285871 introduced an assert that was overly aggressive in the case of a same-named local in different same-named files (in different directories), where the source name and therefore the GUID ended up the same because the files were compiled in their own directory without any leading path. Change the handling in the promotion logic to get the summary for the version in that module. This also exposed an issue where we are not always importing the right copy, which is a performance not correctness issue (because the renaming is based on the module hash which must be different, see the bug report for details). I will fix that as a follow-on. Fixes PR31561. Reviewers: mehdi_amini Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D28411 llvm-svn: 291304
-rw-r--r--llvm/lib/Transforms/Utils/FunctionImportUtils.cpp15
-rw-r--r--llvm/test/ThinLTO/X86/Inputs/local_name_conflict1.ll17
-rw-r--r--llvm/test/ThinLTO/X86/Inputs/local_name_conflict2.ll17
-rw-r--r--llvm/test/ThinLTO/X86/local_name_conflict.ll29
4 files changed, 72 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp b/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
index 678d02e05d4..9844190ef84 100644
--- a/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
+++ b/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
@@ -67,12 +67,15 @@ bool FunctionImportGlobalProcessing::shouldPromoteLocalToGlobal(
return true;
}
- // When exporting, consult the index.
- auto Summaries = ImportIndex.findGlobalValueSummaryList(SGV->getGUID());
- assert(Summaries != ImportIndex.end() &&
- "Missing summary for global value when exporting");
- assert(Summaries->second.size() == 1 && "Local has more than one summary");
- auto Linkage = Summaries->second.front()->linkage();
+ // When exporting, consult the index. We can have more than one local
+ // with the same GUID, in the case of same-named locals in different but
+ // same-named source files that were compiled in their respective directories
+ // (so the source file name and resulting GUID is the same). Find the one
+ // in this module.
+ auto Summary = ImportIndex.findSummaryInModule(
+ SGV->getGUID(), SGV->getParent()->getModuleIdentifier());
+ assert(Summary && "Missing summary for global value when exporting");
+ auto Linkage = Summary->linkage();
if (!GlobalValue::isLocalLinkage(Linkage)) {
assert(!isNonRenamableLocal(*SGV) &&
"Attempting to promote non-renamable local");
diff --git a/llvm/test/ThinLTO/X86/Inputs/local_name_conflict1.ll b/llvm/test/ThinLTO/X86/Inputs/local_name_conflict1.ll
new file mode 100644
index 00000000000..2ef7bdd3eb7
--- /dev/null
+++ b/llvm/test/ThinLTO/X86/Inputs/local_name_conflict1.ll
@@ -0,0 +1,17 @@
+; ModuleID = 'local_name_conflict.o'
+source_filename = "local_name_conflict.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 @a() {
+entry:
+ %call = call i32 @foo()
+ ret i32 %call
+}
+
+; Function Attrs: noinline nounwind uwtable
+define internal i32 @foo() {
+entry:
+ ret i32 1
+}
diff --git a/llvm/test/ThinLTO/X86/Inputs/local_name_conflict2.ll b/llvm/test/ThinLTO/X86/Inputs/local_name_conflict2.ll
new file mode 100644
index 00000000000..a8c20a29228
--- /dev/null
+++ b/llvm/test/ThinLTO/X86/Inputs/local_name_conflict2.ll
@@ -0,0 +1,17 @@
+; ModuleID = 'local_name_conflict.o'
+source_filename = "local_name_conflict.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 @b() {
+entry:
+ %call = call i32 @foo()
+ ret i32 %call
+}
+
+; Function Attrs: noinline nounwind uwtable
+define internal i32 @foo() {
+entry:
+ ret i32 2
+}
diff --git a/llvm/test/ThinLTO/X86/local_name_conflict.ll b/llvm/test/ThinLTO/X86/local_name_conflict.ll
new file mode 100644
index 00000000000..9cbb32ecf21
--- /dev/null
+++ b/llvm/test/ThinLTO/X86/local_name_conflict.ll
@@ -0,0 +1,29 @@
+; 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/local_name_conflict1.ll -o %t2.bc
+; RUN: opt -module-summary -module-hash %p/Inputs/local_name_conflict2.ll -o %t3.bc
+; RUN: llvm-lto -thinlto-action=thinlink -o %t4.bc %t.bc %t2.bc %t3.bc
+
+; Make sure foo is promoted and renamed without complaint in both
+; Inputs/local_name_conflict1.ll and Inputs/local_name_conflict2.ll
+; FIXME: Once the importer is fixed to import the correct copy of the
+; local, we should be able to verify that via an import action.
+; RUN: llvm-lto -thinlto-action=promote %t2.bc -thinlto-index=%t4.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=EXPORTSTATIC
+; RUN: llvm-lto -thinlto-action=promote %t3.bc -thinlto-index=%t4.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=EXPORTSTATIC
+; EXPORTSTATIC: define hidden i32 @foo.llvm.
+
+; ModuleID = 'local_name_conflict_main.o'
+source_filename = "local_name_conflict_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:
+ %retval = alloca i32, align 4
+ store i32 0, i32* %retval, align 4
+ %call = call i32 (...) @b()
+ ret i32 %call
+}
+
+declare i32 @b(...)
OpenPOWER on IntegriCloud