Skip to content

Commit 9e3d59e

Browse files
[openmp] Fix flang detection for offloading test
This patch fixes the flang detection in the openmp fortran offloading test. Reviewed By: jsjodin Differential Revision: https://reviews.llvm.org/D158546
1 parent a43bf8a commit 9e3d59e

File tree

6 files changed

+19
-25
lines changed

6 files changed

+19
-25
lines changed

openmp/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ if (OPENMP_STANDALONE_BUILD)
3636
"C compiler to use for testing OpenMP runtime libraries.")
3737
set(OPENMP_TEST_CXX_COMPILER ${CMAKE_CXX_COMPILER} CACHE STRING
3838
"C++ compiler to use for testing OpenMP runtime libraries.")
39+
set(OPENMP_TEST_Fortran_COMPILER ${CMAKE_Fortran_COMPILER} CACHE STRING
40+
"FORTRAN compiler to use for testing OpenMP runtime libraries.")
3941
set(OPENMP_LLVM_TOOLS_DIR "" CACHE PATH "Path to LLVM tools for testing.")
4042

4143
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
@@ -54,6 +56,11 @@ else()
5456
set(OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++.exe)
5557
endif()
5658

59+
find_program(OPENMP_TEST_Fortran_COMPILER flang-new PATHS LLVM_RUNTIME_OUTPUT_INTDIR)
60+
if (NOT OPENMP_TEST_Fortran_COMPILER)
61+
unset(OPENMP_TEST_Fortran_COMPILER CACHE)
62+
endif()
63+
5764
# If not standalone, set CMAKE_CXX_STANDARD but don't set the global cache value,
5865
# only set it locally for OpenMP.
5966
set(CMAKE_CXX_STANDARD 17)

openmp/README.rst

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ Options for all Libraries
119119
Compiler to use for testing. Defaults to the compiler that was also used for
120120
building.
121121

122+
**OPENMP_TEST_Fortran_COMPILER** = ``${CMAKE_Fortran_COMPILER}``
123+
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.
125+
122126
**OPENMP_LLVM_TOOLS_DIR** = ``/path/to/built/llvm/tools``
123127
Additional path to search for LLVM tools needed by tests.
124128

@@ -165,12 +169,6 @@ Options for ``libomp``
165169
**LIBOMP_FORTRAN_MODULES** = ``OFF|ON``
166170
Create the Fortran modules (requires Fortran compiler).
167171

168-
.. note::
169-
170-
If libomptarget is built in-tree with both flang and openmp in
171-
`LLVM_ENABLE_PROJECTS`, flang will be used for Fortran offloading
172-
tests.
173-
174172
macOS* Fat Libraries
175173
""""""""""""""""""""
176174
On macOS* machines, it is possible to build universal (or fat) libraries which

openmp/libomptarget/test/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,10 @@ foreach(CURRENT_TARGET IN LISTS SYSTEM_TARGETS)
3333
configure_file(lit.site.cfg.in ${CURRENT_TARGET}/lit.site.cfg @ONLY)
3434
endforeach()
3535

36-
if ("flang" IN_LIST LLVM_ENABLE_PROJECTS)
37-
SET(FORTRAN_TEST_DEPS flang-new)
38-
endif()
3936

4037
add_openmp_testsuite(check-libomptarget
4138
"Running libomptarget tests"
4239
${LIBOMPTARGET_LIT_TESTSUITES}
4340
EXCLUDE_FROM_CHECK_ALL
44-
DEPENDS omptarget omp ${LIBOMPTARGET_TESTED_PLUGINS} ${FORTRAN_TEST_DEPS}
41+
DEPENDS omptarget omp ${LIBOMPTARGET_TESTED_PLUGINS}
4542
ARGS ${LIBOMPTARGET_LIT_ARG_LIST})

openmp/libomptarget/test/lit.cfg

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
import os
55
import lit.formats
66

7-
from lit.llvm import llvm_config
8-
from lit.llvm.subst import ToolSubst
9-
from lit.llvm.subst import FindTool
10-
117
# Tell pylint that we know config and lit_config exist somewhere.
128
if 'PYLINT_IMPORT' in os.environ:
139
config = object()
@@ -70,8 +66,6 @@ config.test_source_root = os.path.dirname(__file__)
7066
# test_exec_root: The root object directory where output is placed
7167
config.test_exec_root = config.libomptarget_obj_root
7268

73-
tools = []
74-
7569
# test format
7670
config.test_format = lit.formats.ShTest()
7771

@@ -100,10 +94,6 @@ if config.has_libomptarget_ompt:
10094

10195
config.available_features.add(config.libomptarget_current_target)
10296

103-
if 'flang' in config.llvm_enabled_projects:
104-
config.available_features.add('flang')
105-
tools.append(ToolSubst('%flang', command=FindTool('flang-new'), unresolved='fatal'))
106-
10797
if config.libomptarget_has_libc:
10898
config.available_features.add('libc')
10999

@@ -320,11 +310,15 @@ for libomptarget_target in config.libomptarget_all_targets:
320310

321311
config.substitutions.append(("%clangxx", config.test_cxx_compiler))
322312
config.substitutions.append(("%clang", config.test_c_compiler))
313+
314+
if config.test_fortran_compiler:
315+
config.available_features.add('flang')
316+
config.substitutions.append(("%flang", config.test_fortran_compiler))
317+
323318
config.substitutions.append(("%openmp_flags", config.test_openmp_flags))
324319
if config.libomptarget_current_target.startswith('nvptx') and config.cuda_path:
325320
config.substitutions.append(("%cuda_flags", "--cuda-path=" + config.cuda_path))
326321
else:
327322
config.substitutions.append(("%cuda_flags", ""))
328323
config.substitutions.append(("%flags", config.test_flags))
329324
config.substitutions.append(("%not", config.libomptarget_not))
330-
llvm_config.add_tool_substitutions(tools, config.bin_llvm_tools_dir)

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
config.bin_llvm_tools_dir = "@CMAKE_BINARY_DIR@/bin"
44
config.test_c_compiler = "@OPENMP_TEST_C_COMPILER@"
55
config.test_cxx_compiler = "@OPENMP_TEST_CXX_COMPILER@"
6+
config.test_fortran_compiler="@OPENMP_TEST_Fortran_COMPILER@"
67
config.test_compiler_features = @OPENMP_TEST_COMPILER_FEATURES@
78
config.test_openmp_flags = "@OPENMP_TEST_OPENMP_FLAGS@"
89
config.test_extra_flags = "@OPENMP_TEST_FLAGS@"
@@ -21,11 +22,7 @@ config.libomptarget_filecheck = "@OPENMP_FILECHECK_EXECUTABLE@"
2122
config.libomptarget_not = "@OPENMP_NOT_EXECUTABLE@"
2223
config.libomptarget_debug = @LIBOMPTARGET_DEBUG@
2324
config.has_libomptarget_ompt = @LIBOMPTARGET_OMPT_SUPPORT@
24-
config.llvm_enabled_projects = "@LLVM_ENABLE_PROJECTS@".split(";")
2525
config.libomptarget_has_libc = @LIBOMPTARGET_GPU_LIBC_SUPPORT@
2626

27-
import lit.llvm
28-
lit.llvm.initialize(lit_config, config)
29-
3027
# Let the main config do the real work.
3128
lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg")

openmp/libomptarget/test/offloading/fortran/basic_array.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
subroutine increment_at(c_index, arr) bind(C, name="increment_at")
22
use ISO_C_BINDING
3+
!$omp declare target
34
integer (C_INT), dimension(*), intent(inout) :: arr
45
integer (C_INT), value :: c_index
56
arr(c_index+1) = arr(c_index+1) + 1

0 commit comments

Comments
 (0)