aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Evaluate/intrinsics.cpp
diff options
context:
space:
mode:
authorPeter Klausler <35819229+klausler@users.noreply.github.com>2024-06-18 12:46:15 -0700
committerGitHub <noreply@github.com>2024-06-18 12:46:15 -0700
commit4b57fe65fdc6b8d7163f36440386d1e707d89381 (patch)
tree1593e5fcbaff74572e7502a0ad5a9c55e44ca018 /flang/lib/Evaluate/intrinsics.cpp
parentd7b5741ad117a068537e2f0101999d1184acab4e (diff)
downloadllvm-4b57fe65fdc6b8d7163f36440386d1e707d89381.zip
llvm-4b57fe65fdc6b8d7163f36440386d1e707d89381.tar.gz
llvm-4b57fe65fdc6b8d7163f36440386d1e707d89381.tar.bz2
[flang] Fold IEEE_SUPPORT_xxx() intrinsic functions (#95866)
All of the IEEE_SUPPORT_xxx() intrinsic functions must fold to constant logical values when they have constant arguments; and since they fold to .TRUE. for currently support architectures, always fold them. But also put in the infrastructure whereby a driver can initialize Evaluate's target information to set some of them to .FALSE. if that becomes necessary.
Diffstat (limited to 'flang/lib/Evaluate/intrinsics.cpp')
-rw-r--r--flang/lib/Evaluate/intrinsics.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/flang/lib/Evaluate/intrinsics.cpp b/flang/lib/Evaluate/intrinsics.cpp
index 1bba541..2733f99 100644
--- a/flang/lib/Evaluate/intrinsics.cpp
+++ b/flang/lib/Evaluate/intrinsics.cpp
@@ -88,6 +88,8 @@ ENUM_CLASS(KindCode, none, defaultIntegerKind,
sameKind,
operand, // match any kind, with promotion (non-standard)
typeless, // BOZ literals are INTEGER with this kind
+ ieeeFlagType, // IEEE_FLAG_TYPE from ISO_FORTRAN_EXCEPTION
+ ieeeRoundType, // IEEE_ROUND_TYPE from ISO_FORTRAN_ARITHMETIC
teamType, // TEAM_TYPE from module ISO_FORTRAN_ENV (for coarrays)
kindArg, // this argument is KIND=
effectiveKind, // for function results: "kindArg" value, possibly defaulted
@@ -121,6 +123,9 @@ static constexpr TypePattern DefaultChar{CharType, KindCode::defaultCharKind};
static constexpr TypePattern DefaultLogical{
LogicalType, KindCode::defaultLogicalKind};
static constexpr TypePattern BOZ{IntType, KindCode::typeless};
+static constexpr TypePattern IeeeFlagType{DerivedType, KindCode::ieeeFlagType};
+static constexpr TypePattern IeeeRoundType{
+ DerivedType, KindCode::ieeeRoundType};
static constexpr TypePattern TeamType{DerivedType, KindCode::teamType};
static constexpr TypePattern DoublePrecision{
RealType, KindCode::doublePrecision};
@@ -940,6 +945,12 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
{"__builtin_ieee_support_divide",
{{"x", AnyReal, Rank::elemental, Optionality::optional}},
DefaultLogical},
+ {"__builtin_ieee_support_flag",
+ {{"flag", IeeeFlagType, Rank::scalar},
+ {"x", AnyReal, Rank::elemental, Optionality::optional}},
+ DefaultLogical},
+ {"__builtin_ieee_support_halting", {{"flag", IeeeFlagType, Rank::scalar}},
+ DefaultLogical},
{"__builtin_ieee_support_inf",
{{"x", AnyReal, Rank::elemental, Optionality::optional}},
DefaultLogical},
@@ -949,6 +960,10 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
{"__builtin_ieee_support_nan",
{{"x", AnyReal, Rank::elemental, Optionality::optional}},
DefaultLogical},
+ {"__builtin_ieee_support_rounding",
+ {{"round_value", IeeeRoundType, Rank::scalar},
+ {"x", AnyReal, Rank::elemental, Optionality::optional}},
+ DefaultLogical},
{"__builtin_ieee_support_sqrt",
{{"x", AnyReal, Rank::elemental, Optionality::optional}},
DefaultLogical},
@@ -1851,6 +1866,16 @@ std::optional<SpecificCall> IntrinsicInterface::Match(
case KindCode::typeless:
argOk = false;
break;
+ case KindCode::ieeeFlagType:
+ argOk = !type->IsUnlimitedPolymorphic() &&
+ type->category() == TypeCategory::Derived &&
+ semantics::IsIeeeFlagType(&type->GetDerivedTypeSpec());
+ break;
+ case KindCode::ieeeRoundType:
+ argOk = !type->IsUnlimitedPolymorphic() &&
+ type->category() == TypeCategory::Derived &&
+ semantics::IsIeeeRoundType(&type->GetDerivedTypeSpec());
+ break;
case KindCode::teamType:
argOk = !type->IsUnlimitedPolymorphic() &&
type->category() == TypeCategory::Derived &&