diff --git a/flang/lib/Lower/IntrinsicCall.cpp b/flang/lib/Lower/IntrinsicCall.cpp --- a/flang/lib/Lower/IntrinsicCall.cpp +++ b/flang/lib/Lower/IntrinsicCall.cpp @@ -1189,6 +1189,20 @@ return mlir::FunctionType::get(context, {itype, itype}, {itype}); } +template +static mlir::FunctionType +genComplexComplexFuncType(mlir::MLIRContext *context) { + auto ctype = fir::ComplexType::get(context, Kind); + return mlir::FunctionType::get(context, {ctype}, {ctype}); +} + +template +static mlir::FunctionType +genComplexComplexComplexFuncType(mlir::MLIRContext *context) { + auto ctype = fir::ComplexType::get(context, Kind); + return mlir::FunctionType::get(context, {ctype, ctype}, {ctype}); +} + /// Callback type for generating lowering for a math operation. using MathGeneratorTy = mlir::Value (*)(fir::FirOpBuilder &, mlir::Location, llvm::StringRef, mlir::FunctionType, @@ -1283,10 +1297,16 @@ {"abs", "fabs", genF64F64FuncType, genMathOp}, {"abs", "llvm.fabs.f128", genF128F128FuncType, genMathOp}, + {"abs", "cabsf", genComplexComplexFuncType<4>, genLibCall}, + {"abs", "cabs", genComplexComplexFuncType<8>, genLibCall}, {"acos", "acosf", genF32F32FuncType, genLibCall}, {"acos", "acos", genF64F64FuncType, genLibCall}, + {"acos", "cacosf", genComplexComplexFuncType<4>, genLibCall}, + {"acos", "cacos", genComplexComplexFuncType<8>, genLibCall}, {"acosh", "acoshf", genF32F32FuncType, genLibCall}, {"acosh", "acosh", genF64F64FuncType, genLibCall}, + {"acosh", "cacoshf", genComplexComplexFuncType<4>, genLibCall}, + {"acosh", "cacosh", genComplexComplexFuncType<8>, genLibCall}, // llvm.trunc behaves the same way as libm's trunc. {"aint", "llvm.trunc.f32", genF32F32FuncType, genLibCall}, {"aint", "llvm.trunc.f64", genF64F64FuncType, genLibCall}, @@ -1300,14 +1320,22 @@ genMathOp}, {"asin", "asinf", genF32F32FuncType, genLibCall}, {"asin", "asin", genF64F64FuncType, genLibCall}, + {"asin", "casinf", genComplexComplexFuncType<4>, genLibCall}, + {"asin", "casin", genComplexComplexFuncType<8>, genLibCall}, {"asinh", "asinhf", genF32F32FuncType, genLibCall}, {"asinh", "asinh", genF64F64FuncType, genLibCall}, + {"asinh", "casinhf", genComplexComplexFuncType<4>, genLibCall}, + {"asinh", "casinh", genComplexComplexFuncType<8>, genLibCall}, {"atan", "atanf", genF32F32FuncType, genMathOp}, {"atan", "atan", genF64F64FuncType, genMathOp}, + {"atan", "catanf", genComplexComplexFuncType<4>, genLibCall}, + {"atan", "catan", genComplexComplexFuncType<8>, genLibCall}, {"atan2", "atan2f", genF32F32F32FuncType, genMathOp}, {"atan2", "atan2", genF64F64F64FuncType, genMathOp}, {"atanh", "atanhf", genF32F32FuncType, genLibCall}, {"atanh", "atanh", genF64F64FuncType, genLibCall}, + {"atanh", "ctanhf", genComplexComplexFuncType<4>, genLibCall}, + {"atanh", "ctanh", genComplexComplexFuncType<8>, genLibCall}, {"bessel_j0", "j0f", genF32F32FuncType, genLibCall}, {"bessel_j0", "j0", genF64F64FuncType, genLibCall}, {"bessel_j1", "j1f", genF32F32FuncType, genLibCall}, @@ -1323,16 +1351,24 @@ // math::CeilOp returns a real, while Fortran CEILING returns integer. {"ceil", "ceilf", genF32F32FuncType, genMathOp}, {"ceil", "ceil", genF64F64FuncType, genMathOp}, + {"conjg", "conjf", genComplexComplexFuncType<4>, genLibCall}, + {"conjg", "conj", genComplexComplexFuncType<8>, genLibCall}, {"cos", "cosf", genF32F32FuncType, genMathOp}, {"cos", "cos", genF64F64FuncType, genMathOp}, + {"cos", "ccosf", genComplexComplexFuncType<4>, genLibCall}, + {"cos", "ccos", genComplexComplexFuncType<8>, genLibCall}, {"cosh", "coshf", genF32F32FuncType, genLibCall}, {"cosh", "cosh", genF64F64FuncType, genLibCall}, + {"cosh", "ccoshf", genComplexComplexFuncType<4>, genLibCall}, + {"cosh", "ccosh", genComplexComplexFuncType<8>, genLibCall}, {"erf", "erff", genF32F32FuncType, genMathOp}, {"erf", "erf", genF64F64FuncType, genMathOp}, {"erfc", "erfcf", genF32F32FuncType, genLibCall}, {"erfc", "erfc", genF64F64FuncType, genLibCall}, {"exp", "expf", genF32F32FuncType, genMathOp}, {"exp", "exp", genF64F64FuncType, genMathOp}, + {"exp", "cexpf", genComplexComplexFuncType<4>, genLibCall}, + {"exp", "cexp", genComplexComplexFuncType<8>, genLibCall}, // math::FloorOp returns a real, while Fortran FLOOR returns integer. {"floor", "floorf", genF32F32FuncType, genMathOp}, {"floor", "floor", genF64F64FuncType, genMathOp}, @@ -1342,6 +1378,8 @@ {"hypot", "hypot", genF64F64F64FuncType, genLibCall}, {"log", "logf", genF32F32FuncType, genMathOp}, {"log", "log", genF64F64FuncType, genMathOp}, + {"log", "clogf", genComplexComplexFuncType<4>, genLibCall}, + {"log", "clog", genComplexComplexFuncType<8>, genLibCall}, {"log10", "log10f", genF32F32FuncType, genMathOp}, {"log10", "log10", genF64F64FuncType, genMathOp}, {"log_gamma", "lgammaf", genF32F32FuncType, genLibCall}, @@ -1357,6 +1395,8 @@ {"pow", {}, genIntIntIntFuncType<64>, genMathOp}, {"pow", "powf", genF32F32F32FuncType, genMathOp}, {"pow", "pow", genF64F64F64FuncType, genMathOp}, + {"pow", "cpowf", genComplexComplexComplexFuncType<4>, genLibCall}, + {"pow", "cpow", genComplexComplexComplexFuncType<8>, genLibCall}, // TODO: add PowIOp in math and complex dialects. {"pow", "llvm.powi.f32.i32", genF32F32IntFuncType<32>, genLibCall}, {"pow", "llvm.powi.f64.i32", genF64F64IntFuncType<32>, genLibCall}, @@ -1370,14 +1410,24 @@ genMathOp}, {"sin", "sinf", genF32F32FuncType, genMathOp}, {"sin", "sin", genF64F64FuncType, genMathOp}, + {"sin", "csinf", genComplexComplexFuncType<4>, genLibCall}, + {"sin", "csin", genComplexComplexFuncType<8>, genLibCall}, {"sinh", "sinhf", genF32F32FuncType, genLibCall}, {"sinh", "sinh", genF64F64FuncType, genLibCall}, + {"sinh", "csinhf", genComplexComplexFuncType<4>, genLibCall}, + {"sinh", "csinh", genComplexComplexFuncType<8>, genLibCall}, {"sqrt", "sqrtf", genF32F32FuncType, genMathOp}, {"sqrt", "sqrt", genF64F64FuncType, genMathOp}, + {"sqrt", "csqrtf", genComplexComplexFuncType<4>, genLibCall}, + {"sqrt", "csqrt", genComplexComplexFuncType<8>, genLibCall}, {"tan", "tanf", genF32F32FuncType, genMathOp}, {"tan", "tan", genF64F64FuncType, genMathOp}, + {"tan", "ctanf", genComplexComplexFuncType<4>, genLibCall}, + {"tan", "ctan", genComplexComplexFuncType<8>, genLibCall}, {"tanh", "tanhf", genF32F32FuncType, genMathOp}, {"tanh", "tanh", genF64F64FuncType, genMathOp}, + {"tanh", "ctanhf", genComplexComplexFuncType<4>, genLibCall}, + {"tanh", "ctanh", genComplexComplexFuncType<8>, genLibCall}, }; // This helper class computes a "distance" between two function types. diff --git a/flang/test/Lower/Intrinsics/exp.f90 b/flang/test/Lower/Intrinsics/exp.f90 --- a/flang/test/Lower/Intrinsics/exp.f90 +++ b/flang/test/Lower/Intrinsics/exp.f90 @@ -53,10 +53,10 @@ ! CHECK-LABEL: private @fir.exp.z4.z4 ! CHECK-SAME: (%[[ARG32_OUTLINE]]: !fir.complex<4>) -> !fir.complex<4> -! CHECK: %[[RESULT32_OUTLINE]] = fir.call @__fc_exp_1(%[[ARG32_OUTLINE]]) : (!fir.complex<4>) -> !fir.complex<4> +! CHECK: %[[RESULT32_OUTLINE]] = fir.call @cexpf(%[[ARG32_OUTLINE]]) : (!fir.complex<4>) -> !fir.complex<4> ! CHECK: return %[[RESULT32_OUTLINE]] : !fir.complex<4> ! CHECK-LABEL: private @fir.exp.z8.z8 ! CHECK-SAME: (%[[ARG64_OUTLINE]]: !fir.complex<8>) -> !fir.complex<8> -! CHECK: %[[RESULT64_OUTLINE]] = fir.call @__fz_exp_1(%[[ARG64_OUTLINE]]) : (!fir.complex<8>) -> !fir.complex<8> +! CHECK: %[[RESULT64_OUTLINE]] = fir.call @cexp(%[[ARG64_OUTLINE]]) : (!fir.complex<8>) -> !fir.complex<8> ! CHECK: return %[[RESULT64_OUTLINE]] : !fir.complex<8> diff --git a/flang/test/Lower/Intrinsics/log.f90 b/flang/test/Lower/Intrinsics/log.f90 --- a/flang/test/Lower/Intrinsics/log.f90 +++ b/flang/test/Lower/Intrinsics/log.f90 @@ -73,12 +73,12 @@ ! CHECK-LABEL: private @fir.log.z4.z4 ! CHECK-SAME: (%[[ARG32_OUTLINE]]: !fir.complex<4>) -> !fir.complex<4> -! CHECK: %[[RESULT32_OUTLINE]] = fir.call @__fc_log_1(%[[ARG32_OUTLINE]]) : (!fir.complex<4>) -> !fir.complex<4> +! CHECK: %[[RESULT32_OUTLINE]] = fir.call @clogf(%[[ARG32_OUTLINE]]) : (!fir.complex<4>) -> !fir.complex<4> ! CHECK: return %[[RESULT32_OUTLINE]] : !fir.complex<4> ! CHECK-LABEL: private @fir.log.z8.z8 ! CHECK-SAME: (%[[ARG64_OUTLINE]]: !fir.complex<8>) -> !fir.complex<8> -! CHECK: %[[RESULT64_OUTLINE]] = fir.call @__fz_log_1(%[[ARG64_OUTLINE]]) : (!fir.complex<8>) -> !fir.complex<8> +! CHECK: %[[RESULT64_OUTLINE]] = fir.call @clog(%[[ARG64_OUTLINE]]) : (!fir.complex<8>) -> !fir.complex<8> ! CHECK: return %[[RESULT64_OUTLINE]] : !fir.complex<8> ! CHECK-LABEL: private @fir.log10.f32.f32 diff --git a/flang/test/Lower/sqrt.f90 b/flang/test/Lower/sqrt.f90 --- a/flang/test/Lower/sqrt.f90 +++ b/flang/test/Lower/sqrt.f90 @@ -36,7 +36,7 @@ ! CHECK: math.sqrt %{{.*}} : f64 ! CHECK-LABEL: func private @fir.sqrt.z4.z4 -! CHECK: fir.call {{.*}}fc_sqrt +! CHECK: fir.call @csqrtf ! CHECK-LABEL: @fir.sqrt.z8.z8 -! CHECK: fir.call {{.*}}fz_sqrt +! CHECK: fir.call @csqrt diff --git a/flang/test/Lower/trigonometric-intrinsics.f90 b/flang/test/Lower/trigonometric-intrinsics.f90 --- a/flang/test/Lower/trigonometric-intrinsics.f90 +++ b/flang/test/Lower/trigonometric-intrinsics.f90 @@ -148,10 +148,10 @@ ! CHECK: math.atan %{{.*}} : f64 ! CHECK-LABEL: @fir.atan.z4.z4 -! CHECK: fir.call {{.*}}atan +! CHECK: fir.call @catanf ! CHECK-LABEL: @fir.atan.z8.z8 -! CHECK: fir.call {{.*}}atan +! CHECK: fir.call @catan ! CHECK-LABEL: @fir.cos.f32.f32 ! CHECK: math.cos %{{.*}} : f32 @@ -160,10 +160,10 @@ ! CHECK: math.cos %{{.*}} : f64 ! CHECK-LABEL: @fir.cos.z4.z4 -! CHECK: fir.call {{.*}}cos +! CHECK: fir.call @ccosf ! CHECK-LABEL: @fir.cos.z8.z8 -! CHECK: fir.call {{.*}}cos +! CHECK: fir.call @ccos ! CHECK-LABEL: @fir.cosh.f32.f32 ! CHECK: fir.call {{.*}}cosh @@ -172,10 +172,10 @@ ! CHECK: fir.call {{.*}}cosh ! CHECK-LABEL: @fir.cosh.z4.z4 -! CHECK: fir.call {{.*}}cosh +! CHECK: fir.call @ccoshf ! CHECK-LABEL: @fir.cosh.z8.z8 -! CHECK: fir.call {{.*}}cosh +! CHECK: fir.call @ccosh ! CHECK-LABEL: @fir.sin.f32.f32 ! CHECK: math.sin %{{.*}} : f32 @@ -184,10 +184,10 @@ ! CHECK: math.sin %{{.*}} : f64 ! CHECK-LABEL: @fir.sin.z4.z4 -! CHECK: fir.call {{.*}}sin +! CHECK: fir.call @csinf ! CHECK-LABEL: @fir.sin.z8.z8 -! CHECK: fir.call {{.*}}sin +! CHECK: fir.call @csin ! CHECK-LABEL: @fir.sinh.f32.f32 ! CHECK: fir.call {{.*}}sinh @@ -196,7 +196,7 @@ ! CHECK: fir.call {{.*}}sinh ! CHECK-LABEL: @fir.sinh.z4.z4 -! CHECK: fir.call {{.*}}sinh +! CHECK: fir.call @csinhf ! CHECK-LABEL: @fir.sinh.z8.z8 -! CHECK: fir.call {{.*}}sinh +! CHECK: fir.call @csinh