[Mlir-commits] [mlir] [MLIR] Refactor the walkAndApplyPatterns driver to remove the recursion (PR #154037)
Jakub Kuderski
llvmlistbot at llvm.org
Sun Aug 17 17:26:12 PDT 2025
================
@@ -88,20 +90,97 @@ void walkAndApplyPatterns(Operation *op,
PatternApplicator applicator(patterns);
applicator.applyDefaultCostModel();
+ // Iterator on all reachable operations in the region.
+ // Also keep track if we visited the nested regions of the current op
+ // already to drive the post-order traversal.
+ struct RegionReachableOpIterator {
+ RegionReachableOpIterator(Region *region) : region(region) {
+ regionIt = region->begin();
+ if (regionIt != region->end())
+ blockIt = regionIt->begin();
+ }
+ // Advance the iterator to the next reachable operation.
+ void advance() {
+ assert(regionIt != region->end());
+ hasVisitedRegions = false;
+ if (blockIt == regionIt->end()) {
+ regionIt++;
+ if (regionIt != region->end())
+ blockIt = regionIt->begin();
+ return;
+ }
+ blockIt++;
----------------
kuhar wrote:
```suggestion
++blockIt;
```
https://github.com/llvm/llvm-project/pull/154037
More information about the Mlir-commits
mailing list