[Mlir-commits] [flang] [mlir] [MLIR] Add ComplexTOROCDL pass (PR #144926)
Oleksandr Alex Zinenko
llvmlistbot at llvm.org
Thu Jun 19 11:25:24 PDT 2025
================
@@ -0,0 +1,94 @@
+//===-- ComplexToROCDL.cpp - conversion from Complex to ROCDL calls -------===//
+//
+// 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/ComplexToROCDL/ComplexToROCDL.h"
+#include "mlir/Dialect/Complex/IR/Complex.h"
+#include "mlir/Dialect/Func/IR/FuncOps.h"
+#include "mlir/IR/PatternMatch.h"
+#include "mlir/Transforms/DialectConversion.h"
+#include <optional>
+
+namespace mlir {
+#define GEN_PASS_DEF_CONVERTCOMPLEXTOROCDL
+#include "mlir/Conversion/Passes.h.inc"
+} // namespace mlir
+
+using namespace mlir;
+
+namespace {
+struct FloatTypeResolver {
+ std::optional<bool> operator()(Type type) const {
+ auto elementType = cast<FloatType>(type);
+ if (!isa<Float32Type, Float64Type>(elementType))
+ return {};
+ return elementType.getIntOrFloatBitWidth() == 64;
+ }
+};
+
+template <typename Op, typename TypeResolver = FloatTypeResolver>
+struct ScalarOpToROCDLCall : public OpRewritePattern<Op> {
+ using OpRewritePattern<Op>::OpRewritePattern;
+ ScalarOpToROCDLCall(MLIRContext *context, StringRef floatFunc,
+ StringRef doubleFunc, PatternBenefit benefit)
+ : OpRewritePattern<Op>(context, benefit), floatFunc(floatFunc),
+ doubleFunc(doubleFunc) {}
+
+ LogicalResult matchAndRewrite(Op op, PatternRewriter &rewriter) const final {
+ auto module = SymbolTable::getNearestSymbolTable(op);
----------------
ftynse wrote:
Expand `auto` unless the type is obvious from statement-level context or impossible to spell.
Also avoid using `module` as a name since it will become a reserved keyword with a C++ version bump.
https://github.com/llvm/llvm-project/pull/144926
More information about the Mlir-commits
mailing list