1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00

[StackSafety] Change how callee searched in index

Handle other than local linkage types.
This commit is contained in:
Vitaly Buka 2020-08-06 05:28:03 -07:00
parent 85ebf04519
commit 7e7fd55416
2 changed files with 49 additions and 19 deletions

View File

@ -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<int> StackSafetyMaxIterations("stack-safety-max-iterations",
cl::init(20), cl::Hidden);
@ -604,7 +608,45 @@ StackSafetyDataFlowAnalysis<CalleeTy>::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<AliasSummary>(GVS.get()))
if (!AS->hasAliasee())
continue;
if (!isa<FunctionSummary>(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<GlobalValue> &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;

View File

@ -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