MLIR 24.0.0git
ValueBoundsOpInterfaceImpl.cpp
Go to the documentation of this file.
1//===- ValueBoundsOpInterfaceImpl.cpp - Impl. of ValueBoundsOpInterface ---===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
10
14
15using namespace mlir;
16
17namespace mlir::vector {
18namespace {
19
20struct VectorScaleOpInterface
21 : public ValueBoundsOpInterface::ExternalModel<VectorScaleOpInterface,
22 VectorScaleOp> {
23 void populateBoundsForIndexValue(Operation *op, Value value,
24 ValueBoundsConstraintSet &cstr) const {
25 // vscale is a positive integer by definition.
26 cstr.bound(value) >= 1;
27 auto *scalableCstr = dyn_cast<ScalableValueBoundsConstraintSet>(&cstr);
28 if (!scalableCstr)
29 return;
30 auto vscaleOp = cast<VectorScaleOp>(op);
31 assert(value == vscaleOp.getResult() && "invalid value");
32 if (auto vscale = scalableCstr->getVscaleValue()) {
33 // All copies of vscale are equivalent.
34 scalableCstr->bound(value) == cstr.getExpr(vscale);
35 } else {
36 // We know vscale is confined to [vscaleMin, vscaleMax].
37 scalableCstr->bound(value) >= scalableCstr->getVscaleMin();
38 scalableCstr->bound(value) <= scalableCstr->getVscaleMax();
39 scalableCstr->setVscale(vscaleOp);
40 }
41 }
42};
43
44} // namespace
45} // namespace mlir::vector
46
48 DialectRegistry &registry) {
49 registry.addExtension(+[](MLIRContext *ctx, vector::VectorDialect *dialect) {
50 vector::VectorScaleOp::attachInterface<vector::VectorScaleOpInterface>(
51 *ctx);
52 });
53}
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
bool addExtension(TypeID extensionID, std::unique_ptr< DialectExtensionBase > extension)
Add the given extension to the registry.
MLIRContext is the top-level object for a collection of MLIR operations.
Definition MLIRContext.h:71
AffineExpr getExpr(Value value, std::optional< int64_t > dim=std::nullopt)
Return an expression that represents the given index-typed value or shaped value dimension.
BoundBuilder bound(Value value)
Add a bound for the given index-typed value or shaped value.
void registerValueBoundsOpInterfaceExternalModels(DialectRegistry &registry)
Include the generated interface declarations.