[PATCH] D77083: [MLIR] Add pattern rewriter util to erase block; add affine.if pattern to remove dead else blocks

River Riddle via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 2 18:27:25 PDT 2020


rriddle accepted this revision.
rriddle added inline comments.
This revision is now accepted and ready to land.


================
Comment at: mlir/include/mlir/IR/PatternMatch.h:285
+  /// known to have no uses.
+  virtual void eraseBlock(Block *block);
+
----------------
bondhugula wrote:
> rriddle wrote:
> > bondhugula wrote:
> > > rriddle wrote:
> > > > Can you add proper handling for DialectConversion?
> > > Sorry, I didn't understand. What does dialect conversion need from eraseBlock? and which it doesn't from eraseOp?
> > DialectConversion doesn't allow performing the IR mutation until after the conversion is successful. In this case, you can't erase the block directly because this action may need to be undone later.
> Sure - but could you provide a pointer on what handling you need here? Is it trivial? It looks like one shouldn't use eraseBlock in such cases, but rely on a lower level approach?
I'm fine with adding a `llvm_unreachable` in the ConversionPatternRewriter for now.


================
Comment at: mlir/lib/Dialect/Affine/IR/AffineOps.cpp:1577
+    if (ifOp.elseRegion().empty() ||
+        ifOp.getElseBlock()->getOperations().size() > 1)
+      return failure();
----------------
bondhugula wrote:
> rriddle wrote:
> > Please use has_single_element instead. size() is O(N).
> Thanks. 
I think you could just do: *ifOp.getElseBlock()


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77083/new/

https://reviews.llvm.org/D77083





More information about the llvm-commits mailing list