[Mlir-commits] [mlir] [TOSA] Convert tosa.elementwise to linalg.elementwise (PR #224344)
Sayan Saha
llvmlistbot at llvm.org
Sat Sep 26 10:43:19 PDT 2026
================
@@ -603,6 +728,81 @@ class DepthwiseConvConverter
}
};
+// Lower TOSA elementwise ops that have a direct linalg.elementwise named op
+// counterpart. Unlike linalg.generic, linalg.elementwise dispatches on a single
+// function kind and infers the body, so the conversion is a handful of checks
+// (kind, ranks, static shapes) followed by construction of the indexing maps
+// and the named op.
+template <typename TosaOp>
+class ElementwiseConverter : public OpConversionPattern<TosaOp> {
+public:
+ using OpConversionPattern<TosaOp>::OpConversionPattern;
+ using typename OpConversionPattern<TosaOp>::OpAdaptor;
+
+ LogicalResult
+ matchAndRewrite(TosaOp op, OpAdaptor adaptor,
+ ConversionPatternRewriter &rewriter) const final {
+ if (!isConvertibleToLinalgElementwise(op))
----------------
sahas3 wrote:
Since this function also computes `getElementwiseKind` internally, consider returning that computed value from the function to avoid the second call on L:753
https://github.com/llvm/llvm-project/pull/224344
More information about the Mlir-commits
mailing list