diff --git a/mlir/lib/Transforms/CSE.cpp b/mlir/lib/Transforms/CSE.cpp --- a/mlir/lib/Transforms/CSE.cpp +++ b/mlir/lib/Transforms/CSE.cpp @@ -25,24 +25,6 @@ using namespace mlir; -/// Return true if the specified region is known to follow SSA dominance -/// properties, i.e. it isn't a graph region. -static bool regionHasSSADominance(Operation &op, size_t regionNo, - RegionKindInterface regionKindItf) { - // If the op is unregistered, then we don't know if it has SSADominance or - // not, so assume not. - if (!op.isRegistered()) - return false; - - // If the op is registered but has no RegionKindInterface, then it defaults to - // SSADominance. - if (!regionKindItf) - return true; - - // Otherwise, ask the interface. - return regionKindItf.hasSSADominance(regionNo); -} - namespace { struct SimpleOperationInfo : public llvm::DenseMapInfo { static unsigned getHashValue(const Operation *opC) { @@ -93,8 +75,7 @@ LogicalResult simplifyOperation(ScopedMapTy &knownValues, Operation *op, bool hasSSADominance); void simplifyBlock(ScopedMapTy &knownValues, Block *bb, bool hasSSADominance); - void simplifyRegion(ScopedMapTy &knownValues, Region ®ion, - bool hasSSADominance); + void simplifyRegion(ScopedMapTy &knownValues, Region ®ion); void runOnOperation() override; @@ -184,34 +165,29 @@ if (op.getNumRegions() == 0) continue; - auto regionKindItf = dyn_cast(op); - // If this operation is isolated above, we can't process nested regions with // the given 'knownValues' map. This would cause the insertion of implicit // captures in explicit capture only regions. if (op.mightHaveTrait()) { ScopedMapTy nestedKnownValues; - for (size_t i = 0, e = op.getNumRegions(); i != e; ++i) { - simplifyRegion(nestedKnownValues, op.getRegion(i), - regionHasSSADominance(op, i, regionKindItf)); - } + for (auto ®ion : op.getRegions()) + simplifyRegion(nestedKnownValues, region); continue; } // Otherwise, process nested regions normally. - for (size_t i = 0, e = op.getNumRegions(); i != e; ++i) { - simplifyRegion(knownValues, op.getRegion(i), - regionHasSSADominance(op, i, regionKindItf)); - } + for (auto ®ion : op.getRegions()) + simplifyRegion(knownValues, region); } } -void CSE::simplifyRegion(ScopedMapTy &knownValues, Region ®ion, - bool hasSSADominance) { +void CSE::simplifyRegion(ScopedMapTy &knownValues, Region ®ion) { // If the region is empty there is nothing to do. if (region.empty()) return; + bool hasSSADominance = domInfo->hasSSADominance(®ion); + // If the region only contains one block, then simplify it directly. if (region.hasOneBlock()) { ScopedMapTy::ScopeTy scope(knownValues); @@ -267,11 +243,8 @@ domInfo = &getAnalysis(); Operation *rootOp = getOperation(); - auto regionKindItf = dyn_cast(getOperation()); - for (size_t i = 0, e = rootOp->getNumRegions(); i != e; ++i) { - simplifyRegion(knownValues, rootOp->getRegion(i), - regionHasSSADominance(*rootOp, i, regionKindItf)); - } + for (auto ®ion : rootOp->getRegions()) + simplifyRegion(knownValues, region); // If no operations were erased, then we mark all analyses as preserved. if (opsToErase.empty())