target-supports.exp (check_effective_target_tls): Compile test stubs using ${tool...
[platform/upstream/gcc.git] / gcc / testsuite / lib / target-supports.exp
1 #   Copyright (C) 1999, 2001, 2003, 2004, 2005, 2006
2 #   Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 # Please email any bugs, comments, and/or additions to this file to:
19 # gcc-patches@gcc.gnu.org
20
21 # This file defines procs for determining features supported by the target.
22
23 # Try to compile some code and return the messages printed by the compiler,
24 # and optionally the contents for assembly files.  Either a string or
25 # a list of two strings are returned, depending on WANT_OUTPUT.
26 #
27 # BASENAME is a basename to use for temporary files.
28 # WANT_OUTPUT is a flag which is 0 to request returning just the
29 #   compiler messages, or 1 to return the messages and the contents
30 #   of the assembly file.  TYPE should be "assembly" if WANT_OUTPUT
31 #   is set.
32 # TYPE is the type of compilation to perform (see target_compile).
33 # CONTENTS gives the contents of the input file.
34 # The rest is optional:
35 # OPTIONS: additional compiler options to use.
36 proc get_compiler_messages {basename want_output type contents args} {
37     global tool
38
39     if { [llength $args] > 0 } {
40         set options "additional_flags=[lindex $args 0]"
41     } else {
42         set options ""
43     }
44
45     set src ${basename}[pid].c
46     switch $type {
47         assembly { set output ${basename}[pid].s }
48         object { set output ${basename}[pid].o }
49     }
50     set f [open $src "w"]
51     puts $f $contents
52     close $f
53     set lines [${tool}_target_compile $src $output $type "$options"]
54     file delete $src
55
56     if { $want_output } {
57         if { $type != "assembly" } {
58             error "WANT_OUTPUT can only be used with assembly output"
59         } elseif { ![string match "" $lines] } {
60             # An error occurred.
61             set result [list $lines ""]
62         } else {
63             set text ""
64             set chan [open "$output"]
65             while {[gets $chan line] >= 0} {
66                 append text "$line\n"
67             }
68             close $chan
69             set result [list $lines $text]
70         }
71     } else {
72         set result $lines
73     }
74
75     remote_file build delete $output
76     return $result
77 }
78
79 proc current_target_name { } {
80     global target_info
81     if [info exists target_info(target,name)] {
82         set answer $target_info(target,name)
83     } else {
84         set answer ""
85     }
86     return $answer
87 }
88
89 # Implement an effective-target check for property PROP by invoking
90 # the compiler and seeing if it prints any messages.  Assume that the
91 # property holds if the compiler doesn't print anything.  The other
92 # arguments are as for get_compiler_messages, starting with TYPE.
93 proc check_no_compiler_messages {prop args} {
94     global et_cache
95
96     set target [current_target_name]
97     if {![info exists et_cache($prop,target)]
98         || $et_cache($prop,target) != $target} {
99         verbose "check_no_compiler_messages $prop: compiling source for $target" 2
100         set et_cache($prop,target) $target
101         set et_cache($prop,value) \
102             [string match "" [eval get_compiler_messages $prop 0 $args]]
103     }
104     set value $et_cache($prop,value)
105     verbose "check_no_compiler_messages $prop: returning $value for $target" 2
106     return $value
107 }
108
109 # Similar to check_no_compiler_messages, but also verify that the regular
110 # expression PATTERN matches the compiler's output.
111 proc check_no_messages_and_pattern {prop pattern args} {
112     global et_cache
113
114     set target [current_target_name]
115     if {![info exists et_cache($prop,target)]
116         || $et_cache($prop,target) != $target} {
117         verbose "check_no_messages_and_pattern $prop: compiling source for $target" 2
118         set et_cache($prop,target) $target
119         set results [eval get_compiler_messages $prop 1 $args]
120         set et_cache($prop,value) \
121             [expr [string match "" [lindex $results 0]] \
122                  && [regexp $pattern [lindex $results 1]]]
123     }
124     set value $et_cache($prop,value)
125     verbose "check_no_messages_and_pattern $prop: returning $value for $target" 2
126     return $value
127 }
128
129 ###############################
130 # proc check_weak_available { }
131 ###############################
132
133 # weak symbols are only supported in some configs/object formats
134 # this proc returns 1 if they're supported, 0 if they're not, or -1 if unsure
135
136 proc check_weak_available { } {
137     global target_triplet
138     global target_cpu
139
140     # All mips targets should support it
141
142     if { [ string first "mips" $target_cpu ] >= 0 } {
143         return 1
144     }
145
146     # All solaris2 targets should support it
147
148     if { [regexp ".*-solaris2.*" $target_triplet] } {
149         return 1
150     }
151
152     # DEC OSF/1/Digital UNIX/Tru64 UNIX supports it
153
154     if { [regexp "alpha.*osf.*" $target_triplet] } {
155         return 1
156     }
157
158     # Windows targets Cygwin and MingW32 support it
159
160     if { [regexp ".*mingw32|.*cygwin" $target_triplet] } {
161         return 1
162     }
163
164     # HP-UX 10.X doesn't support it
165
166     if { [regexp "hppa.*hpux10" $target_triplet] } {
167         return 0
168     }
169
170     # ELF and ECOFF support it. a.out does with gas/gld but may also with
171     # other linkers, so we should try it
172
173     set objformat [gcc_target_object_format]
174
175     switch $objformat {
176         elf      { return 1 }
177         ecoff    { return 1 }
178         a.out    { return 1 }
179         mach-o   { return 1 }
180         som      { return 1 }
181         unknown  { return -1 }
182         default  { return 0 }
183     }
184 }
185
186 ###############################
187 # proc check_visibility_available { what_kind }
188 ###############################
189
190 # The visibility attribute is only support in some object formats
191 # This proc returns 1 if it is supported, 0 if not.
192 # The argument is the kind of visibility, default/protected/hidden/internal.
193
194 proc check_visibility_available { what_kind } {
195     global tool
196     global target_triplet
197
198     # On NetWare, support makes no sense.
199     if { [istarget *-*-netware*] } {
200         return 0
201     }
202
203     if [string match "" $what_kind] { set what_kind "hidden" }
204
205     return [check_no_compiler_messages visibility_available_$what_kind object "
206         void f() __attribute__((visibility(\"$what_kind\")));
207         void f() {}
208     "]
209 }
210
211 ###############################
212 # proc check_alias_available { }
213 ###############################
214
215 # Determine if the target toolchain supports the alias attribute.
216
217 # Returns 2 if the target supports aliases.  Returns 1 if the target
218 # only supports weak aliased.  Returns 0 if the target does not
219 # support aliases at all.  Returns -1 if support for aliases could not
220 # be determined.
221
222 proc check_alias_available { } {
223     global alias_available_saved
224     global tool
225
226     if [info exists alias_available_saved] {
227         verbose "check_alias_available  returning saved $alias_available_saved" 2
228     } else {
229         set src alias[pid].c
230         set obj alias[pid].o
231         verbose "check_alias_available  compiling testfile $src" 2
232         set f [open $src "w"]
233         # Compile a small test program.  The definition of "g" is
234         # necessary to keep the Solaris assembler from complaining
235         # about the program.
236         puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
237         puts $f "void g() {} void f() __attribute__((alias(\"g\")));"
238         close $f
239         set lines [${tool}_target_compile $src $obj object ""]
240         file delete $src
241         remote_file build delete $obj
242
243         if [string match "" $lines] then {
244             # No error messages, everything is OK.
245             set alias_available_saved 2
246         } else {
247             if [regexp "alias definitions not supported" $lines] {
248                 verbose "check_alias_available  target does not support aliases" 2
249
250                 set objformat [gcc_target_object_format]
251
252                 if { $objformat == "elf" } {
253                     verbose "check_alias_available  but target uses ELF format, so it ought to" 2
254                     set alias_available_saved -1
255                 } else {
256                     set alias_available_saved 0
257                 }
258             } else {
259                 if [regexp "only weak aliases are supported" $lines] {
260                 verbose "check_alias_available  target supports only weak aliases" 2
261                 set alias_available_saved 1
262                 } else {
263                     set alias_available_saved -1
264                 }
265             }
266         }
267
268         verbose "check_alias_available  returning $alias_available_saved" 2
269     }
270
271     return $alias_available_saved
272 }
273
274 # Returns true if --gc-sections is supported on the target.
275
276 proc check_gc_sections_available { } {
277     global gc_sections_available_saved
278     global tool
279
280     if {![info exists gc_sections_available_saved]} {
281         # Some targets don't support gc-sections despite whatever's
282         # advertised by ld's options.
283         if { [istarget alpha*-*-*]
284              || [istarget ia64-*-*] } {
285             set gc_sections_available_saved 0
286             return 0
287         }
288
289         # Check if the ld used by gcc supports --gc-sections.
290         set gcc_spec [${tool}_target_compile "-dumpspecs" "" "none" ""]
291         regsub ".*\n\*linker:\[ \t\]*\n(\[^ \t\n\]*).*" "$gcc_spec" {\1} linker
292         set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=$linker" "" "none" ""] 0]
293         set ld_output [remote_exec host "$gcc_ld" "--help"]
294         if { [ string first "--gc-sections" $ld_output ] >= 0 } {
295             set gc_sections_available_saved 1
296         } else {
297             set gc_sections_available_saved 0
298         }
299     }
300     return $gc_sections_available_saved
301 }
302
303 # Return true if profiling is supported on the target.
304
305 proc check_profiling_available { test_what } {
306     global profiling_available_saved
307
308     verbose "Profiling argument is <$test_what>" 1
309
310     # These conditions depend on the argument so examine them before
311     # looking at the cache variable.
312
313     # Support for -p on solaris2 relies on mcrt1.o which comes with the
314     # vendor compiler.  We cannot reliably predict the directory where the
315     # vendor compiler (and thus mcrt1.o) is installed so we can't
316     # necessarily find mcrt1.o even if we have it.
317     if { [istarget *-*-solaris2*] && [lindex $test_what 1] == "-p" } {
318         return 0
319     }
320
321     # Support for -p on irix relies on libprof1.a which doesn't appear to
322     # exist on any irix6 system currently posting testsuite results.
323     # Support for -pg on irix relies on gcrt1.o which doesn't exist yet.
324     # See: http://gcc.gnu.org/ml/gcc/2002-10/msg00169.html
325     if { [istarget mips*-*-irix*]
326     && ([lindex $test_what 1] == "-p" || [lindex $test_what 1] == "-pg") } {
327         return 0
328     }
329
330     # At present, there is no profiling support on NetWare.
331     if { [istarget *-*-netware*] } {
332         return 0
333     }
334
335     # Now examine the cache variable.
336     if {![info exists profiling_available_saved]} {
337         # Some targets don't have any implementation of __bb_init_func or are
338         # missing other needed machinery.
339         if { [istarget mmix-*-*]
340              || [istarget arm*-*-eabi*]
341              || [istarget arm*-*-elf]
342              || [istarget arm*-*-symbianelf*]
343              || [istarget powerpc-*-eabi*]
344              || [istarget strongarm*-*-elf]
345              || [istarget xscale*-*-elf]
346              || [istarget cris-*-*]
347              || [istarget h8300-*-*]
348              || [istarget m32c-*-elf]
349              || [istarget m68k-*-elf]
350              || [istarget mips*-*-elf]
351              || [istarget xtensa-*-elf]
352              || [istarget *-*-windiss] } {
353             set profiling_available_saved 0
354         } else {
355             set profiling_available_saved 1
356         }
357     }
358
359     return $profiling_available_saved
360 }
361
362 # Return 1 if target has packed layout of structure members by
363 # default, 0 otherwise.  Note that this is slightly different than
364 # whether the target has "natural alignment": both attributes may be
365 # false.
366
367 proc check_effective_target_default_packed { } {
368     return [check_no_compiler_messages default_packed assembly {
369         struct x { char a; long b; } c;
370         int s[sizeof (c) == sizeof (char) + sizeof (long) ? 1 : -1];
371     }]
372 }
373
374 # Return 1 if target has PCC_BITFIELD_TYPE_MATTERS defined.  See
375 # documentation, where the test also comes from.
376
377 proc check_effective_target_pcc_bitfield_type_matters { } {
378     # PCC_BITFIELD_TYPE_MATTERS isn't just about unnamed or empty
379     # bitfields, but let's stick to the example code from the docs.
380     return [check_no_compiler_messages pcc_bitfield_type_matters assembly {
381         struct foo1 { char x; char :0; char y; };
382         struct foo2 { char x; int :0; char y; };
383         int s[sizeof (struct foo1) != sizeof (struct foo2) ? 1 : -1];
384     }]
385 }
386
387 # Return 1 if thread local storage (TLS) is supported, 0 otherwise.
388 #
389 # This won't change for different subtargets so cache the result.
390
391 proc check_effective_target_tls {} {
392     global et_tls_saved
393     global tool
394
395     if [info exists et_tls_saved] {
396         verbose "check_effective_target_tls: using cached result" 2
397     } else {
398         set et_tls_saved 1
399
400         set src tls[pid].c
401         set asm tls[pid].S
402         verbose "check_effective_target_tls: compiling testfile $src" 2
403         set f [open $src "w"]
404         # Compile a small test program.
405         puts $f "__thread int i;\n"
406         close $f
407
408         # Test for thread-local data supported by the platform.
409         set comp_output \
410             [${tool}_target_compile $src $asm assembly ""]
411         file delete $src
412         if { [string match "*not supported*" $comp_output] } {
413             set et_tls_saved 0
414         }
415         remove-build-file $asm
416     }
417     verbose "check_effective_target_tls: returning $et_tls_saved" 2
418     return $et_tls_saved
419 }
420
421 # Return 1 if TLS executables can run correctly, 0 otherwise.
422 #
423 # This won't change for different subtargets so cache the result.
424
425 proc check_effective_target_tls_runtime {} {
426     global et_tls_runtime_saved
427     global tool
428
429     if [info exists et_tls_runtime_saved] {
430         verbose "check_effective_target_tls_runtime: using cached result" 2
431     } else {
432         set et_tls_runtime_saved 0
433
434         set src tls_runtime[pid].c
435         set exe tls_runtime[pid].x
436         verbose "check_effective_target_tls_runtime: compiling testfile $src" 2
437         set f [open $src "w"]
438         # Compile a small test program.
439         puts $f "__thread int thr = 0;\n"
440         puts $f "int main(void)\n {\n return thr;\n}"
441         close $f
442
443         set comp_output \
444             [${tool}_target_compile $src $exe executable ""]
445         file delete $src
446
447         if [string match "" $comp_output] then {
448             # No error messages, everything is OK.
449
450             set result [remote_load target "./$exe" "" ""]
451             set status [lindex $result 0]
452             remote_file build delete $exe
453
454             verbose "check_effective_target_tls_runtime status is <$status>" 2
455
456             if { $status == "pass" } {
457                 set et_tls_runtime_saved 1
458             }
459
460             verbose "check_effective_target_tls_runtime: returning $et_tls_runtime_saved" 2
461         }
462     }
463
464     return $et_tls_runtime_saved
465 }
466
467 # Return 1 if compilation with -fopenmp is error-free for trivial
468 # code, 0 otherwise.
469
470 proc check_effective_target_fopenmp {} {
471     return [check_no_compiler_messages fopenmp object {
472         void foo (void) { }
473     } "-fopenmp"]
474 }
475
476 # Return 1 if compilation with -freorder-blocks-and-partition is error-free
477 # for trivial code, 0 otherwise.
478
479 proc check_effective_target_freorder {} {
480     return [check_no_compiler_messages freorder object {
481         void foo (void) { }
482     } "-freorder-blocks-and-partition"]
483 }
484
485 # Return 1 if -fpic and -fPIC are supported, as in no warnings or errors
486 # emitted, 0 otherwise.  Whether a shared library can actually be built is
487 # out of scope for this test.
488
489 proc check_effective_target_fpic { } {
490     # Note that M68K has a multilib that supports -fpic but not
491     # -fPIC, so we need to check both.  We test with a program that
492     # requires GOT references.
493     foreach arg {fpic fPIC} {
494         if [check_no_compiler_messages $arg object {
495             extern int foo (void); extern int bar;
496             int baz (void) { return foo () + bar; }
497         } "-$arg"] {
498             return 1
499         }
500     }
501     return 0
502 }
503
504 # Return true if the target supports -mpaired-single (as used on MIPS).
505
506 proc check_effective_target_mpaired_single { } {
507     return [check_no_compiler_messages mpaired_single object {
508         void foo (void) { }
509     } "-mpaired-single"]
510 }
511
512 # Return true if iconv is supported on the target. In particular IBM1047.
513
514 proc check_iconv_available { test_what } {
515     global tool
516     global libiconv
517
518     set result ""
519
520     set src iconv[pid].c
521     set exe iconv[pid].x
522     verbose "check_iconv_available compiling testfile $src" 2
523     set f [open $src "w"]
524     # Compile a small test program.
525     puts $f "#include <iconv.h>\n"
526     puts $f "int main (void)\n {\n iconv_t cd; \n"
527     puts $f "cd = iconv_open (\"[lindex $test_what 1]\", \"UTF-8\");\n"
528     puts $f "if (cd == (iconv_t) -1)\n return 1;\n"
529     puts $f "return 0;\n}"
530     close $f
531
532     # If the tool configuration file has not set libiconv, try "-liconv"
533     if { ![info exists libiconv] } {
534         set libiconv "-liconv"
535     }
536     set lines [${tool}_target_compile $src $exe executable "libs=$libiconv" ]
537     file delete $src
538
539     if [string match "" $lines] then {
540         # No error messages, everything is OK.
541
542         set result [${tool}_load "./$exe" "" ""]
543         set status [lindex $result 0]
544         remote_file build delete $exe
545
546         verbose "check_iconv_available status is <$status>" 2
547
548         if { $status == "pass" } then {
549             return 1
550         }
551     }
552
553     return 0
554 }
555
556 # Return true if named sections are supported on this target.
557
558 proc check_named_sections_available { } {
559     return [check_no_compiler_messages named_sections assembly {
560         int __attribute__ ((section("whatever"))) foo;
561     }]
562 }
563
564 # Return 1 if the target supports Fortran real kinds larger than real(8),
565 # 0 otherwise.
566 #
567 # When the target name changes, replace the cached result.
568
569 proc check_effective_target_fortran_large_real { } {
570     global et_fortran_large_real_saved
571     global et_fortran_large_real_target_name
572     global tool
573
574     if { ![info exists et_fortran_large_real_target_name] } {
575         set et_fortran_large_real_target_name ""
576     }
577
578     # If the target has changed since we set the cached value, clear it.
579     set current_target [current_target_name]
580     if { $current_target != $et_fortran_large_real_target_name } {
581         verbose "check_effective_target_fortran_large_real: `$et_fortran_large_real_target_name' `$current_target'" 2
582         set et_fortran_large_real_target_name $current_target
583         if [info exists et_fortran_large_real_saved] {
584             verbose "check_effective_target_fortran_large_real: removing cached result" 2
585             unset et_fortran_large_real_saved
586         }
587     }
588
589     if [info exists et_fortran_large_real_saved] {
590         verbose "check_effective_target_fortran_large_real returning saved $et_fortran_large_real_saved" 2
591     } else {
592         set et_fortran_large_real_saved 0
593
594         # Set up, compile, and execute a test program using large real
595         # kinds.  Include the current process ID in the file names to
596         # prevent conflicts with invocations for multiple testsuites.
597         set src real[pid].f90
598         set exe real[pid].x
599
600         set f [open $src "w"]
601         puts $f "integer,parameter :: k = &"
602         puts $f "  selected_real_kind (precision (0.0_8) + 1)"
603         puts $f "real(kind=k) :: x"
604         puts $f "x = cos (x);"
605         puts $f "end"
606         close $f
607
608         verbose "check_effective_target_fortran_large_real compiling testfile $src" 2
609         set lines [${tool}_target_compile $src $exe executable ""]
610         file delete $src
611
612         if [string match "" $lines] then {
613             # No error message, compilation succeeded.
614             set et_fortran_large_real_saved 1
615         }
616     }
617
618     return $et_fortran_large_real_saved
619 }
620
621 # Return 1 if the target supports Fortran integer kinds larger than
622 # integer(8), 0 otherwise.
623 #
624 # When the target name changes, replace the cached result.
625
626 proc check_effective_target_fortran_large_int { } {
627     global et_fortran_large_int_saved
628     global et_fortran_large_int_target_name
629     global tool
630
631     if { ![info exists et_fortran_large_int_target_name] } {
632         set et_fortran_large_int_target_name ""
633     }
634
635     # If the target has changed since we set the cached value, clear it.
636     set current_target [current_target_name]
637     if { $current_target != $et_fortran_large_int_target_name } {
638         verbose "check_effective_target_fortran_large_int: `$et_fortran_large_int_target_name' `$current_target'" 2
639         set et_fortran_large_int_target_name $current_target
640         if [info exists et_fortran_large_int_saved] {
641             verbose "check_effective_target_fortran_large_int: removing cached result" 2
642             unset et_fortran_large_int_saved
643         }
644     }
645
646     if [info exists et_fortran_large_int_saved] {
647         verbose "check_effective_target_fortran_large_int returning saved $et_fortran_large_int_saved" 2
648     } else {
649         set et_fortran_large_int_saved 0
650
651         # Set up, compile, and execute a test program using large integer
652         # kinds.  Include the current process ID in the file names to
653         # prevent conflicts with invocations for multiple testsuites.
654         set src int[pid].f90
655         set exe int[pid].x
656
657         set f [open $src "w"]
658         puts $f "integer,parameter :: k = &"
659         puts $f "  selected_int_kind (range (0_8) + 1)"
660         puts $f "integer(kind=k) :: i"
661         puts $f "end"
662         close $f
663
664         verbose "check_effective_target_fortran_large_int compiling testfile $src" 2
665         set lines [${tool}_target_compile $src $exe executable ""]
666         file delete $src
667
668         if [string match "" $lines] then {
669             # No error message, compilation succeeded.
670             set et_fortran_large_int_saved 1
671         }
672     }
673
674     return $et_fortran_large_int_saved
675 }
676
677 # Return 1 if we can statically link libgfortran, 0 otherwise.
678 #
679 # When the target name changes, replace the cached result.
680
681 proc check_effective_target_static_libgfortran { } {
682     global et_static_libgfortran
683     global et_static_libgfortran_target_name
684     global tool
685
686     if { ![info exists et_static_libgfortran_target_name] } {
687        set et_static_libgfortran_target_name ""
688     }
689
690     # If the target has changed since we set the cached value, clear it.
691     set current_target [current_target_name]
692     if { $current_target != $et_static_libgfortran_target_name } {
693        verbose "check_effective_target_static_libgfortran: `$et_static_libgfortran_target_name' `$current_target'" 2
694        set et_static_libgfortran_target_name $current_target
695        if [info exists et_static_libgfortran_saved] {
696            verbose "check_effective_target_static_libgfortran: removing cached result" 2
697            unset et_static_libgfortran_saved
698        }
699     }
700
701     if [info exists et_static_libgfortran_saved] {
702        verbose "check_effective_target_static_libgfortran returning saved $et_static_libgfortran_saved" 2
703     } else {
704        set et_static_libgfortran_saved 0
705
706        # Set up, compile, and execute a test program using static linking.
707        # Include the current process ID in the file names to prevent
708        # conflicts with invocations for multiple testsuites.
709        set opts "additional_flags=-static"
710        set src static[pid].f
711        set exe static[pid].x
712
713        set f [open $src "w"]
714        puts $f "      print *, 'test'"
715        puts $f "      end"
716        close $f
717
718        verbose "check_effective_target_static_libgfortran compiling testfile $src" 2
719        set lines [${tool}_target_compile $src $exe executable "$opts"]
720        file delete $src
721
722        if [string match "" $lines] then {
723            # No error message, compilation succeeded.
724            set et_static_libgfortran_saved 1
725        }
726     }
727
728     return $et_static_libgfortran_saved
729 }
730
731 # Return 1 if the target supports executing AltiVec instructions, 0
732 # otherwise.  Cache the result.
733
734 proc check_vmx_hw_available { } {
735     global vmx_hw_available_saved
736     global tool
737
738     if [info exists vmx_hw_available_saved] {
739         verbose "check_hw_available  returning saved $vmx_hw_available_saved" 2
740     } else {
741         set vmx_hw_available_saved 0
742
743         # Some simulators are known to not support VMX instructions.
744         if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
745             verbose "check_hw_available  returning 0" 2
746             return $vmx_hw_available_saved
747         }
748
749         # Set up, compile, and execute a test program containing VMX
750         # instructions.  Include the current process ID in the file
751         # names to prevent conflicts with invocations for multiple
752         # testsuites.
753         set src vmx[pid].c
754         set exe vmx[pid].x
755
756         set f [open $src "w"]
757         puts $f "int main() {"
758         puts $f "#ifdef __MACH__"
759         puts $f "  asm volatile (\"vor v0,v0,v0\");"
760         puts $f "#else"
761         puts $f "  asm volatile (\"vor 0,0,0\");"
762         puts $f "#endif"
763         puts $f "  return 0; }"
764         close $f
765
766         # Most targets don't require special flags for this test case, but
767         # Darwin does.
768         if [istarget *-*-darwin*] {
769           set opts "additional_flags=-maltivec"
770         } else {
771           set opts ""
772         }
773
774         verbose "check_vmx_hw_available  compiling testfile $src" 2
775         set lines [${tool}_target_compile $src $exe executable "$opts"]
776         file delete $src
777
778         if [string match "" $lines] then {
779             # No error message, compilation succeeded.
780             set result [${tool}_load "./$exe" "" ""]
781             set status [lindex $result 0]
782             remote_file build delete $exe
783             verbose "check_vmx_hw_available testfile status is <$status>" 2
784
785             if { $status == "pass" } then {
786                 set vmx_hw_available_saved 1
787             }
788         } else {
789             verbose "check_vmx_hw_availalble testfile compilation failed" 2
790         }
791     }
792
793     return $vmx_hw_available_saved
794 }
795
796 # GCC 3.4.0 for powerpc64-*-linux* included an ABI fix for passing
797 # complex float arguments.  This affects gfortran tests that call cabsf
798 # in libm built by an earlier compiler.  Return 1 if libm uses the same
799 # argument passing as the compiler under test, 0 otherwise.
800 #
801 # When the target name changes, replace the cached result.
802
803 proc check_effective_target_broken_cplxf_arg { } {
804     global et_broken_cplxf_arg_saved
805     global et_broken_cplxf_arg_target_name
806     global tool
807
808     # Skip the work for targets known not to be affected.
809     if { ![istarget powerpc64-*-linux*] } {
810         return 0
811     } elseif { [is-effective-target ilp32] } {
812         return 0
813     }
814
815     if { ![info exists et_broken_cplxf_arg_target_name] } {
816         set et_broken_cplxf_arg_target_name ""
817     }
818
819     # If the target has changed since we set the cached value, clear it.
820     set current_target [current_target_name]
821     if { $current_target != $et_broken_cplxf_arg_target_name } {
822         verbose "check_effective_target_broken_cplxf_arg: `$et_broken_cplxf_arg_target_name'" 2
823         set et_broken_cplxf_arg_target_name $current_target
824         if [info exists et_broken_cplxf_arg_saved] {
825             verbose "check_effective_target_broken_cplxf_arg: removing cached result" 2
826             unset et_broken_cplxf_arg_saved
827         }
828     }
829
830     if [info exists et_broken_cplxf_arg_saved] {
831         verbose "check_effective_target_broken_cplxf_arg: using cached result" 2
832     } else {
833         set et_broken_cplxf_arg_saved 0
834         # This is only known to affect one target.
835         if { ![istarget powerpc64-*-linux*] || ![is-effective-target lp64] } {
836             set et_broken_cplxf_arg_saved 0
837             verbose "check_effective_target_broken_cplxf_arg: caching 0" 2
838             return $et_broken_cplxf_arg_saved
839         }
840
841         # Set up, compile, and execute a C test program that calls cabsf.
842         set src cabsf[pid].c
843         set exe cabsf[pid].x
844
845         set f [open $src "w"]
846         puts $f "#include <complex.h>"
847         puts $f "extern void abort (void);"
848         puts $f "float fabsf (float);"
849         puts $f "float cabsf (_Complex float);"
850         puts $f "int main ()"
851         puts $f "{"
852         puts $f "  _Complex float cf;"
853         puts $f "  float f;"
854         puts $f "  cf = 3 + 4.0fi;"
855         puts $f "  f = cabsf (cf);"
856         puts $f "  if (fabsf (f - 5.0) > 0.0001) abort ();"
857         puts $f "  return 0;"
858         puts $f "}"
859         close $f
860
861         set lines [${tool}_target_compile $src $exe executable "-lm"]
862         file delete $src
863
864         if [string match "" $lines] {
865             # No error message, compilation succeeded.
866             set result [${tool}_load "./$exe" "" ""]
867             set status [lindex $result 0]
868             remote_file build delete $exe
869
870             verbose "check_effective_target_broken_cplxf_arg: status is <$status>" 2
871
872             if { $status != "pass" } {
873                 set et_broken_cplxf_arg_saved 1
874             }
875         } else {
876             verbose "check_effective_target_broken_cplxf_arg: compilation failed" 2
877         }
878     }
879     return $et_broken_cplxf_arg_saved
880 }
881
882 proc check_alpha_max_hw_available { } {
883     global alpha_max_hw_available_saved
884     global tool
885
886     if [info exists alpha_max_hw_available_saved] {
887         verbose "check_alpha_max_hw_available returning saved $alpha_max_hw_available_saved" 2
888     } else {
889         set alpha_max_hw_available_saved 0
890
891         # Set up, compile, and execute a test program probing bit 8 of the
892         # architecture mask, which indicates presence of MAX instructions.
893         set src max[pid].c
894         set exe max[pid].x
895
896         set f [open $src "w"]
897         puts $f "int main() { return __builtin_alpha_amask(1<<8) != 0; }"
898         close $f
899
900         verbose "check_alpha_max_hw_available compiling testfile $src" 2
901         set lines [${tool}_target_compile $src $exe executable ""]
902         file delete $src
903
904         if [string match "" $lines] then {
905             # No error message, compilation succeeded.
906             set result [${tool}_load "./$exe" "" ""]
907             set status [lindex $result 0]
908             remote_file build delete $exe
909             verbose "check_alpha_max_hw_available testfile status is <$status>" 2
910
911             if { $status == "pass" } then {
912                 set alpha_max_hw_available_saved 1
913             }
914         } else {
915             verbose "check_alpha_max_hw_availalble testfile compilation failed" 2
916         }
917     }
918
919     return $alpha_max_hw_available_saved
920 }
921
922 # Returns true iff the FUNCTION is available on the target system.
923 # (This is essentially a Tcl implementation of Autoconf's
924 # AC_CHECK_FUNC.)
925
926 proc check_function_available { function } {
927     set var "${function}_available_saved"
928     global $var
929     global tool
930
931     if {![info exists $var]} {
932         # Assume it exists.
933         set $var 1
934         # Check to make sure.
935         set src "function[pid].c"
936         set exe "function[pid].exe"
937
938         set f [open $src "w"]
939         puts $f "int main () { $function (); }"
940         close $f
941
942         set lines [${tool}_target_compile $src $exe executable ""]
943         file delete $src
944         file delete $exe
945
946         if {![string match "" $lines]} then {
947             set $var 0
948             verbose -log "$function is not available"
949         } else {
950             verbose -log "$function is available"
951         }
952     }
953
954     eval return \$$var
955 }
956
957 # Returns true iff "fork" is available on the target system.
958
959 proc check_fork_available {} {
960     return [check_function_available "fork"]
961 }
962
963 # Returns true iff "mkfifo" is available on the target system.
964
965 proc check_mkfifo_available {} {
966     if {[istarget *-*-cygwin*]} {
967        # Cygwin has mkfifo, but support is incomplete.
968        return 0
969      }
970
971     return [check_function_available "mkfifo"]
972 }
973
974 # Returns true iff "__cxa_atexit" is used on the target system.
975
976 proc check_cxa_atexit_available { } {
977     global et_cxa_atexit
978     global et_cxa_atexit_target_name
979     global tool 
980
981     if { ![info exists et_cxa_atexit_target_name] } {
982         set et_cxa_atexit_target_name ""
983     }
984
985     # If the target has changed since we set the cached value, clear it.
986     set current_target [current_target_name]
987     if { $current_target != $et_cxa_atexit_target_name } {
988         verbose "check_cxa_atexit_available: `$et_cxa_atexit_target_name'" 2
989         set et_cxa_atexit_target_name $current_target
990         if [info exists et_cxa_atexit] {
991             verbose "check_cxa_atexit_available: removing cached result" 2
992             unset et_cxa_atexit
993         }
994     }
995
996     if [info exists et_cxa_atexit] {
997         verbose "check_cxa_atexit_available: using cached result" 2
998     } else {
999         set et_cxa_atexit 0
1000
1001         # Set up, compile, and execute a C++ test program that depends
1002         # on correct ordering of static object destructors. This is
1003         # indicative of the presence and use of __cxa_atexit.
1004         set src cxaatexit[pid].cc
1005         set exe cxaatexit[pid].x
1006
1007         set f [open $src "w"]
1008         puts $f "#include <stdlib.h>"
1009         puts $f "static unsigned int count;"
1010         puts $f "struct X"
1011         puts $f "{"
1012         puts $f "  X() { count = 1; }"
1013         puts $f "  ~X()"
1014         puts $f "  {"
1015         puts $f "    if (count != 3)"
1016         puts $f "      exit(1);"
1017         puts $f "    count = 4;"
1018         puts $f "  }"
1019         puts $f "};"
1020         puts $f "void f()"
1021         puts $f "{"
1022         puts $f "  static X x;"
1023         puts $f "}"
1024         puts $f "struct Y"
1025         puts $f "{"
1026         puts $f "  Y() { f(); count = 2; }"
1027         puts $f "  ~Y()"
1028         puts $f "  {"
1029         puts $f "    if (count != 2)"
1030         puts $f "      exit(1);"
1031         puts $f "    count = 3;"
1032         puts $f "  }"
1033         puts $f "};"
1034         puts $f "Y y;"
1035         puts $f "int main()"
1036         puts $f "{ return 0; }"
1037         close $f
1038
1039         set lines [${tool}_target_compile $src $exe executable ""]
1040         file delete $src
1041
1042         if [string match "" $lines] {
1043             # No error message, compilation succeeded.
1044             set result [${tool}_load "./$exe" "" ""]
1045             set status [lindex $result 0]
1046             remote_file build delete $exe
1047
1048             verbose "check_cxa_atexit_available: status is <$status>" 2
1049
1050             if { $status == "pass" } {
1051                 set et_cxa_atexit 1
1052             }
1053         } else {
1054             verbose "check_cxa_atexit_available: compilation failed" 2
1055         }
1056     }
1057     return $et_cxa_atexit
1058 }
1059
1060
1061 # Return 1 if we're generating 32-bit code using default options, 0
1062 # otherwise.
1063
1064 proc check_effective_target_ilp32 { } {
1065     return [check_no_compiler_messages ilp32 object {
1066         int dummy[sizeof (int) == 4
1067                   && sizeof (void *) == 4
1068                   && sizeof (long) == 4 ? 1 : -1];
1069     }]
1070 }
1071
1072 # Return 1 if we're generating 32-bit or larger integers using default
1073 # options, 0 otherwise.
1074
1075 proc check_effective_target_int32plus { } {
1076     return [check_no_compiler_messages int32plus object {
1077         int dummy[sizeof (int) >= 4 ? 1 : -1];
1078     }]
1079 }
1080
1081 # Return 1 if we're generating 32-bit or larger pointers using default
1082 # options, 0 otherwise.
1083
1084 proc check_effective_target_ptr32plus { } {
1085     return [check_no_compiler_messages ptr32plus object {
1086         int dummy[sizeof (void *) >= 4 ? 1 : -1];
1087     }]
1088 }
1089
1090 # Return 1 if we support 32-bit or larger array and structure sizes
1091 # using default options, 0 otherwise.
1092
1093 proc check_effective_target_size32plus { } {
1094     return [check_no_compiler_messages size32plus object {
1095         char dummy[65537];
1096     }]
1097 }
1098
1099 # Returns 1 if we're generating 16-bit or smaller integers with the
1100 # default options, 0 otherwise.
1101
1102 proc check_effective_target_int16 { } {
1103     return [check_no_compiler_messages int16 object {
1104         int dummy[sizeof (int) < 4 ? 1 : -1];
1105     }]
1106 }
1107
1108 # Return 1 if we're generating 64-bit code using default options, 0
1109 # otherwise.
1110
1111 proc check_effective_target_lp64 { } {
1112     return [check_no_compiler_messages lp64 object {
1113         int dummy[sizeof (int) == 4
1114                   && sizeof (void *) == 8
1115                   && sizeof (long) == 8 ? 1 : -1];
1116     }]
1117 }
1118
1119 # Return 1 if the target supports compiling decimal floating point,
1120 # 0 otherwise.
1121
1122 proc check_effective_target_dfp_nocache { } {
1123     verbose "check_effective_target_dfp_nocache: compiling source" 2
1124     set ret [string match "" [get_compiler_messages dfp 0 object {
1125         _Decimal32 x; _Decimal64 y; _Decimal128 z;
1126     }]]
1127     verbose "check_effective_target_dfp_nocache: returning $ret" 2
1128     return $ret
1129 }
1130
1131 proc check_effective_target_dfprt_nocache { } {
1132     global tool
1133
1134     set ret 0
1135
1136     verbose "check_effective_target_dfprt_nocache: compiling source" 2
1137     # Set up, compile, and execute a test program containing decimal
1138     # float operations.
1139     set src dfprt[pid].c
1140     set exe dfprt[pid].x
1141
1142     set f [open $src "w"]
1143     puts $f "_Decimal32 x = 1.2df; _Decimal64 y = 2.3dd; _Decimal128 z;"
1144     puts $f "int main () { z = x + y; return 0; }"
1145     close $f
1146
1147     verbose "check_effective_target_dfprt_nocache: compiling testfile $src" 2
1148     set lines [${tool}_target_compile $src $exe executable ""]
1149     file delete $src
1150
1151     if [string match "" $lines] then {
1152         # No error message, compilation succeeded.
1153         set result [${tool}_load "./$exe" "" ""]
1154         set status [lindex $result 0]
1155         remote_file build delete $exe
1156         verbose "check_effective_target_dfprt_nocache: testfile status is <$status>" 2
1157         if { $status == "pass" } then {
1158             set ret 1
1159         }
1160     }
1161     return $ret
1162     verbose "check_effective_target_dfprt_nocache: returning $ret" 2
1163 }
1164
1165 # Return 1 if the target supports compiling Decimal Floating Point,
1166 # 0 otherwise.
1167 #
1168 # This won't change for different subtargets so cache the result.
1169
1170 proc check_effective_target_dfp { } {
1171     global et_dfp_saved
1172
1173     if [info exists et_dfp_saved] {
1174         verbose "check_effective_target_dfp: using cached result" 2
1175     } else {
1176         set et_dfp_saved [check_effective_target_dfp_nocache]
1177     }
1178     verbose "check_effective_target_dfp: returning $et_dfp_saved" 2
1179     return $et_dfp_saved
1180 }
1181
1182 # Return 1 if the target supports linking and executing Decimal Floating
1183 # Point, # 0 otherwise.
1184 #
1185 # This won't change for different subtargets so cache the result.
1186
1187 proc check_effective_target_dfprt { } {
1188     global et_dfprt_saved
1189     global tool
1190
1191     if [info exists et_dfprt_saved] {
1192         verbose "check_effective_target_dfprt: using cached result" 2
1193     } else {
1194         set et_dfprt_saved [check_effective_target_dfprt_nocache]
1195     }
1196     verbose "check_effective_target_dfprt: returning $et_dfprt_saved" 2
1197     return $et_dfprt_saved
1198 }
1199
1200 # Return 1 if the target needs a command line argument to enable a SIMD
1201 # instruction set.
1202 #
1203 # This won't change for different subtargets so cache the result.
1204
1205 proc check_effective_target_vect_cmdline_needed { } {
1206     global et_vect_cmdline_needed_saved
1207
1208     if [info exists et_vect_cmdline_needed_saved] {
1209         verbose "check_effective_target_vect_cmdline_needed: using cached result" 2
1210     } else {
1211         set et_vect_cmdline_needed_saved 1
1212         if { [istarget ia64-*-*]
1213               || [istarget x86_64-*-*] } {
1214            set et_vect_cmdline_needed_saved 0
1215         }
1216     }
1217
1218     verbose "check_effective_target_vect_cmdline_needed: returning $et_vect_cmdline_needed_saved" 2
1219     return $et_vect_cmdline_needed_saved
1220 }
1221
1222 # Return 1 if the target supports hardware vectors of int, 0 otherwise.
1223 #
1224 # This won't change for different subtargets so cache the result.
1225
1226 proc check_effective_target_vect_int { } {
1227     global et_vect_int_saved
1228
1229     if [info exists et_vect_int_saved] {
1230         verbose "check_effective_target_vect_int: using cached result" 2
1231     } else {
1232         set et_vect_int_saved 0
1233         if { [istarget i?86-*-*]
1234               || [istarget powerpc*-*-*]
1235               || [istarget x86_64-*-*]
1236               || [istarget sparc*-*-*]
1237               || [istarget alpha*-*-*]
1238               || [istarget ia64-*-*] } {
1239            set et_vect_int_saved 1
1240         }
1241     }
1242
1243     verbose "check_effective_target_vect_int: returning $et_vect_int_saved" 2
1244     return $et_vect_int_saved
1245 }
1246
1247 # Return 1 is this is an arm target using 32-bit instructions
1248 proc check_effective_target_arm32 { } {
1249     global et_arm32_saved
1250     global et_arm32_target_name
1251     global compiler_flags
1252
1253     if { ![info exists et_arm32_target_name] } {
1254         set et_arm32_target_name ""
1255     }
1256
1257     # If the target has changed since we set the cached value, clear it.
1258     set current_target [current_target_name]
1259     if { $current_target != $et_arm32_target_name } {
1260         verbose "check_effective_target_arm32: `$et_arm32_target_name' `$current_target'" 2
1261         set et_arm32_target_name $current_target
1262         if { [info exists et_arm32_saved] } {
1263             verbose "check_effective_target_arm32: removing cached result" 2
1264             unset et_arm32_saved
1265         }
1266     }
1267
1268     if [info exists et_arm32_saved] {
1269         verbose "check-effective_target_arm32: using cached result" 2
1270     } else {
1271         set et_arm32_saved 0
1272         if { [istarget arm-*-*]
1273               || [istarget strongarm*-*-*]
1274               || [istarget xscale-*-*] } {
1275             if ![string match "*-mthumb *" $compiler_flags] {
1276                 set et_arm32_saved 1
1277             }
1278         }
1279     }
1280     verbose "check_effective_target_arm32: returning $et_arm32_saved" 2
1281     return $et_arm32_saved
1282 }
1283
1284 # Return 1 if this is a PowerPC target with floating-point registers.
1285
1286 proc check_effective_target_powerpc_fprs { } {
1287     if { [istarget powerpc*-*-*]
1288          || [istarget rs6000-*-*] } {
1289         return [check_no_compiler_messages powerpc_fprs object {
1290             #ifdef __NO_FPRS__
1291             #error no FPRs
1292             #else
1293             int dummy;
1294             #endif
1295         }]
1296     } else {
1297         return 0
1298     }
1299 }
1300
1301 # Return 1 if this is a PowerPC target supporting -maltivec.
1302
1303 proc check_effective_target_powerpc_altivec_ok { } {
1304     if { [istarget powerpc*-*-*]
1305          || [istarget rs6000-*-*] } {
1306         # AltiVec is not supported on Aix.
1307         if { [istarget powerpc*-*-aix*] } {
1308             return 0
1309         }
1310         return [check_no_compiler_messages powerpc_altivec_ok object {
1311             int dummy;
1312         } "-maltivec"]
1313     } else {
1314         return 0
1315     }
1316 }
1317
1318 # Return 1 if the target supports hardware vector shift operation.
1319
1320 proc check_effective_target_vect_shift { } {
1321     global et_vect_shift_saved
1322
1323     if [info exists et_vect_shift_saved] {
1324         verbose "check_effective_target_vect_shift: using cached result" 2
1325     } else {
1326         set et_vect_shift_saved 0
1327         if { [istarget powerpc*-*-*]
1328              || [istarget ia64-*-*]
1329              || [istarget i?86-*-*]
1330              || [istarget x86_64-*-*] } {
1331            set et_vect_shift_saved 1
1332         }
1333     }
1334
1335     verbose "check_effective_target_vect_shift: returning $et_vect_shift_saved" 2
1336     return $et_vect_shift_saved
1337 }
1338
1339 # Return 1 if the target supports hardware vectors of long, 0 otherwise.
1340 #
1341 # This can change for different subtargets so do not cache the result.
1342
1343 proc check_effective_target_vect_long { } {
1344     if { [istarget i?86-*-*]
1345          || ([istarget powerpc*-*-*] && [check_effective_target_ilp32])
1346          || [istarget x86_64-*-*]
1347          || ([istarget sparc*-*-*] && [check_effective_target_ilp32]) } {
1348         set answer 1
1349     } else {
1350         set answer 0
1351     }
1352
1353     verbose "check_effective_target_vect_long: returning $answer" 2
1354     return $answer
1355 }
1356
1357 # Return 1 if the target supports hardware vectors of float, 0 otherwise.
1358 #
1359 # This won't change for different subtargets so cache the result.
1360
1361 proc check_effective_target_vect_float { } {
1362     global et_vect_float_saved
1363
1364     if [info exists et_vect_float_saved] {
1365         verbose "check_effective_target_vect_float: using cached result" 2
1366     } else {
1367         set et_vect_float_saved 0
1368         if { [istarget i?86-*-*]
1369               || [istarget powerpc*-*-*]
1370               || [istarget mipsisa64*-*-*]
1371               || [istarget x86_64-*-*]
1372               || [istarget ia64-*-*] } {
1373            set et_vect_float_saved 1
1374         }
1375     }
1376
1377     verbose "check_effective_target_vect_float: returning $et_vect_float_saved" 2
1378     return $et_vect_float_saved
1379 }
1380
1381 # Return 1 if the target supports hardware vectors of double, 0 otherwise.
1382 #
1383 # This won't change for different subtargets so cache the result.
1384
1385 proc check_effective_target_vect_double { } {
1386     global et_vect_double_saved
1387
1388     if [info exists et_vect_double_saved] {
1389         verbose "check_effective_target_vect_double: using cached result" 2
1390     } else {
1391         set et_vect_double_saved 0
1392         if { [istarget i?86-*-*]
1393               || [istarget x86_64-*-*] } {
1394            set et_vect_double_saved 1
1395         }
1396     }
1397
1398     verbose "check_effective_target_vect_double: returning $et_vect_double_saved" 2
1399     return $et_vect_double_saved
1400 }
1401
1402 # Return 1 if the target plus current options does not support a vector
1403 # max instruction on "int", 0 otherwise.
1404 #
1405 # This won't change for different subtargets so cache the result.
1406
1407 proc check_effective_target_vect_no_int_max { } {
1408     global et_vect_no_int_max_saved
1409
1410     if [info exists et_vect_no_int_max_saved] {
1411         verbose "check_effective_target_vect_no_int_max: using cached result" 2
1412     } else {
1413         set et_vect_no_int_max_saved 0
1414         if { [istarget sparc*-*-*]
1415              || [istarget alpha*-*-*] } {
1416             set et_vect_no_int_max_saved 1
1417         }
1418     }
1419     verbose "check_effective_target_vect_no_int_max: returning $et_vect_no_int_max_saved" 2
1420     return $et_vect_no_int_max_saved
1421 }
1422
1423 # Return 1 if the target plus current options does not support a vector
1424 # add instruction on "int", 0 otherwise.
1425 #
1426 # This won't change for different subtargets so cache the result.
1427
1428 proc check_effective_target_vect_no_int_add { } {
1429     global et_vect_no_int_add_saved
1430
1431     if [info exists et_vect_no_int_add_saved] {
1432         verbose "check_effective_target_vect_no_int_add: using cached result" 2
1433     } else {
1434         set et_vect_no_int_add_saved 0
1435         # Alpha only supports vector add on V8QI and V4HI.
1436         if { [istarget alpha*-*-*] } {
1437             set et_vect_no_int_add_saved 1
1438         }
1439     }
1440     verbose "check_effective_target_vect_no_int_add: returning $et_vect_no_int_add_saved" 2
1441     return $et_vect_no_int_add_saved
1442 }
1443
1444 # Return 1 if the target plus current options does not support vector
1445 # bitwise instructions, 0 otherwise.
1446 #
1447 # This won't change for different subtargets so cache the result.
1448
1449 proc check_effective_target_vect_no_bitwise { } {
1450     global et_vect_no_bitwise_saved
1451
1452     if [info exists et_vect_no_bitwise_saved] {
1453         verbose "check_effective_target_vect_no_bitwise: using cached result" 2
1454     } else {
1455         set et_vect_no_bitwise_saved 0
1456     }
1457     verbose "check_effective_target_vect_no_bitwise: returning $et_vect_no_bitwise_saved" 2
1458     return $et_vect_no_bitwise_saved
1459 }
1460
1461 # Return 1 if the target plus current options supports a vector
1462 # widening summation of *short* args into *int* result, 0 otherwise.
1463 #
1464 # This won't change for different subtargets so cache the result.
1465                                                                                                 
1466 proc check_effective_target_vect_widen_sum_hi_to_si { } {
1467     global et_vect_widen_sum_hi_to_si
1468                                                                                                 
1469     if [info exists et_vect_widen_sum_hi_to_si_saved] {
1470         verbose "check_effective_target_vect_widen_sum_hi_to_si: using cached result" 2
1471     } else {
1472         set et_vect_widen_sum_hi_to_si_saved 0
1473         if { [istarget powerpc*-*-*]
1474              || [istarget ia64-*-*] } {
1475             set et_vect_widen_sum_hi_to_si_saved 1
1476         }
1477     }
1478     verbose "check_effective_target_vect_widen_sum_hi_to_si: returning $et_vect_widen_sum_hi_to_si_saved" 2
1479     return $et_vect_widen_sum_hi_to_si_saved
1480 }
1481
1482 # Return 1 if the target plus current options supports a vector
1483 # widening summation of *char* args into *short* result, 0 otherwise.
1484 #
1485 # This won't change for different subtargets so cache the result.
1486                                                                                                 
1487 proc check_effective_target_vect_widen_sum_qi_to_hi { } {
1488     global et_vect_widen_sum_qi_to_hi
1489                                                                                                 
1490     if [info exists et_vect_widen_sum_qi_to_hi_saved] {
1491         verbose "check_effective_target_vect_widen_sum_qi_to_hi: using cached result" 2
1492     } else {
1493         set et_vect_widen_sum_qi_to_hi_saved 0
1494         if { [istarget ia64-*-*] } {
1495             set et_vect_widen_sum_qi_to_hi_saved 1
1496         }
1497     }
1498     verbose "check_effective_target_vect_widen_sum_qi_to_hi: returning $et_vect_widen_sum_qi_to_hi_saved" 2
1499     return $et_vect_widen_sum_qi_to_hi_saved
1500 }
1501
1502 # Return 1 if the target plus current options supports a vector
1503 # widening summation of *char* args into *int* result, 0 otherwise.
1504 #
1505 # This won't change for different subtargets so cache the result.
1506                                                                                                 
1507 proc check_effective_target_vect_widen_sum_qi_to_si { } {
1508     global et_vect_widen_sum_qi_to_si
1509                                                                                                 
1510     if [info exists et_vect_widen_sum_qi_to_si_saved] {
1511         verbose "check_effective_target_vect_widen_sum_qi_to_si: using cached result" 2
1512     } else {
1513         set et_vect_widen_sum_qi_to_si_saved 0
1514         if { [istarget powerpc*-*-*] } {
1515             set et_vect_widen_sum_qi_to_si_saved 1
1516         }
1517     }
1518     verbose "check_effective_target_vect_widen_sum_qi_to_si: returning $et_vect_widen_sum_qi_to_si_saved" 2
1519     return $et_vect_widen_sum_qi_to_si_saved
1520 }
1521
1522 # Return 1 if the target plus current options supports a vector
1523 # widening summation, 0 otherwise.
1524 #
1525 # This won't change for different subtargets so cache the result.
1526                                                                                                 
1527 proc check_effective_target_vect_widen_sum { } {
1528     global et_vect_widen_sum
1529                                                                                                 
1530     if [info exists et_vect_widen_sum_saved] {
1531         verbose "check_effective_target_vect_widen_sum: using cached result" 2
1532     } else {
1533         set et_vect_widen_sum_saved 0
1534         if { [istarget powerpc*-*-*]
1535              || [istarget ia64-*-*] } {
1536             set et_vect_widen_sum_saved 1
1537         }
1538     }
1539     verbose "check_effective_target_vect_widen_sum: returning $et_vect_widen_sum_saved" 2
1540     return $et_vect_widen_sum_saved
1541 }
1542
1543 # Return 1 if the target plus current options supports a vector
1544 # dot-product of signed chars, 0 otherwise.
1545 #
1546 # This won't change for different subtargets so cache the result.
1547
1548 proc check_effective_target_vect_sdot_qi { } {
1549     global et_vect_sdot_qi
1550
1551     if [info exists et_vect_sdot_qi_saved] {
1552         verbose "check_effective_target_vect_sdot_qi: using cached result" 2
1553     } else {
1554         set et_vect_sdot_qi_saved 0
1555         if { [istarget ia64-*-*] } {
1556             set et_vect_sdot_qi_saved 1
1557         }
1558     }
1559     verbose "check_effective_target_vect_sdot_qi: returning $et_vect_sdot_qi_saved" 2
1560     return $et_vect_sdot_qi_saved
1561 }
1562
1563 # Return 1 if the target plus current options supports a vector
1564 # dot-product of unsigned chars, 0 otherwise.
1565 #
1566 # This won't change for different subtargets so cache the result.
1567
1568 proc check_effective_target_vect_udot_qi { } {
1569     global et_vect_udot_qi
1570
1571     if [info exists et_vect_udot_qi_saved] {
1572         verbose "check_effective_target_vect_udot_qi: using cached result" 2
1573     } else {
1574         set et_vect_udot_qi_saved 0
1575         if { [istarget powerpc*-*-*]
1576              || [istarget ia64-*-*] } {
1577             set et_vect_udot_qi_saved 1
1578         }
1579     }
1580     verbose "check_effective_target_vect_udot_qi: returning $et_vect_udot_qi_saved" 2
1581     return $et_vect_udot_qi_saved
1582 }
1583
1584 # Return 1 if the target plus current options supports a vector
1585 # dot-product of signed shorts, 0 otherwise.
1586 #
1587 # This won't change for different subtargets so cache the result.
1588
1589 proc check_effective_target_vect_sdot_hi { } {
1590     global et_vect_sdot_hi
1591
1592     if [info exists et_vect_sdot_hi_saved] {
1593         verbose "check_effective_target_vect_sdot_hi: using cached result" 2
1594     } else {
1595         set et_vect_sdot_hi_saved 0
1596         if { [istarget powerpc*-*-*] 
1597              || [istarget i?86-*-*]
1598              || [istarget x86_64-*-*]
1599              || [istarget ia64-*-*] } {
1600             set et_vect_sdot_hi_saved 1
1601         }
1602     }
1603     verbose "check_effective_target_vect_sdot_hi: returning $et_vect_sdot_hi_saved" 2
1604     return $et_vect_sdot_hi_saved
1605 }
1606
1607 # Return 1 if the target plus current options supports a vector
1608 # dot-product of unsigned shorts, 0 otherwise.
1609 #
1610 # This won't change for different subtargets so cache the result.
1611
1612 proc check_effective_target_vect_udot_hi { } {
1613     global et_vect_udot_hi
1614
1615     if [info exists et_vect_udot_hi_saved] {
1616         verbose "check_effective_target_vect_udot_hi: using cached result" 2
1617     } else {
1618         set et_vect_udot_hi_saved 0
1619         if { [istarget powerpc*-*-*] } {
1620             set et_vect_udot_hi_saved 1
1621         }
1622     }
1623     verbose "check_effective_target_vect_udot_hi: returning $et_vect_udot_hi_saved" 2
1624     return $et_vect_udot_hi_saved
1625 }
1626
1627
1628 # Return 1 if the target plus current options does not support a vector
1629 # alignment mechanism, 0 otherwise.
1630 #
1631 # This won't change for different subtargets so cache the result.
1632
1633 proc check_effective_target_vect_no_align { } {
1634     global et_vect_no_align_saved
1635
1636     if [info exists et_vect_no_align_saved] {
1637         verbose "check_effective_target_vect_no_align: using cached result" 2
1638     } else {
1639         set et_vect_no_align_saved 0
1640         if { [istarget mipsisa64*-*-*]
1641              || [istarget sparc*-*-*]
1642              || [istarget ia64-*-*] } {
1643             set et_vect_no_align_saved 1
1644         }
1645     }
1646     verbose "check_effective_target_vect_no_align: returning $et_vect_no_align_saved" 2
1647     return $et_vect_no_align_saved
1648 }
1649
1650 # Return 1 if the target supports vector conditional operations, 0 otherwise.
1651
1652 proc check_effective_target_vect_condition { } {
1653     global et_vect_cond_saved
1654
1655     if [info exists et_vect_cond_saved] {
1656         verbose "check_effective_target_vect_cond: using cached result" 2
1657     } else {
1658         set et_vect_cond_saved 0
1659         if { [istarget powerpc*-*-*]
1660              || [istarget ia64-*-*]
1661              || [istarget i?86-*-*]
1662              || [istarget x86_64-*-*] } {
1663            set et_vect_cond_saved 1
1664         }
1665     }
1666
1667     verbose "check_effective_target_vect_cond: returning $et_vect_cond_saved" 2
1668     return $et_vect_cond_saved
1669 }
1670
1671 # Return 1 if the target supports vector char multiplication, 0 otherwise.
1672
1673 proc check_effective_target_vect_char_mult { } {
1674     global et_vect_char_mult_saved
1675
1676     if [info exists et_vect_char_mult_saved] {
1677         verbose "check_effective_target_vect_char_mult: using cached result" 2
1678     } else {
1679         set et_vect_char_mult_saved 0
1680         if { [istarget ia64-*-*]
1681              || [istarget i?86-*-*]
1682              || [istarget x86_64-*-*] } {
1683            set et_vect_char_mult_saved 1
1684         }
1685     }
1686
1687     verbose "check_effective_target_vect_char_mult: returning $et_vect_char_mult_saved" 2
1688     return $et_vect_char_mult_saved
1689 }
1690
1691 # Return 1 if the target supports vector short multiplication, 0 otherwise.
1692
1693 proc check_effective_target_vect_short_mult { } {
1694     global et_vect_short_mult_saved
1695
1696     if [info exists et_vect_short_mult_saved] {
1697         verbose "check_effective_target_vect_short_mult: using cached result" 2
1698     } else {
1699         set et_vect_short_mult_saved 0
1700         if { [istarget ia64-*-*]
1701              || [istarget i?86-*-*]
1702              || [istarget x86_64-*-*] } {
1703            set et_vect_short_mult_saved 1
1704         }
1705     }
1706
1707     verbose "check_effective_target_vect_short_mult: returning $et_vect_short_mult_saved" 2
1708     return $et_vect_short_mult_saved
1709 }
1710
1711 # Return 1 if the target supports vector int multiplication, 0 otherwise.
1712
1713 proc check_effective_target_vect_int_mult { } {
1714     global et_vect_int_mult_saved
1715
1716     if [info exists et_vect_int_mult_saved] {
1717         verbose "check_effective_target_vect_int_mult: using cached result" 2
1718     } else {
1719         set et_vect_int_mult_saved 0
1720         if { [istarget powerpc*-*-*]
1721              || [istarget i?86-*-*]
1722              || [istarget x86_64-*-*] } {
1723            set et_vect_int_mult_saved 1
1724         }
1725     }
1726
1727     verbose "check_effective_target_vect_int_mult: returning $et_vect_int_mult_saved" 2
1728     return $et_vect_int_mult_saved
1729 }
1730
1731 # Return 1 if the target supports section-anchors
1732
1733 proc check_effective_target_section_anchors { } {
1734     global et_section_anchors_saved
1735
1736     if [info exists et_section_anchors_saved] {
1737         verbose "check_effective_target_section_anchors: using cached result" 2
1738     } else {
1739         set et_section_anchors_saved 0
1740         if { [istarget powerpc*-*-*] } {
1741            set et_section_anchors_saved 1
1742         }
1743     }
1744
1745     verbose "check_effective_target_section_anchors: returning $et_section_anchors_saved" 2
1746     return $et_section_anchors_saved
1747 }
1748
1749 # Return 1 if the target supports atomic operations on "int" and "long".
1750
1751 proc check_effective_target_sync_int_long { } {
1752     global et_sync_int_long_saved
1753
1754     if [info exists et_sync_int_long_saved] {
1755         verbose "check_effective_target_sync_int_long: using cached result" 2
1756     } else {
1757         set et_sync_int_long_saved 0
1758 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
1759 # load-reserved/store-conditional instructions.
1760         if { [istarget ia64-*-*]
1761              || [istarget i?86-*-*]
1762              || [istarget x86_64-*-*]
1763              || [istarget alpha*-*-*] 
1764              || [istarget s390*-*-*] 
1765              || [istarget powerpc*-*-*]
1766              || [istarget sparc64-*-*]
1767              || [istarget sparcv9-*-*] } {
1768            set et_sync_int_long_saved 1
1769         }
1770     }
1771
1772     verbose "check_effective_target_sync_int_long: returning $et_sync_int_long_saved" 2
1773     return $et_sync_int_long_saved
1774 }
1775
1776 # Return 1 if the target supports atomic operations on "char" and "short".
1777
1778 proc check_effective_target_sync_char_short { } {
1779     global et_sync_char_short_saved
1780
1781     if [info exists et_sync_char_short_saved] {
1782         verbose "check_effective_target_sync_char_short: using cached result" 2
1783     } else {
1784         set et_sync_char_short_saved 0
1785 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
1786 # load-reserved/store-conditional instructions.
1787         if { [istarget ia64-*-*]
1788              || [istarget i?86-*-*]
1789              || [istarget x86_64-*-*]
1790              || [istarget alpha*-*-*] 
1791              || [istarget s390*-*-*] 
1792              || [istarget powerpc*-*-*]
1793              || [istarget sparc64-*-*]
1794              || [istarget sparcv9-*-*] } {
1795            set et_sync_char_short_saved 1
1796         }
1797     }
1798
1799     verbose "check_effective_target_sync_char_short: returning $et_sync_char_short_saved" 2
1800     return $et_sync_char_short_saved
1801 }
1802
1803 # Return 1 if the target matches the effective target 'arg', 0 otherwise.
1804 # This can be used with any check_* proc that takes no argument and
1805 # returns only 1 or 0.  It could be used with check_* procs that take
1806 # arguments with keywords that pass particular arguments.
1807
1808 proc is-effective-target { arg } {
1809     set selected 0
1810     if { [info procs check_effective_target_${arg}] != [list] } {
1811         set selected [check_effective_target_${arg}]
1812     } else {
1813         switch $arg {
1814           "vmx_hw"         { set selected [check_vmx_hw_available] }
1815           "named_sections" { set selected [check_named_sections_available] }
1816           "gc_sections"    { set selected [check_gc_sections_available] }
1817           "cxa_atexit"     { set selected [check_cxa_atexit_available] }
1818           default          { error "unknown effective target keyword `$arg'" }
1819         }
1820     }
1821     verbose "is-effective-target: $arg $selected" 2
1822     return $selected
1823 }
1824
1825 # Return 1 if the argument is an effective-target keyword, 0 otherwise.
1826
1827 proc is-effective-target-keyword { arg } {
1828     if { [info procs check_effective_target_${arg}] != [list] } {
1829         return 1
1830     } else {
1831         # These have different names for their check_* procs.
1832         switch $arg {
1833           "vmx_hw"         { return 1 }
1834           "named_sections" { return 1 }
1835           "gc_sections"    { return 1 }
1836           "cxa_atexit"     { return 1 }
1837           default          { return 0 }
1838         }
1839     }
1840 }
1841
1842 # Return 1 if target default to short enums
1843
1844 proc check_effective_target_short_enums { } {
1845     return [check_no_compiler_messages short_enums assembly {
1846         enum foo { bar };
1847         int s[sizeof (enum foo) == 1 ? 1 : -1];
1848     }]
1849 }
1850
1851 # Return 1 if target supports merging string constants at link time.
1852
1853 proc check_effective_target_string_merging { } {
1854     return [check_no_messages_and_pattern string_merging \
1855                 "rodata\\.str" assembly {
1856                     const char *var = "String";
1857                 } {-O2}]
1858 }