#include "mlir/Dialect/Vector/IR/ValueBoundsOpInterfaceImpl.h"
#include "mlir/Dialect/Vector/IR/ScalableValueBoundsConstraintSet.h"
#include "mlir/Dialect/Vector/IR/VectorOps.h"
#include "mlir/Interfaces/ValueBoundsOpInterface.h"
using namespace mlir;
namespace mlir::vector {
namespace {
struct VectorScaleOpInterface
: public ValueBoundsOpInterface::ExternalModel<VectorScaleOpInterface,
VectorScaleOp> {
void populateBoundsForIndexValue(Operation *op, Value value,
ValueBoundsConstraintSet &cstr) const {
auto *scalableCstr = dyn_cast<ScalableValueBoundsConstraintSet>(&cstr);
if (!scalableCstr)
return;
auto vscaleOp = cast<VectorScaleOp>(op);
assert(value == vscaleOp.getResult() && "invalid value");
if (auto vscale = scalableCstr->getVscaleValue()) {
scalableCstr->bound(value) == cstr.getExpr(vscale);
} else {
scalableCstr->bound(value) >= scalableCstr->getVscaleMin();
scalableCstr->bound(value) <= scalableCstr->getVscaleMax();
scalableCstr->setVscale(vscaleOp);
}
}
};
}
}
void mlir::vector::registerValueBoundsOpInterfaceExternalModels(
DialectRegistry ®istry) {
registry.addExtension(+[](MLIRContext *ctx, vector::VectorDialect *dialect) {
vector::VectorScaleOp::attachInterface<vector::VectorScaleOpInterface>(
*ctx);
});
}