aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2021-08-22 19:00:43 +0000
committerDimitry Andric <dim@FreeBSD.org>2021-11-13 20:39:49 +0000
commitfe6060f10f634930ff71b7c50291ddc610da2475 (patch)
tree1483580c790bd4d27b6500a7542b5ee00534d3cc /contrib/llvm-project/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
parentb61bce17f346d79cecfd8f195a64b10f77be43b1 (diff)
parent344a3780b2e33f6ca763666c380202b18aab72a3 (diff)
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp63
1 files changed, 30 insertions, 33 deletions
diff --git a/contrib/llvm-project/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/contrib/llvm-project/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
index 5f7746eeed15..e43553222128 100644
--- a/contrib/llvm-project/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ b/contrib/llvm-project/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -50,6 +50,7 @@
#include "llvm/Pass.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
@@ -91,14 +92,11 @@ static bool findRefEdges(ModuleSummaryIndex &Index, const User *CurUser,
SmallPtrSet<const User *, 8> &Visited) {
bool HasBlockAddress = false;
SmallVector<const User *, 32> Worklist;
- Worklist.push_back(CurUser);
+ if (Visited.insert(CurUser).second)
+ Worklist.push_back(CurUser);
while (!Worklist.empty()) {
const User *U = Worklist.pop_back_val();
-
- if (!Visited.insert(U).second)
- continue;
-
const auto *CB = dyn_cast<CallBase>(U);
for (const auto &OI : U->operands()) {
@@ -117,7 +115,8 @@ static bool findRefEdges(ModuleSummaryIndex &Index, const User *CurUser,
RefEdges.insert(Index.getOrInsertValueInfo(GV));
continue;
}
- Worklist.push_back(Operand);
+ if (Visited.insert(Operand).second)
+ Worklist.push_back(Operand);
}
}
return HasBlockAddress;
@@ -178,11 +177,7 @@ static void addIntrinsicToSummary(
// Intrinsics that are assumed are relevant only to the devirtualization
// pass, not the type test lowering pass.
bool HasNonAssumeUses = llvm::any_of(CI->uses(), [](const Use &CIU) {
- auto *AssumeCI = dyn_cast<CallInst>(CIU.getUser());
- if (!AssumeCI)
- return true;
- Function *F = AssumeCI->getCalledFunction();
- return !F || F->getIntrinsicID() != Intrinsic::assume;
+ return !isa<AssumeInst>(CIU.getUser());
});
if (HasNonAssumeUses)
TypeTests.insert(Guid);
@@ -459,9 +454,10 @@ static void computeFunctionSummary(
bool NonRenamableLocal = isNonRenamableLocal(F);
bool NotEligibleForImport =
NonRenamableLocal || HasInlineAsmMaybeReferencingInternal;
- GlobalValueSummary::GVFlags Flags(F.getLinkage(), NotEligibleForImport,
- /* Live = */ false, F.isDSOLocal(),
- F.hasLinkOnceODRLinkage() && F.hasGlobalUnnamedAddr());
+ GlobalValueSummary::GVFlags Flags(
+ F.getLinkage(), F.getVisibility(), NotEligibleForImport,
+ /* Live = */ false, F.isDSOLocal(),
+ F.hasLinkOnceODRLinkage() && F.hasGlobalUnnamedAddr());
FunctionSummary::FFlags FunFlags{
F.hasFnAttribute(Attribute::ReadNone),
F.hasFnAttribute(Attribute::ReadOnly),
@@ -510,10 +506,8 @@ static void findFuncPointers(const Constant *I, uint64_t StartingOffset,
assert(STy);
const StructLayout *SL = DL.getStructLayout(C->getType());
- for (StructType::element_iterator EB = STy->element_begin(), EI = EB,
- EE = STy->element_end();
- EI != EE; ++EI) {
- auto Offset = SL->getElementOffset(EI - EB);
+ for (auto EI : llvm::enumerate(STy->elements())) {
+ auto Offset = SL->getElementOffset(EI.index());
unsigned Op = SL->getElementContainingOffset(Offset);
findFuncPointers(cast<Constant>(I->getOperand(Op)),
StartingOffset + Offset, M, Index, VTableFuncs);
@@ -580,9 +574,10 @@ static void computeVariableSummary(ModuleSummaryIndex &Index,
SmallPtrSet<const User *, 8> Visited;
bool HasBlockAddress = findRefEdges(Index, &V, RefEdges, Visited);
bool NonRenamableLocal = isNonRenamableLocal(V);
- GlobalValueSummary::GVFlags Flags(V.getLinkage(), NonRenamableLocal,
- /* Live = */ false, V.isDSOLocal(),
- V.hasLinkOnceODRLinkage() && V.hasGlobalUnnamedAddr());
+ GlobalValueSummary::GVFlags Flags(
+ V.getLinkage(), V.getVisibility(), NonRenamableLocal,
+ /* Live = */ false, V.isDSOLocal(),
+ V.hasLinkOnceODRLinkage() && V.hasGlobalUnnamedAddr());
VTableFuncList VTableFuncs;
// If splitting is not enabled, then we compute the summary information
@@ -622,9 +617,10 @@ static void
computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A,
DenseSet<GlobalValue::GUID> &CantBePromoted) {
bool NonRenamableLocal = isNonRenamableLocal(A);
- GlobalValueSummary::GVFlags Flags(A.getLinkage(), NonRenamableLocal,
- /* Live = */ false, A.isDSOLocal(),
- A.hasLinkOnceODRLinkage() && A.hasGlobalUnnamedAddr());
+ GlobalValueSummary::GVFlags Flags(
+ A.getLinkage(), A.getVisibility(), NonRenamableLocal,
+ /* Live = */ false, A.isDSOLocal(),
+ A.hasLinkOnceODRLinkage() && A.hasGlobalUnnamedAddr());
auto AS = std::make_unique<AliasSummary>(Flags);
auto *Aliasee = A.getBaseObject();
auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
@@ -661,12 +657,12 @@ ModuleSummaryIndex llvm::buildModuleSummaryIndex(
// promotion, but we may have opaque uses e.g. in inline asm. We collect them
// here because we use this information to mark functions containing inline
// assembly calls as not importable.
- SmallPtrSet<GlobalValue *, 8> LocalsUsed;
- SmallPtrSet<GlobalValue *, 8> Used;
+ SmallPtrSet<GlobalValue *, 4> LocalsUsed;
+ SmallVector<GlobalValue *, 4> Used;
// First collect those in the llvm.used set.
- collectUsedGlobalVariables(M, Used, /*CompilerUsed*/ false);
+ collectUsedGlobalVariables(M, Used, /*CompilerUsed=*/false);
// Next collect those in the llvm.compiler.used set.
- collectUsedGlobalVariables(M, Used, /*CompilerUsed*/ true);
+ collectUsedGlobalVariables(M, Used, /*CompilerUsed=*/true);
DenseSet<GlobalValue::GUID> CantBePromoted;
for (auto *V : Used) {
if (V->hasLocalLinkage()) {
@@ -697,11 +693,12 @@ ModuleSummaryIndex llvm::buildModuleSummaryIndex(
if (!GV)
return;
assert(GV->isDeclaration() && "Def in module asm already has definition");
- GlobalValueSummary::GVFlags GVFlags(GlobalValue::InternalLinkage,
- /* NotEligibleToImport = */ true,
- /* Live = */ true,
- /* Local */ GV->isDSOLocal(),
- GV->hasLinkOnceODRLinkage() && GV->hasGlobalUnnamedAddr());
+ GlobalValueSummary::GVFlags GVFlags(
+ GlobalValue::InternalLinkage, GlobalValue::DefaultVisibility,
+ /* NotEligibleToImport = */ true,
+ /* Live = */ true,
+ /* Local */ GV->isDSOLocal(),
+ GV->hasLinkOnceODRLinkage() && GV->hasGlobalUnnamedAddr());
CantBePromoted.insert(GV->getGUID());
// Create the appropriate summary type.
if (Function *F = dyn_cast<Function>(GV)) {