diff options
| author | Michael Kruse <llvm-project@meinersbur.de> | 2025-09-20 13:06:02 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-20 13:06:02 +0200 |
| commit | f205a2c0a093767144f474fe54bbfa103e1d6431 (patch) | |
| tree | d24d70fea883acd646a093e0c97bcebf8b85b64c /openmp | |
| parent | 47c1b650626043f0a8f8e32851617201751f9439 (diff) | |
[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.
Diffstat (limited to 'openmp')
| -rw-r--r-- | openmp/CMakeLists.txt | 15 | ||||
| -rw-r--r-- | openmp/README.rst | 2 | ||||
| -rw-r--r-- | openmp/cmake/OpenMPTesting.cmake | 4 | ||||
| -rw-r--r-- | openmp/runtime/test/CMakeLists.txt | 8 | ||||
| -rw-r--r-- | openmp/runtime/test/lit.cfg | 15 | ||||
| -rw-r--r-- | openmp/runtime/test/lit.site.cfg.in | 2 | ||||
| -rw-r--r-- | openmp/runtime/test/transform/unroll/heuristic_intdo.f90 | 26 |
7 files changed, 63 insertions, 9 deletions
diff --git a/openmp/CMakeLists.txt b/openmp/CMakeLists.txt index a2b7e1054e02..cb76906d7827 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 c34d3e8a40d7..cc485f9a56ce 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 85240aede728..60280b7ed489 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 a7790804542b..9ee3be693981 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 4a5aff241765..72da1ba1411f 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 fc65289e4ce6..cc8b3b252d7d 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 000000000000..d0ef938dd3a8 --- /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 |
