[llvm] r313229 - Reland r313157, "ThinLTO: Correctly follow aliasee references when dead stripping." which was reverted in r313222.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 13 22:02:59 PDT 2017
Author: pcc
Date: Wed Sep 13 22:02:59 2017
New Revision: 313229
URL: http://llvm.org/viewvc/llvm-project?rev=313229&view=rev
Log:
Reland r313157, "ThinLTO: Correctly follow aliasee references when dead stripping." which was reverted in r313222.
This reland includes a fix for the LowerTypeTests pass so that it
looks past aliases when determining which type identifiers are live.
Differential Revision: https://reviews.llvm.org/D37842
Added:
llvm/trunk/test/LTO/Resolution/X86/Inputs/dead-strip-alias.ll
llvm/trunk/test/LTO/Resolution/X86/dead-strip-alias.ll
Modified:
llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h
llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp
llvm/trunk/lib/Transforms/IPO/LowerTypeTests.cpp
llvm/trunk/test/LTO/Resolution/X86/lowertypetests.ll
Modified: llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h?rev=313229&r1=313228&r2=313229&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h (original)
+++ llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h Wed Sep 13 22:02:59 2017
@@ -235,6 +235,10 @@ public:
/// Return the list of values referenced by this global value definition.
ArrayRef<ValueInfo> refs() const { return RefEdgeList; }
+ /// If this is an alias summary, returns the summary of the aliased object (a
+ /// global variable or function), otherwise returns itself.
+ GlobalValueSummary *getBaseObject();
+
friend class ModuleSummaryIndex;
friend void computeDeadSymbols(class ModuleSummaryIndex &,
const DenseSet<GlobalValue::GUID> &);
@@ -266,6 +270,12 @@ public:
}
};
+inline GlobalValueSummary *GlobalValueSummary::getBaseObject() {
+ if (auto *AS = dyn_cast<AliasSummary>(this))
+ return &AS->getAliasee();
+ return this;
+}
+
/// \brief Function summary information to aid decisions and implementation of
/// importing.
class FunctionSummary : public GlobalValueSummary {
Modified: llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp?rev=313229&r1=313228&r2=313229&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp Wed Sep 13 22:02:59 2017
@@ -324,10 +324,8 @@ static void ComputeImportForModule(
DEBUG(dbgs() << "Ignores Dead GUID: " << GVSummary.first << "\n");
continue;
}
- auto *Summary = GVSummary.second;
- if (auto *AS = dyn_cast<AliasSummary>(Summary))
- Summary = &AS->getAliasee();
- auto *FuncSummary = dyn_cast<FunctionSummary>(Summary);
+ auto *FuncSummary =
+ dyn_cast<FunctionSummary>(GVSummary.second->getBaseObject());
if (!FuncSummary)
// Skip import for global variables
continue;
@@ -488,17 +486,12 @@ void llvm::computeDeadSymbols(
while (!Worklist.empty()) {
auto VI = Worklist.pop_back_val();
for (auto &Summary : VI.getSummaryList()) {
- for (auto Ref : Summary->refs())
+ GlobalValueSummary *Base = Summary->getBaseObject();
+ for (auto Ref : Base->refs())
visit(Ref);
- if (auto *FS = dyn_cast<FunctionSummary>(Summary.get()))
+ if (auto *FS = dyn_cast<FunctionSummary>(Base))
for (auto Call : FS->calls())
visit(Call.first);
- if (auto *AS = dyn_cast<AliasSummary>(Summary.get())) {
- auto AliaseeGUID = AS->getAliasee().getOriginalName();
- ValueInfo AliaseeVI = Index.getValueInfo(AliaseeGUID);
- if (AliaseeVI)
- visit(AliaseeVI);
- }
}
}
Index.setWithGlobalValueDeadStripping();
Modified: llvm/trunk/lib/Transforms/IPO/LowerTypeTests.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/LowerTypeTests.cpp?rev=313229&r1=313228&r2=313229&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/LowerTypeTests.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/LowerTypeTests.cpp Wed Sep 13 22:02:59 2017
@@ -1703,12 +1703,12 @@ bool LowerTypeTestsModule::lower() {
for (auto &P : *ExportSummary) {
for (auto &S : P.second.SummaryList) {
- auto *FS = dyn_cast<FunctionSummary>(S.get());
- if (!FS || !ExportSummary->isGlobalValueLive(FS))
+ if (!ExportSummary->isGlobalValueLive(S.get()))
continue;
- for (GlobalValue::GUID G : FS->type_tests())
- for (Metadata *MD : MetadataByGUID[G])
- AddTypeIdUse(MD).IsExported = true;
+ if (auto *FS = dyn_cast<FunctionSummary>(S->getBaseObject()))
+ for (GlobalValue::GUID G : FS->type_tests())
+ for (Metadata *MD : MetadataByGUID[G])
+ AddTypeIdUse(MD).IsExported = true;
}
}
}
Added: llvm/trunk/test/LTO/Resolution/X86/Inputs/dead-strip-alias.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/Resolution/X86/Inputs/dead-strip-alias.ll?rev=313229&view=auto
==============================================================================
--- llvm/trunk/test/LTO/Resolution/X86/Inputs/dead-strip-alias.ll (added)
+++ llvm/trunk/test/LTO/Resolution/X86/Inputs/dead-strip-alias.ll Wed Sep 13 22:02:59 2017
@@ -0,0 +1,4 @@
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at external = global i8 42
Added: llvm/trunk/test/LTO/Resolution/X86/dead-strip-alias.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/Resolution/X86/dead-strip-alias.ll?rev=313229&view=auto
==============================================================================
--- llvm/trunk/test/LTO/Resolution/X86/dead-strip-alias.ll (added)
+++ llvm/trunk/test/LTO/Resolution/X86/dead-strip-alias.ll Wed Sep 13 22:02:59 2017
@@ -0,0 +1,20 @@
+; RUN: opt -module-summary -o %t %s
+; RUN: opt -module-summary -o %t2 %S/Inputs/dead-strip-alias.ll
+; RUN: llvm-lto2 run %t -r %t,main,px -r %t,alias,p -r %t,external, \
+; RUN: %t2 -r %t2,external,p \
+; RUN: -save-temps -o %t3
+; RUN: llvm-nm %t3.1 | FileCheck %s
+
+; CHECK: D external
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at alias = alias i8*, i8** @internal
+
+ at internal = internal global i8* @external
+ at external = external global i8
+
+define i8** @main() {
+ ret i8** @alias
+}
Modified: llvm/trunk/test/LTO/Resolution/X86/lowertypetests.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/Resolution/X86/lowertypetests.ll?rev=313229&r1=313228&r2=313229&view=diff
==============================================================================
--- llvm/trunk/test/LTO/Resolution/X86/lowertypetests.ll (original)
+++ llvm/trunk/test/LTO/Resolution/X86/lowertypetests.ll Wed Sep 13 22:02:59 2017
@@ -1,21 +1,32 @@
; RUN: opt -thinlto-bc -o %t %s
-; RUN: llvm-lto2 run -r %t,f,plx -r %t,foo,lx -r %t,foo,plx -o %t1 %t
+; RUN: llvm-lto2 run -r %t,f,plx -r %t,g_alias,plx -r %t,foo,lx -r %t,foo,plx -r %t,bar,lx -r %t,bar,plx -o %t1 %t
; RUN: llvm-nm %t1.0 | FileCheck --check-prefix=MERGED %s
; RUN: llvm-nm %t1.1 | FileCheck %s
+; MERGED: R __typeid_bar_global_addr
; MERGED: R __typeid_foo_global_addr
+; CHECK: U __typeid_bar_global_addr
; CHECK: U __typeid_foo_global_addr
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
@foo = global i32 0, !type !0
+ at bar = global i32 0, !type !1
define i1 @f(i8* %ptr) {
%p = call i1 @llvm.type.test(i8* %ptr, metadata !"foo")
ret i1 %p
}
+ at g_alias = alias i1 (i8*), i1 (i8*)* @g
+
+define internal i1 @g(i8* %ptr) {
+ %p = call i1 @llvm.type.test(i8* %ptr, metadata !"bar")
+ ret i1 %p
+}
+
declare i1 @llvm.type.test(i8* %ptr, metadata %typeid) nounwind readnone
!0 = !{i32 0, !"foo"}
+!1 = !{i32 0, !"bar"}
More information about the llvm-commits
mailing list