[testsuite] Add scan-ltrans-tree-dump
[gcc.git] / libgomp / testsuite / lib / libgomp.exp
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.
3
4 proc load_gcc_lib { filename } {
5 global srcdir loaded_libs
6
7 load_file $srcdir/../../gcc/testsuite/lib/$filename
8 set loaded_libs($filename) ""
9 }
10
11 load_lib dg.exp
12
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.
16
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 scantree.exp
32 load_gcc_lib scanltranstree.exp
33 load_gcc_lib scanipa.exp
34 load_gcc_lib scanwpaipa.exp
35 load_gcc_lib timeout-dg.exp
36 load_gcc_lib torture-options.exp
37 load_gcc_lib fortran-modules.exp
38
39 # Try to load a test support file, built during libgomp configuration.
40 load_file libgomp-test-support.exp
41
42 # Populate offload_targets_s (offloading targets separated by a space), and
43 # offload_targets_s_openacc (the same, but with OpenACC names; OpenACC spells
44 # some of them a little differently).
45 set offload_targets_s [split $offload_targets ","]
46 set offload_targets_s_openacc {}
47 foreach offload_target_openacc $offload_targets_s {
48 # Translate to OpenACC names, or skip if not yet supported.
49 switch $offload_target_openacc {
50 intelmic {
51 continue
52 }
53 nvptx {
54 set offload_target_openacc "nvidia"
55 }
56 hsa {
57 continue
58 }
59 }
60 lappend offload_targets_s_openacc "$offload_target_openacc"
61 }
62 lappend offload_targets_s_openacc "host"
63
64 set dg-do-what-default run
65
66 #
67 # GCC_UNDER_TEST is the compiler under test.
68 #
69
70 set libgomp_compile_options ""
71
72 #
73 # libgomp_init
74 #
75
76 if [info exists TOOL_OPTIONS] {
77 set multilibs [get_multilibs $TOOL_OPTIONS]
78 } else {
79 set multilibs [get_multilibs]
80 }
81
82 proc libgomp_init { args } {
83 global srcdir blddir objdir tool_root_dir
84 global libgomp_initialized
85 global tmpdir
86 global blddir
87 global gluefile wrap_flags
88 global ALWAYS_CFLAGS
89 global CFLAGS
90 global TOOL_EXECUTABLE TOOL_OPTIONS
91 global GCC_UNDER_TEST
92 global TESTING_IN_BUILD_TREE
93 global target_triplet
94 global always_ld_library_path
95
96 set blddir [lookfor_file [get_multilibs] libgomp]
97
98 # We set LC_ALL and LANG to C so that we get the same error
99 # messages as expected.
100 setenv LC_ALL C
101 setenv LANG C
102
103 # Many hosts now default to a non-ASCII C locale, however, so
104 # they can set a charset encoding here if they need.
105 if { [ishost "*-*-cygwin*"] } {
106 setenv LC_ALL C.ASCII
107 setenv LANG C.ASCII
108 }
109
110 if ![info exists GCC_UNDER_TEST] then {
111 if [info exists TOOL_EXECUTABLE] {
112 set GCC_UNDER_TEST $TOOL_EXECUTABLE
113 } else {
114 set GCC_UNDER_TEST "[find_gcc]"
115 }
116 }
117
118 if ![info exists tmpdir] {
119 set tmpdir "/tmp"
120 }
121
122 if [info exists gluefile] {
123 unset gluefile
124 }
125
126 if {![info exists CFLAGS]} {
127 set CFLAGS ""
128 }
129
130 # Locate libgcc.a so we don't need to account for different values of
131 # SHLIB_EXT on different platforms
132 set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
133 if {$gccdir != ""} {
134 set gccdir [file dirname $gccdir]
135 }
136
137 # Compute what needs to be put into LD_LIBRARY_PATH
138 set always_ld_library_path ".:${blddir}/.libs"
139
140 # Add liboffloadmic build directory in LD_LIBRARY_PATH to support
141 # non-fallback testing for Intel MIC targets
142 global offload_targets
143 if { [string match "*,intelmic,*" ",$offload_targets,"] } {
144 append always_ld_library_path ":${blddir}/../liboffloadmic/.libs"
145 append always_ld_library_path ":${blddir}/../liboffloadmic/plugin/.libs"
146 # libstdc++ is required by liboffloadmic
147 append always_ld_library_path ":${blddir}/../libstdc++-v3/src/.libs"
148 # libgcc_s is required by libstdc++
149 append always_ld_library_path ":${blddir}/../libgcc"
150 }
151
152 global offload_additional_lib_paths
153 if { $offload_additional_lib_paths != "" } {
154 append always_ld_library_path "${offload_additional_lib_paths}"
155 }
156
157 # Compute what needs to be added to the existing LD_LIBRARY_PATH.
158 if {$gccdir != ""} {
159 # Add AIX pthread directory first.
160 if { [llength [glob -nocomplain ${gccdir}/pthread/libgcc_s*.a]] >= 1 } {
161 append always_ld_library_path ":${gccdir}/pthread"
162 }
163 append always_ld_library_path ":${gccdir}"
164 set compiler [lindex $GCC_UNDER_TEST 0]
165
166 if { [is_remote host] == 0 && [which $compiler] != 0 } {
167 foreach i "[exec $compiler --print-multi-lib]" {
168 set mldir ""
169 regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir
170 set mldir [string trimright $mldir "\;@"]
171 if { "$mldir" == "." } {
172 continue
173 }
174 if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
175 append always_ld_library_path ":${gccdir}/${mldir}"
176 }
177 }
178 }
179 }
180
181 set ALWAYS_CFLAGS ""
182 if { $blddir != "" } {
183 lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/"
184 # targets that use libgomp.a%s in their specs need a -B option
185 # for uninstalled testing.
186 lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/.libs"
187 lappend ALWAYS_CFLAGS "additional_flags=-I${blddir}"
188 lappend ALWAYS_CFLAGS "ldflags=-L${blddir}/.libs"
189 # The top-level include directory, for gomp-constants.h.
190 lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/../../include"
191 }
192 lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/.."
193
194 # For build-tree testing, also consider the library paths used for builing.
195 # For installed testing, we assume all that to be provided in the sysroot.
196 if { $blddir != "" } {
197 global cuda_driver_include
198 global cuda_driver_lib
199 if { $cuda_driver_include != "" } {
200 # Stop gfortran from freaking out:
201 # Warning: Nonexistent include directory "[...]"
202 if {[file exists $cuda_driver_include]} {
203 lappend ALWAYS_CFLAGS "additional_flags=-I$cuda_driver_include"
204 }
205 }
206 if { $cuda_driver_lib != "" } {
207 lappend ALWAYS_CFLAGS "additional_flags=-L$cuda_driver_lib"
208 append always_ld_library_path ":$cuda_driver_lib"
209 }
210 global hsa_runtime_lib
211 if { $hsa_runtime_lib != "" } {
212 append always_ld_library_path ":$hsa_runtime_lib"
213 }
214 }
215
216 # We use atomic operations in the testcases to validate results.
217 if { ([istarget i?86-*-*] || [istarget x86_64-*-*])
218 && [check_effective_target_ia32] } {
219 lappend ALWAYS_CFLAGS "additional_flags=-march=i486"
220 }
221
222 if [istarget *-*-darwin*] {
223 lappend ALWAYS_CFLAGS "additional_flags=-shared-libgcc"
224 }
225
226 if [istarget sparc*-*-*] {
227 lappend ALWAYS_CFLAGS "additional_flags=-mcpu=v9"
228 }
229
230 if [info exists TOOL_OPTIONS] {
231 lappend ALWAYS_CFLAGS "additional_flags=$TOOL_OPTIONS"
232 }
233
234 # Make sure that lines are not wrapped. That can confuse the
235 # error-message parsing machinery.
236 lappend ALWAYS_CFLAGS "additional_flags=-fmessage-length=0"
237
238 # Disable caret
239 lappend ALWAYS_CFLAGS "additional_flags=-fno-diagnostics-show-caret"
240
241 # Disable HSA warnings by default.
242 lappend ALWAYS_CFLAGS "additional_flags=-Wno-hsa"
243
244 # Disable color diagnostics
245 lappend ALWAYS_CFLAGS "additional_flags=-fdiagnostics-color=never"
246
247 # Used for support non-fallback offloading.
248 # Help GCC to find target mkoffload.
249 global offload_additional_options
250 if { $offload_additional_options != "" } {
251 lappend ALWAYS_CFLAGS "additional_flags=${offload_additional_options}"
252 }
253 }
254
255 #
256 # libgomp_target_compile -- compile a source file
257 #
258
259 proc libgomp_target_compile { source dest type options } {
260 global blddir
261 global libgomp_compile_options
262 global gluefile wrap_flags
263 global ALWAYS_CFLAGS
264 global GCC_UNDER_TEST
265 global lang_test_file
266 global lang_library_path
267 global lang_link_flags
268 global lang_include_flags
269 global lang_source_re
270
271 if { [info exists lang_test_file] } {
272 if { $blddir != "" } {
273 # Some targets use libgfortran.a%s in their specs, so they need
274 # a -B option for uninstalled testing.
275 lappend options "additional_flags=-B${blddir}/${lang_library_path}"
276 lappend options "ldflags=-L${blddir}/${lang_library_path}"
277 }
278 lappend options "ldflags=${lang_link_flags}"
279 if { [info exists lang_include_flags] \
280 && [regexp ${lang_source_re} ${source}] } {
281 lappend options "additional_flags=${lang_include_flags}"
282 }
283 }
284
285 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
286 lappend options "libs=${gluefile}"
287 lappend options "ldflags=${wrap_flags}"
288 }
289
290 lappend options "additional_flags=[libio_include_flags]"
291 lappend options "timeout=[timeout_value]"
292 lappend options "compiler=$GCC_UNDER_TEST"
293
294 set options [concat $libgomp_compile_options $options]
295
296 if [info exists ALWAYS_CFLAGS] {
297 set options [concat "$ALWAYS_CFLAGS" $options]
298 }
299
300 set options [dg-additional-files-options $options $source]
301
302 set result [target_compile $source $dest $type $options]
303
304 return $result
305 }
306
307 proc libgomp_option_help { } {
308 send_user " --additional_options,OPTIONS\t\tUse OPTIONS to compile the testcase files. OPTIONS should be comma-separated.\n"
309 }
310
311 proc libgomp_option_proc { option } {
312 if [regexp "^--additional_options," $option] {
313 global libgomp_compile_options
314 regsub "--additional_options," $option "" option
315 foreach x [split $option ","] {
316 lappend libgomp_compile_options "additional_flags=$x"
317 }
318 return 1
319 } else {
320 return 0
321 }
322 }
323
324 # Return 1 if offload device is available.
325 proc check_effective_target_offload_device { } {
326 return [check_runtime_nocache offload_device_available_ {
327 #include <omp.h>
328 int main ()
329 {
330 int a;
331 #pragma omp target map(from: a)
332 a = omp_is_initial_device ();
333 return a;
334 }
335 } ]
336 }
337
338 # Return 1 if offload device is available and it has non-shared address space.
339 proc check_effective_target_offload_device_nonshared_as { } {
340 return [check_runtime_nocache offload_device_nonshared_as {
341 int main ()
342 {
343 int a = 8;
344 #pragma omp target map(to: a)
345 a++;
346 return a != 8;
347 }
348 } ]
349 }
350
351 # Return 1 if offload device is available and it has shared address space.
352 proc check_effective_target_offload_device_shared_as { } {
353 return [check_runtime_nocache offload_device_shared_as {
354 int main ()
355 {
356 int x = 10;
357 #pragma omp target map(to: x)
358 x++;
359 return x == 10;
360 }
361 } ]
362 }
363
364 # Return 1 if configured for nvptx offloading.
365
366 proc check_effective_target_openacc_nvidia_accel_configured { } {
367 global offload_targets
368 if { ![string match "*,nvptx,*" ",$offload_targets,"] } {
369 return 0
370 }
371 # PR libgomp/65099: Currently, we only support offloading in 64-bit
372 # configurations.
373 return [is-effective-target lp64]
374 }
375
376 # Return 1 if at least one nvidia board is present.
377
378 proc check_effective_target_openacc_nvidia_accel_present { } {
379 return [check_runtime openacc_nvidia_accel_present {
380 #include <openacc.h>
381 int main () {
382 return !(acc_get_num_devices (acc_device_nvidia) > 0);
383 }
384 } "" ]
385 }
386
387 # Return 1 if at least one nvidia board is present, and the nvidia device type
388 # is selected by default by means of setting the environment variable
389 # ACC_DEVICE_TYPE.
390
391 proc check_effective_target_openacc_nvidia_accel_selected { } {
392 if { ![check_effective_target_openacc_nvidia_accel_present] } {
393 return 0;
394 }
395 global offload_target_openacc
396 if { $offload_target_openacc == "nvidia" } {
397 return 1;
398 }
399 return 0;
400 }
401
402 # Return 1 if the host target is selected for offloaded
403
404 proc check_effective_target_openacc_host_selected { } {
405 global offload_target_openacc
406 if { $offload_target_openacc == "host" } {
407 return 1;
408 }
409 return 0;
410 }
411
412 # Return 1 if the selected OMP device is actually a HSA device
413
414 proc check_effective_target_hsa_offloading_selected_nocache {} {
415 global tool
416
417 set src {
418 int main () {
419 int v = 1;
420 #pragma omp target map(from:v)
421 v = 0;
422 return v;
423 }
424 }
425
426 set result [check_compile hsa_offloading_src executable $src]
427 set lines [lindex $result 0]
428 set exe [lindex $result 1]
429
430 set ok 0
431 if { [string match "" $lines] } {
432 # No error messages, let us switch on HSA debugging output and run it
433 set prev_HSA_DEBUG [getenv HSA_DEBUG]
434 setenv HSA_DEBUG "1"
435 set result [remote_load target "./$exe"]
436 if { [string match "" $prev_HSA_DEBUG] } {
437 unsetenv HSA_DEBUG
438 } else {
439 setenv HSA_DEBUG $prev_HSA_DEBUG
440 }
441 set status [lindex $result 0]
442 if { $status != "pass" } {
443 remote_file build delete $exe
444 verbose "HSA availability test failed"
445 return 0
446 }
447 set output [lindex $result 1]
448 if { [string match "*HSA debug: Going to dispatch kernel*" $output] } {
449 verbose "HSA availability detected"
450 set ok 1
451 }
452 }
453 remote_file build delete $exe
454 return $ok
455 }
456
457 # Return 1 if the selected OMP device is actually a HSA device and
458 # cache the result
459
460 proc check_effective_target_hsa_offloading_selected {} {
461 return [check_cached_effective_target hsa_offloading_selected {
462 check_effective_target_hsa_offloading_selected_nocache
463 }]
464 }