In the gpu dialect, we made the attribute optional and added a region. We then require the region to be empty of the attribute is present. Something like
let arguments = (ins
OptionalAttr<AtomicRMWKindAttr>:$kind,
AnyTypeOf<[AnySignlessInteger, AnyFloat]>:$value,
MemRefOf<[AnySignlessInteger, AnyFloat]>:$memref,
Variadic<Index>:$indices);
let regions = (region AnyRegion:$body);
We would also need to make the value
operand optional, unless we want to require the generic version to always have at least one operand, which feels strange.
At that point, maybe we should consider a separate op. We can still keep both and could even consider adding a default lowering of the short-forms into the general form if there is not dedicated support for the short form in hardware.
For starters, how about an AtomicRMWRegionOp
that gets a Memref that is to be updated atomically, contains a region with the value read from that memref as single region argument. The region may not have any side-effecting operations and is terminated with a AtomicRMWYieldOp
that returns the updated value. The lowering would be as described above.
Once we have a generalized YieldOp
we can switch to use that.