OSDN Git Service

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