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 auto constIndex = dimOp.getConstantIndex();
55 if (!constIndex.has_value())
57 cstr.
bound(value) == cstr.
getExpr(dimOp.getSource(), *constIndex);
61 struct GetGlobalOpInterface
62 :
public ValueBoundsOpInterface::ExternalModel<GetGlobalOpInterface,
64 void populateBoundsForShapedValueDim(
Operation *op,
Value value, int64_t dim,
66 auto getGlobalOp = cast<GetGlobalOp>(op);
67 assert(value == getGlobalOp.getResult() &&
"invalid value");
69 auto type = getGlobalOp.getType();
70 assert(!type.isDynamicDim(dim) &&
"expected static dim");
71 cstr.
bound(value)[dim] == type.getDimSize(dim);
75 struct RankOpInterface
76 :
public ValueBoundsOpInterface::ExternalModel<RankOpInterface, RankOp> {
79 auto rankOp = cast<RankOp>(op);
80 assert(value == rankOp.getResult() &&
"invalid value");
82 auto memrefType = llvm::dyn_cast<MemRefType>(rankOp.getMemref().getType());
85 cstr.
bound(value) == memrefType.getRank();
89 struct SubViewOpInterface
90 :
public ValueBoundsOpInterface::ExternalModel<SubViewOpInterface,
92 void populateBoundsForShapedValueDim(
Operation *op,
Value value, int64_t dim,
94 auto subViewOp = cast<SubViewOp>(op);
95 assert(value == subViewOp.getResult() &&
"invalid value");
97 llvm::SmallBitVector dropped = subViewOp.getDroppedDims();
99 for (int64_t i = 0, e = subViewOp.getMixedSizes().size(); i < e; ++i) {
101 if (!dropped.test(i))
104 cstr.
bound(value)[dim] == subViewOp.getMixedSizes()[i];
108 llvm_unreachable(
"could not find non-rank-reduced dim");
119 memref::AllocOp::attachInterface<memref::AllocOpInterface<memref::AllocOp>>(
121 memref::AllocaOp::attachInterface<
122 memref::AllocOpInterface<memref::AllocaOp>>(*ctx);
123 memref::CastOp::attachInterface<memref::CastOpInterface>(*ctx);
124 memref::DimOp::attachInterface<memref::DimOpInterface>(*ctx);
125 memref::GetGlobalOp::attachInterface<memref::GetGlobalOpInterface>(*ctx);
126 memref::RankOp::attachInterface<memref::RankOpInterface>(*ctx);
127 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.