[llvm] f205a2c - [OpenMP] Allow Fortran tests (#150722)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 20 04:06:06 PDT 2025
Author: Michael Kruse
Date: 2025-09-20T13:06:02+02:00
New Revision: f205a2c0a093767144f474fe54bbfa103e1d6431
URL: https://github.com/llvm/llvm-project/commit/f205a2c0a093767144f474fe54bbfa103e1d6431
DIFF: https://github.com/llvm/llvm-project/commit/f205a2c0a093767144f474fe54bbfa103e1d6431.diff
LOG: [OpenMP] Allow Fortran tests (#150722)
In addition to existing C/C++ tests, add Fortran-based tests. Fortran
tests will only run if a Fortran compiler is found. The first test is
for the unroll construct added in #144785.
Added:
openmp/runtime/test/transform/unroll/heuristic_intdo.f90
Modified:
llvm/runtimes/CMakeLists.txt
openmp/CMakeLists.txt
openmp/README.rst
openmp/cmake/OpenMPTesting.cmake
openmp/runtime/test/CMakeLists.txt
openmp/runtime/test/lit.cfg
openmp/runtime/test/lit.site.cfg.in
Removed:
################################################################################
diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt
index c98d12ce7992d..839929204c064 100644
--- a/llvm/runtimes/CMakeLists.txt
+++ b/llvm/runtimes/CMakeLists.txt
@@ -532,6 +532,10 @@ if(build_runtimes)
endif()
endforeach()
endif()
+ # Allow openmp to see the Fortran compiler
+ if ("openmp" IN_LIST LLVM_ENABLE_RUNTIMES AND "flang" IN_LIST LLVM_ENABLE_PROJECTS)
+ list(APPEND extra_args ENABLE_FORTRAN)
+ endif()
if("openmp" IN_LIST LLVM_ENABLE_RUNTIMES OR "offload" IN_LIST LLVM_ENABLE_RUNTIMES)
if (${LLVM_TOOL_FLANG_BUILD})
message(STATUS "Configuring build of omp_lib.mod and omp_lib_kinds.mod via flang")
diff --git a/openmp/CMakeLists.txt b/openmp/CMakeLists.txt
index a2b7e1054e02b..cb76906d78277 100644
--- a/openmp/CMakeLists.txt
+++ b/openmp/CMakeLists.txt
@@ -78,13 +78,6 @@ else()
set(OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++.exe)
endif()
- # Check for flang
- if (NOT MSVC)
- set(OPENMP_TEST_Fortran_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/flang)
- else()
- set(OPENMP_TEST_Fortran_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/flang.exe)
- endif()
-
# Set fortran test compiler if flang is found
if (EXISTS "${OPENMP_TEST_Fortran_COMPILER}")
message("Using local flang build at ${OPENMP_TEST_Fortran_COMPILER}")
@@ -103,6 +96,14 @@ endif()
include(config-ix)
include(HandleOpenMPOptions)
+# Check for flang
+set(OPENMP_TEST_Fortran_COMPILER_default "flang")
+if (CMAKE_Fortran_COMPILER)
+ set(OPENMP_TEST_Fortran_COMPILER_default "${CMAKE_Fortran_COMPILER}")
+endif ()
+set(OPENMP_TEST_Fortran_COMPILER "${OPENMP_TEST_Fortran_COMPILER_default}" CACHE STRING
+ "Fortran compiler to use for testing OpenMP runtime libraries.")
+
# Set up testing infrastructure.
include(OpenMPTesting)
diff --git a/openmp/README.rst b/openmp/README.rst
index c34d3e8a40d7d..cc485f9a56ce0 100644
--- a/openmp/README.rst
+++ b/openmp/README.rst
@@ -121,7 +121,7 @@ Options for all Libraries
**OPENMP_TEST_Fortran_COMPILER** = ``${CMAKE_Fortran_COMPILER}``
Compiler to use for testing. Defaults to the compiler that was also used for
- building. Will default to flang if build is in-tree.
+ building.
**OPENMP_LLVM_TOOLS_DIR** = ``/path/to/built/llvm/tools``
Additional path to search for LLVM tools needed by tests.
diff --git a/openmp/cmake/OpenMPTesting.cmake b/openmp/cmake/OpenMPTesting.cmake
index 85240aede728d..60280b7ed4893 100644
--- a/openmp/cmake/OpenMPTesting.cmake
+++ b/openmp/cmake/OpenMPTesting.cmake
@@ -238,6 +238,10 @@ function(add_openmp_testsuite target comment)
)
endif()
endif()
+
+ if (TARGET flang-rt)
+ add_dependencies(${target} flang-rt)
+ endif ()
endfunction()
function(construct_check_openmp_target)
diff --git a/openmp/runtime/test/CMakeLists.txt b/openmp/runtime/test/CMakeLists.txt
index a7790804542b7..9ee3be6939811 100644
--- a/openmp/runtime/test/CMakeLists.txt
+++ b/openmp/runtime/test/CMakeLists.txt
@@ -41,7 +41,13 @@ add_library(ompt-print-callback INTERFACE)
target_include_directories(ompt-print-callback INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/ompt)
-add_openmp_testsuite(check-libomp "Running libomp tests" ${CMAKE_CURRENT_BINARY_DIR} DEPENDS omp)
+add_custom_target(libomp-test-depends)
+add_dependencies(libomp-test-depends omp)
+if (LLVM_RUNTIMES_BUILD AND OPENMP_TEST_Fortran_COMPILER AND "flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
+ add_dependencies(libomp-test-depends flang-rt)
+endif ()
+
+add_openmp_testsuite(check-libomp "Running libomp tests" ${CMAKE_CURRENT_BINARY_DIR} DEPENDS libomp-test-depends)
# Add target check-ompt, but make sure to not add the tests twice to check-openmp.
add_openmp_testsuite(check-ompt "Running OMPT tests" ${CMAKE_CURRENT_BINARY_DIR}/ompt EXCLUDE_FROM_CHECK_ALL DEPENDS omp)
diff --git a/openmp/runtime/test/lit.cfg b/openmp/runtime/test/lit.cfg
index 4a5aff241765c..72da1ba1411f8 100644
--- a/openmp/runtime/test/lit.cfg
+++ b/openmp/runtime/test/lit.cfg
@@ -5,6 +5,8 @@ import os
import re
import subprocess
import lit.formats
+from lit.llvm.subst import ToolSubst
+from lit.llvm import llvm_config
# Tell pylint that we know config and lit_config exist somewhere.
if 'PYLINT_IMPORT' in os.environ:
@@ -39,6 +41,19 @@ config.name = 'libomp'
# suffixes: A list of file extensions to treat as test files.
config.suffixes = ['.c', '.cpp']
+if config.test_fortran_compiler:
+ lit_config.note("OpenMP Fortran tests enabled")
+ config.suffixes += ['.f90', '.F90']
+ llvm_config.add_tool_substitutions([
+ ToolSubst(
+ "%flang",
+ command=config.test_fortran_compiler,
+ unresolved="fatal",
+ ),
+ ], [config.llvm_tools_dir])
+else:
+ lit_config.note("OpenMP Fortran tests disabled")
+
# test_source_root: The root path where tests are located.
config.test_source_root = os.path.dirname(__file__)
diff --git a/openmp/runtime/test/lit.site.cfg.in b/openmp/runtime/test/lit.site.cfg.in
index fc65289e4ce64..cc8b3b252d7d1 100644
--- a/openmp/runtime/test/lit.site.cfg.in
+++ b/openmp/runtime/test/lit.site.cfg.in
@@ -2,6 +2,7 @@
config.test_c_compiler = "@OPENMP_TEST_C_COMPILER@"
config.test_cxx_compiler = "@OPENMP_TEST_CXX_COMPILER@"
+config.test_fortran_compiler = "@OPENMP_TEST_Fortran_COMPILER@"
config.test_compiler_features = @OPENMP_TEST_COMPILER_FEATURES@
config.test_compiler_has_omp_h = @OPENMP_TEST_COMPILER_HAS_OMP_H@
config.test_filecheck = "@OPENMP_FILECHECK_EXECUTABLE@"
@@ -24,6 +25,7 @@ config.has_omit_frame_pointer_flag = @OPENMP_TEST_COMPILER_HAS_OMIT_FRAME_POINTE
config.target_arch = "@LIBOMP_ARCH@"
config.compiler_frontend_variant = "@CMAKE_C_COMPILER_FRONTEND_VARIANT@"
config.compiler_simulate_id = "@CMAKE_C_SIMULATE_ID@"
+config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
import lit.llvm
lit.llvm.initialize(lit_config, config)
diff --git a/openmp/runtime/test/transform/unroll/heuristic_intdo.f90 b/openmp/runtime/test/transform/unroll/heuristic_intdo.f90
new file mode 100644
index 0000000000000..d0ef938dd3a8f
--- /dev/null
+++ b/openmp/runtime/test/transform/unroll/heuristic_intdo.f90
@@ -0,0 +1,26 @@
+! This test checks lowering of OpenMP unroll directive
+
+! RUN: %flang %flags %openmp_flags -fopenmp-version=51 %s -o %t.exe
+! RUN: %t.exe | FileCheck %s --match-full-lines
+
+
+program unroll_heuristic
+ integer :: i
+ print *, 'do'
+
+ !$OMP UNROLL
+ do i=7, 18, 3
+ print '("i=", I0)', i
+ end do
+ !$OMP END UNROLL
+
+ print *, 'done'
+end program
+
+
+! CHECK: do
+! CHECK-NEXT: i=7
+! CHECK-NEXT: i=10
+! CHECK-NEXT: i=13
+! CHECK-NEXT: i=16
+! CHECK-NEXT: done
More information about the llvm-commits
mailing list