[llvm] bed6a6e - [Attributor][NFC] Make the MustBeExecutedContextExplorer optional
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 13 16:50:19 PDT 2023
Author: Johannes Doerfert
Date: 2023-06-13T16:49:56-07:00
New Revision: bed6a6e7e06bd3a5a5af15d7a6935d3ba2dc0da4
URL: https://github.com/llvm/llvm-project/commit/bed6a6e7e06bd3a5a5af15d7a6935d3ba2dc0da4
DIFF: https://github.com/llvm/llvm-project/commit/bed6a6e7e06bd3a5a5af15d7a6935d3ba2dc0da4.diff
LOG: [Attributor][NFC] Make the MustBeExecutedContextExplorer optional
For a lightweight pass we do not want to instantiate or use the
MustBeExecutedContextExplorer. This simply allows such a configuration.
While at it, the explorer is now allocated with the bump allocator.
Added:
Modified:
llvm/include/llvm/Transforms/IPO/Attributor.h
llvm/lib/Transforms/IPO/Attributor.cpp
llvm/lib/Transforms/IPO/AttributorAttributes.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h
index 90ed050dde9b7..365301a7e5e9b 100644
--- a/llvm/include/llvm/Transforms/IPO/Attributor.h
+++ b/llvm/include/llvm/Transforms/IPO/Attributor.h
@@ -1164,24 +1164,26 @@ constexpr bool AnalysisGetter::HasLegacyWrapper<
/// instance down in the abstract attributes.
struct InformationCache {
InformationCache(const Module &M, AnalysisGetter &AG,
- BumpPtrAllocator &Allocator, SetVector<Function *> *CGSCC)
- : DL(M.getDataLayout()), Allocator(Allocator),
- Explorer(
- /* ExploreInterBlock */ true, /* ExploreCFGForward */ true,
- /* ExploreCFGBackward */ true,
- /* LIGetter */
- [&](const Function &F) { return AG.getAnalysis<LoopAnalysis>(F); },
- /* DTGetter */
- [&](const Function &F) {
- return AG.getAnalysis<DominatorTreeAnalysis>(F);
- },
- /* PDTGetter */
- [&](const Function &F) {
- return AG.getAnalysis<PostDominatorTreeAnalysis>(F);
- }),
- AG(AG), TargetTriple(M.getTargetTriple()) {
+ BumpPtrAllocator &Allocator, SetVector<Function *> *CGSCC,
+ bool UseExplorer = true)
+ : DL(M.getDataLayout()), Allocator(Allocator), AG(AG),
+ TargetTriple(M.getTargetTriple()) {
if (CGSCC)
initializeModuleSlice(*CGSCC);
+ if (UseExplorer)
+ Explorer = new (Allocator) MustBeExecutedContextExplorer(
+ /* ExploreInterBlock */ true, /* ExploreCFGForward */ true,
+ /* ExploreCFGBackward */ true,
+ /* LIGetter */
+ [&](const Function &F) { return AG.getAnalysis<LoopAnalysis>(F); },
+ /* DTGetter */
+ [&](const Function &F) {
+ return AG.getAnalysis<DominatorTreeAnalysis>(F);
+ },
+ /* PDTGetter */
+ [&](const Function &F) {
+ return AG.getAnalysis<PostDominatorTreeAnalysis>(F);
+ });
}
~InformationCache() {
@@ -1193,6 +1195,8 @@ struct InformationCache {
using AA::InstExclusionSetTy;
for (auto *BES : BESets)
BES->~InstExclusionSetTy();
+ if (Explorer)
+ Explorer->~MustBeExecutedContextExplorer();
}
/// Apply \p CB to all uses of \p F. If \p LookThroughConstantExprUses is
@@ -1275,7 +1279,7 @@ struct InformationCache {
}
/// Return MustBeExecutedContextExplorer
- MustBeExecutedContextExplorer &getMustBeExecutedContextExplorer() {
+ MustBeExecutedContextExplorer *getMustBeExecutedContextExplorer() {
return Explorer;
}
@@ -1381,7 +1385,7 @@ struct InformationCache {
BumpPtrAllocator &Allocator;
/// MustBeExecutedContextExplorer
- MustBeExecutedContextExplorer Explorer;
+ MustBeExecutedContextExplorer *Explorer = nullptr;
/// A map with knowledge retained in `llvm.assume` instructions.
RetainedKnowledgeMap KnowledgeMap;
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index df8cb5c3ee902..5e3c2f92730df 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -1204,11 +1204,13 @@ bool IRPosition::getAttrsFromAssumes(Attribute::AttrKind AK,
LLVMContext &Ctx = AssociatedValue.getContext();
unsigned AttrsSize = Attrs.size();
- MustBeExecutedContextExplorer &Explorer =
+ MustBeExecutedContextExplorer *Explorer =
A.getInfoCache().getMustBeExecutedContextExplorer();
- auto EIt = Explorer.begin(getCtxI()), EEnd = Explorer.end(getCtxI());
+ if (!Explorer)
+ return false;
+ auto EIt = Explorer->begin(getCtxI()), EEnd = Explorer->end(getCtxI());
for (const auto &It : A2K)
- if (Explorer.findInContextOf(It.first, EIt, EEnd))
+ if (Explorer->findInContextOf(It.first, EIt, EEnd))
Attrs.push_back(Attribute::get(Ctx, AK, It.second.Max));
return AttrsSize != Attrs.size();
}
diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index 75ddda689dfeb..58297b5fdc9c8 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -607,10 +607,12 @@ static void followUsesInMBEC(AAType &AA, Attributor &A, StateType &S,
for (const Use &U : AA.getIRPosition().getAssociatedValue().uses())
Uses.insert(&U);
- MustBeExecutedContextExplorer &Explorer =
+ MustBeExecutedContextExplorer *Explorer =
A.getInfoCache().getMustBeExecutedContextExplorer();
+ if (!Explorer)
+ return;
- followUsesInContext<AAType>(AA, A, Explorer, &CtxI, Uses, S);
+ followUsesInContext<AAType>(AA, A, *Explorer, &CtxI, Uses, S);
if (S.isAtFixpoint())
return;
@@ -655,7 +657,7 @@ static void followUsesInMBEC(AAType &AA, Attributor &A, StateType &S,
// }
// }
- Explorer.checkForAllContext(&CtxI, Pred);
+ Explorer->checkForAllContext(&CtxI, Pred);
for (const BranchInst *Br : BrInsts) {
StateType ParentState;
@@ -667,7 +669,7 @@ static void followUsesInMBEC(AAType &AA, Attributor &A, StateType &S,
StateType ChildState;
size_t BeforeSize = Uses.size();
- followUsesInContext(AA, A, Explorer, &BB->front(), Uses, ChildState);
+ followUsesInContext(AA, A, *Explorer, &BB->front(), Uses, ChildState);
// Erase uses which only appear in the child.
for (auto It = Uses.begin() + BeforeSize; It != Uses.end();)
@@ -7022,7 +7024,7 @@ ChangeStatus AAHeapToStackFunction::updateImpl(Attributor &A) {
const auto &LivenessAA =
A.getAAFor<AAIsDead>(*this, IRPosition::function(*F), DepClassTy::NONE);
- MustBeExecutedContextExplorer &Explorer =
+ MustBeExecutedContextExplorer *Explorer =
A.getInfoCache().getMustBeExecutedContextExplorer();
bool StackIsAccessibleByOtherThreads =
@@ -7148,7 +7150,7 @@ ChangeStatus AAHeapToStackFunction::updateImpl(Attributor &A) {
return false;
}
Instruction *CtxI = isa<InvokeInst>(AI.CB) ? AI.CB : AI.CB->getNextNode();
- if (!Explorer.findInContextOf(UniqueFree, CtxI)) {
+ if (!Explorer || !Explorer->findInContextOf(UniqueFree, CtxI)) {
LLVM_DEBUG(
dbgs()
<< "[H2S] unique free call might not be executed with the allocation "
More information about the llvm-commits
mailing list