@@ -689,22 +689,22 @@ prettyPrintIntrinsicName(fir::FirOpBuilder &builder, mlir::Location loc,
689689}
690690
691691// Generate a call to the Fortran runtime library providing
692- // support for 128-bit float math via a third-party library.
693- // If the compiler is built without FLANG_RUNTIME_F128_MATH_LIB,
694- // this function will report an error.
692+ // support for 128-bit float math.
693+ // On 'LDBL_MANT_DIG == 113' targets the implementation
694+ // is provided by FortranRuntime, otherwise, it is done via
695+ // FortranFloat128Math library. In the latter case the compiler
696+ // has to be built with FLANG_RUNTIME_F128_MATH_LIB to guarantee
697+ // proper linking actions in the driver.
695698static mlir::Value genLibF128Call (fir::FirOpBuilder &builder,
696699 mlir::Location loc,
697700 const MathOperation &mathOp,
698701 mlir::FunctionType libFuncType,
699702 llvm::ArrayRef<mlir::Value> args) {
700- #ifndef FLANG_RUNTIME_F128_MATH_LIB
701- std::string message = prettyPrintIntrinsicName (
702- builder, loc, " compiler is built without support for '" , mathOp.key , " '" ,
703- libFuncType);
704- fir::emitFatalError (loc, message, /* genCrashDiag=*/ false );
705- #else // FLANG_RUNTIME_F128_MATH_LIB
703+ // TODO: if we knew that the C 'long double' does not have 113-bit mantissa
704+ // on the target, we could have asserted that FLANG_RUNTIME_F128_MATH_LIB
705+ // must be specified. For now just always generate the call even
706+ // if it will be unresolved.
706707 return genLibCall (builder, loc, mathOp, libFuncType, args);
707- #endif // FLANG_RUNTIME_F128_MATH_LIB
708708}
709709
710710mlir::Value genLibCall (fir::FirOpBuilder &builder, mlir::Location loc,
@@ -926,6 +926,10 @@ constexpr auto FuncTypeInteger8Real16 =
926926 genFuncType<Ty::Integer<8 >, Ty::Real<16 >>;
927927constexpr auto FuncTypeReal16Complex16 =
928928 genFuncType<Ty::Real<16 >, Ty::Complex<16 >>;
929+ constexpr auto FuncTypeComplex16Complex16 =
930+ genFuncType<Ty::Complex<16 >, Ty::Complex<16 >>;
931+ constexpr auto FuncTypeComplex16Complex16Complex16 =
932+ genFuncType<Ty::Complex<16 >, Ty::Complex<16 >, Ty::Complex<16 >>;
929933
930934static constexpr MathOperation mathOperations[] = {
931935 {" abs" , " fabsf" , genFuncType<Ty::Real<4 >, Ty::Real<4 >>,
@@ -944,13 +948,17 @@ static constexpr MathOperation mathOperations[] = {
944948 {" acos" , RTNAME_STRING (AcosF128), FuncTypeReal16Real16, genLibF128Call},
945949 {" acos" , " cacosf" , genFuncType<Ty::Complex<4 >, Ty::Complex<4 >>, genLibCall},
946950 {" acos" , " cacos" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>, genLibCall},
951+ {" acos" , RTNAME_STRING (CAcosF128), FuncTypeComplex16Complex16,
952+ genLibF128Call},
947953 {" acosh" , " acoshf" , genFuncType<Ty::Real<4 >, Ty::Real<4 >>, genLibCall},
948954 {" acosh" , " acosh" , genFuncType<Ty::Real<8 >, Ty::Real<8 >>, genLibCall},
949955 {" acosh" , RTNAME_STRING (AcoshF128), FuncTypeReal16Real16, genLibF128Call},
950956 {" acosh" , " cacoshf" , genFuncType<Ty::Complex<4 >, Ty::Complex<4 >>,
951957 genLibCall},
952958 {" acosh" , " cacosh" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>,
953959 genLibCall},
960+ {" acosh" , RTNAME_STRING (CAcoshF128), FuncTypeComplex16Complex16,
961+ genLibF128Call},
954962 // llvm.trunc behaves the same way as libm's trunc.
955963 {" aint" , " llvm.trunc.f32" , genFuncType<Ty::Real<4 >, Ty::Real<4 >>,
956964 genLibCall},
@@ -972,20 +980,26 @@ static constexpr MathOperation mathOperations[] = {
972980 {" asin" , RTNAME_STRING (AsinF128), FuncTypeReal16Real16, genLibF128Call},
973981 {" asin" , " casinf" , genFuncType<Ty::Complex<4 >, Ty::Complex<4 >>, genLibCall},
974982 {" asin" , " casin" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>, genLibCall},
983+ {" asin" , RTNAME_STRING (CAsinF128), FuncTypeComplex16Complex16,
984+ genLibF128Call},
975985 {" asinh" , " asinhf" , genFuncType<Ty::Real<4 >, Ty::Real<4 >>, genLibCall},
976986 {" asinh" , " asinh" , genFuncType<Ty::Real<8 >, Ty::Real<8 >>, genLibCall},
977987 {" asinh" , RTNAME_STRING (AsinhF128), FuncTypeReal16Real16, genLibF128Call},
978988 {" asinh" , " casinhf" , genFuncType<Ty::Complex<4 >, Ty::Complex<4 >>,
979989 genLibCall},
980990 {" asinh" , " casinh" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>,
981991 genLibCall},
992+ {" asinh" , RTNAME_STRING (CAsinhF128), FuncTypeComplex16Complex16,
993+ genLibF128Call},
982994 {" atan" , " atanf" , genFuncType<Ty::Real<4 >, Ty::Real<4 >>,
983995 genMathOp<mlir::math::AtanOp>},
984996 {" atan" , " atan" , genFuncType<Ty::Real<8 >, Ty::Real<8 >>,
985997 genMathOp<mlir::math::AtanOp>},
986998 {" atan" , RTNAME_STRING (AtanF128), FuncTypeReal16Real16, genLibF128Call},
987999 {" atan" , " catanf" , genFuncType<Ty::Complex<4 >, Ty::Complex<4 >>, genLibCall},
9881000 {" atan" , " catan" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>, genLibCall},
1001+ {" atan" , RTNAME_STRING (CAtanF128), FuncTypeComplex16Complex16,
1002+ genLibF128Call},
9891003 {" atan2" , " atan2f" , genFuncType<Ty::Real<4 >, Ty::Real<4 >, Ty::Real<4 >>,
9901004 genMathOp<mlir::math::Atan2Op>},
9911005 {" atan2" , " atan2" , genFuncType<Ty::Real<8 >, Ty::Real<8 >, Ty::Real<8 >>,
@@ -999,6 +1013,8 @@ static constexpr MathOperation mathOperations[] = {
9991013 genLibCall},
10001014 {" atanh" , " catanh" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>,
10011015 genLibCall},
1016+ {" atanh" , RTNAME_STRING (CAtanhF128), FuncTypeComplex16Complex16,
1017+ genLibF128Call},
10021018 {" bessel_j0" , " j0f" , genFuncType<Ty::Real<4 >, Ty::Real<4 >>, genLibCall},
10031019 {" bessel_j0" , " j0" , genFuncType<Ty::Real<8 >, Ty::Real<8 >>, genLibCall},
10041020 {" bessel_j0" , RTNAME_STRING (J0F128), FuncTypeReal16Real16, genLibF128Call},
@@ -1038,11 +1054,15 @@ static constexpr MathOperation mathOperations[] = {
10381054 genComplexMathOp<mlir::complex ::CosOp>},
10391055 {" cos" , " ccos" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>,
10401056 genComplexMathOp<mlir::complex ::CosOp>},
1057+ {" cos" , RTNAME_STRING (CCosF128), FuncTypeComplex16Complex16,
1058+ genLibF128Call},
10411059 {" cosh" , " coshf" , genFuncType<Ty::Real<4 >, Ty::Real<4 >>, genLibCall},
10421060 {" cosh" , " cosh" , genFuncType<Ty::Real<8 >, Ty::Real<8 >>, genLibCall},
10431061 {" cosh" , RTNAME_STRING (CoshF128), FuncTypeReal16Real16, genLibF128Call},
10441062 {" cosh" , " ccoshf" , genFuncType<Ty::Complex<4 >, Ty::Complex<4 >>, genLibCall},
10451063 {" cosh" , " ccosh" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>, genLibCall},
1064+ {" cosh" , RTNAME_STRING (CCoshF128), FuncTypeComplex16Complex16,
1065+ genLibF128Call},
10461066 {" divc" ,
10471067 {},
10481068 genFuncType<Ty::Complex<2 >, Ty::Complex<2 >, Ty::Complex<2 >>,
@@ -1080,6 +1100,8 @@ static constexpr MathOperation mathOperations[] = {
10801100 genComplexMathOp<mlir::complex ::ExpOp>},
10811101 {" exp" , " cexp" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>,
10821102 genComplexMathOp<mlir::complex ::ExpOp>},
1103+ {" exp" , RTNAME_STRING (CExpF128), FuncTypeComplex16Complex16,
1104+ genLibF128Call},
10831105 {" feclearexcept" , " feclearexcept" ,
10841106 genFuncType<Ty::Integer<4 >, Ty::Integer<4 >>, genLibCall},
10851107 {" fedisableexcept" , " fedisableexcept" ,
@@ -1131,6 +1153,8 @@ static constexpr MathOperation mathOperations[] = {
11311153 genComplexMathOp<mlir::complex ::LogOp>},
11321154 {" log" , " clog" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>,
11331155 genComplexMathOp<mlir::complex ::LogOp>},
1156+ {" log" , RTNAME_STRING (CLogF128), FuncTypeComplex16Complex16,
1157+ genLibF128Call},
11341158 {" log10" , " log10f" , genFuncType<Ty::Real<4 >, Ty::Real<4 >>,
11351159 genMathOp<mlir::math::Log10Op>},
11361160 {" log10" , " log10" , genFuncType<Ty::Real<8 >, Ty::Real<8 >>,
@@ -1178,6 +1202,8 @@ static constexpr MathOperation mathOperations[] = {
11781202 genComplexMathOp<mlir::complex ::PowOp>},
11791203 {" pow" , " cpow" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >, Ty::Complex<8 >>,
11801204 genComplexMathOp<mlir::complex ::PowOp>},
1205+ {" pow" , RTNAME_STRING (CPowF128), FuncTypeComplex16Complex16Complex16,
1206+ genLibF128Call},
11811207 {" pow" , RTNAME_STRING (FPow4i),
11821208 genFuncType<Ty::Real<4 >, Ty::Real<4 >, Ty::Integer<4 >>,
11831209 genMathOp<mlir::math::FPowIOp>},
@@ -1222,11 +1248,15 @@ static constexpr MathOperation mathOperations[] = {
12221248 genComplexMathOp<mlir::complex ::SinOp>},
12231249 {" sin" , " csin" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>,
12241250 genComplexMathOp<mlir::complex ::SinOp>},
1251+ {" sin" , RTNAME_STRING (CSinF128), FuncTypeComplex16Complex16,
1252+ genLibF128Call},
12251253 {" sinh" , " sinhf" , genFuncType<Ty::Real<4 >, Ty::Real<4 >>, genLibCall},
12261254 {" sinh" , " sinh" , genFuncType<Ty::Real<8 >, Ty::Real<8 >>, genLibCall},
12271255 {" sinh" , RTNAME_STRING (SinhF128), FuncTypeReal16Real16, genLibF128Call},
12281256 {" sinh" , " csinhf" , genFuncType<Ty::Complex<4 >, Ty::Complex<4 >>, genLibCall},
12291257 {" sinh" , " csinh" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>, genLibCall},
1258+ {" sinh" , RTNAME_STRING (CSinhF128), FuncTypeComplex16Complex16,
1259+ genLibF128Call},
12301260 {" sqrt" , " sqrtf" , genFuncType<Ty::Real<4 >, Ty::Real<4 >>,
12311261 genMathOp<mlir::math::SqrtOp>},
12321262 {" sqrt" , " sqrt" , genFuncType<Ty::Real<8 >, Ty::Real<8 >>,
@@ -1236,6 +1266,8 @@ static constexpr MathOperation mathOperations[] = {
12361266 genComplexMathOp<mlir::complex ::SqrtOp>},
12371267 {" sqrt" , " csqrt" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>,
12381268 genComplexMathOp<mlir::complex ::SqrtOp>},
1269+ {" sqrt" , RTNAME_STRING (CSqrtF128), FuncTypeComplex16Complex16,
1270+ genLibF128Call},
12391271 {" tan" , " tanf" , genFuncType<Ty::Real<4 >, Ty::Real<4 >>,
12401272 genMathOp<mlir::math::TanOp>},
12411273 {" tan" , " tan" , genFuncType<Ty::Real<8 >, Ty::Real<8 >>,
@@ -1245,6 +1277,8 @@ static constexpr MathOperation mathOperations[] = {
12451277 genComplexMathOp<mlir::complex ::TanOp>},
12461278 {" tan" , " ctan" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>,
12471279 genComplexMathOp<mlir::complex ::TanOp>},
1280+ {" tan" , RTNAME_STRING (CTanF128), FuncTypeComplex16Complex16,
1281+ genLibF128Call},
12481282 {" tanh" , " tanhf" , genFuncType<Ty::Real<4 >, Ty::Real<4 >>,
12491283 genMathOp<mlir::math::TanhOp>},
12501284 {" tanh" , " tanh" , genFuncType<Ty::Real<8 >, Ty::Real<8 >>,
@@ -1254,6 +1288,8 @@ static constexpr MathOperation mathOperations[] = {
12541288 genComplexMathOp<mlir::complex ::TanhOp>},
12551289 {" tanh" , " ctanh" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>,
12561290 genComplexMathOp<mlir::complex ::TanhOp>},
1291+ {" tanh" , RTNAME_STRING (CTanhF128), FuncTypeComplex16Complex16,
1292+ genLibF128Call},
12571293};
12581294
12591295// This helper class computes a "distance" between two function types.
0 commit comments