Skip to content

Commit 6368ca2

Browse files
committed
Cleanup switching on/off tests
1 parent a07aaca commit 6368ca2

File tree

9 files changed

+107
-55
lines changed

9 files changed

+107
-55
lines changed

cmake/Modules/GetToolchainDirs.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ function (get_toolchain_library_subdir outvar)
4747
endfunction ()
4848

4949

50+
51+
52+
5053
# Corresponds to Flang's ToolChain::getDefaultIntrinsicModuleDir().
5154
function (get_toolchain_module_subdir outvar)
5255
set(outval "finclude")

flang/CMakeLists.txt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,28 @@ set(FLANG_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH
273273
"Path for binary subdirectory (defaults to '${CMAKE_INSTALL_BINDIR}')")
274274
mark_as_advanced(FLANG_TOOLS_INSTALL_DIR)
275275

276-
set(FLANG_INTRINSIC_MODULES_DIR "" CACHE PATH "Additional search path for modules; needed for running all tests if not building flang-rt in a bootstrapping build")
276+
#set(FLANG_INTRINSIC_MODULES_DIR "" CACHE PATH "Additional search path for modules; needed for running all tests if not building flang-rt in a bootstrapping build")
277+
#set(FLANG_TEST_FLANG_RT_Fortran_FLAGS "" CACHE STRING "Additional flags that makes Flang find the Flang-RT modules during testing; typically -fintrinsic-modules-path=<path>")
278+
#set(FLANG_TEST_OPENMP_Fortran_FLAGS "" CACHE STRING "Additional flags that makes Flang find the OpenMP modules during testing; typically -fintrinsic-modules-path=<path>")
279+
280+
set(FLANG_TEST_Fortran_FLAGS "" CACHE STRING "Additional Fortran flags for running tests, such as -fintrinsic-modules-path=<path>")
281+
282+
if ("flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
283+
set(FLANG_TEST_ENABLE_INTRINSICS_default ON)
284+
else ()
285+
set(FLANG_TEST_ENABLE_INTRINSICS_default OFF)
286+
endif ()
287+
option(FLANG_TEST_ENABLE_INTRINSICS "Enable tests that require intrinsic modules from Flang-RT" "${FLANG_TEST_ENABLE_INTRINSICS_default}")
288+
289+
290+
if ("openmp" IN_LIST LLVM_ENABLE_RUNTIMES AND FLANG_TEST_ENABLE_INTRINSICS)
291+
set(FLANG_TEST_ENABLE_OPENMP_default ON)
292+
else ()
293+
set(FLANG_TEST_ENABLE_OPENMP_default OFF)
294+
endif ()
295+
option(FLANG_TEST_ENABLE_OPENMP "Enable tests that require modules from OpenMP" "${FLANG_TEST_ENABLE_OPENMP_default}")
296+
297+
277298
set(FLANG_INCLUDE_DIR ${FLANG_BINARY_DIR}/include)
278299

279300
# TODO: Remove when libclangDriver is lifted out of Clang

flang/test/Driver/pp-fixed-form.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
!RUN: %flang -save-temps -### -ffree-form %S/Inputs/free-form-test.f90 2>&1 | FileCheck %s --check-prefix=FREE-FLAG
1010
FREE-FLAG: "-fc1" {{.*}} "-o" "free-form-test.i" {{.*}} "-x" "f95" "{{.*}}/free-form-test.f90"
11-
FREE-FLAG-NEXT: "-fc1" {{.*}} "-emit-llvm-bc" "-ffree-form"
11+
FREE-FLAG-NEXT: "-fc1" {{.*}} "-emit-llvm-bc" {{.*}} "-ffree-form"
1212
FREE-FLAG-NOT: "-ffixed-form"
1313
FREE-FLAG-SAME: "-x" "f95-cpp-input" "free-form-test.i"
1414

1515
!RUN: %flang -save-temps -### -ffixed-form %S/Inputs/fixed-form-test.f 2>&1 | FileCheck %s --check-prefix=FIXED-FLAG
1616
FIXED-FLAG: "-fc1" {{.*}} "-o" "fixed-form-test.i" {{.*}} "-x" "f95" "{{.*}}/fixed-form-test.f"
17-
FIXED-FLAG-NEXT: "-fc1" {{.*}} "-emit-llvm-bc" "-ffixed-form"
17+
FIXED-FLAG-NEXT: "-fc1" {{.*}} "-emit-llvm-bc" {{.*}} "-ffixed-form"
1818
FIXED-FLAG-NOT: "-ffixed-form"
1919
FIXED-FLAG-SAME: "-x" "f95-cpp-input" "fixed-form-test.i"

flang/test/lit.cfg.py

Lines changed: 63 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -145,65 +145,88 @@
145145
lit_config.fatal(f"Could not identify flang executable")
146146

147147

148-
def get_resource_module_intrinsic_dir():
148+
print(f"{config.flang_test_fortran_flags=}")
149+
print(f"{config.flang_test_enable_intrinsics=}")
150+
print(f"{config.flang_test_enable_openmp=}")
151+
152+
def get_resource_module_intrinsic_dir(modfile):
149153
# Determine the intrinsic module search path that is added by the driver. If
150154
# skipping the driver using -fc1, we need to append the path manually.
151-
for modfile in ["__fortran_builtins.mod", "omp_lib.mod"]:
152-
flang_intrinsics_dir = subprocess.check_output([flang_exe, f"-print-file-name={modfile}"], text=True).strip()
153-
flang_intrinsics_dir = os.path.dirname(flang_intrinsics_dir)
154-
if flang_intrinsics_dir:
155-
return flang_intrinsics_dir
156-
return None
155+
flang_intrinsics_dir = subprocess.check_output([flang_exe, *config.flang_test_fortran_flags, f"-print-file-name={modfile}"], text=True).strip()
156+
flang_intrinsics_dir = os.path.dirname(flang_intrinsics_dir)
157+
return flang_intrinsics_dir or None
158+
159+
157160

158161

159162
intrinsics_search_args = []
160-
if flang_intrinsics_dir := get_resource_module_intrinsic_dir():
161-
intrinsics_search_args += [f"-fintrinsic-modules-path={flang_intrinsics_dir}"]
162-
lit_config.note(f"using default module intrinsics: {flang_intrinsics_dir}")
163-
164-
165-
extra_intrinsics_search_args = []
166-
if config.flang_intrinsic_modules_dir:
167-
extra_intrinsics_search_args += [
168-
f"-fintrinsic-modules-path={config.flang_intrinsic_modules_dir}"
169-
]
170-
lit_config.note(
171-
f"using extra module intrinsics: {config.flang_intrinsic_modules_dir}"
172-
)
163+
extra_intrinsics_search_args = config.flang_test_fortran_flags + ["-I", f"{config.flang_obj_root}/../../runtimes/runtimes-bins/openmp/runtime/src"] # FIXME:
164+
165+
intrinsics_mod_path = get_resource_module_intrinsic_dir("__fortran_builtins.mod")
166+
openmp_mod_path = get_resource_module_intrinsic_dir("omp_lib.mod")
167+
openmp_inc_path = get_resource_module_intrinsic_dir("omp_lib.h")
168+
print(f"{intrinsics_mod_path=}")
169+
print(f"{openmp_mod_path=}")
170+
print(f"{openmp_inc_path=}")
171+
if mod_path := intrinsics_mod_path or openmp_mod_path:
172+
intrinsics_search_args += [f"-fintrinsic-modules-path={mod_path}"]
173+
lit_config.note(f"using flang default module intrinsics: {mod_path}")
174+
175+
176+
if extra_intrinsics_search_args:
177+
lit_config.note(f"using flang extra arguments: {' '.join(extra_intrinsics_search_args)}")
178+
179+
180+
181+
#if config.flang_intrinsic_modules_dir:
182+
# extra_intrinsics_search_args += [f"-fintrinsic-modules-path={config.flang_intrinsic_modules_dir}"]
183+
# lit_config.note(f"using extra module intrinsics: {config.flang_intrinsic_modules_dir}")
184+
173185

174186
# If intrinsic modules are not available, disable tests unless they are marked as 'module-independent'.
175187
config.available_features.add("module-independent")
176-
if config.have_flangrt_mod or config.flang_intrinsic_modules_dir:
188+
if config.flang_test_enable_intrinsics:
177189
config.available_features.add("flangrt-modules")
178190
else:
179-
lit_config.warning(f"Intrinsic modules not available: disabling most tests")
191+
lit_config.warning(f"Intrinsic modules not available and not in default path: disabling most tests")
180192
config.limit_to_features.add("module-independent")
181193

182194

195+
183196
# Determine if OpenMP runtime was built (enable OpenMP tests via REQUIRES in test file)
184197
openmp_flags_substitution = "-fopenmp"
185-
if 'flangrt-modules' not in config.available_features:
186-
# OpenMP modules depend on Flang-RT modules
187-
pass
188-
elif not config.have_openmp_rtl:
189-
lit_config.warning(f"OpenMP runtime library not available: OpenMP tests disabled")
190-
elif not config.openmp_module_dir:
191-
lit_config.warning(f"OpenMP modules not available: OpenMP tests disabled")
192-
else:
193-
# For the enabled OpenMP tests, add a substitution that is needed in the tests to find
194-
# the omp_lib.{h,mod} files, depending on whether the OpenMP runtime was built as a
195-
# project or runtime. If not in the compiler resources module directory like the other intrinsic modules, we must add it to the path.
198+
if config.flang_test_enable_openmp:
196199
config.available_features.add("openmp_runtime")
197-
extra_intrinsics_search_args += [
198-
f"-fintrinsic-modules-path={config.openmp_module_dir}"
199-
]
200-
lit_config.note(f"using OpenMP modules: {config.openmp_module_dir}")
200+
lit_config.note(f"OpenMP tests enabled")
201+
else:
202+
lit_config.warning(f"OpenMP tests disabled: FLANG_TEST_ENABLE_OPENMP option no set and omp_lib.mod not in resource path")
203+
204+
205+
206+
#if 'flangrt-modules' not in config.available_features:
207+
# # OpenMP modules depend on Flang-RT modules
208+
# pass
209+
#elif not config.have_openmp_rtl:
210+
# lit_config.warning(f"OpenMP runtime library not available: OpenMP tests disabled")
211+
#elif not config.openmp_module_dir:
212+
# lit_config.warning(f"OpenMP modules not available: OpenMP tests disabled")
213+
#elif openmp_mod_path:
214+
# # For the enabled OpenMP tests, add a substitution that is needed in the tests to find
215+
# # the omp_lib.{h,mod} files, depending on whether the OpenMP runtime was built as a
216+
# # project or runtime. If not in the compiler resources module directory like the other intrinsic modules, we must add it to the path.
217+
# config.available_features.add("openmp_runtime")
218+
# extra_intrinsics_search_args += [
219+
# f"-fintrinsic-modules-path={config.openmp_module_dir}"
220+
# ]
221+
# lit_config.note(f"using OpenMP modules: {config.openmp_module_dir}")
201222

202223

203224

204225

205226
# For each occurrence of a flang tool name, replace it with the full path to
206227
# the build directory holding that tool.
228+
flang_tool = FindTool("flang")
229+
#lit_config.note(f"using flang: {flang_tool.command}")
207230
tools = [
208231
ToolSubst(
209232
"bbc",
@@ -213,13 +236,13 @@ def get_resource_module_intrinsic_dir():
213236
),
214237
ToolSubst(
215238
"%flang",
216-
command=FindTool("flang"),
239+
command=flang_tool,
217240
extra_args=extra_intrinsics_search_args,
218241
unresolved="fatal",
219242
),
220243
ToolSubst(
221244
"%flang_fc1",
222-
command=FindTool("flang"),
245+
command=flang_tool,
223246
extra_args=["-fc1"] + intrinsics_search_args + extra_intrinsics_search_args,
224247
unresolved="fatal",
225248
),
@@ -231,6 +254,7 @@ def get_resource_module_intrinsic_dir():
231254
),
232255
]
233256

257+
234258
# Flang has several unimplemented features. TODO messages are used to mark
235259
# and fail if these features are exercised. Some TODOs exit with a non-zero
236260
# exit code, but others abort the execution in assert builds.

flang/test/lit.site.cfg.py.in

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@"
1313
config.errc_messages = "@LLVM_LIT_ERRC_MESSAGES@"
1414
config.flang_obj_root = "@FLANG_BINARY_DIR@"
1515
config.flang_tools_dir = lit_config.substitute("@FLANG_TOOLS_DIR@")
16-
config.flang_intrinsic_modules_dir = "@FLANG_INTRINSIC_MODULES_DIR@"
1716
config.flang_headers_dir = "@HEADER_BINARY_DIR@"
1817
config.flang_llvm_tools_dir = "@CMAKE_BINARY_DIR@/bin"
1918
config.flang_test_triple = "@FLANG_TEST_TARGET_TRIPLE@"
19+
config.flang_test_fortran_flags = "@FLANG_TEST_Fortran_FLAGS@".split()
20+
config.flang_test_enable_intrinsics = lit.util.pythonize_bool("@FLANG_TEST_ENABLE_INTRINSICS@")
21+
config.flang_test_enable_openmp = lit.util.pythonize_bool("@FLANG_TEST_ENABLE_OPENMP@")
2022
config.flang_examples = @LLVM_BUILD_EXAMPLES@
2123
config.python_executable = "@PYTHON_EXECUTABLE@"
2224
config.flang_standalone_build = @FLANG_STANDALONE_BUILD@
@@ -25,12 +27,6 @@ config.linked_bye_extension = @LLVM_BYE_LINK_INTO_TOOLS@
2527
config.osx_sysroot = path(r"@CMAKE_OSX_SYSROOT@")
2628
config.targets_to_build = "@TARGETS_TO_BUILD@"
2729
config.default_sysroot = "@DEFAULT_SYSROOT@"
28-
config.have_flangrt_mod = ("flang-rt" in "@LLVM_ENABLE_RUNTIMES@".lower().split(";"))
29-
config.have_openmp_rtl = ("@LLVM_TOOL_OPENMP_BUILD@" == "TRUE") or ("openmp" in "@LLVM_ENABLE_RUNTIMES@".lower().split(";"))
30-
if "openmp" in "@LLVM_ENABLE_RUNTIMES@".lower().split(";"):
31-
config.openmp_module_dir = "@CMAKE_BINARY_DIR@/runtimes/runtimes-bins/openmp/runtime/src"
32-
else:
33-
config.openmp_module_dir = None
3430
config.flang_runtime_f128_math_lib = "@FLANG_RUNTIME_F128_MATH_LIB@"
3531
config.have_ldbl_mant_dig_113 = "@HAVE_LDBL_MANT_DIG_113@"
3632

llvm/runtimes/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ function(runtime_default_target)
287287
CUDA CMAKE_CUDA # For runtimes that may look for the CUDA compiler and/or SDK (libc, offload, flang-rt)
288288
FFI # offload uses libffi
289289
FLANG_RUNTIME # Shared between Flang and Flang-RT
290+
LIBOMP
290291
${ARG_PREFIXES}
291292
EXTRA_TARGETS ${extra_targets}
292293
${test_targets}

openmp/runtime/src/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,8 @@ if(WIN32)
365365
endif()
366366
endif()
367367

368+
369+
368370
# Building the Fortran module files
369371
# One compilation step creates both omp_lib.mod and omp_lib_kinds.mod
370372
configure_file(${LIBOMP_INC_DIR}/omp_lib.h.var omp_lib.h @ONLY)
@@ -468,7 +470,7 @@ if(LLVM_RUNTIMES_BUILD AND RUNTIMES_FLANG_MODULES_ENABLED)
468470
if (FORTRAN_MODULE_DEPS)
469471
add_dependencies(libomp-mod ${FORTRAN_MODULE_DEPS})
470472
endif ()
471-
473+
472474
set (destination ${LIBOMP_HEADERS_INSTALL_PATH})
473475
if (NOT ${LIBOMP_MODULES_INSTALL_PATH} STREQUAL "")
474476
set (destination ${LIBOMP_MODULES_INSTALL_PATH})

openmp/tools/omptest/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ if((NOT ${LIBOMP_OMPT_SUPPORT}) OR (NOT ${LLVM_INCLUDE_TESTS}))
2121
endif()
2222

2323
include(CMakePackageConfigHelpers)
24+
find_package(ZLIB)
25+
message("ZLIB_FOUND: ${ZLIB_FOUND}")
2426

2527
include_directories(${LIBOMP_INCLUDE_DIR})
2628

runtimes/CMakeLists.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,10 @@ macro (flang_module_fortran_enable)
400400

401401
include(CheckLanguage)
402402
check_language(Fortran)
403-
403+
404404
if (CMAKE_Fortran_COMPILER)
405405
enable_language(Fortran)
406-
406+
407407
if (CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang" AND "flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
408408
# In a bootstrapping build, the intrinsic modules are not built yet.
409409
# Targets can depend on flang-rt-mod to ensure they are built before.
@@ -412,9 +412,12 @@ macro (flang_module_fortran_enable)
412412
message(STATUS "${LLVM_SUBPROJECT_TITLE}: Building Fortran modules for Flang bootstrapping itself")
413413
else ()
414414
# Check whether building modules works, avoid causing the entire build to fail because of Fortran.
415-
# The primary situation we want to support here is Flang or its intrinsic modules were built in a non-bootstrapping build separately.
415+
# The primary situation we want to support here is Flang or its intrinsic modules were built separately in a non-bootstrapping build.
416416
cmake_push_check_state(RESET)
417417
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
418+
#set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ")
419+
message("CMAKE_Fortran_FLAGS: ${CMAKE_Fortran_FLAGS}")
420+
message("CMAKE_REQUIRED_FLAGS: ${CMAKE_REQUIRED_FLAGS}")
418421
check_fortran_source_compiles("
419422
subroutine testroutine
420423
use iso_c_binding
@@ -431,9 +434,9 @@ macro (flang_module_fortran_enable)
431434
else ()
432435
message(STATUS "Not compiling Flang modules: Fortran not enabled")
433436
endif ()
434-
437+
435438
option(RUNTIMES_FLANG_MODULES_ENABLED "Build Fortran modules" "${RUNTIMES_FLANG_MODULES_ENABLED_default}")
436-
439+
437440
if (RUNTIMES_FLANG_MODULES_ENABLED)
438441
if (CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang")
439442
get_toolchain_module_subdir(toolchain_mod_subdir)

0 commit comments

Comments
 (0)