24 LogicalResult matchAndRewrite(math::SinOp sinOp,
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) {
33 return WalkResult::interrupt();
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"
65 struct MathSincosFusionPass final
66 : math::impl::MathSincosFusionPassBase<MathSincosFusionPass> {
67 using MathSincosFusionPassBase::MathSincosFusionPassBase;
69 void runOnOperation()
override {
76 return signalPassFailure();
static MLIRContext * getContext(OpFoldResult val)
This class allows control over how the GreedyPatternRewriteDriver works.
void setInsertionPoint(Block *block, Block::iterator insertPoint)
Set the insertion point to the specified location.
Operation is the basic unit of execution within MLIR.
bool isBeforeInBlock(Operation *other)
Given an operation 'other' that is within the same parent block, return whether the current operation...
Location getLoc()
The source location the operation was defined or derived from.
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
virtual void replaceOp(Operation *op, ValueRange newValues)
Replace the results of the given (original) operation with the specified list of values (replacements...
This class provides an abstraction over the various different ranges of value types.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
static WalkResult advance()
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...