Skip to content

Commit 146d52e

Browse files
committed
[MLIR] Verify there are no side-effecting ops in GenericAtomicRMWOp body.
Differential Revision: https://reviews.llvm.org/D78559
1 parent c22876b commit 146d52e

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

mlir/include/mlir/Dialect/StandardOps/IR/Ops.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,8 @@ def GenericAtomicRMWOp : Std_Op<"generic_atomic_rmw", [
499499
The result represents the latest value that was stored. The region contains
500500
the code for the modification itself. The entry block has a single argument
501501
that represents the value stored in `memref[indices]` before the write is
502-
performed.
502+
performed. No side-effecting ops are allowed in the body of
503+
`GenericAtomicRMWOp`.
503504

504505
Example:
505506

mlir/lib/Dialect/StandardOps/IR/Ops.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,18 @@ static LogicalResult verify(GenericAtomicRMWOp op) {
507507
if (op.getResult().getType() != block.getArgument(0).getType())
508508
return op.emitOpError(
509509
"expected block argument of the same type result type");
510-
return success();
510+
511+
bool hasSideEffects =
512+
op.body()
513+
.walk([&](Operation *nestedOp) {
514+
if (MemoryEffectOpInterface::hasNoEffect(nestedOp))
515+
return WalkResult::advance();
516+
nestedOp->emitError("body of 'generic_atomic_rmw' should contain "
517+
"only operations with no side effects");
518+
return WalkResult::interrupt();
519+
})
520+
.wasInterrupted();
521+
return hasSideEffects ? failure() : success();
511522
}
512523

513524
static ParseResult parseGenericAtomicRMWOp(OpAsmParser &parser,

mlir/test/IR/invalid-ops.mlir

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,18 @@ func @generic_atomic_rmw_result_type_mismatch(%I: memref<10xf32>, %i : index) {
11791179

11801180
// -----
11811181

1182+
func @generic_atomic_rmw_has_side_effects(%I: memref<10xf32>, %i : index) {
1183+
// expected-error@+4 {{should contain only operations with no side effects}}
1184+
%x = generic_atomic_rmw %I[%i] : memref<10xf32> {
1185+
^bb0(%old_value : f32):
1186+
%c1 = constant 1.0 : f32
1187+
%buf = alloc() : memref<2048xf32>
1188+
atomic_yield %c1 : f32
1189+
}
1190+
}
1191+
1192+
// -----
1193+
11821194
func @atomic_yield_type_mismatch(%I: memref<10xf32>, %i : index) {
11831195
// expected-error@+4 {{op types mismatch between yield op: 'i32' and its parent: 'f32'}}
11841196
%x = generic_atomic_rmw %I[%i] : memref<10xf32> {

0 commit comments

Comments
 (0)