[PATCH] D78559: [MLIR] Verify there are no side-effecting ops in GenericAtomicRMWOp body.

Alexander Belyaev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 21 05:54:43 PDT 2020


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

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78559

Files:
  mlir/lib/Dialect/StandardOps/IR/Ops.cpp
  mlir/test/IR/invalid-ops.mlir


Index: mlir/test/IR/invalid-ops.mlir
===================================================================
--- mlir/test/IR/invalid-ops.mlir
+++ mlir/test/IR/invalid-ops.mlir
@@ -1179,6 +1179,19 @@
 
 // -----
 
+func @generic_atomic_rmw_has_side_effects(%I: memref<10xf32>, %i : index) {
+ // expected-error at +4 {{body of 'generic_atomic_rmw' should contain only operations with no side effects}}
+  %x = generic_atomic_rmw %I[%i] : memref<10xf32> {
+    ^bb0(%old_value : f32):
+      %c1 = constant 1.0 : f32
+      %buf = alloc() : memref<2048xf32>
+      atomic_yield %c1 : f32
+  }
+}
+
+// -----
+
+
 func @atomic_yield_type_mismatch(%I: memref<10xf32>, %i : index) {
   // expected-error at +4 {{op types mismatch between yield op: 'i32' and its parent: 'f32'}}
   %x = generic_atomic_rmw %I[%i] : memref<10xf32> {
Index: mlir/lib/Dialect/StandardOps/IR/Ops.cpp
===================================================================
--- mlir/lib/Dialect/StandardOps/IR/Ops.cpp
+++ mlir/lib/Dialect/StandardOps/IR/Ops.cpp
@@ -507,6 +507,17 @@
   if (op.getResult().getType() != block.getArgument(0).getType())
     return op.emitOpError(
         "expected block argument of the same type result type");
+
+  // Check if there are any ops with side effects in the body.
+  for (auto &block : op.body()) {
+    for (auto &nestedOp : block.getOperations()) {
+      if (MemoryEffectOpInterface::hasNoEffect(&nestedOp) &&
+          nestedOp.getNumRegions() == 0)
+        continue;
+      return nestedOp.emitError("body of 'generic_atomic_rmw' should contain "
+                                "only operations with no side effects");
+    }
+  }
   return success();
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78559.258974.patch
Type: text/x-patch
Size: 1670 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200421/69570422/attachment.bin>


More information about the llvm-commits mailing list