//===-- RemoveShapeConstraints.cpp - Remove Shape Cstr and Assuming Ops ---===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "PassDetail.h" #include "mlir/Dialect/Shape/IR/Shape.h" #include "mlir/Dialect/Shape/Transforms/Passes.h" #include "mlir/Transforms/DialectConversion.h" #include "mlir/Transforms/GreedyPatternRewriteDriver.h" using namespace mlir; namespace { /// Removal patterns. class RemoveCstrBroadcastableOp : public OpRewritePattern { public: using OpRewritePattern::OpRewritePattern; LogicalResult matchAndRewrite(shape::CstrBroadcastableOp op, PatternRewriter &rewriter) const override { rewriter.replaceOpWithNewOp(op.getOperation(), true); return success(); } }; class RemoveCstrEqOp : public OpRewritePattern { public: using OpRewritePattern::OpRewritePattern; LogicalResult matchAndRewrite(shape::CstrEqOp op, PatternRewriter &rewriter) const override { rewriter.replaceOpWithNewOp(op.getOperation(), true); return success(); } }; /// Removal pass. class RemoveShapeConstraintsPass : public RemoveShapeConstraintsBase { void runOnFunction() override { MLIRContext &ctx = getContext(); OwningRewritePatternList patterns; populateRemoveShapeConstraintsPatterns(patterns, &ctx); applyPatternsAndFoldGreedily(getFunction(), std::move(patterns)); } }; } // namespace void mlir::populateRemoveShapeConstraintsPatterns( OwningRewritePatternList &patterns, MLIRContext *ctx) { patterns.insert(ctx); } std::unique_ptr mlir::createRemoveShapeConstraintsPass() { return std::make_unique(); }