Skip to content

[flang][NFC] Refactor MODULE definitions to not accidentally leak symbols #80833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions flang/module/__cuda_builtins.f90
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,16 @@
blockIdx => __builtin_blockIdx, &
gridDim => __builtin_gridDim, &
warpsize => __builtin_warpsize

implicit none

! Set PRIVATE by default to explicitly only export what is meant
! to be exported by this MODULE.
private

public :: threadIdx, &
blockDim, &
blockIdx, &
gridDim, &
warpsize
end module
68 changes: 49 additions & 19 deletions flang/module/__fortran_builtins.f90
Original file line number Diff line number Diff line change
Expand Up @@ -11,52 +11,60 @@
! to USE the standard intrinsic modules in order to access the
! standard names of the procedures.
module __fortran_builtins
implicit none

! Set PRIVATE by default to explicitly only export what is meant
! to be exported by this MODULE.
private

intrinsic :: __builtin_c_loc

intrinsic :: __builtin_c_f_pointer
public :: __builtin_c_f_pointer

intrinsic :: sizeof ! extension
public :: sizeof

intrinsic :: selected_int_kind
private :: selected_int_kind
integer, parameter, private :: int64 = selected_int_kind(18)
integer, parameter :: int64 = selected_int_kind(18)

type, bind(c) :: __builtin_c_ptr
type, bind(c), public :: __builtin_c_ptr
integer(kind=int64), private :: __address
end type

type, bind(c) :: __builtin_c_funptr
type, bind(c), public :: __builtin_c_funptr
integer(kind=int64), private :: __address
end type

type :: __builtin_event_type
type, public :: __builtin_event_type
integer(kind=int64), private :: __count
end type

type :: __builtin_notify_type
type, public :: __builtin_notify_type
integer(kind=int64), private :: __count
end type

type :: __builtin_lock_type
type, public :: __builtin_lock_type
integer(kind=int64), private :: __count
end type

type :: __builtin_team_type
type, public :: __builtin_team_type
integer(kind=int64), private :: __id
end type

integer, parameter :: __builtin_atomic_int_kind = selected_int_kind(18)
integer, parameter :: &
integer, parameter, public :: __builtin_atomic_int_kind = selected_int_kind(18)
integer, parameter, public :: &
__builtin_atomic_logical_kind = __builtin_atomic_int_kind

procedure(type(__builtin_c_ptr)) :: __builtin_c_loc
procedure(type(__builtin_c_ptr)), public :: __builtin_c_loc

type :: __builtin_dim3
type, public :: __builtin_dim3
integer :: x=1, y=1, z=1
end type
type(__builtin_dim3) :: &
type(__builtin_dim3), public :: &
__builtin_threadIdx, __builtin_blockDim, __builtin_blockIdx, &
__builtin_gridDim
integer, parameter :: __builtin_warpsize = 32
integer, parameter, public :: __builtin_warpsize = 32

intrinsic :: __builtin_fma
intrinsic :: __builtin_ieee_is_nan, __builtin_ieee_is_negative, &
Expand All @@ -71,8 +79,21 @@
__builtin_ieee_support_nan, __builtin_ieee_support_sqrt, &
__builtin_ieee_support_standard, __builtin_ieee_support_subnormal, &
__builtin_ieee_support_underflow_control
public :: __builtin_fma
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 :: scale ! for ieee_scalb
public :: __builtin_ieee_selected_real_kind
public :: __builtin_ieee_support_datatype, &
__builtin_ieee_support_denormal, __builtin_ieee_support_divide, &
__builtin_ieee_support_inf, __builtin_ieee_support_io, &
__builtin_ieee_support_nan, __builtin_ieee_support_sqrt, &
__builtin_ieee_support_standard, __builtin_ieee_support_subnormal, &
__builtin_ieee_support_underflow_control

type, private :: __force_derived_type_instantiations
type :: __force_derived_type_instantiations
type(__builtin_c_ptr) :: c_ptr
type(__builtin_c_funptr) :: c_funptr
type(__builtin_event_type) :: event_type
Expand All @@ -81,25 +102,34 @@
end type

intrinsic :: __builtin_compiler_options, __builtin_compiler_version
public :: __builtin_compiler_options, __builtin_compiler_version

interface operator(==)
module procedure __builtin_c_ptr_eq
end interface
public :: operator(==)

interface operator(/=)
module procedure __builtin_c_ptr_eq
end interface
public :: operator(/=)

interface __builtin_c_associated
module procedure c_associated_c_ptr
module procedure c_associated_c_funptr
end interface
private :: c_associated_c_ptr, c_associated_c_funptr
public :: __builtin_c_associated
! private :: c_associated_c_ptr, c_associated_c_funptr

type(__builtin_c_ptr), parameter :: __builtin_c_null_ptr = __builtin_c_ptr(0)
type(__builtin_c_funptr), parameter :: &
type(__builtin_c_ptr), parameter, public :: __builtin_c_null_ptr = __builtin_c_ptr(0)
type(__builtin_c_funptr), parameter, public :: &
__builtin_c_null_funptr = __builtin_c_funptr(0)

contains
public :: __builtin_c_ptr_eq
public :: __builtin_c_ptr_ne
public :: __builtin_c_funloc

contains

elemental logical function __builtin_c_ptr_eq(x, y)
type(__builtin_c_ptr), intent(in) :: x, y
Expand Down
42 changes: 20 additions & 22 deletions flang/module/__fortran_ieee_exceptions.f90
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@
include '../include/flang/Runtime/magic-numbers.h'

module __fortran_ieee_exceptions
implicit none

type :: ieee_flag_type ! Fortran 2018, 17.2 & 17.3
! 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 :: &
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 = &
Expand All @@ -29,16 +34,16 @@
ieee_inexact = ieee_flag_type(_FORTRAN_RUNTIME_IEEE_INEXACT), &
ieee_denorm = ieee_flag_type(_FORTRAN_RUNTIME_IEEE_DENORM) ! extension

type(ieee_flag_type), parameter :: &
type(ieee_flag_type), parameter, public :: &
ieee_usual(*) = [ ieee_overflow, ieee_divide_by_zero, ieee_invalid ], &
ieee_all(*) = [ ieee_usual, ieee_underflow, ieee_inexact ]

type :: ieee_modes_type ! Fortran 2018, 17.7
type, public :: ieee_modes_type ! Fortran 2018, 17.7
private ! opaque fenv.h femode_t data
integer(kind=4) :: __data(_FORTRAN_RUNTIME_IEEE_FEMODE_T_EXTENT)
end type ieee_modes_type

type :: ieee_status_type ! Fortran 2018, 17.7
type, public :: ieee_status_type ! Fortran 2018, 17.7
private ! opaque fenv.h fenv_t data
integer(kind=4) :: __data(_FORTRAN_RUNTIME_IEEE_FENV_T_EXTENT)
end type ieee_status_type
Expand All @@ -54,18 +59,6 @@
G(2) G(3) G(4) G(8) G(16)
#endif

! Set PRIVATE accessibility for specifics with 1 LOGICAL or REAL argument for
! generic G.
#define PRIVATE_L(G) private :: \
G##_l1, G##_l2, G##_l4, G##_l8
#if __x86_64__
#define PRIVATE_R(G) private :: \
G##_a2, G##_a3, G##_a4, G##_a8, G##_a10, G##_a16
#else
#define PRIVATE_R(G) private :: \
G##_a2, G##_a3, G##_a4, G##_a8, G##_a16
#endif

#define IEEE_GET_FLAG_L(FVKIND) \
elemental subroutine ieee_get_flag_l##FVKIND(flag, flag_value); \
import ieee_flag_type; \
Expand All @@ -75,7 +68,7 @@ end subroutine ieee_get_flag_l##FVKIND;
interface ieee_get_flag
SPECIFICS_L(IEEE_GET_FLAG_L)
end interface ieee_get_flag
PRIVATE_L(IEEE_GET_FLAG)
public :: ieee_get_flag
#undef IEEE_GET_FLAG_L

#define IEEE_GET_HALTING_MODE_L(HKIND) \
Expand All @@ -87,7 +80,7 @@ end subroutine ieee_get_halting_mode_l##HKIND;
interface ieee_get_halting_mode
SPECIFICS_L(IEEE_GET_HALTING_MODE_L)
end interface ieee_get_halting_mode
PRIVATE_L(IEEE_GET_HALTING_MODE)
public :: ieee_get_halting_mode
#undef IEEE_GET_HALTING_MODE_L

interface ieee_get_modes
Expand All @@ -96,13 +89,15 @@ pure subroutine ieee_get_modes_0(modes)
type(ieee_modes_type), intent(out) :: modes
end subroutine ieee_get_modes_0
end interface
public :: ieee_get_modes

interface ieee_get_status
pure subroutine ieee_get_status_0(status)
import ieee_status_type
type(ieee_status_type), intent(out) :: status
end subroutine ieee_get_status_0
end interface
public :: ieee_get_status

#define IEEE_SET_FLAG_L(FVKIND) \
elemental subroutine ieee_set_flag_l##FVKIND(flag, flag_value); \
Expand All @@ -113,7 +108,7 @@ end subroutine ieee_set_flag_l##FVKIND;
interface ieee_set_flag
SPECIFICS_L(IEEE_SET_FLAG_L)
end interface ieee_set_flag
PRIVATE_L(IEEE_SET_FLAG)
public :: ieee_set_flag
#undef IEEE_SET_FLAG_L

#define IEEE_SET_HALTING_MODE_L(HKIND) \
Expand All @@ -125,7 +120,7 @@ end subroutine ieee_set_halting_mode_l##HKIND;
interface ieee_set_halting_mode
SPECIFICS_L(IEEE_SET_HALTING_MODE_L)
end interface ieee_set_halting_mode
PRIVATE_L(IEEE_SET_HALTING_MODE)
public :: ieee_set_halting_mode
#undef IEEE_SET_HALTING_MODE_L

interface ieee_set_modes
Expand All @@ -134,13 +129,15 @@ subroutine ieee_set_modes_0(modes)
type(ieee_modes_type), intent(in) :: modes
end subroutine ieee_set_modes_0
end interface
public :: ieee_set_modes

interface ieee_set_status
subroutine ieee_set_status_0(status)
import ieee_status_type
type(ieee_status_type), intent(in) :: status
end subroutine ieee_set_status_0
end interface
public :: ieee_set_status

#define IEEE_SUPPORT_FLAG_R(XKIND) \
pure logical function ieee_support_flag_a##XKIND(flag, x); \
Expand All @@ -155,7 +152,7 @@ pure logical function ieee_support_flag_0(flag)
end function ieee_support_flag_0
SPECIFICS_R(IEEE_SUPPORT_FLAG_R)
end interface ieee_support_flag
PRIVATE_R(IEEE_SUPPORT_FLAG)
public :: ieee_support_flag
#undef IEEE_SUPPORT_FLAG_R

interface ieee_support_halting
Expand All @@ -164,5 +161,6 @@ pure logical function ieee_support_halting_0(flag)
type(ieee_flag_type), intent(in) :: flag
end function ieee_support_halting_0
end interface
public :: ieee_support_halting

end module __fortran_ieee_exceptions
3 changes: 3 additions & 0 deletions flang/module/__fortran_type_info.f90
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@

use, intrinsic :: __fortran_builtins, &
only: __builtin_c_ptr, __builtin_c_funptr
implicit none

! Set PRIVATE by default to explicitly only export what is meant
! to be exported by this MODULE.
private

integer, parameter :: int64 = selected_int_kind(18)
Expand Down
5 changes: 5 additions & 0 deletions flang/module/__ppc_types.f90
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
!===------------------------------------------------------------------------===!

module __ppc_types
implicit none

! Set PRIVATE by default to explicitly only export what is meant
! to be exported by this MODULE.
private

! Definition of derived-types that represent PowerPC vector types.
type __builtin_ppc_intrinsic_vector(element_category, element_kind)
integer, kind :: element_category, element_kind
Expand Down
Loading