[Mlir-commits] [llvm] [mlir] [mlir][EmitC] Add MathToEmitC pass for math function lowering to EmitC (PR #113799)

Tomer Solomon llvmlistbot at llvm.org
Wed Nov 20 06:53:21 PST 2024


================
@@ -0,0 +1,83 @@
+//===- MathToEmitC.cpp - Math to EmitC  Patterns ----------------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/Conversion/MathToEmitC/MathToEmitC.h"
+
+#include "mlir/Dialect/EmitC/IR/EmitC.h"
+#include "mlir/Dialect/Math/IR/Math.h"
+#include "mlir/Transforms/DialectConversion.h"
+
+using namespace mlir;
+
+namespace {
+template <typename OpType>
+class LowerToEmitCCallOpaque : public OpRewritePattern<OpType> {
+  std::string calleeStr;
+  emitc::MathToEmitCLanguageTarget languageTarget;
+
+public:
+  LowerToEmitCCallOpaque(MLIRContext *context, std::string calleeStr,
+                         emitc::MathToEmitCLanguageTarget languageTarget)
+      : OpRewritePattern<OpType>(context), calleeStr(std::move(calleeStr)),
+        languageTarget(languageTarget) {}
+
+  LogicalResult matchAndRewrite(OpType op,
+                                PatternRewriter &rewriter) const override;
+};
+
+template <typename OpType>
+LogicalResult LowerToEmitCCallOpaque<OpType>::matchAndRewrite(
+    OpType op, PatternRewriter &rewriter) const {
+  if (!llvm::all_of(op->getOperandTypes(), llvm::IsaPred<Float32Type, Float64Type>)||
+      !llvm::all_of(op->getResultTypes(),llvm::IsaPred<Float32Type, Float64Type>))
+    return rewriter.notifyMatchFailure(
+        op.getLoc(), "expected all operands and results to be of type f32");
----------------
recursion-man wrote:

Right

https://github.com/llvm/llvm-project/pull/113799


More information about the Mlir-commits mailing list