20 template <
typename OpTy>
21 struct AllocOpInterface
22 :
public ValueBoundsOpInterface::ExternalModel<AllocOpInterface<OpTy>,
24 void populateBoundsForShapedValueDim(
Operation *op,
Value value, int64_t dim,
26 auto allocOp = cast<OpTy>(op);
27 assert(value == allocOp.getResult() &&
"invalid value");
29 cstr.
bound(value)[dim] == allocOp.getMixedSizes()[dim];
33 struct CastOpInterface
34 :
public ValueBoundsOpInterface::ExternalModel<CastOpInterface, CastOp> {
35 void populateBoundsForShapedValueDim(
Operation *op,
Value value, int64_t dim,
37 auto castOp = cast<CastOp>(op);
38 assert(value == castOp.getResult() &&
"invalid value");
40 if (llvm::isa<MemRefType>(castOp.getResult().getType()) &&
41 llvm::isa<MemRefType>(castOp.getSource().getType())) {
42 cstr.
bound(value)[dim] == cstr.
getExpr(castOp.getSource(), dim);
48 :
public ValueBoundsOpInterface::ExternalModel<DimOpInterface, DimOp> {
51 auto dimOp = cast<DimOp>(op);
52 assert(value == dimOp.getResult() &&
"invalid value");
54 cstr.
bound(value) >= 0;
55 auto constIndex = dimOp.getConstantIndex();
56 if (!constIndex.has_value())
58 cstr.
bound(value) == cstr.
getExpr(dimOp.getSource(), *constIndex);
62 struct GetGlobalOpInterface
63 :
public ValueBoundsOpInterface::ExternalModel<GetGlobalOpInterface,
65 void populateBoundsForShapedValueDim(
Operation *op,
Value value, int64_t dim,
67 auto getGlobalOp = cast<GetGlobalOp>(op);
68 assert(value == getGlobalOp.getResult() &&
"invalid value");
70 auto type = getGlobalOp.getType();
71 assert(!type.isDynamicDim(dim) &&
"expected static dim");
72 cstr.
bound(value)[dim] == type.getDimSize(dim);
76 struct RankOpInterface
77 :
public ValueBoundsOpInterface::ExternalModel<RankOpInterface, RankOp> {
80 auto rankOp = cast<RankOp>(op);
81 assert(value == rankOp.getResult() &&
"invalid value");
83 auto memrefType = llvm::dyn_cast<MemRefType>(rankOp.getMemref().getType());
86 cstr.
bound(value) == memrefType.getRank();
90 struct SubViewOpInterface
91 :
public ValueBoundsOpInterface::ExternalModel<SubViewOpInterface,
93 void populateBoundsForShapedValueDim(
Operation *op,
Value value, int64_t dim,
95 auto subViewOp = cast<SubViewOp>(op);
96 assert(value == subViewOp.getResult() &&
"invalid value");
98 llvm::SmallBitVector dropped = subViewOp.getDroppedDims();
100 for (int64_t i = 0, e = subViewOp.getMixedSizes().size(); i < e; ++i) {
102 if (!dropped.test(i))
105 cstr.
bound(value)[dim] == subViewOp.getMixedSizes()[i];
109 llvm_unreachable(
"could not find non-rank-reduced dim");
120 memref::AllocOp::attachInterface<memref::AllocOpInterface<memref::AllocOp>>(
122 memref::AllocaOp::attachInterface<
123 memref::AllocOpInterface<memref::AllocaOp>>(*ctx);
124 memref::CastOp::attachInterface<memref::CastOpInterface>(*ctx);
125 memref::DimOp::attachInterface<memref::DimOpInterface>(*ctx);
126 memref::GetGlobalOp::attachInterface<memref::GetGlobalOpInterface>(*ctx);
127 memref::RankOp::attachInterface<memref::RankOpInterface>(*ctx);
128 memref::SubViewOp::attachInterface<memref::SubViewOpInterface>(*ctx);
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.
Operation is the basic unit of execution within MLIR.
A helper class to be used with ValueBoundsOpInterface.
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.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
void registerValueBoundsOpInterfaceExternalModels(DialectRegistry ®istry)
Include the generated interface declarations.