22#define DEBUG_TYPE "linalg-category-to-named"
28 LogicalResult matchAndRewrite(ElementwiseOp op,
31 if (!op.getIndexingMapsArray().empty() &&
32 !llvm::all_of(op.getIndexingMapsArray(),
33 [](
AffineMap map) { return map.isIdentity(); }))
36 auto inputs = op.getDpsInputs();
37 auto inits = op.getDpsInits();
38 auto loc = op.getLoc();
41 auto replaceWith = [&](
auto namedOp) {
42 using OpTy =
decltype(namedOp);
43 rewriter.
replaceOp(op, OpTy::create(rewriter, loc, inputs, inits,
48 switch (op.getKind()) {
49 case ElementwiseKind::exp:
50 return replaceWith(ExpOp{});
51 case ElementwiseKind::log:
52 return replaceWith(LogOp{});
53 case ElementwiseKind::abs:
54 return replaceWith(AbsOp{});
55 case ElementwiseKind::ceil:
56 return replaceWith(CeilOp{});
57 case ElementwiseKind::floor:
58 return replaceWith(FloorOp{});
59 case ElementwiseKind::negf:
60 return replaceWith(NegFOp{});
61 case ElementwiseKind::reciprocal:
62 return replaceWith(ReciprocalOp{});
63 case ElementwiseKind::round:
64 return replaceWith(RoundOp{});
65 case ElementwiseKind::sqrt:
66 return replaceWith(SqrtOp{});
67 case ElementwiseKind::rsqrt:
68 return replaceWith(RsqrtOp{});
69 case ElementwiseKind::square:
70 return replaceWith(SquareOp{});
71 case ElementwiseKind::tanh:
72 return replaceWith(TanhOp{});
73 case ElementwiseKind::erf:
74 return replaceWith(ErfOp{});
75 case ElementwiseKind::add:
76 return replaceWith(AddOp{});
77 case ElementwiseKind::sub:
78 return replaceWith(SubOp{});
79 case ElementwiseKind::mul:
80 return replaceWith(MulOp{});
81 case ElementwiseKind::div:
82 return replaceWith(DivOp{});
83 case ElementwiseKind::div_unsigned:
84 return replaceWith(DivUnsignedOp{});
85 case ElementwiseKind::max_signed:
86 return replaceWith(MaxOp{});
87 case ElementwiseKind::min_signed:
88 return replaceWith(MinOp{});
89 case ElementwiseKind::powf:
90 return replaceWith(PowFOp{});
91 case ElementwiseKind::select:
92 return replaceWith(SelectOp{});
102 patterns.
add<ElementwiseToNamedPattern>(patterns.
getContext());
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
MLIRContext * getContext() const
RewritePatternSet & add(ConstructorArg &&arg, ConstructorArgs &&...args)
Add an instance of each of the pattern types 'Ts' to the pattern list with the given arguments.
virtual void replaceOp(Operation *op, ValueRange newValues)
Replace the results of the given (original) operation with the specified list of values (replacements...
void populateLinalgCategoryToNamedPatterns(RewritePatternSet &patterns)
Populates patterns that convert linalg category ops (e.g.
Include the generated interface declarations.
OpRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting against an...