[flang-commits] [flang] [Flang] Add new ConvertComplexPow pass for Flang (PR #158642)
Slava Zakharin via flang-commits
flang-commits at lists.llvm.org
Mon Sep 15 11:08:26 PDT 2025
================
@@ -0,0 +1,124 @@
+//===- ConvertComplexPow.cpp - Convert complex.pow to library 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 "flang/Common/static-multimap-view.h"
+#include "flang/Optimizer/Builder/FIRBuilder.h"
+#include "flang/Optimizer/Dialect/FIRDialect.h"
+#include "flang/Optimizer/Transforms/Passes.h"
+#include "flang/Runtime/entry-names.h"
+#include "mlir/Dialect/Arith/IR/Arith.h"
+#include "mlir/Dialect/Complex/IR/Complex.h"
+#include "mlir/Dialect/Func/IR/FuncOps.h"
+#include "mlir/Pass/Pass.h"
+
+namespace fir {
+#define GEN_PASS_DEF_CONVERTCOMPLEXPOW
+#include "flang/Optimizer/Transforms/Passes.h.inc"
+} // namespace fir
+
+using namespace mlir;
+
+namespace {
+class ConvertComplexPowPass
+ : public fir::impl::ConvertComplexPowBase<ConvertComplexPowPass> {
+public:
+ void getDependentDialects(DialectRegistry ®istry) const override {
+ registry.insert<fir::FIROpsDialect, complex::ComplexDialect,
+ arith::ArithDialect, func::FuncDialect>();
+ }
+ void runOnOperation() override;
+};
+} // namespace
+
+// Helper to declare or get a math library function.
+static func::FuncOp getOrDeclare(fir::FirOpBuilder &builder, Location loc,
+ StringRef name, FunctionType type) {
+ if (auto func = builder.getNamedFunction(name))
+ return func;
+ auto func = builder.createFunction(loc, name, type);
+ func->setAttr(fir::getSymbolAttrName(), builder.getStringAttr(name));
+ func->setAttr(fir::FIROpsDialect::getFirRuntimeAttrName(),
+ builder.getUnitAttr());
+ return func;
+}
+
+static bool isZero(Value v) {
+ if (auto cst = v.getDefiningOp<arith::ConstantOp>())
+ if (auto attr = dyn_cast<FloatAttr>(cst.getValue()))
+ return attr.getValue().isZero();
+ return false;
+}
+
+void ConvertComplexPowPass::runOnOperation() {
+ ModuleOp mod = getOperation();
+ if (fir::getTargetTriple(mod).isAMDGCN())
----------------
vzakhari wrote:
Can you please make the pass generic, and instead not schedule it for AMDGCN in the `Pipelines.cpp`?
https://github.com/llvm/llvm-project/pull/158642
More information about the flang-commits
mailing list