[Mlir-commits] [mlir] [mlir][bufferization] Support custom types (1/N) (PR #142986)
Andrei Golubev
llvmlistbot at llvm.org
Mon Jun 16 05:36:15 PDT 2025
================
@@ -473,19 +482,19 @@ def Bufferization_ToTensorOp : Bufferization_Op<"to_tensor", [
FailureOr<BaseMemRefType> getBufferType(
Value value, const BufferizationOptions &options,
const BufferizationState &state, SmallVector<Value> &invocationStack) {
- return ::llvm::cast<BaseMemRefType>(getMemref().getType());
+ return ::llvm::cast<BaseMemRefType>(getBuffer().getType());
}
}];
let assemblyFormat = [{
- $memref (`restrict` $restrict^)? (`writable` $writable^)? attr-dict
- `:` type($memref) `to` type($result)
+ $buffer (`restrict` $restrict^)? (`writable` $writable^)? attr-dict
+ `:` type($buffer) `to` type($result)
}];
let builders = [
- OpBuilder<(ins "Value":$memref, CArg<"bool", "false">:$restrict, CArg<"bool", "false">:$writeable), [{
- auto rtt = memref::getTensorTypeFromMemRefType(memref.getType());
- build($_builder, $_state, rtt, memref, restrict, writeable);
+ OpBuilder<(ins "Value":$buffer, CArg<"bool", "false">:$restrict, CArg<"bool", "false">:$writeable), [{
+ auto rtt = bufferization::detail::getTensorFromBuffer(buffer.getType());
----------------
andrey-golubev wrote:
@matthias-springer I took a look at the current implementation. I think there's a problem with this API if we switch to a BufferLike's function:
* ToTensor seems to infer the tensor type from buffer type
* Without options here, there's no (good) way to customize the (reverse) bufferization behavior for builtins
Should this be changed somehow? The things I could think of:
1. Drop type inference and make ToTensor always be constructed with an explicit type (so, user has to care about reverse bufferization)
2. Pass bufferization options to the builder
3. Assume that the current API is the way it is -> meaning that options cannot be used as customization point for builtins also and a different mechanism is needed
4. something else?
https://github.com/llvm/llvm-project/pull/142986
More information about the Mlir-commits
mailing list