[flang-commits] [flang] [flang] Make IEEE_INT and IEEE_REAL into builtin intrinsic functions (PR #109191)
via flang-commits
flang-commits at lists.llvm.org
Wed Sep 18 13:32:09 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Peter Klausler (klausler)
<details>
<summary>Changes</summary>
For proper error detection of bad KIND= arguments, make IEEE_INT and IEEE_REAL actual intrinsic functions. Lowering will have to check for the new __builtin_ names.
---
Full diff: https://github.com/llvm/llvm-project/pull/109191.diff
4 Files Affected:
- (modified) flang/lib/Evaluate/intrinsics.cpp (+4)
- (modified) flang/module/__fortran_builtins.f90 (+4)
- (modified) flang/module/ieee_arithmetic.f90 (+4-57)
- (added) flang/test/Semantics/ieee_int.f90 (+12)
``````````diff
diff --git a/flang/lib/Evaluate/intrinsics.cpp b/flang/lib/Evaluate/intrinsics.cpp
index 166dae93178c51..637ee5b8923f19 100644
--- a/flang/lib/Evaluate/intrinsics.cpp
+++ b/flang/lib/Evaluate/intrinsics.cpp
@@ -935,12 +935,16 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
{"__builtin_compiler_version", {}, DefaultChar},
{"__builtin_fma", {{"f1", SameReal}, {"f2", SameReal}, {"f3", SameReal}},
SameReal},
+ {"__builtin_ieee_int",
+ {{"a", AnyFloating}, {"round", IeeeRoundType}, DefaultingKIND},
+ KINDInt},
{"__builtin_ieee_is_nan", {{"a", AnyFloating}}, DefaultLogical},
{"__builtin_ieee_is_negative", {{"a", AnyFloating}}, DefaultLogical},
{"__builtin_ieee_is_normal", {{"a", AnyFloating}}, DefaultLogical},
{"__builtin_ieee_next_after", {{"x", SameReal}, {"y", AnyReal}}, SameReal},
{"__builtin_ieee_next_down", {{"x", SameReal}}, SameReal},
{"__builtin_ieee_next_up", {{"x", SameReal}}, SameReal},
+ {"__builtin_ieee_real", {{"a", AnyIntOrReal}, DefaultingKIND}, KINDReal},
{"__builtin_ieee_support_datatype",
{{"x", AnyReal, Rank::elemental, Optionality::optional}},
DefaultLogical},
diff --git a/flang/module/__fortran_builtins.f90 b/flang/module/__fortran_builtins.f90
index d1d4a639e70d72..ef206dfd943102 100644
--- a/flang/module/__fortran_builtins.f90
+++ b/flang/module/__fortran_builtins.f90
@@ -108,11 +108,13 @@
end type
intrinsic :: __builtin_fma
+ intrinsic :: __builtin_ieee_int
intrinsic :: __builtin_ieee_is_nan, __builtin_ieee_is_negative, &
__builtin_ieee_is_normal
intrinsic :: __builtin_ieee_next_after, __builtin_ieee_next_down, &
__builtin_ieee_next_up
intrinsic :: scale ! for ieee_scalb
+ intrinsic :: __builtin_ieee_real
intrinsic :: __builtin_ieee_selected_real_kind
intrinsic :: __builtin_ieee_support_datatype, &
__builtin_ieee_support_denormal, __builtin_ieee_support_divide, &
@@ -123,10 +125,12 @@
__builtin_ieee_support_standard, __builtin_ieee_support_subnormal, &
__builtin_ieee_support_underflow_control
public :: __builtin_fma
+ public :: __builtin_ieee_int
public :: __builtin_ieee_is_nan, __builtin_ieee_is_negative, &
__builtin_ieee_is_normal
public :: __builtin_ieee_next_after, __builtin_ieee_next_down, &
__builtin_ieee_next_up
+ public :: __builtin_ieee_real
public :: scale ! for ieee_scalb
public :: __builtin_ieee_selected_real_kind
public :: __builtin_ieee_support_datatype, &
diff --git a/flang/module/ieee_arithmetic.f90 b/flang/module/ieee_arithmetic.f90
index 7eaa7db55af9f8..0e8d5f1af01e7b 100644
--- a/flang/module/ieee_arithmetic.f90
+++ b/flang/module/ieee_arithmetic.f90
@@ -21,6 +21,7 @@ module ieee_arithmetic
ieee_away => __builtin_ieee_away, &
ieee_down => __builtin_ieee_down, &
ieee_fma => __builtin_fma, &
+ ieee_int => __builtin_ieee_int, &
ieee_is_nan => __builtin_ieee_is_nan, &
ieee_is_negative => __builtin_ieee_is_negative, &
ieee_is_normal => __builtin_ieee_is_normal, &
@@ -29,6 +30,7 @@ module ieee_arithmetic
ieee_next_down => __builtin_ieee_next_down, &
ieee_next_up => __builtin_ieee_next_up, &
ieee_other => __builtin_ieee_other, &
+ ieee_real => __builtin_ieee_real, &
ieee_round_type => __builtin_ieee_round_type, &
ieee_scalb => scale, &
ieee_selected_real_kind => __builtin_ieee_selected_real_kind, &
@@ -57,6 +59,7 @@ module ieee_arithmetic
public :: ieee_away
public :: ieee_down
public :: ieee_fma
+ public :: ieee_int
public :: ieee_is_nan
public :: ieee_is_negative
public :: ieee_is_normal
@@ -65,6 +68,7 @@ module ieee_arithmetic
public :: ieee_next_after
public :: ieee_next_down
public :: ieee_next_up
+ public :: ieee_real
public :: ieee_round_type
public :: ieee_scalb
public :: ieee_selected_real_kind
@@ -303,29 +307,6 @@ end subroutine ieee_get_underflow_mode_l##GKIND;
public :: ieee_get_underflow_mode
#undef IEEE_GET_UNDERFLOW_MODE_L
-! When kind argument is present, kind(result) is value(kind), not kind(kind).
-! That is not known here, so return integer(16).
-#define IEEE_INT_R(AKIND) \
- elemental integer function ieee_int_a##AKIND(a, round); \
- import ieee_round_type; \
- real(AKIND), intent(in) :: a; \
- type(ieee_round_type), intent(in) :: round; \
- end function ieee_int_a##AKIND;
-#define IEEE_INT_RI(AKIND, KKIND) \
- elemental integer(16) function ieee_int_a##AKIND##_i##KKIND(a, round, kind); \
- import ieee_round_type; \
- real(AKIND), intent(in) :: a; \
- type(ieee_round_type), intent(in) :: round; \
- integer(KKIND), intent(in) :: kind; \
- end function ieee_int_a##AKIND##_i##KKIND;
- interface ieee_int
- SPECIFICS_R(IEEE_INT_R)
- SPECIFICS_RI(IEEE_INT_RI)
- end interface ieee_int
- public :: ieee_int
-#undef IEEE_INT_R
-#undef IEEE_INT_RI
-
#define IEEE_IS_FINITE_R(XKIND) \
elemental logical function ieee_is_finite_a##XKIND(x); \
real(XKIND), intent(in) :: x; \
@@ -486,40 +467,6 @@ end function ieee_quiet_ne_a##AKIND;
public :: ieee_quiet_ne
#undef IEEE_QUIET_NE_R
-! When kind argument is present, kind(result) is value(kind), not kind(kind).
-! That is not known here, so return real(16).
-#define IEEE_REAL_I(AKIND) \
- elemental real function ieee_real_i##AKIND(a); \
- integer(AKIND), intent(in) :: a; \
- end function ieee_real_i##AKIND;
-#define IEEE_REAL_R(AKIND) \
- elemental real function ieee_real_a##AKIND(a); \
- real(AKIND), intent(in) :: a; \
- end function ieee_real_a##AKIND;
-#define IEEE_REAL_II(AKIND, KKIND) \
- elemental real(16) function ieee_real_i##AKIND##_i##KKIND(a, kind); \
- integer(AKIND), intent(in) :: a; \
- integer(KKIND), intent(in) :: kind; \
- end function ieee_real_i##AKIND##_i##KKIND;
-#define IEEE_REAL_RI(AKIND, KKIND) \
- elemental real(16) function ieee_real_a##AKIND##_i##KKIND(a, kind); \
- real(AKIND), intent(in) :: a; \
- integer(KKIND), intent(in) :: kind; \
- end function ieee_real_a##AKIND##_i##KKIND;
- interface ieee_real
- SPECIFICS_I(IEEE_REAL_I)
- SPECIFICS_R(IEEE_REAL_R)
-#if FLANG_SUPPORT_R16
- SPECIFICS_II(IEEE_REAL_II)
- SPECIFICS_RI(IEEE_REAL_RI)
-#endif
- end interface ieee_real
- public :: ieee_real
-#undef IEEE_REAL_I
-#undef IEEE_REAL_R
-#undef IEEE_REAL_II
-#undef IEEE_REAL_RI
-
#define IEEE_REM_RR(XKIND, YKIND) \
elemental real(XKIND) function ieee_rem_a##XKIND##_a##YKIND(x, y); \
real(XKIND), intent(in) :: x; \
diff --git a/flang/test/Semantics/ieee_int.f90 b/flang/test/Semantics/ieee_int.f90
new file mode 100644
index 00000000000000..3af554ad8706ae
--- /dev/null
+++ b/flang/test/Semantics/ieee_int.f90
@@ -0,0 +1,12 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+use ieee_arithmetic, only: ieee_int, ieee_real, ieee_up
+implicit none
+print *, ieee_int(1.5, ieee_up)
+print *, ieee_int(1.5, ieee_up, 4)
+!ERROR: 'kind=' argument must be a constant scalar integer whose value is a supported kind for the intrinsic result type
+print *, ieee_int(1.5, ieee_up, 3)
+print *, ieee_real(1)
+print *, ieee_real(1, 4)
+!ERROR: 'kind=' argument must be a constant scalar integer whose value is a supported kind for the intrinsic result type
+print *, ieee_real(1, 7)
+end
``````````
</details>
https://github.com/llvm/llvm-project/pull/109191
More information about the flang-commits
mailing list