[Mlir-commits] [mlir] [mlir][bufferization] Introduce reconcileBufferTypeMismatchFn hook (PR #202667)
Matthias Springer
llvmlistbot at llvm.org
Tue Jun 16 08:34:47 PDT 2026
================
@@ -2019,6 +2019,79 @@ test::TestCreateTensorOp::getBufferType(
options);
}
+::mlir::LogicalResult test::TestTensorWithFutureLayoutOp::bufferize(
+ ::mlir::RewriterBase &rewriter,
+ const ::mlir::bufferization::BufferizationOptions &options,
+ ::mlir::bufferization::BufferizationState &state) {
+ const auto bufferizedOutType =
+ mlir::bufferization::getBufferType(getOutput(), options, state);
+ if (mlir::failed(bufferizedOutType))
+ return failure();
+
+ auto createMemrefOp =
+ test::TestCreateMemrefOp::create(rewriter, getLoc(), *bufferizedOutType);
+ mlir::bufferization::replaceOpWithBufferizedValues(
+ rewriter, getOperation(), createMemrefOp.getResult());
+ return mlir::success();
+}
+
+mlir::FailureOr<mlir::bufferization::BufferLikeType>
+test::TestTensorWithFutureLayoutOp::getBufferType(
+ mlir::Value value, const mlir::bufferization::BufferizationOptions &,
+ const mlir::bufferization::BufferizationState &,
+ llvm::SmallVector<::mlir::Value> &) {
+ auto tensorType = dyn_cast<RankedTensorType>(value.getType());
+ if (!tensorType)
+ return failure();
+
+ // Set the memref layout to the op's 'layout' attribute, ignoring
+ // any pre-existing tensor encoding. This is what lets two
+ // `test.tensor_with_layout` ops produce *bufferized* memrefs with different
+ // layouts while keeping their *tensor* result types identical -- which is
+ // required to construct SCF iter_arg/branch mismatches that the verifier
+ // still accepts.
+ auto layout = cast<MemRefLayoutAttrInterface>(getLayout());
+ return cast<bufferization::BufferLikeType>(MemRefType::get(
+ tensorType.getShape(), tensorType.getElementType(), layout));
+}
+
+::mlir::LogicalResult test::TestForceNewLayoutOp::bufferize(
----------------
matthias-springer wrote:
nit: You can probably drop the `::mlir` and `::llvm` around here.
https://github.com/llvm/llvm-project/pull/202667
More information about the Mlir-commits
mailing list