[PATCH] D25345: [ThinLTO] Handle empty summaries during internalization
Teresa Johnson via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 6 13:12:44 PDT 2016
tejohnson created this revision.
tejohnson added a reviewer: mehdi_amini.
tejohnson added a subscriber: llvm-commits.
Fix a problem I discovered when testing a fix for PR30610. The
callback MustPreserveGV in llvm::thinLTOInternalizeModule will assert if
there is no summary for a GV. We were handling this in the LTO API by
guarding the invocation of thinLTOInternalizeModule, but it was exposed
by llvm-lto which uses the legacy libLTO interface. Moved the guard into
thinLTOInternalizeModule and add a test.
https://reviews.llvm.org/D25345
Files:
lib/LTO/LTOBackend.cpp
lib/Transforms/IPO/FunctionImport.cpp
test/Transforms/FunctionImport/Inputs/inlineasm.ll
test/Transforms/FunctionImport/inlineasm.ll
Index: test/Transforms/FunctionImport/inlineasm.ll
===================================================================
--- test/Transforms/FunctionImport/inlineasm.ll
+++ test/Transforms/FunctionImport/inlineasm.ll
@@ -3,11 +3,16 @@
; RUN: opt -module-summary %p/Inputs/inlineasm.ll -o %t2.bc
; RUN: llvm-lto -thinlto -o %t3 %t.bc %t2.bc
+; RUN: llvm-lto2 -o %t3 %t.bc %t2.bc -r=%t.bc,main,plx -r=%t.bc,foo,l -r=%t2.bc,foo,pl
+
; Attempt the import now, ensure below that file containing inline assembly
; is not imported from. Otherwise we would need to promote its local variable
; used in the inline assembly, which would not see the rename.
; RUN: opt -function-import -summary-file %t3.thinlto.bc %t.bc -S 2>&1 | FileCheck %s --check-prefix=CHECK
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
define i32 @main() #0 {
entry:
%f = alloca i64, align 8
Index: test/Transforms/FunctionImport/Inputs/inlineasm.ll
===================================================================
--- test/Transforms/FunctionImport/Inputs/inlineasm.ll
+++ test/Transforms/FunctionImport/Inputs/inlineasm.ll
@@ -1,3 +1,6 @@
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
@myvar = internal constant i8 1, align 1
@llvm.used = appending global [1 x i8*] [i8* @myvar], section "llvm.metadata"
Index: lib/Transforms/IPO/FunctionImport.cpp
===================================================================
--- lib/Transforms/IPO/FunctionImport.cpp
+++ lib/Transforms/IPO/FunctionImport.cpp
@@ -547,6 +547,14 @@
/// Run internalization on \p TheModule based on symmary analysis.
void llvm::thinLTOInternalizeModule(Module &TheModule,
const GVSummaryMapTy &DefinedGlobals) {
+ // Skip this if there are no GV summaries. Either there are no
+ // defined GVs to internalize, or we had an empty summary (e.g.
+ // due to inline or module-level assembly that prevents us from
+ // being able to rename local references). If we don't bail out here
+ // then we would get an assert below in the MustPreserveGV callback.
+ if (DefinedGlobals.empty())
+ return;
+
// Parse inline ASM and collect the list of symbols that are not defined in
// the current module.
StringSet<> AsmUndefinedRefs;
Index: lib/LTO/LTOBackend.cpp
===================================================================
--- lib/LTO/LTOBackend.cpp
+++ lib/LTO/LTOBackend.cpp
@@ -342,8 +342,7 @@
if (Conf.PostPromoteModuleHook && !Conf.PostPromoteModuleHook(Task, Mod))
return Error();
- if (!DefinedGlobals.empty())
- thinLTOInternalizeModule(Mod, DefinedGlobals);
+ thinLTOInternalizeModule(Mod, DefinedGlobals);
if (Conf.PostInternalizeModuleHook &&
!Conf.PostInternalizeModuleHook(Task, Mod))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25345.73842.patch
Type: text/x-patch
Size: 2859 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161006/2ca32f9c/attachment.bin>
More information about the llvm-commits
mailing list