[Mlir-commits] [mlir] 254d139 - [mlir][bufferization] CloneOp: implement memory side-effects in ODS
Martin Erhart
llvmlistbot at llvm.org
Wed Aug 9 03:30:05 PDT 2023
Author: Martin Erhart
Date: 2023-08-09T10:25:06Z
New Revision: 254d1396f0e00c05ba8fe32e974492a8211b10c8
URL: https://github.com/llvm/llvm-project/commit/254d1396f0e00c05ba8fe32e974492a8211b10c8
DIFF: https://github.com/llvm/llvm-project/commit/254d1396f0e00c05ba8fe32e974492a8211b10c8.diff
LOG: [mlir][bufferization] CloneOp: implement memory side-effects in ODS
Reviewed By: springerm
Differential Revision: https://reviews.llvm.org/D157393
Added:
mlir/test/Dialect/Bufferization/side-effects.mlir
Modified:
mlir/include/mlir/Dialect/Bufferization/IR/BufferizationOps.td
mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/Bufferization/IR/BufferizationOps.td b/mlir/include/mlir/Dialect/Bufferization/IR/BufferizationOps.td
index a9e7b7215c1b43..8a4fea27a45629 100644
--- a/mlir/include/mlir/Dialect/Bufferization/IR/BufferizationOps.td
+++ b/mlir/include/mlir/Dialect/Bufferization/IR/BufferizationOps.td
@@ -167,7 +167,7 @@ def Bufferization_AllocTensorOp : Bufferization_Op<"alloc_tensor",
def Bufferization_CloneOp : Bufferization_Op<"clone", [
CopyOpInterface,
- DeclareOpInterfaceMethods<MemoryEffectsOpInterface>,
+ MemoryEffectsOpInterface,
DeclareOpInterfaceMethods<AllocationOpInterface, ["buildDealloc", "buildClone"]>
]> {
let builders = [
@@ -191,8 +191,11 @@ def Bufferization_CloneOp : Bufferization_Op<"clone", [
behavior.
}];
- let arguments = (ins Arg<AnyRankedOrUnrankedMemRef, "", []>:$input);
- let results = (outs Arg<AnyRankedOrUnrankedMemRef, "", []>:$output);
+ let arguments = (ins Arg<AnyRankedOrUnrankedMemRef, "",
+ [MemRead<DefaultResource>]>:$input);
+ let results = (outs Res<AnyRankedOrUnrankedMemRef, "",
+ [MemWrite<DefaultResource>,
+ MemAlloc<DefaultResource>]>:$output);
let extraClassDeclaration = [{
Value getSource() { return getInput(); }
diff --git a/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp b/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
index e981b80a60083a..8be72fb98644f1 100644
--- a/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
+++ b/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
@@ -489,17 +489,6 @@ LogicalResult CopyTensorOp::reifyResultShapes(
// CloneOp
//===----------------------------------------------------------------------===//
-void CloneOp::getEffects(
- SmallVectorImpl<SideEffects::EffectInstance<MemoryEffects::Effect>>
- &effects) {
- effects.emplace_back(MemoryEffects::Read::get(), getInput(),
- SideEffects::DefaultResource::get());
- effects.emplace_back(MemoryEffects::Write::get(), getOutput(),
- SideEffects::DefaultResource::get());
- effects.emplace_back(MemoryEffects::Allocate::get(), getOutput(),
- SideEffects::DefaultResource::get());
-}
-
OpFoldResult CloneOp::fold(FoldAdaptor adaptor) {
return succeeded(memref::foldMemRefCast(*this)) ? getResult() : Value();
}
diff --git a/mlir/test/Dialect/Bufferization/side-effects.mlir b/mlir/test/Dialect/Bufferization/side-effects.mlir
new file mode 100644
index 00000000000000..680219a48b450d
--- /dev/null
+++ b/mlir/test/Dialect/Bufferization/side-effects.mlir
@@ -0,0 +1,10 @@
+// RUN: mlir-opt %s --test-side-effects --verify-diagnostics
+
+func.func @test_side_effects(%arg0: memref<2xi32>) -> memref<2xi32> {
+ // expected-remark @below {{found an instance of 'read' on a value, on resource '<Default>'}}
+ // expected-remark @below {{found an instance of 'write' on a value, on resource '<Default>'}}
+ // expected-remark @below {{found an instance of 'allocate' on a value, on resource '<Default>'}}
+ %0 = bufferization.clone %arg0 : memref<2xi32> to memref<2xi32>
+ // expected-remark @below {{operation has no memory effects}}
+ return %0 : memref<2xi32>
+}
More information about the Mlir-commits
mailing list