llvm/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp

//===- ComplexToStandard.cpp - conversion from Complex to Standard dialect ===//
//
// 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/ComplexToStandard/ComplexToStandard.h"

#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/Complex/IR/Complex.h"
#include "mlir/Dialect/Math/IR/Math.h"
#include "mlir/IR/ImplicitLocOpBuilder.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Transforms/DialectConversion.h"
#include <memory>
#include <type_traits>

namespace mlir {
#define GEN_PASS_DEF_CONVERTCOMPLEXTOSTANDARD
#include "mlir/Conversion/Passes.h.inc"
} // namespace mlir

usingnamespacemlir;

namespace {

enum class AbsFn {};

// Returns the absolute value, its square root or its reciprocal square root.
Value computeAbs(Value real, Value imag, arith::FastMathFlags fmf,
                 ImplicitLocOpBuilder &b, AbsFn fn = AbsFn::abs) {}

struct AbsOpConversion : public OpConversionPattern<complex::AbsOp> {};

// atan2(y,x) = -i * log((x + i * y)/sqrt(x**2+y**2))
struct Atan2OpConversion : public OpConversionPattern<complex::Atan2Op> {};

template <typename ComparisonOp, arith::CmpFPredicate p>
struct ComparisonOpConversion : public OpConversionPattern<ComparisonOp> {};

// Default conversion which applies the BinaryStandardOp separately on the real
// and imaginary parts. Can for example be used for complex::AddOp and
// complex::SubOp.
template <typename BinaryComplexOp, typename BinaryStandardOp>
struct BinaryComplexOpConversion : public OpConversionPattern<BinaryComplexOp> {};

template <typename TrigonometricOp>
struct TrigonometricOpConversion : public OpConversionPattern<TrigonometricOp> {};

struct CosOpConversion : public TrigonometricOpConversion<complex::CosOp> {};

struct DivOpConversion : public OpConversionPattern<complex::DivOp> {};

struct ExpOpConversion : public OpConversionPattern<complex::ExpOp> {};

struct Expm1OpConversion : public OpConversionPattern<complex::Expm1Op> {};

struct LogOpConversion : public OpConversionPattern<complex::LogOp> {};

struct Log1pOpConversion : public OpConversionPattern<complex::Log1pOp> {};

struct MulOpConversion : public OpConversionPattern<complex::MulOp> {};

struct NegOpConversion : public OpConversionPattern<complex::NegOp> {};

struct SinOpConversion : public TrigonometricOpConversion<complex::SinOp> {};

// The algorithm is listed in https://dl.acm.org/doi/pdf/10.1145/363717.363780.
struct SqrtOpConversion : public OpConversionPattern<complex::SqrtOp> {};

struct SignOpConversion : public OpConversionPattern<complex::SignOp> {};

template <typename Op>
struct TanTanhOpConversion : public OpConversionPattern<Op> {};

struct ConjOpConversion : public OpConversionPattern<complex::ConjOp> {};

/// Converts lhs^y = (a+bi)^(c+di) to
///    (a*a+b*b)^(0.5c) * exp(-d*atan2(b,a)) * (cos(q) + i*sin(q)),
///    where q = c*atan2(b,a)+0.5d*ln(a*a+b*b)
static Value powOpConversionImpl(mlir::ImplicitLocOpBuilder &builder,
                                 ComplexType type, Value lhs, Value c, Value d,
                                 arith::FastMathFlags fmf) {}

struct PowOpConversion : public OpConversionPattern<complex::PowOp> {};

struct RsqrtOpConversion : public OpConversionPattern<complex::RsqrtOp> {};

struct AngleOpConversion : public OpConversionPattern<complex::AngleOp> {};

} // namespace

void mlir::populateComplexToStandardConversionPatterns(
    RewritePatternSet &patterns) {}

namespace {
struct ConvertComplexToStandardPass
    : public impl::ConvertComplexToStandardBase<ConvertComplexToStandardPass> {};

void ConvertComplexToStandardPass::runOnOperation() {}
} // namespace

std::unique_ptr<Pass> mlir::createConvertComplexToStandardPass() {}