@@ -31,6 +31,27 @@ struct CastOpInterface
3131 }
3232};
3333
34+ struct CollapseShapeOpInterface
35+ : public ValueBoundsOpInterface::ExternalModel<CollapseShapeOpInterface,
36+ CollapseShapeOp> {
37+ void populateBoundsForShapedValueDim (Operation *op, Value value, int64_t dim,
38+ ValueBoundsConstraintSet &cstr) const {
39+ auto collapseOp = cast<CollapseShapeOp>(op);
40+ assert (value == collapseOp.getResult () && " invalid value" );
41+
42+ // Multiply the expressions for the dimensions in the reassociation group.
43+ const ReassociationIndices &reassocIndices =
44+ collapseOp.getReassociationIndices ()[dim];
45+ AffineExpr productExpr =
46+ cstr.getExpr (collapseOp.getSrc (), reassocIndices[0 ]);
47+ for (size_t i = 1 ; i < reassocIndices.size (); ++i) {
48+ productExpr =
49+ productExpr * cstr.getExpr (collapseOp.getSrc (), reassocIndices[i]);
50+ }
51+ cstr.bound (value)[dim] == productExpr;
52+ }
53+ };
54+
3455struct DimOpInterface
3556 : public ValueBoundsOpInterface::ExternalModel<DimOpInterface, DimOp> {
3657 void populateBoundsForIndexValue (Operation *op, Value value,
@@ -57,6 +78,17 @@ struct EmptyOpInterface
5778 }
5879};
5980
81+ struct ExpandShapeOpInterface
82+ : public ValueBoundsOpInterface::ExternalModel<ExpandShapeOpInterface,
83+ ExpandShapeOp> {
84+ void populateBoundsForShapedValueDim (Operation *op, Value value, int64_t dim,
85+ ValueBoundsConstraintSet &cstr) const {
86+ auto expandOp = cast<ExpandShapeOp>(op);
87+ assert (value == expandOp.getResult () && " invalid value" );
88+ cstr.bound (value)[dim] == expandOp.getMixedOutputShape ()[dim];
89+ }
90+ };
91+
6092struct ExtractSliceOpInterface
6193 : public ValueBoundsOpInterface::ExternalModel<ExtractSliceOpInterface,
6294 ExtractSliceOp> {
@@ -117,8 +149,12 @@ void mlir::tensor::registerValueBoundsOpInterfaceExternalModels(
117149 DialectRegistry ®istry) {
118150 registry.addExtension (+[](MLIRContext *ctx, tensor::TensorDialect *dialect) {
119151 tensor::CastOp::attachInterface<tensor::CastOpInterface>(*ctx);
152+ tensor::CollapseShapeOp::attachInterface<tensor::CollapseShapeOpInterface>(
153+ *ctx);
120154 tensor::DimOp::attachInterface<tensor::DimOpInterface>(*ctx);
121155 tensor::EmptyOp::attachInterface<tensor::EmptyOpInterface>(*ctx);
156+ tensor::ExpandShapeOp::attachInterface<tensor::ExpandShapeOpInterface>(
157+ *ctx);
122158 tensor::ExtractSliceOp::attachInterface<tensor::ExtractSliceOpInterface>(
123159 *ctx);
124160 tensor::PadOp::attachInterface<tensor::PadOpInterface>(*ctx);
0 commit comments