diff --git a/flang-rt/lib/runtime/CMakeLists.txt b/flang-rt/lib/runtime/CMakeLists.txt index 9db7037355498..13ce726c19002 100644 --- a/flang-rt/lib/runtime/CMakeLists.txt +++ b/flang-rt/lib/runtime/CMakeLists.txt @@ -12,14 +12,10 @@ find_package(Backtrace) set(HAVE_BACKTRACE ${Backtrace_FOUND}) set(BACKTRACE_HEADER ${Backtrace_HEADER}) -# Module sources that are required by other modules -set(intrinsics_sources - __fortran_builtins.f90 - __cuda_builtins.f90 -) - # Fortran sources for builtin .mod files set(module_sources + __fortran_builtins.f90 + __cuda_builtins.f90 __fortran_ieee_exceptions.f90 __fortran_type_info.f90 flang_debug.f90 @@ -215,10 +211,8 @@ file(GLOB_RECURSE private_headers ) if (LLVM_TARGET_TRIPLE MATCHES "^ppc|^powerpc") - list(APPEND intrinsics_sources - __ppc_types.f90 - ) list(APPEND module_sources + __ppc_types.f90 __ppc_intrinsics.f90 mma.f90 ) @@ -264,21 +258,6 @@ if (TARGET FortranFloat128MathILib) endif () -# When a target depends on an object library, CMake seems to try to only build -# the object files that the target actual needs. If we are only interested -# in the module files, nothing gets built at all. To ensure that the module -# files are built, insert a custom target that is opaque to CMake so it cannot -# apply this optimization. Dependees on module files must depend on this -# barrier instead. An actual COMMAND (that does nothing) seems to be necessary -# on Windows to work. -function (add_module_barrier barriername objlib) - add_custom_target(${barriername} - COMMAND ${CMAKE_COMMAND} -E true - ) - add_dependencies(${barriername} ${objlib}) -endfunction () - - # Build module files if requested. # The object files written by Flang for these are unused. In the future parts # of flang-rt may itself be implemented in Fortran in which case these Fortran @@ -286,50 +265,10 @@ endfunction () # libflang_rt.runtime{.a/.so}. If they also provide an importable .mod, add them # to flang_module_target(... PUBLIC). if (FLANG_RT_FORTRAN_MODULES) - # CMake ignores intrinsic USE dependencies - # CMake has an option Fortran_BUILDING_INSTRINSIC_MODULES/Fortran_BUILDING_INTRINSIC_MODULES - # to disable this behavior, unfortunately it does not work with Ninja - # (https://gitlab.kitware.com/cmake/cmake/-/issues/26803) - # As a workaround, we build those intrinsic modules first such that the main - # runtime can depend on it. To ensure that modules files are also transitively - # updated if a USE'd .mod file changes (a .mod stores the checksums of all - # .mod files it depends on and therefore needs to be updated as well), inject - # an file-level dependency via OBJECT_DEPENDS. - - add_flangrt_library(flang_rt.mod.fortran.builtins OBJECT - __fortran_builtins.f90 - ) - set_property(SOURCE __fortran_builtins.f90 PROPERTY OBJECT_OUTPUTS "${CMAKE_BINARY_DIR}/modules/${CMAKE_CFG_INTDIR}/__fortran_builtins${CMAKE_Fortran_OUTPUT_EXTENSION}") - flang_module_target(flang_rt.mod.fortran.builtins PUBLIC) - add_module_barrier(flang_rt.mod.fortran.builtins.barrier flang_rt.mod.fortran.builtins) - - add_flangrt_library(flang_rt.mod.cuda.builtins OBJECT - __cuda_builtins.f90 - ) - set_property(SOURCE __cuda_builtins.f90 PROPERTY OBJECT_OUTPUTS "${CMAKE_BINARY_DIR}/modules/${CMAKE_CFG_INTDIR}/__cuda_builtins${CMAKE_Fortran_OUTPUT_EXTENSION}") - add_dependencies(flang_rt.mod.cuda.builtins flang_rt.mod.fortran.builtins.barrier) - set_property(SOURCE __cuda_builtins.f90 - APPEND PROPERTY OBJECT_DEPENDS - "${CMAKE_BINARY_DIR}/modules/${CMAKE_CFG_INTDIR}/__fortran_builtins${CMAKE_Fortran_OUTPUT_EXTENSION}" - ) - flang_module_target(flang_rt.mod.cuda.builtins PUBLIC) - add_module_barrier(flang_rt.mod.cuda.builtins.barrier flang_rt.mod.cuda.builtins) - - # The modules themselves - add_flangrt_library(flang_rt.mod OBJECT + add_flangrt_library(flang-rt-mod OBJECT ${module_sources} ) - add_dependencies(flang_rt.mod flang_rt.mod.fortran.builtins.barrier flang_rt.mod.cuda.builtins.barrier) - foreach(_srcfile IN LISTS module_sources) - set_property(SOURCE ${_srcfile} - APPEND PROPERTY OBJECT_DEPENDS - "${CMAKE_BINARY_DIR}/modules/${CMAKE_CFG_INTDIR}/__fortran_builtins${CMAKE_Fortran_OUTPUT_EXTENSION}" - "${CMAKE_BINARY_DIR}/modules/${CMAKE_CFG_INTDIR}/__cuda_builtins${CMAKE_Fortran_OUTPUT_EXTENSION}" - ) - endforeach() - - flang_module_target(flang_rt.mod PUBLIC) - add_module_barrier(flang-rt-mod flang_rt.mod) + flang_module_target(flang-rt-mod PUBLIC) if (RUNTIMES_FORTRAN_MODULES) set(_mod_install_dest "${RUNTIMES_INSTALL_RESOURCE_MOD_PATH}/..") diff --git a/flang-rt/lib/runtime/__fortran_type_info.f90 b/flang-rt/lib/runtime/__fortran_type_info.f90 index 0f1c3d018d009..d8cf385b8665e 100644 --- a/flang-rt/lib/runtime/__fortran_type_info.f90 +++ b/flang-rt/lib/runtime/__fortran_type_info.f90 @@ -13,7 +13,7 @@ module __fortran_type_info - use, intrinsic :: __fortran_builtins, & + use __fortran_builtins, & only: __builtin_c_ptr, __builtin_c_devptr, __builtin_c_funptr implicit none diff --git a/flang-rt/lib/runtime/cooperative_groups.f90 b/flang-rt/lib/runtime/cooperative_groups.f90 index 5ca0c3aa1f3a5..5c141d4d254db 100644 --- a/flang-rt/lib/runtime/cooperative_groups.f90 +++ b/flang-rt/lib/runtime/cooperative_groups.f90 @@ -10,8 +10,8 @@ module cooperative_groups -use, intrinsic :: __fortran_builtins, only: c_devptr => __builtin_c_devptr -use :: cudadevice ! implicit dependency, made explicit for CMake +use __fortran_builtins, only: c_devptr => __builtin_c_devptr +use cudadevice ! implicit dependency, made explicit for CMake implicit none diff --git a/flang-rt/lib/runtime/cudadevice.f90 b/flang-rt/lib/runtime/cudadevice.f90 index be041ba9d0a71..ea4787dd62e40 100644 --- a/flang-rt/lib/runtime/cudadevice.f90 +++ b/flang-rt/lib/runtime/cudadevice.f90 @@ -10,9 +10,9 @@ module cudadevice use __cuda_device - use, intrinsic :: __fortran_builtins, only: dim3 => __builtin_dim3 - use, intrinsic :: __fortran_builtins, only: c_devptr => __builtin_c_devptr - use, intrinsic :: __fortran_builtins, only: c_devloc => __builtin_c_devloc + use __fortran_builtins, only: dim3 => __builtin_dim3 + use __fortran_builtins, only: c_devptr => __builtin_c_devptr + use __fortran_builtins, only: c_devloc => __builtin_c_devloc implicit none ! Synchronization Functions diff --git a/openmp/module/CMakeLists.txt b/openmp/module/CMakeLists.txt index 451cbf9cc8fc8..f905cfbde0a04 100644 --- a/openmp/module/CMakeLists.txt +++ b/openmp/module/CMakeLists.txt @@ -33,13 +33,6 @@ if ("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^amdgcn|^nvptx") endif () flang_module_target(libomp-mod PUBLIC) -add_dependencies(libomp-mod ${RUNTIMES_FORTRAN_BUILD_DEPS}) -if ("flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES) - set_property(SOURCE "${CMAKE_CURRENT_BINARY_DIR}/omp_lib.F90" - APPEND PROPERTY OBJECT_DEPENDS - "${CMAKE_BINARY_DIR}/modules/${CMAKE_CFG_INTDIR}/__fortran_builtins${CMAKE_Fortran_OUTPUT_EXTENSION}" - ) -endif () install(FILES "${RUNTIMES_OUTPUT_RESOURCE_MOD_DIR}/omp_lib.h" diff --git a/openmp/module/omp_lib.F90.var b/openmp/module/omp_lib.F90.var index 464056847ab92..2db2a33e90127 100644 --- a/openmp/module/omp_lib.F90.var +++ b/openmp/module/omp_lib.F90.var @@ -12,7 +12,7 @@ module omp_lib_kinds - use, intrinsic :: iso_c_binding + use :: iso_c_binding ! Set PRIVATE by default to explicitly only export what is meant ! to be exported by this MODULE. @@ -640,20 +640,20 @@ end subroutine omp_display_env function omp_target_alloc(size, device_num) bind(c) - use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int + use :: iso_c_binding, only: c_ptr, c_size_t, c_int type(c_ptr) omp_target_alloc integer(c_size_t), value :: size integer(c_int), value :: device_num end function omp_target_alloc subroutine omp_target_free(device_ptr, device_num) bind(c) - use, intrinsic :: iso_c_binding, only: c_ptr, c_int + use :: iso_c_binding, only: c_ptr, c_int type(c_ptr), value :: device_ptr integer(c_int), value :: device_num end subroutine omp_target_free function omp_target_is_present(ptr, device_num) bind(c) - use, intrinsic :: iso_c_binding, only: c_ptr, c_int + use :: iso_c_binding, only: c_ptr, c_int integer(c_int) omp_target_is_present type(c_ptr), value :: ptr integer(c_int), value :: device_num @@ -661,7 +661,7 @@ function omp_target_memcpy(dst, src, length, dst_offset, src_offset, & dst_device_num, src_device_num) bind(c) - use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int + use :: iso_c_binding, only: c_ptr, c_size_t, c_int integer(c_int) omp_target_memcpy type(c_ptr), value :: dst, src integer(c_size_t), value :: length, dst_offset, src_offset @@ -671,7 +671,7 @@ function omp_target_memcpy_rect(dst, src, element_size, num_dims, & volume, dst_offsets, src_offsets, dst_dimensions, & src_dimensions, dst_device_num, src_device_num) bind(c) - use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int + use :: iso_c_binding, only: c_ptr, c_size_t, c_int integer(c_int) omp_target_memcpy_rect type(c_ptr), value :: dst, src integer(c_size_t), value :: element_size @@ -684,7 +684,7 @@ src_offset, dst_device_num, src_device_num, depobj_count, & depobj_list) bind(c) use omp_lib_kinds - use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int + use :: iso_c_binding, only: c_ptr, c_size_t, c_int integer(c_int) omp_target_memcpy_async type(c_ptr), value :: dst, src integer(c_size_t), value :: length, dst_offset, src_offset @@ -698,7 +698,7 @@ src_dimensions, dst_device_num, src_device_num, depobj_count, & depobj_list) bind(c) use omp_lib_kinds - use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int + use :: iso_c_binding, only: c_ptr, c_size_t, c_int integer(c_int) omp_target_memcpy_rect_async type(c_ptr), value :: dst, src integer(c_size_t), value :: element_size @@ -710,7 +710,7 @@ end function omp_target_memcpy_rect_async function omp_target_memset(ptr, val, count, device_num) bind(c) - use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_size_t + use :: iso_c_binding, only : c_ptr, c_int, c_size_t type(c_ptr) :: omp_target_memset type(c_ptr), value :: ptr integer(c_int), value :: val @@ -721,7 +721,7 @@ function omp_target_memset_async(ptr, val, count, device_num, & depobj_count, depobj_list) bind(c) use omp_lib_kinds - use, intrinsic :: iso_c_binding, only : c_ptr, c_int, c_size_t + use :: iso_c_binding, only : c_ptr, c_int, c_size_t type(c_ptr) :: omp_target_memset_async type(c_ptr), value :: ptr integer(c_int), value :: val @@ -733,7 +733,7 @@ function omp_target_associate_ptr(host_ptr, device_ptr, size, & device_offset, device_num) bind(c) - use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int + use :: iso_c_binding, only: c_ptr, c_size_t, c_int integer(c_int) omp_target_associate_ptr type(c_ptr), value :: host_ptr, device_ptr integer(c_size_t), value :: size, device_offset @@ -741,21 +741,21 @@ end function omp_target_associate_ptr function omp_get_mapped_ptr(ptr, device_num) bind(c) - use, intrinsic :: iso_c_binding, only: c_ptr, c_int + use :: iso_c_binding, only: c_ptr, c_int type(c_ptr) omp_get_mapped_ptr type(c_ptr), value :: ptr integer(c_int), value :: device_num end function omp_get_mapped_ptr function omp_target_disassociate_ptr(ptr, device_num) bind(c) - use, intrinsic :: iso_c_binding, only: c_ptr, c_int + use :: iso_c_binding, only: c_ptr, c_int integer(c_int) omp_target_disassociate_ptr type(c_ptr), value :: ptr integer(c_int), value :: device_num end function omp_target_disassociate_ptr function omp_target_is_accessible(ptr, size, device_num) bind(c) - use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t, c_int + use :: iso_c_binding, only : c_ptr, c_size_t, c_int integer(c_int) omp_target_is_accessible type(c_ptr), value :: ptr integer(c_size_t), value :: size @@ -764,7 +764,7 @@ function omp_alloc(size, allocator) bind(c) use omp_lib_kinds - use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t + use :: iso_c_binding, only : c_ptr, c_size_t type(c_ptr) omp_alloc integer(c_size_t), value :: size integer(omp_allocator_handle_kind), value :: allocator @@ -772,7 +772,7 @@ function omp_aligned_alloc(alignment, size, allocator) bind(c) use omp_lib_kinds - use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t + use :: iso_c_binding, only : c_ptr, c_size_t type(c_ptr) omp_aligned_alloc integer(c_size_t), value :: alignment, size integer(omp_allocator_handle_kind), value :: allocator @@ -780,7 +780,7 @@ function omp_calloc(nmemb, size, allocator) bind(c) use omp_lib_kinds - use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t + use :: iso_c_binding, only : c_ptr, c_size_t type(c_ptr) omp_calloc integer(c_size_t), value :: nmemb, size integer(omp_allocator_handle_kind), value :: allocator @@ -788,7 +788,7 @@ function omp_aligned_calloc(alignment, nmemb, size, allocator) bind(c) use omp_lib_kinds - use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t + use :: iso_c_binding, only : c_ptr, c_size_t type(c_ptr) omp_aligned_calloc integer(c_size_t), value :: alignment, nmemb, size integer(omp_allocator_handle_kind), value :: allocator @@ -796,7 +796,7 @@ function omp_realloc(ptr, size, allocator, free_allocator) bind(c) use omp_lib_kinds - use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t + use :: iso_c_binding, only : c_ptr, c_size_t type(c_ptr) omp_realloc type(c_ptr), value :: ptr integer(c_size_t), value :: size @@ -806,7 +806,7 @@ subroutine omp_free(ptr, allocator) bind(c) use omp_lib_kinds - use, intrinsic :: iso_c_binding, only : c_ptr + use :: iso_c_binding, only : c_ptr type(c_ptr), value :: ptr integer(omp_allocator_handle_kind), value :: allocator end subroutine omp_free diff --git a/runtimes/cmake/config-Fortran.cmake b/runtimes/cmake/config-Fortran.cmake index 74fd15021f0a0..6d2d3bdbf60ea 100644 --- a/runtimes/cmake/config-Fortran.cmake +++ b/runtimes/cmake/config-Fortran.cmake @@ -74,14 +74,8 @@ endfunction () set(RUNTIMES_ENABLE_FORTRAN OFF) -# Insert at least one element for -# -# add_dependencies(target ${RUNTIMES_FORTRAN_BUILD_DEPS}) -# -# to not fail -add_custom_target(fortran-dummy-dep) -set(RUNTIMES_FORTRAN_BUILD_DEPS fortran-dummy-dep) +set(RUNTIMES_FORTRAN_BUILD_DEPS "") if (CMAKE_Fortran_COMPILER) # Workarounds for older versions of CMake not recognizing FLang. Hence, we @@ -244,6 +238,22 @@ function (flang_module_target tgtname) "$<$:-fintrinsic-modules-path=${RUNTIMES_OUTPUT_RESOURCE_MOD_DIR}>" ) + # Make CMake not ignore "use, intrinsic ::"-dependencies. Unfortunately, + # it is not universally handled by CMake s.t. we currently must not use + # "use, intrinsic ::" in our sources. + # * CMake 3.22: Added Fortran_BUILDING_INSTRINSIC_MODULES handling "Unix Makefiles" generator + # * CMake 4.0: Renamed INSTRINSIC to INTRINSIC (typo fix); INSTRINSIC spelling kept but deprecated + # * CMake 4.5: Added handling by Ninja generators as well + set_target_properties(${tgtname} + PROPERTIES + Fortran_BUILDING_INTRINSIC_MODULES ON + Fortran_BUILDING_INSTRINSIC_MODULES ON + ) + + if (RUNTIMES_FORTRAN_BUILD_DEPS AND NOT tgtname IN_LIST RUNTIMES_FORTRAN_BUILD_DEPS) + target_link_libraries(${tgtname} PRIVATE ${RUNTIMES_FORTRAN_BUILD_DEPS}) + endif () + if (CMAKE_Fortran_COMPILER_ID MATCHES "LLVM") target_compile_options(${tgtname} PRIVATE # Flang bug workaround: Reformating of cooked token buffer causes