mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-04 03:44:59 +00:00
[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.
This commit is contained in:
parent
d8562e27e0
commit
bed6a6e7e0
@ -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 @@ private:
|
||||
BumpPtrAllocator &Allocator;
|
||||
|
||||
/// MustBeExecutedContextExplorer
|
||||
MustBeExecutedContextExplorer Explorer;
|
||||
MustBeExecutedContextExplorer *Explorer = nullptr;
|
||||
|
||||
/// A map with knowledge retained in `llvm.assume` instructions.
|
||||
RetainedKnowledgeMap KnowledgeMap;
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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 "
|
||||
|
Loading…
Reference in New Issue
Block a user