20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/TypeSwitch.h"
26 #define DEBUG_TYPE "linalg-named-to-elementwise"
31 .Case([](SelectOp) {
return ElementwiseKind::select; })
33 .Case([](SubOp) {
return ElementwiseKind::sub; })
34 .Case([](MulOp) {
return ElementwiseKind::mul; })
35 .Case([](DivOp) {
return ElementwiseKind::div; })
36 .Case([](DivUnsignedOp) {
return ElementwiseKind::div_unsigned; })
37 .Case([](PowFOp) {
return ElementwiseKind::powf; })
38 .Case([](ExpOp) {
return ElementwiseKind::exp; })
39 .Case([](LogOp) {
return ElementwiseKind::log; })
43 .Case([](NegFOp) {
return ElementwiseKind::negf; })
44 .Case([](ReciprocalOp) {
return ElementwiseKind::reciprocal; })
46 .Case([](SqrtOp) {
return ElementwiseKind::sqrt; })
47 .Case([](RsqrtOp) {
return ElementwiseKind::rsqrt; })
48 .Case([](SquareOp) {
return ElementwiseKind::square; })
49 .Case([](TanhOp) {
return ElementwiseKind::tanh; })
50 .Case([](ErfOp) {
return ElementwiseKind::erf; })
52 llvm_unreachable(
"unhandled case in named to elementwise");
53 return ElementwiseKind::sub;
57 template <
typename NamedOpTy>
61 LogicalResult matchAndRewrite(NamedOpTy op,
65 attrs.push_back(rewriter.
getNamedAttr(
"kind", kindAttr));
67 rewriter.
getNamedAttr(
"indexing_maps", op.getIndexingMaps()));
70 op.getDpsInits(), attrs);
83 patterns.add<NamedToElementwisePattern<DivUnsignedOp>>(
patterns.getContext());
91 patterns.add<NamedToElementwisePattern<ReciprocalOp>>(
patterns.getContext());
NamedAttribute getNamedAttr(StringRef name, Attribute val)
Operation is the basic unit of execution within MLIR.
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
OpTy replaceOpWithNewOp(Operation *op, Args &&...args)
Replace the results of the given (original) op with a new op that is created without verification (re...
void populateLinalgNamedToElementwisePatterns(RewritePatternSet &patterns)
Populates patterns that convert linalg named ops e.g.
DynamicAPInt floor(const Fraction &f)
DynamicAPInt ceil(const Fraction &f)
DynamicAPInt round(const Fraction &f)
Fraction abs(const Fraction &f)
Include the generated interface declarations.
const FrozenRewritePatternSet & patterns
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
OpRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting against an...