From 47552a614a8c95e1817d83755a4a6a2508da7f8a Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Thu, 6 Aug 2020 05:28:03 -0700 Subject: [PATCH] [StackSafety] Change how callee searched in index Handle other than local linkage types. --- llvm/lib/Analysis/StackSafetyAnalysis.cpp | 64 ++++++++++++++++++++------- llvm/test/Analysis/StackSafetyAnalysis/ipa.ll | 4 +- 2 files changed, 49 insertions(+), 19 deletions(-) diff --git a/llvm/lib/Analysis/StackSafetyAnalysis.cpp b/llvm/lib/Analysis/StackSafetyAnalysis.cpp index f613639..0a8a4cc 100644 --- a/llvm/lib/Analysis/StackSafetyAnalysis.cpp +++ b/llvm/lib/Analysis/StackSafetyAnalysis.cpp @@ -52,6 +52,10 @@ STATISTIC(NumCombinedParamAccessesAfter, "Number of total param accesses after generateParamAccessSummary."); STATISTIC(NumCombinedDataFlowNodes, "Number of total nodes in combined index for dataflow processing."); +STATISTIC(NumIndexCalleeUnhandled, "Number of index callee which are unhandled."); +STATISTIC(NumIndexCalleeMultipleWeak, "Number of index callee non-unique weak."); +STATISTIC(NumIndexCalleeMultipleExternal, "Number of index callee non-unique external."); + static cl::opt StackSafetyMaxIterations("stack-safety-max-iterations", cl::init(20), cl::Hidden); @@ -604,7 +608,45 @@ StackSafetyDataFlowAnalysis::run() { return Functions; } -FunctionSummary *resolveCallee(GlobalValueSummary *S) { +FunctionSummary *findCalleeFunctionSummary(ValueInfo VI, StringRef ModuleId) { + if (!VI) + return nullptr; + auto SummaryList = VI.getSummaryList(); + GlobalValueSummary* S = nullptr; + for (const auto& GVS : SummaryList) { + if (!GVS->isLive()) + continue; + if (const AliasSummary *AS = dyn_cast(GVS.get())) + if (!AS->hasAliasee()) + continue; + if (!isa(GVS->getBaseObject())) + continue; + if (GlobalValue::isLocalLinkage(GVS->linkage())) { + if (GVS->modulePath() == ModuleId) { + S = GVS.get(); + break; + } + } else if (GlobalValue::isExternalLinkage(GVS->linkage())) { + if (S) { + ++NumIndexCalleeMultipleExternal; + return nullptr; + } + S = GVS.get(); + } else if (GlobalValue::isWeakLinkage(GVS->linkage())) { + if (S) { + ++NumIndexCalleeMultipleWeak; + return nullptr; + } + S = GVS.get(); + } else if (GlobalValue::isAvailableExternallyLinkage(GVS->linkage()) || + GlobalValue::isLinkOnceLinkage(GVS->linkage())) { + if (SummaryList.size() == 1) + S = GVS.get(); + // According thinLTOResolvePrevailingGUID these are unlikely prevailing. + } else { + ++NumIndexCalleeUnhandled; + } + }; while (S) { if (!S->isLive() || !S->isDSOLocal()) return nullptr; @@ -636,15 +678,6 @@ const Function *findCalleeInModule(const GlobalValue *GV) { return nullptr; } -GlobalValueSummary *getGlobalValueSummary(const ModuleSummaryIndex *Index, - uint64_t ValueGUID) { - auto VI = Index->getValueInfo(ValueGUID); - if (!VI || VI.getSummaryList().empty()) - return nullptr; - auto &Summary = VI.getSummaryList()[0]; - return Summary.get(); -} - const ConstantRange *findParamAccess(const FunctionSummary &FS, uint32_t ParamNo) { assert(FS.isLive()); @@ -668,10 +701,9 @@ void resolveAllCalls(UseInfo &Use, if (!Index) return Use.updateRange(FullSet); - GlobalValueSummary *GVS = - getGlobalValueSummary(Index, C.first.Callee->getGUID()); - - FunctionSummary *FS = resolveCallee(GVS); + FunctionSummary *FS = + findCalleeFunctionSummary(Index->getValueInfo(C.first.Callee->getGUID()), + C.first.Callee->getParent()->getModuleIdentifier()); ++NumModuleCalleeLookupTotal; if (!FS) { ++NumModuleCalleeLookupFailed; @@ -997,8 +1029,8 @@ void llvm::generateParamAccessSummary(ModuleSummaryIndex &Index) { US.Range = PS.Use; for (auto &Call : PS.Calls) { assert(!Call.Offsets.isFullSet()); - FunctionSummary *S = resolveCallee( - Index.findSummaryInModule(Call.Callee, FS->modulePath())); + FunctionSummary *S = + findCalleeFunctionSummary(Call.Callee, FS->modulePath()); ++NumCombinedCalleeLookupTotal; if (!S) { ++NumCombinedCalleeLookupFailed; diff --git a/llvm/test/Analysis/StackSafetyAnalysis/ipa.ll b/llvm/test/Analysis/StackSafetyAnalysis/ipa.ll index 6be426f..a610f1b 100644 --- a/llvm/test/Analysis/StackSafetyAnalysis/ipa.ll +++ b/llvm/test/Analysis/StackSafetyAnalysis/ipa.ll @@ -469,14 +469,12 @@ entry: ret void } -; FIXME: LTO should match NOLTO define void @TestCrossModuleTwice() #0 { ; CHECK-DAG: @TestCrossModuleTwice dso_preemptable{{$}} ; CHECK-NEXT: args uses: ; CHECK-NEXT: allocas uses: ; LOCAL-NEXT: z[1]: empty-set, @Write1DiffModule(arg0, [0,1)){{$}} -; NOLTO-NEXT: z[1]: [0,1), @Write1DiffModule(arg0, [0,1)){{$}} -; LTO-NEXT: z[1]: full-set, @Write1DiffModule(arg0, [0,1)){{$}} +; GLOBAL-NEXT: z[1]: [0,1), @Write1DiffModule(arg0, [0,1)){{$}} ; CHECK-EMPTY: entry: %z = alloca i8, align 4 -- 2.7.4