//===- StandalonePasses.cpp - Standalone passes -----------------*- C++ -*-===// // // This file is licensed 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 "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/PatternMatch.h" #include "mlir/Rewrite/FrozenRewritePatternSet.h" #include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/GreedyPatternRewriteDriver.h" #include "Standalone/StandalonePasses.h" namespace mlir::standalone { #define GEN_PASS_DEF_STANDALONESWITCHBARFOO #include "Standalone/StandalonePasses.h.inc" namespace { class StandaloneSwitchBarFooRewriter : public OpRewritePattern { public: using OpRewritePattern::OpRewritePattern; LogicalResult matchAndRewrite(func::FuncOp op, PatternRewriter &rewriter) const final { if (op.getSymName() == "bar") { rewriter.modifyOpInPlace(op, [&op]() { op.setSymName("foo"); }); return success(); } return failure(); } }; class StandaloneSwitchBarFoo : public impl::StandaloneSwitchBarFooBase { public: using impl::StandaloneSwitchBarFooBase< StandaloneSwitchBarFoo>::StandaloneSwitchBarFooBase; void runOnOperation() final { RewritePatternSet patterns(&getContext()); patterns.add(&getContext()); FrozenRewritePatternSet patternSet(std::move(patterns)); if (failed(applyPatternsAndFoldGreedily(getOperation(), patternSet))) signalPassFailure(); } }; } // namespace } // namespace mlir::standalone