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 scanoffloadipa.exp
36 load_gcc_lib scanoffloadtree.exp
37 load_gcc_lib scanoffloadrtl.exp
38 load_gcc_lib scanipa.exp
39 load_gcc_lib scanwpaipa.exp
40 load_gcc_lib timeout-dg.exp
41 load_gcc_lib torture-options.exp
42 load_gcc_lib fortran-modules.exp
44 # Try to load a test support file, built during libgomp configuration.
45 load_file libgomp-test-support.exp
47 set dg-do-what-default run
50 # GCC_UNDER_TEST is the compiler under test.
53 set libgomp_compile_options ""
59 if [info exists TOOL_OPTIONS] {
60 set multilibs [get_multilibs $TOOL_OPTIONS]
62 set multilibs [get_multilibs]
65 proc libgomp_init { args } {
66 global srcdir blddir objdir tool_root_dir
67 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 "."
122 global offload_additional_lib_paths
123 if { $offload_additional_lib_paths != "" } {
124 append always_ld_library_path "${offload_additional_lib_paths}"
127 # Compute what needs to be added to the existing LD_LIBRARY_PATH.
129 # Add AIX pthread directory first.
130 if { [llength [glob -nocomplain ${gccdir}/pthread/libgcc_s*.a]] >= 1 } {
131 append always_ld_library_path ":${gccdir}/pthread"
133 append always_ld_library_path ":${gccdir}"
134 set compiler [lindex $GCC_UNDER_TEST 0]
136 if { [is_remote host] == 0 && [which $compiler] != 0 } {
137 foreach i "[exec $compiler --print-multi-lib]" {
139 regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir
140 set mldir [string trimright $mldir "\;@"]
141 if { "$mldir" == "." } {
144 if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
145 append always_ld_library_path ":${gccdir}/${mldir}"
152 if { $blddir != "" } {
153 lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/"
154 # targets that use libgomp.a%s in their specs need a -B option
155 # for uninstalled testing.
156 lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/.libs"
157 lappend ALWAYS_CFLAGS "additional_flags=-I${blddir}"
158 lappend ALWAYS_CFLAGS "ldflags=-L${blddir}/.libs"
160 append always_ld_library_path ":${blddir}/.libs"
162 # The top-level include directory, for gomp-constants.h.
163 lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/../../include"
164 lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/.."
166 # For build-tree testing, also consider the library paths used for builing.
167 # For installed testing, we assume all that to be provided in the sysroot.
168 if { $blddir != "" } {
169 # The `-fopenacc' and `-fopenmp' options imply `-pthread', and
170 # that implies `-latomic' on some hosts, so wire in libatomic
172 if [ishost "riscv*-*-linux*"] {
173 set shlib_ext [get_shlib_extension]
174 set atomic_library_path "${blddir}/../libatomic/.libs"
175 if { [file exists "${atomic_library_path}/libatomic.a"]
177 "${atomic_library_path}/libatomic.${shlib_ext}"] } {
178 lappend ALWAYS_CFLAGS \
179 "additional_flags=-L${atomic_library_path}"
180 append always_ld_library_path ":${atomic_library_path}"
185 # We use atomic operations in the testcases to validate results.
186 if { ([istarget i?86-*-*] || [istarget x86_64-*-*])
187 && [check_effective_target_ia32]
188 && ![check_effective_target_cas_char] } {
189 lappend ALWAYS_CFLAGS "additional_flags=-march=i486"
192 if [istarget *-*-darwin*] {
193 lappend ALWAYS_CFLAGS "additional_flags=-shared-libgcc"
196 if [istarget sparc*-*-*] {
197 lappend ALWAYS_CFLAGS "additional_flags=-mcpu=v9"
200 if [info exists TOOL_OPTIONS] {
201 lappend ALWAYS_CFLAGS "additional_flags=$TOOL_OPTIONS"
204 # Make sure that lines are not wrapped. That can confuse the
205 # error-message parsing machinery.
206 lappend ALWAYS_CFLAGS "additional_flags=-fmessage-length=0"
209 lappend ALWAYS_CFLAGS "additional_flags=-fno-diagnostics-show-caret"
211 # Disable color diagnostics
212 lappend ALWAYS_CFLAGS "additional_flags=-fdiagnostics-color=never"
214 # Help GCC to find offload compilers' 'mkoffload'.
215 global offload_additional_options
216 if { $offload_additional_options != "" } {
217 lappend ALWAYS_CFLAGS "additional_flags=${offload_additional_options}"
220 # Tell warning from error diagnostics. This fits for C, C++, and Fortran.
221 global gcc_warning_prefix
222 set gcc_warning_prefix "\[Ww\]arning:"
223 global gcc_error_prefix
224 set gcc_error_prefix "(\[Ff\]atal )?\[Ee\]rror:"
228 # libgomp_target_compile -- compile a source file
231 proc libgomp_target_compile { source dest type options } {
233 global libgomp_compile_options
234 global gluefile wrap_flags
236 global GCC_UNDER_TEST
237 global lang_test_file
238 global lang_library_path
239 global lang_link_flags
240 global lang_include_flags
241 global lang_source_re
243 if { [info exists lang_test_file] } {
244 if { $blddir != "" } {
245 # Some targets use libgfortran.a%s in their specs, so they need
246 # a -B option for uninstalled testing.
247 lappend options "additional_flags=-B${blddir}/${lang_library_path}"
248 lappend options "ldflags=-L${blddir}/${lang_library_path}"
250 lappend options "ldflags=${lang_link_flags}"
251 if { [info exists lang_include_flags] \
252 && [regexp ${lang_source_re} ${source}] } {
253 lappend options "additional_flags=${lang_include_flags}"
257 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
258 lappend options "libs=${gluefile}"
259 lappend options "ldflags=${wrap_flags}"
262 lappend options "additional_flags=[libio_include_flags]"
263 lappend options "timeout=[timeout_value]"
264 lappend options "compiler=$GCC_UNDER_TEST"
266 set options [concat $libgomp_compile_options $options]
268 if [info exists ALWAYS_CFLAGS] {
269 set options [concat "$ALWAYS_CFLAGS" $options]
272 set options [dg-additional-files-options $options $source]
274 set result [target_compile $source $dest $type $options]
279 proc libgomp_option_help { } {
280 send_user " --additional_options,OPTIONS\t\tUse OPTIONS to compile the testcase files. OPTIONS should be comma-separated.\n"
283 proc libgomp_option_proc { option } {
284 if [regexp "^--additional_options," $option] {
285 global libgomp_compile_options
286 regsub "--additional_options," $option "" option
287 foreach x [split $option ","] {
288 lappend libgomp_compile_options "additional_flags=$x"
296 # Translate offload target to OpenACC device type. Return the empty string if
297 # not supported, and 'host' for offload target 'disable'.
298 proc offload_target_to_openacc_device_type { offload_target } {
299 switch -glob $offload_target {
310 error "Unknown offload target: $offload_target"
315 # Return 1 if compiling for the specified offload target
316 # Takes -foffload=... into account by checking OFFLOAD_TARGET_NAMES=
317 # in the -v compiler output.
318 proc libgomp_check_effective_target_offload_target { target_name } {
319 # Consider all actual options, including the flags passed to
320 # 'gcc-dg-runtest', or 'gfortran-dg-runtest' (see the 'libgomp.*/*.exp'
321 # files; in particular, '-foffload', 'libgomp.oacc-*/*.exp'), which don't
322 # get passed on to 'check_effective_target_*' functions. (Not caching the
323 # result due to that.)
324 set options [list "additional_flags=[concat "-v" [current_compiler_flags]]"]
325 # Instead of inspecting command-line options, look what the compiler driver
326 # decides. This is somewhat modelled after
327 # 'gcc/testsuite/lib/target-supports.exp:check_configured_with'.
328 set gcc_output [libgomp_target_compile "" "" "none" $options]
329 if [regexp "(?n)^OFFLOAD_TARGET_NAMES=(.*)" $gcc_output dummy gcc_offload_targets] {
330 verbose "compiling for offload targets: $gcc_offload_targets"
331 return [string match "*:$target_name*:*" ":$gcc_offload_targets:"]
334 verbose "not compiling for $target_name offload target"
338 # Return 1 if compiling for any offload target.
339 proc check_effective_target_offload_target_any { } {
340 return [libgomp_check_effective_target_offload_target ""]
343 # Return 1 if compiling for offload target nvptx.
344 proc check_effective_target_offload_target_nvptx { } {
345 return [libgomp_check_effective_target_offload_target "nvptx"]
348 # Return 1 if compiling for offload target amdgcn
349 proc check_effective_target_offload_target_amdgcn { } {
350 return [libgomp_check_effective_target_offload_target "amdgcn"]
353 # Return 1 if offload device is available.
354 proc check_effective_target_offload_device { } {
355 return [check_runtime_nocache offload_device_available_ {
360 #pragma omp target map(from: a)
361 a = omp_is_initial_device ();
367 # Return 1 if offload device is available and it has non-shared address space.
368 proc check_effective_target_offload_device_nonshared_as { } {
369 return [check_runtime_nocache offload_device_nonshared_as {
373 #pragma omp target map(to: a)
380 # Return 1 if offload device is available and it has shared address space.
381 proc check_effective_target_offload_device_shared_as { } {
382 return [check_runtime_nocache offload_device_shared_as {
386 #pragma omp target map(to: x)
393 # Return 1 if using nvptx offload device.
394 proc check_effective_target_offload_device_nvptx { } {
395 return [check_runtime_nocache offload_device_nvptx {
397 #include "testsuite/libgomp.c-c++-common/on_device_arch.h"
400 return !on_device_arch_nvptx ();
405 # Return 1 if using a GCN offload device.
406 proc check_effective_target_offload_device_gcn { } {
407 return [check_runtime_nocache offload_device_gcn {
409 #include "testsuite/libgomp.c-c++-common/on_device_arch.h"
412 return !on_device_arch_gcn ();
417 # Return 1 if at least one Nvidia GPU is accessible.
419 proc check_effective_target_openacc_nvidia_accel_present { } {
420 return [check_runtime openacc_nvidia_accel_present {
423 return !(acc_get_num_devices (acc_device_nvidia) > 0);
428 # Return 1 if at least one Nvidia GPU is accessible, and the OpenACC 'nvidia'
429 # device type is selected.
431 proc check_effective_target_openacc_nvidia_accel_selected { } {
432 if { ![check_effective_target_openacc_nvidia_accel_present] } {
435 global openacc_device_type
436 return [string match "nvidia" $openacc_device_type]
439 # Return 1 if the OpenACC 'host' device type is selected.
441 proc check_effective_target_openacc_host_selected { } {
442 global openacc_device_type
443 return [string match "host" $openacc_device_type]
446 # Return 1 if at least one AMD GPU is accessible.
448 proc check_effective_target_openacc_radeon_accel_present { } {
449 return [check_runtime openacc_radeon_accel_present {
452 return !(acc_get_num_devices (acc_device_radeon) > 0);
457 # Return 1 if at least one AMD GPU is accessible, and the OpenACC 'radeon'
458 # device type is selected.
460 proc check_effective_target_openacc_radeon_accel_selected { } {
461 if { ![check_effective_target_openacc_radeon_accel_present] } {
464 global openacc_device_type
465 return [string match "radeon" $openacc_device_type]
468 # Return 1 if cuda.h and -lcuda are available.
470 proc check_effective_target_openacc_cuda { } {
471 return [check_no_compiler_messages openacc_cuda executable {
475 CUresult r = cuDeviceGet (&dev, 0);
476 if (r != CUDA_SUCCESS)
482 # Return 1 if cublas_v2.h and -lcublas are available.
484 proc check_effective_target_openacc_cublas { } {
485 return [check_no_compiler_messages openacc_cublas executable {
487 #include <cublas_v2.h>
492 CUresult r = cuDeviceGet (&dev, 0);
493 if (r != CUDA_SUCCESS)
495 s = cublasCreate (&h);
496 if (s != CUBLAS_STATUS_SUCCESS)
499 } } "-lcuda -lcublas" ]
502 # Return 1 if cuda_runtime_api.h and -lcudart are available.
504 proc check_effective_target_openacc_cudart { } {
505 return [check_no_compiler_messages openacc_cudart executable {
507 #include <cuda_runtime_api.h>
512 CUresult r = cuDeviceGet (&dev, 0);
513 if (r != CUDA_SUCCESS)
515 e = cudaGetDevice (&devn);
516 if (e != cudaSuccess)
519 } } "-lcuda -lcudart" ]