[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
Schrodinger ZHU Yifan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Jul 2 10:30:25 PDT 2022
SchrodingerZhu updated this revision to Diff 441891.
SchrodingerZhu added a comment.
fix liveness of resolvers
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D129009/new/
https://reviews.llvm.org/D129009
Files:
llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/lib/Transforms/IPO/FunctionImport.cpp
llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
Index: llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
===================================================================
--- /dev/null
+++ llvm/test/LTO/Resolution/X86/alias-indirect-function-lto.ll
@@ -0,0 +1,22 @@
+; RUN: opt -module-summary -o %t.bc %s
+; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,pl -r %t.bc,bar,pl -r %t.bc,baz,pl -o %t2
+; RUN: llvm-nm %t2.1 | FileCheck %s
+; CHECK: i bar
+; CHECK: i baz
+; CHECK: i foo
+; CHECK: t foo_resolver
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver
+
+define internal i32 (i32)* @foo_resolver() {
+entry:
+ ret i32 (i32)* null
+}
+
+ at bar = alias i32 (i32), i32 (i32)* @foo
+
+ at baz = weak alias i32 (i32), i32 (i32)* @foo
+; no crash
Index: llvm/lib/Transforms/IPO/FunctionImport.cpp
===================================================================
--- llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -1147,6 +1147,12 @@
// Declare a callback for the internalize pass that will ask for every
// candidate GlobalValue if it can be internalized or not.
auto MustPreserveGV = [&](const GlobalValue &GV) -> bool {
+ // It maybe the case that the symbol is aliasing an ifunc where
+ // the summary is not available.
+ if (isa<GlobalAlias>(&GV) &&
+ isa<GlobalIFunc>(dyn_cast<GlobalAlias>(&GV)->getAliasee()))
+ return true;
+
// Lookup the linkage recorded in the summaries during global analysis.
auto GS = DefinedGlobals.find(GV.getGUID());
if (GS == DefinedGlobals.end()) {
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===================================================================
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,9 @@
for (const GlobalAlias &A : M.aliases()) {
auto *Aliasee = A.getAliaseeObject();
- if (!Aliasee->hasName())
- // Nameless function don't have an entry in the summary, skip it.
+ // IFunc function and Nameless function don't have an entry in the
+ // summary, skip it.
+ if (!Aliasee->hasName() || isa<GlobalIFunc>(Aliasee))
continue;
auto AliasId = VE.getValueID(&A);
auto AliaseeId = VE.getValueID(Aliasee);
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===================================================================
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -646,15 +646,20 @@
Index.addGlobalValueSummary(V, std::move(GVarSummary));
}
-static void
-computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A,
- DenseSet<GlobalValue::GUID> &CantBePromoted) {
+static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A,
+ DenseSet<GlobalValue::GUID> &CantBePromoted) {
+ auto *Aliasee = A.getAliaseeObject();
+
+ // Skip summary for indirect function aliases as summary for aliasee will not
+ // be emitted.
+ if (isa<GlobalIFunc>(Aliasee))
+ return;
+
bool NonRenamableLocal = isNonRenamableLocal(A);
GlobalValueSummary::GVFlags Flags(
A.getLinkage(), A.getVisibility(), NonRenamableLocal,
/* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
auto AS = std::make_unique<AliasSummary>(Flags);
- auto *Aliasee = A.getAliaseeObject();
auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
assert(AliaseeVI && "Alias expects aliasee summary to be available");
assert(AliaseeVI.getSummaryList().size() == 1 &&
@@ -811,6 +816,10 @@
for (const GlobalAlias &A : M.aliases())
computeAliasSummary(Index, A, CantBePromoted);
+ // Iterate through ifuncs, set their resolvers all alive.
+ for (const GlobalIFunc &I : M.ifuncs())
+ Index.getGlobalValueSummary(*I.getResolverFunction())->setLive(true);
+
for (auto *V : LocalsUsed) {
auto *Summary = Index.getGlobalValueSummary(*V);
assert(Summary && "Missing summary for global value");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129009.441891.patch
Type: text/x-patch
Size: 4116 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220702/a686df6c/attachment.bin>
More information about the cfe-commits
mailing list