1 # Damn dejagnu for not having proper library search paths for load_lib.
2 # We have to explicitly load everything that gcc-dg.exp wants to load.
4 proc load_gcc_lib { filename } {
5 global srcdir loaded_libs
7 load_file $srcdir/../../gcc/testsuite/lib/$filename
8 set loaded_libs($filename) ""
13 # Required to use gcc-dg.exp - however, the latter should NOT be
14 # loaded until ${tool}_target_compile is defined since it uses that
15 # to determine default LTO options.
17 load_gcc_lib multiline.exp
18 load_gcc_lib prune.exp
19 load_gcc_lib target-libpath.exp
20 load_gcc_lib wrapper.exp
21 load_gcc_lib target-supports.exp
22 load_gcc_lib target-utils.exp
23 load_gcc_lib gcc-defs.exp
24 load_gcc_lib timeout.exp
25 load_gcc_lib file-format.exp
26 load_gcc_lib target-supports-dg.exp
27 load_gcc_lib scanasm.exp
28 load_gcc_lib scandump.exp
29 load_gcc_lib scanlang.exp
30 load_gcc_lib scanrtl.exp
31 load_gcc_lib scansarif.exp
32 load_gcc_lib scantree.exp
33 load_gcc_lib scanltranstree.exp
34 load_gcc_lib scanoffload.exp
35 load_gcc_lib scanoffloadtree.exp
36 load_gcc_lib scanoffloadrtl.exp
37 load_gcc_lib scanipa.exp
38 load_gcc_lib scanwpaipa.exp
39 load_gcc_lib timeout-dg.exp
40 load_gcc_lib torture-options.exp
41 load_gcc_lib fortran-modules.exp
43 # Try to load a test support file, built during libgomp configuration.
44 load_file libgomp-test-support.exp
46 set dg-do-what-default run
49 # GCC_UNDER_TEST is the compiler under test.
52 set libgomp_compile_options ""
58 if [info exists TOOL_OPTIONS] {
59 set multilibs [get_multilibs $TOOL_OPTIONS]
61 set multilibs [get_multilibs]
64 proc libgomp_init { args } {
65 global srcdir blddir objdir tool_root_dir
66 global libgomp_initialized
69 global gluefile wrap_flags
72 global TOOL_EXECUTABLE TOOL_OPTIONS
74 global TESTING_IN_BUILD_TREE
76 global always_ld_library_path
78 set blddir [lookfor_file [get_multilibs] libgomp]
80 # We set LC_ALL and LANG to C so that we get the same error
81 # messages as expected.
85 # Many hosts now default to a non-ASCII C locale, however, so
86 # they can set a charset encoding here if they need.
87 if { [ishost "*-*-cygwin*"] } {
92 if ![info exists GCC_UNDER_TEST] then {
93 if [info exists TOOL_EXECUTABLE] {
94 set GCC_UNDER_TEST $TOOL_EXECUTABLE
96 set GCC_UNDER_TEST "[find_gcc]"
100 if ![info exists tmpdir] {
104 if [info exists gluefile] {
108 if {![info exists CFLAGS]} {
112 # Locate libgcc.a so we don't need to account for different values of
113 # SHLIB_EXT on different platforms
114 set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
116 set gccdir [file dirname $gccdir]
119 # Compute what needs to be put into LD_LIBRARY_PATH
120 set always_ld_library_path ".:${blddir}/.libs"
122 # Add liboffloadmic build directory in LD_LIBRARY_PATH to support
123 # Intel MIC offloading testing.
124 global offload_plugins
125 if { [string match "*,intelmic,*" ",$offload_plugins,"] } {
126 append always_ld_library_path ":${blddir}/../liboffloadmic/.libs"
127 append always_ld_library_path ":${blddir}/../liboffloadmic/plugin/.libs"
128 # libstdc++ is required by liboffloadmic
129 append always_ld_library_path ":${blddir}/../libstdc++-v3/src/.libs"
130 # libgcc_s is required by libstdc++
131 append always_ld_library_path ":${blddir}/../libgcc"
134 global offload_additional_lib_paths
135 if { $offload_additional_lib_paths != "" } {
136 append always_ld_library_path "${offload_additional_lib_paths}"
139 # Compute what needs to be added to the existing LD_LIBRARY_PATH.
141 # Add AIX pthread directory first.
142 if { [llength [glob -nocomplain ${gccdir}/pthread/libgcc_s*.a]] >= 1 } {
143 append always_ld_library_path ":${gccdir}/pthread"
145 append always_ld_library_path ":${gccdir}"
146 set compiler [lindex $GCC_UNDER_TEST 0]
148 if { [is_remote host] == 0 && [which $compiler] != 0 } {
149 foreach i "[exec $compiler --print-multi-lib]" {
151 regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir
152 set mldir [string trimright $mldir "\;@"]
153 if { "$mldir" == "." } {
156 if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
157 append always_ld_library_path ":${gccdir}/${mldir}"
164 if { $blddir != "" } {
165 lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/"
166 # targets that use libgomp.a%s in their specs need a -B option
167 # for uninstalled testing.
168 lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/.libs"
169 lappend ALWAYS_CFLAGS "additional_flags=-I${blddir}"
170 lappend ALWAYS_CFLAGS "ldflags=-L${blddir}/.libs"
172 # The top-level include directory, for gomp-constants.h.
173 lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/../../include"
174 lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/.."
176 # For build-tree testing, also consider the library paths used for builing.
177 # For installed testing, we assume all that to be provided in the sysroot.
178 if { $blddir != "" } {
179 # The `-fopenacc' and `-fopenmp' options imply `-pthread', and
180 # that implies `-latomic' on some hosts, so wire in libatomic
182 if [ishost "riscv*-*-linux*"] {
183 set shlib_ext [get_shlib_extension]
184 set atomic_library_path "${blddir}/../libatomic/.libs"
185 if { [file exists "${atomic_library_path}/libatomic.a"]
187 "${atomic_library_path}/libatomic.${shlib_ext}"] } {
188 lappend ALWAYS_CFLAGS \
189 "additional_flags=-L${atomic_library_path}"
190 append always_ld_library_path ":${atomic_library_path}"
195 # We use atomic operations in the testcases to validate results.
196 if { ([istarget i?86-*-*] || [istarget x86_64-*-*])
197 && [check_effective_target_ia32]
198 && ![check_effective_target_cas_char] } {
199 lappend ALWAYS_CFLAGS "additional_flags=-march=i486"
202 if [istarget *-*-darwin*] {
203 lappend ALWAYS_CFLAGS "additional_flags=-shared-libgcc"
206 if [istarget sparc*-*-*] {
207 lappend ALWAYS_CFLAGS "additional_flags=-mcpu=v9"
210 if [info exists TOOL_OPTIONS] {
211 lappend ALWAYS_CFLAGS "additional_flags=$TOOL_OPTIONS"
214 # Make sure that lines are not wrapped. That can confuse the
215 # error-message parsing machinery.
216 lappend ALWAYS_CFLAGS "additional_flags=-fmessage-length=0"
219 lappend ALWAYS_CFLAGS "additional_flags=-fno-diagnostics-show-caret"
221 # Disable color diagnostics
222 lappend ALWAYS_CFLAGS "additional_flags=-fdiagnostics-color=never"
224 # Help GCC to find offload compilers' 'mkoffload'.
225 global offload_additional_options
226 if { $offload_additional_options != "" } {
227 lappend ALWAYS_CFLAGS "additional_flags=${offload_additional_options}"
230 # Tell warning from error diagnostics. This fits for C, C++, and Fortran.
231 global gcc_warning_prefix
232 set gcc_warning_prefix "\[Ww\]arning:"
233 global gcc_error_prefix
234 set gcc_error_prefix "(\[Ff\]atal )?\[Ee\]rror:"
238 # libgomp_target_compile -- compile a source file
241 proc libgomp_target_compile { source dest type options } {
243 global libgomp_compile_options
244 global gluefile wrap_flags
246 global GCC_UNDER_TEST
247 global lang_test_file
248 global lang_library_path
249 global lang_link_flags
250 global lang_include_flags
251 global lang_source_re
253 if { [info exists lang_test_file] } {
254 if { $blddir != "" } {
255 # Some targets use libgfortran.a%s in their specs, so they need
256 # a -B option for uninstalled testing.
257 lappend options "additional_flags=-B${blddir}/${lang_library_path}"
258 lappend options "ldflags=-L${blddir}/${lang_library_path}"
260 lappend options "ldflags=${lang_link_flags}"
261 if { [info exists lang_include_flags] \
262 && [regexp ${lang_source_re} ${source}] } {
263 lappend options "additional_flags=${lang_include_flags}"
267 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
268 lappend options "libs=${gluefile}"
269 lappend options "ldflags=${wrap_flags}"
272 lappend options "additional_flags=[libio_include_flags]"
273 lappend options "timeout=[timeout_value]"
274 lappend options "compiler=$GCC_UNDER_TEST"
276 set options [concat $libgomp_compile_options $options]
278 if [info exists ALWAYS_CFLAGS] {
279 set options [concat "$ALWAYS_CFLAGS" $options]
282 set options [dg-additional-files-options $options $source]
284 set result [target_compile $source $dest $type $options]
289 proc libgomp_option_help { } {
290 send_user " --additional_options,OPTIONS\t\tUse OPTIONS to compile the testcase files. OPTIONS should be comma-separated.\n"
293 proc libgomp_option_proc { option } {
294 if [regexp "^--additional_options," $option] {
295 global libgomp_compile_options
296 regsub "--additional_options," $option "" option
297 foreach x [split $option ","] {
298 lappend libgomp_compile_options "additional_flags=$x"
306 # Translate offload target to OpenACC device type. Return the empty string if
307 # not supported, and 'host' for offload target 'disable'.
308 proc offload_target_to_openacc_device_type { offload_target } {
309 switch -glob $offload_target {
323 error "Unknown offload target: $offload_target"
328 # Return 1 if compiling for the specified offload target
329 # Takes -foffload=... into account by checking OFFLOAD_TARGET_NAMES=
330 # in the -v compiler output.
331 proc libgomp_check_effective_target_offload_target { target_name } {
332 # Consider all actual options, including the flags passed to
333 # 'gcc-dg-runtest', or 'gfortran-dg-runtest' (see the 'libgomp.*/*.exp'
334 # files; in particular, '-foffload', 'libgomp.oacc-*/*.exp'), which don't
335 # get passed on to 'check_effective_target_*' functions. (Not caching the
336 # result due to that.)
337 set options [list "additional_flags=[concat "-v" [current_compiler_flags]]"]
338 # Instead of inspecting command-line options, look what the compiler driver
339 # decides. This is somewhat modelled after
340 # 'gcc/testsuite/lib/target-supports.exp:check_configured_with'.
341 set gcc_output [libgomp_target_compile "" "" "none" $options]
342 if [regexp "(?n)^OFFLOAD_TARGET_NAMES=(.*)" $gcc_output dummy gcc_offload_targets] {
343 verbose "compiling for offload targets: $gcc_offload_targets"
344 return [string match "*:$target_name*:*" ":$gcc_offload_targets:"]
347 verbose "not compiling for $target_name offload target"
351 # Return 1 if compiling for any offload target.
352 proc check_effective_target_offload_target_any { } {
353 return [libgomp_check_effective_target_offload_target ""]
356 # Return 1 if compiling for offload target nvptx.
357 proc check_effective_target_offload_target_nvptx { } {
358 return [libgomp_check_effective_target_offload_target "nvptx"]
361 # Return 1 if compiling for offload target amdgcn
362 proc check_effective_target_offload_target_amdgcn { } {
363 return [libgomp_check_effective_target_offload_target "amdgcn"]
366 # Return 1 if offload device is available.
367 proc check_effective_target_offload_device { } {
368 return [check_runtime_nocache offload_device_available_ {
373 #pragma omp target map(from: a)
374 a = omp_is_initial_device ();
380 # Return 1 if offload device is available and it has non-shared address space.
381 proc check_effective_target_offload_device_nonshared_as { } {
382 return [check_runtime_nocache offload_device_nonshared_as {
386 #pragma omp target map(to: a)
393 # Return 1 if offload device is available and it has shared address space.
394 proc check_effective_target_offload_device_shared_as { } {
395 return [check_runtime_nocache offload_device_shared_as {
399 #pragma omp target map(to: x)
406 # Return 1 if using nvptx offload device.
407 proc check_effective_target_offload_device_nvptx { } {
408 return [check_runtime_nocache offload_device_nvptx {
410 #include "testsuite/libgomp.c-c++-common/on_device_arch.h"
413 return !on_device_arch_nvptx ();
418 # Return 1 if using a GCN offload device.
419 proc check_effective_target_offload_device_gcn { } {
420 return [check_runtime_nocache offload_device_gcn {
422 #include "testsuite/libgomp.c-c++-common/on_device_arch.h"
425 return !on_device_arch_gcn ();
430 # Return 1 if at least one Nvidia GPU is accessible.
432 proc check_effective_target_openacc_nvidia_accel_present { } {
433 return [check_runtime openacc_nvidia_accel_present {
436 return !(acc_get_num_devices (acc_device_nvidia) > 0);
441 # Return 1 if at least one Nvidia GPU is accessible, and the OpenACC 'nvidia'
442 # device type is selected.
444 proc check_effective_target_openacc_nvidia_accel_selected { } {
445 if { ![check_effective_target_openacc_nvidia_accel_present] } {
448 global openacc_device_type
449 return [string match "nvidia" $openacc_device_type]
452 # Return 1 if using Intel MIC offload device.
453 proc check_effective_target_offload_device_intel_mic { } {
454 return [check_runtime_nocache offload_device_intel_mic {
455 #include "testsuite/libgomp.c-c++-common/on_device_arch.h"
458 return !on_device_arch_intel_mic ();
463 # Return 1 if any Intel MIC offload device is available.
464 proc check_effective_target_offload_device_any_intel_mic { } {
465 return [check_runtime_nocache offload_device_any_intel_mic {
466 #include "testsuite/libgomp.c-c++-common/on_device_arch.h"
469 return !any_device_arch_intel_mic ();
474 # Return 1 if the OpenACC 'host' device type is selected.
476 proc check_effective_target_openacc_host_selected { } {
477 global openacc_device_type
478 return [string match "host" $openacc_device_type]
481 # Return 1 if at least one AMD GPU is accessible.
483 proc check_effective_target_openacc_radeon_accel_present { } {
484 return [check_runtime openacc_radeon_accel_present {
487 return !(acc_get_num_devices (acc_device_radeon) > 0);
492 # Return 1 if at least one AMD GPU is accessible, and the OpenACC 'radeon'
493 # device type is selected.
495 proc check_effective_target_openacc_radeon_accel_selected { } {
496 if { ![check_effective_target_openacc_radeon_accel_present] } {
499 global openacc_device_type
500 return [string match "radeon" $openacc_device_type]
503 # Return 1 if cuda.h and -lcuda are available.
505 proc check_effective_target_openacc_cuda { } {
506 return [check_no_compiler_messages openacc_cuda executable {
510 CUresult r = cuDeviceGet (&dev, 0);
511 if (r != CUDA_SUCCESS)
517 # Return 1 if cublas_v2.h and -lcublas are available.
519 proc check_effective_target_openacc_cublas { } {
520 return [check_no_compiler_messages openacc_cublas executable {
522 #include <cublas_v2.h>
527 CUresult r = cuDeviceGet (&dev, 0);
528 if (r != CUDA_SUCCESS)
530 s = cublasCreate (&h);
531 if (s != CUBLAS_STATUS_SUCCESS)
534 } } "-lcuda -lcublas" ]
537 # Return 1 if cuda_runtime_api.h and -lcudart are available.
539 proc check_effective_target_openacc_cudart { } {
540 return [check_no_compiler_messages openacc_cudart executable {
542 #include <cuda_runtime_api.h>
547 CUresult r = cuDeviceGet (&dev, 0);
548 if (r != CUDA_SUCCESS)
550 e = cudaGetDevice (&devn);
551 if (e != cudaSuccess)
554 } } "-lcuda -lcudart" ]