[Mlir-commits] [mlir] [mlir][IR] Add `Block::isReachable` helper function (PR #114928)
Mehdi Amini
llvmlistbot at llvm.org
Wed Nov 6 14:01:24 PST 2024
================
@@ -349,6 +352,23 @@ SuccessorRange::SuccessorRange(Operation *term) : SuccessorRange() {
base = term->getBlockOperands().data();
}
+bool Block::isReachable(Block *other, ArrayRef<Block *> except) {
+ assert(getParent() == other->getParent() && "expected same region");
+ SmallVector<Block *> worklist(succ_begin(), succ_end());
+ SmallPtrSet<Block *, 16> visited;
+ while (!worklist.empty()) {
+ Block *next = worklist.pop_back_val();
+ if (llvm::is_contained(except, next))
+ continue;
----------------
joker-eph wrote:
This is a linear search, should this be the last check of the three?
https://github.com/llvm/llvm-project/pull/114928
More information about the Mlir-commits
mailing list