[flang] Allow runtime build with AVOID_NATIVE_INT128_T=1

This patch enables the Fortran runtime support library to be
built without native 128-bit integer support in the C++ compiler.

Experimental: do not merge yet.

Differential Revision: https://reviews.llvm.org/D154660
This commit is contained in:
Peter Klausler 2023-07-06 15:03:05 -07:00
parent f41223eeca
commit 1c35c1a739
No known key found for this signature in database
4 changed files with 39 additions and 18 deletions

View File

@ -107,9 +107,13 @@ static void StoreLengthToDescriptor(
}
template <int KIND> struct FitsInIntegerKind {
bool operator()(std::int64_t value) {
return value <= std::numeric_limits<Fortran::runtime::CppTypeFor<
Fortran::common::TypeCategory::Integer, KIND>>::max();
bool operator()([[maybe_unused]] std::int64_t value) {
if constexpr (KIND >= 8) {
return true;
} else {
return value <= std::numeric_limits<Fortran::runtime::CppTypeFor<
Fortran::common::TypeCategory::Integer, KIND>>::max();
}
}
};

View File

@ -1484,7 +1484,9 @@ static enum Iostat CheckUnitNumberInRangeImpl(INT unit, bool handleError,
// Only provide the bad unit number in the message if SignalError can print
// it accurately. Otherwise, the generic IostatUnitOverflow message will be
// used.
if (static_cast<std::intmax_t>(unit) == unit) {
if constexpr (sizeof(INT) > sizeof(std::intmax_t)) {
errorHandler.SignalError(IostatUnitOverflow);
} else if (static_cast<std::intmax_t>(unit) == unit) {
errorHandler.SignalError(IostatUnitOverflow,
"UNIT number %jd is out of range", static_cast<std::intmax_t>(unit));
} else {

View File

@ -306,7 +306,7 @@ CppTypeFor<TypeCategory::Integer, 8> RTNAME(Ceiling4_8)(
CppTypeFor<TypeCategory::Real, 4> x) {
return Ceiling<CppTypeFor<TypeCategory::Integer, 8>>(x);
}
#ifdef __SIZEOF_INT128__
#if defined __SIZEOF_INT128__ && !AVOID_NATIVE_UINT128_T
CppTypeFor<TypeCategory::Integer, 16> RTNAME(Ceiling4_16)(
CppTypeFor<TypeCategory::Real, 4> x) {
return Ceiling<CppTypeFor<TypeCategory::Integer, 16>>(x);
@ -328,7 +328,7 @@ CppTypeFor<TypeCategory::Integer, 8> RTNAME(Ceiling8_8)(
CppTypeFor<TypeCategory::Real, 8> x) {
return Ceiling<CppTypeFor<TypeCategory::Integer, 8>>(x);
}
#ifdef __SIZEOF_INT128__
#if defined __SIZEOF_INT128__ && !AVOID_NATIVE_UINT128_T
CppTypeFor<TypeCategory::Integer, 16> RTNAME(Ceiling8_16)(
CppTypeFor<TypeCategory::Real, 8> x) {
return Ceiling<CppTypeFor<TypeCategory::Integer, 16>>(x);
@ -351,7 +351,7 @@ CppTypeFor<TypeCategory::Integer, 8> RTNAME(Ceiling10_8)(
CppTypeFor<TypeCategory::Real, 10> x) {
return Ceiling<CppTypeFor<TypeCategory::Integer, 8>>(x);
}
#ifdef __SIZEOF_INT128__
#if defined __SIZEOF_INT128__ && !AVOID_NATIVE_UINT128_T
CppTypeFor<TypeCategory::Integer, 16> RTNAME(Ceiling10_16)(
CppTypeFor<TypeCategory::Real, 10> x) {
return Ceiling<CppTypeFor<TypeCategory::Integer, 16>>(x);
@ -374,7 +374,7 @@ CppTypeFor<TypeCategory::Integer, 8> RTNAME(Ceiling16_8)(
CppTypeFor<TypeCategory::Real, 16> x) {
return Ceiling<CppTypeFor<TypeCategory::Integer, 8>>(x);
}
#ifdef __SIZEOF_INT128__
#if defined __SIZEOF_INT128__ && !AVOID_NATIVE_UINT128_T
CppTypeFor<TypeCategory::Integer, 16> RTNAME(Ceiling16_16)(
CppTypeFor<TypeCategory::Real, 16> x) {
return Ceiling<CppTypeFor<TypeCategory::Integer, 16>>(x);
@ -434,7 +434,7 @@ CppTypeFor<TypeCategory::Integer, 8> RTNAME(Floor4_8)(
CppTypeFor<TypeCategory::Real, 4> x) {
return Floor<CppTypeFor<TypeCategory::Integer, 8>>(x);
}
#ifdef __SIZEOF_INT128__
#if defined __SIZEOF_INT128__ && !AVOID_NATIVE_UINT128_T
CppTypeFor<TypeCategory::Integer, 16> RTNAME(Floor4_16)(
CppTypeFor<TypeCategory::Real, 4> x) {
return Floor<CppTypeFor<TypeCategory::Integer, 16>>(x);
@ -456,7 +456,7 @@ CppTypeFor<TypeCategory::Integer, 8> RTNAME(Floor8_8)(
CppTypeFor<TypeCategory::Real, 8> x) {
return Floor<CppTypeFor<TypeCategory::Integer, 8>>(x);
}
#ifdef __SIZEOF_INT128__
#if defined __SIZEOF_INT128__ && !AVOID_NATIVE_UINT128_T
CppTypeFor<TypeCategory::Integer, 16> RTNAME(Floor8_16)(
CppTypeFor<TypeCategory::Real, 8> x) {
return Floor<CppTypeFor<TypeCategory::Integer, 16>>(x);
@ -479,7 +479,7 @@ CppTypeFor<TypeCategory::Integer, 8> RTNAME(Floor10_8)(
CppTypeFor<TypeCategory::Real, 10> x) {
return Floor<CppTypeFor<TypeCategory::Integer, 8>>(x);
}
#ifdef __SIZEOF_INT128__
#if defined __SIZEOF_INT128__ && !AVOID_NATIVE_UINT128_T
CppTypeFor<TypeCategory::Integer, 16> RTNAME(Floor10_16)(
CppTypeFor<TypeCategory::Real, 10> x) {
return Floor<CppTypeFor<TypeCategory::Integer, 16>>(x);
@ -502,7 +502,7 @@ CppTypeFor<TypeCategory::Integer, 8> RTNAME(Floor16_8)(
CppTypeFor<TypeCategory::Real, 16> x) {
return Floor<CppTypeFor<TypeCategory::Integer, 8>>(x);
}
#ifdef __SIZEOF_INT128__
#if defined __SIZEOF_INT128__ && !AVOID_NATIVE_UINT128_T
CppTypeFor<TypeCategory::Integer, 16> RTNAME(Floor16_16)(
CppTypeFor<TypeCategory::Real, 16> x) {
return Floor<CppTypeFor<TypeCategory::Integer, 16>>(x);
@ -710,7 +710,7 @@ CppTypeFor<TypeCategory::Integer, 8> RTNAME(Nint4_8)(
CppTypeFor<TypeCategory::Real, 4> x) {
return Nint<CppTypeFor<TypeCategory::Integer, 8>>(x);
}
#ifdef __SIZEOF_INT128__
#if defined __SIZEOF_INT128__ && !AVOID_NATIVE_UINT128_T
CppTypeFor<TypeCategory::Integer, 16> RTNAME(Nint4_16)(
CppTypeFor<TypeCategory::Real, 4> x) {
return Nint<CppTypeFor<TypeCategory::Integer, 16>>(x);
@ -732,7 +732,7 @@ CppTypeFor<TypeCategory::Integer, 8> RTNAME(Nint8_8)(
CppTypeFor<TypeCategory::Real, 8> x) {
return Nint<CppTypeFor<TypeCategory::Integer, 8>>(x);
}
#ifdef __SIZEOF_INT128__
#if defined __SIZEOF_INT128__ && !AVOID_NATIVE_UINT128_T
CppTypeFor<TypeCategory::Integer, 16> RTNAME(Nint8_16)(
CppTypeFor<TypeCategory::Real, 8> x) {
return Nint<CppTypeFor<TypeCategory::Integer, 16>>(x);
@ -755,7 +755,7 @@ CppTypeFor<TypeCategory::Integer, 8> RTNAME(Nint10_8)(
CppTypeFor<TypeCategory::Real, 10> x) {
return Nint<CppTypeFor<TypeCategory::Integer, 8>>(x);
}
#ifdef __SIZEOF_INT128__
#if defined __SIZEOF_INT128__ && !AVOID_NATIVE_UINT128_T
CppTypeFor<TypeCategory::Integer, 16> RTNAME(Nint10_16)(
CppTypeFor<TypeCategory::Real, 10> x) {
return Nint<CppTypeFor<TypeCategory::Integer, 16>>(x);
@ -778,7 +778,7 @@ CppTypeFor<TypeCategory::Integer, 8> RTNAME(Nint16_8)(
CppTypeFor<TypeCategory::Real, 16> x) {
return Nint<CppTypeFor<TypeCategory::Integer, 8>>(x);
}
#ifdef __SIZEOF_INT128__
#if defined __SIZEOF_INT128__ && !AVOID_NATIVE_UINT128_T
CppTypeFor<TypeCategory::Integer, 16> RTNAME(Nint16_16)(
CppTypeFor<TypeCategory::Real, 16> x) {
return Nint<CppTypeFor<TypeCategory::Integer, 16>>(x);

View File

@ -131,7 +131,7 @@ inline RT_API_ATTRS RESULT ApplyType(
return FUNC<TypeCategory::Integer, 4>{}(std::forward<A>(x)...);
case 8:
return FUNC<TypeCategory::Integer, 8>{}(std::forward<A>(x)...);
#ifdef __SIZEOF_INT128__
#if defined __SIZEOF_INT128__ && !AVOID_NATIVE_UINT128_T
case 16:
return FUNC<TypeCategory::Integer, 16>{}(std::forward<A>(x)...);
#endif
@ -230,7 +230,7 @@ inline RT_API_ATTRS RESULT ApplyIntegerKind(
return FUNC<4>{}(std::forward<A>(x)...);
case 8:
return FUNC<8>{}(std::forward<A>(x)...);
#ifdef __SIZEOF_INT128__
#if defined __SIZEOF_INT128__ && !AVOID_NATIVE_UINT128_T
case 16:
return FUNC<16>{}(std::forward<A>(x)...);
#endif
@ -310,6 +310,11 @@ std::optional<std::pair<TypeCategory, int>> inline constexpr GetResultType(
return std::make_pair(TypeCategory::Integer, maxKind);
case TypeCategory::Real:
case TypeCategory::Complex:
#if !(defined __SIZEOF_INT128__ && !AVOID_NATIVE_UINT128_T)
if (xKind == 16) {
break;
}
#endif
return std::make_pair(yCat, yKind);
default:
break;
@ -318,6 +323,11 @@ std::optional<std::pair<TypeCategory, int>> inline constexpr GetResultType(
case TypeCategory::Real:
switch (yCat) {
case TypeCategory::Integer:
#if !(defined __SIZEOF_INT128__ && !AVOID_NATIVE_UINT128_T)
if (yKind == 16) {
break;
}
#endif
return std::make_pair(TypeCategory::Real, xKind);
case TypeCategory::Real:
case TypeCategory::Complex:
@ -329,6 +339,11 @@ std::optional<std::pair<TypeCategory, int>> inline constexpr GetResultType(
case TypeCategory::Complex:
switch (yCat) {
case TypeCategory::Integer:
#if !(defined __SIZEOF_INT128__ && !AVOID_NATIVE_UINT128_T)
if (yKind == 16) {
break;
}
#endif
return std::make_pair(TypeCategory::Complex, xKind);
case TypeCategory::Real:
case TypeCategory::Complex: