Skip to content

Commit 70dbb33

Browse files
committed
Allow tests written in Fortran
1 parent dac9d8f commit 70dbb33

File tree

8 files changed

+68
-9
lines changed

8 files changed

+68
-9
lines changed

llvm/runtimes/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,11 @@ if(build_runtimes)
524524
endif()
525525
endforeach()
526526
endif()
527+
528+
if ("openmp" IN_LIST LLVM_ENABLE_RUNTIMES AND "flang" IN_LIST LLVM_ENABLE_PROJECTS)
529+
# Allow openmp to see the Fortran compiler
530+
list(APPEND extra_args ENABLE_FORTRAN)
531+
endif()
527532
if("openmp" IN_LIST LLVM_ENABLE_RUNTIMES OR "offload" IN_LIST LLVM_ENABLE_RUNTIMES)
528533
if (${LLVM_TOOL_FLANG_BUILD})
529534
message(STATUS "Configuring build of omp_lib.mod and omp_lib_kinds.mod via flang")

openmp/CMakeLists.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,6 @@ else()
7878
set(OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++.exe)
7979
endif()
8080

81-
# Check for flang
82-
if (NOT MSVC)
83-
set(OPENMP_TEST_Fortran_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/flang)
84-
else()
85-
set(OPENMP_TEST_Fortran_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/flang.exe)
86-
endif()
87-
8881
# Set fortran test compiler if flang is found
8982
if (EXISTS "${OPENMP_TEST_Fortran_COMPILER}")
9083
message("Using local flang build at ${OPENMP_TEST_Fortran_COMPILER}")
@@ -103,6 +96,14 @@ endif()
10396
include(config-ix)
10497
include(HandleOpenMPOptions)
10598

99+
# Check for flang
100+
set(OPENMP_TEST_Fortran_COMPILER_default "flang")
101+
if (CMAKE_Fortran_COMPILER)
102+
set(OPENMP_TEST_Fortran_COMPILER_default "${CMAKE_Fortran_COMPILER}")
103+
endif ()
104+
set(OPENMP_TEST_Fortran_COMPILER "${OPENMP_TEST_Fortran_COMPILER_default}" CACHE STRING
105+
"Fortran compiler to use for testing OpenMP runtime libraries.")
106+
106107
# Set up testing infrastructure.
107108
include(OpenMPTesting)
108109

openmp/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Options for all Libraries
121121

122122
**OPENMP_TEST_Fortran_COMPILER** = ``${CMAKE_Fortran_COMPILER}``
123123
Compiler to use for testing. Defaults to the compiler that was also used for
124-
building. Will default to flang if build is in-tree.
124+
building.
125125

126126
**OPENMP_LLVM_TOOLS_DIR** = ``/path/to/built/llvm/tools``
127127
Additional path to search for LLVM tools needed by tests.

openmp/cmake/OpenMPTesting.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ function(add_openmp_testsuite target comment)
238238
)
239239
endif()
240240
endif()
241+
242+
if (TARGET flang-rt)
243+
add_dependencies(${target} flang-rt)
244+
endif ()
241245
endfunction()
242246

243247
function(construct_check_openmp_target)

openmp/runtime/test/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ add_library(ompt-print-callback INTERFACE)
4141
target_include_directories(ompt-print-callback INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/ompt)
4242

4343

44-
add_openmp_testsuite(check-libomp "Running libomp tests" ${CMAKE_CURRENT_BINARY_DIR} DEPENDS omp)
44+
add_custom_target(libomp-test-depends)
45+
add_dependencies(libomp-test-depends omp)
46+
if (LLVM_RUNTIMES_BUILD AND OPENMP_TEST_Fortran_COMPILER AND "flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
47+
add_dependencies(libomp-test-depends flang-rt)
48+
endif ()
49+
50+
add_openmp_testsuite(check-libomp "Running libomp tests" ${CMAKE_CURRENT_BINARY_DIR} DEPENDS libomp-test-depends)
4551
# Add target check-ompt, but make sure to not add the tests twice to check-openmp.
4652
add_openmp_testsuite(check-ompt "Running OMPT tests" ${CMAKE_CURRENT_BINARY_DIR}/ompt EXCLUDE_FROM_CHECK_ALL DEPENDS omp)
4753

openmp/runtime/test/lit.cfg

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import os
55
import re
66
import subprocess
77
import lit.formats
8+
from lit.llvm.subst import ToolSubst
9+
from lit.llvm import llvm_config
810

911
# Tell pylint that we know config and lit_config exist somewhere.
1012
if 'PYLINT_IMPORT' in os.environ:
@@ -39,6 +41,19 @@ config.name = 'libomp'
3941
# suffixes: A list of file extensions to treat as test files.
4042
config.suffixes = ['.c', '.cpp']
4143

44+
if config.test_fortran_compiler:
45+
lit_config.note("OpenMP Fortran tests enabled")
46+
config.suffixes += ['.f90', '.F90']
47+
llvm_config.add_tool_substitutions([
48+
ToolSubst(
49+
"%flang",
50+
command=config.test_fortran_compiler,
51+
unresolved="fatal",
52+
),
53+
], [config.llvm_tools_dir])
54+
else:
55+
lit_config.note("OpenMP Fortran tests disabled")
56+
4257
# test_source_root: The root path where tests are located.
4358
config.test_source_root = os.path.dirname(__file__)
4459

openmp/runtime/test/lit.site.cfg.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
config.test_c_compiler = "@OPENMP_TEST_C_COMPILER@"
44
config.test_cxx_compiler = "@OPENMP_TEST_CXX_COMPILER@"
5+
config.test_fortran_compiler = "@OPENMP_TEST_Fortran_COMPILER@"
56
config.test_compiler_features = @OPENMP_TEST_COMPILER_FEATURES@
67
config.test_compiler_has_omp_h = @OPENMP_TEST_COMPILER_HAS_OMP_H@
78
config.test_filecheck = "@OPENMP_FILECHECK_EXECUTABLE@"
@@ -24,6 +25,7 @@ config.has_omit_frame_pointer_flag = @OPENMP_TEST_COMPILER_HAS_OMIT_FRAME_POINTE
2425
config.target_arch = "@LIBOMP_ARCH@"
2526
config.compiler_frontend_variant = "@CMAKE_C_COMPILER_FRONTEND_VARIANT@"
2627
config.compiler_simulate_id = "@CMAKE_C_SIMULATE_ID@"
28+
config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
2729

2830
import lit.llvm
2931
lit.llvm.initialize(lit_config, config)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
! This test checks lowering of OpenMP unroll directive
2+
3+
! RUN: %flang %flags %openmp_flags -fopenmp-version=51 %s -o %t.exe
4+
! RUN: %t.exe | FileCheck %s --match-full-lines
5+
6+
7+
program unroll_heuristic
8+
integer :: i
9+
print *, 'do'
10+
11+
!$OMP UNROLL
12+
do i=7, 18, 3
13+
print '("i=", I0)', i
14+
end do
15+
!$OMP END UNROLL
16+
17+
print *, 'done'
18+
end program
19+
20+
21+
! CHECK: do
22+
! CHECK-NEXT: i=7
23+
! CHECK-NEXT: i=10
24+
! CHECK-NEXT: i=13
25+
! CHECK-NEXT: i=16
26+
! CHECK-NEXT: done

0 commit comments

Comments
 (0)