[Mlir-commits] [mlir] [MLIR] Prevent CF to SCF transform from erasing blocks still in use (PR #206310)
Martin P
llvmlistbot at llvm.org
Wed Jul 1 04:26:06 PDT 2026
================
@@ -1234,10 +1234,24 @@ static ReturnLikeExitCombiner createSingleExitBlocksForReturnLike(
/// Returns failure if any precondition is violated.
static LogicalResult
checkTransformationPreconditions(Region ®ion, CFGToSCFInterface &interface) {
- for (Block &block : region.getBlocks())
- if (block.hasNoPredecessors() && !block.isEntryBlock())
+ const auto reachableBlocks = [®ion] {
+ SmallVector<Block *, 16> workList = {®ion.front()};
+ SmallPtrSet<Block *, 16> visited = {®ion.front()};
+ while (!workList.empty()) {
+ Block *current = workList.pop_back_val();
+ for (Block *succ : current->getSuccessors()) {
+ if (visited.insert(succ).second) {
+ workList.push_back(succ);
+ }
+ }
+ }
+ return visited;
+ }();
----------------
pechy wrote:
neat
https://github.com/llvm/llvm-project/pull/206310
More information about the Mlir-commits
mailing list