OSDN Git Service

* lib/target-supports.exp (check_gc_sections_available):
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / target-supports.exp
1 #   Copyright (C) 1999, 2001, 2003, 2004, 2005, 2006, 2007
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 [list "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 { [istarget "hppa*-*-hpux10*"] } {
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         # elf2flt uses -q (--emit-relocs), which is incompatible with
290         # --gc-sections.
291         if { [board_info target exists ldflags]
292              && [regexp " -elf2flt\[ =\]" " [board_info target ldflags] "] } {
293             set gc_sections_available_saved 0
294             return 0
295         }
296
297         # VxWorks kernel modules are relocatable objects linked with -r,
298         # while RTP executables are linked with -q (--emit-relocs).
299         # Both of these options are incompatible with --gc-sections.
300         if { [istarget *-*-vxworks*] } {
301             set gc_sections_available_saved 0
302             return 0
303         }
304
305         # Check if the ld used by gcc supports --gc-sections.
306         set gcc_spec [${tool}_target_compile "-dumpspecs" "" "none" ""]
307         regsub ".*\n\*linker:\[ \t\]*\n(\[^ \t\n\]*).*" "$gcc_spec" {\1} linker
308         set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=$linker" "" "none" ""] 0]
309         set ld_output [remote_exec host "$gcc_ld" "--help"]
310         if { [ string first "--gc-sections" $ld_output ] >= 0 } {
311             set gc_sections_available_saved 1
312         } else {
313             set gc_sections_available_saved 0
314         }
315     }
316     return $gc_sections_available_saved
317 }
318
319 # Return true if profiling is supported on the target.
320
321 proc check_profiling_available { test_what } {
322     global profiling_available_saved
323
324     verbose "Profiling argument is <$test_what>" 1
325
326     # These conditions depend on the argument so examine them before
327     # looking at the cache variable.
328
329     # Support for -p on solaris2 relies on mcrt1.o which comes with the
330     # vendor compiler.  We cannot reliably predict the directory where the
331     # vendor compiler (and thus mcrt1.o) is installed so we can't
332     # necessarily find mcrt1.o even if we have it.
333     if { [istarget *-*-solaris2*] && [lindex $test_what 1] == "-p" } {
334         return 0
335     }
336
337     # Support for -p on irix relies on libprof1.a which doesn't appear to
338     # exist on any irix6 system currently posting testsuite results.
339     # Support for -pg on irix relies on gcrt1.o which doesn't exist yet.
340     # See: http://gcc.gnu.org/ml/gcc/2002-10/msg00169.html
341     if { [istarget mips*-*-irix*]
342     && ([lindex $test_what 1] == "-p" || [lindex $test_what 1] == "-pg") } {
343         return 0
344     }
345
346     # At present, there is no profiling support on NetWare.
347     if { [istarget *-*-netware*] } {
348         return 0
349     }
350
351     # Now examine the cache variable.
352     if {![info exists profiling_available_saved]} {
353         # Some targets don't have any implementation of __bb_init_func or are
354         # missing other needed machinery.
355         if { [istarget mmix-*-*]
356              || [istarget arm*-*-eabi*]
357              || [istarget arm*-*-elf]
358              || [istarget arm*-*-symbianelf*]
359              || [istarget bfin-*-*]
360              || [istarget powerpc-*-eabi*]
361              || [istarget strongarm*-*-elf]
362              || [istarget xscale*-*-elf]
363              || [istarget cris-*-*]
364              || [istarget h8300-*-*]
365              || [istarget m32c-*-elf]
366              || [istarget m68k-*-elf]
367              || [istarget mips*-*-elf]
368              || [istarget xtensa-*-elf]
369              || [istarget *-*-vxworks*]
370              || [istarget *-*-windiss] } {
371             set profiling_available_saved 0
372         } else {
373             set profiling_available_saved 1
374         }
375     }
376
377     return $profiling_available_saved
378 }
379
380 # Return 1 if target has packed layout of structure members by
381 # default, 0 otherwise.  Note that this is slightly different than
382 # whether the target has "natural alignment": both attributes may be
383 # false.
384
385 proc check_effective_target_default_packed { } {
386     return [check_no_compiler_messages default_packed assembly {
387         struct x { char a; long b; } c;
388         int s[sizeof (c) == sizeof (char) + sizeof (long) ? 1 : -1];
389     }]
390 }
391
392 # Return 1 if target has PCC_BITFIELD_TYPE_MATTERS defined.  See
393 # documentation, where the test also comes from.
394
395 proc check_effective_target_pcc_bitfield_type_matters { } {
396     # PCC_BITFIELD_TYPE_MATTERS isn't just about unnamed or empty
397     # bitfields, but let's stick to the example code from the docs.
398     return [check_no_compiler_messages pcc_bitfield_type_matters assembly {
399         struct foo1 { char x; char :0; char y; };
400         struct foo2 { char x; int :0; char y; };
401         int s[sizeof (struct foo1) != sizeof (struct foo2) ? 1 : -1];
402     }]
403 }
404
405 # Return 1 if *native* thread local storage (TLS) is supported, 0 otherwise.
406 #
407 # This won't change for different subtargets so cache the result.
408
409 proc check_effective_target_tls {} {
410     global et_tls_saved
411     global tool
412
413     if [info exists et_tls_saved] {
414         verbose "check_effective_target_tls: using cached result" 2
415     } else {
416         set et_tls_saved 1
417
418         set src tls[pid].c
419         set asm tls[pid].S
420         verbose "check_effective_target_tls: compiling testfile $src" 2
421         set f [open $src "w"]
422         # Compile a small test program.
423         puts $f "__thread int i;\n"
424         close $f
425
426         # Test for thread-local data supported by the platform.
427         set comp_output [${tool}_target_compile $src $asm assembly ""]
428         file delete $src
429         if { [string match "*not supported*" $comp_output] } {
430             set et_tls_saved 0
431         } else {
432             set fd [open $asm r]
433             set text [read $fd]
434             close $fd
435             if { [string match "*emutls*" $text]} {
436                 set et_tls_saved 0
437             } else {
438                 set et_tls_saved 1
439             }
440         }
441         remove-build-file $asm
442     }
443     verbose "check_effective_target_tls: returning $et_tls_saved" 2
444     return $et_tls_saved
445 }
446
447 # Return 1 if TLS executables can run correctly, 0 otherwise.
448 #
449 # This won't change for different subtargets so cache the result.
450
451 proc check_effective_target_tls_runtime {} {
452     global et_tls_runtime_saved
453     global tool
454
455     if [info exists et_tls_runtime_saved] {
456         verbose "check_effective_target_tls_runtime: using cached result" 2
457     } else {
458         set et_tls_runtime_saved 0
459
460         set src tls_runtime[pid].c
461         set exe tls_runtime[pid].x
462         verbose "check_effective_target_tls_runtime: compiling testfile $src" 2
463         set f [open $src "w"]
464         # Compile a small test program.
465         puts $f "__thread int thr = 0;\n"
466         puts $f "int main(void)\n {\n return thr;\n}"
467         close $f
468
469         set comp_output \
470             [${tool}_target_compile $src $exe executable ""]
471         file delete $src
472
473         if [string match "" $comp_output] then {
474             # No error messages, everything is OK.
475
476             set result [remote_load target "./$exe" "" ""]
477             set status [lindex $result 0]
478             remote_file build delete $exe
479
480             verbose "check_effective_target_tls_runtime status is <$status>" 2
481
482             if { $status == "pass" } {
483                 set et_tls_runtime_saved 1
484             }
485
486             verbose "check_effective_target_tls_runtime: returning $et_tls_runtime_saved" 2
487         }
488     }
489
490     return $et_tls_runtime_saved
491 }
492
493 # Return 1 if compilation with -fopenmp is error-free for trivial
494 # code, 0 otherwise.
495
496 proc check_effective_target_fopenmp {} {
497     return [check_no_compiler_messages fopenmp object {
498         void foo (void) { }
499     } "-fopenmp"]
500 }
501
502 # Return 1 if the target supports -fstack-protector
503 proc check_effective_target_fstack_protector {} {
504     global tool
505     set result ""
506
507     set src stack_prot[pid].c
508     set exe stack_prot[pid].x
509
510     verbose "check_effective_target_fstack_protector compiling testfile $src" 2
511
512     set f [open $src "w"]
513     # Compile a small test program.
514     puts $f "int main (void)\n { return 0; }\n"
515     close $f
516
517     set opts "additional_flags=-fstack-protector"
518     set lines [${tool}_target_compile $src $exe executable "$opts" ]
519     file delete $src
520
521     if [string match "" $lines] then {
522         # No error messages, everything is OK.
523         set result [${tool}_load "./$exe" "" ""]
524         set status [lindex $result 0]
525         remote_file build delete $exe
526         verbose "check_iconv_available status is <$status>" 2
527
528         if { $status == "pass" } then {
529             return 1
530         }
531     }
532     return 0
533 }
534
535 # Return 1 if compilation with -freorder-blocks-and-partition is error-free
536 # for trivial code, 0 otherwise.
537
538 proc check_effective_target_freorder {} {
539     return [check_no_compiler_messages freorder object {
540         void foo (void) { }
541     } "-freorder-blocks-and-partition"]
542 }
543
544 # Return 1 if -fpic and -fPIC are supported, as in no warnings or errors
545 # emitted, 0 otherwise.  Whether a shared library can actually be built is
546 # out of scope for this test.
547
548 proc check_effective_target_fpic { } {
549     # Note that M68K has a multilib that supports -fpic but not
550     # -fPIC, so we need to check both.  We test with a program that
551     # requires GOT references.
552     foreach arg {fpic fPIC} {
553         if [check_no_compiler_messages $arg object {
554             extern int foo (void); extern int bar;
555             int baz (void) { return foo () + bar; }
556         } "-$arg"] {
557             return 1
558         }
559     }
560     return 0
561 }
562
563 # Return true if the target supports -mpaired-single (as used on MIPS).
564
565 proc check_effective_target_mpaired_single { } {
566     return [check_no_compiler_messages mpaired_single object {
567         void foo (void) { }
568     } "-mpaired-single"]
569 }
570
571 # Return 1 if the current multilib does not generate PIC by default.
572
573 proc check_effective_target_nonpic { } {
574     return [check_no_compiler_messages nonpic assembly {
575         #if __PIC__
576         #error FOO
577         #endif
578     }]
579 }
580
581 # Return 1 if the target does not use a status wrapper.
582
583 proc check_effective_target_unwrapped { } {
584     if { [target_info needs_status_wrapper] != "" \
585              && [target_info needs_status_wrapper] != "0" } {
586         return 0
587     }
588     return 1
589 }
590
591 # Return true if iconv is supported on the target. In particular IBM1047.
592
593 proc check_iconv_available { test_what } {
594     global tool
595     global libiconv
596
597     set result ""
598
599     set src iconv[pid].c
600     set exe iconv[pid].x
601     verbose "check_iconv_available compiling testfile $src" 2
602     set f [open $src "w"]
603     # Compile a small test program.
604     puts $f "#include <iconv.h>\n"
605     puts $f "int main (void)\n {\n iconv_t cd; \n"
606     puts $f "cd = iconv_open (\"[lindex $test_what 1]\", \"UTF-8\");\n"
607     puts $f "if (cd == (iconv_t) -1)\n return 1;\n"
608     puts $f "return 0;\n}"
609     close $f
610
611     # If the tool configuration file has not set libiconv, try "-liconv"
612     if { ![info exists libiconv] } {
613         set libiconv "-liconv"
614     }
615     set lines [${tool}_target_compile $src $exe executable "libs=$libiconv" ]
616     file delete $src
617
618     if [string match "" $lines] then {
619         # No error messages, everything is OK.
620
621         set result [${tool}_load "./$exe" "" ""]
622         set status [lindex $result 0]
623         remote_file build delete $exe
624
625         verbose "check_iconv_available status is <$status>" 2
626
627         if { $status == "pass" } then {
628             return 1
629         }
630     }
631
632     return 0
633 }
634
635 # Return true if named sections are supported on this target.
636
637 proc check_named_sections_available { } {
638     return [check_no_compiler_messages named_sections assembly {
639         int __attribute__ ((section("whatever"))) foo;
640     }]
641 }
642
643 # Return 1 if the target supports Fortran real kinds larger than real(8),
644 # 0 otherwise.
645 #
646 # When the target name changes, replace the cached result.
647
648 proc check_effective_target_fortran_large_real { } {
649     global et_fortran_large_real_saved
650     global et_fortran_large_real_target_name
651     global tool
652
653     if { ![info exists et_fortran_large_real_target_name] } {
654         set et_fortran_large_real_target_name ""
655     }
656
657     # If the target has changed since we set the cached value, clear it.
658     set current_target [current_target_name]
659     if { $current_target != $et_fortran_large_real_target_name } {
660         verbose "check_effective_target_fortran_large_real: `$et_fortran_large_real_target_name' `$current_target'" 2
661         set et_fortran_large_real_target_name $current_target
662         if [info exists et_fortran_large_real_saved] {
663             verbose "check_effective_target_fortran_large_real: removing cached result" 2
664             unset et_fortran_large_real_saved
665         }
666     }
667
668     if [info exists et_fortran_large_real_saved] {
669         verbose "check_effective_target_fortran_large_real returning saved $et_fortran_large_real_saved" 2
670     } else {
671         set et_fortran_large_real_saved 0
672
673         # Set up, compile, and execute a test program using large real
674         # kinds.  Include the current process ID in the file names to
675         # prevent conflicts with invocations for multiple testsuites.
676         set src real[pid].f90
677         set exe real[pid].x
678
679         set f [open $src "w"]
680         puts $f "integer,parameter :: k = &"
681         puts $f "  selected_real_kind (precision (0.0_8) + 1)"
682         puts $f "real(kind=k) :: x"
683         puts $f "x = cos (x);"
684         puts $f "end"
685         close $f
686
687         verbose "check_effective_target_fortran_large_real compiling testfile $src" 2
688         set lines [${tool}_target_compile $src $exe executable ""]
689         file delete $src
690
691         if [string match "" $lines] then {
692             # No error message, compilation succeeded.
693             remote_file build delete $exe
694             set et_fortran_large_real_saved 1
695         }
696     }
697
698     return $et_fortran_large_real_saved
699 }
700
701 # Return 1 if the target supports Fortran integer kinds larger than
702 # integer(8), 0 otherwise.
703 #
704 # When the target name changes, replace the cached result.
705
706 proc check_effective_target_fortran_large_int { } {
707     global et_fortran_large_int_saved
708     global et_fortran_large_int_target_name
709     global tool
710
711     if { ![info exists et_fortran_large_int_target_name] } {
712         set et_fortran_large_int_target_name ""
713     }
714
715     # If the target has changed since we set the cached value, clear it.
716     set current_target [current_target_name]
717     if { $current_target != $et_fortran_large_int_target_name } {
718         verbose "check_effective_target_fortran_large_int: `$et_fortran_large_int_target_name' `$current_target'" 2
719         set et_fortran_large_int_target_name $current_target
720         if [info exists et_fortran_large_int_saved] {
721             verbose "check_effective_target_fortran_large_int: removing cached result" 2
722             unset et_fortran_large_int_saved
723         }
724     }
725
726     if [info exists et_fortran_large_int_saved] {
727         verbose "check_effective_target_fortran_large_int returning saved $et_fortran_large_int_saved" 2
728     } else {
729         set et_fortran_large_int_saved 0
730
731         # Set up, compile, and execute a test program using large integer
732         # kinds.  Include the current process ID in the file names to
733         # prevent conflicts with invocations for multiple testsuites.
734         set src int[pid].f90
735         set exe int[pid].x
736
737         set f [open $src "w"]
738         puts $f "integer,parameter :: k = &"
739         puts $f "  selected_int_kind (range (0_8) + 1)"
740         puts $f "integer(kind=k) :: i"
741         puts $f "end"
742         close $f
743
744         verbose "check_effective_target_fortran_large_int compiling testfile $src" 2
745         set lines [${tool}_target_compile $src $exe executable ""]
746         file delete $src
747
748         if [string match "" $lines] then {
749             # No error message, compilation succeeded.
750             remote_file build delete $exe
751             set et_fortran_large_int_saved 1
752         }
753     }
754
755     return $et_fortran_large_int_saved
756 }
757
758 # Return 1 if we can statically link libgfortran, 0 otherwise.
759 #
760 # When the target name changes, replace the cached result.
761
762 proc check_effective_target_static_libgfortran { } {
763     global et_static_libgfortran
764     global et_static_libgfortran_target_name
765     global tool
766
767     if { ![info exists et_static_libgfortran_target_name] } {
768        set et_static_libgfortran_target_name ""
769     }
770
771     # If the target has changed since we set the cached value, clear it.
772     set current_target [current_target_name]
773     if { $current_target != $et_static_libgfortran_target_name } {
774        verbose "check_effective_target_static_libgfortran: `$et_static_libgfortran_target_name' `$current_target'" 2
775        set et_static_libgfortran_target_name $current_target
776        if [info exists et_static_libgfortran_saved] {
777            verbose "check_effective_target_static_libgfortran: removing cached result" 2
778            unset et_static_libgfortran_saved
779        }
780     }
781
782     if [info exists et_static_libgfortran_saved] {
783        verbose "check_effective_target_static_libgfortran returning saved $et_static_libgfortran_saved" 2
784     } else {
785        set et_static_libgfortran_saved 0
786
787        # Set up, compile, and execute a test program using static linking.
788        # Include the current process ID in the file names to prevent
789        # conflicts with invocations for multiple testsuites.
790        set opts "additional_flags=-static"
791        set src static[pid].f
792        set exe static[pid].x
793
794        set f [open $src "w"]
795        puts $f "      print *, 'test'"
796        puts $f "      end"
797        close $f
798
799        verbose "check_effective_target_static_libgfortran compiling testfile $src" 2
800        set lines [${tool}_target_compile $src $exe executable "$opts"]
801        file delete $src
802
803        if [string match "" $lines] then {
804            # No error message, compilation succeeded.
805            remote_file build delete $exe
806            set et_static_libgfortran_saved 1
807        }
808     }
809
810     return $et_static_libgfortran_saved
811 }
812
813 # Return 1 if the target supports executing AltiVec instructions, 0
814 # otherwise.  Cache the result.
815
816 proc check_vmx_hw_available { } {
817     global vmx_hw_available_saved
818     global tool
819
820     if [info exists vmx_hw_available_saved] {
821         verbose "check_hw_available  returning saved $vmx_hw_available_saved" 2
822     } else {
823         set vmx_hw_available_saved 0
824
825         # Some simulators are known to not support VMX instructions.
826         if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
827             verbose "check_hw_available  returning 0" 2
828             return $vmx_hw_available_saved
829         }
830
831         # Set up, compile, and execute a test program containing VMX
832         # instructions.  Include the current process ID in the file
833         # names to prevent conflicts with invocations for multiple
834         # testsuites.
835         set src vmx[pid].c
836         set exe vmx[pid].x
837
838         set f [open $src "w"]
839         puts $f "int main() {"
840         puts $f "#ifdef __MACH__"
841         puts $f "  asm volatile (\"vor v0,v0,v0\");"
842         puts $f "#else"
843         puts $f "  asm volatile (\"vor 0,0,0\");"
844         puts $f "#endif"
845         puts $f "  return 0; }"
846         close $f
847
848         # Most targets don't require special flags for this test case, but
849         # Darwin does.
850         if [istarget *-*-darwin*] {
851           set opts "additional_flags=-maltivec"
852         } else {
853           set opts ""
854         }
855
856         verbose "check_vmx_hw_available  compiling testfile $src" 2
857         set lines [${tool}_target_compile $src $exe executable "$opts"]
858         file delete $src
859
860         if [string match "" $lines] then {
861             # No error message, compilation succeeded.
862             set result [${tool}_load "./$exe" "" ""]
863             set status [lindex $result 0]
864             remote_file build delete $exe
865             verbose "check_vmx_hw_available testfile status is <$status>" 2
866
867             if { $status == "pass" } then {
868                 set vmx_hw_available_saved 1
869             }
870         } else {
871             verbose "check_vmx_hw_availalble testfile compilation failed" 2
872         }
873     }
874
875     return $vmx_hw_available_saved
876 }
877
878 # GCC 3.4.0 for powerpc64-*-linux* included an ABI fix for passing
879 # complex float arguments.  This affects gfortran tests that call cabsf
880 # in libm built by an earlier compiler.  Return 1 if libm uses the same
881 # argument passing as the compiler under test, 0 otherwise.
882 #
883 # When the target name changes, replace the cached result.
884
885 proc check_effective_target_broken_cplxf_arg { } {
886     global et_broken_cplxf_arg_saved
887     global et_broken_cplxf_arg_target_name
888     global tool
889
890     # Skip the work for targets known not to be affected.
891     if { ![istarget powerpc64-*-linux*] } {
892         return 0
893     } elseif { [is-effective-target ilp32] } {
894         return 0
895     }
896
897     if { ![info exists et_broken_cplxf_arg_target_name] } {
898         set et_broken_cplxf_arg_target_name ""
899     }
900
901     # If the target has changed since we set the cached value, clear it.
902     set current_target [current_target_name]
903     if { $current_target != $et_broken_cplxf_arg_target_name } {
904         verbose "check_effective_target_broken_cplxf_arg: `$et_broken_cplxf_arg_target_name'" 2
905         set et_broken_cplxf_arg_target_name $current_target
906         if [info exists et_broken_cplxf_arg_saved] {
907             verbose "check_effective_target_broken_cplxf_arg: removing cached result" 2
908             unset et_broken_cplxf_arg_saved
909         }
910     }
911
912     if [info exists et_broken_cplxf_arg_saved] {
913         verbose "check_effective_target_broken_cplxf_arg: using cached result" 2
914     } else {
915         set et_broken_cplxf_arg_saved 0
916         # This is only known to affect one target.
917         if { ![istarget powerpc64-*-linux*] || ![is-effective-target lp64] } {
918             set et_broken_cplxf_arg_saved 0
919             verbose "check_effective_target_broken_cplxf_arg: caching 0" 2
920             return $et_broken_cplxf_arg_saved
921         }
922
923         # Set up, compile, and execute a C test program that calls cabsf.
924         set src cabsf[pid].c
925         set exe cabsf[pid].x
926
927         set f [open $src "w"]
928         puts $f "#include <complex.h>"
929         puts $f "extern void abort (void);"
930         puts $f "float fabsf (float);"
931         puts $f "float cabsf (_Complex float);"
932         puts $f "int main ()"
933         puts $f "{"
934         puts $f "  _Complex float cf;"
935         puts $f "  float f;"
936         puts $f "  cf = 3 + 4.0fi;"
937         puts $f "  f = cabsf (cf);"
938         puts $f "  if (fabsf (f - 5.0) > 0.0001) abort ();"
939         puts $f "  return 0;"
940         puts $f "}"
941         close $f
942
943         set lines [${tool}_target_compile $src $exe executable "-lm"]
944         file delete $src
945
946         if [string match "" $lines] {
947             # No error message, compilation succeeded.
948             set result [${tool}_load "./$exe" "" ""]
949             set status [lindex $result 0]
950             remote_file build delete $exe
951
952             verbose "check_effective_target_broken_cplxf_arg: status is <$status>" 2
953
954             if { $status != "pass" } {
955                 set et_broken_cplxf_arg_saved 1
956             }
957         } else {
958             verbose "check_effective_target_broken_cplxf_arg: compilation failed" 2
959         }
960     }
961     return $et_broken_cplxf_arg_saved
962 }
963
964 proc check_alpha_max_hw_available { } {
965     global alpha_max_hw_available_saved
966     global tool
967
968     if [info exists alpha_max_hw_available_saved] {
969         verbose "check_alpha_max_hw_available returning saved $alpha_max_hw_available_saved" 2
970     } else {
971         set alpha_max_hw_available_saved 0
972
973         # Set up, compile, and execute a test program probing bit 8 of the
974         # architecture mask, which indicates presence of MAX instructions.
975         set src max[pid].c
976         set exe max[pid].x
977
978         set f [open $src "w"]
979         puts $f "int main() { return __builtin_alpha_amask(1<<8) != 0; }"
980         close $f
981
982         verbose "check_alpha_max_hw_available compiling testfile $src" 2
983         set lines [${tool}_target_compile $src $exe executable ""]
984         file delete $src
985
986         if [string match "" $lines] then {
987             # No error message, compilation succeeded.
988             set result [${tool}_load "./$exe" "" ""]
989             set status [lindex $result 0]
990             remote_file build delete $exe
991             verbose "check_alpha_max_hw_available testfile status is <$status>" 2
992
993             if { $status == "pass" } then {
994                 set alpha_max_hw_available_saved 1
995             }
996         } else {
997             verbose "check_alpha_max_hw_availalble testfile compilation failed" 2
998         }
999     }
1000
1001     return $alpha_max_hw_available_saved
1002 }
1003
1004 # Returns true iff the FUNCTION is available on the target system.
1005 # (This is essentially a Tcl implementation of Autoconf's
1006 # AC_CHECK_FUNC.)
1007
1008 proc check_function_available { function } {
1009     set var "${function}_available_saved"
1010     global $var
1011     global tool
1012
1013     if {![info exists $var]} {
1014         # Assume it exists.
1015         set $var 1
1016         # Check to make sure.
1017         set src "function[pid].c"
1018         set exe "function[pid].exe"
1019
1020         set f [open $src "w"]
1021         puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
1022         puts $f "char $function ();\n"
1023         puts $f "int main () { $function (); }"
1024         close $f
1025
1026         set lines [${tool}_target_compile $src $exe executable ""]
1027         file delete $src
1028         file delete $exe
1029
1030         if {![string match "" $lines]} then {
1031             set $var 0
1032             verbose -log "$function is not available"
1033         } else {
1034             verbose -log "$function is available"
1035         }
1036     }
1037
1038     eval return \$$var
1039 }
1040
1041 # Returns true iff "fork" is available on the target system.
1042
1043 proc check_fork_available {} {
1044     return [check_function_available "fork"]
1045 }
1046
1047 # Returns true iff "mkfifo" is available on the target system.
1048
1049 proc check_mkfifo_available {} {
1050     if {[istarget *-*-cygwin*]} {
1051        # Cygwin has mkfifo, but support is incomplete.
1052        return 0
1053      }
1054
1055     return [check_function_available "mkfifo"]
1056 }
1057
1058 # Returns true iff "__cxa_atexit" is used on the target system.
1059
1060 proc check_cxa_atexit_available { } {
1061     global et_cxa_atexit
1062     global et_cxa_atexit_target_name
1063     global tool 
1064
1065     if { ![info exists et_cxa_atexit_target_name] } {
1066         set et_cxa_atexit_target_name ""
1067     }
1068
1069     # If the target has changed since we set the cached value, clear it.
1070     set current_target [current_target_name]
1071     if { $current_target != $et_cxa_atexit_target_name } {
1072         verbose "check_cxa_atexit_available: `$et_cxa_atexit_target_name'" 2
1073         set et_cxa_atexit_target_name $current_target
1074         if [info exists et_cxa_atexit] {
1075             verbose "check_cxa_atexit_available: removing cached result" 2
1076             unset et_cxa_atexit
1077         }
1078     }
1079
1080     if [info exists et_cxa_atexit] {
1081         verbose "check_cxa_atexit_available: using cached result" 2
1082     } elseif { [istarget "hppa*-*-hpux10*"] } {
1083         # HP-UX 10 doesn't have __cxa_atexit but subsequent test passes.
1084         set et_cxa_atexit 0
1085     } else {
1086         set et_cxa_atexit 0
1087
1088         # Set up, compile, and execute a C++ test program that depends
1089         # on correct ordering of static object destructors. This is
1090         # indicative of the presence and use of __cxa_atexit.
1091         set src cxaatexit[pid].cc
1092         set exe cxaatexit[pid].x
1093
1094         set f [open $src "w"]
1095         puts $f "#include <stdlib.h>"
1096         puts $f "static unsigned int count;"
1097         puts $f "struct X"
1098         puts $f "{"
1099         puts $f "  X() { count = 1; }"
1100         puts $f "  ~X()"
1101         puts $f "  {"
1102         puts $f "    if (count != 3)"
1103         puts $f "      exit(1);"
1104         puts $f "    count = 4;"
1105         puts $f "  }"
1106         puts $f "};"
1107         puts $f "void f()"
1108         puts $f "{"
1109         puts $f "  static X x;"
1110         puts $f "}"
1111         puts $f "struct Y"
1112         puts $f "{"
1113         puts $f "  Y() { f(); count = 2; }"
1114         puts $f "  ~Y()"
1115         puts $f "  {"
1116         puts $f "    if (count != 2)"
1117         puts $f "      exit(1);"
1118         puts $f "    count = 3;"
1119         puts $f "  }"
1120         puts $f "};"
1121         puts $f "Y y;"
1122         puts $f "int main()"
1123         puts $f "{ return 0; }"
1124         close $f
1125
1126         set lines [${tool}_target_compile $src $exe executable ""]
1127         file delete $src
1128
1129         if [string match "" $lines] {
1130             # No error message, compilation succeeded.
1131             set result [${tool}_load "./$exe" "" ""]
1132             set status [lindex $result 0]
1133             remote_file build delete $exe
1134
1135             verbose "check_cxa_atexit_available: status is <$status>" 2
1136
1137             if { $status == "pass" } {
1138                 set et_cxa_atexit 1
1139             }
1140         } else {
1141             verbose "check_cxa_atexit_available: compilation failed" 2
1142         }
1143     }
1144     return $et_cxa_atexit
1145 }
1146
1147
1148 # Return 1 if we're generating 32-bit code using default options, 0
1149 # otherwise.
1150
1151 proc check_effective_target_ilp32 { } {
1152     return [check_no_compiler_messages ilp32 object {
1153         int dummy[sizeof (int) == 4
1154                   && sizeof (void *) == 4
1155                   && sizeof (long) == 4 ? 1 : -1];
1156     }]
1157 }
1158
1159 # Return 1 if we're generating 32-bit or larger integers using default
1160 # options, 0 otherwise.
1161
1162 proc check_effective_target_int32plus { } {
1163     return [check_no_compiler_messages int32plus object {
1164         int dummy[sizeof (int) >= 4 ? 1 : -1];
1165     }]
1166 }
1167
1168 # Return 1 if we're generating 32-bit or larger pointers using default
1169 # options, 0 otherwise.
1170
1171 proc check_effective_target_ptr32plus { } {
1172     return [check_no_compiler_messages ptr32plus object {
1173         int dummy[sizeof (void *) >= 4 ? 1 : -1];
1174     }]
1175 }
1176
1177 # Return 1 if we support 32-bit or larger array and structure sizes
1178 # using default options, 0 otherwise.
1179
1180 proc check_effective_target_size32plus { } {
1181     return [check_no_compiler_messages size32plus object {
1182         char dummy[65537];
1183     }]
1184 }
1185
1186 # Returns 1 if we're generating 16-bit or smaller integers with the
1187 # default options, 0 otherwise.
1188
1189 proc check_effective_target_int16 { } {
1190     return [check_no_compiler_messages int16 object {
1191         int dummy[sizeof (int) < 4 ? 1 : -1];
1192     }]
1193 }
1194
1195 # Return 1 if we're generating 64-bit code using default options, 0
1196 # otherwise.
1197
1198 proc check_effective_target_lp64 { } {
1199     return [check_no_compiler_messages lp64 object {
1200         int dummy[sizeof (int) == 4
1201                   && sizeof (void *) == 8
1202                   && sizeof (long) == 8 ? 1 : -1];
1203     }]
1204 }
1205
1206 # Return 1 if the target supports long double larger than double,
1207 # 0 otherwise.
1208
1209 proc check_effective_target_large_long_double { } {
1210     return [check_no_compiler_messages large_long_double object {
1211         int dummy[sizeof(long double) > sizeof(double) ? 1 : -1];
1212     }]
1213 }
1214
1215
1216 # Return 1 if the target supports compiling decimal floating point,
1217 # 0 otherwise.
1218
1219 proc check_effective_target_dfp_nocache { } {
1220     verbose "check_effective_target_dfp_nocache: compiling source" 2
1221     set ret [string match "" [get_compiler_messages dfp 0 object {
1222         _Decimal32 x; _Decimal64 y; _Decimal128 z;
1223     }]]
1224     verbose "check_effective_target_dfp_nocache: returning $ret" 2
1225     return $ret
1226 }
1227
1228 proc check_effective_target_dfprt_nocache { } {
1229     global tool
1230
1231     set ret 0
1232
1233     verbose "check_effective_target_dfprt_nocache: compiling source" 2
1234     # Set up, compile, and execute a test program containing decimal
1235     # float operations.
1236     set src dfprt[pid].c
1237     set exe dfprt[pid].x
1238
1239     set f [open $src "w"]
1240     puts $f "_Decimal32 x = 1.2df; _Decimal64 y = 2.3dd; _Decimal128 z;"
1241     puts $f "int main () { z = x + y; return 0; }"
1242     close $f
1243
1244     verbose "check_effective_target_dfprt_nocache: compiling testfile $src" 2
1245     set lines [${tool}_target_compile $src $exe executable ""]
1246     file delete $src
1247
1248     if [string match "" $lines] then {
1249         # No error message, compilation succeeded.
1250         set result [${tool}_load "./$exe" "" ""]
1251         set status [lindex $result 0]
1252         remote_file build delete $exe
1253         verbose "check_effective_target_dfprt_nocache: testfile status is <$status>" 2
1254         if { $status == "pass" } then {
1255             set ret 1
1256         }
1257     }
1258     return $ret
1259     verbose "check_effective_target_dfprt_nocache: returning $ret" 2
1260 }
1261
1262 # Return 1 if the target supports compiling Decimal Floating Point,
1263 # 0 otherwise.
1264 #
1265 # This won't change for different subtargets so cache the result.
1266
1267 proc check_effective_target_dfp { } {
1268     global et_dfp_saved
1269
1270     if [info exists et_dfp_saved] {
1271         verbose "check_effective_target_dfp: using cached result" 2
1272     } else {
1273         set et_dfp_saved [check_effective_target_dfp_nocache]
1274     }
1275     verbose "check_effective_target_dfp: returning $et_dfp_saved" 2
1276     return $et_dfp_saved
1277 }
1278
1279 # Return 1 if the target supports linking and executing Decimal Floating
1280 # Point, # 0 otherwise.
1281 #
1282 # This won't change for different subtargets so cache the result.
1283
1284 proc check_effective_target_dfprt { } {
1285     global et_dfprt_saved
1286     global tool
1287
1288     if [info exists et_dfprt_saved] {
1289         verbose "check_effective_target_dfprt: using cached result" 2
1290     } else {
1291         set et_dfprt_saved [check_effective_target_dfprt_nocache]
1292     }
1293     verbose "check_effective_target_dfprt: returning $et_dfprt_saved" 2
1294     return $et_dfprt_saved
1295 }
1296
1297 # Return 1 if the target needs a command line argument to enable a SIMD
1298 # instruction set.
1299
1300 proc check_effective_target_vect_cmdline_needed { } {
1301     global et_vect_cmdline_needed_saved
1302     global et_vect_cmdline_needed_target_name
1303
1304     if { ![info exists et_vect_cmdline_needed_target_name] } {
1305         set et_vect_cmdline_needed_target_name ""
1306     }
1307
1308     # If the target has changed since we set the cached value, clear it.
1309     set current_target [current_target_name]
1310     if { $current_target != $et_vect_cmdline_needed_target_name } {
1311         verbose "check_effective_target_vect_cmdline_needed: `$et_vect_cmdline_needed_target_name' `$current_target'" 2
1312         set et_vect_cmdline_needed_target_name $current_target
1313         if { [info exists et_vect_cmdline_needed_saved] } {
1314             verbose "check_effective_target_vect_cmdline_needed: removing cached result" 2
1315             unset et_vect_cmdline_needed_saved
1316         }
1317     }
1318
1319     if [info exists et_vect_cmdline_needed_saved] {
1320         verbose "check_effective_target_vect_cmdline_needed: using cached result" 2
1321     } else {
1322         set et_vect_cmdline_needed_saved 1
1323         if { [istarget ia64-*-*]
1324              || (([istarget x86_64-*-*] || [istarget i?86-*-*])
1325                  && [check_effective_target_lp64])
1326              || ([istarget powerpc*-*-*]
1327                  && ([check_effective_target_powerpc_spe]
1328                      || [check_effective_target_powerpc_altivec]))} {
1329            set et_vect_cmdline_needed_saved 0
1330         }
1331     }
1332
1333     verbose "check_effective_target_vect_cmdline_needed: returning $et_vect_cmdline_needed_saved" 2
1334     return $et_vect_cmdline_needed_saved
1335 }
1336
1337 # Return 1 if the target supports hardware vectors of int, 0 otherwise.
1338 #
1339 # This won't change for different subtargets so cache the result.
1340
1341 proc check_effective_target_vect_int { } {
1342     global et_vect_int_saved
1343
1344     if [info exists et_vect_int_saved] {
1345         verbose "check_effective_target_vect_int: using cached result" 2
1346     } else {
1347         set et_vect_int_saved 0
1348         if { [istarget i?86-*-*]
1349               || [istarget powerpc*-*-*]
1350               || [istarget spu-*-*]
1351               || [istarget x86_64-*-*]
1352               || [istarget sparc*-*-*]
1353               || [istarget alpha*-*-*]
1354               || [istarget ia64-*-*] } {
1355            set et_vect_int_saved 1
1356         }
1357     }
1358
1359     verbose "check_effective_target_vect_int: returning $et_vect_int_saved" 2
1360     return $et_vect_int_saved
1361 }
1362
1363 # Return 1 is this is an arm target using 32-bit instructions
1364 proc check_effective_target_arm32 { } {
1365     global et_arm32_saved
1366     global et_arm32_target_name
1367     global compiler_flags
1368
1369     if { ![info exists et_arm32_target_name] } {
1370         set et_arm32_target_name ""
1371     }
1372
1373     # If the target has changed since we set the cached value, clear it.
1374     set current_target [current_target_name]
1375     if { $current_target != $et_arm32_target_name } {
1376         verbose "check_effective_target_arm32: `$et_arm32_target_name' `$current_target'" 2
1377         set et_arm32_target_name $current_target
1378         if { [info exists et_arm32_saved] } {
1379             verbose "check_effective_target_arm32: removing cached result" 2
1380             unset et_arm32_saved
1381         }
1382     }
1383
1384     if [info exists et_arm32_saved] {
1385         verbose "check-effective_target_arm32: using cached result" 2
1386     } else {
1387         set et_arm32_saved 0
1388         if { [istarget arm-*-*]
1389               || [istarget strongarm*-*-*]
1390               || [istarget xscale-*-*] } {
1391             if ![string match "*-mthumb *" $compiler_flags] {
1392                 set et_arm32_saved 1
1393             }
1394         }
1395     }
1396     verbose "check_effective_target_arm32: returning $et_arm32_saved" 2
1397     return $et_arm32_saved
1398 }
1399
1400 # Return 1 if this is an ARM target supporting -mfpu=vfp
1401 # -mfloat-abi=softfp.  Some multilibs may be incompatible with these
1402 # options.
1403
1404 proc check_effective_target_arm_vfp_ok { } {
1405     if { [check_effective_target_arm32] } {
1406         return [check_no_compiler_messages arm_vfp_ok object {
1407             int dummy;
1408         } "-mfpu=vfp -mfloat-abi=softfp"]
1409     } else {
1410         return 0
1411     }
1412 }
1413
1414 # Return 1 if this is a PowerPC target with floating-point registers.
1415
1416 proc check_effective_target_powerpc_fprs { } {
1417     if { [istarget powerpc*-*-*]
1418          || [istarget rs6000-*-*] } {
1419         return [check_no_compiler_messages powerpc_fprs object {
1420             #ifdef __NO_FPRS__
1421             #error no FPRs
1422             #else
1423             int dummy;
1424             #endif
1425         }]
1426     } else {
1427         return 0
1428     }
1429 }
1430
1431 # Return 1 if this is a PowerPC target supporting -maltivec.
1432
1433 proc check_effective_target_powerpc_altivec_ok { } {
1434     if { [istarget powerpc*-*-*]
1435          || [istarget rs6000-*-*] } {
1436         # AltiVec is not supported on Aix.
1437         if { [istarget powerpc*-*-aix*] } {
1438             return 0
1439         }
1440         return [check_no_compiler_messages powerpc_altivec_ok object {
1441             int dummy;
1442         } "-maltivec"]
1443     } else {
1444         return 0
1445     }
1446 }
1447
1448 # Return 1 if this is a PowerPC target with SPE enabled.
1449
1450 proc check_effective_target_powerpc_spe { } {
1451     if { [istarget powerpc*-*-*] } {
1452         return [check_no_compiler_messages powerpc_spe object {
1453             #ifndef __SPE__
1454             #error not SPE
1455             #else
1456             int dummy;
1457             #endif
1458         }]
1459     } else {
1460         return 0
1461     }
1462 }
1463
1464 # Return 1 if this is a PowerPC target with Altivec enabled.
1465
1466 proc check_effective_target_powerpc_altivec { } {
1467     if { [istarget powerpc*-*-*] } {
1468         return [check_no_compiler_messages powerpc_altivec object {
1469             #ifndef __ALTIVEC__
1470             #error not Altivec
1471             #else
1472             int dummy;
1473             #endif
1474         }]
1475     } else {
1476         return 0
1477     }
1478 }
1479
1480 # Return 1 if the target supports hardware vector shift operation.
1481
1482 proc check_effective_target_vect_shift { } {
1483     global et_vect_shift_saved
1484
1485     if [info exists et_vect_shift_saved] {
1486         verbose "check_effective_target_vect_shift: using cached result" 2
1487     } else {
1488         set et_vect_shift_saved 0
1489         if { [istarget powerpc*-*-*]
1490              || [istarget ia64-*-*]
1491              || [istarget i?86-*-*]
1492              || [istarget x86_64-*-*] } {
1493            set et_vect_shift_saved 1
1494         }
1495     }
1496
1497     verbose "check_effective_target_vect_shift: returning $et_vect_shift_saved" 2
1498     return $et_vect_shift_saved
1499 }
1500
1501 # Return 1 if the target supports hardware vectors of long, 0 otherwise.
1502 #
1503 # This can change for different subtargets so do not cache the result.
1504
1505 proc check_effective_target_vect_long { } {
1506     if { [istarget i?86-*-*]
1507          || ([istarget powerpc*-*-*] && [check_effective_target_ilp32])
1508          || [istarget x86_64-*-*]
1509          || ([istarget sparc*-*-*] && [check_effective_target_ilp32]) } {
1510         set answer 1
1511     } else {
1512         set answer 0
1513     }
1514
1515     verbose "check_effective_target_vect_long: returning $answer" 2
1516     return $answer
1517 }
1518
1519 # Return 1 if the target supports hardware vectors of float, 0 otherwise.
1520 #
1521 # This won't change for different subtargets so cache the result.
1522
1523 proc check_effective_target_vect_float { } {
1524     global et_vect_float_saved
1525
1526     if [info exists et_vect_float_saved] {
1527         verbose "check_effective_target_vect_float: using cached result" 2
1528     } else {
1529         set et_vect_float_saved 0
1530         if { [istarget i?86-*-*]
1531               || [istarget powerpc*-*-*]
1532               || [istarget spu-*-*]
1533               || [istarget mipsisa64*-*-*]
1534               || [istarget x86_64-*-*]
1535               || [istarget ia64-*-*] } {
1536            set et_vect_float_saved 1
1537         }
1538     }
1539
1540     verbose "check_effective_target_vect_float: returning $et_vect_float_saved" 2
1541     return $et_vect_float_saved
1542 }
1543
1544 # Return 1 if the target supports hardware vectors of double, 0 otherwise.
1545 #
1546 # This won't change for different subtargets so cache the result.
1547
1548 proc check_effective_target_vect_double { } {
1549     global et_vect_double_saved
1550
1551     if [info exists et_vect_double_saved] {
1552         verbose "check_effective_target_vect_double: using cached result" 2
1553     } else {
1554         set et_vect_double_saved 0
1555         if { [istarget i?86-*-*]
1556               || [istarget x86_64-*-*] 
1557               || [istarget spu-*-*] } {
1558            set et_vect_double_saved 1
1559         }
1560     }
1561
1562     verbose "check_effective_target_vect_double: returning $et_vect_double_saved" 2
1563     return $et_vect_double_saved
1564 }
1565
1566 # Return 0 if the target supports hardware comparison of vectors of double, 0 otherwise.
1567 #
1568 # This won't change for different subtargets so cache the result.
1569
1570 proc check_effective_target_vect_no_compare_double { } {
1571     global et_vect_no_compare_double_saved
1572
1573     if [info exists et_vect_no_compare_double_saved] {
1574         verbose "check_effective_target_vect_no_compare_double: using cached result" 2
1575     } else {
1576         set et_vect_no_compare_double_saved 0
1577         if { [istarget spu-*-*] } {
1578            set et_vect_no_compare_double_saved 1
1579         }
1580     }
1581
1582     verbose "check_effective_target_vect_no_compare_double: returning $et_vect_no_compare_double_saved" 2
1583     return $et_vect_no_compare_double_saved
1584 }
1585
1586 # Return 1 if the target plus current options does not support a vector
1587 # max instruction on "int", 0 otherwise.
1588 #
1589 # This won't change for different subtargets so cache the result.
1590
1591 proc check_effective_target_vect_no_int_max { } {
1592     global et_vect_no_int_max_saved
1593
1594     if [info exists et_vect_no_int_max_saved] {
1595         verbose "check_effective_target_vect_no_int_max: using cached result" 2
1596     } else {
1597         set et_vect_no_int_max_saved 0
1598         if { [istarget sparc*-*-*]
1599              || [istarget spu-*-*]
1600              || [istarget alpha*-*-*] } {
1601             set et_vect_no_int_max_saved 1
1602         }
1603     }
1604     verbose "check_effective_target_vect_no_int_max: returning $et_vect_no_int_max_saved" 2
1605     return $et_vect_no_int_max_saved
1606 }
1607
1608 # Return 1 if the target plus current options does not support a vector
1609 # add instruction on "int", 0 otherwise.
1610 #
1611 # This won't change for different subtargets so cache the result.
1612
1613 proc check_effective_target_vect_no_int_add { } {
1614     global et_vect_no_int_add_saved
1615
1616     if [info exists et_vect_no_int_add_saved] {
1617         verbose "check_effective_target_vect_no_int_add: using cached result" 2
1618     } else {
1619         set et_vect_no_int_add_saved 0
1620         # Alpha only supports vector add on V8QI and V4HI.
1621         if { [istarget alpha*-*-*] } {
1622             set et_vect_no_int_add_saved 1
1623         }
1624     }
1625     verbose "check_effective_target_vect_no_int_add: returning $et_vect_no_int_add_saved" 2
1626     return $et_vect_no_int_add_saved
1627 }
1628
1629 # Return 1 if the target plus current options does not support vector
1630 # bitwise instructions, 0 otherwise.
1631 #
1632 # This won't change for different subtargets so cache the result.
1633
1634 proc check_effective_target_vect_no_bitwise { } {
1635     global et_vect_no_bitwise_saved
1636
1637     if [info exists et_vect_no_bitwise_saved] {
1638         verbose "check_effective_target_vect_no_bitwise: using cached result" 2
1639     } else {
1640         set et_vect_no_bitwise_saved 0
1641     }
1642     verbose "check_effective_target_vect_no_bitwise: returning $et_vect_no_bitwise_saved" 2
1643     return $et_vect_no_bitwise_saved
1644 }
1645
1646 # Return 1 if the target plus current options supports a vector
1647 # widening summation of *short* args into *int* result, 0 otherwise.
1648 # A target can also support this widening summation if it can support
1649 # promotion (unpacking) from shorts to ints.
1650 #
1651 # This won't change for different subtargets so cache the result.
1652                                                                                                 
1653 proc check_effective_target_vect_widen_sum_hi_to_si { } {
1654     global et_vect_widen_sum_hi_to_si
1655
1656     if [info exists et_vect_widen_sum_hi_to_si_saved] {
1657         verbose "check_effective_target_vect_widen_sum_hi_to_si: using cached result" 2
1658     } else {
1659         set et_vect_widen_sum_hi_to_si_saved [check_effective_target_vect_unpack]
1660         if { [istarget powerpc*-*-*] } {
1661             set et_vect_widen_sum_hi_to_si_saved 1
1662         }
1663     }
1664     verbose "check_effective_target_vect_widen_sum_hi_to_si: returning $et_vect_widen_sum_hi_to_si_saved" 2
1665     return $et_vect_widen_sum_hi_to_si_saved
1666 }
1667
1668 # Return 1 if the target plus current options supports a vector
1669 # widening summation of *char* args into *short* result, 0 otherwise.
1670 # A target can also support this widening summation if it can support
1671 # promotion (unpacking) from chars to shorts.
1672 #
1673 # This won't change for different subtargets so cache the result.
1674                                                                                                 
1675 proc check_effective_target_vect_widen_sum_qi_to_hi { } {
1676     global et_vect_widen_sum_qi_to_hi
1677
1678     if [info exists et_vect_widen_sum_qi_to_hi_saved] {
1679         verbose "check_effective_target_vect_widen_sum_qi_to_hi: using cached result" 2
1680     } else {
1681         set et_vect_widen_sum_qi_to_hi_saved 0
1682         if { [check_effective_target_vect_unpack] } {
1683             set et_vect_widen_sum_qi_to_hi_saved 1
1684         }
1685     }
1686     verbose "check_effective_target_vect_widen_sum_qi_to_hi: returning $et_vect_widen_sum_qi_to_hi_saved" 2
1687     return $et_vect_widen_sum_qi_to_hi_saved
1688 }
1689
1690 # Return 1 if the target plus current options supports a vector
1691 # widening summation of *char* args into *int* result, 0 otherwise.
1692 #
1693 # This won't change for different subtargets so cache the result.
1694                                                                                                 
1695 proc check_effective_target_vect_widen_sum_qi_to_si { } {
1696     global et_vect_widen_sum_qi_to_si
1697
1698     if [info exists et_vect_widen_sum_qi_to_si_saved] {
1699         verbose "check_effective_target_vect_widen_sum_qi_to_si: using cached result" 2
1700     } else {
1701         set et_vect_widen_sum_qi_to_si_saved 0
1702         if { [istarget powerpc*-*-*] } {
1703             set et_vect_widen_sum_qi_to_si_saved 1
1704         }
1705     }
1706     verbose "check_effective_target_vect_widen_sum_qi_to_si: returning $et_vect_widen_sum_qi_to_si_saved" 2
1707     return $et_vect_widen_sum_qi_to_si_saved
1708 }
1709
1710 # Return 1 if the target plus current options supports a vector
1711 # widening multiplication of *char* args into *short* result, 0 otherwise.
1712 # A target can also support this widening multplication if it can support
1713 # promotion (unpacking) from chars to shorts, and vect_short_mult (non-widening
1714 # multiplication of shorts).
1715 #
1716 # This won't change for different subtargets so cache the result.
1717
1718
1719 proc check_effective_target_vect_widen_mult_qi_to_hi { } {
1720     global et_vect_widen_mult_qi_to_hi
1721
1722     if [info exists et_vect_widen_mult_qi_to_hi_saved] {
1723         verbose "check_effective_target_vect_widen_mult_qi_to_hi: using cached result" 2
1724     } else {
1725         if { [check_effective_target_vect_unpack]
1726              && [check_effective_target_vect_short_mult] } {
1727             set et_vect_widen_mult_qi_to_hi_saved 1
1728         } else {
1729             set et_vect_widen_mult_qi_to_hi_saved 0
1730         }
1731         if { [istarget powerpc*-*-*] } {
1732             set et_vect_widen_mult_qi_to_hi_saved 1
1733         }
1734     }
1735     verbose "check_effective_target_vect_widen_mult_qi_to_hi: returning $et_vect_widen_mult_qi_to_hi_saved" 2
1736     return $et_vect_widen_mult_qi_to_hi_saved
1737 }
1738
1739 # Return 1 if the target plus current options supports a vector
1740 # widening multiplication of *short* args into *int* result, 0 otherwise.
1741 # A target can also support this widening multplication if it can support
1742 # promotion (unpacking) from shorts to ints, and vect_int_mult (non-widening
1743 # multiplication of ints).
1744 #
1745 # This won't change for different subtargets so cache the result.
1746
1747
1748 proc check_effective_target_vect_widen_mult_hi_to_si { } {
1749     global et_vect_widen_mult_hi_to_si
1750
1751     if [info exists et_vect_widen_mult_hi_to_si_saved] {
1752         verbose "check_effective_target_vect_widen_mult_hi_to_si: using cached result" 2
1753     } else {
1754         if { [check_effective_target_vect_unpack]
1755              && [check_effective_target_vect_int_mult] } {
1756           set et_vect_widen_mult_hi_to_si_saved 1
1757         } else {
1758           set et_vect_widen_mult_hi_to_si_saved 0
1759         }
1760         if { [istarget powerpc*-*-*]
1761               || [istarget spu-*-*]
1762               || [istarget i?86-*-*]
1763               || [istarget x86_64-*-*] } {
1764             set et_vect_widen_mult_hi_to_si_saved 1
1765         }
1766     }
1767     verbose "check_effective_target_vect_widen_mult_hi_to_si: returning $et_vect_widen_mult_hi_to_si_saved" 2
1768     return $et_vect_widen_mult_hi_to_si_saved
1769 }
1770
1771 # Return 1 if the target plus current options supports a vector
1772 # dot-product of signed chars, 0 otherwise.
1773 #
1774 # This won't change for different subtargets so cache the result.
1775
1776 proc check_effective_target_vect_sdot_qi { } {
1777     global et_vect_sdot_qi
1778
1779     if [info exists et_vect_sdot_qi_saved] {
1780         verbose "check_effective_target_vect_sdot_qi: using cached result" 2
1781     } else {
1782         set et_vect_sdot_qi_saved 0
1783     }
1784     verbose "check_effective_target_vect_sdot_qi: returning $et_vect_sdot_qi_saved" 2
1785     return $et_vect_sdot_qi_saved
1786 }
1787
1788 # Return 1 if the target plus current options supports a vector
1789 # dot-product of unsigned chars, 0 otherwise.
1790 #
1791 # This won't change for different subtargets so cache the result.
1792
1793 proc check_effective_target_vect_udot_qi { } {
1794     global et_vect_udot_qi
1795
1796     if [info exists et_vect_udot_qi_saved] {
1797         verbose "check_effective_target_vect_udot_qi: using cached result" 2
1798     } else {
1799         set et_vect_udot_qi_saved 0
1800         if { [istarget powerpc*-*-*] } {
1801             set et_vect_udot_qi_saved 1
1802         }
1803     }
1804     verbose "check_effective_target_vect_udot_qi: returning $et_vect_udot_qi_saved" 2
1805     return $et_vect_udot_qi_saved
1806 }
1807
1808 # Return 1 if the target plus current options supports a vector
1809 # dot-product of signed shorts, 0 otherwise.
1810 #
1811 # This won't change for different subtargets so cache the result.
1812
1813 proc check_effective_target_vect_sdot_hi { } {
1814     global et_vect_sdot_hi
1815
1816     if [info exists et_vect_sdot_hi_saved] {
1817         verbose "check_effective_target_vect_sdot_hi: using cached result" 2
1818     } else {
1819         set et_vect_sdot_hi_saved 0
1820         if { [istarget powerpc*-*-*] 
1821              || [istarget i?86-*-*]
1822              || [istarget x86_64-*-*] } {
1823             set et_vect_sdot_hi_saved 1
1824         }
1825     }
1826     verbose "check_effective_target_vect_sdot_hi: returning $et_vect_sdot_hi_saved" 2
1827     return $et_vect_sdot_hi_saved
1828 }
1829
1830 # Return 1 if the target plus current options supports a vector
1831 # dot-product of unsigned shorts, 0 otherwise.
1832 #
1833 # This won't change for different subtargets so cache the result.
1834
1835 proc check_effective_target_vect_udot_hi { } {
1836     global et_vect_udot_hi
1837
1838     if [info exists et_vect_udot_hi_saved] {
1839         verbose "check_effective_target_vect_udot_hi: using cached result" 2
1840     } else {
1841         set et_vect_udot_hi_saved 0
1842         if { [istarget powerpc*-*-*] } {
1843             set et_vect_udot_hi_saved 1
1844         }
1845     }
1846     verbose "check_effective_target_vect_udot_hi: returning $et_vect_udot_hi_saved" 2
1847     return $et_vect_udot_hi_saved
1848 }
1849
1850
1851 # Return 1 if the target plus current options supports a vector
1852 # demotion (packing) of shorts (to chars) and ints (to shorts) 
1853 # using modulo arithmetic, 0 otherwise.
1854 #
1855 # This won't change for different subtargets so cache the result.
1856                                                                                 
1857 proc check_effective_target_vect_pack_mod { } {
1858     global et_vect_pack_mod
1859                                                                                 
1860     if [info exists et_vect_pack_mod_saved] {
1861         verbose "check_effective_target_vect_pack_mod: using cached result" 2
1862     } else {
1863         set et_vect_pack_mod_saved 0
1864         if { [istarget powerpc*-*-*]
1865              || [istarget i?86-*-*]
1866              || [istarget x86_64-*-*] } {
1867             set et_vect_pack_mod_saved 1
1868         }
1869     }
1870     verbose "check_effective_target_vect_pack_mod: returning $et_vect_pack_mod_saved" 2
1871     return $et_vect_pack_mod_saved
1872 }
1873
1874 # Return 1 if the target plus current options supports a vector
1875 # promotion (unpacking) of chars (to shorts) and shorts (to ints), 0 otherwise.
1876 #
1877 # This won't change for different subtargets so cache the result.
1878                                    
1879 proc check_effective_target_vect_unpack { } {
1880     global et_vect_unpack
1881                                         
1882     if [info exists et_vect_unpack_saved] {
1883         verbose "check_effective_target_vect_unpack: using cached result" 2
1884     } else {
1885         set et_vect_unpack_saved 0
1886         if { [istarget powerpc*-*-*]
1887              || [istarget i?86-*-*]
1888              || [istarget x86_64-*-*] } {
1889             set et_vect_unpack_saved 1
1890         }
1891     }
1892     verbose "check_effective_target_vect_unpack: returning $et_vect_unpack_saved" 2  
1893     return $et_vect_unpack_saved
1894 }
1895
1896 # Return 1 if the target plus current options does not support a vector
1897 # alignment mechanism, 0 otherwise.
1898 #
1899 # This won't change for different subtargets so cache the result.
1900
1901 proc check_effective_target_vect_no_align { } {
1902     global et_vect_no_align_saved
1903
1904     if [info exists et_vect_no_align_saved] {
1905         verbose "check_effective_target_vect_no_align: using cached result" 2
1906     } else {
1907         set et_vect_no_align_saved 0
1908         if { [istarget mipsisa64*-*-*]
1909              || [istarget sparc*-*-*]
1910              || [istarget ia64-*-*] } {
1911             set et_vect_no_align_saved 1
1912         }
1913     }
1914     verbose "check_effective_target_vect_no_align: returning $et_vect_no_align_saved" 2
1915     return $et_vect_no_align_saved
1916 }
1917
1918 # Return 1 if the target supports vector conditional operations, 0 otherwise.
1919
1920 proc check_effective_target_vect_condition { } {
1921     global et_vect_cond_saved
1922
1923     if [info exists et_vect_cond_saved] {
1924         verbose "check_effective_target_vect_cond: using cached result" 2
1925     } else {
1926         set et_vect_cond_saved 0
1927         if { [istarget powerpc*-*-*]
1928              || [istarget ia64-*-*]
1929              || [istarget i?86-*-*]
1930              || [istarget x86_64-*-*] } {
1931            set et_vect_cond_saved 1
1932         }
1933     }
1934
1935     verbose "check_effective_target_vect_cond: returning $et_vect_cond_saved" 2
1936     return $et_vect_cond_saved
1937 }
1938
1939 # Return 1 if the target supports vector char multiplication, 0 otherwise.
1940
1941 proc check_effective_target_vect_char_mult { } {
1942     global et_vect_char_mult_saved
1943
1944     if [info exists et_vect_char_mult_saved] {
1945         verbose "check_effective_target_vect_char_mult: using cached result" 2
1946     } else {
1947         set et_vect_char_mult_saved 0
1948         if { [istarget ia64-*-*]
1949              || [istarget i?86-*-*]
1950              || [istarget x86_64-*-*] } {
1951            set et_vect_char_mult_saved 1
1952         }
1953     }
1954
1955     verbose "check_effective_target_vect_char_mult: returning $et_vect_char_mult_saved" 2
1956     return $et_vect_char_mult_saved
1957 }
1958
1959 # Return 1 if the target supports vector short multiplication, 0 otherwise.
1960
1961 proc check_effective_target_vect_short_mult { } {
1962     global et_vect_short_mult_saved
1963
1964     if [info exists et_vect_short_mult_saved] {
1965         verbose "check_effective_target_vect_short_mult: using cached result" 2
1966     } else {
1967         set et_vect_short_mult_saved 0
1968         if { [istarget ia64-*-*]
1969              || [istarget i?86-*-*]
1970              || [istarget x86_64-*-*] } {
1971            set et_vect_short_mult_saved 1
1972         }
1973     }
1974
1975     verbose "check_effective_target_vect_short_mult: returning $et_vect_short_mult_saved" 2
1976     return $et_vect_short_mult_saved
1977 }
1978
1979 # Return 1 if the target supports vector int multiplication, 0 otherwise.
1980
1981 proc check_effective_target_vect_int_mult { } {
1982     global et_vect_int_mult_saved
1983
1984     if [info exists et_vect_int_mult_saved] {
1985         verbose "check_effective_target_vect_int_mult: using cached result" 2
1986     } else {
1987         set et_vect_int_mult_saved 0
1988         if { [istarget powerpc*-*-*]
1989              || [istarget i?86-*-*]
1990              || [istarget x86_64-*-*] } {
1991            set et_vect_int_mult_saved 1
1992         }
1993     }
1994
1995     verbose "check_effective_target_vect_int_mult: returning $et_vect_int_mult_saved" 2
1996     return $et_vect_int_mult_saved
1997 }
1998
1999 # Return 1 if the target supports vector even/odd elements extraction, 0 otherwise.
2000
2001 proc check_effective_target_vect_extract_even_odd { } {
2002     global et_vect_extract_even_odd_saved
2003     
2004     if [info exists et_vect_extract_even_odd_saved] {
2005         verbose "check_effective_target_vect_extract_even_odd: using cached result" 2
2006     } else {
2007         set et_vect_extract_even_odd_saved 0 
2008         if { [istarget powerpc*-*-*] } {
2009            set et_vect_extract_even_odd_saved 1
2010         }
2011     }
2012
2013     verbose "check_effective_target_vect_extract_even_odd: returning $et_vect_extract_even_odd_saved" 2
2014     return $et_vect_extract_even_odd_saved
2015 }
2016
2017 # Return 1 if the target supports vector interleaving, 0 otherwise.
2018
2019 proc check_effective_target_vect_interleave { } {
2020     global et_vect_interleave_saved
2021     
2022     if [info exists et_vect_interleave_saved] {
2023         verbose "check_effective_target_vect_interleave: using cached result" 2
2024     } else {
2025         set et_vect_interleave_saved 0
2026         if { [istarget powerpc*-*-*]
2027              || [istarget i?86-*-*]
2028              || [istarget x86_64-*-*] } {
2029            set et_vect_interleave_saved 1
2030         }
2031     }
2032
2033     verbose "check_effective_target_vect_interleave: returning $et_vect_interleave_saved" 2
2034     return $et_vect_interleave_saved
2035 }
2036
2037 # Return 1 if the target supports section-anchors
2038
2039 proc check_effective_target_section_anchors { } {
2040     global et_section_anchors_saved
2041
2042     if [info exists et_section_anchors_saved] {
2043         verbose "check_effective_target_section_anchors: using cached result" 2
2044     } else {
2045         set et_section_anchors_saved 0
2046         if { [istarget powerpc*-*-*] } {
2047            set et_section_anchors_saved 1
2048         }
2049     }
2050
2051     verbose "check_effective_target_section_anchors: returning $et_section_anchors_saved" 2
2052     return $et_section_anchors_saved
2053 }
2054
2055 # Return 1 if the target supports atomic operations on "int" and "long".
2056
2057 proc check_effective_target_sync_int_long { } {
2058     global et_sync_int_long_saved
2059
2060     if [info exists et_sync_int_long_saved] {
2061         verbose "check_effective_target_sync_int_long: using cached result" 2
2062     } else {
2063         set et_sync_int_long_saved 0
2064 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
2065 # load-reserved/store-conditional instructions.
2066         if { [istarget ia64-*-*]
2067              || [istarget i?86-*-*]
2068              || [istarget x86_64-*-*]
2069              || [istarget alpha*-*-*] 
2070              || [istarget s390*-*-*] 
2071              || [istarget powerpc*-*-*]
2072              || [istarget sparc64-*-*]
2073              || [istarget sparcv9-*-*] } {
2074            set et_sync_int_long_saved 1
2075         }
2076     }
2077
2078     verbose "check_effective_target_sync_int_long: returning $et_sync_int_long_saved" 2
2079     return $et_sync_int_long_saved
2080 }
2081
2082 # Return 1 if the target supports atomic operations on "char" and "short".
2083
2084 proc check_effective_target_sync_char_short { } {
2085     global et_sync_char_short_saved
2086
2087     if [info exists et_sync_char_short_saved] {
2088         verbose "check_effective_target_sync_char_short: using cached result" 2
2089     } else {
2090         set et_sync_char_short_saved 0
2091 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
2092 # load-reserved/store-conditional instructions.
2093         if { [istarget ia64-*-*]
2094              || [istarget i?86-*-*]
2095              || [istarget x86_64-*-*]
2096              || [istarget alpha*-*-*] 
2097              || [istarget s390*-*-*] 
2098              || [istarget powerpc*-*-*]
2099              || [istarget sparc64-*-*]
2100              || [istarget sparcv9-*-*] } {
2101            set et_sync_char_short_saved 1
2102         }
2103     }
2104
2105     verbose "check_effective_target_sync_char_short: returning $et_sync_char_short_saved" 2
2106     return $et_sync_char_short_saved
2107 }
2108
2109 # Return 1 if the target uses a ColdFire FPU.
2110
2111 proc check_effective_target_coldfire_fpu { } {
2112     return [check_no_compiler_messages coldfire_fpu assembly {
2113         #ifndef __mcffpu__
2114         #error FOO
2115         #endif
2116     }]
2117 }
2118
2119 # Return true if this is a uClibc target.
2120
2121 proc check_effective_target_uclibc {} {
2122     return [check_no_compiler_messages uclibc object {
2123         #include <features.h>
2124         #if !defined (__UCLIBC__)
2125         #error FOO
2126         #endif
2127     }]
2128 }
2129
2130 # Return true if this is a uclibc target and if the uclibc feature
2131 # described by __$feature__ is not present.
2132
2133 proc check_missing_uclibc_feature {feature} {
2134     return [check_no_compiler_messages $feature object "
2135         #include <features.h>
2136         #if !defined (__UCLIBC) || defined (__${feature}__)
2137         #error FOO
2138         #endif
2139     "]
2140 }
2141
2142 # Return true if this is a Newlib target.
2143
2144 proc check_effective_target_newlib {} {
2145     return [check_no_compiler_messages newlib object {
2146         #include <newlib.h>
2147     }]
2148 }
2149
2150 # Return 1 if
2151 #   (a) an error of a few ULP is expected in string to floating-point
2152 #       conversion functions; and
2153 #   (b) overflow is not always detected correctly by those functions.
2154
2155 proc check_effective_target_lax_strtofp {} {
2156     # By default, assume that all uClibc targets suffer from this.
2157     return [check_effective_target_uclibc]
2158 }
2159
2160 # Return 1 if this is a target for which wcsftime is a dummy
2161 # function that always returns 0.
2162
2163 proc check_effective_target_dummy_wcsftime {} {
2164     # By default, assume that all uClibc targets suffer from this.
2165     return [check_effective_target_uclibc]
2166 }
2167
2168 # Return 1 if constructors with initialization priority arguments are
2169 # supposed on this target.
2170
2171 proc check_effective_target_init_priority {} {
2172     return [check_no_compiler_messages init_priority assembly "
2173         void f() __attribute__((constructor (1000)));
2174         void f() \{\}
2175     "]
2176 }
2177
2178 # Return 1 if the target matches the effective target 'arg', 0 otherwise.
2179 # This can be used with any check_* proc that takes no argument and
2180 # returns only 1 or 0.  It could be used with check_* procs that take
2181 # arguments with keywords that pass particular arguments.
2182
2183 proc is-effective-target { arg } {
2184     set selected 0
2185     if { [info procs check_effective_target_${arg}] != [list] } {
2186         set selected [check_effective_target_${arg}]
2187     } else {
2188         switch $arg {
2189           "vmx_hw"         { set selected [check_vmx_hw_available] }
2190           "named_sections" { set selected [check_named_sections_available] }
2191           "gc_sections"    { set selected [check_gc_sections_available] }
2192           "cxa_atexit"     { set selected [check_cxa_atexit_available] }
2193           default          { error "unknown effective target keyword `$arg'" }
2194         }
2195     }
2196     verbose "is-effective-target: $arg $selected" 2
2197     return $selected
2198 }
2199
2200 # Return 1 if the argument is an effective-target keyword, 0 otherwise.
2201
2202 proc is-effective-target-keyword { arg } {
2203     if { [info procs check_effective_target_${arg}] != [list] } {
2204         return 1
2205     } else {
2206         # These have different names for their check_* procs.
2207         switch $arg {
2208           "vmx_hw"         { return 1 }
2209           "named_sections" { return 1 }
2210           "gc_sections"    { return 1 }
2211           "cxa_atexit"     { return 1 }
2212           default          { return 0 }
2213         }
2214     }
2215 }
2216
2217 # Return 1 if target default to short enums
2218
2219 proc check_effective_target_short_enums { } {
2220     return [check_no_compiler_messages short_enums assembly {
2221         enum foo { bar };
2222         int s[sizeof (enum foo) == 1 ? 1 : -1];
2223     }]
2224 }
2225
2226 # Return 1 if target supports merging string constants at link time.
2227
2228 proc check_effective_target_string_merging { } {
2229     return [check_no_messages_and_pattern string_merging \
2230                 "rodata\\.str" assembly {
2231                     const char *var = "String";
2232                 } {-O2}]
2233 }
2234
2235 # Return 1 if target has the basic signed and unsigned types in
2236 # <stdint.h>, 0 otherwise.
2237
2238 proc check_effective_target_stdint_types { } {
2239     return [check_no_compiler_messages stdint_types assembly {
2240         #include <stdint.h>
2241         int8_t a; int16_t b; int32_t c; int64_t d;
2242         uint8_t e; uint16_t f; uint32_t g; uint64_t h;
2243     }]
2244 }
2245
2246 # Return 1 if programs are intended to be run on a simulator
2247 # (i.e. slowly) rather than hardware (i.e. fast).
2248
2249 proc check_effective_target_simulator { } {
2250
2251     # All "src/sim" simulators set this one.
2252     if [board_info target exists is_simulator] {
2253         return [board_info target is_simulator]
2254     }
2255
2256     # The "sid" simulators don't set that one, but at least they set
2257     # this one.
2258     if [board_info target exists slow_simulator] {
2259         return [board_info target slow_simulator]
2260     }
2261
2262     return 0
2263 }
2264
2265 # Return 1 if the target is a VxWorks RTP.
2266
2267 proc check_effective_target_vxworks_kernel { } {
2268     return [check_no_compiler_messages vxworks_kernel assembly {
2269         #if !defined __vxworks || defined __RTP__
2270         #error NO
2271         #endif
2272     }]
2273 }
2274
2275 # Return 1 if the target is expected to provide wide character support.
2276
2277 proc check_effective_target_wchar { } {
2278     if {[check_missing_uclibc_feature UCLIBC_HAS_WCHAR]} {
2279         return 0
2280     }
2281     return [check_no_compiler_messages wchar assembly {
2282         #include <wchar.h>
2283     }]
2284 }