llvm.org GIT mirror llvm / a28eeed
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313229 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Collingbourne 3 years ago
6 changed file(s) with 56 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
234234 /// Return the list of values referenced by this global value definition.
235235 ArrayRef refs() const { return RefEdgeList; }
236236
237 /// If this is an alias summary, returns the summary of the aliased object (a
238 /// global variable or function), otherwise returns itself.
239 GlobalValueSummary *getBaseObject();
240
237241 friend class ModuleSummaryIndex;
238242 friend void computeDeadSymbols(class ModuleSummaryIndex &,
239243 const DenseSet &);
264268 static_cast(this)->getAliasee());
265269 }
266270 };
271
272 inline GlobalValueSummary *GlobalValueSummary::getBaseObject() {
273 if (auto *AS = dyn_cast(this))
274 return &AS->getAliasee();
275 return this;
276 }
267277
268278 /// \brief Function summary information to aid decisions and implementation of
269279 /// importing.
323323 DEBUG(dbgs() << "Ignores Dead GUID: " << GVSummary.first << "\n");
324324 continue;
325325 }
326 auto *Summary = GVSummary.second;
327 if (auto *AS = dyn_cast(Summary))
328 Summary = &AS->getAliasee();
329 auto *FuncSummary = dyn_cast(Summary);
326 auto *FuncSummary =
327 dyn_cast(GVSummary.second->getBaseObject());
330328 if (!FuncSummary)
331329 // Skip import for global variables
332330 continue;
487485 while (!Worklist.empty()) {
488486 auto VI = Worklist.pop_back_val();
489487 for (auto &Summary : VI.getSummaryList()) {
490 for (auto Ref : Summary->refs())
488 GlobalValueSummary *Base = Summary->getBaseObject();
489 for (auto Ref : Base->refs())
491490 visit(Ref);
492 if (auto *FS = dyn_cast(Summary.get()))
491 if (auto *FS = dyn_cast(Base))
493492 for (auto Call : FS->calls())
494493 visit(Call.first);
495 if (auto *AS = dyn_cast(Summary.get())) {
496 auto AliaseeGUID = AS->getAliasee().getOriginalName();
497 ValueInfo AliaseeVI = Index.getValueInfo(AliaseeGUID);
498 if (AliaseeVI)
499 visit(AliaseeVI);
500 }
501494 }
502495 }
503496 Index.setWithGlobalValueDeadStripping();
17021702
17031703 for (auto &P : *ExportSummary) {
17041704 for (auto &S : P.second.SummaryList) {
1705 auto *FS = dyn_cast(S.get());
1706 if (!FS || !ExportSummary->isGlobalValueLive(FS))
1705 if (!ExportSummary->isGlobalValueLive(S.get()))
17071706 continue;
1708 for (GlobalValue::GUID G : FS->type_tests())
1709 for (Metadata *MD : MetadataByGUID[G])
1710 AddTypeIdUse(MD).IsExported = true;
1707 if (auto *FS = dyn_cast(S->getBaseObject()))
1708 for (GlobalValue::GUID G : FS->type_tests())
1709 for (Metadata *MD : MetadataByGUID[G])
1710 AddTypeIdUse(MD).IsExported = true;
17111711 }
17121712 }
17131713 }
0 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
1 target triple = "x86_64-unknown-linux-gnu"
2
3 @external = global i8 42
0 ; RUN: opt -module-summary -o %t %s
1 ; RUN: opt -module-summary -o %t2 %S/Inputs/dead-strip-alias.ll
2 ; RUN: llvm-lto2 run %t -r %t,main,px -r %t,alias,p -r %t,external, \
3 ; RUN: %t2 -r %t2,external,p \
4 ; RUN: -save-temps -o %t3
5 ; RUN: llvm-nm %t3.1 | FileCheck %s
6
7 ; CHECK: D external
8
9 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
10 target triple = "x86_64-unknown-linux-gnu"
11
12 @alias = alias i8*, i8** @internal
13
14 @internal = internal global i8* @external
15 @external = external global i8
16
17 define i8** @main() {
18 ret i8** @alias
19 }
0 ; RUN: opt -thinlto-bc -o %t %s
1 ; RUN: llvm-lto2 run -r %t,f,plx -r %t,foo,lx -r %t,foo,plx -o %t1 %t
1 ; 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
22 ; RUN: llvm-nm %t1.0 | FileCheck --check-prefix=MERGED %s
33 ; RUN: llvm-nm %t1.1 | FileCheck %s
44
5 ; MERGED: R __typeid_bar_global_addr
56 ; MERGED: R __typeid_foo_global_addr
7 ; CHECK: U __typeid_bar_global_addr
68 ; CHECK: U __typeid_foo_global_addr
79
810 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
911 target triple = "x86_64-unknown-linux-gnu"
1012
1113 @foo = global i32 0, !type !0
14 @bar = global i32 0, !type !1
1215
1316 define i1 @f(i8* %ptr) {
1417 %p = call i1 @llvm.type.test(i8* %ptr, metadata !"foo")
1518 ret i1 %p
1619 }
1720
21 @g_alias = alias i1 (i8*), i1 (i8*)* @g
22
23 define internal i1 @g(i8* %ptr) {
24 %p = call i1 @llvm.type.test(i8* %ptr, metadata !"bar")
25 ret i1 %p
26 }
27
1828 declare i1 @llvm.type.test(i8* %ptr, metadata %typeid) nounwind readnone
1929
2030 !0 = !{i32 0, !"foo"}
31 !1 = !{i32 0, !"bar"}