[Mlir-commits] [mlir] [mlir][tosa][spirv] Lower TOSA elementwise ops to SPIR-V TOSA (PR #199505)
Jakub Kuderski
llvmlistbot at llvm.org
Mon May 25 09:22:13 PDT 2026
================
@@ -0,0 +1,129 @@
+//===- TosaToSPIRVTosaOps.cpp - TOSA to SPIR-V Graph/TOSA patterns --------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements patterns to convert TOSA IR to SPIR-V Graph/TOSA.
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/Conversion/TosaToSPIRVTosa/TosaToSPIRVTosa.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
+#include "mlir/Dialect/Tosa/IR/TosaOps.h"
+#include "mlir/Transforms/DialectConversion.h"
+
+#define DEBUG_TYPE "tosa-to-spirv-tosa-ops-pattern"
+
+namespace mlir {
+namespace tosa {
+namespace {
+
+template <typename OpAdaptor>
+inline Value getInput1(OpAdaptor adaptor) {
+ return adaptor.getInput1();
+}
+
+inline Value getInput1(tosa::ErfOpAdaptor adaptor) {
+ return adaptor.getInput();
+}
+
+inline Value getInput1(tosa::SigmoidOpAdaptor adaptor) {
+ return adaptor.getInput();
+}
+
+inline Value getInput1(tosa::TanhOpAdaptor adaptor) {
+ return adaptor.getInput();
+}
+
+template <typename SourceOp, typename TargetOp>
+struct UnaryElementwiseOpConvert final : public OpConversionPattern<SourceOp> {
+ using OpConversionPattern<SourceOp>::OpConversionPattern;
+
+ LogicalResult
+ matchAndRewrite(SourceOp op, typename SourceOp::Adaptor adaptor,
+ ConversionPatternRewriter &rewriter) const override {
+ Type type = this->getTypeConverter()->convertType(op.getType());
----------------
kuhar wrote:
Should we check if this succeeded?
https://github.com/llvm/llvm-project/pull/199505
More information about the Mlir-commits
mailing list