@@ -689,22 +689,22 @@ prettyPrintIntrinsicName(fir::FirOpBuilder &builder, mlir::Location loc,
689
689
}
690
690
691
691
// 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.
695
698
static mlir::Value genLibF128Call (fir::FirOpBuilder &builder,
696
699
mlir::Location loc,
697
700
const MathOperation &mathOp,
698
701
mlir::FunctionType libFuncType,
699
702
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.
706
707
return genLibCall (builder, loc, mathOp, libFuncType, args);
707
- #endif // FLANG_RUNTIME_F128_MATH_LIB
708
708
}
709
709
710
710
mlir::Value genLibCall (fir::FirOpBuilder &builder, mlir::Location loc,
@@ -926,6 +926,10 @@ constexpr auto FuncTypeInteger8Real16 =
926
926
genFuncType<Ty::Integer<8 >, Ty::Real<16 >>;
927
927
constexpr auto FuncTypeReal16Complex16 =
928
928
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 >>;
929
933
930
934
static constexpr MathOperation mathOperations[] = {
931
935
{" abs" , " fabsf" , genFuncType<Ty::Real<4 >, Ty::Real<4 >>,
@@ -944,13 +948,17 @@ static constexpr MathOperation mathOperations[] = {
944
948
{" acos" , RTNAME_STRING (AcosF128), FuncTypeReal16Real16, genLibF128Call},
945
949
{" acos" , " cacosf" , genFuncType<Ty::Complex<4 >, Ty::Complex<4 >>, genLibCall},
946
950
{" acos" , " cacos" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>, genLibCall},
951
+ {" acos" , RTNAME_STRING (CAcosF128), FuncTypeComplex16Complex16,
952
+ genLibF128Call},
947
953
{" acosh" , " acoshf" , genFuncType<Ty::Real<4 >, Ty::Real<4 >>, genLibCall},
948
954
{" acosh" , " acosh" , genFuncType<Ty::Real<8 >, Ty::Real<8 >>, genLibCall},
949
955
{" acosh" , RTNAME_STRING (AcoshF128), FuncTypeReal16Real16, genLibF128Call},
950
956
{" acosh" , " cacoshf" , genFuncType<Ty::Complex<4 >, Ty::Complex<4 >>,
951
957
genLibCall},
952
958
{" acosh" , " cacosh" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>,
953
959
genLibCall},
960
+ {" acosh" , RTNAME_STRING (CAcoshF128), FuncTypeComplex16Complex16,
961
+ genLibF128Call},
954
962
// llvm.trunc behaves the same way as libm's trunc.
955
963
{" aint" , " llvm.trunc.f32" , genFuncType<Ty::Real<4 >, Ty::Real<4 >>,
956
964
genLibCall},
@@ -972,20 +980,26 @@ static constexpr MathOperation mathOperations[] = {
972
980
{" asin" , RTNAME_STRING (AsinF128), FuncTypeReal16Real16, genLibF128Call},
973
981
{" asin" , " casinf" , genFuncType<Ty::Complex<4 >, Ty::Complex<4 >>, genLibCall},
974
982
{" asin" , " casin" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>, genLibCall},
983
+ {" asin" , RTNAME_STRING (CAsinF128), FuncTypeComplex16Complex16,
984
+ genLibF128Call},
975
985
{" asinh" , " asinhf" , genFuncType<Ty::Real<4 >, Ty::Real<4 >>, genLibCall},
976
986
{" asinh" , " asinh" , genFuncType<Ty::Real<8 >, Ty::Real<8 >>, genLibCall},
977
987
{" asinh" , RTNAME_STRING (AsinhF128), FuncTypeReal16Real16, genLibF128Call},
978
988
{" asinh" , " casinhf" , genFuncType<Ty::Complex<4 >, Ty::Complex<4 >>,
979
989
genLibCall},
980
990
{" asinh" , " casinh" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>,
981
991
genLibCall},
992
+ {" asinh" , RTNAME_STRING (CAsinhF128), FuncTypeComplex16Complex16,
993
+ genLibF128Call},
982
994
{" atan" , " atanf" , genFuncType<Ty::Real<4 >, Ty::Real<4 >>,
983
995
genMathOp<mlir::math::AtanOp>},
984
996
{" atan" , " atan" , genFuncType<Ty::Real<8 >, Ty::Real<8 >>,
985
997
genMathOp<mlir::math::AtanOp>},
986
998
{" atan" , RTNAME_STRING (AtanF128), FuncTypeReal16Real16, genLibF128Call},
987
999
{" atan" , " catanf" , genFuncType<Ty::Complex<4 >, Ty::Complex<4 >>, genLibCall},
988
1000
{" atan" , " catan" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>, genLibCall},
1001
+ {" atan" , RTNAME_STRING (CAtanF128), FuncTypeComplex16Complex16,
1002
+ genLibF128Call},
989
1003
{" atan2" , " atan2f" , genFuncType<Ty::Real<4 >, Ty::Real<4 >, Ty::Real<4 >>,
990
1004
genMathOp<mlir::math::Atan2Op>},
991
1005
{" atan2" , " atan2" , genFuncType<Ty::Real<8 >, Ty::Real<8 >, Ty::Real<8 >>,
@@ -999,6 +1013,8 @@ static constexpr MathOperation mathOperations[] = {
999
1013
genLibCall},
1000
1014
{" atanh" , " catanh" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>,
1001
1015
genLibCall},
1016
+ {" atanh" , RTNAME_STRING (CAtanhF128), FuncTypeComplex16Complex16,
1017
+ genLibF128Call},
1002
1018
{" bessel_j0" , " j0f" , genFuncType<Ty::Real<4 >, Ty::Real<4 >>, genLibCall},
1003
1019
{" bessel_j0" , " j0" , genFuncType<Ty::Real<8 >, Ty::Real<8 >>, genLibCall},
1004
1020
{" bessel_j0" , RTNAME_STRING (J0F128), FuncTypeReal16Real16, genLibF128Call},
@@ -1038,11 +1054,15 @@ static constexpr MathOperation mathOperations[] = {
1038
1054
genComplexMathOp<mlir::complex::CosOp>},
1039
1055
{" cos" , " ccos" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>,
1040
1056
genComplexMathOp<mlir::complex::CosOp>},
1057
+ {" cos" , RTNAME_STRING (CCosF128), FuncTypeComplex16Complex16,
1058
+ genLibF128Call},
1041
1059
{" cosh" , " coshf" , genFuncType<Ty::Real<4 >, Ty::Real<4 >>, genLibCall},
1042
1060
{" cosh" , " cosh" , genFuncType<Ty::Real<8 >, Ty::Real<8 >>, genLibCall},
1043
1061
{" cosh" , RTNAME_STRING (CoshF128), FuncTypeReal16Real16, genLibF128Call},
1044
1062
{" cosh" , " ccoshf" , genFuncType<Ty::Complex<4 >, Ty::Complex<4 >>, genLibCall},
1045
1063
{" cosh" , " ccosh" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>, genLibCall},
1064
+ {" cosh" , RTNAME_STRING (CCoshF128), FuncTypeComplex16Complex16,
1065
+ genLibF128Call},
1046
1066
{" divc" ,
1047
1067
{},
1048
1068
genFuncType<Ty::Complex<2 >, Ty::Complex<2 >, Ty::Complex<2 >>,
@@ -1080,6 +1100,8 @@ static constexpr MathOperation mathOperations[] = {
1080
1100
genComplexMathOp<mlir::complex::ExpOp>},
1081
1101
{" exp" , " cexp" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>,
1082
1102
genComplexMathOp<mlir::complex::ExpOp>},
1103
+ {" exp" , RTNAME_STRING (CExpF128), FuncTypeComplex16Complex16,
1104
+ genLibF128Call},
1083
1105
{" feclearexcept" , " feclearexcept" ,
1084
1106
genFuncType<Ty::Integer<4 >, Ty::Integer<4 >>, genLibCall},
1085
1107
{" fedisableexcept" , " fedisableexcept" ,
@@ -1131,6 +1153,8 @@ static constexpr MathOperation mathOperations[] = {
1131
1153
genComplexMathOp<mlir::complex::LogOp>},
1132
1154
{" log" , " clog" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>,
1133
1155
genComplexMathOp<mlir::complex::LogOp>},
1156
+ {" log" , RTNAME_STRING (CLogF128), FuncTypeComplex16Complex16,
1157
+ genLibF128Call},
1134
1158
{" log10" , " log10f" , genFuncType<Ty::Real<4 >, Ty::Real<4 >>,
1135
1159
genMathOp<mlir::math::Log10Op>},
1136
1160
{" log10" , " log10" , genFuncType<Ty::Real<8 >, Ty::Real<8 >>,
@@ -1178,6 +1202,8 @@ static constexpr MathOperation mathOperations[] = {
1178
1202
genComplexMathOp<mlir::complex::PowOp>},
1179
1203
{" pow" , " cpow" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >, Ty::Complex<8 >>,
1180
1204
genComplexMathOp<mlir::complex::PowOp>},
1205
+ {" pow" , RTNAME_STRING (CPowF128), FuncTypeComplex16Complex16Complex16,
1206
+ genLibF128Call},
1181
1207
{" pow" , RTNAME_STRING (FPow4i),
1182
1208
genFuncType<Ty::Real<4 >, Ty::Real<4 >, Ty::Integer<4 >>,
1183
1209
genMathOp<mlir::math::FPowIOp>},
@@ -1222,11 +1248,15 @@ static constexpr MathOperation mathOperations[] = {
1222
1248
genComplexMathOp<mlir::complex::SinOp>},
1223
1249
{" sin" , " csin" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>,
1224
1250
genComplexMathOp<mlir::complex::SinOp>},
1251
+ {" sin" , RTNAME_STRING (CSinF128), FuncTypeComplex16Complex16,
1252
+ genLibF128Call},
1225
1253
{" sinh" , " sinhf" , genFuncType<Ty::Real<4 >, Ty::Real<4 >>, genLibCall},
1226
1254
{" sinh" , " sinh" , genFuncType<Ty::Real<8 >, Ty::Real<8 >>, genLibCall},
1227
1255
{" sinh" , RTNAME_STRING (SinhF128), FuncTypeReal16Real16, genLibF128Call},
1228
1256
{" sinh" , " csinhf" , genFuncType<Ty::Complex<4 >, Ty::Complex<4 >>, genLibCall},
1229
1257
{" sinh" , " csinh" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>, genLibCall},
1258
+ {" sinh" , RTNAME_STRING (CSinhF128), FuncTypeComplex16Complex16,
1259
+ genLibF128Call},
1230
1260
{" sqrt" , " sqrtf" , genFuncType<Ty::Real<4 >, Ty::Real<4 >>,
1231
1261
genMathOp<mlir::math::SqrtOp>},
1232
1262
{" sqrt" , " sqrt" , genFuncType<Ty::Real<8 >, Ty::Real<8 >>,
@@ -1236,6 +1266,8 @@ static constexpr MathOperation mathOperations[] = {
1236
1266
genComplexMathOp<mlir::complex::SqrtOp>},
1237
1267
{" sqrt" , " csqrt" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>,
1238
1268
genComplexMathOp<mlir::complex::SqrtOp>},
1269
+ {" sqrt" , RTNAME_STRING (CSqrtF128), FuncTypeComplex16Complex16,
1270
+ genLibF128Call},
1239
1271
{" tan" , " tanf" , genFuncType<Ty::Real<4 >, Ty::Real<4 >>,
1240
1272
genMathOp<mlir::math::TanOp>},
1241
1273
{" tan" , " tan" , genFuncType<Ty::Real<8 >, Ty::Real<8 >>,
@@ -1245,6 +1277,8 @@ static constexpr MathOperation mathOperations[] = {
1245
1277
genComplexMathOp<mlir::complex::TanOp>},
1246
1278
{" tan" , " ctan" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>,
1247
1279
genComplexMathOp<mlir::complex::TanOp>},
1280
+ {" tan" , RTNAME_STRING (CTanF128), FuncTypeComplex16Complex16,
1281
+ genLibF128Call},
1248
1282
{" tanh" , " tanhf" , genFuncType<Ty::Real<4 >, Ty::Real<4 >>,
1249
1283
genMathOp<mlir::math::TanhOp>},
1250
1284
{" tanh" , " tanh" , genFuncType<Ty::Real<8 >, Ty::Real<8 >>,
@@ -1254,6 +1288,8 @@ static constexpr MathOperation mathOperations[] = {
1254
1288
genComplexMathOp<mlir::complex::TanhOp>},
1255
1289
{" tanh" , " ctanh" , genFuncType<Ty::Complex<8 >, Ty::Complex<8 >>,
1256
1290
genComplexMathOp<mlir::complex::TanhOp>},
1291
+ {" tanh" , RTNAME_STRING (CTanhF128), FuncTypeComplex16Complex16,
1292
+ genLibF128Call},
1257
1293
};
1258
1294
1259
1295
// This helper class computes a "distance" between two function types.
0 commit comments