1 //===- ValueBoundsOpInterfaceImpl.cpp - Impl. of ValueBoundsOpInterface ---===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "mlir/Dialect/Linalg/IR/ValueBoundsOpInterfaceImpl.h"
11 #include "mlir/Dialect/Linalg/IR/Linalg.h"
12 #include "mlir/Interfaces/ValueBoundsOpInterface.h"
20 struct IndexOpInterface
21 : public ValueBoundsOpInterface::ExternalModel
<IndexOpInterface
, IndexOp
> {
22 void populateBoundsForIndexValue(Operation
*op
, Value value
,
23 ValueBoundsConstraintSet
&cstr
) const {
24 auto indexOp
= cast
<IndexOp
>(op
);
25 auto linalgOp
= indexOp
->getParentOfType
<LinalgOp
>();
26 assert(value
== indexOp
.getResult() && "invalid value");
29 cstr
.bound(value
) >= 0;
34 linalgOp
.getShapesToLoopsMap().getResult(indexOp
.getDim()))
36 // Find the `flatDimPos`-th operand dimension.
37 int64_t flatDimCtr
= 0;
38 for (Value operand
: linalgOp
->getOperands()) {
39 assert(flatDimPos
>= flatDimCtr
&& "invalid pos");
40 auto shapedType
= llvm::cast
<ShapedType
>(operand
.getType());
41 if (flatDimPos
< flatDimCtr
+ shapedType
.getRank()) {
42 cstr
.bound(value
) < cstr
.getExpr(operand
, flatDimPos
- flatDimCtr
);
45 flatDimCtr
+= shapedType
.getRank();
54 void mlir::linalg::registerValueBoundsOpInterfaceExternalModels(
55 DialectRegistry
®istry
) {
56 registry
.addExtension(+[](MLIRContext
*ctx
, linalg::LinalgDialect
*dialect
) {
57 IndexOp::attachInterface
<IndexOpInterface
>(*ctx
);
58 // Note: ValueBoundsOpInterface implementation is not required for ops that
59 // implement `DestinationStyleOpInterface` (for querying shaped OpResults).