[PATCH] D129009: [llvm.analysis] Fix LTO for aliased IFuncs.
SchrodingerZhu created this revision. Herald added subscribers: steakhal, ormris, jeroen.dobbelaere, steven_wu, hiraditya, inglorion. Herald added a project: All. SchrodingerZhu requested review of this revision. Herald added projects: clang, LLVM. Herald added subscribers: llvm-commits, cfe-commits. Signed-off-by: SchrodingerZhu Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D129009 Files: clang/test/Analysis/alias-indirect-function-lto.c llvm/lib/Analysis/ModuleSummaryAnalysis.cpp llvm/lib/Bitcode/Writer/BitcodeWriter.cpp Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp === --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -4103,8 +4103,10 @@ 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. +if (!Aliasee->hasName() || +Aliasee->getValueID() == Value::ValueTy::GlobalIFuncVal) + // IFunc function and Nameless function don't have an entry in the + // summary, skip it. 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,23 +646,26 @@ Index.addGlobalValueSummary(V, std::move(GVarSummary)); } -static void -computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, -DenseSet &CantBePromoted) { - bool NonRenamableLocal = isNonRenamableLocal(A); - GlobalValueSummary::GVFlags Flags( - A.getLinkage(), A.getVisibility(), NonRenamableLocal, - /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable()); - auto AS = std::make_unique(Flags); +static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, +DenseSet &CantBePromoted) { auto *Aliasee = A.getAliaseeObject(); - auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID()); - assert(AliaseeVI && "Alias expects aliasee summary to be available"); - assert(AliaseeVI.getSummaryList().size() == 1 && - "Expected a single entry per aliasee in per-module index"); - AS->setAliasee(AliaseeVI, AliaseeVI.getSummaryList()[0].get()); - if (NonRenamableLocal) -CantBePromoted.insert(A.getGUID()); - Index.addGlobalValueSummary(A, std::move(AS)); + // Currently, skip summary for indirect function aliases as + // summary for aliasee will not be emitted. + if (Aliasee->getValueID() != Value::ValueTy::GlobalIFuncVal) { +bool NonRenamableLocal = isNonRenamableLocal(A); +GlobalValueSummary::GVFlags Flags( +A.getLinkage(), A.getVisibility(), NonRenamableLocal, +/* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable()); +auto AS = std::make_unique(Flags); +auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID()); +assert(AliaseeVI && "Alias expects aliasee summary to be available"); +assert(AliaseeVI.getSummaryList().size() == 1 && + "Expected a single entry per aliasee in per-module index"); +AS->setAliasee(AliaseeVI, AliaseeVI.getSummaryList()[0].get()); +if (NonRenamableLocal) + CantBePromoted.insert(A.getGUID()); +Index.addGlobalValueSummary(A, std::move(AS)); + } } // Set LiveRoot flag on entries matching the given value name. Index: clang/test/Analysis/alias-indirect-function-lto.c === --- /dev/null +++ clang/test/Analysis/alias-indirect-function-lto.c @@ -0,0 +1,4 @@ +// RUN: %clang_analyze_cc1 -flto -c +void f() __attribute__((ifunc("g"))); +static void *g() { return 0; }; +void h() __attribute__((alias("f"))); \ No newline at end of file Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp === --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -4103,8 +4103,10 @@ 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. +if (!Aliasee->hasName() || +Aliasee->getValueID() == Value::ValueTy::GlobalIFuncVal) + // IFunc function and Nameless function don't have an entry in the + // summary, skip it. 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,23 +646,26 @@ Index.addGlobalValueSummary(V, std::move(GVarSummar
[PATCH] D129009: [llvm.analysis] Fix LTO for aliased IFuncs. As https://github.com/llvm/llvm-project/issues/56290 indicates, when an ifunc is aliased in LTO, clang will attempt to create an alias su
SchrodingerZhu updated this revision to Diff 441756. SchrodingerZhu retitled this revision from "[llvm.analysis] Fix LTO for aliased IFuncs." to "[llvm.analysis] Fix LTO for aliased IFuncs. As https://github.com/llvm/llvm-project/issues/56290 indicates, when an ifunc is aliased in LTO, clang will attempt to create an alias summary; however, as ifunc is not included in the module summary...". SchrodingerZhu edited the summary of this revision. SchrodingerZhu added a comment. Updating D129009: [llvm.analysis] Fix LTO for aliased IFuncs. = As https://github.com/llvm/llvm-project/issues/56290 indicates, when an ifunc is aliased in LTO, clang will attempt to create an alias summary; however, as ifunc is not included in the module summary... Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129009/new/ https://reviews.llvm.org/D129009 Files: clang/test/Analysis/alias-indirect-function-lto.c llvm/lib/Analysis/ModuleSummaryAnalysis.cpp llvm/lib/Bitcode/Writer/BitcodeWriter.cpp Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp === --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -4103,8 +4103,10 @@ 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. +if (!Aliasee->hasName() || +Aliasee->getValueID() == Value::ValueTy::GlobalIFuncVal) + // IFunc function and Nameless function don't have an entry in the + // summary, skip it. 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,23 +646,26 @@ Index.addGlobalValueSummary(V, std::move(GVarSummary)); } -static void -computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, -DenseSet &CantBePromoted) { - bool NonRenamableLocal = isNonRenamableLocal(A); - GlobalValueSummary::GVFlags Flags( - A.getLinkage(), A.getVisibility(), NonRenamableLocal, - /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable()); - auto AS = std::make_unique(Flags); +static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, +DenseSet &CantBePromoted) { auto *Aliasee = A.getAliaseeObject(); - auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID()); - assert(AliaseeVI && "Alias expects aliasee summary to be available"); - assert(AliaseeVI.getSummaryList().size() == 1 && - "Expected a single entry per aliasee in per-module index"); - AS->setAliasee(AliaseeVI, AliaseeVI.getSummaryList()[0].get()); - if (NonRenamableLocal) -CantBePromoted.insert(A.getGUID()); - Index.addGlobalValueSummary(A, std::move(AS)); + // Currently, skip summary for indirect function aliases as + // summary for aliasee will not be emitted. + if (Aliasee->getValueID() != Value::ValueTy::GlobalIFuncVal) { +bool NonRenamableLocal = isNonRenamableLocal(A); +GlobalValueSummary::GVFlags Flags( +A.getLinkage(), A.getVisibility(), NonRenamableLocal, +/* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable()); +auto AS = std::make_unique(Flags); +auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID()); +assert(AliaseeVI && "Alias expects aliasee summary to be available"); +assert(AliaseeVI.getSummaryList().size() == 1 && + "Expected a single entry per aliasee in per-module index"); +AS->setAliasee(AliaseeVI, AliaseeVI.getSummaryList()[0].get()); +if (NonRenamableLocal) + CantBePromoted.insert(A.getGUID()); +Index.addGlobalValueSummary(A, std::move(AS)); + } } // Set LiveRoot flag on entries matching the given value name. Index: clang/test/Analysis/alias-indirect-function-lto.c === --- /dev/null +++ clang/test/Analysis/alias-indirect-function-lto.c @@ -0,0 +1,4 @@ +// RUN: %clang_analyze_cc1 -flto -c +void f() __attribute__((ifunc("g"))); +static void *g() { return 0; }; +void h() __attribute__((alias("f"))); \ No newline at end of file Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp === --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -4103,8 +4103,10 @@ 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. +if (!Aliasee->hasName() || +Alia
[PATCH] D129009: [Analysis] Fix LTO for aliased IFuncs.
SchrodingerZhu updated this revision to Diff 441758. SchrodingerZhu retitled this revision from "[llvm.analysis] Fix LTO for aliased IFuncs. As https://github.com/llvm/llvm-project/issues/56290 indicates, when an ifunc is aliased in LTO, clang will attempt to create an alias summary; however, as ifunc is not included in the module summary..." to "[Analysis] Fix LTO for aliased IFuncs.". SchrodingerZhu edited the summary of this revision. SchrodingerZhu added a comment. update code area Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129009/new/ https://reviews.llvm.org/D129009 Files: clang/test/Analysis/alias-indirect-function-lto.c llvm/lib/Analysis/ModuleSummaryAnalysis.cpp llvm/lib/Bitcode/Writer/BitcodeWriter.cpp Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp === --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -4103,8 +4103,10 @@ 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. +if (!Aliasee->hasName() || +Aliasee->getValueID() == Value::ValueTy::GlobalIFuncVal) + // IFunc function and Nameless function don't have an entry in the + // summary, skip it. 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,23 +646,26 @@ Index.addGlobalValueSummary(V, std::move(GVarSummary)); } -static void -computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, -DenseSet &CantBePromoted) { - bool NonRenamableLocal = isNonRenamableLocal(A); - GlobalValueSummary::GVFlags Flags( - A.getLinkage(), A.getVisibility(), NonRenamableLocal, - /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable()); - auto AS = std::make_unique(Flags); +static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, +DenseSet &CantBePromoted) { auto *Aliasee = A.getAliaseeObject(); - auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID()); - assert(AliaseeVI && "Alias expects aliasee summary to be available"); - assert(AliaseeVI.getSummaryList().size() == 1 && - "Expected a single entry per aliasee in per-module index"); - AS->setAliasee(AliaseeVI, AliaseeVI.getSummaryList()[0].get()); - if (NonRenamableLocal) -CantBePromoted.insert(A.getGUID()); - Index.addGlobalValueSummary(A, std::move(AS)); + // Currently, skip summary for indirect function aliases as + // summary for aliasee will not be emitted. + if (Aliasee->getValueID() != Value::ValueTy::GlobalIFuncVal) { +bool NonRenamableLocal = isNonRenamableLocal(A); +GlobalValueSummary::GVFlags Flags( +A.getLinkage(), A.getVisibility(), NonRenamableLocal, +/* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable()); +auto AS = std::make_unique(Flags); +auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID()); +assert(AliaseeVI && "Alias expects aliasee summary to be available"); +assert(AliaseeVI.getSummaryList().size() == 1 && + "Expected a single entry per aliasee in per-module index"); +AS->setAliasee(AliaseeVI, AliaseeVI.getSummaryList()[0].get()); +if (NonRenamableLocal) + CantBePromoted.insert(A.getGUID()); +Index.addGlobalValueSummary(A, std::move(AS)); + } } // Set LiveRoot flag on entries matching the given value name. Index: clang/test/Analysis/alias-indirect-function-lto.c === --- /dev/null +++ clang/test/Analysis/alias-indirect-function-lto.c @@ -0,0 +1,4 @@ +// RUN: %clang_analyze_cc1 -flto -c +void f() __attribute__((ifunc("g"))); +static void *g() { return 0; }; +void h() __attribute__((alias("f"))); \ No newline at end of file Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp === --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -4103,8 +4103,10 @@ 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. +if (!Aliasee->hasName() || +Aliasee->getValueID() == Value::ValueTy::GlobalIFuncVal) + // IFunc function and Nameless function don't have an entry in the + // summary, skip it. continue; auto AliasId = VE.getValueID(&A); auto AliaseeId = VE.getValueID(Aliasee); Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
[PATCH] D129009: [Analysis][LTO] Fix LTO for aliased IFuncs.
SchrodingerZhu updated this revision to Diff 441784. SchrodingerZhu added a comment. fix integration test Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129009/new/ https://reviews.llvm.org/D129009 Files: clang/test/Analysis/alias-indirect-function-lto.c llvm/lib/Analysis/ModuleSummaryAnalysis.cpp llvm/lib/Bitcode/Writer/BitcodeWriter.cpp Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp === --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -4103,8 +4103,10 @@ 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. +if (!Aliasee->hasName() || +Aliasee->getValueID() == Value::ValueTy::GlobalIFuncVal) + // IFunc function and Nameless function don't have an entry in the + // summary, skip it. 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,23 +646,26 @@ Index.addGlobalValueSummary(V, std::move(GVarSummary)); } -static void -computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, -DenseSet &CantBePromoted) { - bool NonRenamableLocal = isNonRenamableLocal(A); - GlobalValueSummary::GVFlags Flags( - A.getLinkage(), A.getVisibility(), NonRenamableLocal, - /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable()); - auto AS = std::make_unique(Flags); +static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, +DenseSet &CantBePromoted) { auto *Aliasee = A.getAliaseeObject(); - auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID()); - assert(AliaseeVI && "Alias expects aliasee summary to be available"); - assert(AliaseeVI.getSummaryList().size() == 1 && - "Expected a single entry per aliasee in per-module index"); - AS->setAliasee(AliaseeVI, AliaseeVI.getSummaryList()[0].get()); - if (NonRenamableLocal) -CantBePromoted.insert(A.getGUID()); - Index.addGlobalValueSummary(A, std::move(AS)); + // Currently, skip summary for indirect function aliases as + // summary for aliasee will not be emitted. + if (Aliasee->getValueID() != Value::ValueTy::GlobalIFuncVal) { +bool NonRenamableLocal = isNonRenamableLocal(A); +GlobalValueSummary::GVFlags Flags( +A.getLinkage(), A.getVisibility(), NonRenamableLocal, +/* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable()); +auto AS = std::make_unique(Flags); +auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID()); +assert(AliaseeVI && "Alias expects aliasee summary to be available"); +assert(AliaseeVI.getSummaryList().size() == 1 && + "Expected a single entry per aliasee in per-module index"); +AS->setAliasee(AliaseeVI, AliaseeVI.getSummaryList()[0].get()); +if (NonRenamableLocal) + CantBePromoted.insert(A.getGUID()); +Index.addGlobalValueSummary(A, std::move(AS)); + } } // Set LiveRoot flag on entries matching the given value name. Index: clang/test/Analysis/alias-indirect-function-lto.c === --- /dev/null +++ clang/test/Analysis/alias-indirect-function-lto.c @@ -0,0 +1,5 @@ +// RUN: %clang_analyze_cc1 -flto %s +void f() __attribute__((ifunc("g"))); +static void *g() { return 0; }; +void h() __attribute__((alias("f"))); +// no crash \ No newline at end of file Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp === --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -4103,8 +4103,10 @@ 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. +if (!Aliasee->hasName() || +Aliasee->getValueID() == Value::ValueTy::GlobalIFuncVal) + // IFunc function and Nameless function don't have an entry in the + // summary, skip it. 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,23 +646,26 @@ Index.addGlobalValueSummary(V, std::move(GVarSummary)); } -static void -computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, -DenseSet &CantBePromoted) { - boo
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
SchrodingerZhu updated this revision to Diff 441819. SchrodingerZhu added a comment. address CR 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 Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp === --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -4103,8 +4103,7 @@ for (const GlobalAlias &A : M.aliases()) { auto *Aliasee = A.getAliaseeObject(); -if (!Aliasee->hasName() || -Aliasee->getValueID() == Value::ValueTy::GlobalIFuncVal) +if (!Aliasee->hasName() || isa(Aliasee)) // IFunc function and Nameless function don't have an entry in the // summary, skip it. continue; Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp === --- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp +++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp @@ -649,23 +649,24 @@ static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, DenseSet &CantBePromoted) { auto *Aliasee = A.getAliaseeObject(); - // Currently, skip summary for indirect function aliases as + // Skip summary for indirect function aliases as // summary for aliasee will not be emitted. - if (Aliasee->getValueID() != Value::ValueTy::GlobalIFuncVal) { -bool NonRenamableLocal = isNonRenamableLocal(A); -GlobalValueSummary::GVFlags Flags( -A.getLinkage(), A.getVisibility(), NonRenamableLocal, -/* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable()); -auto AS = std::make_unique(Flags); -auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID()); -assert(AliaseeVI && "Alias expects aliasee summary to be available"); -assert(AliaseeVI.getSummaryList().size() == 1 && - "Expected a single entry per aliasee in per-module index"); -AS->setAliasee(AliaseeVI, AliaseeVI.getSummaryList()[0].get()); -if (NonRenamableLocal) - CantBePromoted.insert(A.getGUID()); -Index.addGlobalValueSummary(A, std::move(AS)); + if (isa(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(Flags); + auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID()); + assert(AliaseeVI && "Alias expects aliasee summary to be available"); + assert(AliaseeVI.getSummaryList().size() == 1 && + "Expected a single entry per aliasee in per-module index"); + AS->setAliasee(AliaseeVI, AliaseeVI.getSummaryList()[0].get()); + if (NonRenamableLocal) +CantBePromoted.insert(A.getGUID()); + Index.addGlobalValueSummary(A, std::move(AS)); } // Set LiveRoot flag on entries matching the given value name. Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp === --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -4103,8 +4103,7 @@ for (const GlobalAlias &A : M.aliases()) { auto *Aliasee = A.getAliaseeObject(); -if (!Aliasee->hasName() || -Aliasee->getValueID() == Value::ValueTy::GlobalIFuncVal) +if (!Aliasee->hasName() || isa(Aliasee)) // IFunc function and Nameless function don't have an entry in the // summary, skip it. continue; Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp === --- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp +++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp @@ -649,23 +649,24 @@ static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, DenseSet &CantBePromoted) { auto *Aliasee = A.getAliaseeObject(); - // Currently, skip summary for indirect function aliases as + // Skip summary for indirect function aliases as // summary for aliasee will not be emitted. - if (Aliasee->getValueID() != Value::ValueTy::GlobalIFuncVal) { -bool NonRenamableLocal = isNonRenamableLocal(A); -GlobalValueSummary::GVFlags Flags( -A.getLinkage(), A.getVisibility(), NonRenamableLocal, -/* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable()); -auto AS = std::make_unique(Flags); -auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID()); -assert(AliaseeVI && "Alias expects aliasee summary to be available"); -assert(AliaseeVI.getSummaryList().size() == 1 && - "Expected a single entry per aliasee in per-module index"); -AS->setAliasee(AliaseeVI, AliaseeVI.getSummaryList()[0].get()); -if (NonRenamableLocal) - C
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
SchrodingerZhu updated this revision to Diff 441820. SchrodingerZhu added a comment. address CR 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 Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp === --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -4103,8 +4103,7 @@ for (const GlobalAlias &A : M.aliases()) { auto *Aliasee = A.getAliaseeObject(); -if (!Aliasee->hasName() || -Aliasee->getValueID() == Value::ValueTy::GlobalIFuncVal) +if (!Aliasee->hasName() || isa(Aliasee)) // IFunc function and Nameless function don't have an entry in the // summary, skip it. continue; Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp === --- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp +++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp @@ -649,23 +649,24 @@ static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, DenseSet &CantBePromoted) { auto *Aliasee = A.getAliaseeObject(); - // Currently, skip summary for indirect function aliases as + // Skip summary for indirect function aliases as // summary for aliasee will not be emitted. - if (Aliasee->getValueID() != Value::ValueTy::GlobalIFuncVal) { -bool NonRenamableLocal = isNonRenamableLocal(A); -GlobalValueSummary::GVFlags Flags( -A.getLinkage(), A.getVisibility(), NonRenamableLocal, -/* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable()); -auto AS = std::make_unique(Flags); -auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID()); -assert(AliaseeVI && "Alias expects aliasee summary to be available"); -assert(AliaseeVI.getSummaryList().size() == 1 && - "Expected a single entry per aliasee in per-module index"); -AS->setAliasee(AliaseeVI, AliaseeVI.getSummaryList()[0].get()); -if (NonRenamableLocal) - CantBePromoted.insert(A.getGUID()); -Index.addGlobalValueSummary(A, std::move(AS)); + if (isa(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(Flags); + auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID()); + assert(AliaseeVI && "Alias expects aliasee summary to be available"); + assert(AliaseeVI.getSummaryList().size() == 1 && + "Expected a single entry per aliasee in per-module index"); + AS->setAliasee(AliaseeVI, AliaseeVI.getSummaryList()[0].get()); + if (NonRenamableLocal) +CantBePromoted.insert(A.getGUID()); + Index.addGlobalValueSummary(A, std::move(AS)); } // Set LiveRoot flag on entries matching the given value name. Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp === --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -4103,8 +4103,7 @@ for (const GlobalAlias &A : M.aliases()) { auto *Aliasee = A.getAliaseeObject(); -if (!Aliasee->hasName() || -Aliasee->getValueID() == Value::ValueTy::GlobalIFuncVal) +if (!Aliasee->hasName() || isa(Aliasee)) // IFunc function and Nameless function don't have an entry in the // summary, skip it. continue; Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp === --- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp +++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp @@ -649,23 +649,24 @@ static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, DenseSet &CantBePromoted) { auto *Aliasee = A.getAliaseeObject(); - // Currently, skip summary for indirect function aliases as + // Skip summary for indirect function aliases as // summary for aliasee will not be emitted. - if (Aliasee->getValueID() != Value::ValueTy::GlobalIFuncVal) { -bool NonRenamableLocal = isNonRenamableLocal(A); -GlobalValueSummary::GVFlags Flags( -A.getLinkage(), A.getVisibility(), NonRenamableLocal, -/* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable()); -auto AS = std::make_unique(Flags); -auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID()); -assert(AliaseeVI && "Alias expects aliasee summary to be available"); -assert(AliaseeVI.getSummaryList().size() == 1 && - "Expected a single entry per aliasee in per-module index"); -AS->setAliasee(AliaseeVI, AliaseeVI.getSummaryList()[0].get()); -if (NonRenamableLocal) - C
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
SchrodingerZhu updated this revision to Diff 441821. SchrodingerZhu added a comment. undo wrong patch Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129009/new/ https://reviews.llvm.org/D129009 Files: clang/test/Analysis/alias-indirect-function-lto.c llvm/lib/Analysis/ModuleSummaryAnalysis.cpp llvm/lib/Bitcode/Writer/BitcodeWriter.cpp 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. +if (!Aliasee->hasName() || isa(Aliasee)) + // IFunc function and Nameless function don't have an entry in the + // summary, skip it. 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,19 @@ Index.addGlobalValueSummary(V, std::move(GVarSummary)); } -static void -computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, -DenseSet &CantBePromoted) { +static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, +DenseSet &CantBePromoted) { + auto *Aliasee = A.getAliaseeObject(); + // Skip summary for indirect function aliases as + // summary for aliasee will not be emitted. + if (isa(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(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 && Index: clang/test/Analysis/alias-indirect-function-lto.c === --- /dev/null +++ clang/test/Analysis/alias-indirect-function-lto.c @@ -0,0 +1,5 @@ +// RUN: %clang_analyze_cc1 -flto %s +void f() __attribute__((ifunc("g"))); +static void *g() { return 0; }; +void h() __attribute__((alias("f"))); +// no crash \ No newline at end of file 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. +if (!Aliasee->hasName() || isa(Aliasee)) + // IFunc function and Nameless function don't have an entry in the + // summary, skip it. 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,19 @@ Index.addGlobalValueSummary(V, std::move(GVarSummary)); } -static void -computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, -DenseSet &CantBePromoted) { +static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, +DenseSet &CantBePromoted) { + auto *Aliasee = A.getAliaseeObject(); + // Skip summary for indirect function aliases as + // summary for aliasee will not be emitted. + if (isa(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(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 && Index: clang/test/Analysis/alias-indirect-function-lto.c === --- /dev/null +++ clang/test/Analysis/alias-indirect-function-lto.c @@ -0,0 +1,5 @@ +// RUN: %clang_analyze_cc1 -flto %s +void f() __attribute__((ifunc("g"))); +static void *g() { return 0; }; +void h() __attribute__((alias("f"))
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
SchrodingerZhu updated this revision to Diff 441828. SchrodingerZhu edited the summary of this revision. SchrodingerZhu added a comment. address CR Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129009/new/ https://reviews.llvm.org/D129009 Files: clang/test/Analysis/alias-indirect-function-lto.c llvm/test/LTO/alias-indirect-function-lto.c Index: llvm/test/LTO/alias-indirect-function-lto.c === --- llvm/test/LTO/alias-indirect-function-lto.c +++ llvm/test/LTO/alias-indirect-function-lto.c @@ -1,5 +1,5 @@ -// RUN: %clang_analyze_cc1 -flto %s +// RUN: clang -flto %s void f() __attribute__((ifunc("g"))); static void *g() { return 0; }; void h() __attribute__((alias("f"))); -// no crash \ No newline at end of file +// no crash Index: llvm/test/LTO/alias-indirect-function-lto.c === --- llvm/test/LTO/alias-indirect-function-lto.c +++ llvm/test/LTO/alias-indirect-function-lto.c @@ -1,5 +1,5 @@ -// RUN: %clang_analyze_cc1 -flto %s +// RUN: clang -flto %s void f() __attribute__((ifunc("g"))); static void *g() { return 0; }; void h() __attribute__((alias("f"))); -// no crash \ No newline at end of file +// no crash ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
SchrodingerZhu updated this revision to Diff 441829. SchrodingerZhu added a comment. address CR 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/test/LTO/alias-indirect-function-lto.c Index: llvm/test/LTO/alias-indirect-function-lto.c === --- /dev/null +++ llvm/test/LTO/alias-indirect-function-lto.c @@ -0,0 +1,5 @@ +// RUN: clang -flto %s +void f() __attribute__((ifunc("g"))); +static void *g() { return 0; }; +void h() __attribute__((alias("f"))); +// no crash 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. +if (!Aliasee->hasName() || isa(Aliasee)) + // IFunc function and Nameless function don't have an entry in the + // summary, skip it. 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,19 @@ Index.addGlobalValueSummary(V, std::move(GVarSummary)); } -static void -computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, -DenseSet &CantBePromoted) { +static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, +DenseSet &CantBePromoted) { + auto *Aliasee = A.getAliaseeObject(); + // Skip summary for indirect function aliases as + // summary for aliasee will not be emitted. + if (isa(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(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 && Index: llvm/test/LTO/alias-indirect-function-lto.c === --- /dev/null +++ llvm/test/LTO/alias-indirect-function-lto.c @@ -0,0 +1,5 @@ +// RUN: clang -flto %s +void f() __attribute__((ifunc("g"))); +static void *g() { return 0; }; +void h() __attribute__((alias("f"))); +// no crash 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. +if (!Aliasee->hasName() || isa(Aliasee)) + // IFunc function and Nameless function don't have an entry in the + // summary, skip it. 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,19 @@ Index.addGlobalValueSummary(V, std::move(GVarSummary)); } -static void -computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, -DenseSet &CantBePromoted) { +static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, +DenseSet &CantBePromoted) { + auto *Aliasee = A.getAliaseeObject(); + // Skip summary for indirect function aliases as + // summary for aliasee will not be emitted. + if (isa(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(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 && ___ cfe-commits mailing list c
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
SchrodingerZhu updated this revision to Diff 441830. SchrodingerZhu added a comment. - adjust run arg 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/test/LTO/alias-indirect-function-lto.c Index: llvm/test/LTO/alias-indirect-function-lto.c === --- /dev/null +++ llvm/test/LTO/alias-indirect-function-lto.c @@ -0,0 +1,5 @@ +// RUN: clang -flto %s -c -o %t1 +void f() __attribute__((ifunc("g"))); +static void *g() { return 0; }; +void h() __attribute__((alias("f"))); +// no crash 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. +if (!Aliasee->hasName() || isa(Aliasee)) + // IFunc function and Nameless function don't have an entry in the + // summary, skip it. 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,19 @@ Index.addGlobalValueSummary(V, std::move(GVarSummary)); } -static void -computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, -DenseSet &CantBePromoted) { +static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, +DenseSet &CantBePromoted) { + auto *Aliasee = A.getAliaseeObject(); + // Skip summary for indirect function aliases as + // summary for aliasee will not be emitted. + if (isa(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(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 && Index: llvm/test/LTO/alias-indirect-function-lto.c === --- /dev/null +++ llvm/test/LTO/alias-indirect-function-lto.c @@ -0,0 +1,5 @@ +// RUN: clang -flto %s -c -o %t1 +void f() __attribute__((ifunc("g"))); +static void *g() { return 0; }; +void h() __attribute__((alias("f"))); +// no crash 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. +if (!Aliasee->hasName() || isa(Aliasee)) + // IFunc function and Nameless function don't have an entry in the + // summary, skip it. 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,19 @@ Index.addGlobalValueSummary(V, std::move(GVarSummary)); } -static void -computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, -DenseSet &CantBePromoted) { +static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, +DenseSet &CantBePromoted) { + auto *Aliasee = A.getAliaseeObject(); + // Skip summary for indirect function aliases as + // summary for aliasee will not be emitted. + if (isa(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(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 && ___
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
SchrodingerZhu added a comment. Sorry for the noise during the process. I am really new to LLVM. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129009/new/ https://reviews.llvm.org/D129009 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
SchrodingerZhu updated this revision to Diff 441844. SchrodingerZhu added a comment. - specify target 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/test/LTO/alias-indirect-function-lto.c Index: llvm/test/LTO/alias-indirect-function-lto.c === --- /dev/null +++ llvm/test/LTO/alias-indirect-function-lto.c @@ -0,0 +1,5 @@ +// RUN: clang -flto %s -c -o %t1 -target x86_64-unknown-linux-gnu +void f() __attribute__((ifunc("g"))); +static void *g() { return 0; }; +void h() __attribute__((alias("f"))); +// no crash 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. +if (!Aliasee->hasName() || isa(Aliasee)) + // IFunc function and Nameless function don't have an entry in the + // summary, skip it. 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,19 @@ Index.addGlobalValueSummary(V, std::move(GVarSummary)); } -static void -computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, -DenseSet &CantBePromoted) { +static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, +DenseSet &CantBePromoted) { + auto *Aliasee = A.getAliaseeObject(); + // Skip summary for indirect function aliases as + // summary for aliasee will not be emitted. + if (isa(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(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 && Index: llvm/test/LTO/alias-indirect-function-lto.c === --- /dev/null +++ llvm/test/LTO/alias-indirect-function-lto.c @@ -0,0 +1,5 @@ +// RUN: clang -flto %s -c -o %t1 -target x86_64-unknown-linux-gnu +void f() __attribute__((ifunc("g"))); +static void *g() { return 0; }; +void h() __attribute__((alias("f"))); +// no crash 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. +if (!Aliasee->hasName() || isa(Aliasee)) + // IFunc function and Nameless function don't have an entry in the + // summary, skip it. 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,19 @@ Index.addGlobalValueSummary(V, std::move(GVarSummary)); } -static void -computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, -DenseSet &CantBePromoted) { +static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, +DenseSet &CantBePromoted) { + auto *Aliasee = A.getAliaseeObject(); + // Skip summary for indirect function aliases as + // summary for aliasee will not be emitted. + if (isa(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(Flags); - auto *Aliasee = A.getAliaseeObject(); auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID()); assert(AliaseeVI && "Alias expects aliasee summary to be available"); assert(AliaseeVI.getSummaryList
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
SchrodingerZhu updated this revision to Diff 441846. SchrodingerZhu added a comment. - address cr: code brace 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/test/LTO/alias-indirect-function-lto.c Index: llvm/test/LTO/alias-indirect-function-lto.c === --- /dev/null +++ llvm/test/LTO/alias-indirect-function-lto.c @@ -0,0 +1,5 @@ +// RUN: clang -flto %s -c -o %t1 -target x86_64-unknown-linux-gnu +void f() __attribute__((ifunc("g"))); +static void *g() { return 0; }; +void h() __attribute__((alias("f"))); +// no crash 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. +if (!Aliasee->hasName() || isa(Aliasee)) + // IFunc function and Nameless function don't have an entry in the + // summary, skip it. 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 &CantBePromoted) { +static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, +DenseSet &CantBePromoted) { + auto *Aliasee = A.getAliaseeObject(); + + if (isa(Aliasee)) +// Skip summary for indirect function aliases as +// summary for aliasee will not be emitted. +return; + bool NonRenamableLocal = isNonRenamableLocal(A); GlobalValueSummary::GVFlags Flags( A.getLinkage(), A.getVisibility(), NonRenamableLocal, /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable()); auto AS = std::make_unique(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 && Index: llvm/test/LTO/alias-indirect-function-lto.c === --- /dev/null +++ llvm/test/LTO/alias-indirect-function-lto.c @@ -0,0 +1,5 @@ +// RUN: clang -flto %s -c -o %t1 -target x86_64-unknown-linux-gnu +void f() __attribute__((ifunc("g"))); +static void *g() { return 0; }; +void h() __attribute__((alias("f"))); +// no crash 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. +if (!Aliasee->hasName() || isa(Aliasee)) + // IFunc function and Nameless function don't have an entry in the + // summary, skip it. 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 &CantBePromoted) { +static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, +DenseSet &CantBePromoted) { + auto *Aliasee = A.getAliaseeObject(); + + if (isa(Aliasee)) +// Skip summary for indirect function aliases as +// summary for aliasee will not be emitted. +return; + bool NonRenamableLocal = isNonRenamableLocal(A); GlobalValueSummary::GVFlags Flags( A.getLinkage(), A.getVisibility(), NonRenamableLocal, /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable()); auto AS = std::make_unique(Flags); - auto *Aliasee = A.getAliaseeObject(); auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID()); assert(AliaseeVI && "Alias expects aliasee summary to be available"); assert(AliaseeVI.getS
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
SchrodingerZhu updated this revision to Diff 441848. SchrodingerZhu added a comment. - address cr: use IR instead 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/test/LTO/alias-indirect-function-lto.ll Index: llvm/test/LTO/alias-indirect-function-lto.ll === --- /dev/null +++ llvm/test/LTO/alias-indirect-function-lto.ll @@ -0,0 +1,16 @@ +; RUN: opt -module-summary -o %t.bc %s + +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" + +@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver + +define internal i32 (i32)* @foo_resolver() { +entry: + ret i32 (i32)* null +} + +@bar = alias i32 (i32), i32 (i32)* @foo + +@baz = weak alias i32 (i32), i32 (i32)* @foo +; no crash 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. +if (!Aliasee->hasName() || isa(Aliasee)) + // IFunc function and Nameless function don't have an entry in the + // summary, skip it. 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 &CantBePromoted) { +static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, +DenseSet &CantBePromoted) { + auto *Aliasee = A.getAliaseeObject(); + + if (isa(Aliasee)) +// Skip summary for indirect function aliases as +// summary for aliasee will not be emitted. +return; + bool NonRenamableLocal = isNonRenamableLocal(A); GlobalValueSummary::GVFlags Flags( A.getLinkage(), A.getVisibility(), NonRenamableLocal, /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable()); auto AS = std::make_unique(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 && Index: llvm/test/LTO/alias-indirect-function-lto.ll === --- /dev/null +++ llvm/test/LTO/alias-indirect-function-lto.ll @@ -0,0 +1,16 @@ +; RUN: opt -module-summary -o %t.bc %s + +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" + +@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver + +define internal i32 (i32)* @foo_resolver() { +entry: + ret i32 (i32)* null +} + +@bar = alias i32 (i32), i32 (i32)* @foo + +@baz = weak alias i32 (i32), i32 (i32)* @foo +; no crash 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. +if (!Aliasee->hasName() || isa(Aliasee)) + // IFunc function and Nameless function don't have an entry in the + // summary, skip it. 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 &CantBePromoted) { +static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, +DenseSet &CantBePromoted) { + auto *Aliasee = A.getAliaseeObject(); + + if (isa(Aliasee)) +// Skip summary for indirect function aliases as +// summary for aliasee will not be emitted. +re
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
SchrodingerZhu updated this revision to Diff 441849. SchrodingerZhu added a comment. - move to proper place 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/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,16 @@ +; RUN: opt -module-summary -o %t.bc %s + +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" + +@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver + +define internal i32 (i32)* @foo_resolver() { +entry: + ret i32 (i32)* null +} + +@bar = alias i32 (i32), i32 (i32)* @foo + +@baz = weak alias i32 (i32), i32 (i32)* @foo +; no crash 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. +if (!Aliasee->hasName() || isa(Aliasee)) + // IFunc function and Nameless function don't have an entry in the + // summary, skip it. 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 &CantBePromoted) { +static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, +DenseSet &CantBePromoted) { + auto *Aliasee = A.getAliaseeObject(); + + if (isa(Aliasee)) +// Skip summary for indirect function aliases as +// summary for aliasee will not be emitted. +return; + bool NonRenamableLocal = isNonRenamableLocal(A); GlobalValueSummary::GVFlags Flags( A.getLinkage(), A.getVisibility(), NonRenamableLocal, /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable()); auto AS = std::make_unique(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 && 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,16 @@ +; RUN: opt -module-summary -o %t.bc %s + +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" + +@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver + +define internal i32 (i32)* @foo_resolver() { +entry: + ret i32 (i32)* null +} + +@bar = alias i32 (i32), i32 (i32)* @foo + +@baz = weak alias i32 (i32), i32 (i32)* @foo +; no crash 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. +if (!Aliasee->hasName() || isa(Aliasee)) + // IFunc function and Nameless function don't have an entry in the + // summary, skip it. 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 &CantBePromoted) { +static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, +DenseSet &CantBePromoted) { + auto *Aliasee = A.getAliaseeObject(); + + if (isa(Aliasee)) +// Skip summary for indirect functio
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
SchrodingerZhu updated this revision to Diff 441850. SchrodingerZhu added a comment. - adjust comment 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/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,16 @@ +; RUN: opt -module-summary -o %t.bc %s + +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" + +@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver + +define internal i32 (i32)* @foo_resolver() { +entry: + ret i32 (i32)* null +} + +@bar = alias i32 (i32), i32 (i32)* @foo + +@baz = weak alias i32 (i32), i32 (i32)* @foo +; no crash 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(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 &CantBePromoted) { +static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, +DenseSet &CantBePromoted) { + auto *Aliasee = A.getAliaseeObject(); + + // Skip summary for indirect function aliases as summary for aliasee will not + // be emitted. + if (isa(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(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 && 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,16 @@ +; RUN: opt -module-summary -o %t.bc %s + +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" + +@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver + +define internal i32 (i32)* @foo_resolver() { +entry: + ret i32 (i32)* null +} + +@bar = alias i32 (i32), i32 (i32)* @foo + +@baz = weak alias i32 (i32), i32 (i32)* @foo +; no crash 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(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 &CantBePromoted) { +static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, +DenseSet &CantBePromoted) { + auto *Aliasee = A.getAliaseeObject(); + + // Skip summary for indirect function aliases as summary for aliasee will not
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
SchrodingerZhu added a comment. @MaskRay unfortunately and fortunately, extending the test case to ; RUN: opt -module-summary -o %t.bc %s ; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,pl -r %t.bc,bar,px -r %t.bc,baz,px -o %t2 ; RUN: llvm-nm %t2.1 | FileCheck %s ; CHECK: i foo ; CHECK: t foo_resolver ; CHECK: T bar ; CHECK: W baz gives me another crash at LTO stage: #0 0x56128a37edb9 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/schrodinger/Documents/llvm-project/llvm/cmake-build-minsizerel/bin/llvm-lto2+0x1bb4db9) #1 0x56128a37ef6e SignalHandler(int) Signals.cpp:0:0 #2 0x7f0ba5506150 (/usr/lib/libc.so.6+0x42150) #3 0x56128a6dcdd7 std::_Function_handler, llvm::detail::DenseMapPair> const&)::$_4>::_M_invoke(std::_Any_data const&, llvm::GlobalValue const&) FunctionImport.cpp:0:0 #4 0x56128a7073fe llvm::InternalizePass::maybeInternalize(llvm::GlobalValue&, llvm::DenseMap, llvm::detail::DenseMapPair>&) (/home/schrodinger/Documents/llvm-project/llvm/cmake-build-minsizerel/bin/llvm-lto2+0x1f3d3fe) #5 0x56128a707990 llvm::InternalizePass::internalizeModule(llvm::Module&, llvm::CallGraph*) (/home/schrodinger/Documents/llvm-project/llvm/cmake-build-minsizerel/bin/llvm-lto2+0x1f3d990) #6 0x56128a6d9df0 llvm::thinLTOInternalizeModule(llvm::Module&, llvm::DenseMap, llvm::detail::DenseMapPair> const&) (/home/schrodinger/Documents/llvm-project/llvm/cmake-build-minsizerel/bin/llvm-lto2+0x1f0fdf0) #7 0x56128a181dba llvm::lto::thinBackend(llvm::lto::Config const&, unsigned int, std::function>> (unsigned int)>, llvm::Module&, llvm::ModuleSummaryIndex const&, llvm::StringMap, std::equal_to, std::allocator>, llvm::MallocAllocator> const&, llvm::DenseMap, llvm::detail::DenseMapPair> const&, llvm::MapVector, llvm::detail::DenseMapPair>, std::vector, std::allocator>>>*, std::vector> const&) (/home/schrodinger/Documents/llvm-project/llvm/cmake-build-minsizerel/bin/llvm-lto2+0x19b7dba) #8 0x56128a17d8b0 (anonymous namespace)::InProcessThinBackend::runThinLTOBackendThread(std::function>> (unsigned int)>, std::function>> (unsigned int)>> (unsigned int, llvm::StringRef)>, unsigned int, llvm::BitcodeModule, llvm::ModuleSummaryIndex&, llvm::StringMap, std::equal_to, std::allocator>, llvm::MallocAllocator> const&, llvm::DenseSet> const&, std::map, std::allocator>> const&, llvm::DenseMap, llvm::detail::DenseMapPair> const&, llvm::MapVector, llvm::detail::DenseMapPair>, std::vector, std::allocator>>>&)::'lambda'(std::function>> (unsigned int)>)::operator()(std::function>> (unsigned int)>) const LTO.cpp:0:0 #9 0x56128a17d1fa std::_Function_handler, std::equal_to, std::allocator>, llvm::MallocAllocator> const&, llvm::DenseSet> const&, std::map, std::allocator>> const&, llvm::MapVector, llvm::detail::DenseMapPair>, std::vector, std::allocator>>>&)::'lambda'(llvm::BitcodeModule, llvm::ModuleSummaryIndex&, llvm::StringMap, std::equal_to, std::allocator>, llvm::MallocAllocator> const&, llvm::DenseSet> const&, std::map, std::allocator>> const&, llvm::DenseMap, llvm::detail::DenseMapPair> const&, llvm::MapVector, llvm::detail::DenseMapPair>, std::vector, std::allocator>>>&) (llvm::BitcodeModule, std::reference_wrapper, std::reference_wrapper, std::equal_to, std::allocator>, llvm::MallocAllocator> const>, std::reference_wrapper> const>, std::reference_wrapper, std::allocator>> const>, std::reference_wrapper, llvm::detail::DenseMapPair> const>, std::reference_wrapper, llvm::detail::DenseMapPair>, std::vector, std::allocator)>>::_M_invoke(std::_Any_data const&) LTO.cpp:0:0 #10 0x56128a17c851 void std::__invoke_impl)::'lambda'()&>(std::__invoke_other, llvm::ThreadPool::createTaskAndFuture(std::function)::'lambda'()&) (/home/schrodinger/Documents/llvm-project/llvm/cmake-build-minsizerel/bin/llvm-lto2+0x19b2851) #11 0x56128a33eed1 llvm::ThreadPool::processTasks(llvm::ThreadPoolTaskGroup*) (/home/schrodinger/Documents/llvm-project/llvm/cmake-build-minsizerel/bin/llvm-lto2+0x1b74ed1) I am looking into it Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129009/new/ https://reviews.llvm.org/D129009 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
SchrodingerZhu updated this revision to Diff 441886. SchrodingerZhu added a comment. - stage - stage - fix lto 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" + +@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver + +define internal i32 (i32)* @foo_resolver() { +entry: + ret i32 (i32)* null +} + +@bar = alias i32 (i32), i32 (i32)* @foo + +@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(&GV) && + isa(dyn_cast(&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(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 &CantBePromoted) { +static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, +DenseSet &CantBePromoted) { + auto *Aliasee = A.getAliaseeObject(); + + // Skip summary for indirect function aliases as summary for aliasee will not + // be emitted. + if (isa(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(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 && 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" + +@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver + +define internal i32 (i32)* @foo_resolver() { +entry: + ret i32 (i32)* null +} + +@bar = alias i32 (i32), i32 (i32)* @foo + +@baz = weak alias i32 (i32), i32 (i32)* @foo +; no crash Index: llvm/lib/Transforms/IPO/FunctionImport.cpp === --- llvm/lib/Trans
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
SchrodingerZhu updated this revision to Diff 441887. SchrodingerZhu added a comment. - format 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" + +@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver + +define internal i32 (i32)* @foo_resolver() { +entry: + ret i32 (i32)* null +} + +@bar = alias i32 (i32), i32 (i32)* @foo + +@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(&GV) && +isa(dyn_cast(&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(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 &CantBePromoted) { +static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, +DenseSet &CantBePromoted) { + auto *Aliasee = A.getAliaseeObject(); + + // Skip summary for indirect function aliases as summary for aliasee will not + // be emitted. + if (isa(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(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 && 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" + +@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver + +define internal i32 (i32)* @foo_resolver() { +entry: + ret i32 (i32)* null +} + +@bar = alias i32 (i32), i32 (i32)* @foo + +@baz = weak alias i32 (i32), i32 (i32)* @foo +; no crash Index: llvm/lib/Transforms/IPO/FunctionImport.cpp === --- llvm/lib/Transforms/IPO/Function
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
SchrodingerZhu added a comment. The LTO problem is fixed but thinlto is not fully resolved: /home/schrodinger/Documents/llvm-project/llvm/cmake-build-debug/bin/clang test.c -o test -flto=thin -sha red -fuse-ld=lld IFunc resolver must be a definition ptr @f LLVM ERROR: Broken module found, compilation aborted! PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. #0 0x559adcf4c647 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/schrodinger/Documents/llvm-project/llvm/lib/Support/Unix/Signals.inc:569:11 #1 0x559adcf4c85b PrintStackTraceSignalHandler(void*) /home/schrodinger/Documents/llvm-project/llvm/lib/Support/Unix/Signals.inc:636:1 #2 0x559adcf4abf3 llvm::sys::RunSignalHandlers() /home/schrodinger/Documents/llvm-project/llvm/lib/Support/Signals.cpp:103:5 #3 0x559adcf4d071 SignalHandler(int) /home/schrodinger/Documents/llvm-project/llvm/lib/Support/Unix/Signals.inc:0:3 #4 0x7f4a56705150 (/usr/lib/libc.so.6+0x42150) #5 0x7f4a567606db pthread_kill (/usr/lib/libc.so.6+0x9d6db) #6 0x7f4a567050a8 gsignal (/usr/lib/libc.so.6+0x420a8) #7 0x7f4a566eb535 abort (/usr/lib/libc.so.6+0x28535) #8 0x559adce51e34 llvm::report_fatal_error(llvm::Twine const&, bool) /home/schrodinger/Documents/llvm-project/llvm/lib/Support/ErrorHandling.cpp:125:5 #9 0x559adce51ca2 /home/schrodinger/Documents/llvm-project/llvm/lib/Support/ErrorHandling.cpp:83:3 #10 0x559ae2a64551 llvm::VerifierPass::run(llvm::Module&, llvm::AnalysisManager&) /home/schrodinger/Documents/llvm-project/llvm/lib/IR/Verifier.cpp:0:5 #11 0x559ae006e757 llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) /home/schrodinger/Documents/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:88:17 #12 0x559ae2ac llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) /home/schrodinger/Documents/llvm-project/llvm/include/llvm/IR/PassManager.h:522:16 #13 0x559ae0062e9f runNewPMPasses(llvm::lto::Config const&, llvm::Module&, llvm::TargetMachine*, unsigned int, bool, llvm::ModuleSummaryIndex*, llvm::ModuleSummaryIndex const*) /home/schrodinger/Documents/llvm-project/llvm/lib/LTO/LTOBackend.cpp:309:7 #14 0x559ae00620f7 llvm::lto::opt(llvm::lto::Config const&, llvm::TargetMachine*, unsigned int, llvm::Module&, bool, llvm::ModuleSummaryIndex*, llvm::ModuleSummaryIndex const*, std::vector> const&) /home/schrodinger/Documents/llvm-project/llvm/lib/LTO/LTOBackend.cpp:336:11 #15 0x559ae0064d1f llvm::lto::thinBackend(llvm::lto::Config const&, unsigned int, std::function>> (unsigned int)>, llvm::Module&, llvm::ModuleSummaryIndex const&, llvm::StringMap, std::equal_to, std::allocator>, llvm::MallocAllocator> const&, llvm::DenseMap, llvm::detail::DenseMapPair> const&, llvm::MapVector, llvm::detail::DenseMapPair>, std::vector, std::allocator>>>*, std::vector> const&)::$_6::operator()(llvm::Module&, llvm::TargetMachine*, std::unique_ptr>) const /home/schrodinger/Documents/llvm-project/llvm/lib/LTO/LTOBackend.cpp:554:13 #16 0x559ae0064c2c llvm::lto::thinBackend(llvm::lto::Config const&, unsigned int, std::function>> (unsigned int)>, llvm::Module&, llvm::ModuleSummaryIndex const&, llvm::StringMap, std::equal_to, std::allocator>, llvm::MallocAllocator> const&, llvm::DenseMap, llvm::detail::DenseMapPair> const&, llvm::MapVector, llvm::detail::DenseMapPair>, std::vector, std::allocator>>>*, std::vector> const&) /home/schrodinger/Documents/llvm-project/llvm/lib/LTO/LTOBackend.cpp:630:3 #17 0x559ae0031752 (anonymous namespace)::InProcessThinBackend::runThinLTOBackendThread(std::function>> (unsigned int)>, std::function>> (unsigned int)>> (unsigned int, llvm::StringRef)>, unsigned int, llvm::BitcodeModule, llvm::ModuleSummaryIndex&, llvm::StringMap, std::equal_to, std::allocator>, llvm::MallocAllocator> const&, llvm::DenseSet> const&, std::map, std::allocator>> const&, llvm::DenseMap, llvm::detail::DenseMapPair> const&, llvm::MapVector, llvm::detail::DenseMapPair>, std::vector, std::allocator>>>&)::'lambda'(std::function>> (unsigned int)>)::operator()(std::function>> (unsigned int)>) const /home/schrodinger/Documents/llvm-project/llvm/lib/LTO/LTO.cpp:1256:7 #18 0x559ae00312df (anonymous namespace)::InProcessThinBackend::runThinLTOBackendThread(std::function>> (unsigned int)>, std::function>> (unsigned int)>> (unsigned int, llvm::StringRef)>, unsigned int, llvm::BitcodeModule, llvm::ModuleSummaryIndex&, llvm::StringMap, std::equal_to, std::allocator>, llvm::MallocAllocator> const&, llvm::DenseSet> const&, std::map, std::allocator>> const&, llvm::DenseMap, llvm::detail::DenseMapPair> const&, llvm::MapVector, llvm::detail::DenseMapPair>, std::vector, std::allocator>>>&) /home/schrodinger/Documents/llvm-project/llvm/lib/LTO/LTO.cpp:1272:7 #19 0x559ae0030e86 (anonymous namespace)::InProcessThinBackend:
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
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" + +@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver + +define internal i32 (i32)* @foo_resolver() { +entry: + ret i32 (i32)* null +} + +@bar = alias i32 (i32), i32 (i32)* @foo + +@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(&GV) && +isa(dyn_cast(&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(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 &CantBePromoted) { +static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, +DenseSet &CantBePromoted) { + auto *Aliasee = A.getAliaseeObject(); + + // Skip summary for indirect function aliases as summary for aliasee will not + // be emitted. + if (isa(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(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"); 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-f8
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
SchrodingerZhu updated this revision to Diff 441894. SchrodingerZhu added a comment. fix more 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/lib/Transforms/Utils/FunctionImportUtils.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" + +@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver + +define internal i32 (i32)* @foo_resolver() { +entry: + ret i32 (i32)* null +} + +@bar = alias i32 (i32), i32 (i32)* @foo + +@baz = weak alias i32 (i32), i32 (i32)* @foo +; no crash Index: llvm/lib/Transforms/Utils/FunctionImportUtils.cpp === --- llvm/lib/Transforms/Utils/FunctionImportUtils.cpp +++ llvm/lib/Transforms/Utils/FunctionImportUtils.cpp @@ -59,7 +59,13 @@ // in this module. auto Summary = ImportIndex.findSummaryInModule( VI, SGV->getParent()->getModuleIdentifier()); - assert(Summary && "Missing summary for global value when exporting"); + + // It maybe the case that SGV is on a chain of an ifunc, its alias and + // subsequent aliases. In this case, the summary for the value is not + // available. + if (!Summary) +return false; + auto Linkage = Summary->linkage(); if (!GlobalValue::isLocalLinkage(Linkage)) { assert(!isNonRenamableLocal(*SGV) && Index: llvm/lib/Transforms/IPO/FunctionImport.cpp === --- llvm/lib/Transforms/IPO/FunctionImport.cpp +++ llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -1169,10 +1169,13 @@ // recorded in the index using the original name. // FIXME: This may not be needed once PR27866 is fixed. GS = DefinedGlobals.find(GlobalValue::getGUID(OrigName)); -assert(GS != DefinedGlobals.end()); } } -return !GlobalValue::isLocalLinkage(GS->second->linkage()); +// It maybe the case that GV is on a chain of an ifunc, its alias and +// subsequent aliases. In this case, the summary for the value is not +// available. +return GS != DefinedGlobals.end() || + !GlobalValue::isLocalLinkage(GS->second->linkage()); }; // FIXME: See if we can just internalize directly here via linkage changes 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(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 &CantBePromoted) { +static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, +DenseSet &CantBePromoted) { + auto *Aliasee = A.getAliaseeObject(); + + // Skip summary for indirect function aliases as summary for aliasee will not + // be emitted. + if (isa(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(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
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
SchrodingerZhu updated this revision to Diff 441895. SchrodingerZhu added a comment. fix typo 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/lib/Transforms/Utils/FunctionImportUtils.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" + +@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver + +define internal i32 (i32)* @foo_resolver() { +entry: + ret i32 (i32)* null +} + +@bar = alias i32 (i32), i32 (i32)* @foo + +@baz = weak alias i32 (i32), i32 (i32)* @foo +; no crash Index: llvm/lib/Transforms/Utils/FunctionImportUtils.cpp === --- llvm/lib/Transforms/Utils/FunctionImportUtils.cpp +++ llvm/lib/Transforms/Utils/FunctionImportUtils.cpp @@ -59,7 +59,13 @@ // in this module. auto Summary = ImportIndex.findSummaryInModule( VI, SGV->getParent()->getModuleIdentifier()); - assert(Summary && "Missing summary for global value when exporting"); + + // It maybe the case that SGV is on a chain of an ifunc, its alias and + // subsequent aliases. In this case, the summary for the value is not + // available. + if (!Summary) +return false; + auto Linkage = Summary->linkage(); if (!GlobalValue::isLocalLinkage(Linkage)) { assert(!isNonRenamableLocal(*SGV) && Index: llvm/lib/Transforms/IPO/FunctionImport.cpp === --- llvm/lib/Transforms/IPO/FunctionImport.cpp +++ llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -1169,10 +1169,13 @@ // recorded in the index using the original name. // FIXME: This may not be needed once PR27866 is fixed. GS = DefinedGlobals.find(GlobalValue::getGUID(OrigName)); -assert(GS != DefinedGlobals.end()); } } -return !GlobalValue::isLocalLinkage(GS->second->linkage()); +// It maybe the case that GV is on a chain of an ifunc, its alias and +// subsequent aliases. In this case, the summary for the value is not +// available. +return GS == DefinedGlobals.end() || + !GlobalValue::isLocalLinkage(GS->second->linkage()); }; // FIXME: See if we can just internalize directly here via linkage changes 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(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 &CantBePromoted) { +static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, +DenseSet &CantBePromoted) { + auto *Aliasee = A.getAliaseeObject(); + + // Skip summary for indirect function aliases as summary for aliasee will not + // be emitted. + if (isa(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(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
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
SchrodingerZhu updated this revision to Diff 441897. SchrodingerZhu added a comment. enlarge test and fix accordingly 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/lib/Transforms/Utils/FunctionImportUtils.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,31 @@ +; 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 +; CHECK: i grault +; CHECK: i quuz +; CHECK: i qux + +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" + +@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver + +define internal i32 (i32)* @foo_resolver() { +entry: + ret i32 (i32)* null +} + +@bar = alias i32 (i32), i32 (i32)* @foo +@baz = weak alias i32 (i32), i32 (i32)* @foo +@qux = alias i32 (i32), i32 (i32)* @bar + +@quux = internal alias i32 (i32)* (), i32 (i32)* ()* @foo_resolver +@quuz = internal ifunc i32 (i32), i32 (i32)* ()* @quux +@corge = internal alias i32 (i32), i32 (i32)* @quuz +@grault = alias i32 (i32), i32 (i32)* @corge + +; no crash Index: llvm/lib/Transforms/Utils/FunctionImportUtils.cpp === --- llvm/lib/Transforms/Utils/FunctionImportUtils.cpp +++ llvm/lib/Transforms/Utils/FunctionImportUtils.cpp @@ -59,7 +59,13 @@ // in this module. auto Summary = ImportIndex.findSummaryInModule( VI, SGV->getParent()->getModuleIdentifier()); - assert(Summary && "Missing summary for global value when exporting"); + + // It maybe the case that SGV is on a chain of an ifunc, its alias and + // subsequent aliases. In this case, the summary for the value is not + // available. + if (!Summary) +return false; + auto Linkage = Summary->linkage(); if (!GlobalValue::isLocalLinkage(Linkage)) { assert(!isNonRenamableLocal(*SGV) && Index: llvm/lib/Transforms/IPO/FunctionImport.cpp === --- llvm/lib/Transforms/IPO/FunctionImport.cpp +++ llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -1169,10 +1169,13 @@ // recorded in the index using the original name. // FIXME: This may not be needed once PR27866 is fixed. GS = DefinedGlobals.find(GlobalValue::getGUID(OrigName)); -assert(GS != DefinedGlobals.end()); } } -return !GlobalValue::isLocalLinkage(GS->second->linkage()); +// It maybe the case that GV is on a chain of an ifunc, its alias and +// subsequent aliases. In this case, the summary for the value is not +// available. +return GS == DefinedGlobals.end() || + !GlobalValue::isLocalLinkage(GS->second->linkage()); }; // FIXME: See if we can just internalize directly here via linkage changes 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(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 &CantBePromoted) { +static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, +DenseSet &CantBePromoted) { + auto *Aliasee = A.getAliaseeObject(); + + // Skip summary for indirect function aliases as summary for aliasee will not + // be emitted. + if (isa(Aliasee)) +return; + bool NonRenamableLocal = isNonRenamableLocal(A); GlobalValueSummary::GVFlags Flags( A.getLinkage(), A.getVisibility(), NonRenamableLocal, /* Live = */ false, A.isDSOLocal(), A.
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
SchrodingerZhu updated this revision to Diff 441898. SchrodingerZhu added a comment. fix test arg 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/lib/Transforms/Utils/FunctionImportUtils.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,31 @@ +; RUN: opt -module-summary -o %t.bc %s +; RUN: llvm-lto2 run %t.bc -r t.bc,foo,px -r t.bc,bar,px -r t.bc,baz,px -r t.bc,qux,px -r t.bc,grault,px -o %t2 +; RUN: llvm-nm %t2.1 | FileCheck %s +; CHECK: i bar +; CHECK: i baz +; CHECK: i foo +; CHECK: t foo_resolver +; CHECK: i grault +; CHECK: i quuz +; CHECK: i qux + +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" + +@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver + +define internal i32 (i32)* @foo_resolver() { +entry: + ret i32 (i32)* null +} + +@bar = alias i32 (i32), i32 (i32)* @foo +@baz = weak alias i32 (i32), i32 (i32)* @foo +@qux = alias i32 (i32), i32 (i32)* @bar + +@quux = internal alias i32 (i32)* (), i32 (i32)* ()* @foo_resolver +@quuz = internal ifunc i32 (i32), i32 (i32)* ()* @quux +@corge = internal alias i32 (i32), i32 (i32)* @quuz +@grault = alias i32 (i32), i32 (i32)* @corge + +; no crash Index: llvm/lib/Transforms/Utils/FunctionImportUtils.cpp === --- llvm/lib/Transforms/Utils/FunctionImportUtils.cpp +++ llvm/lib/Transforms/Utils/FunctionImportUtils.cpp @@ -59,7 +59,13 @@ // in this module. auto Summary = ImportIndex.findSummaryInModule( VI, SGV->getParent()->getModuleIdentifier()); - assert(Summary && "Missing summary for global value when exporting"); + + // It maybe the case that SGV is on a chain of an ifunc, its alias and + // subsequent aliases. In this case, the summary for the value is not + // available. + if (!Summary) +return false; + auto Linkage = Summary->linkage(); if (!GlobalValue::isLocalLinkage(Linkage)) { assert(!isNonRenamableLocal(*SGV) && Index: llvm/lib/Transforms/IPO/FunctionImport.cpp === --- llvm/lib/Transforms/IPO/FunctionImport.cpp +++ llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -1169,10 +1169,13 @@ // recorded in the index using the original name. // FIXME: This may not be needed once PR27866 is fixed. GS = DefinedGlobals.find(GlobalValue::getGUID(OrigName)); -assert(GS != DefinedGlobals.end()); } } -return !GlobalValue::isLocalLinkage(GS->second->linkage()); +// It maybe the case that GV is on a chain of an ifunc, its alias and +// subsequent aliases. In this case, the summary for the value is not +// available. +return GS == DefinedGlobals.end() || + !GlobalValue::isLocalLinkage(GS->second->linkage()); }; // FIXME: See if we can just internalize directly here via linkage changes 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(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 &CantBePromoted) { +static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, +DenseSet &CantBePromoted) { + auto *Aliasee = A.getAliaseeObject(); + + // Skip summary for indirect function aliases as summary for aliasee will not + // be emitted. + if (isa(Aliasee)) +return; + bool NonRenamableLocal = isNonRenamableLocal(A); GlobalValueSummary::GVFlags Flags( A.getLinkage(), A.getVisibility(), NonRenamableLocal, /* Live = */ false, A.isDSOL
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
SchrodingerZhu updated this revision to Diff 441899. SchrodingerZhu added a comment. fix test arg 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/lib/Transforms/Utils/FunctionImportUtils.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,31 @@ +; RUN: opt -module-summary -o %t.bc %s +; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,px -r %t.bc,bar,px -r %t.bc,baz,px -r %t.bc,qux,px -r %t.bc,grault,px -o %t2 +; RUN: llvm-nm %t2.1 | FileCheck %s +; CHECK: i bar +; CHECK: i baz +; CHECK: i foo +; CHECK: t foo_resolver +; CHECK: i grault +; CHECK: i quuz +; CHECK: i qux + +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" + +@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver + +define internal i32 (i32)* @foo_resolver() { +entry: + ret i32 (i32)* null +} + +@bar = alias i32 (i32), i32 (i32)* @foo +@baz = weak alias i32 (i32), i32 (i32)* @foo +@qux = alias i32 (i32), i32 (i32)* @bar + +@quux = internal alias i32 (i32)* (), i32 (i32)* ()* @foo_resolver +@quuz = internal ifunc i32 (i32), i32 (i32)* ()* @quux +@corge = internal alias i32 (i32), i32 (i32)* @quuz +@grault = alias i32 (i32), i32 (i32)* @corge + +; no crash Index: llvm/lib/Transforms/Utils/FunctionImportUtils.cpp === --- llvm/lib/Transforms/Utils/FunctionImportUtils.cpp +++ llvm/lib/Transforms/Utils/FunctionImportUtils.cpp @@ -59,7 +59,13 @@ // in this module. auto Summary = ImportIndex.findSummaryInModule( VI, SGV->getParent()->getModuleIdentifier()); - assert(Summary && "Missing summary for global value when exporting"); + + // It maybe the case that SGV is on a chain of an ifunc, its alias and + // subsequent aliases. In this case, the summary for the value is not + // available. + if (!Summary) +return false; + auto Linkage = Summary->linkage(); if (!GlobalValue::isLocalLinkage(Linkage)) { assert(!isNonRenamableLocal(*SGV) && Index: llvm/lib/Transforms/IPO/FunctionImport.cpp === --- llvm/lib/Transforms/IPO/FunctionImport.cpp +++ llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -1169,10 +1169,13 @@ // recorded in the index using the original name. // FIXME: This may not be needed once PR27866 is fixed. GS = DefinedGlobals.find(GlobalValue::getGUID(OrigName)); -assert(GS != DefinedGlobals.end()); } } -return !GlobalValue::isLocalLinkage(GS->second->linkage()); +// It maybe the case that GV is on a chain of an ifunc, its alias and +// subsequent aliases. In this case, the summary for the value is not +// available. +return GS == DefinedGlobals.end() || + !GlobalValue::isLocalLinkage(GS->second->linkage()); }; // FIXME: See if we can just internalize directly here via linkage changes 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(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 &CantBePromoted) { +static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, +DenseSet &CantBePromoted) { + auto *Aliasee = A.getAliaseeObject(); + + // Skip summary for indirect function aliases as summary for aliasee will not + // be emitted. + if (isa(Aliasee)) +return; + bool NonRenamableLocal = isNonRenamableLocal(A); GlobalValueSummary::GVFlags Flags( A.getLinkage(), A.getVisibility(), NonRenamableLocal, /* Live = */ false, A.i
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
SchrodingerZhu marked an inline comment as done. SchrodingerZhu added a comment. ThinLTO with IFUNC is still Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129009/new/ https://reviews.llvm.org/D129009 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
SchrodingerZhu updated this revision to Diff 441905. SchrodingerZhu added a comment. more clean ups for ifunc logic Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129009/new/ https://reviews.llvm.org/D129009 Files: llvm/include/llvm/IR/GlobalIFunc.h llvm/lib/Analysis/ModuleSummaryAnalysis.cpp llvm/lib/Bitcode/Writer/BitcodeWriter.cpp llvm/lib/IR/Globals.cpp llvm/lib/Transforms/IPO/FunctionImport.cpp llvm/lib/Transforms/Utils/FunctionImportUtils.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,31 @@ +; RUN: opt -module-summary -o %t.bc %s +; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,px -r %t.bc,bar,px -r %t.bc,baz,px -r %t.bc,qux,px -r %t.bc,grault,px -o %t2 +; RUN: llvm-nm %t2.1 | FileCheck %s +; CHECK: i bar +; CHECK: i baz +; CHECK: i foo +; CHECK: t foo_resolver +; CHECK: i grault +; CHECK: i quuz +; CHECK: i qux + +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" + +@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver + +define internal i32 (i32)* @foo_resolver() { +entry: + ret i32 (i32)* null +} + +@bar = alias i32 (i32), i32 (i32)* @foo +@baz = weak alias i32 (i32), i32 (i32)* @foo +@qux = alias i32 (i32), i32 (i32)* @bar + +@quux = internal alias i32 (i32)* (), i32 (i32)* ()* @foo_resolver +@quuz = internal ifunc i32 (i32), i32 (i32)* ()* @quux +@corge = internal alias i32 (i32), i32 (i32)* @quuz +@grault = alias i32 (i32), i32 (i32)* @corge + +; no crash Index: llvm/lib/Transforms/Utils/FunctionImportUtils.cpp === --- llvm/lib/Transforms/Utils/FunctionImportUtils.cpp +++ llvm/lib/Transforms/Utils/FunctionImportUtils.cpp @@ -35,6 +35,13 @@ bool FunctionImportGlobalProcessing::shouldPromoteLocalToGlobal( const GlobalValue *SGV, ValueInfo VI) { assert(SGV->hasLocalLinkage()); + + // ifuncs and ifunc aliasee does not have summary + if (isa(SGV) || + (isa(SGV) && + isa(cast(SGV)->getAliaseeObject( +return false; + // Both the imported references and the original local variable must // be promoted. if (!isPerformingImport() && !isModuleExporting()) Index: llvm/lib/Transforms/IPO/FunctionImport.cpp === --- llvm/lib/Transforms/IPO/FunctionImport.cpp +++ llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -1147,6 +1147,14 @@ // 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 GV is on a chain of an ifunc, its alias and +// subsequent aliases. In this case, the summary for the value is not +// available. +if (isa(&GV) || +(isa(&GV) && + isa(dyn_cast(&GV)->getAliaseeObject( + return true; + // Lookup the linkage recorded in the summaries during global analysis. auto GS = DefinedGlobals.find(GV.getGUID()); if (GS == DefinedGlobals.end()) { @@ -1277,7 +1285,7 @@ } } for (GlobalAlias &GA : SrcModule->aliases()) { - if (!GA.hasName()) + if (!GA.hasName() || isa(GA.getAliaseeObject())) continue; auto GUID = GA.getGUID(); auto Import = ImportGUIDs.count(GUID); Index: llvm/lib/IR/Globals.cpp === --- llvm/lib/IR/Globals.cpp +++ llvm/lib/IR/Globals.cpp @@ -316,32 +316,38 @@ return true; } +template static const GlobalObject * -findBaseObject(const Constant *C, DenseSet &Aliases) { - if (auto *GO = dyn_cast(C)) +findBaseObject(const Constant *C, DenseSet &Aliases, + const Operation &Op) { + if (auto *GO = dyn_cast(C)) { +Op(GO); return GO; - if (auto *GA = dyn_cast(C)) + } + if (auto *GA = dyn_cast(C)) { +Op(GA); if (Aliases.insert(GA).second) - return findBaseObject(GA->getOperand(0), Aliases); + return findBaseObject(GA->getOperand(0), Aliases, Op); + } if (auto *CE = dyn_cast(C)) { switch (CE->getOpcode()) { case Instruction::Add: { - auto *LHS = findBaseObject(CE->getOperand(0), Aliases); - auto *RHS = findBaseObject(CE->getOperand(1), Aliases); + auto *LHS = findBaseObject(CE->getOperand(0), Aliases, Op); + auto *RHS = findBaseObject(CE->getOperand(1), Aliases, Op); if (LHS && RHS) return nullptr; return LHS ? LHS : RHS; } case Instruction::Sub: { - if (findBaseObject(CE->getOperand(1), Aliases)) + if (findBaseObject(CE->getOperand(1), Aliases, Op)) return nullptr; - return findBaseObject(CE->
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
SchrodingerZhu updated this revision to Diff 441906. SchrodingerZhu added a comment. typo Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129009/new/ https://reviews.llvm.org/D129009 Files: llvm/include/llvm/IR/GlobalIFunc.h llvm/lib/Analysis/ModuleSummaryAnalysis.cpp llvm/lib/Bitcode/Writer/BitcodeWriter.cpp llvm/lib/IR/Globals.cpp llvm/lib/Transforms/IPO/FunctionImport.cpp llvm/lib/Transforms/Utils/FunctionImportUtils.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,31 @@ +; RUN: opt -module-summary -o %t.bc %s +; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,px -r %t.bc,bar,px -r %t.bc,baz,px -r %t.bc,qux,px -r %t.bc,grault,px -o %t2 +; RUN: llvm-nm %t2.1 | FileCheck %s +; CHECK: i bar +; CHECK: i baz +; CHECK: i foo +; CHECK: t foo_resolver +; CHECK: i grault +; CHECK: i quuz +; CHECK: i qux + +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" + +@foo = ifunc i32 (i32), i32 (i32)* ()* @foo_resolver + +define internal i32 (i32)* @foo_resolver() { +entry: + ret i32 (i32)* null +} + +@bar = alias i32 (i32), i32 (i32)* @foo +@baz = weak alias i32 (i32), i32 (i32)* @foo +@qux = alias i32 (i32), i32 (i32)* @bar + +@quux = internal alias i32 (i32)* (), i32 (i32)* ()* @foo_resolver +@quuz = internal ifunc i32 (i32), i32 (i32)* ()* @quux +@corge = internal alias i32 (i32), i32 (i32)* @quuz +@grault = alias i32 (i32), i32 (i32)* @corge + +; no crash Index: llvm/lib/Transforms/Utils/FunctionImportUtils.cpp === --- llvm/lib/Transforms/Utils/FunctionImportUtils.cpp +++ llvm/lib/Transforms/Utils/FunctionImportUtils.cpp @@ -35,6 +35,13 @@ bool FunctionImportGlobalProcessing::shouldPromoteLocalToGlobal( const GlobalValue *SGV, ValueInfo VI) { assert(SGV->hasLocalLinkage()); + + // ifuncs and ifunc aliasee does not have summary + if (isa(SGV) || + (isa(SGV) && + isa(cast(SGV)->getAliaseeObject( +return false; + // Both the imported references and the original local variable must // be promoted. if (!isPerformingImport() && !isModuleExporting()) Index: llvm/lib/Transforms/IPO/FunctionImport.cpp === --- llvm/lib/Transforms/IPO/FunctionImport.cpp +++ llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -1147,6 +1147,14 @@ // 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 GV is on a chain of an ifunc, its alias and +// subsequent aliases. In this case, the summary for the value is not +// available. +if (isa(&GV) || +(isa(&GV) && + isa(dyn_cast(&GV)->getAliaseeObject( + return true; + // Lookup the linkage recorded in the summaries during global analysis. auto GS = DefinedGlobals.find(GV.getGUID()); if (GS == DefinedGlobals.end()) { @@ -1277,7 +1285,7 @@ } } for (GlobalAlias &GA : SrcModule->aliases()) { - if (!GA.hasName()) + if (!GA.hasName() || isa(GA.getAliaseeObject())) continue; auto GUID = GA.getGUID(); auto Import = ImportGUIDs.count(GUID); Index: llvm/lib/IR/Globals.cpp === --- llvm/lib/IR/Globals.cpp +++ llvm/lib/IR/Globals.cpp @@ -316,32 +316,38 @@ return true; } +template static const GlobalObject * -findBaseObject(const Constant *C, DenseSet &Aliases) { - if (auto *GO = dyn_cast(C)) +findBaseObject(const Constant *C, DenseSet &Aliases, + const Operation &Op) { + if (auto *GO = dyn_cast(C)) { +Op(GO); return GO; - if (auto *GA = dyn_cast(C)) + } + if (auto *GA = dyn_cast(C)) { +Op(GA); if (Aliases.insert(GA).second) - return findBaseObject(GA->getOperand(0), Aliases); + return findBaseObject(GA->getOperand(0), Aliases, Op); + } if (auto *CE = dyn_cast(C)) { switch (CE->getOpcode()) { case Instruction::Add: { - auto *LHS = findBaseObject(CE->getOperand(0), Aliases); - auto *RHS = findBaseObject(CE->getOperand(1), Aliases); + auto *LHS = findBaseObject(CE->getOperand(0), Aliases, Op); + auto *RHS = findBaseObject(CE->getOperand(1), Aliases, Op); if (LHS && RHS) return nullptr; return LHS ? LHS : RHS; } case Instruction::Sub: { - if (findBaseObject(CE->getOperand(1), Aliases)) + if (findBaseObject(CE->getOperand(1), Aliases, Op)) return nullptr; - return findBaseObject(CE->getOperand(0), Aliases); +
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
SchrodingerZhu added a comment. @MaskRay PTAL Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129009/new/ https://reviews.llvm.org/D129009 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
SchrodingerZhu added a comment. First of all, I am really sorry about the noise and the misbehavior here. I have to admit that some of the changes here are because I am still in the way of getting familiar with the patch system. I apologize for being careless in the progress. > I don't know how you added reviewers or whether you got upset after I clicked > "Request Changes". I am very glad to recieve any review from you and any other member from the team! It is just that I saw you push some commits to the monorepo recently, so I thought that you were too busy to review the patch. Again, I am sorry for the confusion. > I haven't taken a second deep look at this patch but the > applyAlongResolverPath change looks too intrusive to me. One previous version > seems more favorable to me. Back to the patch itself, I made the changes because in the previous version, I assumed that, along the de-aliasing path to the `resolver` object, the immediate instance of `Constant*` need to be `GlobalObject` or `GlobalAlias`; but the `resolver` is stored as a `Constant *`, behind which, according to the implementation of `findBaseObject`, can also be instantiated as `Expr`. I am looking forward to your suggestions, on the code and on how to follow the community conventions better! Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129009/new/ https://reviews.llvm.org/D129009 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
SchrodingerZhu updated this revision to Diff 443503. SchrodingerZhu marked 5 inline comments as done. SchrodingerZhu added a comment. This commit addresses problems mentioned in code reviews: - Fix format and wording for comments - Add more checks with llvm-dis - Adjust code styles for function references, and auto inference. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129009/new/ https://reviews.llvm.org/D129009 Files: llvm/include/llvm/IR/GlobalIFunc.h llvm/lib/Analysis/ModuleSummaryAnalysis.cpp llvm/lib/Bitcode/Writer/BitcodeWriter.cpp llvm/lib/IR/Globals.cpp llvm/lib/Transforms/IPO/FunctionImport.cpp llvm/lib/Transforms/Utils/FunctionImportUtils.cpp llvm/test/ThinLTO/X86/alias-ifunc.ll Index: llvm/test/ThinLTO/X86/alias-ifunc.ll === --- /dev/null +++ llvm/test/ThinLTO/X86/alias-ifunc.ll @@ -0,0 +1,51 @@ +; RUN: opt -module-summary -o %t.bc %s +; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-BAR +; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-BAZ +; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-QUX +; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-RESOLVER +; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-QUUX +; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-CORGE +; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-GRAULT +; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,px -r %t.bc,bar,px -r %t.bc,baz,px -r %t.bc,qux,px -r %t.bc,grault,px -o %t2 +; RUN: llvm-nm %t2.1 | FileCheck %s --check-prefix=CHECK-SYMBOL +; CHECK-SYMBOL: i bar +; CHECK-SYMBOL: i baz +; CHECK-SYMBOL: i foo +; CHECK-SYMBOL: t foo_resolver +; CHECK-SYMBOL: i grault +; CHECK-SYMBOL: i quuz +; CHECK-SYMBOL: i qux + +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" +@foo = ifunc i32 (i32), ptr @foo_resolver +; CHECK-RESOLVER: (name: "foo_resolver" +; CHECK-RESOLVER-SAME: live: 1 +define internal i32 (i32)* @foo_resolver() { +entry: + ret i32 (i32)* null +} +; CHECK-BAR: (name: "bar" +; CHECK-BAR-NOT: summaries: ( +; CHECK-BAR-SAME: ; guid = {{[0-9]+}} +@bar = alias i32 (i32), ptr @foo +; CHECK-BAZ: (name: "baz" +; CHECK-BAZ-NOT: summaries: ( +; CHECK-BAZ-SAME: ; guid = {{[0-9]+}} +@baz = weak alias i32 (i32), ptr @foo +; CHECK-QUX: (name: "qux" +; CHECK-QUX-NOT: summaries: ( +; CHECK-QUX-SAME: ; guid = {{[0-9]+}} +@qux = alias i32 (i32), ptr @bar +; CHECK-QUUX: (name: "quux" +; CHECK-QUUX-SAME: live: 1 +@quux = internal alias i32 (i32)* (), ptr @foo_resolver +@quuz = internal ifunc i32 (i32), ptr @quux +; CHECK-CORGE: (name: "corge" +; CHECK-CORGE-NOT: summaries: ( +; CHECK-CORGE-SAME: ; guid = {{[0-9]+}} +@corge = internal alias i32 (i32), ptr @quuz +; CHECK-GRAULT: (name: "grault" +; CHECK-GRAULT-NOT: summaries: ( +; CHECK-GRAULT-SAME: ; guid = {{[0-9]+}} +@grault = alias i32 (i32), ptr @corge Index: llvm/lib/Transforms/Utils/FunctionImportUtils.cpp === --- llvm/lib/Transforms/Utils/FunctionImportUtils.cpp +++ llvm/lib/Transforms/Utils/FunctionImportUtils.cpp @@ -35,6 +35,13 @@ bool FunctionImportGlobalProcessing::shouldPromoteLocalToGlobal( const GlobalValue *SGV, ValueInfo VI) { assert(SGV->hasLocalLinkage()); + + // Ifuncs and ifunc alias does not have summary. + if (isa(SGV) || + (isa(SGV) && + isa(cast(SGV)->getAliaseeObject( +return false; + // Both the imported references and the original local variable must // be promoted. if (!isPerformingImport() && !isModuleExporting()) Index: llvm/lib/Transforms/IPO/FunctionImport.cpp === --- llvm/lib/Transforms/IPO/FunctionImport.cpp +++ llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -1147,6 +1147,14 @@ // 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 may be the case that GV is on a chain of an ifunc, its alias and +// subsequent aliases. In this case, the summary for the value is not +// available. +if (isa(&GV) || +(isa(&GV) && + isa(cast(&GV)->getAliaseeObject( + return true; + // Lookup the linkage recorded in the summaries during global analysis. auto GS = DefinedGlobals.find(GV.getGUID()); if (GS == DefinedGlobals.end()) { @@ -1277,7 +1285,7 @@ } } for (GlobalAlias &GA : SrcModule->aliases()) { - if (!GA.hasName()) + if (!GA.hasName() || isa(GA.getAliaseeObject())) continue; auto GUID = GA.getGUID(); auto Import = ImportGUIDs.count(GUID); Index: llvm/lib/IR/Globals.cpp === --- llvm/lib/IR/Globals.cpp +++ ll
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
SchrodingerZhu updated this revision to Diff 443536. SchrodingerZhu added a comment. This commit addresses issues mentioned in code reviews: - change applyAlongResolverPath to use reference since the pointer is supposed to be non-null. - update test format to align check rules under the same prefix. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129009/new/ https://reviews.llvm.org/D129009 Files: llvm/include/llvm/IR/GlobalIFunc.h llvm/lib/Analysis/ModuleSummaryAnalysis.cpp llvm/lib/Bitcode/Writer/BitcodeWriter.cpp llvm/lib/IR/Globals.cpp llvm/lib/Transforms/IPO/FunctionImport.cpp llvm/lib/Transforms/Utils/FunctionImportUtils.cpp llvm/test/ThinLTO/X86/alias-ifunc.ll Index: llvm/test/ThinLTO/X86/alias-ifunc.ll === --- /dev/null +++ llvm/test/ThinLTO/X86/alias-ifunc.ll @@ -0,0 +1,51 @@ +; RUN: opt -module-summary -o %t.bc %s +; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-BAR +; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-BAZ +; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-QUX +; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-RESOLVER +; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-QUUX +; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-CORGE +; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-GRAULT +; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,px -r %t.bc,bar,px -r %t.bc,baz,px -r %t.bc,qux,px -r %t.bc,grault,px -o %t2 +; RUN: llvm-nm %t2.1 | FileCheck %s --check-prefix=CHECK-SYMBOL +; CHECK-SYMBOL: i bar +; CHECK-SYMBOL: i baz +; CHECK-SYMBOL: i foo +; CHECK-SYMBOL: t foo_resolver +; CHECK-SYMBOL: i grault +; CHECK-SYMBOL: i quuz +; CHECK-SYMBOL: i qux + +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" +@foo = ifunc i32 (i32), ptr @foo_resolver +; CHECK-RESOLVER: (name: "foo_resolver" +; CHECK-RESOLVER-SAME: live: 1 +define internal i32 (i32)* @foo_resolver() { +entry: + ret i32 (i32)* null +} +; CHECK-BAR: (name: "bar" +; CHECK-BAR-NOT: summaries: ( +; CHECK-BAR-SAME: ; guid = {{[0-9]+}} +@bar = alias i32 (i32), ptr @foo +; CHECK-BAZ: (name: "baz" +; CHECK-BAZ-NOT: summaries: ( +; CHECK-BAZ-SAME: ; guid = {{[0-9]+}} +@baz = weak alias i32 (i32), ptr @foo +; CHECK-QUX: (name: "qux" +; CHECK-QUX-NOT: summaries: ( +; CHECK-QUX-SAME: ; guid = {{[0-9]+}} +@qux = alias i32 (i32), ptr @bar +; CHECK-QUUX: (name: "quux" +; CHECK-QUUX-SAME: live: 1 +@quux = internal alias i32 (i32)* (), ptr @foo_resolver +@quuz = internal ifunc i32 (i32), ptr @quux +; CHECK-CORGE: (name: "corge" +; CHECK-CORGE-NOT: summaries: ( +; CHECK-CORGE-SAME: ; guid = {{[0-9]+}} +@corge = internal alias i32 (i32), ptr @quuz +; CHECK-GRAULT: (name: "grault" +; CHECK-GRAULT-NOT: summaries: ( +; CHECK-GRAULT-SAME: ; guid = {{[0-9]+}} +@grault = alias i32 (i32), ptr @corge Index: llvm/lib/Transforms/Utils/FunctionImportUtils.cpp === --- llvm/lib/Transforms/Utils/FunctionImportUtils.cpp +++ llvm/lib/Transforms/Utils/FunctionImportUtils.cpp @@ -35,6 +35,13 @@ bool FunctionImportGlobalProcessing::shouldPromoteLocalToGlobal( const GlobalValue *SGV, ValueInfo VI) { assert(SGV->hasLocalLinkage()); + + // Ifuncs and ifunc alias does not have summary. + if (isa(SGV) || + (isa(SGV) && + isa(cast(SGV)->getAliaseeObject( +return false; + // Both the imported references and the original local variable must // be promoted. if (!isPerformingImport() && !isModuleExporting()) Index: llvm/lib/Transforms/IPO/FunctionImport.cpp === --- llvm/lib/Transforms/IPO/FunctionImport.cpp +++ llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -1147,6 +1147,14 @@ // 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 may be the case that GV is on a chain of an ifunc, its alias and +// subsequent aliases. In this case, the summary for the value is not +// available. +if (isa(&GV) || +(isa(&GV) && + isa(cast(&GV)->getAliaseeObject( + return true; + // Lookup the linkage recorded in the summaries during global analysis. auto GS = DefinedGlobals.find(GV.getGUID()); if (GS == DefinedGlobals.end()) { @@ -1277,7 +1285,7 @@ } } for (GlobalAlias &GA : SrcModule->aliases()) { - if (!GA.hasName()) + if (!GA.hasName() || isa(GA.getAliaseeObject())) continue; auto GUID = GA.getGUID(); auto Import = ImportGUIDs.count(GUID); Index: llvm/lib/IR/Globals.cpp === --- llvm/lib/IR/Glob
[PATCH] D129009: [LTO] Fix LTO for aliased IFuncs
SchrodingerZhu added a comment. Hi, is there anything else I should do for this patch? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129009/new/ https://reviews.llvm.org/D129009 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits