Skip to content

Commit

Permalink
[Attributor] Provide an edge-based interface in AAIsDead
Browse files Browse the repository at this point in the history
This patch produces an edge-based interface in AAIsDead.
By this, we can query a set of basic blocks that are directly reachable from a given basic block.
This is specifically useful for implementation of AAReachability.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D85547
  • Loading branch information
okuraofvegetable committed Aug 26, 2020
1 parent 3b75f65 commit 3050713
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions llvm/include/llvm/Transforms/IPO/Attributor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2646,6 +2646,12 @@ struct AAIsDead : public StateWrapper<BooleanState, AbstractAttribute> {
return F.hasPersonalityFn() && !canSimplifyInvokeNoUnwind(&F);
}

/// Return if the edge from \p From BB to \p To BB is assumed dead.
/// This is specifically useful in AAReachability.
virtual bool isEdgeDead(const BasicBlock *From, const BasicBlock *To) const {
return false;
}

/// See AbstractAttribute::getName()
const std::string getName() const override { return "AAIsDead"; }

Expand Down
10 changes: 10 additions & 0 deletions llvm/lib/Transforms/IPO/AttributorAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3093,6 +3093,10 @@ struct AAIsDeadFunction : public AAIsDead {
/// See AbstractAttribute::updateImpl(...).
ChangeStatus updateImpl(Attributor &A) override;

bool isEdgeDead(const BasicBlock *From, const BasicBlock *To) const override {
return !AssumedLiveEdges.count(std::make_pair(From, To));
}

/// See AbstractAttribute::trackStatistics()
void trackStatistics() const override {}

Expand Down Expand Up @@ -3170,6 +3174,9 @@ struct AAIsDeadFunction : public AAIsDead {
/// Collection of instructions that are known to not transfer control.
SmallSetVector<const Instruction *, 8> KnownDeadEnds;

/// Collection of all assumed live edges
DenseSet<std::pair<const BasicBlock *, const BasicBlock *>> AssumedLiveEdges;

/// Collection of all assumed live BasicBlocks.
DenseSet<const BasicBlock *> AssumedLiveBlocks;
};
Expand Down Expand Up @@ -3340,6 +3347,9 @@ ChangeStatus AAIsDeadFunction::updateImpl(Attributor &A) {
"Non-terminator expected to have a single successor!");
Worklist.push_back(AliveSuccessor);
} else {
// record the assumed live edge
AssumedLiveEdges.insert(
std::make_pair(I->getParent(), AliveSuccessor->getParent()));
if (assumeLive(A, *AliveSuccessor->getParent()))
Worklist.push_back(AliveSuccessor);
}
Expand Down

0 comments on commit 3050713

Please sign in to comment.