[Mlir-commits] [llvm] [mlir] [mlir][EmitC] Add MathToEmitC pass for math function lowering to EmitC (PR #113799)
Simon Camphausen
llvmlistbot at llvm.org
Tue Oct 29 07:06:28 PDT 2024
================
@@ -0,0 +1,65 @@
+//===- MathToEmitC.cpp - Math to EmitC Pass Implementation ----------===//
+//
+// 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 mlir::OpRewritePattern<OpType> {
+ std::string calleeStr;
+
+public:
+ LowerToEmitCCallOpaque(MLIRContext *context, std::string calleeStr)
+ : OpRewritePattern<OpType>(context), calleeStr(std::move(calleeStr)) {}
+
+ LogicalResult matchAndRewrite(OpType op,
+ PatternRewriter &rewriter) const override;
+};
+
+template <typename OpType>
+LogicalResult LowerToEmitCCallOpaque<OpType>::matchAndRewrite(
+ OpType op, PatternRewriter &rewriter) const {
+ auto actualOp = mlir::cast<OpType>(op);
+ if (!llvm::all_of(
----------------
simon-camp wrote:
You can use something like
```cpp
!llvm::all_of(actualOp->getOperandTypes(), llvm::IsaPred<Float32Type, Float64Type>)
```
https://github.com/llvm/llvm-project/pull/113799
More information about the Mlir-commits
mailing list