Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / gcc / testsuite / lib / target-supports.exp
blobc7b56f35425c8d336ab0431e30c9fec339c9f4b4
1 # Copyright (C) 1999, 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # gcc-patches@gcc.gnu.org
20 # This file defines procs for determining features supported by the target.
22 # Try to compile some code and return the messages printed by the compiler.
24 # BASENAME is a basename to use for temporary files.
25 # TYPE is the type of compilation to perform (see target_compile).
26 # CONTENTS gives the contents of the input file.
27 # The rest is optional:
28 # OPTIONS: additional compiler options to use.
29 proc get_compiler_messages {basename type contents args} {
30 global tool
32 if { [llength $args] > 0 } {
33 set options "additional_flags=[lindex $args 0]"
34 } else {
35 set options ""
38 set src ${basename}[pid].c
39 switch $type {
40 assembly { set output ${basename}[pid].s }
41 object { set output ${basename}[pid].o }
43 set f [open $src "w"]
44 puts $f $contents
45 close $f
46 set lines [${tool}_target_compile $src $output $type "$options"]
47 file delete $src
48 remote_file build delete $output
50 return $lines
53 proc current_target_name { } {
54 global target_info
55 if [info exists target_info(target,name)] {
56 set answer $target_info(target,name)
57 } else {
58 set answer ""
60 return $answer
63 ###############################
64 # proc check_weak_available { }
65 ###############################
67 # weak symbols are only supported in some configs/object formats
68 # this proc returns 1 if they're supported, 0 if they're not, or -1 if unsure
70 proc check_weak_available { } {
71 global target_triplet
72 global target_cpu
74 # All mips targets should support it
76 if { [ string first "mips" $target_cpu ] >= 0 } {
77 return 1
80 # All solaris2 targets should support it
82 if { [regexp ".*-solaris2.*" $target_triplet] } {
83 return 1
86 # DEC OSF/1/Digital UNIX/Tru64 UNIX supports it
88 if { [regexp "alpha.*osf.*" $target_triplet] } {
89 return 1
92 # Windows targets Cygwin and MingW32 support it
94 if { [regexp ".*mingw32|.*cygwin" $target_triplet] } {
95 return 1
98 # HP-UX 10.X doesn't support it
100 if { [regexp "hppa.*hpux10" $target_triplet] } {
101 return 0
104 # ELF and ECOFF support it. a.out does with gas/gld but may also with
105 # other linkers, so we should try it
107 set objformat [gcc_target_object_format]
109 switch $objformat {
110 elf { return 1 }
111 ecoff { return 1 }
112 a.out { return 1 }
113 mach-o { return 1 }
114 som { return 1 }
115 unknown { return -1 }
116 default { return 0 }
120 ###############################
121 # proc check_visibility_available { what_kind }
122 ###############################
124 # The visibility attribute is only support in some object formats
125 # This proc returns 1 if it is supported, 0 if not.
126 # The argument is the kind of visibility, default/protected/hidden/internal.
128 proc check_visibility_available { what_kind } {
129 global visibility_available_saved
130 global tool
131 global target_triplet
133 # On NetWare, support makes no sense.
134 if { [string match "*-*-netware*" $target_triplet] } {
135 return 0
138 if [string match "" $what_kind] { set what_kind "hidden" }
140 if { [info exists visibility_available_saved] } {
141 verbose "Saved result is <$visibility_available_saved>" 1
142 if { [ lsearch -exact $visibility_available_saved $what_kind ] != -1 } {
143 return 1
144 } elseif { [ lsearch -exact $visibility_available_saved "!$what_kind" ] != -1 } {
145 return 0
149 set lines [get_compiler_messages visibility object "
150 void f() __attribute__((visibility(\"$what_kind\")));
151 void f() {}
153 if [string match "" $lines] then {
154 set answer 1
155 lappend visibility_available_saved $what_kind
156 } else {
157 set answer 0
158 lappend visibility_available_saved "!$what_kind"
160 return $answer
163 ###############################
164 # proc check_alias_available { }
165 ###############################
167 # Determine if the target toolchain supports the alias attribute.
169 # Returns 2 if the target supports aliases. Returns 1 if the target
170 # only supports weak aliased. Returns 0 if the target does not
171 # support aliases at all. Returns -1 if support for aliases could not
172 # be determined.
174 proc check_alias_available { } {
175 global alias_available_saved
176 global tool
178 if [info exists alias_available_saved] {
179 verbose "check_alias_available returning saved $alias_available_saved" 2
180 } else {
181 set src alias[pid].c
182 set obj alias[pid].o
183 verbose "check_alias_available compiling testfile $src" 2
184 set f [open $src "w"]
185 # Compile a small test program. The definition of "g" is
186 # necessary to keep the Solaris assembler from complaining
187 # about the program.
188 puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
189 puts $f "void g() {} void f() __attribute__((alias(\"g\")));"
190 close $f
191 set lines [${tool}_target_compile $src $obj object ""]
192 file delete $src
193 remote_file build delete $obj
195 if [string match "" $lines] then {
196 # No error messages, everything is OK.
197 set alias_available_saved 2
198 } else {
199 if [regexp "alias definitions not supported" $lines] {
200 verbose "check_alias_available target does not support aliases" 2
202 set objformat [gcc_target_object_format]
204 if { $objformat == "elf" } {
205 verbose "check_alias_available but target uses ELF format, so it ought to" 2
206 set alias_available_saved -1
207 } else {
208 set alias_available_saved 0
210 } else {
211 if [regexp "only weak aliases are supported" $lines] {
212 verbose "check_alias_available target supports only weak aliases" 2
213 set alias_available_saved 1
214 } else {
215 set alias_available_saved -1
220 verbose "check_alias_available returning $alias_available_saved" 2
223 return $alias_available_saved
226 # Returns true if --gc-sections is supported on the target.
228 proc check_gc_sections_available { } {
229 global gc_sections_available_saved
230 global tool
232 if {![info exists gc_sections_available_saved]} {
233 # Some targets don't support gc-sections despite whatever's
234 # advertised by ld's options.
235 if { [istarget alpha*-*-*]
236 || [istarget ia64-*-*] } {
237 set gc_sections_available_saved 0
238 return 0
241 # Check if the ld used by gcc supports --gc-sections.
242 set gcc_spec [${tool}_target_compile "-dumpspecs" "" "none" ""]
243 regsub ".*\n\*linker:\[ \t\]*\n(\[^ \t\n\]*).*" "$gcc_spec" {\1} linker
244 set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=$linker" "" "none" ""] 0]
245 set ld_output [remote_exec host "$gcc_ld" "--help"]
246 if { [ string first "--gc-sections" $ld_output ] >= 0 } {
247 set gc_sections_available_saved 1
248 } else {
249 set gc_sections_available_saved 0
252 return $gc_sections_available_saved
255 # Return true if profiling is supported on the target.
257 proc check_profiling_available { test_what } {
258 global profiling_available_saved
260 verbose "Profiling argument is <$test_what>" 1
262 # These conditions depend on the argument so examine them before
263 # looking at the cache variable.
265 # Support for -p on solaris2 relies on mcrt1.o which comes with the
266 # vendor compiler. We cannot reliably predict the directory where the
267 # vendor compiler (and thus mcrt1.o) is installed so we can't
268 # necessarily find mcrt1.o even if we have it.
269 if { [istarget *-*-solaris2*] && [lindex $test_what 1] == "-p" } {
270 return 0
273 # Support for -p on irix relies on libprof1.a which doesn't appear to
274 # exist on any irix6 system currently posting testsuite results.
275 # Support for -pg on irix relies on gcrt1.o which doesn't exist yet.
276 # See: http://gcc.gnu.org/ml/gcc/2002-10/msg00169.html
277 if { [istarget mips*-*-irix*]
278 && ([lindex $test_what 1] == "-p" || [lindex $test_what 1] == "-pg") } {
279 return 0
282 # Now examine the cache variable.
283 if {![info exists profiling_available_saved]} {
284 # Some targets don't have any implementation of __bb_init_func or are
285 # missing other needed machinery.
286 if { [istarget mmix-*-*]
287 || [istarget arm*-*-eabi*]
288 || [istarget arm*-*-elf]
289 || [istarget arm*-*-symbianelf*]
290 || [istarget powerpc-*-eabi*]
291 || [istarget strongarm*-*-elf]
292 || [istarget xscale*-*-elf]
293 || [istarget cris-*-*]
294 || [istarget h8300-*-*]
295 || [istarget mips*-*-elf]
296 || [istarget xtensa-*-elf]
297 || [istarget *-*-windiss] } {
298 set profiling_available_saved 0
299 } else {
300 set profiling_available_saved 1
304 return $profiling_available_saved
307 # Return 1 if target has packed layout of structure members by
308 # default, 0 otherwise. Note that this is slightly different than
309 # whether the target has "natural alignment": both attributes may be
310 # false.
312 proc check_effective_target_default_packed { } {
313 global et_default_packed_saved
314 global et_default_packed_target_name
316 if { ![info exists et_default_packed_target_name] } {
317 set et_default_packed_target_name ""
320 # If the target has changed since we set the cached value, clear it.
321 set current_target [current_target_name]
322 if { $current_target != $et_default_packed_target_name } {
323 verbose "check_effective_target_default_packed: `$et_default_packed_target_name'" 2
324 set et_default_packed_target_name $current_target
325 if [info exists et_default_packed_saved] {
326 verbose "check_effective_target_default_packed: removing cached result" 2
327 unset et_default_packed_saved
331 if [info exists et_default_packed_saved] {
332 verbose "check_effective_target_default_packed: using cached result" 2
333 } else {
334 verbose "check_effective_target_default_packed: compiling source" 2
336 set et_default_packed_saved \
337 [string match "" [get_compiler_messages default_packed assembly {
338 struct x { char a; long b; } c;
339 int s[sizeof (c) == sizeof (char) + sizeof (long) ? 1 : -1];
340 } ]]
343 verbose "check_effective_target_default_packed: returning $et_default_packed_saved" 2
344 return $et_default_packed_saved
347 # Return 1 if target has PCC_BITFIELD_TYPE_MATTERS defined. See
348 # documentation, where the test also comes from.
350 proc check_effective_target_pcc_bitfield_type_matters { } {
351 global et_pcc_bitfield_type_matters_saved
352 global et_pcc_bitfield_type_matters_target_name
354 if { ![info exists et_pcc_bitfield_type_matters_target_name] } {
355 set et_pcc_bitfield_type_matters_target_name ""
358 # If the target has changed since we set the cached value, clear it.
359 set current_target [current_target_name]
360 if { $current_target != $et_pcc_bitfield_type_matters_target_name } {
361 verbose "check_effective_target_pcc_bitfield_type_matters: `$et_pcc_bitfield_type_matters_target_name'" 2
362 set et_pcc_bitfield_type_matters_target_name $current_target
363 if [info exists et_pcc_bitfield_type_matters_saved] {
364 verbose "check_effective_target_pcc_bitfield_type_matters: removing cached result" 2
365 unset et_pcc_bitfield_type_matters_saved
369 if [info exists et_pcc_bitfield_type_matters_saved] {
370 verbose "check_effective_target_pcc_bitfield_type_matters: using cached result" 2
371 } else {
372 verbose "check_effective_target_pcc_bitfield_type_matters: compiling source" 2
374 # PCC_BITFIELD_TYPE_MATTERS isn't just about unnamed or empty
375 # bitfields, but let's stick to the example code from the docs.
376 set et_pcc_bitfield_type_matters_saved \
377 [string match "" [get_compiler_messages pcc_bitfield_type_matters assembly {
378 struct foo1 { char x; char :0; char y; };
379 struct foo2 { char x; int :0; char y; };
380 int s[sizeof (struct foo1) != sizeof (struct foo2) ? 1 : -1];
381 } ]]
383 verbose "check_effective_target_pcc_bitfield_type_matters: returning $et_pcc_bitfield_type_matters_saved" 2
384 return $et_pcc_bitfield_type_matters_saved
387 # Return 1 if thread local storage (TLS) is supported, 0 otherwise.
389 # This won't change for different subtargets so cache the result.
391 proc check_effective_target_tls {} {
392 global et_tls_saved
394 if [info exists et_tls_saved] {
395 verbose "check_effective_target_tls: using cached result" 2
396 } else {
397 set et_tls_saved 1
399 set src tls[pid].c
400 set asm tls[pid].S
401 verbose "check_effective_target_tls: compiling testfile $src" 2
402 set f [open $src "w"]
403 # Compile a small test program.
404 puts $f "__thread int i;\n"
405 close $f
407 # Test for thread-local data supported by the platform.
408 set comp_output \
409 [target_compile $src $asm assembly ""]
410 file delete $src
411 if { [string match "*not supported*" $comp_output] } {
412 set et_tls_saved 0
414 remove-build-file $asm
416 verbose "check_effective_target_tls: returning $et_tls_saved" 2
417 return $et_tls_saved
420 # Return 1 if TLS executables can run correctly, 0 otherwise.
422 # This won't change for different subtargets so cache the result.
424 proc check_effective_target_tls_runtime {} {
425 global et_tls_runtime_saved
427 if [info exists et_tls_runtime_saved] {
428 verbose "check_effective_target_tls_runtime: using cached result" 2
429 } else {
430 set et_tls_runtime_saved 0
432 set src tls_runtime[pid].c
433 set exe tls_runtime[pid].x
434 verbose "check_effective_target_tls_runtime: compiling testfile $src" 2
435 set f [open $src "w"]
436 # Compile a small test program.
437 puts $f "__thread int thr = 0;\n"
438 puts $f "int main(void)\n {\n return thr;\n}"
439 close $f
441 set comp_output \
442 [target_compile $src $exe executable ""]
443 file delete $src
445 if [string match "" $comp_output] then {
446 # No error messages, everything is OK.
448 set result [remote_load target "./$exe" "" ""]
449 set status [lindex $result 0]
450 remote_file build delete $exe
452 verbose "check_effective_target_tls_runtime status is <$status>" 2
454 if { $status == "pass" } {
455 set et_tls_runtime_saved 1
458 verbose "check_effective_target_tls_runtime: returning $et_tls_runtime_saved" 2
462 return $et_tls_runtime_saved
465 # Return 1 if -fpic and -fPIC are supported, as in no warnings or errors
466 # emitted, 0 otherwise. Whether a shared library can actually be built is
467 # out of scope for this test.
469 # When the target name changes, replace the cached result.
471 proc check_effective_target_fpic { } {
472 global et_fpic_saved
473 global et_fpic_target_name
475 if { ![info exists et_fpic_target_name] } {
476 set et_fpic_target_name ""
479 # If the target has changed since we set the cached value, clear it.
480 set current_target [current_target_name]
481 if { $current_target != $et_fpic_target_name } {
482 verbose "check_effective_target_fpic: `$et_fpic_target_name'" 2
483 set et_fpic_target_name $current_target
484 if [info exists et_fpic_saved] {
485 verbose "check_effective_target_fpic: removing cached result" 2
486 unset et_fpic_saved
490 if [info exists et_fpic_saved] {
491 verbose "check_effective_target_fpic: using cached result" 2
492 } else {
493 verbose "check_effective_target_fpic: compiling source" 2
495 # Note that M68K has a multilib that supports -fpic but not
496 # -fPIC, so we need to check both. We test with a program that
497 # requires GOT references.
498 set et_fpic_saved [string match "" [get_compiler_messages fpic object {
499 extern int foo (void); extern int bar;
500 int baz (void) { return foo () + bar; }
501 } "-fpic"]]
503 if { $et_fpic_saved != 0 } {
504 set et_fpic_saved [string match "" [get_compiler_messages fpic object {
505 extern int foo (void); extern int bar;
506 int baz (void) { return foo () + bar; }
507 } "-fPIC"]]
510 verbose "check_effective_target_fpic: returning $et_fpic_saved" 2
511 return $et_fpic_saved
514 # Return true if iconv is supported on the target. In particular IBM1047.
516 proc check_iconv_available { test_what } {
517 global tool
518 global libiconv
520 set result ""
522 set src iconv[pid].c
523 set exe iconv[pid].x
524 verbose "check_iconv_available compiling testfile $src" 2
525 set f [open $src "w"]
526 # Compile a small test program.
527 puts $f "#include <iconv.h>\n"
528 puts $f "int main (void)\n {\n iconv_t cd; \n"
529 puts $f "cd = iconv_open (\"[lindex $test_what 1]\", \"UTF-8\");\n"
530 puts $f "if (cd == (iconv_t) -1)\n return 1;\n"
531 puts $f "return 0;\n}"
532 close $f
534 # If the tool configuration file has not set libiconv, try "-liconv"
535 if { ![info exists libiconv] } {
536 set libiconv "-liconv"
538 set lines [${tool}_target_compile $src $exe executable "libs=$libiconv" ]
539 file delete $src
541 if [string match "" $lines] then {
542 # No error messages, everything is OK.
544 set result [${tool}_load "./$exe" "" ""]
545 set status [lindex $result 0]
546 remote_file build delete $exe
548 verbose "check_iconv_available status is <$status>" 2
550 if { $status == "pass" } then {
551 return 1
555 return 0
558 # Return true if named sections are supported on this target.
559 # This proc does not cache results, because the answer may vary
560 # when cycling over subtarget options (e.g. irix o32/n32/n64) in
561 # the same test run.
562 proc check_named_sections_available { } {
563 verbose "check_named_sections_available: compiling source" 2
564 set answer [string match "" [get_compiler_messages named object {
565 int __attribute__ ((section("whatever"))) foo;
567 verbose "check_named_sections_available: returning $answer" 2
568 return $answer
571 # Return 1 if the target supports Fortran real kinds larger than real(8),
572 # 0 otherwise.
574 # When the target name changes, replace the cached result.
576 proc check_effective_target_fortran_large_real { } {
577 global et_fortran_large_real_saved
578 global et_fortran_large_real_target_name
579 global tool
581 if { ![info exists et_fortran_large_real_target_name] } {
582 set et_fortran_large_real_target_name ""
585 # If the target has changed since we set the cached value, clear it.
586 set current_target [current_target_name]
587 if { $current_target != $et_fortran_large_real_target_name } {
588 verbose "check_effective_target_fortran_large_real: `$et_fortran_large_real_target_name' `$current_target'" 2
589 set et_fortran_large_real_target_name $current_target
590 if [info exists et_fortran_large_real_saved] {
591 verbose "check_effective_target_fortran_large_real: removing cached result" 2
592 unset et_fortran_large_real_saved
596 if [info exists et_fortran_large_real_saved] {
597 verbose "check_effective_target_fortran_large_real returning saved $et_fortran_large_real_saved" 2
598 } else {
599 set et_fortran_large_real_saved 0
601 # Set up, compile, and execute a test program using large real
602 # kinds. Include the current process ID in the file names to
603 # prevent conflicts with invocations for multiple testsuites.
604 set src real[pid].f90
605 set exe real[pid].x
607 set f [open $src "w"]
608 puts $f "integer,parameter :: k = &"
609 puts $f " selected_real_kind (precision (0.0_8) + 1)"
610 puts $f "real(kind=k) :: x"
611 puts $f "x = cos (x);"
612 puts $f "end"
613 close $f
615 verbose "check_effective_target_fortran_large_real compiling testfile $src" 2
616 set lines [${tool}_target_compile $src $exe executable ""]
617 file delete $src
619 if [string match "" $lines] then {
620 # No error message, compilation succeeded.
621 set et_fortran_large_real_saved 1
625 return $et_fortran_large_real_saved
628 # Return 1 if the target supports Fortran integer kinds larger than
629 # integer(8), 0 otherwise.
631 # When the target name changes, replace the cached result.
633 proc check_effective_target_fortran_large_int { } {
634 global et_fortran_large_int_saved
635 global et_fortran_large_int_target_name
636 global tool
638 if { ![info exists et_fortran_large_int_target_name] } {
639 set et_fortran_large_int_target_name ""
642 # If the target has changed since we set the cached value, clear it.
643 set current_target [current_target_name]
644 if { $current_target != $et_fortran_large_int_target_name } {
645 verbose "check_effective_target_fortran_large_int: `$et_fortran_large_int_target_name' `$current_target'" 2
646 set et_fortran_large_int_target_name $current_target
647 if [info exists et_fortran_large_int_saved] {
648 verbose "check_effective_target_fortran_large_int: removing cached result" 2
649 unset et_fortran_large_int_saved
653 if [info exists et_fortran_large_int_saved] {
654 verbose "check_effective_target_fortran_large_int returning saved $et_fortran_large_int_saved" 2
655 } else {
656 set et_fortran_large_int_saved 0
658 # Set up, compile, and execute a test program using large integer
659 # kinds. Include the current process ID in the file names to
660 # prevent conflicts with invocations for multiple testsuites.
661 set src int[pid].f90
662 set exe int[pid].x
664 set f [open $src "w"]
665 puts $f "integer,parameter :: k = &"
666 puts $f " selected_int_kind (range (0_8) + 1)"
667 puts $f "integer(kind=k) :: i"
668 puts $f "end"
669 close $f
671 verbose "check_effective_target_fortran_large_int compiling testfile $src" 2
672 set lines [${tool}_target_compile $src $exe executable ""]
673 file delete $src
675 if [string match "" $lines] then {
676 # No error message, compilation succeeded.
677 set et_fortran_large_int_saved 1
681 return $et_fortran_large_int_saved
684 # Return 1 if we can statically link libgfortran, 0 otherwise.
686 # When the target name changes, replace the cached result.
688 proc check_effective_target_static_libgfortran { } {
689 global et_static_libgfortran
690 global et_static_libgfortran_target_name
691 global tool
693 if { ![info exists et_static_libgfortran_target_name] } {
694 set et_static_libgfortran_target_name ""
697 # If the target has changed since we set the cached value, clear it.
698 set current_target [current_target_name]
699 if { $current_target != $et_static_libgfortran_target_name } {
700 verbose "check_effective_target_static_libgfortran: `$et_static_libgfortran_target_name' `$current_target'" 2
701 set et_static_libgfortran_target_name $current_target
702 if [info exists et_static_libgfortran_saved] {
703 verbose "check_effective_target_static_libgfortran: removing cached result" 2
704 unset et_static_libgfortran_saved
708 if [info exists et_static_libgfortran_saved] {
709 verbose "check_effective_target_static_libgfortran returning saved $et_static_libgfortran_saved" 2
710 } else {
711 set et_static_libgfortran_saved 0
713 # Set up, compile, and execute a test program using static linking.
714 # Include the current process ID in the file names to prevent
715 # conflicts with invocations for multiple testsuites.
716 set opts "additional_flags=-static"
717 set src static[pid].f
718 set exe static[pid].x
720 set f [open $src "w"]
721 puts $f " print *, 'test'"
722 puts $f " end"
723 close $f
725 verbose "check_effective_target_static_libgfortran compiling testfile $src" 2
726 set lines [${tool}_target_compile $src $exe executable "$opts"]
727 file delete $src
729 if [string match "" $lines] then {
730 # No error message, compilation succeeded.
731 set et_static_libgfortran_saved 1
735 return $et_static_libgfortran_saved
738 # Return 1 if the target supports executing AltiVec instructions, 0
739 # otherwise. Cache the result.
741 proc check_vmx_hw_available { } {
742 global vmx_hw_available_saved
743 global tool
745 if [info exists vmx_hw_available_saved] {
746 verbose "check_hw_available returning saved $vmx_hw_available_saved" 2
747 } else {
748 set vmx_hw_available_saved 0
750 # Some simulators are known to not support VMX instructions.
751 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
752 verbose "check_hw_available returning 0" 2
753 return $vmx_hw_available_saved
756 # Set up, compile, and execute a test program containing VMX
757 # instructions. Include the current process ID in the file
758 # names to prevent conflicts with invocations for multiple
759 # testsuites.
760 set src vmx[pid].c
761 set exe vmx[pid].x
763 set f [open $src "w"]
764 puts $f "int main() {"
765 puts $f "#ifdef __MACH__"
766 puts $f " asm volatile (\"vor v0,v0,v0\");"
767 puts $f "#else"
768 puts $f " asm volatile (\"vor 0,0,0\");"
769 puts $f "#endif"
770 puts $f " return 0; }"
771 close $f
773 # Most targets don't require special flags for this test case, but
774 # Darwin does.
775 if [istarget *-*-darwin*] {
776 set opts "additional_flags=-maltivec"
777 } else {
778 set opts ""
781 verbose "check_vmx_hw_available compiling testfile $src" 2
782 set lines [${tool}_target_compile $src $exe executable "$opts"]
783 file delete $src
785 if [string match "" $lines] then {
786 # No error message, compilation succeeded.
787 set result [${tool}_load "./$exe" "" ""]
788 set status [lindex $result 0]
789 remote_file build delete $exe
790 verbose "check_vmx_hw_available testfile status is <$status>" 2
792 if { $status == "pass" } then {
793 set vmx_hw_available_saved 1
795 } else {
796 verbose "check_vmx_hw_availalble testfile compilation failed" 2
800 return $vmx_hw_available_saved
803 # GCC 3.4.0 for powerpc64-*-linux* included an ABI fix for passing
804 # complex float arguments. This affects gfortran tests that call cabsf
805 # in libm built by an earlier compiler. Return 1 if libm uses the same
806 # argument passing as the compiler under test, 0 otherwise.
808 # When the target name changes, replace the cached result.
810 proc check_effective_target_broken_cplxf_arg { } {
811 global et_broken_cplxf_arg_saved
812 global et_broken_cplxf_arg_target_name
813 global tool
815 # Skip the work for targets known not to be affected.
816 if { ![istarget powerpc64-*-linux*] } {
817 return 0
818 } elseif { [is-effective-target ilp32] } {
819 return 0
822 if { ![info exists et_broken_cplxf_arg_target_name] } {
823 set et_broken_cplxf_arg_target_name ""
826 # If the target has changed since we set the cached value, clear it.
827 set current_target [current_target_name]
828 if { $current_target != $et_broken_cplxf_arg_target_name } {
829 verbose "check_effective_target_broken_cplxf_arg: `$et_broken_cplxf_arg_target_name'" 2
830 set et_broken_cplxf_arg_target_name $current_target
831 if [info exists et_broken_cplxf_arg_saved] {
832 verbose "check_effective_target_broken_cplxf_arg: removing cached result" 2
833 unset et_broken_cplxf_arg_saved
837 if [info exists et_broken_cplxf_arg_saved] {
838 verbose "check_effective_target_broken_cplxf_arg: using cached result" 2
839 } else {
840 set et_broken_cplxf_arg_saved 0
841 # This is only known to affect one target.
842 if { ![istarget powerpc64-*-linux*] || ![is-effective-target lp64] } {
843 set et_broken_cplxf_arg_saved 0
844 verbose "check_effective_target_broken_cplxf_arg: caching 0" 2
845 return $et_broken_cplxf_arg_saved
848 # Set up, compile, and execute a C test program that calls cabsf.
849 set src cabsf[pid].c
850 set exe cabsf[pid].x
852 set f [open $src "w"]
853 puts $f "#include <complex.h>"
854 puts $f "extern void abort (void);"
855 puts $f "float fabsf (float);"
856 puts $f "float cabsf (_Complex float);"
857 puts $f "int main ()"
858 puts $f "{"
859 puts $f " _Complex float cf;"
860 puts $f " float f;"
861 puts $f " cf = 3 + 4.0fi;"
862 puts $f " f = cabsf (cf);"
863 puts $f " if (fabsf (f - 5.0) > 0.0001) abort ();"
864 puts $f " return 0;"
865 puts $f "}"
866 close $f
868 set lines [${tool}_target_compile $src $exe executable "-lm"]
869 file delete $src
871 if [string match "" $lines] {
872 # No error message, compilation succeeded.
873 set result [${tool}_load "./$exe" "" ""]
874 set status [lindex $result 0]
875 remote_file build delete $exe
877 verbose "check_effective_target_broken_cplxf_arg: status is <$status>" 2
879 if { $status != "pass" } {
880 set et_broken_cplxf_arg_saved 1
882 } else {
883 verbose "check_effective_target_broken_cplxf_arg: compilation failed" 2
886 return $et_broken_cplxf_arg_saved
889 proc check_alpha_max_hw_available { } {
890 global alpha_max_hw_available_saved
891 global tool
893 if [info exists alpha_max_hw_available_saved] {
894 verbose "check_alpha_max_hw_available returning saved $alpha_max_hw_available_saved" 2
895 } else {
896 set alpha_max_hw_available_saved 0
898 # Set up, compile, and execute a test program probing bit 8 of the
899 # architecture mask, which indicates presence of MAX instructions.
900 set src max[pid].c
901 set exe max[pid].x
903 set f [open $src "w"]
904 puts $f "int main() { return __builtin_alpha_amask(1<<8) != 0; }"
905 close $f
907 verbose "check_alpha_max_hw_available compiling testfile $src" 2
908 set lines [${tool}_target_compile $src $exe executable ""]
909 file delete $src
911 if [string match "" $lines] then {
912 # No error message, compilation succeeded.
913 set result [${tool}_load "./$exe" "" ""]
914 set status [lindex $result 0]
915 remote_file build delete $exe
916 verbose "check_alpha_max_hw_available testfile status is <$status>" 2
918 if { $status == "pass" } then {
919 set alpha_max_hw_available_saved 1
921 } else {
922 verbose "check_alpha_max_hw_availalble testfile compilation failed" 2
926 return $alpha_max_hw_available_saved
929 # Returns true iff the FUNCTION is available on the target system.
930 # (This is essentially a Tcl implementation of Autoconf's
931 # AC_CHECK_FUNC.)
933 proc check_function_available { function } {
934 set var "${function}_available_saved"
935 global $var
936 global tool
938 if {![info exists $var]} {
939 # Assume it exists.
940 set $var 1
941 # Check to make sure.
942 set src "function[pid].c"
943 set exe "function[pid].exe"
945 set f [open $src "w"]
946 puts $f "int main () { $function (); }"
947 close $f
949 set lines [${tool}_target_compile $src $exe executable ""]
950 file delete $src
951 file delete $exe
953 if {![string match "" $lines]} then {
954 set $var 0
955 verbose -log "$function is not available"
956 } else {
957 verbose -log "$function is available"
961 eval return \$$var
964 # Returns true iff "fork" is available on the target system.
966 proc check_fork_available {} {
967 return [check_function_available "fork"]
970 # Returns true iff "mkfifo" is available on the target system.
972 proc check_mkfifo_available {} {
973 if {[istarget *-*-cygwin*]} {
974 # Cygwin has mkfifo, but support is incomplete.
975 return 0
978 return [check_function_available "mkfifo"]
981 # Return 1 if we're generating 32-bit code using default options, 0
982 # otherwise.
984 # When the target name changes, replace the cached result.
986 proc check_effective_target_ilp32 { } {
987 global et_ilp32_saved
988 global et_ilp32_target_name
990 if { ![info exists et_ilp32_target_name] } {
991 set et_ilp32_target_name ""
994 # If the target has changed since we set the cached value, clear it.
995 set current_target [current_target_name]
996 if { $current_target != $et_ilp32_target_name } {
997 verbose "check_effective_target_ilp32: `$et_ilp32_target_name' `$current_target'" 2
998 set et_ilp32_target_name $current_target
999 if { [info exists et_ilp32_saved] } {
1000 verbose "check_effective_target_ilp32: removing cached result" 2
1001 unset et_ilp32_saved
1005 if [info exists et_ilp32_saved] {
1006 verbose "check-effective_target_ilp32: using cached result" 2
1007 } else {
1008 verbose "check_effective_target_ilp32: compiling source" 2
1009 set et_ilp32_saved [string match "" [get_compiler_messages ilp32 object {
1010 int dummy[(sizeof (int) == 4 && sizeof (void *) == 4 && sizeof (long) == 4 ) ? 1 : -1];
1013 verbose "check_effective_target_ilp32: returning $et_ilp32_saved" 2
1014 return $et_ilp32_saved
1017 # Return 1 if we're generating 64-bit code using default options, 0
1018 # otherwise.
1020 # When the target name changes, replace the cached result.
1022 proc check_effective_target_lp64 { } {
1023 global et_lp64_saved
1024 global et_lp64_target_name
1026 if { ![info exists et_lp64_target_name] } {
1027 set et_lp64_target_name ""
1030 # If the target has changed since we set the cached value, clear it.
1031 set current_target [current_target_name]
1032 if { $current_target != $et_lp64_target_name } {
1033 verbose "check_effective_target_lp64: `$et_lp64_target_name' `$current_target'" 2
1034 set et_lp64_target_name $current_target
1035 if [info exists et_lp64_saved] {
1036 verbose "check_effective_target_lp64: removing cached result" 2
1037 unset et_lp64_saved
1041 if [info exists et_lp64_saved] {
1042 verbose "check_effective_target_lp64: using cached result" 2
1043 } else {
1044 verbose "check_effective_target_lp64: compiling source" 2
1045 set et_lp64_saved [string match "" [get_compiler_messages lp64 object {
1046 int dummy[(sizeof (int) == 4 && sizeof (void *) == 8 && sizeof (long) == 8 ) ? 1 : -1];
1049 verbose "check_effective_target_lp64: returning $et_lp64_saved" 2
1050 return $et_lp64_saved
1053 # Return 1 if the target needs a command line argument to enable a SIMD
1054 # instruction set.
1056 # This won't change for different subtargets so cache the result.
1058 proc check_effective_target_vect_cmdline_needed { } {
1059 global et_vect_cmdline_needed_saved
1061 if [info exists et_vect_cmdline_needed_saved] {
1062 verbose "check_effective_target_vect_cmdline_needed: using cached result" 2
1063 } else {
1064 set et_vect_cmdline_needed_saved 1
1065 if { [istarget ia64-*-*]
1066 || [istarget x86_64-*-*] } {
1067 set et_vect_cmdline_needed_saved 0
1071 verbose "check_effective_target_vect_cmdline_needed: returning $et_vect_cmdline_needed_saved" 2
1072 return $et_vect_cmdline_needed_saved
1075 # Return 1 if the target supports hardware vectors of int, 0 otherwise.
1077 # This won't change for different subtargets so cache the result.
1079 proc check_effective_target_vect_int { } {
1080 global et_vect_int_saved
1082 if [info exists et_vect_int_saved] {
1083 verbose "check_effective_target_vect_int: using cached result" 2
1084 } else {
1085 set et_vect_int_saved 0
1086 if { [istarget i?86-*-*]
1087 || [istarget powerpc*-*-*]
1088 || [istarget x86_64-*-*]
1089 || [istarget sparc*-*-*]
1090 || [istarget alpha*-*-*]
1091 || [istarget ia64-*-*] } {
1092 set et_vect_int_saved 1
1096 verbose "check_effective_target_vect_int: returning $et_vect_int_saved" 2
1097 return $et_vect_int_saved
1100 # Return 1 is this is an arm target using 32-bit instructions
1101 proc check_effective_target_arm32 { } {
1102 global et_arm32_saved
1103 global et_arm32_target_name
1104 global compiler_flags
1106 if { ![info exists et_arm32_target_name] } {
1107 set et_arm32_target_name ""
1110 # If the target has changed since we set the cached value, clear it.
1111 set current_target [current_target_name]
1112 if { $current_target != $et_arm32_target_name } {
1113 verbose "check_effective_target_arm32: `$et_arm32_target_name' `$current_target'" 2
1114 set et_arm32_target_name $current_target
1115 if { [info exists et_arm32_saved] } {
1116 verbose "check_effective_target_arm32: removing cached result" 2
1117 unset et_arm32_saved
1121 if [info exists et_arm32_saved] {
1122 verbose "check-effective_target_arm32: using cached result" 2
1123 } else {
1124 set et_arm32_saved 0
1125 if { [istarget arm-*-*]
1126 || [istarget strongarm*-*-*]
1127 || [istarget xscale-*-*] } {
1128 if ![string match "*-mthumb *" $compiler_flags] {
1129 set et_arm32_saved 1
1133 verbose "check_effective_target_arm32: returning $et_arm32_saved" 2
1134 return $et_arm32_saved
1137 # Return 1 if the target supports hardware vector shift operation.
1139 proc check_effective_target_vect_shift { } {
1140 global et_vect_shift_saved
1142 if [info exists et_vect_shift_saved] {
1143 verbose "check_effective_target_vect_shift: using cached result" 2
1144 } else {
1145 set et_vect_shift_saved 0
1146 if { [istarget powerpc*-*-*]
1147 || [istarget ia64-*-*]
1148 || [istarget i?86-*-*]
1149 || [istarget x86_64-*-*] } {
1150 set et_vect_shift_saved 1
1154 verbose "check_effective_target_vect_shift: returning $et_vect_shift_saved" 2
1155 return $et_vect_shift_saved
1158 # Return 1 if the target supports hardware vectors of long, 0 otherwise.
1160 # This can change for different subtargets so do not cache the result.
1162 proc check_effective_target_vect_long { } {
1163 if { [istarget i?86-*-*]
1164 || ([istarget powerpc*-*-*] && [check_effective_target_ilp32])
1165 || [istarget x86_64-*-*]
1166 || ([istarget sparc*-*-*] && [check_effective_target_ilp32]) } {
1167 set answer 1
1168 } else {
1169 set answer 0
1172 verbose "check_effective_target_vect_long: returning $answer" 2
1173 return $answer
1176 # Return 1 if the target supports hardware vectors of float, 0 otherwise.
1178 # This won't change for different subtargets so cache the result.
1180 proc check_effective_target_vect_float { } {
1181 global et_vect_float_saved
1183 if [info exists et_vect_float_saved] {
1184 verbose "check_effective_target_vect_float: using cached result" 2
1185 } else {
1186 set et_vect_float_saved 0
1187 if { [istarget i?86-*-*]
1188 || [istarget powerpc*-*-*]
1189 || [istarget mipsisa64*-*-*]
1190 || [istarget x86_64-*-*]
1191 || [istarget ia64-*-*] } {
1192 set et_vect_float_saved 1
1196 verbose "check_effective_target_vect_float: returning $et_vect_float_saved" 2
1197 return $et_vect_float_saved
1200 # Return 1 if the target supports hardware vectors of double, 0 otherwise.
1202 # This won't change for different subtargets so cache the result.
1204 proc check_effective_target_vect_double { } {
1205 global et_vect_double_saved
1207 if [info exists et_vect_double_saved] {
1208 verbose "check_effective_target_vect_double: using cached result" 2
1209 } else {
1210 set et_vect_double_saved 0
1211 if { [istarget i?86-*-*]
1212 || [istarget x86_64-*-*] } {
1213 set et_vect_double_saved 1
1217 verbose "check_effective_target_vect_double: returning $et_vect_double_saved" 2
1218 return $et_vect_double_saved
1221 # Return 1 if the target plus current options does not support a vector
1222 # max instruction on "int", 0 otherwise.
1224 # This won't change for different subtargets so cache the result.
1226 proc check_effective_target_vect_no_int_max { } {
1227 global et_vect_no_int_max_saved
1229 if [info exists et_vect_no_int_max_saved] {
1230 verbose "check_effective_target_vect_no_int_max: using cached result" 2
1231 } else {
1232 set et_vect_no_int_max_saved 0
1233 if { [istarget sparc*-*-*]
1234 || [istarget alpha*-*-*] } {
1235 set et_vect_no_int_max_saved 1
1238 verbose "check_effective_target_vect_no_int_max: returning $et_vect_no_int_max_saved" 2
1239 return $et_vect_no_int_max_saved
1242 # Return 1 if the target plus current options does not support a vector
1243 # add instruction on "int", 0 otherwise.
1245 # This won't change for different subtargets so cache the result.
1247 proc check_effective_target_vect_no_int_add { } {
1248 global et_vect_no_int_add_saved
1250 if [info exists et_vect_no_int_add_saved] {
1251 verbose "check_effective_target_vect_no_int_add: using cached result" 2
1252 } else {
1253 set et_vect_no_int_add_saved 0
1254 # Alpha only supports vector add on V8QI and V4HI.
1255 if { [istarget alpha*-*-*] } {
1256 set et_vect_no_int_add_saved 1
1259 verbose "check_effective_target_vect_no_int_add: returning $et_vect_no_int_add_saved" 2
1260 return $et_vect_no_int_add_saved
1263 # Return 1 if the target plus current options does not support vector
1264 # bitwise instructions, 0 otherwise.
1266 # This won't change for different subtargets so cache the result.
1268 proc check_effective_target_vect_no_bitwise { } {
1269 global et_vect_no_bitwise_saved
1271 if [info exists et_vect_no_bitwise_saved] {
1272 verbose "check_effective_target_vect_no_bitwise: using cached result" 2
1273 } else {
1274 set et_vect_no_bitwise_saved 0
1276 verbose "check_effective_target_vect_no_bitwise: returning $et_vect_no_bitwise_saved" 2
1277 return $et_vect_no_bitwise_saved
1280 # Return 1 if the target plus current options does not support a vector
1281 # alignment mechanism, 0 otherwise.
1283 # This won't change for different subtargets so cache the result.
1285 proc check_effective_target_vect_no_align { } {
1286 global et_vect_no_align_saved
1288 if [info exists et_vect_no_align_saved] {
1289 verbose "check_effective_target_vect_no_align: using cached result" 2
1290 } else {
1291 set et_vect_no_align_saved 0
1292 if { [istarget mipsisa64*-*-*]
1293 || [istarget sparc*-*-*]
1294 || [istarget ia64-*-*] } {
1295 set et_vect_no_align_saved 1
1298 verbose "check_effective_target_vect_no_align: returning $et_vect_no_align_saved" 2
1299 return $et_vect_no_align_saved
1302 # Return 1 if the target supports vector conditional operations, 0 otherwise.
1304 proc check_effective_target_vect_condition { } {
1305 global et_vect_cond_saved
1307 if [info exists et_vect_cond_saved] {
1308 verbose "check_effective_target_vect_cond: using cached result" 2
1309 } else {
1310 set et_vect_cond_saved 0
1311 if { [istarget powerpc*-*-*]
1312 || [istarget ia64-*-*]
1313 || [istarget i?86-*-*]
1314 || [istarget x86_64-*-*] } {
1315 set et_vect_cond_saved 1
1319 verbose "check_effective_target_vect_cond: returning $et_vect_cond_saved" 2
1320 return $et_vect_cond_saved
1323 # Return 1 if the target supports vector int multiplication, 0 otherwise.
1325 proc check_effective_target_vect_int_mult { } {
1326 global et_vect_int_mult_saved
1328 if [info exists et_vect_int_mult_saved] {
1329 verbose "check_effective_target_vect_int_mult: using cached result" 2
1330 } else {
1331 set et_vect_int_mult_saved 0
1332 if { [istarget powerpc*-*-*]
1333 || [istarget i?86-*-*]
1334 || [istarget x86_64-*-*] } {
1335 set et_vect_int_mult_saved 1
1339 verbose "check_effective_target_vect_int_mult: returning $et_vect_int_mult_saved" 2
1340 return $et_vect_int_mult_saved
1343 # Return 1 if the target supports vector short multiplication, 0 otherwise.
1345 proc check_effective_target_vect_short_mult { } {
1346 global et_vect_short_mult_saved
1348 if [info exists et_vect_short_mult_saved] {
1349 verbose "check_effective_target_vect_short_mult: using cached result" 2
1350 } else {
1351 set et_vect_short_mult_saved 0
1352 if { [istarget i?86-*-*]
1353 || [istarget x86_64-*-*] } {
1354 set et_vect_short_mult_saved 1
1358 verbose "check_effective_target_vect_short_mult: returning $et_vect_short_mult_saved" 2
1359 return $et_vect_short_mult_saved
1362 # Return 1 if the target supports vectorization of strided accesses, 0 otherwise.
1364 proc check_effective_target_vect_strided { } {
1365 global et_vect_strided_saved
1367 if [info exists et_vect_strided_saved] {
1368 verbose "check_effective_target_vect_strided: using cached result" 2
1369 } else {
1370 set et_vect_strided_saved 0
1371 if { [istarget powerpc*-*-*]
1372 || [istarget ia64-*-*]
1373 || [istarget i?86-*-*]
1374 || [istarget x86_64-*-*] } {
1375 set et_vect_strided_saved 1
1379 verbose "check_effective_target_vect_strided: returning $et_vect_strided_saved" 2
1380 return $et_vect_strided_saved
1383 # Return 1 if the target supports atomic operations on "int" and "long".
1385 proc check_effective_target_sync_int_long { } {
1386 global et_sync_int_long_saved
1388 if [info exists et_sync_int_long_saved] {
1389 verbose "check_effective_target_sync_int_long: using cached result" 2
1390 } else {
1391 set et_sync_int_long_saved 0
1392 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
1393 # load-reserved/store-conditional instructions.
1394 if { [istarget ia64-*-*]
1395 || [istarget i?86-*-*]
1396 || [istarget x86_64-*-*]
1397 || [istarget alpha*-*-*]
1398 || [istarget s390*-*-*]
1399 || [istarget powerpc*-*-*] } {
1400 set et_sync_int_long_saved 1
1404 verbose "check_effective_target_sync_int_long: returning $et_sync_int_long_saved" 2
1405 return $et_sync_int_long_saved
1408 # Return 1 if the target supports atomic operations on "char" and "short".
1410 proc check_effective_target_sync_char_short { } {
1411 global et_sync_char_short_saved
1413 if [info exists et_sync_char_short_saved] {
1414 verbose "check_effective_target_sync_char_short: using cached result" 2
1415 } else {
1416 set et_sync_char_short_saved 0
1417 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
1418 # load-reserved/store-conditional instructions.
1419 if { [istarget ia64-*-*]
1420 || [istarget i?86-*-*]
1421 || [istarget x86_64-*-*]
1422 || [istarget alpha*-*-*]
1423 || [istarget s390*-*-*]
1424 || [istarget powerpc*-*-*] } {
1425 set et_sync_char_short_saved 1
1429 verbose "check_effective_target_sync_char_short: returning $et_sync_char_short_saved" 2
1430 return $et_sync_char_short_saved
1433 # Return 1 if the target matches the effective target 'arg', 0 otherwise.
1434 # This can be used with any check_* proc that takes no argument and
1435 # returns only 1 or 0. It could be used with check_* procs that take
1436 # arguments with keywords that pass particular arguments.
1438 proc is-effective-target { arg } {
1439 set selected 0
1440 if { [info procs check_effective_target_${arg}] != [list] } {
1441 set selected [check_effective_target_${arg}]
1442 } else {
1443 switch $arg {
1444 "vmx_hw" { set selected [check_vmx_hw_available] }
1445 "named_sections" { set selected [check_named_sections_available] }
1446 "gc_sections" { set selected [check_gc_sections_available] }
1447 default { error "unknown effective target keyword `$arg'" }
1450 verbose "is-effective-target: $arg $selected" 2
1451 return $selected
1454 # Return 1 if the argument is an effective-target keyword, 0 otherwise.
1456 proc is-effective-target-keyword { arg } {
1457 if { [info procs check_effective_target_${arg}] != [list] } {
1458 return 1
1459 } else {
1460 # These have different names for their check_* procs.
1461 switch $arg {
1462 "vmx_hw" { return 1 }
1463 "named_sections" { return 1 }
1464 "gc_sections" { return 1 }
1465 default { return 0 }