24 LogicalResult matchAndRewrite(math::SinOp sinOp,
25 PatternRewriter &rewriter)
const override {
26 Value operand = sinOp.getOperand();
27 mlir::arith::FastMathFlags sinFastMathFlags = sinOp.getFastmath();
29 math::CosOp cosOp =
nullptr;
30 sinOp->getBlock()->walk([&](math::CosOp op) {
31 if (op.getOperand() == operand && op.getFastmath() == sinFastMathFlags) {
41 Operation *firstOp = sinOp->isBeforeInBlock(cosOp) ? sinOp.getOperation()
42 : cosOp.getOperation();
45 Type elemType = sinOp.getType();
46 auto sincos = math::SincosOp::create(rewriter, firstOp->
getLoc(),
48 sinOp.getFastmathAttr());
50 rewriter.
replaceOp(sinOp, sincos.getSin());
51 rewriter.
replaceOp(cosOp, sincos.getCos());
59#define GEN_PASS_DEF_MATHSINCOSFUSIONPASS
60#include "mlir/Dialect/Math/Transforms/Passes.h.inc"
65struct MathSincosFusionPass final
67 using MathSincosFusionPassBase::MathSincosFusionPassBase;
69 void runOnOperation()
override {
73 GreedyRewriteConfig
config;
76 return signalPassFailure();
void setInsertionPoint(Block *block, Block::iterator insertPoint)
Set the insertion point to the specified location.
Location getLoc()
The source location the operation was defined or derived from.
virtual void replaceOp(Operation *op, ValueRange newValues)
Replace the results of the given (original) operation with the specified list of values (replacements...
static WalkResult advance()
static WalkResult interrupt()
Include the generated interface declarations.
const FrozenRewritePatternSet GreedyRewriteConfig config
LogicalResult applyPatternsGreedily(Region ®ion, 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
OpRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting against an...