MLIR 22.0.0git
RemoveShapeConstraints.cpp
Go to the documentation of this file.
1//===-- RemoveShapeConstraints.cpp - Remove Shape Cstr and Assuming Ops ---===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10
15
16namespace mlir {
17#define GEN_PASS_DEF_REMOVESHAPECONSTRAINTSPASS
18#include "mlir/Dialect/Shape/Transforms/Passes.h.inc"
19} // namespace mlir
20
21using namespace mlir;
22
23namespace {
24/// Removal patterns.
25class RemoveCstrBroadcastableOp
26 : public OpRewritePattern<shape::CstrBroadcastableOp> {
27public:
29
30 LogicalResult matchAndRewrite(shape::CstrBroadcastableOp op,
31 PatternRewriter &rewriter) const override {
32 rewriter.replaceOpWithNewOp<shape::ConstWitnessOp>(op.getOperation(), true);
33 return success();
34 }
35};
36
37class RemoveCstrEqOp : public OpRewritePattern<shape::CstrEqOp> {
38public:
40
41 LogicalResult matchAndRewrite(shape::CstrEqOp op,
42 PatternRewriter &rewriter) const override {
43 rewriter.replaceOpWithNewOp<shape::ConstWitnessOp>(op.getOperation(), true);
44 return success();
45 }
46};
47
48/// Removal pass.
49class RemoveShapeConstraintsPass
50 : public impl::RemoveShapeConstraintsPassBase<RemoveShapeConstraintsPass> {
51
52 void runOnOperation() override {
53 MLIRContext &ctx = getContext();
54
55 RewritePatternSet patterns(&ctx);
57
58 (void)applyPatternsGreedily(getOperation(), std::move(patterns));
59 }
60};
61
62} // namespace
63
65 patterns.add<RemoveCstrBroadcastableOp, RemoveCstrEqOp>(
66 patterns.getContext());
67}
return success()
b getContext())
OpTy replaceOpWithNewOp(Operation *op, Args &&...args)
Replace the results of the given (original) op with a new op that is created without verification (re...
Include the generated interface declarations.
LogicalResult applyPatternsGreedily(Region &region, const FrozenRewritePatternSet &patterns, GreedyRewriteConfig config=GreedyRewriteConfig(), bool *changed=nullptr)
Rewrite ops in the given region, which must be isolated from above, by repeatedly applying the highes...
const FrozenRewritePatternSet & patterns
void populateRemoveShapeConstraintsPatterns(RewritePatternSet &patterns)
OpRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting against an...
OpRewritePattern(MLIRContext *context, PatternBenefit benefit=1, ArrayRef< StringRef > generatedNames={})
Patterns must specify the root operation name they match against, and can also specify the benefit of...