[Mlir-commits] [mlir] [mlir][bufferization] Introduce reconcileBufferTypeMismatchFn hook (PR #202667)

Matthias Springer llvmlistbot at llvm.org
Tue Jun 16 08:34:46 PDT 2026


================
@@ -4178,6 +4178,104 @@ def TestCreateMemrefOp : TEST_Op<"create_memref_op"> {
   let results = (outs Arg<Bufferization_BufferLikeTypeInterface>:$output);
 }
 
+def TestTensorWithFutureLayoutOp
+    : TEST_Op<"tensor_with_future_layout",
+              [DeclareOpInterfaceMethods<
+                  BufferizableOpInterface,
+                  ["bufferize", "getBufferType", "bufferizesToMemoryRead",
+                   "bufferizesToMemoryWrite", "getAliasingValues",
+                   "getAliasingOpOperands", "bufferizesToAllocation"]>]> {
+  let description = [{
+    A tensor creation operation that forces a specific `TestMemRefLayoutAttr`
+    layout  to be set during bufferization into a memref. In tensor world, this
+    op does nothing encoding/layout wise. Thus, it allows to create memref
+    layout mismatches that can later be resolved by the bufferization framework
+    while keeping tensor IR valid.
+  }];
+
+  let arguments = (ins TestMemRefLayoutAttr:$layout);
+  let results = (outs AnyRankedTensor:$output);
+  let extraClassDefinition = [{
+    bool test::TestTensorWithFutureLayoutOp::bufferizesToMemoryRead(
+        ::mlir::OpOperand&,
+        const ::mlir::bufferization::AnalysisState&) {
+      return false;
+    }
+    bool test::TestTensorWithFutureLayoutOp::bufferizesToMemoryWrite(
+        ::mlir::OpOperand&,
+        const ::mlir::bufferization::AnalysisState&) {
+      return false;
+    }
+    bool test::TestTensorWithFutureLayoutOp::bufferizesToAllocation(
+        mlir::Value) {
+      return true;
+    }
+    ::mlir::bufferization::AliasingValueList
+    test::TestTensorWithFutureLayoutOp::getAliasingValues(::mlir::OpOperand&,
+        const ::mlir::bufferization::AnalysisState&) {
+      return {};
+    }
+    ::mlir::bufferization::AliasingOpOperandList
+    test::TestTensorWithFutureLayoutOp::getAliasingOpOperands(::mlir::Value,
+        const ::mlir::bufferization::AnalysisState&) {
+      return {};
+    }
+  }];
+}
+
+def TestForceNewLayoutOp
+    : TEST_Op<"force_new_layout",
+              [DeclareOpInterfaceMethods<
+                  BufferizableOpInterface,
+                  ["bufferize", "getBufferType", "bufferizesToMemoryRead",
+                   "bufferizesToMemoryWrite", "getAliasingValues",
+                   "getAliasingOpOperands"]>]> {
+  let description = [{
+    A tensor operation that forces a specific `TestMemRefLayoutAttr` to be set
+    during bufferization into a memref. In tensor world, this op does nothing
+    encoding/layout wise. Thus, it allows to create memref layout mismatches
+    that can later be resolved by the bufferization framework while keeping
+    tensor IR valid.
+  }];
+
+  let arguments = (ins
+    Arg<AnyRankedTensor>:$input,
----------------
matthias-springer wrote:

Is the `Arg<...>` doing anything here?

https://github.com/llvm/llvm-project/pull/202667


More information about the Mlir-commits mailing list