From 0ddba0bd59c337f16b51a00cb205ecfda46f97fa Mon Sep 17 00:00:00 2001 From: River Riddle Date: Thu, 12 Mar 2020 14:06:41 -0700 Subject: [mlir][SideEffects] Replace HasNoSideEffect with the memory effect interfaces. HasNoSideEffect can now be implemented using the MemoryEffectInterface, removing the need to check multiple things for the same information. This also removes an easy foot-gun for users as 'Operation::hasNoSideEffect' would ignore operations that dynamically, or recursively, have no side effects. This also leads to an immediate improvement in some of the existing users, such as DCE, now that they have access to more information. Differential Revision: https://reviews.llvm.org/D76036 --- mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp') diff --git a/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp b/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp index f9a9be5..e40a4d9 100644 --- a/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp +++ b/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp @@ -10,9 +10,8 @@ // //===----------------------------------------------------------------------===// -#include "mlir/Dialect/StandardOps/IR/Ops.h" -#include "mlir/IR/Builders.h" #include "mlir/IR/PatternMatch.h" +#include "mlir/Interfaces/SideEffects.h" #include "mlir/Transforms/FoldUtils.h" #include "mlir/Transforms/RegionUtils.h" #include "llvm/ADT/DenseMap.h" @@ -162,11 +161,8 @@ bool GreedyPatternRewriteDriver::simplify(MutableArrayRef regions, if (op == nullptr) continue; - // If the operation has no side effects, and no users, then it is - // trivially dead - remove it. - if (op->isKnownNonTerminator() && op->hasNoSideEffect() && - op->use_empty()) { - // Be careful to update bookkeeping. + // If the operation is trivially dead - remove it. + if (isOpTriviallyDead(op)) { notifyOperationRemoved(op); op->erase(); continue; @@ -204,7 +200,10 @@ bool GreedyPatternRewriteDriver::simplify(MutableArrayRef regions, // After applying patterns, make sure that the CFG of each of the regions is // kept up to date. - changed |= succeeded(simplifyRegions(regions)); + if (succeeded(simplifyRegions(regions))) { + folder.clear(); + changed = true; + } } while (changed && ++i < maxIterations); // Whether the rewrite converges, i.e. wasn't changed in the last iteration. return !changed; -- cgit v1.1