OSDN Git Service

2009-01-09 Joel Sherrill <joel.sherrill@oarcorp.com>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / target-supports.exp
1 #   Copyright (C) 1999, 2001, 2003, 2004, 2005, 2006, 2007, 2008
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 3 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 GCC; see the file COPYING3.  If not see
16 # <http://www.gnu.org/licenses/>.
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 the code given by CONTENTS into an output file of
24 # type TYPE, where TYPE is as for target_compile.  Return a list
25 # whose first element contains the compiler messages and whose
26 # second element is the name of the output file.
27 #
28 # BASENAME is a prefix to use for source and output files.
29 # If ARGS is not empty, its first element is a string that
30 # should be added to the command line.
31 #
32 # Assume by default that CONTENTS is C code.  C++ code should contain
33 # "// C++" and Fortran code should contain "! Fortran".
34 proc check_compile {basename type contents args} {
35     global tool
36
37     if { [llength $args] > 0 } {
38         set options [list "additional_flags=[lindex $args 0]"]
39     } else {
40         set options ""
41     }
42     switch -glob -- $contents {
43         "*! Fortran*" { set src ${basename}[pid].f90 }
44         "*// C++*" { set src ${basename}[pid].cc }
45         default { set src ${basename}[pid].c }
46     }
47     set compile_type $type
48     switch -glob $type {
49         assembly { set output ${basename}[pid].s }
50         object { set output ${basename}[pid].o }
51         executable { set output ${basename}[pid].exe }
52         "rtl-*" {
53             set output ${basename}[pid].s
54             lappend options "additional_flags=-fdump-$type"
55             set compile_type assembly
56         }
57     }
58     set f [open $src "w"]
59     puts $f $contents
60     close $f
61     set lines [${tool}_target_compile $src $output $compile_type "$options"]
62     file delete $src
63
64     set scan_output $output
65     # Don't try folding this into the switch above; calling "glob" before the
66     # file is created won't work.
67     if [regexp "rtl-(.*)" $type dummy rtl_type] {
68         set scan_output "[glob $src.\[0-9\]\[0-9\]\[0-9\]r.$rtl_type]"
69         file delete $output
70     }
71
72     return [list $lines $scan_output]
73 }
74
75 proc current_target_name { } {
76     global target_info
77     if [info exists target_info(target,name)] {
78         set answer $target_info(target,name)
79     } else {
80         set answer ""
81     }
82     return $answer
83 }
84
85 # Implement an effective-target check for property PROP by invoking
86 # the Tcl command ARGS and seeing if it returns true.
87
88 proc check_cached_effective_target { prop args } {
89     global et_cache
90
91     set target [current_target_name]
92     if {![info exists et_cache($prop,target)]
93         || $et_cache($prop,target) != $target} {
94         verbose "check_cached_effective_target $prop: checking $target" 2
95         set et_cache($prop,target) $target
96         set et_cache($prop,value) [uplevel eval $args]
97     }
98     set value $et_cache($prop,value)
99     verbose "check_cached_effective_target $prop: returning $value for $target" 2
100     return $value
101 }
102
103 # Like check_compile, but delete the output file and return true if the
104 # compiler printed no messages.
105 proc check_no_compiler_messages_nocache {args} {
106     set result [eval check_compile $args]
107     set lines [lindex $result 0]
108     set output [lindex $result 1]
109     remote_file build delete $output
110     return [string match "" $lines]
111 }
112
113 # Like check_no_compiler_messages_nocache, but cache the result.
114 # PROP is the property we're checking, and doubles as a prefix for
115 # temporary filenames.
116 proc check_no_compiler_messages {prop args} {
117     return [check_cached_effective_target $prop {
118         eval [list check_no_compiler_messages_nocache $prop] $args
119     }]
120 }
121
122 # Like check_compile, but return true if the compiler printed no
123 # messages and if the contents of the output file satisfy PATTERN.
124 # If PATTERN has the form "!REGEXP", the contents satisfy it if they
125 # don't match regular expression REGEXP, otherwise they satisfy it
126 # if they do match regular expression PATTERN.  (PATTERN can start
127 # with something like "[!]" if the regular expression needs to match
128 # "!" as the first character.)
129 #
130 # Delete the output file before returning.  The other arguments are
131 # as for check_compile.
132 proc check_no_messages_and_pattern_nocache {basename pattern args} {
133     global tool
134
135     set result [eval [list check_compile $basename] $args]
136     set lines [lindex $result 0]
137     set output [lindex $result 1]
138
139     set ok 0
140     if { [string match "" $lines] } {
141         set chan [open "$output"]
142         set invert [regexp {^!(.*)} $pattern dummy pattern]
143         set ok [expr { [regexp $pattern [read $chan]] != $invert }]
144         close $chan
145     }
146
147     remote_file build delete $output
148     return $ok
149 }
150
151 # Like check_no_messages_and_pattern_nocache, but cache the result.
152 # PROP is the property we're checking, and doubles as a prefix for
153 # temporary filenames.
154 proc check_no_messages_and_pattern {prop pattern args} {
155     return [check_cached_effective_target $prop {
156         eval [list check_no_messages_and_pattern_nocache $prop $pattern] $args
157     }]
158 }
159
160 # Try to compile and run an executable from code CONTENTS.  Return true
161 # if the compiler reports no messages and if execution "passes" in the
162 # usual DejaGNU sense.  The arguments are as for check_compile, with
163 # TYPE implicitly being "executable".
164 proc check_runtime_nocache {basename contents args} {
165     global tool
166
167     set result [eval [list check_compile $basename executable $contents] $args]
168     set lines [lindex $result 0]
169     set output [lindex $result 1]
170
171     set ok 0
172     if { [string match "" $lines] } {
173         # No error messages, everything is OK.
174         set result [remote_load target "./$output" "" ""]
175         set status [lindex $result 0]
176         verbose "check_runtime_nocache $basename: status is <$status>" 2
177         if { $status == "pass" } {
178             set ok 1
179         }
180     }
181     remote_file build delete $output
182     return $ok
183 }
184
185 # Like check_runtime_nocache, but cache the result.  PROP is the
186 # property we're checking, and doubles as a prefix for temporary
187 # filenames.
188 proc check_runtime {prop args} {
189     global tool
190
191     return [check_cached_effective_target $prop {
192         eval [list check_runtime_nocache $prop] $args
193     }]
194 }
195
196 ###############################
197 # proc check_weak_available { }
198 ###############################
199
200 # weak symbols are only supported in some configs/object formats
201 # this proc returns 1 if they're supported, 0 if they're not, or -1 if unsure
202
203 proc check_weak_available { } {
204     global target_triplet
205     global target_cpu
206
207     # All mips targets should support it
208
209     if { [ string first "mips" $target_cpu ] >= 0 } {
210         return 1
211     }
212
213     # All solaris2 targets should support it
214
215     if { [regexp ".*-solaris2.*" $target_triplet] } {
216         return 1
217     }
218
219     # DEC OSF/1/Digital UNIX/Tru64 UNIX supports it
220
221     if { [regexp "alpha.*osf.*" $target_triplet] } {
222         return 1
223     }
224
225     # Windows targets Cygwin and MingW32 support it
226
227     if { [regexp ".*mingw32|.*cygwin" $target_triplet] } {
228         return 1
229     }
230
231     # HP-UX 10.X doesn't support it
232
233     if { [istarget "hppa*-*-hpux10*"] } {
234         return 0
235     }
236
237     # ELF and ECOFF support it. a.out does with gas/gld but may also with
238     # other linkers, so we should try it
239
240     set objformat [gcc_target_object_format]
241
242     switch $objformat {
243         elf      { return 1 }
244         ecoff    { return 1 }
245         a.out    { return 1 }
246         mach-o   { return 1 }
247         som      { return 1 }
248         unknown  { return -1 }
249         default  { return 0 }
250     }
251 }
252
253 ###############################
254 # proc check_weak_override_available { }
255 ###############################
256
257 # Like check_weak_available, but return 0 if weak symbol definitions
258 # cannot be overridden.
259
260 proc check_weak_override_available { } {
261     if { [istarget "*-*-mingw*"] } {
262         return 0
263     }
264     return [check_weak_available]
265 }
266
267 ###############################
268 # proc check_visibility_available { what_kind }
269 ###############################
270
271 # The visibility attribute is only support in some object formats
272 # This proc returns 1 if it is supported, 0 if not.
273 # The argument is the kind of visibility, default/protected/hidden/internal.
274
275 proc check_visibility_available { what_kind } {
276     global tool
277     global target_triplet
278
279     # On NetWare, support makes no sense.
280     if { [istarget *-*-netware*] } {
281         return 0
282     }
283
284     if [string match "" $what_kind] { set what_kind "hidden" }
285
286     return [check_no_compiler_messages visibility_available_$what_kind object "
287         void f() __attribute__((visibility(\"$what_kind\")));
288         void f() {}
289     "]
290 }
291
292 ###############################
293 # proc check_alias_available { }
294 ###############################
295
296 # Determine if the target toolchain supports the alias attribute.
297
298 # Returns 2 if the target supports aliases.  Returns 1 if the target
299 # only supports weak aliased.  Returns 0 if the target does not
300 # support aliases at all.  Returns -1 if support for aliases could not
301 # be determined.
302
303 proc check_alias_available { } {
304     global alias_available_saved
305     global tool
306
307     if [info exists alias_available_saved] {
308         verbose "check_alias_available  returning saved $alias_available_saved" 2
309     } else {
310         set src alias[pid].c
311         set obj alias[pid].o
312         verbose "check_alias_available  compiling testfile $src" 2
313         set f [open $src "w"]
314         # Compile a small test program.  The definition of "g" is
315         # necessary to keep the Solaris assembler from complaining
316         # about the program.
317         puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
318         puts $f "void g() {} void f() __attribute__((alias(\"g\")));"
319         close $f
320         set lines [${tool}_target_compile $src $obj object ""]
321         file delete $src
322         remote_file build delete $obj
323
324         if [string match "" $lines] then {
325             # No error messages, everything is OK.
326             set alias_available_saved 2
327         } else {
328             if [regexp "alias definitions not supported" $lines] {
329                 verbose "check_alias_available  target does not support aliases" 2
330
331                 set objformat [gcc_target_object_format]
332
333                 if { $objformat == "elf" } {
334                     verbose "check_alias_available  but target uses ELF format, so it ought to" 2
335                     set alias_available_saved -1
336                 } else {
337                     set alias_available_saved 0
338                 }
339             } else {
340                 if [regexp "only weak aliases are supported" $lines] {
341                 verbose "check_alias_available  target supports only weak aliases" 2
342                 set alias_available_saved 1
343                 } else {
344                     set alias_available_saved -1
345                 }
346             }
347         }
348
349         verbose "check_alias_available  returning $alias_available_saved" 2
350     }
351
352     return $alias_available_saved
353 }
354
355 # Returns true if --gc-sections is supported on the target.
356
357 proc check_gc_sections_available { } {
358     global gc_sections_available_saved
359     global tool
360
361     if {![info exists gc_sections_available_saved]} {
362         # Some targets don't support gc-sections despite whatever's
363         # advertised by ld's options.
364         if { [istarget alpha*-*-*]
365              || [istarget ia64-*-*] } {
366             set gc_sections_available_saved 0
367             return 0
368         }
369
370         # elf2flt uses -q (--emit-relocs), which is incompatible with
371         # --gc-sections.
372         if { [board_info target exists ldflags]
373              && [regexp " -elf2flt\[ =\]" " [board_info target ldflags] "] } {
374             set gc_sections_available_saved 0
375             return 0
376         }
377
378         # VxWorks kernel modules are relocatable objects linked with -r,
379         # while RTP executables are linked with -q (--emit-relocs).
380         # Both of these options are incompatible with --gc-sections.
381         if { [istarget *-*-vxworks*] } {
382             set gc_sections_available_saved 0
383             return 0
384         }
385
386         # Check if the ld used by gcc supports --gc-sections.
387         set gcc_spec [${tool}_target_compile "-dumpspecs" "" "none" ""]
388         regsub ".*\n\*linker:\[ \t\]*\n(\[^ \t\n\]*).*" "$gcc_spec" {\1} linker
389         set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=$linker" "" "none" ""] 0]
390         set ld_output [remote_exec host "$gcc_ld" "--help"]
391         if { [ string first "--gc-sections" $ld_output ] >= 0 } {
392             set gc_sections_available_saved 1
393         } else {
394             set gc_sections_available_saved 0
395         }
396     }
397     return $gc_sections_available_saved
398 }
399
400 # Return 1 if according to target_info struct and explicit target list
401 # target is supposed to support trampolines.
402  
403 proc check_effective_target_trampolines { } {
404     if [target_info exists no_trampolines] {
405       return 0
406     }
407     if { [istarget avr-*-*]
408          || [istarget hppa2.0w-hp-hpux11.23]
409         || [istarget hppa64-hp-hpux11.23] } {
410         return 0;   
411     }
412     return 1
413 }
414
415 # Return 1 if according to target_info struct and explicit target list
416 # target is supposed to keep null pointer checks. This could be due to 
417 # use of option fno-delete-null-pointer-checks or hardwired in target.
418  
419 proc check_effective_target_keeps_null_pointer_checks { } {
420     if [target_info exists keeps_null_pointer_checks] {
421       return 1
422     }
423     if { [istarget avr-*-*] } {
424         return 1;   
425     }
426     return 0
427 }
428
429 # Return true if profiling is supported on the target.
430
431 proc check_profiling_available { test_what } {
432     global profiling_available_saved
433
434     verbose "Profiling argument is <$test_what>" 1
435
436     # These conditions depend on the argument so examine them before
437     # looking at the cache variable.
438
439     # Support for -p on solaris2 relies on mcrt1.o which comes with the
440     # vendor compiler.  We cannot reliably predict the directory where the
441     # vendor compiler (and thus mcrt1.o) is installed so we can't
442     # necessarily find mcrt1.o even if we have it.
443     if { [istarget *-*-solaris2*] && [lindex $test_what 1] == "-p" } {
444         return 0
445     }
446
447     # Support for -p on irix relies on libprof1.a which doesn't appear to
448     # exist on any irix6 system currently posting testsuite results.
449     # Support for -pg on irix relies on gcrt1.o which doesn't exist yet.
450     # See: http://gcc.gnu.org/ml/gcc/2002-10/msg00169.html
451     if { [istarget mips*-*-irix*]
452     && ([lindex $test_what 1] == "-p" || [lindex $test_what 1] == "-pg") } {
453         return 0
454     }
455
456     # We don't yet support profiling for MIPS16.
457     if { [istarget mips*-*-*]
458          && ![check_effective_target_nomips16]
459          && ([lindex $test_what 1] == "-p"
460              || [lindex $test_what 1] == "-pg") } {
461         return 0
462     }
463
464     # MinGW does not support -p.
465     if { [istarget *-*-mingw*] && [lindex $test_what 1] == "-p" } {
466         return 0
467     }
468
469     # uClibc does not have gcrt1.o.
470     if { [check_effective_target_uclibc]
471          && ([lindex $test_what 1] == "-p"
472              || [lindex $test_what 1] == "-pg") } {
473         return 0
474     }
475
476     # Now examine the cache variable.
477     if {![info exists profiling_available_saved]} {
478         # Some targets don't have any implementation of __bb_init_func or are
479         # missing other needed machinery.
480         if { [istarget mmix-*-*]
481              || [istarget arm*-*-eabi*]
482              || [istarget picochip-*-*]
483              || [istarget *-*-netware*]
484              || [istarget arm*-*-elf]
485              || [istarget arm*-*-symbianelf*]
486              || [istarget avr-*-*]
487              || [istarget bfin-*-*]
488              || [istarget powerpc-*-eabi*]
489              || [istarget cris-*-*]
490              || [istarget crisv32-*-*]
491              || [istarget fido-*-elf]
492              || [istarget h8300-*-*]
493              || [istarget m32c-*-elf]
494              || [istarget m68k-*-elf]
495              || [istarget m68k-*-uclinux*]
496              || [istarget mips*-*-elf*]
497              || [istarget xstormy16-*]
498              || [istarget xtensa*-*-elf]
499              || [istarget *-*-rtems*]
500              || [istarget *-*-vxworks*] } {
501             set profiling_available_saved 0
502         } else {
503             set profiling_available_saved 1
504         }
505     }
506
507     return $profiling_available_saved
508 }
509
510 # Check to see if a target is "freestanding". This is as per the definition
511 # in Section 4 of C99 standard. Effectively, it is a target which supports no
512 # extra headers or libraries other than what is considered essential.
513 proc check_effective_target_freestanding { } {
514     if { [istarget picochip-*-*] } then {
515         return 1
516     } else {
517         return 0
518     }
519 }
520
521 # Return 1 if target has packed layout of structure members by
522 # default, 0 otherwise.  Note that this is slightly different than
523 # whether the target has "natural alignment": both attributes may be
524 # false.
525
526 proc check_effective_target_default_packed { } {
527     return [check_no_compiler_messages default_packed assembly {
528         struct x { char a; long b; } c;
529         int s[sizeof (c) == sizeof (char) + sizeof (long) ? 1 : -1];
530     }]
531 }
532
533 # Return 1 if target has PCC_BITFIELD_TYPE_MATTERS defined.  See
534 # documentation, where the test also comes from.
535
536 proc check_effective_target_pcc_bitfield_type_matters { } {
537     # PCC_BITFIELD_TYPE_MATTERS isn't just about unnamed or empty
538     # bitfields, but let's stick to the example code from the docs.
539     return [check_no_compiler_messages pcc_bitfield_type_matters assembly {
540         struct foo1 { char x; char :0; char y; };
541         struct foo2 { char x; int :0; char y; };
542         int s[sizeof (struct foo1) != sizeof (struct foo2) ? 1 : -1];
543     }]
544 }
545
546 # Return 1 if thread local storage (TLS) is supported, 0 otherwise.
547 #
548 # This won't change for different subtargets so cache the result.
549
550 proc check_effective_target_tls {} {
551     return [check_no_compiler_messages tls assembly {
552         __thread int i;
553         int f (void) { return i; }
554         void g (int j) { i = j; }
555     }]
556 }
557
558 # Return 1 if *native* thread local storage (TLS) is supported, 0 otherwise.
559 #
560 # This won't change for different subtargets so cache the result.
561
562 proc check_effective_target_tls_native {} {
563     # VxWorks uses emulated TLS machinery, but with non-standard helper
564     # functions, so we fail to automatically detect it.
565     global target_triplet
566     if { [regexp ".*-.*-vxworks.*" $target_triplet] } {
567         return 0
568     }
569     
570     return [check_no_messages_and_pattern tls_native "!emutls" assembly {
571         __thread int i;
572         int f (void) { return i; }
573         void g (int j) { i = j; }
574     }]
575 }
576
577 # Return 1 if TLS executables can run correctly, 0 otherwise.
578 #
579 # This won't change for different subtargets so cache the result.
580
581 proc check_effective_target_tls_runtime {} {
582     return [check_runtime tls_runtime {
583         __thread int thr = 0;
584         int main (void) { return thr; }
585     }]
586 }
587
588 # Return 1 if compilation with -fgraphite is error-free for trivial 
589 # code, 0 otherwise.
590
591 proc check_effective_target_fgraphite {} {
592     return [check_no_compiler_messages fgraphite object {
593         void foo (void) { }
594     } "-O1 -fgraphite"]
595 }
596
597 # Return 1 if compilation with -fopenmp is error-free for trivial
598 # code, 0 otherwise.
599
600 proc check_effective_target_fopenmp {} {
601     return [check_no_compiler_messages fopenmp object {
602         void foo (void) { }
603     } "-fopenmp"]
604 }
605
606 # Return 1 if compilation with -pthread is error-free for trivial
607 # code, 0 otherwise.
608
609 proc check_effective_target_pthread {} {
610     return [check_no_compiler_messages pthread object {
611         void foo (void) { }
612     } "-pthread"]
613 }
614
615 # Return 1 if the target supports -fstack-protector
616 proc check_effective_target_fstack_protector {} {
617     return [check_runtime fstack_protector {
618         int main (void) { return 0; }
619     } "-fstack-protector"]
620 }
621
622 # Return 1 if compilation with -freorder-blocks-and-partition is error-free
623 # for trivial code, 0 otherwise.
624
625 proc check_effective_target_freorder {} {
626     return [check_no_compiler_messages freorder object {
627         void foo (void) { }
628     } "-freorder-blocks-and-partition"]
629 }
630
631 # Return 1 if -fpic and -fPIC are supported, as in no warnings or errors
632 # emitted, 0 otherwise.  Whether a shared library can actually be built is
633 # out of scope for this test.
634
635 proc check_effective_target_fpic { } {
636     # Note that M68K has a multilib that supports -fpic but not
637     # -fPIC, so we need to check both.  We test with a program that
638     # requires GOT references.
639     foreach arg {fpic fPIC} {
640         if [check_no_compiler_messages $arg object {
641             extern int foo (void); extern int bar;
642             int baz (void) { return foo () + bar; }
643         } "-$arg"] {
644             return 1
645         }
646     }
647     return 0
648 }
649
650 # Return true if the target supports -mpaired-single (as used on MIPS).
651
652 proc check_effective_target_mpaired_single { } {
653     return [check_no_compiler_messages mpaired_single object {
654         void foo (void) { }
655     } "-mpaired-single"]
656 }
657
658 # Return true if the target has access to FPU instructions.
659
660 proc check_effective_target_hard_float { } {
661     if { [istarget mips*-*-*] } {
662         return [check_no_compiler_messages hard_float assembly {
663                 #if (defined __mips_soft_float || defined __mips16)
664                 #error FOO
665                 #endif
666         }]
667     }
668
669     # The generic test equates hard_float with "no call for adding doubles".
670     return [check_no_messages_and_pattern hard_float "!\\(call" rtl-expand {
671         double a (double b, double c) { return b + c; }
672     }]
673 }
674
675 # Return true if the target is a 64-bit MIPS target.
676
677 proc check_effective_target_mips64 { } {
678     return [check_no_compiler_messages mips64 assembly {
679         #ifndef __mips64
680         #error FOO
681         #endif
682     }]
683 }
684
685 # Return true if the target is a MIPS target that does not produce
686 # MIPS16 code.
687
688 proc check_effective_target_nomips16 { } {
689     return [check_no_compiler_messages nomips16 object {
690         #ifndef __mips
691         #error FOO
692         #else
693         /* A cheap way of testing for -mflip-mips16.  */
694         void foo (void) { asm ("addiu $20,$20,1"); }
695         void bar (void) { asm ("addiu $20,$20,1"); }
696         #endif
697     }]
698 }
699
700 # Add the options needed for MIPS16 function attributes.  At the moment,
701 # we don't support MIPS16 PIC.
702
703 proc add_options_for_mips16_attribute { flags } {
704     return "$flags -mno-abicalls -fno-pic -DMIPS16=__attribute__((mips16))"
705 }
706
707 # Return true if we can force a mode that allows MIPS16 code generation.
708 # We don't support MIPS16 PIC, and only support MIPS16 -mhard-float
709 # for o32 and o64.
710
711 proc check_effective_target_mips16_attribute { } {
712     return [check_no_compiler_messages mips16_attribute assembly {
713         #ifdef PIC
714         #error FOO
715         #endif
716         #if defined __mips_hard_float \
717             && (!defined _ABIO32 || _MIPS_SIM != _ABIO32) \
718             && (!defined _ABIO64 || _MIPS_SIM != _ABIO64)
719         #error FOO
720         #endif
721     } [add_options_for_mips16_attribute ""]]
722 }
723
724 # Return 1 if the current multilib does not generate PIC by default.
725
726 proc check_effective_target_nonpic { } {
727     return [check_no_compiler_messages nonpic assembly {
728         #if __PIC__
729         #error FOO
730         #endif
731     }]
732 }
733
734 # Return 1 if the target does not use a status wrapper.
735
736 proc check_effective_target_unwrapped { } {
737     if { [target_info needs_status_wrapper] != "" \
738              && [target_info needs_status_wrapper] != "0" } {
739         return 0
740     }
741     return 1
742 }
743
744 # Return true if iconv is supported on the target. In particular IBM1047.
745
746 proc check_iconv_available { test_what } {
747     global libiconv
748
749     # If the tool configuration file has not set libiconv, try "-liconv"
750     if { ![info exists libiconv] } {
751         set libiconv "-liconv"
752     }
753     set test_what [lindex $test_what 1]
754     return [check_runtime_nocache $test_what [subst {
755         #include <iconv.h>
756         int main (void)
757         {
758           iconv_t cd;
759
760           cd = iconv_open ("$test_what", "UTF-8");
761           if (cd == (iconv_t) -1)
762             return 1;
763           return 0;
764         }
765     }] $libiconv]
766 }
767
768 # Return true if named sections are supported on this target.
769
770 proc check_named_sections_available { } {
771     return [check_no_compiler_messages named_sections assembly {
772         int __attribute__ ((section("whatever"))) foo;
773     }]
774 }
775
776 # Return 1 if the target supports Fortran real kinds larger than real(8),
777 # 0 otherwise.
778 #
779 # When the target name changes, replace the cached result.
780
781 proc check_effective_target_fortran_large_real { } {
782     return [check_no_compiler_messages fortran_large_real executable {
783         ! Fortran
784         integer,parameter :: k = selected_real_kind (precision (0.0_8) + 1)
785         real(kind=k) :: x
786         x = cos (x)
787         end
788     }]
789 }
790
791 # Return 1 if the target supports Fortran integer kinds larger than
792 # integer(8), 0 otherwise.
793 #
794 # When the target name changes, replace the cached result.
795
796 proc check_effective_target_fortran_large_int { } {
797     return [check_no_compiler_messages fortran_large_int executable {
798         ! Fortran
799         integer,parameter :: k = selected_int_kind (range (0_8) + 1)
800         integer(kind=k) :: i
801         end
802     }]
803 }
804
805 # Return 1 if the target supports Fortran integer(16), 0 otherwise.
806 #
807 # When the target name changes, replace the cached result.
808
809 proc check_effective_target_fortran_integer_16 { } {
810     return [check_no_compiler_messages fortran_integer_16 executable {
811         ! Fortran
812         integer(16) :: i
813         end
814     }]
815 }
816
817 # Return 1 if we can statically link libgfortran, 0 otherwise.
818 #
819 # When the target name changes, replace the cached result.
820
821 proc check_effective_target_static_libgfortran { } {
822     return [check_no_compiler_messages static_libgfortran executable {
823         ! Fortran
824         print *, 'test'
825         end
826     } "-static"]
827 }
828
829 # Return 1 if the target supports executing 750CL paired-single instructions, 0
830 # otherwise.  Cache the result.
831
832 proc check_750cl_hw_available { } {
833     return [check_cached_effective_target 750cl_hw_available {
834         # If this is not the right target then we can skip the test.
835         if { ![istarget powerpc-*paired*] } {
836             expr 0
837         } else {
838             check_runtime_nocache 750cl_hw_available {
839                  int main()
840                  {
841                  #ifdef __MACH__
842                    asm volatile ("ps_mul v0,v0,v0");
843                  #else
844                    asm volatile ("ps_mul 0,0,0");
845                  #endif
846                    return 0;
847                  }
848             } "-mpaired"
849         }
850     }]
851 }
852
853 # Return 1 if the target supports executing SSE2 instructions, 0
854 # otherwise.  Cache the result.
855
856 proc check_sse2_hw_available { } {
857     return [check_cached_effective_target sse2_hw_available {
858         # If this is not the right target then we can skip the test.
859         if { !([istarget x86_64-*-*] || [istarget i?86-*-*]) } {
860             expr 0
861         } else {
862             check_runtime_nocache sse2_hw_available {
863                 #include "cpuid.h"
864                 int main ()
865                 {
866                   unsigned int eax, ebx, ecx, edx = 0;
867                   if (__get_cpuid (1, &eax, &ebx, &ecx, &edx))
868                     return !(edx & bit_SSE2);
869                   return 1;
870                 }
871             } ""
872         }
873     }]
874 }
875
876 # Return 1 if the target supports executing AltiVec instructions, 0
877 # otherwise.  Cache the result.
878
879 proc check_vmx_hw_available { } {
880     return [check_cached_effective_target vmx_hw_available {
881         # Some simulators are known to not support VMX instructions.
882         if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
883             expr 0
884         } else {
885             # Most targets don't require special flags for this test case, but
886             # Darwin does.
887             if { [istarget *-*-darwin*]
888                  || [istarget *-*-aix*] } {
889                 set options "-maltivec"
890             } else {
891                 set options ""
892             }
893             check_runtime_nocache vmx_hw_available {
894                 int main()
895                 {
896                 #ifdef __MACH__
897                   asm volatile ("vor v0,v0,v0");
898                 #else
899                   asm volatile ("vor 0,0,0");
900                 #endif
901                   return 0;
902                 }
903             } $options
904         }
905     }]
906 }
907
908 # GCC 3.4.0 for powerpc64-*-linux* included an ABI fix for passing
909 # complex float arguments.  This affects gfortran tests that call cabsf
910 # in libm built by an earlier compiler.  Return 1 if libm uses the same
911 # argument passing as the compiler under test, 0 otherwise.
912 #
913 # When the target name changes, replace the cached result.
914
915 proc check_effective_target_broken_cplxf_arg { } {
916     return [check_cached_effective_target broken_cplxf_arg {
917         # Skip the work for targets known not to be affected.
918         if { ![istarget powerpc64-*-linux*] } {
919             expr 0
920         } elseif { ![is-effective-target lp64] } {
921             expr 0
922         } else {
923             check_runtime_nocache broken_cplxf_arg {
924                 #include <complex.h>
925                 extern void abort (void);
926                 float fabsf (float);
927                 float cabsf (_Complex float);
928                 int main ()
929                 {
930                   _Complex float cf;
931                   float f;
932                   cf = 3 + 4.0fi;
933                   f = cabsf (cf);
934                   if (fabsf (f - 5.0) > 0.0001)
935                     abort ();
936                   return 0;
937                 }
938             } "-lm"
939         }
940     }]
941 }
942
943 proc check_alpha_max_hw_available { } {
944     return [check_runtime alpha_max_hw_available {
945         int main() { return __builtin_alpha_amask(1<<8) != 0; }
946     }]
947 }
948
949 # Returns true iff the FUNCTION is available on the target system.
950 # (This is essentially a Tcl implementation of Autoconf's
951 # AC_CHECK_FUNC.)
952
953 proc check_function_available { function } {
954     return [check_no_compiler_messages ${function}_available \
955                 executable [subst {
956         #ifdef __cplusplus
957         extern "C"
958         #endif
959         char $function ();
960         int main () { $function (); }
961     }]]
962 }
963
964 # Returns true iff "fork" is available on the target system.
965
966 proc check_fork_available {} {
967     return [check_function_available "fork"]
968 }
969
970 # Returns true iff "mkfifo" is available on the target system.
971
972 proc check_mkfifo_available {} {
973     if {[istarget *-*-cygwin*]} {
974        # Cygwin has mkfifo, but support is incomplete.
975        return 0
976      }
977
978     return [check_function_available "mkfifo"]
979 }
980
981 # Returns true iff "__cxa_atexit" is used on the target system.
982
983 proc check_cxa_atexit_available { } {
984     return [check_cached_effective_target cxa_atexit_available {
985         if { [istarget "hppa*-*-hpux10*"] } {
986             # HP-UX 10 doesn't have __cxa_atexit but subsequent test passes.
987             expr 0
988         } else {
989             check_runtime_nocache cxa_atexit_available {
990                 // C++
991                 #include <stdlib.h>
992                 static unsigned int count;
993                 struct X
994                 {
995                   X() { count = 1; }
996                   ~X()
997                   {
998                     if (count != 3)
999                       exit(1);
1000                     count = 4;
1001                   }
1002                 };
1003                 void f()
1004                 {
1005                   static X x;
1006                 }
1007                 struct Y
1008                 {
1009                   Y() { f(); count = 2; }
1010                   ~Y()
1011                   {
1012                     if (count != 2)
1013                       exit(1);
1014                     count = 3;
1015                   }
1016                 };
1017                 Y y;
1018                 int main() { return 0; }
1019             }
1020         }
1021     }]
1022 }
1023
1024
1025 # Return 1 if we're generating 32-bit code using default options, 0
1026 # otherwise.
1027
1028 proc check_effective_target_ilp32 { } {
1029     return [check_no_compiler_messages ilp32 object {
1030         int dummy[sizeof (int) == 4
1031                   && sizeof (void *) == 4
1032                   && sizeof (long) == 4 ? 1 : -1];
1033     }]
1034 }
1035
1036 # Return 1 if we're generating 32-bit or larger integers using default
1037 # options, 0 otherwise.
1038
1039 proc check_effective_target_int32plus { } {
1040     return [check_no_compiler_messages int32plus object {
1041         int dummy[sizeof (int) >= 4 ? 1 : -1];
1042     }]
1043 }
1044
1045 # Return 1 if we're generating 32-bit or larger pointers using default
1046 # options, 0 otherwise.
1047
1048 proc check_effective_target_ptr32plus { } {
1049     return [check_no_compiler_messages ptr32plus object {
1050         int dummy[sizeof (void *) >= 4 ? 1 : -1];
1051     }]
1052 }
1053
1054 # Return 1 if we support 32-bit or larger array and structure sizes
1055 # using default options, 0 otherwise.
1056
1057 proc check_effective_target_size32plus { } {
1058     return [check_no_compiler_messages size32plus object {
1059         char dummy[65537];
1060     }]
1061 }
1062
1063 # Returns 1 if we're generating 16-bit or smaller integers with the
1064 # default options, 0 otherwise.
1065
1066 proc check_effective_target_int16 { } {
1067     return [check_no_compiler_messages int16 object {
1068         int dummy[sizeof (int) < 4 ? 1 : -1];
1069     }]
1070 }
1071
1072 # Return 1 if we're generating 64-bit code using default options, 0
1073 # otherwise.
1074
1075 proc check_effective_target_lp64 { } {
1076     return [check_no_compiler_messages lp64 object {
1077         int dummy[sizeof (int) == 4
1078                   && sizeof (void *) == 8
1079                   && sizeof (long) == 8 ? 1 : -1];
1080     }]
1081 }
1082
1083 # Return 1 if we're generating 64-bit code using default llp64 options,
1084 # 0 otherwise.
1085
1086 proc check_effective_target_llp64 { } {
1087     return [check_no_compiler_messages llp64 object {
1088         int dummy[sizeof (int) == 4
1089                   && sizeof (void *) == 8
1090                   && sizeof (long long) == 8
1091                   && sizeof (long) == 4 ? 1 : -1];
1092     }]
1093 }
1094
1095 # Return 1 if the target supports long double larger than double,
1096 # 0 otherwise.
1097
1098 proc check_effective_target_large_long_double { } {
1099     return [check_no_compiler_messages large_long_double object {
1100         int dummy[sizeof(long double) > sizeof(double) ? 1 : -1];
1101     }]
1102 }
1103
1104 # Return 1 if the target supports compiling fixed-point,
1105 # 0 otherwise.
1106
1107 proc check_effective_target_fixed_point { } {
1108     return [check_no_compiler_messages fixed_point object {
1109         _Sat _Fract x; _Sat _Accum y;
1110     }]
1111 }
1112
1113 # Return 1 if the target supports compiling decimal floating point,
1114 # 0 otherwise.
1115
1116 proc check_effective_target_dfp_nocache { } {
1117     verbose "check_effective_target_dfp_nocache: compiling source" 2
1118     set ret [check_no_compiler_messages_nocache dfp object {
1119         _Decimal32 x; _Decimal64 y; _Decimal128 z;
1120     }]
1121     verbose "check_effective_target_dfp_nocache: returning $ret" 2
1122     return $ret
1123 }
1124
1125 proc check_effective_target_dfprt_nocache { } {
1126     return [check_runtime_nocache dfprt {
1127         _Decimal32 x = 1.2df; _Decimal64 y = 2.3dd; _Decimal128 z;
1128         int main () { z = x + y; return 0; }
1129     }]
1130 }
1131
1132 # Return 1 if the target supports compiling Decimal Floating Point,
1133 # 0 otherwise.
1134 #
1135 # This won't change for different subtargets so cache the result.
1136
1137 proc check_effective_target_dfp { } {
1138     return [check_cached_effective_target dfp {
1139         check_effective_target_dfp_nocache
1140     }]
1141 }
1142
1143 # Return 1 if the target supports linking and executing Decimal Floating
1144 # Point, # 0 otherwise.
1145 #
1146 # This won't change for different subtargets so cache the result.
1147
1148 proc check_effective_target_dfprt { } {
1149     return [check_cached_effective_target dfprt {
1150         check_effective_target_dfprt_nocache
1151     }]
1152 }
1153
1154 # Return 1 if the target needs a command line argument to enable a SIMD
1155 # instruction set.
1156
1157 proc check_effective_target_vect_cmdline_needed { } {
1158     global et_vect_cmdline_needed_saved
1159     global et_vect_cmdline_needed_target_name
1160
1161     if { ![info exists et_vect_cmdline_needed_target_name] } {
1162         set et_vect_cmdline_needed_target_name ""
1163     }
1164
1165     # If the target has changed since we set the cached value, clear it.
1166     set current_target [current_target_name]
1167     if { $current_target != $et_vect_cmdline_needed_target_name } {
1168         verbose "check_effective_target_vect_cmdline_needed: `$et_vect_cmdline_needed_target_name' `$current_target'" 2
1169         set et_vect_cmdline_needed_target_name $current_target
1170         if { [info exists et_vect_cmdline_needed_saved] } {
1171             verbose "check_effective_target_vect_cmdline_needed: removing cached result" 2
1172             unset et_vect_cmdline_needed_saved
1173         }
1174     }
1175
1176     if [info exists et_vect_cmdline_needed_saved] {
1177         verbose "check_effective_target_vect_cmdline_needed: using cached result" 2
1178     } else {
1179         set et_vect_cmdline_needed_saved 1
1180         if { [istarget ia64-*-*]
1181              || (([istarget x86_64-*-*] || [istarget i?86-*-*])
1182                  && [check_effective_target_lp64])
1183              || ([istarget powerpc*-*-*]
1184                  && ([check_effective_target_powerpc_spe]
1185                      || [check_effective_target_powerpc_altivec]))
1186              || [istarget spu-*-*]
1187              || ([istarget arm*-*-*] && [check_effective_target_arm_neon]) } {
1188            set et_vect_cmdline_needed_saved 0
1189         }
1190     }
1191
1192     verbose "check_effective_target_vect_cmdline_needed: returning $et_vect_cmdline_needed_saved" 2
1193     return $et_vect_cmdline_needed_saved
1194 }
1195
1196 # Return 1 if the target supports hardware vectors of int, 0 otherwise.
1197 #
1198 # This won't change for different subtargets so cache the result.
1199
1200 proc check_effective_target_vect_int { } {
1201     global et_vect_int_saved
1202
1203     if [info exists et_vect_int_saved] {
1204         verbose "check_effective_target_vect_int: using cached result" 2
1205     } else {
1206         set et_vect_int_saved 0
1207         if { [istarget i?86-*-*]
1208              || ([istarget powerpc*-*-*]
1209                   && ![istarget powerpc-*-linux*paired*])
1210               || [istarget spu-*-*]
1211               || [istarget x86_64-*-*]
1212               || [istarget sparc*-*-*]
1213               || [istarget alpha*-*-*]
1214               || [istarget ia64-*-*] 
1215               || [check_effective_target_arm32] } {
1216            set et_vect_int_saved 1
1217         }
1218     }
1219
1220     verbose "check_effective_target_vect_int: returning $et_vect_int_saved" 2
1221     return $et_vect_int_saved
1222 }
1223
1224 # Return 1 if the target supports int->float conversion 
1225 #
1226
1227 proc check_effective_target_vect_intfloat_cvt { } {
1228     global et_vect_intfloat_cvt_saved
1229
1230     if [info exists et_vect_intfloat_cvt_saved] {
1231         verbose "check_effective_target_vect_intfloat_cvt: using cached result" 2
1232     } else {
1233         set et_vect_intfloat_cvt_saved 0
1234         if { [istarget i?86-*-*]
1235               || ([istarget powerpc*-*-*]
1236                    && ![istarget powerpc-*-linux*paired*])
1237               || [istarget x86_64-*-*] } {
1238            set et_vect_intfloat_cvt_saved 1
1239         }
1240     }
1241
1242     verbose "check_effective_target_vect_intfloat_cvt: returning $et_vect_intfloat_cvt_saved" 2
1243     return $et_vect_intfloat_cvt_saved
1244 }
1245
1246
1247 # Return 1 if the target supports float->int conversion
1248 #
1249
1250 proc check_effective_target_vect_floatint_cvt { } {
1251     global et_vect_floatint_cvt_saved
1252
1253     if [info exists et_vect_floatint_cvt_saved] {
1254         verbose "check_effective_target_vect_floatint_cvt: using cached result" 2
1255     } else {
1256         set et_vect_floatint_cvt_saved 0
1257         if { [istarget i?86-*-*]
1258               || ([istarget powerpc*-*-*]
1259                    && ![istarget powerpc-*-linux*paired*])
1260               || [istarget x86_64-*-*] } {
1261            set et_vect_floatint_cvt_saved 1
1262         }
1263     }
1264
1265     verbose "check_effective_target_vect_floatint_cvt: returning $et_vect_floatint_cvt_saved" 2
1266     return $et_vect_floatint_cvt_saved
1267 }
1268
1269 # Return 1 is this is an arm target using 32-bit instructions
1270 proc check_effective_target_arm32 { } {
1271     return [check_no_compiler_messages arm32 assembly {
1272         #if !defined(__arm__) || (defined(__thumb__) && !defined(__thumb2__))
1273         #error FOO
1274         #endif
1275     }]
1276 }
1277
1278 # Return 1 if this is an ARM target supporting -mfpu=vfp
1279 # -mfloat-abi=softfp.  Some multilibs may be incompatible with these
1280 # options.
1281
1282 proc check_effective_target_arm_vfp_ok { } {
1283     if { [check_effective_target_arm32] } {
1284         return [check_no_compiler_messages arm_vfp_ok object {
1285             int dummy;
1286         } "-mfpu=vfp -mfloat-abi=softfp"]
1287     } else {
1288         return 0
1289     }
1290 }
1291
1292 # Return 1 if this is an ARM target supporting -mfpu=neon
1293 # -mfloat-abi=softfp.  Some multilibs may be incompatible with these
1294 # options.
1295
1296 proc check_effective_target_arm_neon_ok { } {
1297     if { [check_effective_target_arm32] } {
1298         return [check_no_compiler_messages arm_neon_ok object {
1299             int dummy;
1300         } "-mfpu=neon -mfloat-abi=softfp"]
1301     } else {
1302         return 0
1303     }
1304 }
1305
1306 # Return 1 is this is an ARM target where -mthumb causes Thumb-1 to be
1307 # used.
1308
1309 proc check_effective_target_arm_thumb1_ok { } {
1310     return [check_no_compiler_messages arm_thumb1_ok assembly {
1311         #if !defined(__arm__) || !defined(__thumb__) || defined(__thumb2__)
1312         #error FOO
1313         #endif
1314     } "-mthumb"]
1315 }
1316
1317 # Return 1 if the target supports executing NEON instructions, 0
1318 # otherwise.  Cache the result.
1319
1320 proc check_effective_target_arm_neon_hw { } {
1321     return [check_runtime arm_neon_hw_available {
1322         int
1323         main (void)
1324         {
1325           long long a = 0, b = 1;
1326           asm ("vorr %P0, %P1, %P2"
1327                : "=w" (a)
1328                : "0" (a), "w" (b));
1329           return (a != 1);
1330         }
1331     } "-mfpu=neon -mfloat-abi=softfp"]
1332 }
1333
1334 # Return 1 if this is a ARM target with NEON enabled.
1335
1336 proc check_effective_target_arm_neon { } {
1337     if { [check_effective_target_arm32] } {
1338         return [check_no_compiler_messages arm_neon object {
1339             #ifndef __ARM_NEON__
1340             #error not NEON
1341             #else
1342             int dummy;
1343             #endif
1344         }]
1345     } else {
1346         return 0
1347     }
1348 }
1349
1350 # Return 1 if this a Loongson-2E or -2F target using an ABI that supports
1351 # the Loongson vector modes.
1352
1353 proc check_effective_target_mips_loongson { } {
1354     return [check_no_compiler_messages loongson assembly {
1355         #if !defined(__mips_loongson_vector_rev)
1356         #error FOO
1357         #endif
1358     }]
1359 }
1360
1361 # Return 1 if this is a PowerPC target with floating-point registers.
1362
1363 proc check_effective_target_powerpc_fprs { } {
1364     if { [istarget powerpc*-*-*]
1365          || [istarget rs6000-*-*] } {
1366         return [check_no_compiler_messages powerpc_fprs object {
1367             #ifdef __NO_FPRS__
1368             #error no FPRs
1369             #else
1370             int dummy;
1371             #endif
1372         }]
1373     } else {
1374         return 0
1375     }
1376 }
1377
1378 # Return 1 if this is a PowerPC target with hardware double-precision
1379 # floating point.
1380
1381 proc check_effective_target_powerpc_hard_double { } {
1382     if { [istarget powerpc*-*-*]
1383          || [istarget rs6000-*-*] } {
1384         return [check_no_compiler_messages powerpc_hard_double object {
1385             #ifdef _SOFT_DOUBLE
1386             #error soft double
1387             #else
1388             int dummy;
1389             #endif
1390         }]
1391     } else {
1392         return 0
1393     }
1394 }
1395
1396 # Return 1 if this is a PowerPC target supporting -maltivec.
1397
1398 proc check_effective_target_powerpc_altivec_ok { } {
1399     if { ([istarget powerpc*-*-*]
1400          && ![istarget powerpc-*-linux*paired*])
1401          || [istarget rs6000-*-*] } {
1402         # AltiVec is not supported on AIX before 5.3.
1403         if { [istarget powerpc*-*-aix4*]
1404              || [istarget powerpc*-*-aix5.1*] 
1405              || [istarget powerpc*-*-aix5.2*] } {
1406             return 0
1407         }
1408         return [check_no_compiler_messages powerpc_altivec_ok object {
1409             int dummy;
1410         } "-maltivec"]
1411     } else {
1412         return 0
1413     }
1414 }
1415
1416 # Return 1 if this is a PowerPC target supporting -mcpu=cell.
1417
1418 proc check_effective_target_powerpc_ppu_ok { } {
1419     if [check_effective_target_powerpc_altivec_ok] {
1420         return [check_no_compiler_messages cell_asm_available object {
1421             int main (void) {
1422 #ifdef __MACH__
1423                 asm volatile ("lvlx v0,v0,v0");
1424 #else
1425                 asm volatile ("lvlx 0,0,0");
1426 #endif
1427                 return 0;
1428             }
1429         }]
1430     } else {
1431         return 0
1432     }
1433 }
1434
1435 # Return 1 if this is a PowerPC target that supports SPU.
1436
1437 proc check_effective_target_powerpc_spu { } {
1438     if [istarget powerpc*-*-linux*] {
1439         return [check_effective_target_powerpc_altivec_ok]
1440     } else {
1441         return 0
1442     }
1443 }
1444
1445 # Return 1 if this is a PowerPC target with SPE enabled.
1446
1447 proc check_effective_target_powerpc_spe { } {
1448     if { [istarget powerpc*-*-*] } {
1449         return [check_no_compiler_messages powerpc_spe object {
1450             #ifndef __SPE__
1451             #error not SPE
1452             #else
1453             int dummy;
1454             #endif
1455         }]
1456     } else {
1457         return 0
1458     }
1459 }
1460
1461 # Return 1 if this is a PowerPC target with Altivec enabled.
1462
1463 proc check_effective_target_powerpc_altivec { } {
1464     if { [istarget powerpc*-*-*] } {
1465         return [check_no_compiler_messages powerpc_altivec object {
1466             #ifndef __ALTIVEC__
1467             #error not Altivec
1468             #else
1469             int dummy;
1470             #endif
1471         }]
1472     } else {
1473         return 0
1474     }
1475 }
1476
1477 # Return 1 if this is a PowerPC 405 target.  The check includes options
1478 # specified by dg-options for this test, so don't cache the result.
1479
1480 proc check_effective_target_powerpc_405_nocache { } {
1481     if { [istarget powerpc*-*-*] || [istarget rs6000-*-*] } {
1482         return [check_no_compiler_messages_nocache powerpc_405 object {
1483             #ifdef __PPC405__
1484             int dummy;
1485             #else
1486             #error not a PPC405
1487             #endif
1488         } [current_compiler_flags]]
1489     } else {
1490         return 0
1491     }
1492 }
1493
1494 # Return 1 if this is a SPU target with a toolchain that
1495 # supports automatic overlay generation.
1496
1497 proc check_effective_target_spu_auto_overlay { } {
1498     if { [istarget spu*-*-elf*] } {
1499         return [check_no_compiler_messages spu_auto_overlay executable {
1500                 int main (void) { }
1501                 } "-Wl,--auto-overlay" ]
1502     } else {
1503         return 0
1504     }
1505 }
1506
1507 # The VxWorks SPARC simulator accepts only EM_SPARC executables and
1508 # chokes on EM_SPARC32PLUS or EM_SPARCV9 executables.  Return 1 if the
1509 # test environment appears to run executables on such a simulator.
1510
1511 proc check_effective_target_ultrasparc_hw { } {
1512     return [check_runtime ultrasparc_hw {
1513         int main() { return 0; }
1514     } "-mcpu=ultrasparc"]
1515 }
1516
1517 # Return 1 if the target supports hardware vector shift operation.
1518
1519 proc check_effective_target_vect_shift { } {
1520     global et_vect_shift_saved
1521
1522     if [info exists et_vect_shift_saved] {
1523         verbose "check_effective_target_vect_shift: using cached result" 2
1524     } else {
1525         set et_vect_shift_saved 0
1526         if { ([istarget powerpc*-*-*]
1527              && ![istarget powerpc-*-linux*paired*])
1528              || [istarget ia64-*-*]
1529              || [istarget i?86-*-*]
1530              || [istarget x86_64-*-*]
1531              || [check_effective_target_arm32] } {
1532            set et_vect_shift_saved 1
1533         }
1534     }
1535
1536     verbose "check_effective_target_vect_shift: returning $et_vect_shift_saved" 2
1537     return $et_vect_shift_saved
1538 }
1539
1540 # Return 1 if the target supports hardware vectors of long, 0 otherwise.
1541 #
1542 # This can change for different subtargets so do not cache the result.
1543
1544 proc check_effective_target_vect_long { } {
1545     if { [istarget i?86-*-*]
1546          || (([istarget powerpc*-*-*] 
1547               && ![istarget powerpc-*-linux*paired*]) 
1548               && [check_effective_target_ilp32])
1549          || [istarget x86_64-*-*]
1550          || [check_effective_target_arm32]
1551          || ([istarget sparc*-*-*] && [check_effective_target_ilp32]) } {
1552         set answer 1
1553     } else {
1554         set answer 0
1555     }
1556
1557     verbose "check_effective_target_vect_long: returning $answer" 2
1558     return $answer
1559 }
1560
1561 # Return 1 if the target supports hardware vectors of float, 0 otherwise.
1562 #
1563 # This won't change for different subtargets so cache the result.
1564
1565 proc check_effective_target_vect_float { } {
1566     global et_vect_float_saved
1567
1568     if [info exists et_vect_float_saved] {
1569         verbose "check_effective_target_vect_float: using cached result" 2
1570     } else {
1571         set et_vect_float_saved 0
1572         if { [istarget i?86-*-*]
1573               || [istarget powerpc*-*-*]
1574               || [istarget spu-*-*]
1575               || [istarget mipsisa64*-*-*]
1576               || [istarget x86_64-*-*]
1577               || [istarget ia64-*-*]
1578               || [check_effective_target_arm32] } {
1579            set et_vect_float_saved 1
1580         }
1581     }
1582
1583     verbose "check_effective_target_vect_float: returning $et_vect_float_saved" 2
1584     return $et_vect_float_saved
1585 }
1586
1587 # Return 1 if the target supports hardware vectors of double, 0 otherwise.
1588 #
1589 # This won't change for different subtargets so cache the result.
1590
1591 proc check_effective_target_vect_double { } {
1592     global et_vect_double_saved
1593
1594     if [info exists et_vect_double_saved] {
1595         verbose "check_effective_target_vect_double: using cached result" 2
1596     } else {
1597         set et_vect_double_saved 0
1598         if { [istarget i?86-*-*]
1599               || [istarget x86_64-*-*] 
1600               || [istarget spu-*-*] } {
1601            set et_vect_double_saved 1
1602         }
1603     }
1604
1605     verbose "check_effective_target_vect_double: returning $et_vect_double_saved" 2
1606     return $et_vect_double_saved
1607 }
1608
1609 # Return 1 if the target supports hardware vectors of long long, 0 otherwise.
1610 #
1611 # This won't change for different subtargets so cache the result.
1612
1613 proc check_effective_target_vect_long_long { } {
1614     global et_vect_long_long_saved
1615
1616     if [info exists et_vect_long_long_saved] {
1617         verbose "check_effective_target_vect_long_long: using cached result" 2
1618     } else {
1619         set et_vect_long_long_saved 0
1620         if { [istarget i?86-*-*]
1621               || [istarget x86_64-*-*] } {
1622            set et_vect_long_long_saved 1
1623         }
1624     }
1625
1626     verbose "check_effective_target_vect_long_long: returning $et_vect_long_long_saved" 2
1627     return $et_vect_long_long_saved
1628 }
1629
1630
1631 # Return 1 if the target plus current options does not support a vector
1632 # max instruction on "int", 0 otherwise.
1633 #
1634 # This won't change for different subtargets so cache the result.
1635
1636 proc check_effective_target_vect_no_int_max { } {
1637     global et_vect_no_int_max_saved
1638
1639     if [info exists et_vect_no_int_max_saved] {
1640         verbose "check_effective_target_vect_no_int_max: using cached result" 2
1641     } else {
1642         set et_vect_no_int_max_saved 0
1643         if { [istarget sparc*-*-*]
1644              || [istarget spu-*-*]
1645              || [istarget alpha*-*-*] } {
1646             set et_vect_no_int_max_saved 1
1647         }
1648     }
1649     verbose "check_effective_target_vect_no_int_max: returning $et_vect_no_int_max_saved" 2
1650     return $et_vect_no_int_max_saved
1651 }
1652
1653 # Return 1 if the target plus current options does not support a vector
1654 # add instruction on "int", 0 otherwise.
1655 #
1656 # This won't change for different subtargets so cache the result.
1657
1658 proc check_effective_target_vect_no_int_add { } {
1659     global et_vect_no_int_add_saved
1660
1661     if [info exists et_vect_no_int_add_saved] {
1662         verbose "check_effective_target_vect_no_int_add: using cached result" 2
1663     } else {
1664         set et_vect_no_int_add_saved 0
1665         # Alpha only supports vector add on V8QI and V4HI.
1666         if { [istarget alpha*-*-*] } {
1667             set et_vect_no_int_add_saved 1
1668         }
1669     }
1670     verbose "check_effective_target_vect_no_int_add: returning $et_vect_no_int_add_saved" 2
1671     return $et_vect_no_int_add_saved
1672 }
1673
1674 # Return 1 if the target plus current options does not support vector
1675 # bitwise instructions, 0 otherwise.
1676 #
1677 # This won't change for different subtargets so cache the result.
1678
1679 proc check_effective_target_vect_no_bitwise { } {
1680     global et_vect_no_bitwise_saved
1681
1682     if [info exists et_vect_no_bitwise_saved] {
1683         verbose "check_effective_target_vect_no_bitwise: using cached result" 2
1684     } else {
1685         set et_vect_no_bitwise_saved 0
1686     }
1687     verbose "check_effective_target_vect_no_bitwise: returning $et_vect_no_bitwise_saved" 2
1688     return $et_vect_no_bitwise_saved
1689 }
1690
1691 # Return 1 if the target plus current options supports vector permutation,
1692 # 0 otherwise.
1693 #
1694 # This won't change for different subtargets so cache the result.
1695
1696 proc check_effective_target_vect_perm { } {
1697     global et_vect_perm
1698
1699     if [info exists et_vect_perm_saved] {
1700         verbose "check_effective_target_vect_perm: using cached result" 2
1701     } else {
1702         set et_vect_perm_saved 0
1703         if { [istarget powerpc*-*-*]
1704              || [istarget spu-*-*] } {
1705             set et_vect_perm_saved 1
1706         }
1707     }
1708     verbose "check_effective_target_vect_perm: returning $et_vect_perm_saved" 2
1709     return $et_vect_perm_saved
1710 }
1711
1712
1713 # Return 1 if the target plus current options supports a vector
1714 # widening summation of *short* args into *int* result, 0 otherwise.
1715 # A target can also support this widening summation if it can support
1716 # promotion (unpacking) from shorts to ints.
1717 #
1718 # This won't change for different subtargets so cache the result.
1719                                                                                                 
1720 proc check_effective_target_vect_widen_sum_hi_to_si { } {
1721     global et_vect_widen_sum_hi_to_si
1722
1723     if [info exists et_vect_widen_sum_hi_to_si_saved] {
1724         verbose "check_effective_target_vect_widen_sum_hi_to_si: using cached result" 2
1725     } else {
1726         set et_vect_widen_sum_hi_to_si_saved [check_effective_target_vect_unpack]
1727         if { [istarget powerpc*-*-*] 
1728              || [istarget ia64-*-*] } {
1729             set et_vect_widen_sum_hi_to_si_saved 1
1730         }
1731     }
1732     verbose "check_effective_target_vect_widen_sum_hi_to_si: returning $et_vect_widen_sum_hi_to_si_saved" 2
1733     return $et_vect_widen_sum_hi_to_si_saved
1734 }
1735
1736 # Return 1 if the target plus current options supports a vector
1737 # widening summation of *char* args into *short* result, 0 otherwise.
1738 # A target can also support this widening summation if it can support
1739 # promotion (unpacking) from chars to shorts.
1740 #
1741 # This won't change for different subtargets so cache the result.
1742                                                                                                 
1743 proc check_effective_target_vect_widen_sum_qi_to_hi { } {
1744     global et_vect_widen_sum_qi_to_hi
1745
1746     if [info exists et_vect_widen_sum_qi_to_hi_saved] {
1747         verbose "check_effective_target_vect_widen_sum_qi_to_hi: using cached result" 2
1748     } else {
1749         set et_vect_widen_sum_qi_to_hi_saved 0
1750         if { [check_effective_target_vect_unpack] 
1751              || [istarget ia64-*-*] } {
1752             set et_vect_widen_sum_qi_to_hi_saved 1
1753         }
1754     }
1755     verbose "check_effective_target_vect_widen_sum_qi_to_hi: returning $et_vect_widen_sum_qi_to_hi_saved" 2
1756     return $et_vect_widen_sum_qi_to_hi_saved
1757 }
1758
1759 # Return 1 if the target plus current options supports a vector
1760 # widening summation of *char* args into *int* result, 0 otherwise.
1761 #
1762 # This won't change for different subtargets so cache the result.
1763                                                                                                 
1764 proc check_effective_target_vect_widen_sum_qi_to_si { } {
1765     global et_vect_widen_sum_qi_to_si
1766
1767     if [info exists et_vect_widen_sum_qi_to_si_saved] {
1768         verbose "check_effective_target_vect_widen_sum_qi_to_si: using cached result" 2
1769     } else {
1770         set et_vect_widen_sum_qi_to_si_saved 0
1771         if { [istarget powerpc*-*-*] } {
1772             set et_vect_widen_sum_qi_to_si_saved 1
1773         }
1774     }
1775     verbose "check_effective_target_vect_widen_sum_qi_to_si: returning $et_vect_widen_sum_qi_to_si_saved" 2
1776     return $et_vect_widen_sum_qi_to_si_saved
1777 }
1778
1779 # Return 1 if the target plus current options supports a vector
1780 # widening multiplication of *char* args into *short* result, 0 otherwise.
1781 # A target can also support this widening multplication if it can support
1782 # promotion (unpacking) from chars to shorts, and vect_short_mult (non-widening
1783 # multiplication of shorts).
1784 #
1785 # This won't change for different subtargets so cache the result.
1786
1787
1788 proc check_effective_target_vect_widen_mult_qi_to_hi { } {
1789     global et_vect_widen_mult_qi_to_hi
1790
1791     if [info exists et_vect_widen_mult_qi_to_hi_saved] {
1792         verbose "check_effective_target_vect_widen_mult_qi_to_hi: using cached result" 2
1793     } else {
1794         if { [check_effective_target_vect_unpack]
1795              && [check_effective_target_vect_short_mult] } {
1796             set et_vect_widen_mult_qi_to_hi_saved 1
1797         } else {
1798             set et_vect_widen_mult_qi_to_hi_saved 0
1799         }
1800         if { [istarget powerpc*-*-*] } {
1801             set et_vect_widen_mult_qi_to_hi_saved 1
1802         }
1803     }
1804     verbose "check_effective_target_vect_widen_mult_qi_to_hi: returning $et_vect_widen_mult_qi_to_hi_saved" 2
1805     return $et_vect_widen_mult_qi_to_hi_saved
1806 }
1807
1808 # Return 1 if the target plus current options supports a vector
1809 # widening multiplication of *short* args into *int* result, 0 otherwise.
1810 # A target can also support this widening multplication if it can support
1811 # promotion (unpacking) from shorts to ints, and vect_int_mult (non-widening
1812 # multiplication of ints).
1813 #
1814 # This won't change for different subtargets so cache the result.
1815
1816
1817 proc check_effective_target_vect_widen_mult_hi_to_si { } {
1818     global et_vect_widen_mult_hi_to_si
1819
1820     if [info exists et_vect_widen_mult_hi_to_si_saved] {
1821         verbose "check_effective_target_vect_widen_mult_hi_to_si: using cached result" 2
1822     } else {
1823         if { [check_effective_target_vect_unpack]
1824              && [check_effective_target_vect_int_mult] } {
1825           set et_vect_widen_mult_hi_to_si_saved 1
1826         } else {
1827           set et_vect_widen_mult_hi_to_si_saved 0
1828         }
1829         if { [istarget powerpc*-*-*]
1830               || [istarget spu-*-*]
1831               || [istarget i?86-*-*]
1832               || [istarget x86_64-*-*] } {
1833             set et_vect_widen_mult_hi_to_si_saved 1
1834         }
1835     }
1836     verbose "check_effective_target_vect_widen_mult_hi_to_si: returning $et_vect_widen_mult_hi_to_si_saved" 2
1837     return $et_vect_widen_mult_hi_to_si_saved
1838 }
1839
1840 # Return 1 if the target plus current options supports a vector
1841 # dot-product of signed chars, 0 otherwise.
1842 #
1843 # This won't change for different subtargets so cache the result.
1844
1845 proc check_effective_target_vect_sdot_qi { } {
1846     global et_vect_sdot_qi
1847
1848     if [info exists et_vect_sdot_qi_saved] {
1849         verbose "check_effective_target_vect_sdot_qi: using cached result" 2
1850     } else {
1851         set et_vect_sdot_qi_saved 0
1852     }
1853     verbose "check_effective_target_vect_sdot_qi: returning $et_vect_sdot_qi_saved" 2
1854     return $et_vect_sdot_qi_saved
1855 }
1856
1857 # Return 1 if the target plus current options supports a vector
1858 # dot-product of unsigned chars, 0 otherwise.
1859 #
1860 # This won't change for different subtargets so cache the result.
1861
1862 proc check_effective_target_vect_udot_qi { } {
1863     global et_vect_udot_qi
1864
1865     if [info exists et_vect_udot_qi_saved] {
1866         verbose "check_effective_target_vect_udot_qi: using cached result" 2
1867     } else {
1868         set et_vect_udot_qi_saved 0
1869         if { [istarget powerpc*-*-*] } {
1870             set et_vect_udot_qi_saved 1
1871         }
1872     }
1873     verbose "check_effective_target_vect_udot_qi: returning $et_vect_udot_qi_saved" 2
1874     return $et_vect_udot_qi_saved
1875 }
1876
1877 # Return 1 if the target plus current options supports a vector
1878 # dot-product of signed shorts, 0 otherwise.
1879 #
1880 # This won't change for different subtargets so cache the result.
1881
1882 proc check_effective_target_vect_sdot_hi { } {
1883     global et_vect_sdot_hi
1884
1885     if [info exists et_vect_sdot_hi_saved] {
1886         verbose "check_effective_target_vect_sdot_hi: using cached result" 2
1887     } else {
1888         set et_vect_sdot_hi_saved 0
1889         if { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*])
1890              || [istarget i?86-*-*]
1891              || [istarget x86_64-*-*] } {
1892             set et_vect_sdot_hi_saved 1
1893         }
1894     }
1895     verbose "check_effective_target_vect_sdot_hi: returning $et_vect_sdot_hi_saved" 2
1896     return $et_vect_sdot_hi_saved
1897 }
1898
1899 # Return 1 if the target plus current options supports a vector
1900 # dot-product of unsigned shorts, 0 otherwise.
1901 #
1902 # This won't change for different subtargets so cache the result.
1903
1904 proc check_effective_target_vect_udot_hi { } {
1905     global et_vect_udot_hi
1906
1907     if [info exists et_vect_udot_hi_saved] {
1908         verbose "check_effective_target_vect_udot_hi: using cached result" 2
1909     } else {
1910         set et_vect_udot_hi_saved 0
1911         if { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*]) } {
1912             set et_vect_udot_hi_saved 1
1913         }
1914     }
1915     verbose "check_effective_target_vect_udot_hi: returning $et_vect_udot_hi_saved" 2
1916     return $et_vect_udot_hi_saved
1917 }
1918
1919
1920 # Return 1 if the target plus current options supports a vector
1921 # demotion (packing) of shorts (to chars) and ints (to shorts) 
1922 # using modulo arithmetic, 0 otherwise.
1923 #
1924 # This won't change for different subtargets so cache the result.
1925                                                                                 
1926 proc check_effective_target_vect_pack_trunc { } {
1927     global et_vect_pack_trunc
1928                                                                                 
1929     if [info exists et_vect_pack_trunc_saved] {
1930         verbose "check_effective_target_vect_pack_trunc: using cached result" 2
1931     } else {
1932         set et_vect_pack_trunc_saved 0
1933         if { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*])
1934              || [istarget i?86-*-*]
1935              || [istarget x86_64-*-*]
1936              || [istarget spu-*-*] } {
1937             set et_vect_pack_trunc_saved 1
1938         }
1939     }
1940     verbose "check_effective_target_vect_pack_trunc: returning $et_vect_pack_trunc_saved" 2
1941     return $et_vect_pack_trunc_saved
1942 }
1943
1944 # Return 1 if the target plus current options supports a vector
1945 # promotion (unpacking) of chars (to shorts) and shorts (to ints), 0 otherwise.
1946 #
1947 # This won't change for different subtargets so cache the result.
1948                                    
1949 proc check_effective_target_vect_unpack { } {
1950     global et_vect_unpack
1951                                         
1952     if [info exists et_vect_unpack_saved] {
1953         verbose "check_effective_target_vect_unpack: using cached result" 2
1954     } else {
1955         set et_vect_unpack_saved 0
1956         if { ([istarget powerpc*-*-*] && ![istarget powerpc-*paired*])
1957              || [istarget i?86-*-*]
1958              || [istarget x86_64-*-*] 
1959              || [istarget spu-*-*] } {
1960             set et_vect_unpack_saved 1
1961         }
1962     }
1963     verbose "check_effective_target_vect_unpack: returning $et_vect_unpack_saved" 2  
1964     return $et_vect_unpack_saved
1965 }
1966
1967 # Return 1 if the target plus current options does not guarantee
1968 # that its STACK_BOUNDARY is >= the reguired vector alignment.
1969 #
1970 # This won't change for different subtargets so cache the result.
1971
1972 proc check_effective_target_unaligned_stack { } {
1973     global et_unaligned_stack_saved
1974
1975     if [info exists et_unaligned_stack_saved] {
1976         verbose "check_effective_target_unaligned_stack: using cached result" 2
1977     } else {
1978         set et_unaligned_stack_saved 0
1979     }
1980     verbose "check_effective_target_unaligned_stack: returning $et_unaligned_stack_saved" 2
1981     return $et_unaligned_stack_saved
1982 }
1983
1984 # Return 1 if the target plus current options does not support a vector
1985 # alignment mechanism, 0 otherwise.
1986 #
1987 # This won't change for different subtargets so cache the result.
1988
1989 proc check_effective_target_vect_no_align { } {
1990     global et_vect_no_align_saved
1991
1992     if [info exists et_vect_no_align_saved] {
1993         verbose "check_effective_target_vect_no_align: using cached result" 2
1994     } else {
1995         set et_vect_no_align_saved 0
1996         if { [istarget mipsisa64*-*-*]
1997              || [istarget sparc*-*-*]
1998              || [istarget ia64-*-*]
1999              || [check_effective_target_arm32] } { 
2000             set et_vect_no_align_saved 1
2001         }
2002     }
2003     verbose "check_effective_target_vect_no_align: returning $et_vect_no_align_saved" 2
2004     return $et_vect_no_align_saved
2005 }
2006
2007 # Return 1 if arrays are aligned to the vector alignment
2008 # boundary, 0 otherwise.
2009 #
2010 # This won't change for different subtargets so cache the result.
2011
2012 proc check_effective_target_vect_aligned_arrays { } {
2013     global et_vect_aligned_arrays
2014
2015     if [info exists et_vect_aligned_arrays_saved] {
2016         verbose "check_effective_target_vect_aligned_arrays: using cached result" 2
2017     } else {
2018         set et_vect_aligned_arrays_saved 0
2019         if { (([istarget x86_64-*-*]
2020               || [istarget i?86-*-*]) && [is-effective-target lp64])
2021               || [istarget spu-*-*] } {
2022             set et_vect_aligned_arrays_saved 1
2023         }
2024     }
2025     verbose "check_effective_target_vect_aligned_arrays: returning $et_vect_aligned_arrays_saved" 2
2026     return $et_vect_aligned_arrays_saved
2027 }
2028
2029 # Return 1 if types of size 32 bit or less are naturally aligned
2030 # (aligned to their type-size), 0 otherwise.
2031 #
2032 # This won't change for different subtargets so cache the result.
2033
2034 proc check_effective_target_natural_alignment_32 { } {
2035     global et_natural_alignment_32
2036
2037     if [info exists et_natural_alignment_32_saved] {
2038         verbose "check_effective_target_natural_alignment_32: using cached result" 2
2039     } else {
2040         # FIXME: 32bit powerpc: guaranteed only if MASK_ALIGN_NATURAL/POWER.
2041         set et_natural_alignment_32_saved 1
2042         if { ([istarget *-*-darwin*] && [is-effective-target lp64]) } {
2043             set et_natural_alignment_32_saved 0
2044         }
2045     }
2046     verbose "check_effective_target_natural_alignment_32: returning $et_natural_alignment_32_saved" 2
2047     return $et_natural_alignment_32_saved
2048 }
2049
2050 # Return 1 if types of size 64 bit or less are naturally aligned (aligned to their
2051 # type-size), 0 otherwise.
2052 #
2053 # This won't change for different subtargets so cache the result.
2054
2055 proc check_effective_target_natural_alignment_64 { } {
2056     global et_natural_alignment_64
2057
2058     if [info exists et_natural_alignment_64_saved] {
2059         verbose "check_effective_target_natural_alignment_64: using cached result" 2
2060     } else {
2061         set et_natural_alignment_64_saved 0
2062         if { ([is-effective-target lp64] && ![istarget *-*-darwin*])
2063              || [istarget spu-*-*] } {
2064             set et_natural_alignment_64_saved 1
2065         }
2066     }
2067     verbose "check_effective_target_natural_alignment_64: returning $et_natural_alignment_64_saved" 2
2068     return $et_natural_alignment_64_saved
2069 }
2070
2071 # Return 1 if vector alignment (for types of size 32 bit or less) is reachable, 0 otherwise.
2072 #
2073 # This won't change for different subtargets so cache the result.
2074
2075 proc check_effective_target_vector_alignment_reachable { } {
2076     global et_vector_alignment_reachable
2077
2078     if [info exists et_vector_alignment_reachable_saved] {
2079         verbose "check_effective_target_vector_alignment_reachable: using cached result" 2
2080     } else {
2081         if { [check_effective_target_vect_aligned_arrays]
2082              || [check_effective_target_natural_alignment_32] } {
2083             set et_vector_alignment_reachable_saved 1
2084         } else {
2085             set et_vector_alignment_reachable_saved 0
2086         }
2087     }
2088     verbose "check_effective_target_vector_alignment_reachable: returning $et_vector_alignment_reachable_saved" 2
2089     return $et_vector_alignment_reachable_saved
2090 }
2091
2092 # Return 1 if vector alignment for 64 bit is reachable, 0 otherwise.
2093 #
2094 # This won't change for different subtargets so cache the result.
2095
2096 proc check_effective_target_vector_alignment_reachable_for_64bit { } {
2097     global et_vector_alignment_reachable_for_64bit
2098
2099     if [info exists et_vector_alignment_reachable_for_64bit_saved] {
2100         verbose "check_effective_target_vector_alignment_reachable_for_64bit: using cached result" 2
2101     } else {
2102         if { [check_effective_target_vect_aligned_arrays] 
2103              || [check_effective_target_natural_alignment_64] } {
2104             set et_vector_alignment_reachable_for_64bit_saved 1
2105         } else {
2106             set et_vector_alignment_reachable_for_64bit_saved 0
2107         }
2108     }
2109     verbose "check_effective_target_vector_alignment_reachable_for_64bit: returning $et_vector_alignment_reachable_for_64bit_saved" 2
2110     return $et_vector_alignment_reachable_for_64bit_saved
2111 }
2112
2113 # Return 1 if the target supports vector conditional operations, 0 otherwise.
2114
2115 proc check_effective_target_vect_condition { } {
2116     global et_vect_cond_saved
2117
2118     if [info exists et_vect_cond_saved] {
2119         verbose "check_effective_target_vect_cond: using cached result" 2
2120     } else {
2121         set et_vect_cond_saved 0
2122         if { [istarget powerpc*-*-*]
2123              || [istarget ia64-*-*]
2124              || [istarget i?86-*-*]
2125              || [istarget spu-*-*]
2126              || [istarget x86_64-*-*] } {
2127            set et_vect_cond_saved 1
2128         }
2129     }
2130
2131     verbose "check_effective_target_vect_cond: returning $et_vect_cond_saved" 2
2132     return $et_vect_cond_saved
2133 }
2134
2135 # Return 1 if the target supports vector char multiplication, 0 otherwise.
2136
2137 proc check_effective_target_vect_char_mult { } {
2138     global et_vect_char_mult_saved
2139
2140     if [info exists et_vect_char_mult_saved] {
2141         verbose "check_effective_target_vect_char_mult: using cached result" 2
2142     } else {
2143         set et_vect_char_mult_saved 0
2144         if { [istarget ia64-*-*]
2145              || [istarget i?86-*-*]
2146              || [istarget x86_64-*-*] } {
2147            set et_vect_char_mult_saved 1
2148         }
2149     }
2150
2151     verbose "check_effective_target_vect_char_mult: returning $et_vect_char_mult_saved" 2
2152     return $et_vect_char_mult_saved
2153 }
2154
2155 # Return 1 if the target supports vector short multiplication, 0 otherwise.
2156
2157 proc check_effective_target_vect_short_mult { } {
2158     global et_vect_short_mult_saved
2159
2160     if [info exists et_vect_short_mult_saved] {
2161         verbose "check_effective_target_vect_short_mult: using cached result" 2
2162     } else {
2163         set et_vect_short_mult_saved 0
2164         if { [istarget ia64-*-*]
2165              || [istarget spu-*-*]
2166              || [istarget i?86-*-*]
2167              || [istarget x86_64-*-*] 
2168              || [istarget powerpc*-*-*] } {
2169            set et_vect_short_mult_saved 1
2170         }
2171     }
2172
2173     verbose "check_effective_target_vect_short_mult: returning $et_vect_short_mult_saved" 2
2174     return $et_vect_short_mult_saved
2175 }
2176
2177 # Return 1 if the target supports vector int multiplication, 0 otherwise.
2178
2179 proc check_effective_target_vect_int_mult { } {
2180     global et_vect_int_mult_saved
2181
2182     if [info exists et_vect_int_mult_saved] {
2183         verbose "check_effective_target_vect_int_mult: using cached result" 2
2184     } else {
2185         set et_vect_int_mult_saved 0
2186         if { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*])
2187              || [istarget spu-*-*]
2188              || [istarget i?86-*-*]
2189              || [istarget x86_64-*-*]
2190              || [check_effective_target_arm32] } {
2191            set et_vect_int_mult_saved 1
2192         }
2193     }
2194
2195     verbose "check_effective_target_vect_int_mult: returning $et_vect_int_mult_saved" 2
2196     return $et_vect_int_mult_saved
2197 }
2198
2199 # Return 1 if the target supports vector even/odd elements extraction, 0 otherwise.
2200
2201 proc check_effective_target_vect_extract_even_odd { } {
2202     global et_vect_extract_even_odd_saved
2203     
2204     if [info exists et_vect_extract_even_odd_saved] {
2205         verbose "check_effective_target_vect_extract_even_odd: using cached result" 2
2206     } else {
2207         set et_vect_extract_even_odd_saved 0 
2208         if { [istarget powerpc*-*-*]
2209              || [istarget spu-*-*] } {
2210            set et_vect_extract_even_odd_saved 1
2211         }
2212     }
2213
2214     verbose "check_effective_target_vect_extract_even_odd: returning $et_vect_extract_even_odd_saved" 2
2215     return $et_vect_extract_even_odd_saved
2216 }
2217
2218 # Return 1 if the target supports vector even/odd elements extraction of
2219 # vectors with SImode elements or larger, 0 otherwise.
2220
2221 proc check_effective_target_vect_extract_even_odd_wide { } {
2222     global et_vect_extract_even_odd_wide_saved
2223     
2224     if [info exists et_vect_extract_even_odd_wide_saved] {
2225         verbose "check_effective_target_vect_extract_even_odd_wide: using cached result" 2
2226     } else {
2227         set et_vect_extract_even_odd_wide_saved 0 
2228         if { [istarget powerpc*-*-*] 
2229              || [istarget i?86-*-*]
2230              || [istarget x86_64-*-*]
2231              || [istarget spu-*-*] } {
2232            set et_vect_extract_even_odd_wide_saved 1
2233         }
2234     }
2235
2236     verbose "check_effective_target_vect_extract_even_wide_odd: returning $et_vect_extract_even_odd_wide_saved" 2
2237     return $et_vect_extract_even_odd_wide_saved
2238 }
2239
2240 # Return 1 if the target supports vector interleaving, 0 otherwise.
2241
2242 proc check_effective_target_vect_interleave { } {
2243     global et_vect_interleave_saved
2244     
2245     if [info exists et_vect_interleave_saved] {
2246         verbose "check_effective_target_vect_interleave: using cached result" 2
2247     } else {
2248         set et_vect_interleave_saved 0
2249         if { [istarget powerpc*-*-*]
2250              || [istarget i?86-*-*]
2251              || [istarget x86_64-*-*]
2252              || [istarget spu-*-*] } {
2253            set et_vect_interleave_saved 1
2254         }
2255     }
2256
2257     verbose "check_effective_target_vect_interleave: returning $et_vect_interleave_saved" 2
2258     return $et_vect_interleave_saved
2259 }
2260
2261 # Return 1 if the target supports vector interleaving and extract even/odd, 0 otherwise.
2262 proc check_effective_target_vect_strided { } {
2263     global et_vect_strided_saved
2264
2265     if [info exists et_vect_strided_saved] {
2266         verbose "check_effective_target_vect_strided: using cached result" 2
2267     } else {
2268         set et_vect_strided_saved 0
2269         if { [check_effective_target_vect_interleave]
2270              && [check_effective_target_vect_extract_even_odd] } {
2271            set et_vect_strided_saved 1
2272         }
2273     }
2274
2275     verbose "check_effective_target_vect_strided: returning $et_vect_strided_saved" 2
2276     return $et_vect_strided_saved
2277 }
2278
2279 # Return 1 if the target supports vector interleaving and extract even/odd
2280 # for wide element types, 0 otherwise.
2281 proc check_effective_target_vect_strided_wide { } {
2282     global et_vect_strided_wide_saved
2283
2284     if [info exists et_vect_strided_wide_saved] {
2285         verbose "check_effective_target_vect_strided_wide: using cached result" 2
2286     } else {
2287         set et_vect_strided_wide_saved 0
2288         if { [check_effective_target_vect_interleave]
2289              && [check_effective_target_vect_extract_even_odd_wide] } {
2290            set et_vect_strided_wide_saved 1
2291         }
2292     }
2293
2294     verbose "check_effective_target_vect_strided_wide: returning $et_vect_strided_wide_saved" 2
2295     return $et_vect_strided_wide_saved
2296 }
2297
2298 # Return 1 if the target supports section-anchors
2299
2300 proc check_effective_target_section_anchors { } {
2301     global et_section_anchors_saved
2302
2303     if [info exists et_section_anchors_saved] {
2304         verbose "check_effective_target_section_anchors: using cached result" 2
2305     } else {
2306         set et_section_anchors_saved 0
2307         if { [istarget powerpc*-*-*] } {
2308            set et_section_anchors_saved 1
2309         }
2310     }
2311
2312     verbose "check_effective_target_section_anchors: returning $et_section_anchors_saved" 2
2313     return $et_section_anchors_saved
2314 }
2315
2316 # Return 1 if the target supports atomic operations on "int" and "long".
2317
2318 proc check_effective_target_sync_int_long { } {
2319     global et_sync_int_long_saved
2320
2321     if [info exists et_sync_int_long_saved] {
2322         verbose "check_effective_target_sync_int_long: using cached result" 2
2323     } else {
2324         set et_sync_int_long_saved 0
2325 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
2326 # load-reserved/store-conditional instructions.
2327         if { [istarget ia64-*-*]
2328              || [istarget i?86-*-*]
2329              || [istarget x86_64-*-*]
2330              || [istarget alpha*-*-*] 
2331              || [istarget s390*-*-*] 
2332              || [istarget powerpc*-*-*]
2333              || [istarget sparc64-*-*]
2334              || [istarget sparcv9-*-*]
2335              || [istarget mips*-*-*] } {
2336            set et_sync_int_long_saved 1
2337         }
2338     }
2339
2340     verbose "check_effective_target_sync_int_long: returning $et_sync_int_long_saved" 2
2341     return $et_sync_int_long_saved
2342 }
2343
2344 # Return 1 if the target supports atomic operations on "char" and "short".
2345
2346 proc check_effective_target_sync_char_short { } {
2347     global et_sync_char_short_saved
2348
2349     if [info exists et_sync_char_short_saved] {
2350         verbose "check_effective_target_sync_char_short: using cached result" 2
2351     } else {
2352         set et_sync_char_short_saved 0
2353 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
2354 # load-reserved/store-conditional instructions.
2355         if { [istarget ia64-*-*]
2356              || [istarget i?86-*-*]
2357              || [istarget x86_64-*-*]
2358              || [istarget alpha*-*-*] 
2359              || [istarget s390*-*-*] 
2360              || [istarget powerpc*-*-*]
2361              || [istarget sparc64-*-*]
2362              || [istarget sparcv9-*-*]
2363              || [istarget mips*-*-*] } {
2364            set et_sync_char_short_saved 1
2365         }
2366     }
2367
2368     verbose "check_effective_target_sync_char_short: returning $et_sync_char_short_saved" 2
2369     return $et_sync_char_short_saved
2370 }
2371
2372 # Return 1 if the target uses a ColdFire FPU.
2373
2374 proc check_effective_target_coldfire_fpu { } {
2375     return [check_no_compiler_messages coldfire_fpu assembly {
2376         #ifndef __mcffpu__
2377         #error FOO
2378         #endif
2379     }]
2380 }
2381
2382 # Return true if this is a uClibc target.
2383
2384 proc check_effective_target_uclibc {} {
2385     return [check_no_compiler_messages uclibc object {
2386         #include <features.h>
2387         #if !defined (__UCLIBC__)
2388         #error FOO
2389         #endif
2390     }]
2391 }
2392
2393 # Return true if this is a uclibc target and if the uclibc feature
2394 # described by __$feature__ is not present.
2395
2396 proc check_missing_uclibc_feature {feature} {
2397     return [check_no_compiler_messages $feature object "
2398         #include <features.h>
2399         #if !defined (__UCLIBC) || defined (__${feature}__)
2400         #error FOO
2401         #endif
2402     "]
2403 }
2404
2405 # Return true if this is a Newlib target.
2406
2407 proc check_effective_target_newlib {} {
2408     return [check_no_compiler_messages newlib object {
2409         #include <newlib.h>
2410     }]
2411 }
2412
2413 # Return 1 if
2414 #   (a) an error of a few ULP is expected in string to floating-point
2415 #       conversion functions; and
2416 #   (b) overflow is not always detected correctly by those functions.
2417
2418 proc check_effective_target_lax_strtofp {} {
2419     # By default, assume that all uClibc targets suffer from this.
2420     return [check_effective_target_uclibc]
2421 }
2422
2423 # Return 1 if this is a target for which wcsftime is a dummy
2424 # function that always returns 0.
2425
2426 proc check_effective_target_dummy_wcsftime {} {
2427     # By default, assume that all uClibc targets suffer from this.
2428     return [check_effective_target_uclibc]
2429 }
2430
2431 # Return 1 if constructors with initialization priority arguments are
2432 # supposed on this target.
2433
2434 proc check_effective_target_init_priority {} {
2435     return [check_no_compiler_messages init_priority assembly "
2436         void f() __attribute__((constructor (1000)));
2437         void f() \{\}
2438     "]
2439 }
2440
2441 # Return 1 if the target matches the effective target 'arg', 0 otherwise.
2442 # This can be used with any check_* proc that takes no argument and
2443 # returns only 1 or 0.  It could be used with check_* procs that take
2444 # arguments with keywords that pass particular arguments.
2445
2446 proc is-effective-target { arg } {
2447     set selected 0
2448     if { [info procs check_effective_target_${arg}] != [list] } {
2449         set selected [check_effective_target_${arg}]
2450     } else {
2451         switch $arg {
2452           "vmx_hw"         { set selected [check_vmx_hw_available] }
2453           "named_sections" { set selected [check_named_sections_available] }
2454           "gc_sections"    { set selected [check_gc_sections_available] }
2455           "cxa_atexit"     { set selected [check_cxa_atexit_available] }
2456           default          { error "unknown effective target keyword `$arg'" }
2457         }
2458     }
2459     verbose "is-effective-target: $arg $selected" 2
2460     return $selected
2461 }
2462
2463 # Return 1 if the argument is an effective-target keyword, 0 otherwise.
2464
2465 proc is-effective-target-keyword { arg } {
2466     if { [info procs check_effective_target_${arg}] != [list] } {
2467         return 1
2468     } else {
2469         # These have different names for their check_* procs.
2470         switch $arg {
2471           "vmx_hw"         { return 1 }
2472           "named_sections" { return 1 }
2473           "gc_sections"    { return 1 }
2474           "cxa_atexit"     { return 1 }
2475           default          { return 0 }
2476         }
2477     }
2478 }
2479
2480 # Return 1 if target default to short enums
2481
2482 proc check_effective_target_short_enums { } {
2483     return [check_no_compiler_messages short_enums assembly {
2484         enum foo { bar };
2485         int s[sizeof (enum foo) == 1 ? 1 : -1];
2486     }]
2487 }
2488
2489 # Return 1 if target supports merging string constants at link time.
2490
2491 proc check_effective_target_string_merging { } {
2492     return [check_no_messages_and_pattern string_merging \
2493                 "rodata\\.str" assembly {
2494                     const char *var = "String";
2495                 } {-O2}]
2496 }
2497
2498 # Return 1 if target has the basic signed and unsigned types in
2499 # <stdint.h>, 0 otherwise.
2500
2501 proc check_effective_target_stdint_types { } {
2502     return [check_no_compiler_messages stdint_types assembly {
2503         #include <stdint.h>
2504         int8_t a; int16_t b; int32_t c; int64_t d;
2505         uint8_t e; uint16_t f; uint32_t g; uint64_t h;
2506     }]
2507 }
2508
2509 # Return 1 if programs are intended to be run on a simulator
2510 # (i.e. slowly) rather than hardware (i.e. fast).
2511
2512 proc check_effective_target_simulator { } {
2513
2514     # All "src/sim" simulators set this one.
2515     if [board_info target exists is_simulator] {
2516         return [board_info target is_simulator]
2517     }
2518
2519     # The "sid" simulators don't set that one, but at least they set
2520     # this one.
2521     if [board_info target exists slow_simulator] {
2522         return [board_info target slow_simulator]
2523     }
2524
2525     return 0
2526 }
2527
2528 # Return 1 if the target is a VxWorks kernel.
2529
2530 proc check_effective_target_vxworks_kernel { } {
2531     return [check_no_compiler_messages vxworks_kernel assembly {
2532         #if !defined __vxworks || defined __RTP__
2533         #error NO
2534         #endif
2535     }]
2536 }
2537
2538 # Return 1 if the target is a VxWorks RTP.
2539
2540 proc check_effective_target_vxworks_rtp { } {
2541     return [check_no_compiler_messages vxworks_rtp assembly {
2542         #if !defined __vxworks || !defined __RTP__
2543         #error NO
2544         #endif
2545     }]
2546 }
2547
2548 # Return 1 if the target is expected to provide wide character support.
2549
2550 proc check_effective_target_wchar { } {
2551     if {[check_missing_uclibc_feature UCLIBC_HAS_WCHAR]} {
2552         return 0
2553     }
2554     return [check_no_compiler_messages wchar assembly {
2555         #include <wchar.h>
2556     }]
2557 }
2558
2559 # Return 1 if the target has <pthread.h>.
2560
2561 proc check_effective_target_pthread_h { } {
2562     return [check_no_compiler_messages pthread_h assembly {
2563         #include <pthread.h>
2564     }]
2565 }
2566
2567 # Return 1 if the target can truncate a file from a file-descriptor,
2568 # as used by libgfortran/io/unix.c:fd_truncate; i.e. ftruncate or
2569 # chsize.  We test for a trivially functional truncation; no stubs.
2570 # As libgfortran uses _FILE_OFFSET_BITS 64, we do too; it'll cause a
2571 # different function to be used.
2572
2573 proc check_effective_target_fd_truncate { } {
2574     set prog {
2575         #define _FILE_OFFSET_BITS 64
2576         #include <unistd.h>
2577         #include <stdio.h>
2578         #include <stdlib.h>
2579         int main ()
2580         {
2581           FILE *f = fopen ("tst.tmp", "wb");
2582           int fd;
2583           const char t[] = "test writing more than ten characters";
2584           char s[11];
2585           fd =  fileno (f);
2586           write (fd, t, sizeof (t) - 1);
2587           lseek (fd, 0, 0);
2588           if (ftruncate (fd, 10) != 0)
2589             exit (1);
2590           close (fd);
2591           f = fopen ("tst.tmp", "rb");
2592           if (fread (s, 1, sizeof (s), f) != 10 || strncmp (s, t, 10) != 0)
2593             exit (1);
2594           exit (0);
2595         }
2596     }
2597
2598     if { [check_runtime ftruncate $prog] } {
2599       return 1;
2600     }
2601
2602     regsub "ftruncate" $prog "chsize" prog
2603     return [check_runtime chsize $prog]
2604 }
2605
2606 # Add to FLAGS all the target-specific flags needed to access the c99 runtime.
2607
2608 proc add_options_for_c99_runtime { flags } {
2609     if { [istarget *-*-solaris2*] } {
2610         return "$flags -std=c99"
2611     }
2612     if { [istarget powerpc-*-darwin*] } {
2613         return "$flags -mmacosx-version-min=10.3"
2614     }
2615     return $flags
2616 }
2617
2618 # Return 1 if the target provides a full C99 runtime.
2619
2620 proc check_effective_target_c99_runtime { } {
2621     return [check_cached_effective_target c99_runtime {
2622         global srcdir
2623
2624         set file [open "$srcdir/gcc.dg/builtins-config.h"]
2625         set contents [read $file]
2626         close $file
2627         append contents {
2628             #ifndef HAVE_C99_RUNTIME
2629             #error FOO
2630             #endif
2631         }
2632         check_no_compiler_messages_nocache c99_runtime assembly \
2633             $contents [add_options_for_c99_runtime ""]
2634     }]
2635 }
2636
2637 # Return 1 if  target wchar_t is at least 4 bytes.
2638
2639 proc check_effective_target_4byte_wchar_t { } {
2640     return [check_no_compiler_messages 4byte_wchar_t object {
2641         int dummy[sizeof (__WCHAR_TYPE__) >= 4 ? 1 : -1];
2642     }]
2643 }
2644
2645 # Return 1 if the target supports automatic stack alignment.
2646
2647 proc check_effective_target_automatic_stack_alignment  { } {
2648     if { [istarget i?86*-*-*]
2649          || [istarget x86_64-*-*] } then {
2650         return 1
2651     } else {
2652         return 0
2653     }
2654 }
2655
2656 # Return 1 if avx instructions can be compiled.
2657
2658 proc check_effective_target_avx { } {
2659     return [check_no_compiler_messages avx object {
2660         void _mm256_zeroall (void)
2661         {
2662            __builtin_ia32_vzeroall ();
2663         }
2664     } "-O2 -mavx" ]
2665 }
2666
2667 # Return 1 if C wchar_t type is compatible with char16_t.
2668
2669 proc check_effective_target_wchar_t_char16_t_compatible { } {
2670     return [check_no_compiler_messages wchar_t_char16_t object {
2671         __WCHAR_TYPE__ wc;
2672         __CHAR16_TYPE__ *p16 = &wc;
2673         char t[(((__CHAR16_TYPE__) -1) < 0 == ((__WCHAR_TYPE__) -1) < 0) ? 1 : -1];
2674     }]
2675 }
2676
2677 # Return 1 if C wchar_t type is compatible with char32_t.
2678
2679 proc check_effective_target_wchar_t_char32_t_compatible { } {
2680     return [check_no_compiler_messages wchar_t_char32_t object {
2681         __WCHAR_TYPE__ wc;
2682         __CHAR32_TYPE__ *p32 = &wc;
2683         char t[(((__CHAR32_TYPE__) -1) < 0 == ((__WCHAR_TYPE__) -1) < 0) ? 1 : -1];
2684     }]
2685 }
2686
2687 # Return 1 if pow10 function exists.
2688
2689 proc check_effective_target_pow10 { } {
2690     return [check_runtime pow10 {
2691         #include <math.h>
2692         int main () {
2693         double x;
2694         x = pow10 (1);
2695         return 0;
2696         }
2697     } "-lm" ]
2698 }
2699
2700 # Return 1 if current options generate DFP instructions, 0 otherwise.
2701
2702 proc check_effective_target_hard_dfp {} {
2703     return [check_no_messages_and_pattern hard_dfp "!adddd3" assembly {
2704         _Decimal64 x, y, z;
2705         void foo (void) { z = x + y; }
2706     }]
2707 }