[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.
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
!
|
||||
!===------------------------------------------------------------------------===!
|
||||
|
||||
include '../include/flang/Runtime/magic-numbers.h'
|
||||
|
||||
! These naming shenanigans prevent names from Fortran intrinsic modules
|
||||
! from being usable on INTRINSIC statements, and force the program
|
||||
! to USE the standard intrinsic modules in order to access the
|
||||
@@ -49,6 +51,42 @@ module __fortran_builtins
|
||||
integer(kind=int64), private :: __count
|
||||
end type
|
||||
|
||||
type, public :: __builtin_ieee_flag_type
|
||||
integer(kind=1), private :: flag = 0
|
||||
end type
|
||||
|
||||
type(__builtin_ieee_flag_type), parameter, public :: &
|
||||
__builtin_ieee_invalid = &
|
||||
__builtin_ieee_flag_type(_FORTRAN_RUNTIME_IEEE_INVALID), &
|
||||
__builtin_ieee_overflow = &
|
||||
__builtin_ieee_flag_type(_FORTRAN_RUNTIME_IEEE_OVERFLOW), &
|
||||
__builtin_ieee_divide_by_zero = &
|
||||
__builtin_ieee_flag_type(_FORTRAN_RUNTIME_IEEE_DIVIDE_BY_ZERO), &
|
||||
__builtin_ieee_underflow = &
|
||||
__builtin_ieee_flag_type(_FORTRAN_RUNTIME_IEEE_UNDERFLOW), &
|
||||
__builtin_ieee_inexact = &
|
||||
__builtin_ieee_flag_type(_FORTRAN_RUNTIME_IEEE_INEXACT), &
|
||||
__builtin_ieee_denorm = & ! extension
|
||||
__builtin_ieee_flag_type(_FORTRAN_RUNTIME_IEEE_DENORM)
|
||||
|
||||
type, public :: __builtin_ieee_round_type
|
||||
integer(kind=1), private :: mode = 0
|
||||
end type
|
||||
|
||||
type(__builtin_ieee_round_type), parameter, public :: &
|
||||
__builtin_ieee_to_zero = &
|
||||
__builtin_ieee_round_type(_FORTRAN_RUNTIME_IEEE_TO_ZERO), &
|
||||
__builtin_ieee_nearest = &
|
||||
__builtin_ieee_round_type(_FORTRAN_RUNTIME_IEEE_NEAREST), &
|
||||
__builtin_ieee_up = &
|
||||
__builtin_ieee_round_type(_FORTRAN_RUNTIME_IEEE_UP), &
|
||||
__builtin_ieee_down = &
|
||||
__builtin_ieee_round_type(_FORTRAN_RUNTIME_IEEE_DOWN), &
|
||||
__builtin_ieee_away = &
|
||||
__builtin_ieee_round_type(_FORTRAN_RUNTIME_IEEE_AWAY), &
|
||||
__builtin_ieee_other = &
|
||||
__builtin_ieee_round_type(_FORTRAN_RUNTIME_IEEE_OTHER)
|
||||
|
||||
type, public :: __builtin_team_type
|
||||
integer(kind=int64), private :: __id
|
||||
end type
|
||||
@@ -74,8 +112,10 @@ module __fortran_builtins
|
||||
intrinsic :: __builtin_ieee_selected_real_kind
|
||||
intrinsic :: __builtin_ieee_support_datatype, &
|
||||
__builtin_ieee_support_denormal, __builtin_ieee_support_divide, &
|
||||
__builtin_ieee_support_flag, __builtin_ieee_support_halting, &
|
||||
__builtin_ieee_support_inf, __builtin_ieee_support_io, &
|
||||
__builtin_ieee_support_nan, __builtin_ieee_support_sqrt, &
|
||||
__builtin_ieee_support_nan, __builtin_ieee_support_rounding, &
|
||||
__builtin_ieee_support_sqrt, &
|
||||
__builtin_ieee_support_standard, __builtin_ieee_support_subnormal, &
|
||||
__builtin_ieee_support_underflow_control
|
||||
public :: __builtin_fma
|
||||
@@ -87,8 +127,10 @@ module __fortran_builtins
|
||||
public :: __builtin_ieee_selected_real_kind
|
||||
public :: __builtin_ieee_support_datatype, &
|
||||
__builtin_ieee_support_denormal, __builtin_ieee_support_divide, &
|
||||
__builtin_ieee_support_flag, __builtin_ieee_support_halting, &
|
||||
__builtin_ieee_support_inf, __builtin_ieee_support_io, &
|
||||
__builtin_ieee_support_nan, __builtin_ieee_support_sqrt, &
|
||||
__builtin_ieee_support_nan, __builtin_ieee_support_rounding, &
|
||||
__builtin_ieee_support_sqrt, &
|
||||
__builtin_ieee_support_standard, __builtin_ieee_support_subnormal, &
|
||||
__builtin_ieee_support_underflow_control
|
||||
|
||||
|
||||
@@ -14,25 +14,22 @@
|
||||
include '../include/flang/Runtime/magic-numbers.h'
|
||||
|
||||
module __fortran_ieee_exceptions
|
||||
use __fortran_builtins, only: &
|
||||
ieee_flag_type => __builtin_ieee_flag_type, &
|
||||
ieee_support_flag => __builtin_ieee_support_flag, &
|
||||
ieee_support_halting => __builtin_ieee_support_halting, &
|
||||
ieee_invalid => __builtin_ieee_invalid, &
|
||||
ieee_overflow => __builtin_ieee_overflow, &
|
||||
ieee_divide_by_zero => __builtin_ieee_divide_by_zero, &
|
||||
ieee_underflow => __builtin_ieee_underflow, &
|
||||
ieee_inexact => __builtin_ieee_inexact, &
|
||||
ieee_denorm => __builtin_ieee_denorm
|
||||
implicit none
|
||||
|
||||
! Set PRIVATE by default to explicitly only export what is meant
|
||||
! to be exported by this MODULE.
|
||||
private
|
||||
|
||||
type, public :: ieee_flag_type ! Fortran 2018, 17.2 & 17.3
|
||||
private
|
||||
integer(kind=1) :: flag = 0
|
||||
end type ieee_flag_type
|
||||
|
||||
type(ieee_flag_type), parameter, public :: &
|
||||
ieee_invalid = ieee_flag_type(_FORTRAN_RUNTIME_IEEE_INVALID), &
|
||||
ieee_overflow = ieee_flag_type(_FORTRAN_RUNTIME_IEEE_OVERFLOW), &
|
||||
ieee_divide_by_zero = &
|
||||
ieee_flag_type(_FORTRAN_RUNTIME_IEEE_DIVIDE_BY_ZERO), &
|
||||
ieee_underflow = ieee_flag_type(_FORTRAN_RUNTIME_IEEE_UNDERFLOW), &
|
||||
ieee_inexact = ieee_flag_type(_FORTRAN_RUNTIME_IEEE_INEXACT), &
|
||||
ieee_denorm = ieee_flag_type(_FORTRAN_RUNTIME_IEEE_DENORM) ! extension
|
||||
public :: ieee_flag_type, ieee_support_flag, ieee_support_halting
|
||||
public :: ieee_invalid, ieee_overflow, ieee_divide_by_zero, ieee_underflow, &
|
||||
ieee_inexact, ieee_denorm
|
||||
|
||||
type(ieee_flag_type), parameter, public :: &
|
||||
ieee_usual(*) = [ ieee_overflow, ieee_divide_by_zero, ieee_invalid ], &
|
||||
@@ -139,28 +136,4 @@ module __fortran_ieee_exceptions
|
||||
end interface
|
||||
public :: ieee_set_status
|
||||
|
||||
#define IEEE_SUPPORT_FLAG_R(XKIND) \
|
||||
pure logical function ieee_support_flag_a##XKIND(flag, x); \
|
||||
import ieee_flag_type; \
|
||||
type(ieee_flag_type), intent(in) :: flag; \
|
||||
real(XKIND), intent(in) :: x(..); \
|
||||
end function ieee_support_flag_a##XKIND;
|
||||
interface ieee_support_flag
|
||||
pure logical function ieee_support_flag_0(flag)
|
||||
import ieee_flag_type
|
||||
type(ieee_flag_type), intent(in) :: flag
|
||||
end function ieee_support_flag_0
|
||||
SPECIFICS_R(IEEE_SUPPORT_FLAG_R)
|
||||
end interface ieee_support_flag
|
||||
public :: ieee_support_flag
|
||||
#undef IEEE_SUPPORT_FLAG_R
|
||||
|
||||
interface ieee_support_halting
|
||||
pure logical function ieee_support_halting_0(flag)
|
||||
import ieee_flag_type
|
||||
type(ieee_flag_type), intent(in) :: flag
|
||||
end function ieee_support_halting_0
|
||||
end interface
|
||||
public :: ieee_support_halting
|
||||
|
||||
end module __fortran_ieee_exceptions
|
||||
|
||||
@@ -18,13 +18,18 @@ module ieee_arithmetic
|
||||
use __fortran_ieee_exceptions
|
||||
|
||||
use __fortran_builtins, only: &
|
||||
ieee_away => __builtin_ieee_away, &
|
||||
ieee_down => __builtin_ieee_down, &
|
||||
ieee_fma => __builtin_fma, &
|
||||
ieee_is_nan => __builtin_ieee_is_nan, &
|
||||
ieee_is_negative => __builtin_ieee_is_negative, &
|
||||
ieee_is_normal => __builtin_ieee_is_normal, &
|
||||
ieee_nearest => __builtin_ieee_nearest, &
|
||||
ieee_next_after => __builtin_ieee_next_after, &
|
||||
ieee_next_down => __builtin_ieee_next_down, &
|
||||
ieee_next_up => __builtin_ieee_next_up, &
|
||||
ieee_other => __builtin_ieee_other, &
|
||||
ieee_round_type => __builtin_ieee_round_type, &
|
||||
ieee_scalb => scale, &
|
||||
ieee_selected_real_kind => __builtin_ieee_selected_real_kind, &
|
||||
ieee_support_datatype => __builtin_ieee_support_datatype, &
|
||||
@@ -33,10 +38,14 @@ module ieee_arithmetic
|
||||
ieee_support_inf => __builtin_ieee_support_inf, &
|
||||
ieee_support_io => __builtin_ieee_support_io, &
|
||||
ieee_support_nan => __builtin_ieee_support_nan, &
|
||||
ieee_support_rounding => __builtin_ieee_support_rounding, &
|
||||
ieee_support_sqrt => __builtin_ieee_support_sqrt, &
|
||||
ieee_support_standard => __builtin_ieee_support_standard, &
|
||||
ieee_support_subnormal => __builtin_ieee_support_subnormal, &
|
||||
ieee_support_underflow_control => __builtin_ieee_support_underflow_control
|
||||
ieee_support_underflow_control => __builtin_ieee_support_underflow_control, &
|
||||
ieee_to_zero => __builtin_ieee_to_zero, &
|
||||
ieee_up => __builtin_ieee_up
|
||||
|
||||
|
||||
implicit none
|
||||
|
||||
@@ -45,13 +54,18 @@ module ieee_arithmetic
|
||||
private
|
||||
|
||||
! Explicitly export the symbols from __fortran_builtins
|
||||
public :: ieee_away
|
||||
public :: ieee_down
|
||||
public :: ieee_fma
|
||||
public :: ieee_is_nan
|
||||
public :: ieee_is_negative
|
||||
public :: ieee_is_normal
|
||||
public :: ieee_nearest
|
||||
public :: ieee_other
|
||||
public :: ieee_next_after
|
||||
public :: ieee_next_down
|
||||
public :: ieee_next_up
|
||||
public :: ieee_round_type
|
||||
public :: ieee_scalb
|
||||
public :: ieee_selected_real_kind
|
||||
public :: ieee_support_datatype
|
||||
@@ -60,10 +74,13 @@ module ieee_arithmetic
|
||||
public :: ieee_support_inf
|
||||
public :: ieee_support_io
|
||||
public :: ieee_support_nan
|
||||
public :: ieee_support_rounding
|
||||
public :: ieee_support_sqrt
|
||||
public :: ieee_support_standard
|
||||
public :: ieee_support_subnormal
|
||||
public :: ieee_support_underflow_control
|
||||
public :: ieee_to_zero
|
||||
public :: ieee_up
|
||||
|
||||
! Explicitly export the symbols from __fortran_ieee_exceptions
|
||||
public :: ieee_flag_type
|
||||
@@ -114,19 +131,6 @@ module ieee_arithmetic
|
||||
ieee_negative_denormal = ieee_negative_subnormal, &
|
||||
ieee_positive_denormal = ieee_positive_subnormal
|
||||
|
||||
type, public :: ieee_round_type
|
||||
private
|
||||
integer(kind=1) :: mode = 0
|
||||
end type ieee_round_type
|
||||
|
||||
type(ieee_round_type), parameter, public :: &
|
||||
ieee_to_zero = ieee_round_type(_FORTRAN_RUNTIME_IEEE_TO_ZERO), &
|
||||
ieee_nearest = ieee_round_type(_FORTRAN_RUNTIME_IEEE_NEAREST), &
|
||||
ieee_up = ieee_round_type(_FORTRAN_RUNTIME_IEEE_UP), &
|
||||
ieee_down = ieee_round_type(_FORTRAN_RUNTIME_IEEE_DOWN), &
|
||||
ieee_away = ieee_round_type(_FORTRAN_RUNTIME_IEEE_AWAY), &
|
||||
ieee_other = ieee_round_type(_FORTRAN_RUNTIME_IEEE_OTHER)
|
||||
|
||||
interface operator(==)
|
||||
elemental logical function ieee_class_eq(x, y)
|
||||
import ieee_class_type
|
||||
@@ -586,22 +590,6 @@ module ieee_arithmetic
|
||||
public :: ieee_signbit
|
||||
#undef IEEE_SIGNBIT_R
|
||||
|
||||
#define IEEE_SUPPORT_ROUNDING_R(XKIND) \
|
||||
pure logical function ieee_support_rounding_a##XKIND(round_value, x); \
|
||||
import ieee_round_type; \
|
||||
type(ieee_round_type), intent(in) :: round_value; \
|
||||
real(XKIND), intent(in) :: x(..); \
|
||||
end function ieee_support_rounding_a##XKIND;
|
||||
interface ieee_support_rounding
|
||||
pure logical function ieee_support_rounding_0(round_value)
|
||||
import ieee_round_type
|
||||
type(ieee_round_type), intent(in) :: round_value
|
||||
end function ieee_support_rounding_0
|
||||
SPECIFICS_R(IEEE_SUPPORT_ROUNDING_R)
|
||||
end interface ieee_support_rounding
|
||||
public :: ieee_support_rounding
|
||||
#undef IEEE_SUPPORT_ROUNDING_R
|
||||
|
||||
#define IEEE_UNORDERED_RR(XKIND, YKIND) \
|
||||
elemental logical function ieee_unordered_a##XKIND##_a##YKIND(x, y); \
|
||||
real(XKIND), intent(in) :: x; \
|
||||
|
||||
Reference in New Issue
Block a user