[Mlir-commits] [llvm] [mlir] [mlir][bufferization] Add a ValueBoundsOpInterface model for to_tensor (PR #215357)
Victor Perez
llvmlistbot at llvm.org
Tue Aug 11 04:41:44 PDT 2026
================
@@ -0,0 +1,48 @@
+//===- ValueBoundsOpInterfaceImpl.cpp - Impl. of ValueBoundsOpInterface ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/Dialect/Bufferization/IR/ValueBoundsOpInterfaceImpl.h"
+
+#include "mlir/Dialect/Bufferization/IR/Bufferization.h"
+#include "mlir/Interfaces/ValueBoundsOpInterface.h"
+
+using namespace mlir;
+
+namespace mlir {
+namespace bufferization {
+namespace {
+
+struct ToTensorOpInterface
+ : public ValueBoundsOpInterface::ExternalModel<ToTensorOpInterface,
+ ToTensorOp> {
+ void populateBoundsForShapedValueDim(Operation *op, Value value, int64_t dim,
+ ValueBoundsConstraintSet &cstr) const {
+ auto toTensorOp = cast<ToTensorOp>(op);
+ assert(value == toTensorOp.getResult() && "invalid value");
+
+ // The tensor and the buffer describe the same memory, so they have the same
+ // size in every dimension. The op also accepts types that are not shaped,
+ // for which no bound can be computed.
+ if (isa<ShapedType>(toTensorOp.getResult().getType()) &&
+ isa<ShapedType>(toTensorOp.getBuffer().getType()))
+ cstr.bound(value)[dim] == cstr.getExpr(toTensorOp.getBuffer(), dim);
----------------
victor-eds wrote:
I'm pretty sure that the convention in LLVM is not adding braces here. I'll keep it as is to follow [the convention](https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements).
https://github.com/llvm/llvm-project/pull/215357
More information about the Mlir-commits
mailing list