[Mlir-commits] [mlir] [mlir][Interfaces] Add interface methods to allow reifying single result/single dim of result. (PR #162924)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Oct 24 12:57:42 PDT 2025
================
@@ -361,20 +361,76 @@ def ReifyRankedShapedTypeOpInterface :
let methods = [
InterfaceMethod<
/*desc=*/[{
- Reify the shape of the result of an operation (typically in terms of the
- shape of its operands).
+ Reify the shapes of all the result of an operation (typically in terms
+ of the shape of its operands).
`reifiedReturnShapes` is populated with one vector per op result. Each
of those vectors contains an OpFoldResult for each dimension of the
shaped type. The given builder may be used to insert ops that compute
result shapes.
- If the shape of a particular result cannot be computed it must be empty.
+ If the shape of a particular result cannot be computed it in terms of
+ its operands it must be left empty. If any dimension of the result cannot
+ be computed it must be set to OpFoldResult().
}],
/*retTy=*/"::llvm::LogicalResult",
/*methodName=*/"reifyResultShapes",
/*args=*/(ins "::mlir::OpBuilder &":$builder,
- "::mlir::ReifiedRankedShapedTypeDims &":$reifiedReturnShapes)
+ "::mlir::ReifiedRankedShapedTypeDims &":$reifiedReturnShapes),
+ /*methodBody=*/"",
+ /*defaultImplementation=*/[{ return ::mlir::failure(); }]
+ >,
+ InterfaceMethod<
+ /*desc=*/[{
+ Reify the shape of a single result of an operation (typically in terms
+ of the shape of its operands).
+
+ Returns the shape of a single result of the operation as a
+ `SmallVector<OpFoldResult>`, one per dimension of the shaped type. The
+ given builder may be used to insert ops that compute result shapes.
+
+ If any dimension of the result cannot be computed it must be set to
+ OpFoldResult().
+ }],
+ /*retTy=*/"::llvm::FailureOr<::llvm::SmallVector<::mlir::OpFoldResult>>",
+ /*methodName=*/"reifyShapeOfResult",
+ /*args=*/(ins "::mlir::OpBuilder &":$builder,
+ "int":$resultIndex),
+ /*methodBody=*/"",
+ /*defaultImplementation=*/[{
+ ReifiedRankedShapedTypeDims reifiedShapes;
+ if (failed(cast<ReifyRankedShapedTypeOpInterface>($_op.getOperation()).reifyResultShapes(builder, reifiedShapes)))
+ return failure();
+ if (resultIndex < 0 || resultIndex >= (int)(reifiedShapes.size()))
+ return $_op.emitOpError("invalid result index");
----------------
MaheshRavishankar wrote:
If I just assert here, then in release builds it will hit a segfault. I'd rather bail gracefully.
https://github.com/llvm/llvm-project/pull/162924
More information about the Mlir-commits
mailing list