[PATCH] D76415: [mlir] Fix unsafe create operation in GreedyPatternRewriter

Mahesh Ravishankar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 18 23:57:35 PDT 2020


mravishankar created this revision.
Herald added subscribers: llvm-commits, Joonsoo, liufengdb, lucyrfox, mgester, arpith-jacob, nicolasvasilache, antiagainst, shauheen, burmako, jpienaar, rriddle, mehdi_amini.
Herald added a project: LLVM.
mravishankar added a reviewer: rriddle.

When trying to fold an operation during operation creation check that
the operation folding succeeds before inserting the op.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76415

Files:
  mlir/include/mlir/Transforms/FoldUtils.h


Index: mlir/include/mlir/Transforms/FoldUtils.h
===================================================================
--- mlir/include/mlir/Transforms/FoldUtils.h
+++ mlir/include/mlir/Transforms/FoldUtils.h
@@ -75,11 +75,16 @@
   template <typename OpTy, typename... Args>
   void create(OpBuilder &builder, SmallVectorImpl<Value> &results,
               Location location, Args &&... args) {
-    Operation *op = builder.create<OpTy>(location, std::forward<Args>(args)...);
-    if (failed(tryToFold(op, results)))
+    OperationState state(location, OpTy::getOperationName());
+    OpTy::build(&builder, state, std::forward<Args>(args)...);
+    Operation *op = Operation::create(state);
+
+    if (failed(tryToFold(op, results))) {
+      builder.insert(op);
       results.assign(op->result_begin(), op->result_end());
-    else if (op->getNumResults() != 0)
-      op->erase();
+    } else if (op->getNumResults() != 0) {
+      op->destroy();
+    }
   }
 
   /// Overload to create or fold a single result operation.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76415.251286.patch
Type: text/x-patch
Size: 1024 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200319/8e6c9e65/attachment.bin>


More information about the llvm-commits mailing list