OSDN Git Service

* configure.ac (gnu_indirect_function): New test.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / target-supports.exp
1 #   Copyright (C) 1999, 2001, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
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.  
33 # Otherwise, code should contain:
34 # "// C++" for c++,
35 # "! Fortran" for Fortran code,
36 # "/* ObjC", for ObjC
37 # and "// ObjC++" for ObjC++
38 # If the tool is ObjC/ObjC++ then we overide the extension to .m/.mm to 
39 # allow for ObjC/ObjC++ specific flags.
40 proc check_compile {basename type contents args} {
41     global tool
42     verbose "check_compile tool: $tool for $basename" 
43
44     if { [llength $args] > 0 } {
45         set options [list "additional_flags=[lindex $args 0]"]
46     } else {
47         set options ""
48     }
49     switch -glob -- $contents {
50         "*! Fortran*" { set src ${basename}[pid].f90 }
51         "*// C++*" { set src ${basename}[pid].cc }
52         "*// ObjC++*" { set src ${basename}[pid].mm }
53         "*/* ObjC*" { set src ${basename}[pid].m }
54         default {
55             switch -- $tool {
56                 "objc" { set src ${basename}[pid].m }
57                 "obj-c++" { set src ${basename}[pid].mm }
58                 default { set src ${basename}[pid].c }
59             }
60         }
61     }
62
63     set compile_type $type
64     switch -glob $type {
65         assembly { set output ${basename}[pid].s }
66         object { set output ${basename}[pid].o }
67         executable { set output ${basename}[pid].exe }
68         "rtl-*" {
69             set output ${basename}[pid].s
70             lappend options "additional_flags=-fdump-$type"
71             set compile_type assembly
72         }
73     }
74     set f [open $src "w"]
75     puts $f $contents
76     close $f
77     set lines [${tool}_target_compile $src $output $compile_type "$options"]
78     file delete $src
79
80     set scan_output $output
81     # Don't try folding this into the switch above; calling "glob" before the
82     # file is created won't work.
83     if [regexp "rtl-(.*)" $type dummy rtl_type] {
84         set scan_output "[glob $src.\[0-9\]\[0-9\]\[0-9\]r.$rtl_type]"
85         file delete $output
86     }
87
88     return [list $lines $scan_output]
89 }
90
91 proc current_target_name { } {
92     global target_info
93     if [info exists target_info(target,name)] {
94         set answer $target_info(target,name)
95     } else {
96         set answer ""
97     }
98     return $answer
99 }
100
101 # Implement an effective-target check for property PROP by invoking
102 # the Tcl command ARGS and seeing if it returns true.
103
104 proc check_cached_effective_target { prop args } {
105     global et_cache
106
107     set target [current_target_name]
108     if {![info exists et_cache($prop,target)]
109         || $et_cache($prop,target) != $target} {
110         verbose "check_cached_effective_target $prop: checking $target" 2
111         set et_cache($prop,target) $target
112         set et_cache($prop,value) [uplevel eval $args]
113     }
114     set value $et_cache($prop,value)
115     verbose "check_cached_effective_target $prop: returning $value for $target" 2
116     return $value
117 }
118
119 # Like check_compile, but delete the output file and return true if the
120 # compiler printed no messages.
121 proc check_no_compiler_messages_nocache {args} {
122     set result [eval check_compile $args]
123     set lines [lindex $result 0]
124     set output [lindex $result 1]
125     remote_file build delete $output
126     return [string match "" $lines]
127 }
128
129 # Like check_no_compiler_messages_nocache, but cache the result.
130 # PROP is the property we're checking, and doubles as a prefix for
131 # temporary filenames.
132 proc check_no_compiler_messages {prop args} {
133     return [check_cached_effective_target $prop {
134         eval [list check_no_compiler_messages_nocache $prop] $args
135     }]
136 }
137
138 # Like check_compile, but return true if the compiler printed no
139 # messages and if the contents of the output file satisfy PATTERN.
140 # If PATTERN has the form "!REGEXP", the contents satisfy it if they
141 # don't match regular expression REGEXP, otherwise they satisfy it
142 # if they do match regular expression PATTERN.  (PATTERN can start
143 # with something like "[!]" if the regular expression needs to match
144 # "!" as the first character.)
145 #
146 # Delete the output file before returning.  The other arguments are
147 # as for check_compile.
148 proc check_no_messages_and_pattern_nocache {basename pattern args} {
149     global tool
150
151     set result [eval [list check_compile $basename] $args]
152     set lines [lindex $result 0]
153     set output [lindex $result 1]
154
155     set ok 0
156     if { [string match "" $lines] } {
157         set chan [open "$output"]
158         set invert [regexp {^!(.*)} $pattern dummy pattern]
159         set ok [expr { [regexp $pattern [read $chan]] != $invert }]
160         close $chan
161     }
162
163     remote_file build delete $output
164     return $ok
165 }
166
167 # Like check_no_messages_and_pattern_nocache, but cache the result.
168 # PROP is the property we're checking, and doubles as a prefix for
169 # temporary filenames.
170 proc check_no_messages_and_pattern {prop pattern args} {
171     return [check_cached_effective_target $prop {
172         eval [list check_no_messages_and_pattern_nocache $prop $pattern] $args
173     }]
174 }
175
176 # Try to compile and run an executable from code CONTENTS.  Return true
177 # if the compiler reports no messages and if execution "passes" in the
178 # usual DejaGNU sense.  The arguments are as for check_compile, with
179 # TYPE implicitly being "executable".
180 proc check_runtime_nocache {basename contents args} {
181     global tool
182
183     set result [eval [list check_compile $basename executable $contents] $args]
184     set lines [lindex $result 0]
185     set output [lindex $result 1]
186
187     set ok 0
188     if { [string match "" $lines] } {
189         # No error messages, everything is OK.
190         set result [remote_load target "./$output" "" ""]
191         set status [lindex $result 0]
192         verbose "check_runtime_nocache $basename: status is <$status>" 2
193         if { $status == "pass" } {
194             set ok 1
195         }
196     }
197     remote_file build delete $output
198     return $ok
199 }
200
201 # Like check_runtime_nocache, but cache the result.  PROP is the
202 # property we're checking, and doubles as a prefix for temporary
203 # filenames.
204 proc check_runtime {prop args} {
205     global tool
206
207     return [check_cached_effective_target $prop {
208         eval [list check_runtime_nocache $prop] $args
209     }]
210 }
211
212 ###############################
213 # proc check_weak_available { }
214 ###############################
215
216 # weak symbols are only supported in some configs/object formats
217 # this proc returns 1 if they're supported, 0 if they're not, or -1 if unsure
218
219 proc check_weak_available { } {
220     global target_triplet
221     global target_cpu
222
223     # All mips targets should support it
224
225     if { [ string first "mips" $target_cpu ] >= 0 } {
226         return 1
227     }
228
229     # All solaris2 targets should support it
230
231     if { [regexp ".*-solaris2.*" $target_triplet] } {
232         return 1
233     }
234
235     # DEC OSF/1/Digital UNIX/Tru64 UNIX supports it
236
237     if { [regexp "alpha.*osf.*" $target_triplet] } {
238         return 1
239     }
240
241     # Windows targets Cygwin and MingW32 support it
242
243     if { [regexp ".*mingw32|.*cygwin" $target_triplet] } {
244         return 1
245     }
246
247     # HP-UX 10.X doesn't support it
248
249     if { [istarget "hppa*-*-hpux10*"] } {
250         return 0
251     }
252
253     # ELF and ECOFF support it. a.out does with gas/gld but may also with
254     # other linkers, so we should try it
255
256     set objformat [gcc_target_object_format]
257
258     switch $objformat {
259         elf      { return 1 }
260         ecoff    { return 1 }
261         a.out    { return 1 }
262         mach-o   { return 1 }
263         som      { return 1 }
264         unknown  { return -1 }
265         default  { return 0 }
266     }
267 }
268
269 ###############################
270 # proc check_weak_override_available { }
271 ###############################
272
273 # Like check_weak_available, but return 0 if weak symbol definitions
274 # cannot be overridden.
275
276 proc check_weak_override_available { } {
277     if { [istarget "*-*-mingw*"] } {
278         return 0
279     }
280     return [check_weak_available]
281 }
282
283 ###############################
284 # proc check_visibility_available { what_kind }
285 ###############################
286
287 # The visibility attribute is only support in some object formats
288 # This proc returns 1 if it is supported, 0 if not.
289 # The argument is the kind of visibility, default/protected/hidden/internal.
290
291 proc check_visibility_available { what_kind } {
292     global tool
293     global target_triplet
294
295     # On NetWare, support makes no sense.
296     if { [istarget *-*-netware*] } {
297         return 0
298     }
299
300     if [string match "" $what_kind] { set what_kind "hidden" }
301
302     return [check_no_compiler_messages visibility_available_$what_kind object "
303         void f() __attribute__((visibility(\"$what_kind\")));
304         void f() {}
305     "]
306 }
307
308 ###############################
309 # proc check_alias_available { }
310 ###############################
311
312 # Determine if the target toolchain supports the alias attribute.
313
314 # Returns 2 if the target supports aliases.  Returns 1 if the target
315 # only supports weak aliased.  Returns 0 if the target does not
316 # support aliases at all.  Returns -1 if support for aliases could not
317 # be determined.
318
319 proc check_alias_available { } {
320     global alias_available_saved
321     global tool
322
323     if [info exists alias_available_saved] {
324         verbose "check_alias_available  returning saved $alias_available_saved" 2
325     } else {
326         set src alias[pid].c
327         set obj alias[pid].o
328         verbose "check_alias_available  compiling testfile $src" 2
329         set f [open $src "w"]
330         # Compile a small test program.  The definition of "g" is
331         # necessary to keep the Solaris assembler from complaining
332         # about the program.
333         puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
334         puts $f "void g() {} void f() __attribute__((alias(\"g\")));"
335         close $f
336         set lines [${tool}_target_compile $src $obj object ""]
337         file delete $src
338         remote_file build delete $obj
339
340         if [string match "" $lines] then {
341             # No error messages, everything is OK.
342             set alias_available_saved 2
343         } else {
344             if [regexp "alias definitions not supported" $lines] {
345                 verbose "check_alias_available  target does not support aliases" 2
346
347                 set objformat [gcc_target_object_format]
348
349                 if { $objformat == "elf" } {
350                     verbose "check_alias_available  but target uses ELF format, so it ought to" 2
351                     set alias_available_saved -1
352                 } else {
353                     set alias_available_saved 0
354                 }
355             } else {
356                 if [regexp "only weak aliases are supported" $lines] {
357                 verbose "check_alias_available  target supports only weak aliases" 2
358                 set alias_available_saved 1
359                 } else {
360                     set alias_available_saved -1
361                 }
362             }
363         }
364
365         verbose "check_alias_available  returning $alias_available_saved" 2
366     }
367
368     return $alias_available_saved
369 }
370
371 ###############################
372 # proc check_ifunc_available { }
373 ###############################
374
375 # Determine if the target toolchain supports the alias attribute.
376
377 # Returns 2 if the target supports aliases.  Returns 1 if the target
378 # only supports weak aliased.  Returns 0 if the target does not
379 # support aliases at all.  Returns -1 if support for aliases could not
380 # be determined.
381
382 proc check_ifunc_available { } {
383     global ifunc_available_saved
384     global tool
385
386     if [info exists ifunc_available_saved] {
387         verbose "check_ifunc_available  returning saved $ifunc_available_saved" 2
388     } else {
389         set src ifunc[pid].c
390         set obj ifunc[pid].o
391         verbose "check_ifunc_available  compiling testfile $src" 2
392         set f [open $src "w"]
393         # Compile a small test program.  The definition of "g" is
394         # necessary to keep the Solaris assembler from complaining
395         # about the program.
396         puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
397         puts $f "void g() {} void f() __attribute__((ifunc(\"g\")));"
398         close $f
399         set lines [${tool}_target_compile $src $obj object ""]
400         file delete $src
401         remote_file build delete $obj
402
403         if [string match "" $lines] then {
404             # No error messages, everything is OK.
405             set ifunc_available_saved 2
406         } else {
407             if [regexp "ifunc is not supported" $lines] {
408                 verbose "check_ifunc_available  target does not support ifunc" 2
409                 set ifunc_available_saved 0
410             } else {
411                 set ifunc_available_saved -1
412             }
413         }
414
415         verbose "check_ifunc_available  returning $ifunc_available_saved" 2
416     }
417
418     return $ifunc_available_saved
419 }
420
421 # Returns true if --gc-sections is supported on the target.
422
423 proc check_gc_sections_available { } {
424     global gc_sections_available_saved
425     global tool
426
427     if {![info exists gc_sections_available_saved]} {
428         # Some targets don't support gc-sections despite whatever's
429         # advertised by ld's options.
430         if { [istarget alpha*-*-*]
431              || [istarget ia64-*-*] } {
432             set gc_sections_available_saved 0
433             return 0
434         }
435
436         # elf2flt uses -q (--emit-relocs), which is incompatible with
437         # --gc-sections.
438         if { [board_info target exists ldflags]
439              && [regexp " -elf2flt\[ =\]" " [board_info target ldflags] "] } {
440             set gc_sections_available_saved 0
441             return 0
442         }
443
444         # VxWorks kernel modules are relocatable objects linked with -r,
445         # while RTP executables are linked with -q (--emit-relocs).
446         # Both of these options are incompatible with --gc-sections.
447         if { [istarget *-*-vxworks*] } {
448             set gc_sections_available_saved 0
449             return 0
450         }
451
452         # Check if the ld used by gcc supports --gc-sections.
453         set gcc_spec [${tool}_target_compile "-dumpspecs" "" "none" ""]
454         regsub ".*\n\\*linker:\[ \t\]*\n(\[^ \t\n\]*).*" "$gcc_spec" {\1} linker
455         set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=$linker" "" "none" ""] 0]
456         set ld_output [remote_exec host "$gcc_ld" "--help"]
457         if { [ string first "--gc-sections" $ld_output ] >= 0 } {
458             set gc_sections_available_saved 1
459         } else {
460             set gc_sections_available_saved 0
461         }
462     }
463     return $gc_sections_available_saved
464 }
465
466 # Return 1 if according to target_info struct and explicit target list
467 # target is supposed to support trampolines.
468  
469 proc check_effective_target_trampolines { } {
470     if [target_info exists no_trampolines] {
471       return 0
472     }
473     if { [istarget avr-*-*]
474          || [istarget hppa2.0w-hp-hpux11.23]
475         || [istarget hppa64-hp-hpux11.23] } {
476         return 0;   
477     }
478     return 1
479 }
480
481 # Return 1 if according to target_info struct and explicit target list
482 # target is supposed to keep null pointer checks. This could be due to 
483 # use of option fno-delete-null-pointer-checks or hardwired in target.
484  
485 proc check_effective_target_keeps_null_pointer_checks { } {
486     if [target_info exists keeps_null_pointer_checks] {
487       return 1
488     }
489     if { [istarget avr-*-*] } {
490         return 1;   
491     }
492     return 0
493 }
494
495 # Return true if profiling is supported on the target.
496
497 proc check_profiling_available { test_what } {
498     global profiling_available_saved
499
500     verbose "Profiling argument is <$test_what>" 1
501
502     # These conditions depend on the argument so examine them before
503     # looking at the cache variable.
504
505     # Support for -p on solaris2 relies on mcrt1.o which comes with the
506     # vendor compiler.  We cannot reliably predict the directory where the
507     # vendor compiler (and thus mcrt1.o) is installed so we can't
508     # necessarily find mcrt1.o even if we have it.
509     if { [istarget *-*-solaris2*] && [lindex $test_what 1] == "-p" } {
510         return 0
511     }
512
513     # Support for -p on irix relies on libprof1.a which doesn't appear to
514     # exist on any irix6 system currently posting testsuite results.
515     # Support for -pg on irix relies on gcrt1.o which doesn't exist yet.
516     # See: http://gcc.gnu.org/ml/gcc/2002-10/msg00169.html
517     if { [istarget mips*-*-irix*]
518     && ([lindex $test_what 1] == "-p" || [lindex $test_what 1] == "-pg") } {
519         return 0
520     }
521
522     # We don't yet support profiling for MIPS16.
523     if { [istarget mips*-*-*]
524          && ![check_effective_target_nomips16]
525          && ([lindex $test_what 1] == "-p"
526              || [lindex $test_what 1] == "-pg") } {
527         return 0
528     }
529
530     # MinGW does not support -p.
531     if { [istarget *-*-mingw*] && [lindex $test_what 1] == "-p" } {
532         return 0
533     }
534
535     # cygwin does not support -p.
536     if { [istarget *-*-cygwin*] && [lindex $test_what 1] == "-p" } {
537         return 0
538     }
539
540     # uClibc does not have gcrt1.o.
541     if { [check_effective_target_uclibc]
542          && ([lindex $test_what 1] == "-p"
543              || [lindex $test_what 1] == "-pg") } {
544         return 0
545     }
546
547     # Now examine the cache variable.
548     if {![info exists profiling_available_saved]} {
549         # Some targets don't have any implementation of __bb_init_func or are
550         # missing other needed machinery.
551         if { [istarget mmix-*-*]
552              || [istarget arm*-*-eabi*]
553              || [istarget picochip-*-*]
554              || [istarget *-*-netware*]
555              || [istarget arm*-*-elf]
556              || [istarget arm*-*-symbianelf*]
557              || [istarget avr-*-*]
558              || [istarget bfin-*-*]
559              || [istarget powerpc-*-eabi*]
560              || [istarget powerpc-*-elf]
561              || [istarget cris-*-*]
562              || [istarget crisv32-*-*]
563              || [istarget fido-*-elf]
564              || [istarget h8300-*-*]
565              || [istarget lm32-*-*]
566              || [istarget m32c-*-elf]
567              || [istarget m68k-*-elf]
568              || [istarget m68k-*-uclinux*]
569              || [istarget mep-*-elf]
570              || [istarget mips*-*-elf*]
571              || [istarget moxie-*-elf*]
572              || [istarget rx-*-*]       
573              || [istarget xstormy16-*]
574              || [istarget xtensa*-*-elf]
575              || [istarget *-*-rtems*]
576              || [istarget *-*-vxworks*] } {
577             set profiling_available_saved 0
578         } else {
579             set profiling_available_saved 1
580         }
581     }
582
583     return $profiling_available_saved
584 }
585
586 # Check to see if a target is "freestanding". This is as per the definition
587 # in Section 4 of C99 standard. Effectively, it is a target which supports no
588 # extra headers or libraries other than what is considered essential.
589 proc check_effective_target_freestanding { } {
590     if { [istarget picochip-*-*] } then {
591         return 1
592     } else {
593         return 0
594     }
595 }
596
597 # Return 1 if target has packed layout of structure members by
598 # default, 0 otherwise.  Note that this is slightly different than
599 # whether the target has "natural alignment": both attributes may be
600 # false.
601
602 proc check_effective_target_default_packed { } {
603     return [check_no_compiler_messages default_packed assembly {
604         struct x { char a; long b; } c;
605         int s[sizeof (c) == sizeof (char) + sizeof (long) ? 1 : -1];
606     }]
607 }
608
609 # Return 1 if target has PCC_BITFIELD_TYPE_MATTERS defined.  See
610 # documentation, where the test also comes from.
611
612 proc check_effective_target_pcc_bitfield_type_matters { } {
613     # PCC_BITFIELD_TYPE_MATTERS isn't just about unnamed or empty
614     # bitfields, but let's stick to the example code from the docs.
615     return [check_no_compiler_messages pcc_bitfield_type_matters assembly {
616         struct foo1 { char x; char :0; char y; };
617         struct foo2 { char x; int :0; char y; };
618         int s[sizeof (struct foo1) != sizeof (struct foo2) ? 1 : -1];
619     }]
620 }
621
622 # Add to FLAGS all the target-specific flags needed to use thread-local storage.
623
624 proc add_options_for_tls { flags } {
625     # On Solaris 8 and 9, __tls_get_addr/___tls_get_addr only lives in
626     # libthread, so always pass -pthread for native TLS.
627     # Need to duplicate native TLS check from
628     # check_effective_target_tls_native to avoid recursion.
629     if { [istarget *-*-solaris2.\[89\]*] &&
630          [check_no_messages_and_pattern tls_native "!emutls" assembly {
631              __thread int i;
632              int f (void) { return i; }
633              void g (int j) { i = j; }
634          }] } {
635         return "$flags -pthread"
636     }
637     return $flags
638 }
639
640 # Return 1 if thread local storage (TLS) is supported, 0 otherwise.
641
642 proc check_effective_target_tls {} {
643     return [check_no_compiler_messages tls assembly {
644         __thread int i;
645         int f (void) { return i; }
646         void g (int j) { i = j; }
647     }]
648 }
649
650 # Return 1 if *native* thread local storage (TLS) is supported, 0 otherwise.
651
652 proc check_effective_target_tls_native {} {
653     # VxWorks uses emulated TLS machinery, but with non-standard helper
654     # functions, so we fail to automatically detect it.
655     global target_triplet
656     if { [regexp ".*-.*-vxworks.*" $target_triplet] } {
657         return 0
658     }
659     
660     return [check_no_messages_and_pattern tls_native "!emutls" assembly {
661         __thread int i;
662         int f (void) { return i; }
663         void g (int j) { i = j; }
664     }]
665 }
666
667 # Return 1 if *emulated* thread local storage (TLS) is supported, 0 otherwise.
668
669 proc check_effective_target_tls_emulated {} {
670     # VxWorks uses emulated TLS machinery, but with non-standard helper
671     # functions, so we fail to automatically detect it.
672     global target_triplet
673     if { [regexp ".*-.*-vxworks.*" $target_triplet] } {
674         return 1
675     }
676     
677     return [check_no_messages_and_pattern tls_emulated "emutls" assembly {
678         __thread int i;
679         int f (void) { return i; }
680         void g (int j) { i = j; }
681     }]
682 }
683
684 # Return 1 if TLS executables can run correctly, 0 otherwise.
685
686 proc check_effective_target_tls_runtime {} {
687     return [check_runtime tls_runtime {
688         __thread int thr = 0;
689         int main (void) { return thr; }
690     }]
691 }
692
693 # Return 1 if -ffunction-sections is supported, 0 otherwise.
694
695 proc check_effective_target_function_sections {} {
696     # Darwin has its own scheme and silently accepts -ffunction-sections.
697     global target_triplet
698     if { [regexp ".*-.*-darwin.*" $target_triplet] } {
699         return 0
700     }
701     
702     return [check_no_compiler_messages functionsections assembly {
703         void foo (void) { }
704     } "-ffunction-sections"]
705 }
706
707 # Return 1 if compilation with -fgraphite is error-free for trivial 
708 # code, 0 otherwise.
709
710 proc check_effective_target_fgraphite {} {
711     return [check_no_compiler_messages fgraphite object {
712         void foo (void) { }
713     } "-O1 -fgraphite"]
714 }
715
716 # Return 1 if compilation with -fopenmp is error-free for trivial
717 # code, 0 otherwise.
718
719 proc check_effective_target_fopenmp {} {
720     return [check_no_compiler_messages fopenmp object {
721         void foo (void) { }
722     } "-fopenmp"]
723 }
724
725 # Return 1 if compilation with -pthread is error-free for trivial
726 # code, 0 otherwise.
727
728 proc check_effective_target_pthread {} {
729     return [check_no_compiler_messages pthread object {
730         void foo (void) { }
731     } "-pthread"]
732 }
733
734 # Return 1 if compilation with -mpe-aligned-commons is error-free
735 # for trivial code, 0 otherwise.
736
737 proc check_effective_target_pe_aligned_commons {} {
738     if { [istarget *-*-cygwin*] || [istarget *-*-mingw*] } {
739         return [check_no_compiler_messages pe_aligned_commons object {
740             int foo;
741         } "-mpe-aligned-commons"]
742     }
743     return 0
744 }
745
746 # Return 1 if the target supports -static
747 proc check_effective_target_static {} {
748     return [check_no_compiler_messages static executable {
749         int main (void) { return 0; }
750     } "-static"]
751 }
752
753 # Return 1 if the target supports -fstack-protector
754 proc check_effective_target_fstack_protector {} {
755     return [check_runtime fstack_protector {
756         int main (void) { return 0; }
757     } "-fstack-protector"]
758 }
759
760 # Return 1 if compilation with -freorder-blocks-and-partition is error-free
761 # for trivial code, 0 otherwise.
762
763 proc check_effective_target_freorder {} {
764     return [check_no_compiler_messages freorder object {
765         void foo (void) { }
766     } "-freorder-blocks-and-partition"]
767 }
768
769 # Return 1 if -fpic and -fPIC are supported, as in no warnings or errors
770 # emitted, 0 otherwise.  Whether a shared library can actually be built is
771 # out of scope for this test.
772
773 proc check_effective_target_fpic { } {
774     # Note that M68K has a multilib that supports -fpic but not
775     # -fPIC, so we need to check both.  We test with a program that
776     # requires GOT references.
777     foreach arg {fpic fPIC} {
778         if [check_no_compiler_messages $arg object {
779             extern int foo (void); extern int bar;
780             int baz (void) { return foo () + bar; }
781         } "-$arg"] {
782             return 1
783         }
784     }
785     return 0
786 }
787
788 # Return true if the target supports -mpaired-single (as used on MIPS).
789
790 proc check_effective_target_mpaired_single { } {
791     return [check_no_compiler_messages mpaired_single object {
792         void foo (void) { }
793     } "-mpaired-single"]
794 }
795
796 # Return true if the target has access to FPU instructions.
797
798 proc check_effective_target_hard_float { } {
799     if { [istarget mips*-*-*] } {
800         return [check_no_compiler_messages hard_float assembly {
801                 #if (defined __mips_soft_float || defined __mips16)
802                 #error FOO
803                 #endif
804         }]
805     }
806
807     # This proc is actually checking the availabilty of FPU
808     # support for doubles, so on the RX we must fail if the
809     # 64-bit double multilib has been selected.
810     if { [istarget rx-*-*] } {
811         return 0
812         # return [check_no_compiler_messages hard_float assembly {
813                 #if defined __RX_64_BIT_DOUBLES__
814                 #error FOO
815                 #endif
816         # }]
817     }
818
819     # The generic test equates hard_float with "no call for adding doubles".
820     return [check_no_messages_and_pattern hard_float "!\\(call" rtl-expand {
821         double a (double b, double c) { return b + c; }
822     }]
823 }
824
825 # Return true if the target is a 64-bit MIPS target.
826
827 proc check_effective_target_mips64 { } {
828     return [check_no_compiler_messages mips64 assembly {
829         #ifndef __mips64
830         #error FOO
831         #endif
832     }]
833 }
834
835 # Return true if the target is a MIPS target that does not produce
836 # MIPS16 code.
837
838 proc check_effective_target_nomips16 { } {
839     return [check_no_compiler_messages nomips16 object {
840         #ifndef __mips
841         #error FOO
842         #else
843         /* A cheap way of testing for -mflip-mips16.  */
844         void foo (void) { asm ("addiu $20,$20,1"); }
845         void bar (void) { asm ("addiu $20,$20,1"); }
846         #endif
847     }]
848 }
849
850 # Add the options needed for MIPS16 function attributes.  At the moment,
851 # we don't support MIPS16 PIC.
852
853 proc add_options_for_mips16_attribute { flags } {
854     return "$flags -mno-abicalls -fno-pic -DMIPS16=__attribute__((mips16))"
855 }
856
857 # Return true if we can force a mode that allows MIPS16 code generation.
858 # We don't support MIPS16 PIC, and only support MIPS16 -mhard-float
859 # for o32 and o64.
860
861 proc check_effective_target_mips16_attribute { } {
862     return [check_no_compiler_messages mips16_attribute assembly {
863         #ifdef PIC
864         #error FOO
865         #endif
866         #if defined __mips_hard_float \
867             && (!defined _ABIO32 || _MIPS_SIM != _ABIO32) \
868             && (!defined _ABIO64 || _MIPS_SIM != _ABIO64)
869         #error FOO
870         #endif
871     } [add_options_for_mips16_attribute ""]]
872 }
873
874 # Return 1 if the target supports long double larger than double when
875 # using the new ABI, 0 otherwise.
876
877 proc check_effective_target_mips_newabi_large_long_double { } {
878     return [check_no_compiler_messages mips_newabi_large_long_double object {
879         int dummy[sizeof(long double) > sizeof(double) ? 1 : -1];
880     } "-mabi=64"]
881 }
882
883 # Return 1 if the current multilib does not generate PIC by default.
884
885 proc check_effective_target_nonpic { } {
886     return [check_no_compiler_messages nonpic assembly {
887         #if __PIC__
888         #error FOO
889         #endif
890     }]
891 }
892
893 # Return 1 if the target does not use a status wrapper.
894
895 proc check_effective_target_unwrapped { } {
896     if { [target_info needs_status_wrapper] != "" \
897              && [target_info needs_status_wrapper] != "0" } {
898         return 0
899     }
900     return 1
901 }
902
903 # Return true if iconv is supported on the target. In particular IBM1047.
904
905 proc check_iconv_available { test_what } {
906     global libiconv
907
908     # If the tool configuration file has not set libiconv, try "-liconv"
909     if { ![info exists libiconv] } {
910         set libiconv "-liconv"
911     }
912     set test_what [lindex $test_what 1]
913     return [check_runtime_nocache $test_what [subst {
914         #include <iconv.h>
915         int main (void)
916         {
917           iconv_t cd;
918
919           cd = iconv_open ("$test_what", "UTF-8");
920           if (cd == (iconv_t) -1)
921             return 1;
922           return 0;
923         }
924     }] $libiconv]
925 }
926
927 # Return true if named sections are supported on this target.
928
929 proc check_named_sections_available { } {
930     return [check_no_compiler_messages named_sections assembly {
931         int __attribute__ ((section("whatever"))) foo;
932     }]
933 }
934
935 # Return 1 if the target supports Fortran real kinds larger than real(8),
936 # 0 otherwise.
937 #
938 # When the target name changes, replace the cached result.
939
940 proc check_effective_target_fortran_large_real { } {
941     return [check_no_compiler_messages fortran_large_real executable {
942         ! Fortran
943         integer,parameter :: k = selected_real_kind (precision (0.0_8) + 1)
944         real(kind=k) :: x
945         x = cos (x)
946         end
947     }]
948 }
949
950 # Return 1 if the target supports Fortran integer kinds larger than
951 # integer(8), 0 otherwise.
952 #
953 # When the target name changes, replace the cached result.
954
955 proc check_effective_target_fortran_large_int { } {
956     return [check_no_compiler_messages fortran_large_int executable {
957         ! Fortran
958         integer,parameter :: k = selected_int_kind (range (0_8) + 1)
959         integer(kind=k) :: i
960         end
961     }]
962 }
963
964 # Return 1 if the target supports Fortran integer(16), 0 otherwise.
965 #
966 # When the target name changes, replace the cached result.
967
968 proc check_effective_target_fortran_integer_16 { } {
969     return [check_no_compiler_messages fortran_integer_16 executable {
970         ! Fortran
971         integer(16) :: i
972         end
973     }]
974 }
975
976 # Return 1 if we can statically link libgfortran, 0 otherwise.
977 #
978 # When the target name changes, replace the cached result.
979
980 proc check_effective_target_static_libgfortran { } {
981     return [check_no_compiler_messages static_libgfortran executable {
982         ! Fortran
983         print *, 'test'
984         end
985     } "-static"]
986 }
987
988 proc check_linker_plugin_available { } {
989   return [check_no_compiler_messages_nocache linker_plugin executable {
990      int main() { return 0; }
991   } "-flto -fuse-linker-plugin"]
992 }
993
994 # Return 1 if the target supports executing 750CL paired-single instructions, 0
995 # otherwise.  Cache the result.
996
997 proc check_750cl_hw_available { } {
998     return [check_cached_effective_target 750cl_hw_available {
999         # If this is not the right target then we can skip the test.
1000         if { ![istarget powerpc-*paired*] } {
1001             expr 0
1002         } else {
1003             check_runtime_nocache 750cl_hw_available {
1004                  int main()
1005                  {
1006                  #ifdef __MACH__
1007                    asm volatile ("ps_mul v0,v0,v0");
1008                  #else
1009                    asm volatile ("ps_mul 0,0,0");
1010                  #endif
1011                    return 0;
1012                  }
1013             } "-mpaired"
1014         }
1015     }]
1016 }
1017
1018 # Return 1 if the target OS supports running SSE executables, 0
1019 # otherwise.  Cache the result.
1020
1021 proc check_sse_os_support_available { } {
1022     return [check_cached_effective_target sse_os_support_available {
1023         # If this is not the right target then we can skip the test.
1024         if { !([istarget x86_64-*-*] || [istarget i?86-*-*]) } {
1025             expr 0
1026         } elseif { [istarget i?86-*-solaris2*] } {
1027             # The Solaris 2 kernel doesn't save and restore SSE registers
1028             # before Solaris 9 4/04.  Before that, executables die with SIGILL.
1029             check_runtime_nocache sse_os_support_available {
1030                 int main ()
1031                 {
1032                     __asm__ volatile ("movss %xmm2,%xmm1");
1033                     return 0;
1034                 }
1035             } "-msse"
1036         } else {
1037             expr 1
1038         }
1039     }]
1040 }
1041
1042 # Return 1 if the target supports executing SSE instructions, 0
1043 # otherwise.  Cache the result.
1044
1045 proc check_sse_hw_available { } {
1046     return [check_cached_effective_target sse_hw_available {
1047         # If this is not the right target then we can skip the test.
1048         if { !([istarget x86_64-*-*] || [istarget i?86-*-*]) } {
1049             expr 0
1050         } else {
1051             check_runtime_nocache sse_hw_available {
1052                 #include "cpuid.h"
1053                 int main ()
1054                 {
1055                   unsigned int eax, ebx, ecx, edx;
1056                   if (__get_cpuid (1, &eax, &ebx, &ecx, &edx))
1057                     return !(edx & bit_SSE);
1058                   return 1;
1059                 }
1060             } ""
1061         }
1062     }]
1063 }
1064
1065 # Return 1 if the target supports executing SSE2 instructions, 0
1066 # otherwise.  Cache the result.
1067
1068 proc check_sse2_hw_available { } {
1069     return [check_cached_effective_target sse2_hw_available {
1070         # If this is not the right target then we can skip the test.
1071         if { !([istarget x86_64-*-*] || [istarget i?86-*-*]) } {
1072             expr 0
1073         } else {
1074             check_runtime_nocache sse2_hw_available {
1075                 #include "cpuid.h"
1076                 int main ()
1077                 {
1078                   unsigned int eax, ebx, ecx, edx;
1079                   if (__get_cpuid (1, &eax, &ebx, &ecx, &edx))
1080                     return !(edx & bit_SSE2);
1081                   return 1;
1082                 }
1083             } ""
1084         }
1085     }]
1086 }
1087
1088 # Return 1 if the target supports executing AVX instructions, 0
1089 # otherwise.  Cache the result.
1090
1091 proc check_avx_hw_available { } {
1092     return [check_cached_effective_target avx_hw_available {
1093         # If this is not the right target then we can skip the test.
1094         if { !([istarget x86_64-*-*] || [istarget i?86-*-*]) } {
1095             expr 0
1096         } else {
1097             check_runtime_nocache avx_hw_available {
1098                 #include "cpuid.h"
1099                 int main ()
1100                 {
1101                   unsigned int eax, ebx, ecx, edx;
1102                   if (__get_cpuid (1, &eax, &ebx, &ecx, &edx))
1103                     return ((ecx & (bit_AVX | bit_OSXSAVE))
1104                             != (bit_AVX | bit_OSXSAVE));
1105                   return 1;
1106                 }
1107             } ""
1108         }
1109     }]
1110 }
1111
1112 # Return 1 if the target supports running SSE executables, 0 otherwise.
1113
1114 proc check_effective_target_sse_runtime { } {
1115     if { [check_effective_target_sse]
1116          && [check_sse_hw_available]
1117          && [check_sse_os_support_available] } {
1118         return 1
1119     }
1120     return 0
1121 }
1122
1123 # Return 1 if the target supports running SSE2 executables, 0 otherwise.
1124
1125 proc check_effective_target_sse2_runtime { } {
1126     if { [check_effective_target_sse2]
1127          && [check_sse2_hw_available]
1128          && [check_sse_os_support_available] } {
1129         return 1
1130     }
1131     return 0
1132 }
1133
1134 # Return 1 if the target supports running AVX executables, 0 otherwise.
1135
1136 proc check_effective_target_avx_runtime { } {
1137     if { [check_effective_target_avx]
1138          && [check_avx_hw_available] } {
1139         return 1
1140     }
1141     return 0
1142 }
1143
1144 # Return 1 if the target supports executing VSX instructions, 0
1145 # otherwise.  Cache the result.
1146
1147 proc check_vsx_hw_available { } {
1148     return [check_cached_effective_target vsx_hw_available {
1149         # Some simulators are known to not support VSX instructions.
1150         # For now, disable on Darwin
1151         if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] || [istarget *-*-darwin*]} {
1152             expr 0
1153         } else {
1154             set options "-mvsx"
1155             check_runtime_nocache vsx_hw_available {
1156                 int main()
1157                 {
1158                 #ifdef __MACH__
1159                   asm volatile ("xxlor vs0,vs0,vs0");
1160                 #else
1161                   asm volatile ("xxlor 0,0,0");
1162                 #endif
1163                   return 0;
1164                 }
1165             } $options
1166         }
1167     }]
1168 }
1169
1170 # Return 1 if the target supports executing AltiVec instructions, 0
1171 # otherwise.  Cache the result.
1172
1173 proc check_vmx_hw_available { } {
1174     return [check_cached_effective_target vmx_hw_available {
1175         # Some simulators are known to not support VMX instructions.
1176         if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
1177             expr 0
1178         } else {
1179             # Most targets don't require special flags for this test case, but
1180             # Darwin does.  Just to be sure, make sure VSX is not enabled for
1181             # the altivec tests.
1182             if { [istarget *-*-darwin*]
1183                  || [istarget *-*-aix*] } {
1184                 set options "-maltivec -mno-vsx"
1185             } else {
1186                 set options "-mno-vsx"
1187             }
1188             check_runtime_nocache vmx_hw_available {
1189                 int main()
1190                 {
1191                 #ifdef __MACH__
1192                   asm volatile ("vor v0,v0,v0");
1193                 #else
1194                   asm volatile ("vor 0,0,0");
1195                 #endif
1196                   return 0;
1197                 }
1198             } $options
1199         }
1200     }]
1201 }
1202
1203 proc check_ppc_recip_hw_available { } {
1204     return [check_cached_effective_target ppc_recip_hw_available {
1205         # Some simulators may not support FRE/FRES/FRSQRTE/FRSQRTES
1206         # For now, disable on Darwin
1207         if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] || [istarget *-*-darwin*]} {
1208             expr 0
1209         } else {
1210             set options "-mpowerpc-gfxopt -mpowerpc-gpopt -mpopcntb"
1211             check_runtime_nocache ppc_recip_hw_available {
1212                 volatile double d_recip, d_rsqrt, d_four = 4.0;
1213                 volatile float f_recip, f_rsqrt, f_four = 4.0f;
1214                 int main()
1215                 {
1216                   asm volatile ("fres %0,%1" : "=f" (f_recip) : "f" (f_four));
1217                   asm volatile ("fre %0,%1" : "=d" (d_recip) : "d" (d_four));
1218                   asm volatile ("frsqrtes %0,%1" : "=f" (f_rsqrt) : "f" (f_four));
1219                   asm volatile ("frsqrte %0,%1" : "=f" (d_rsqrt) : "d" (d_four));
1220                   return 0;
1221                 }
1222             } $options
1223         }
1224     }]
1225 }
1226
1227 # Return 1 if the target supports executing AltiVec and Cell PPU
1228 # instructions, 0 otherwise.  Cache the result.
1229
1230 proc check_effective_target_cell_hw { } {
1231     return [check_cached_effective_target cell_hw_available {
1232         # Some simulators are known to not support VMX and PPU instructions.
1233         if { [istarget powerpc-*-eabi*] } {
1234             expr 0
1235         } else {
1236             # Most targets don't require special flags for this test
1237             # case, but Darwin and AIX do.
1238             if { [istarget *-*-darwin*]
1239                  || [istarget *-*-aix*] } {
1240                 set options "-maltivec -mcpu=cell"
1241             } else {
1242                 set options "-mcpu=cell"
1243             }
1244             check_runtime_nocache cell_hw_available {
1245                 int main()
1246                 {
1247                 #ifdef __MACH__
1248                   asm volatile ("vor v0,v0,v0");
1249                   asm volatile ("lvlx v0,r0,r0");
1250                 #else
1251                   asm volatile ("vor 0,0,0");
1252                   asm volatile ("lvlx 0,0,0");
1253                 #endif
1254                   return 0;
1255                 }
1256             } $options
1257         }
1258     }]
1259 }
1260
1261 # Return 1 if the target supports executing 64-bit instructions, 0
1262 # otherwise.  Cache the result.
1263
1264 proc check_effective_target_powerpc64 { } {
1265     global powerpc64_available_saved
1266     global tool
1267
1268     if [info exists powerpc64_available_saved] {
1269         verbose "check_effective_target_powerpc64 returning saved $powerpc64_available_saved" 2
1270     } else {
1271         set powerpc64_available_saved 0
1272
1273         # Some simulators are known to not support powerpc64 instructions.
1274         if { [istarget powerpc-*-eabi*] || [istarget powerpc-ibm-aix*] } {
1275             verbose "check_effective_target_powerpc64 returning 0" 2
1276             return $powerpc64_available_saved
1277         }
1278
1279         # Set up, compile, and execute a test program containing a 64-bit
1280         # instruction.  Include the current process ID in the file
1281         # names to prevent conflicts with invocations for multiple
1282         # testsuites.
1283         set src ppc[pid].c
1284         set exe ppc[pid].x
1285
1286         set f [open $src "w"]
1287         puts $f "int main() {"
1288         puts $f "#ifdef __MACH__"
1289         puts $f "  asm volatile (\"extsw r0,r0\");"
1290         puts $f "#else"
1291         puts $f "  asm volatile (\"extsw 0,0\");"
1292         puts $f "#endif"
1293         puts $f "  return 0; }"
1294         close $f
1295
1296         set opts "additional_flags=-mcpu=G5"
1297
1298         verbose "check_effective_target_powerpc64 compiling testfile $src" 2
1299         set lines [${tool}_target_compile $src $exe executable "$opts"]
1300         file delete $src
1301
1302         if [string match "" $lines] then {
1303             # No error message, compilation succeeded.
1304             set result [${tool}_load "./$exe" "" ""]
1305             set status [lindex $result 0]
1306             remote_file build delete $exe
1307             verbose "check_effective_target_powerpc64 testfile status is <$status>" 2
1308
1309             if { $status == "pass" } then {
1310                 set powerpc64_available_saved 1
1311             }
1312         } else {
1313             verbose "check_effective_target_powerpc64 testfile compilation failed" 2
1314         }
1315     }
1316
1317     return $powerpc64_available_saved
1318 }
1319
1320 # GCC 3.4.0 for powerpc64-*-linux* included an ABI fix for passing
1321 # complex float arguments.  This affects gfortran tests that call cabsf
1322 # in libm built by an earlier compiler.  Return 1 if libm uses the same
1323 # argument passing as the compiler under test, 0 otherwise.
1324 #
1325 # When the target name changes, replace the cached result.
1326
1327 proc check_effective_target_broken_cplxf_arg { } {
1328     return [check_cached_effective_target broken_cplxf_arg {
1329         # Skip the work for targets known not to be affected.
1330         if { ![istarget powerpc64-*-linux*] } {
1331             expr 0
1332         } elseif { ![is-effective-target lp64] } {
1333             expr 0
1334         } else {
1335             check_runtime_nocache broken_cplxf_arg {
1336                 #include <complex.h>
1337                 extern void abort (void);
1338                 float fabsf (float);
1339                 float cabsf (_Complex float);
1340                 int main ()
1341                 {
1342                   _Complex float cf;
1343                   float f;
1344                   cf = 3 + 4.0fi;
1345                   f = cabsf (cf);
1346                   if (fabsf (f - 5.0) > 0.0001)
1347                     abort ();
1348                   return 0;
1349                 }
1350             } "-lm"
1351         }
1352     }]
1353 }
1354
1355 proc check_alpha_max_hw_available { } {
1356     return [check_runtime alpha_max_hw_available {
1357         int main() { return __builtin_alpha_amask(1<<8) != 0; }
1358     }]
1359 }
1360
1361 # Returns true iff the FUNCTION is available on the target system.
1362 # (This is essentially a Tcl implementation of Autoconf's
1363 # AC_CHECK_FUNC.)
1364
1365 proc check_function_available { function } {
1366     return [check_no_compiler_messages ${function}_available \
1367                 executable [subst {
1368         #ifdef __cplusplus
1369         extern "C"
1370         #endif
1371         char $function ();
1372         int main () { $function (); }
1373     }]]
1374 }
1375
1376 # Returns true iff "fork" is available on the target system.
1377
1378 proc check_fork_available {} {
1379     return [check_function_available "fork"]
1380 }
1381
1382 # Returns true iff "mkfifo" is available on the target system.
1383
1384 proc check_mkfifo_available {} {
1385     if {[istarget *-*-cygwin*]} {
1386        # Cygwin has mkfifo, but support is incomplete.
1387        return 0
1388      }
1389
1390     return [check_function_available "mkfifo"]
1391 }
1392
1393 # Returns true iff "__cxa_atexit" is used on the target system.
1394
1395 proc check_cxa_atexit_available { } {
1396     return [check_cached_effective_target cxa_atexit_available {
1397         if { [istarget "hppa*-*-hpux10*"] } {
1398             # HP-UX 10 doesn't have __cxa_atexit but subsequent test passes.
1399             expr 0
1400         } elseif { [istarget "*-*-vxworks"] } {
1401             # vxworks doesn't have __cxa_atexit but subsequent test passes.
1402             expr 0
1403         } else {
1404             check_runtime_nocache cxa_atexit_available {
1405                 // C++
1406                 #include <stdlib.h>
1407                 static unsigned int count;
1408                 struct X
1409                 {
1410                   X() { count = 1; }
1411                   ~X()
1412                   {
1413                     if (count != 3)
1414                       exit(1);
1415                     count = 4;
1416                   }
1417                 };
1418                 void f()
1419                 {
1420                   static X x;
1421                 }
1422                 struct Y
1423                 {
1424                   Y() { f(); count = 2; }
1425                   ~Y()
1426                   {
1427                     if (count != 2)
1428                       exit(1);
1429                     count = 3;
1430                   }
1431                 };
1432                 Y y;
1433                 int main() { return 0; }
1434             }
1435         }
1436     }]
1437 }
1438
1439 proc check_effective_target_objc2 { } {
1440     return [check_no_compiler_messages objc2 object {
1441         #ifdef __OBJC2__
1442         int dummy[1];
1443         #else
1444         #error
1445         #endif 
1446     }]
1447 }
1448
1449 proc check_effective_target_next_runtime { } {
1450     return [check_no_compiler_messages objc2 object {
1451         #ifdef __NEXT_RUNTIME__
1452         int dummy[1];
1453         #else
1454         #error
1455         #endif 
1456     }]
1457 }
1458
1459 # Return 1 if we're generating 32-bit code using default options, 0
1460 # otherwise.
1461
1462 proc check_effective_target_ilp32 { } {
1463     return [check_no_compiler_messages ilp32 object {
1464         int dummy[sizeof (int) == 4
1465                   && sizeof (void *) == 4
1466                   && sizeof (long) == 4 ? 1 : -1];
1467     }]
1468 }
1469
1470 # Return 1 if we're generating 32-bit or larger integers using default
1471 # options, 0 otherwise.
1472
1473 proc check_effective_target_int32plus { } {
1474     return [check_no_compiler_messages int32plus object {
1475         int dummy[sizeof (int) >= 4 ? 1 : -1];
1476     }]
1477 }
1478
1479 # Return 1 if we're generating 32-bit or larger pointers using default
1480 # options, 0 otherwise.
1481
1482 proc check_effective_target_ptr32plus { } {
1483     return [check_no_compiler_messages ptr32plus object {
1484         int dummy[sizeof (void *) >= 4 ? 1 : -1];
1485     }]
1486 }
1487
1488 # Return 1 if we support 32-bit or larger array and structure sizes
1489 # using default options, 0 otherwise.
1490
1491 proc check_effective_target_size32plus { } {
1492     return [check_no_compiler_messages size32plus object {
1493         char dummy[65537];
1494     }]
1495 }
1496
1497 # Returns 1 if we're generating 16-bit or smaller integers with the
1498 # default options, 0 otherwise.
1499
1500 proc check_effective_target_int16 { } {
1501     return [check_no_compiler_messages int16 object {
1502         int dummy[sizeof (int) < 4 ? 1 : -1];
1503     }]
1504 }
1505
1506 # Return 1 if we're generating 64-bit code using default options, 0
1507 # otherwise.
1508
1509 proc check_effective_target_lp64 { } {
1510     return [check_no_compiler_messages lp64 object {
1511         int dummy[sizeof (int) == 4
1512                   && sizeof (void *) == 8
1513                   && sizeof (long) == 8 ? 1 : -1];
1514     }]
1515 }
1516
1517 # Return 1 if we're generating 64-bit code using default llp64 options,
1518 # 0 otherwise.
1519
1520 proc check_effective_target_llp64 { } {
1521     return [check_no_compiler_messages llp64 object {
1522         int dummy[sizeof (int) == 4
1523                   && sizeof (void *) == 8
1524                   && sizeof (long long) == 8
1525                   && sizeof (long) == 4 ? 1 : -1];
1526     }]
1527 }
1528
1529 # Return 1 if the target supports long double larger than double,
1530 # 0 otherwise.
1531
1532 proc check_effective_target_large_long_double { } {
1533     return [check_no_compiler_messages large_long_double object {
1534         int dummy[sizeof(long double) > sizeof(double) ? 1 : -1];
1535     }]
1536 }
1537
1538 # Return 1 if the target supports double larger than float,
1539 # 0 otherwise.
1540
1541 proc check_effective_target_large_double { } {
1542     return [check_no_compiler_messages large_double object {
1543         int dummy[sizeof(double) > sizeof(float) ? 1 : -1];
1544     }]
1545 }
1546
1547 # Return 1 if the target supports double of 64 bits,
1548 # 0 otherwise.
1549
1550 proc check_effective_target_double64 { } {
1551     return [check_no_compiler_messages double64 object {
1552         int dummy[sizeof(double) == 8 ? 1 : -1];
1553     }]
1554 }
1555
1556 # Return 1 if the target supports double of at least 64 bits,
1557 # 0 otherwise.
1558
1559 proc check_effective_target_double64plus { } {
1560     return [check_no_compiler_messages double64plus object {
1561         int dummy[sizeof(double) >= 8 ? 1 : -1];
1562     }]
1563 }
1564
1565 # Return 1 if the target supports compiling fixed-point,
1566 # 0 otherwise.
1567
1568 proc check_effective_target_fixed_point { } {
1569     return [check_no_compiler_messages fixed_point object {
1570         _Sat _Fract x; _Sat _Accum y;
1571     }]
1572 }
1573
1574 # Return 1 if the target supports compiling decimal floating point,
1575 # 0 otherwise.
1576
1577 proc check_effective_target_dfp_nocache { } {
1578     verbose "check_effective_target_dfp_nocache: compiling source" 2
1579     set ret [check_no_compiler_messages_nocache dfp object {
1580         float x __attribute__((mode(DD)));
1581     }]
1582     verbose "check_effective_target_dfp_nocache: returning $ret" 2
1583     return $ret
1584 }
1585
1586 proc check_effective_target_dfprt_nocache { } {
1587     return [check_runtime_nocache dfprt {
1588         typedef float d64 __attribute__((mode(DD)));
1589         d64 x = 1.2df, y = 2.3dd, z;
1590         int main () { z = x + y; return 0; }
1591     }]
1592 }
1593
1594 # Return 1 if the target supports compiling Decimal Floating Point,
1595 # 0 otherwise.
1596 #
1597 # This won't change for different subtargets so cache the result.
1598
1599 proc check_effective_target_dfp { } {
1600     return [check_cached_effective_target dfp {
1601         check_effective_target_dfp_nocache
1602     }]
1603 }
1604
1605 # Return 1 if the target supports linking and executing Decimal Floating
1606 # Point, 0 otherwise.
1607 #
1608 # This won't change for different subtargets so cache the result.
1609
1610 proc check_effective_target_dfprt { } {
1611     return [check_cached_effective_target dfprt {
1612         check_effective_target_dfprt_nocache
1613     }]
1614 }
1615
1616 # Return 1 if the target supports compiling and assembling UCN, 0 otherwise.
1617
1618 proc check_effective_target_ucn_nocache { } {
1619     # -std=c99 is only valid for C
1620     if [check_effective_target_c] {
1621         set ucnopts "-std=c99"
1622     }
1623     append ucnopts " -fextended-identifiers"
1624     verbose "check_effective_target_ucn_nocache: compiling source" 2
1625     set ret [check_no_compiler_messages_nocache ucn object {
1626         int \u00C0;
1627     } $ucnopts]
1628     verbose "check_effective_target_ucn_nocache: returning $ret" 2
1629     return $ret
1630 }
1631
1632 # Return 1 if the target supports compiling and assembling UCN, 0 otherwise.
1633 #
1634 # This won't change for different subtargets, so cache the result.
1635
1636 proc check_effective_target_ucn { } {
1637     return [check_cached_effective_target ucn {
1638         check_effective_target_ucn_nocache
1639     }]
1640 }
1641
1642 # Return 1 if the target needs a command line argument to enable a SIMD
1643 # instruction set.
1644
1645 proc check_effective_target_vect_cmdline_needed { } {
1646     global et_vect_cmdline_needed_saved
1647     global et_vect_cmdline_needed_target_name
1648
1649     if { ![info exists et_vect_cmdline_needed_target_name] } {
1650         set et_vect_cmdline_needed_target_name ""
1651     }
1652
1653     # If the target has changed since we set the cached value, clear it.
1654     set current_target [current_target_name]
1655     if { $current_target != $et_vect_cmdline_needed_target_name } {
1656         verbose "check_effective_target_vect_cmdline_needed: `$et_vect_cmdline_needed_target_name' `$current_target'" 2
1657         set et_vect_cmdline_needed_target_name $current_target
1658         if { [info exists et_vect_cmdline_needed_saved] } {
1659             verbose "check_effective_target_vect_cmdline_needed: removing cached result" 2
1660             unset et_vect_cmdline_needed_saved
1661         }
1662     }
1663
1664     if [info exists et_vect_cmdline_needed_saved] {
1665         verbose "check_effective_target_vect_cmdline_needed: using cached result" 2
1666     } else {
1667         set et_vect_cmdline_needed_saved 1
1668         if { [istarget alpha*-*-*]
1669              || [istarget ia64-*-*]
1670              || (([istarget x86_64-*-*] || [istarget i?86-*-*])
1671                  && [check_effective_target_lp64])
1672              || ([istarget powerpc*-*-*]
1673                  && ([check_effective_target_powerpc_spe]
1674                      || [check_effective_target_powerpc_altivec]))
1675              || [istarget spu-*-*]
1676              || ([istarget arm*-*-*] && [check_effective_target_arm_neon]) } {
1677            set et_vect_cmdline_needed_saved 0
1678         }
1679     }
1680
1681     verbose "check_effective_target_vect_cmdline_needed: returning $et_vect_cmdline_needed_saved" 2
1682     return $et_vect_cmdline_needed_saved
1683 }
1684
1685 # Return 1 if the target supports hardware vectors of int, 0 otherwise.
1686 #
1687 # This won't change for different subtargets so cache the result.
1688
1689 proc check_effective_target_vect_int { } {
1690     global et_vect_int_saved
1691
1692     if [info exists et_vect_int_saved] {
1693         verbose "check_effective_target_vect_int: using cached result" 2
1694     } else {
1695         set et_vect_int_saved 0
1696         if { [istarget i?86-*-*]
1697              || ([istarget powerpc*-*-*]
1698                   && ![istarget powerpc-*-linux*paired*])
1699               || [istarget spu-*-*]
1700               || [istarget x86_64-*-*]
1701               || [istarget sparc*-*-*]
1702               || [istarget alpha*-*-*]
1703               || [istarget ia64-*-*] 
1704               || [check_effective_target_arm32]
1705               || ([istarget mips*-*-*]
1706                   && [check_effective_target_mips_loongson]) } {
1707            set et_vect_int_saved 1
1708         }
1709     }
1710
1711     verbose "check_effective_target_vect_int: returning $et_vect_int_saved" 2
1712     return $et_vect_int_saved
1713 }
1714
1715 # Return 1 if the target supports signed int->float conversion 
1716 #
1717
1718 proc check_effective_target_vect_intfloat_cvt { } {
1719     global et_vect_intfloat_cvt_saved
1720
1721     if [info exists et_vect_intfloat_cvt_saved] {
1722         verbose "check_effective_target_vect_intfloat_cvt: using cached result" 2
1723     } else {
1724         set et_vect_intfloat_cvt_saved 0
1725         if { [istarget i?86-*-*]
1726               || ([istarget powerpc*-*-*]
1727                    && ![istarget powerpc-*-linux*paired*])
1728               || [istarget x86_64-*-*] } {
1729            set et_vect_intfloat_cvt_saved 1
1730         }
1731     }
1732
1733     verbose "check_effective_target_vect_intfloat_cvt: returning $et_vect_intfloat_cvt_saved" 2
1734     return $et_vect_intfloat_cvt_saved
1735 }
1736
1737 #Return 1 if we're supporting __int128 for target, 0 otherwise.
1738
1739 proc check_effective_target_int128 { } {
1740     return [check_no_compiler_messages int128 object {
1741         int dummy[
1742         #ifndef __SIZEOF_INT128__
1743         -1
1744         #else
1745         1
1746         #endif
1747         ];
1748     }]
1749 }
1750
1751 # Return 1 if the target supports unsigned int->float conversion 
1752 #
1753
1754 proc check_effective_target_vect_uintfloat_cvt { } {
1755     global et_vect_uintfloat_cvt_saved
1756
1757     if [info exists et_vect_uintfloat_cvt_saved] {
1758         verbose "check_effective_target_vect_uintfloat_cvt: using cached result" 2
1759     } else {
1760         set et_vect_uintfloat_cvt_saved 0
1761         if { [istarget i?86-*-*]
1762               || ([istarget powerpc*-*-*]
1763                   && ![istarget powerpc-*-linux*paired*])
1764               || [istarget x86_64-*-*] } {
1765            set et_vect_uintfloat_cvt_saved 1
1766         }
1767     }
1768
1769     verbose "check_effective_target_vect_uintfloat_cvt: returning $et_vect_uintfloat_cvt_saved" 2
1770     return $et_vect_uintfloat_cvt_saved
1771 }
1772
1773
1774 # Return 1 if the target supports signed float->int conversion
1775 #
1776
1777 proc check_effective_target_vect_floatint_cvt { } {
1778     global et_vect_floatint_cvt_saved
1779
1780     if [info exists et_vect_floatint_cvt_saved] {
1781         verbose "check_effective_target_vect_floatint_cvt: using cached result" 2
1782     } else {
1783         set et_vect_floatint_cvt_saved 0
1784         if { [istarget i?86-*-*]
1785               || ([istarget powerpc*-*-*]
1786                    && ![istarget powerpc-*-linux*paired*])
1787               || [istarget x86_64-*-*] } {
1788            set et_vect_floatint_cvt_saved 1
1789         }
1790     }
1791
1792     verbose "check_effective_target_vect_floatint_cvt: returning $et_vect_floatint_cvt_saved" 2
1793     return $et_vect_floatint_cvt_saved
1794 }
1795
1796 # Return 1 if the target supports unsigned float->int conversion
1797 #
1798
1799 proc check_effective_target_vect_floatuint_cvt { } {
1800     global et_vect_floatuint_cvt_saved
1801
1802     if [info exists et_vect_floatuint_cvt_saved] {
1803         verbose "check_effective_target_vect_floatuint_cvt: using cached result" 2
1804     } else {
1805         set et_vect_floatuint_cvt_saved 0
1806         if { ([istarget powerpc*-*-*]
1807               && ![istarget powerpc-*-linux*paired*]) } {
1808            set et_vect_floatuint_cvt_saved 1
1809         }
1810     }
1811
1812     verbose "check_effective_target_vect_floatuint_cvt: returning $et_vect_floatuint_cvt_saved" 2
1813     return $et_vect_floatuint_cvt_saved
1814 }
1815
1816 # Return 1 is this is an arm target using 32-bit instructions
1817 proc check_effective_target_arm32 { } {
1818     return [check_no_compiler_messages arm32 assembly {
1819         #if !defined(__arm__) || (defined(__thumb__) && !defined(__thumb2__))
1820         #error FOO
1821         #endif
1822     }]
1823 }
1824
1825 # Return 1 if this is an ARM target supporting -mfpu=vfp
1826 # -mfloat-abi=softfp.  Some multilibs may be incompatible with these
1827 # options.
1828
1829 proc check_effective_target_arm_vfp_ok { } {
1830     if { [check_effective_target_arm32] } {
1831         return [check_no_compiler_messages arm_vfp_ok object {
1832             int dummy;
1833         } "-mfpu=vfp -mfloat-abi=softfp"]
1834     } else {
1835         return 0
1836     }
1837 }
1838
1839 # Return 1 if this is an ARM target supporting -mfpu=vfp
1840 # -mfloat-abi=hard.  Some multilibs may be incompatible with these
1841 # options.
1842
1843 proc check_effective_target_arm_hard_vfp_ok { } {
1844     if { [check_effective_target_arm32] } {
1845         return [check_no_compiler_messages arm_hard_vfp_ok executable {
1846             int main() { return 0;}
1847         } "-mfpu=vfp -mfloat-abi=hard"]
1848     } else {
1849         return 0
1850     }
1851 }
1852
1853 # Add the options needed for NEON.  We need either -mfloat-abi=softfp
1854 # or -mfloat-abi=hard, but if one is already specified by the
1855 # multilib, use it.  Similarly, if a -mfpu option already enables
1856 # NEON, do not add -mfpu=neon.
1857
1858 proc add_options_for_arm_neon { flags } {
1859     if { ! [check_effective_target_arm_neon_ok] } {
1860         return "$flags"
1861     }
1862     global et_arm_neon_flags
1863     return "$flags $et_arm_neon_flags"
1864 }
1865
1866 # Return 1 if this is an ARM target supporting -mfpu=neon
1867 # -mfloat-abi=softfp or equivalent options.  Some multilibs may be
1868 # incompatible with these options.  Also set et_arm_neon_flags to the
1869 # best options to add.
1870
1871 proc check_effective_target_arm_neon_ok_nocache { } {
1872     global et_arm_neon_flags
1873     set et_arm_neon_flags ""
1874     if { [check_effective_target_arm32] } {
1875         foreach flags {"" "-mfloat-abi=softfp" "-mfpu=neon" "-mfpu=neon -mfloat-abi=softfp"} {
1876             if { [check_no_compiler_messages_nocache arm_neon_ok object {
1877                 #include "arm_neon.h"
1878                 int dummy;
1879             } "$flags"] } {
1880                 set et_arm_neon_flags $flags
1881                 return 1
1882             }
1883         }
1884     }
1885
1886     return 0
1887 }
1888
1889 proc check_effective_target_arm_neon_ok { } {
1890     return [check_cached_effective_target arm_neon_ok \
1891                 check_effective_target_arm_neon_ok_nocache]
1892 }
1893
1894 # Add the options needed for NEON.  We need either -mfloat-abi=softfp
1895 # or -mfloat-abi=hard, but if one is already specified by the
1896 # multilib, use it.
1897
1898 proc add_options_for_arm_neon_fp16 { flags } {
1899     if { ! [check_effective_target_arm_neon_fp16_ok] } {
1900         return "$flags"
1901     }
1902     global et_arm_neon_fp16_flags
1903     return "$flags $et_arm_neon_fp16_flags"
1904 }
1905
1906 # Return 1 if this is an ARM target supporting -mfpu=neon-fp16
1907 # -mfloat-abi=softfp or equivalent options.  Some multilibs may be
1908 # incompatible with these options.  Also set et_arm_neon_flags to the
1909 # best options to add.
1910
1911 proc check_effective_target_arm_neon_fp16_ok_nocache { } {
1912     global et_arm_neon_fp16_flags
1913     set et_arm_neon_fp16_flags ""
1914     if { [check_effective_target_arm32] } {
1915         # Always add -mfpu=neon-fp16, since there is no preprocessor
1916         # macro for FP16 support.
1917         foreach flags {"-mfpu=neon-fp16" "-mfpu=neon-fp16 -mfloat-abi=softfp"} {
1918             if { [check_no_compiler_messages_nocache arm_neon_fp16_ok object {
1919                 #include "arm_neon.h"
1920                 int dummy;
1921             } "$flags"] } {
1922                 set et_arm_neon_fp16_flags $flags
1923                 return 1
1924             }
1925         }
1926     }
1927
1928     return 0
1929 }
1930
1931 proc check_effective_target_arm_neon_fp16_ok { } {
1932     return [check_cached_effective_target arm_neon_fp16_ok \
1933                 check_effective_target_arm_neon_fp16_ok_nocache]
1934 }
1935
1936 # Return 1 is this is an ARM target where -mthumb causes Thumb-1 to be
1937 # used.
1938
1939 proc check_effective_target_arm_thumb1_ok { } {
1940     return [check_no_compiler_messages arm_thumb1_ok assembly {
1941         #if !defined(__arm__) || !defined(__thumb__) || defined(__thumb2__)
1942         #error FOO
1943         #endif
1944     } "-mthumb"]
1945 }
1946
1947 # Return 1 is this is an ARM target where -mthumb causes Thumb-2 to be
1948 # used.
1949
1950 proc check_effective_target_arm_thumb2_ok { } {
1951     return [check_no_compiler_messages arm_thumb2_ok assembly {
1952         #if !defined(__thumb2__)
1953         #error FOO
1954         #endif
1955     } "-mthumb"]
1956 }
1957
1958 # Return 1 if the target supports executing NEON instructions, 0
1959 # otherwise.  Cache the result.
1960
1961 proc check_effective_target_arm_neon_hw { } {
1962     return [check_runtime arm_neon_hw_available {
1963         int
1964         main (void)
1965         {
1966           long long a = 0, b = 1;
1967           asm ("vorr %P0, %P1, %P2"
1968                : "=w" (a)
1969                : "0" (a), "w" (b));
1970           return (a != 1);
1971         }
1972     } [add_options_for_arm_neon ""]]
1973 }
1974
1975 # Return 1 if this is a ARM target with NEON enabled.
1976
1977 proc check_effective_target_arm_neon { } {
1978     if { [check_effective_target_arm32] } {
1979         return [check_no_compiler_messages arm_neon object {
1980             #ifndef __ARM_NEON__
1981             #error not NEON
1982             #else
1983             int dummy;
1984             #endif
1985         }]
1986     } else {
1987         return 0
1988     }
1989 }
1990
1991 # Return 1 if this a Loongson-2E or -2F target using an ABI that supports
1992 # the Loongson vector modes.
1993
1994 proc check_effective_target_mips_loongson { } {
1995     return [check_no_compiler_messages loongson assembly {
1996         #if !defined(__mips_loongson_vector_rev)
1997         #error FOO
1998         #endif
1999     }]
2000 }
2001
2002 # Return 1 if this is an ARM target that adheres to the ABI for the ARM
2003 # Architecture.
2004
2005 proc check_effective_target_arm_eabi { } {
2006     return [check_no_compiler_messages arm_eabi object {
2007         #ifndef __ARM_EABI__
2008         #error not EABI
2009         #else
2010         int dummy;
2011         #endif
2012     }]
2013 }
2014
2015 # Return 1 if this is an ARM target supporting -mcpu=iwmmxt.
2016 # Some multilibs may be incompatible with this option.
2017
2018 proc check_effective_target_arm_iwmmxt_ok { } {
2019     if { [check_effective_target_arm32] } {
2020         return [check_no_compiler_messages arm_iwmmxt_ok object {
2021             int dummy;
2022         } "-mcpu=iwmmxt"]
2023     } else {
2024         return 0
2025     }
2026 }
2027
2028 # Return 1 if this is a PowerPC target with floating-point registers.
2029
2030 proc check_effective_target_powerpc_fprs { } {
2031     if { [istarget powerpc*-*-*]
2032          || [istarget rs6000-*-*] } {
2033         return [check_no_compiler_messages powerpc_fprs object {
2034             #ifdef __NO_FPRS__
2035             #error no FPRs
2036             #else
2037             int dummy;
2038             #endif
2039         }]
2040     } else {
2041         return 0
2042     }
2043 }
2044
2045 # Return 1 if this is a PowerPC target with hardware double-precision
2046 # floating point.
2047
2048 proc check_effective_target_powerpc_hard_double { } {
2049     if { [istarget powerpc*-*-*]
2050          || [istarget rs6000-*-*] } {
2051         return [check_no_compiler_messages powerpc_hard_double object {
2052             #ifdef _SOFT_DOUBLE
2053             #error soft double
2054             #else
2055             int dummy;
2056             #endif
2057         }]
2058     } else {
2059         return 0
2060     }
2061 }
2062
2063 # Return 1 if this is a PowerPC target supporting -maltivec.
2064
2065 proc check_effective_target_powerpc_altivec_ok { } {
2066     if { ([istarget powerpc*-*-*]
2067          && ![istarget powerpc-*-linux*paired*])
2068          || [istarget rs6000-*-*] } {
2069         # AltiVec is not supported on AIX before 5.3.
2070         if { [istarget powerpc*-*-aix4*]
2071              || [istarget powerpc*-*-aix5.1*] 
2072              || [istarget powerpc*-*-aix5.2*] } {
2073             return 0
2074         }
2075         return [check_no_compiler_messages powerpc_altivec_ok object {
2076             int dummy;
2077         } "-maltivec"]
2078     } else {
2079         return 0
2080     }
2081 }
2082
2083 # Return 1 if this is a PowerPC target supporting -mvsx
2084
2085 proc check_effective_target_powerpc_vsx_ok { } {
2086     if { ([istarget powerpc*-*-*]
2087          && ![istarget powerpc-*-linux*paired*])
2088          || [istarget rs6000-*-*] } {
2089         # AltiVec is not supported on AIX before 5.3.
2090         if { [istarget powerpc*-*-aix4*]
2091              || [istarget powerpc*-*-aix5.1*] 
2092              || [istarget powerpc*-*-aix5.2*] } {
2093             return 0
2094         }
2095         return [check_no_compiler_messages powerpc_vsx_ok object {
2096             int main (void) {
2097 #ifdef __MACH__
2098                 asm volatile ("xxlor vs0,vs0,vs0");
2099 #else
2100                 asm volatile ("xxlor 0,0,0");
2101 #endif
2102                 return 0;
2103             }
2104         } "-mvsx"]
2105     } else {
2106         return 0
2107     }
2108 }
2109
2110 # Return 1 if this is a PowerPC target supporting -mcpu=cell.
2111
2112 proc check_effective_target_powerpc_ppu_ok { } {
2113     if [check_effective_target_powerpc_altivec_ok] {
2114         return [check_no_compiler_messages cell_asm_available object {
2115             int main (void) {
2116 #ifdef __MACH__
2117                 asm volatile ("lvlx v0,v0,v0");
2118 #else
2119                 asm volatile ("lvlx 0,0,0");
2120 #endif
2121                 return 0;
2122             }
2123         }]
2124     } else {
2125         return 0
2126     }
2127 }
2128
2129 # Return 1 if this is a PowerPC target that supports SPU.
2130
2131 proc check_effective_target_powerpc_spu { } {
2132     if [istarget powerpc*-*-linux*] {
2133         return [check_effective_target_powerpc_altivec_ok]
2134     } else {
2135         return 0
2136     }
2137 }
2138
2139 # Return 1 if this is a PowerPC SPE target.  The check includes options
2140 # specified by dg-options for this test, so don't cache the result.
2141
2142 proc check_effective_target_powerpc_spe_nocache { } {
2143     if { [istarget powerpc*-*-*] } {
2144         return [check_no_compiler_messages_nocache powerpc_spe object {
2145             #ifndef __SPE__
2146             #error not SPE
2147             #else
2148             int dummy;
2149             #endif
2150         } [current_compiler_flags]]
2151     } else {
2152         return 0
2153     }
2154 }
2155
2156 # Return 1 if this is a PowerPC target with SPE enabled.
2157
2158 proc check_effective_target_powerpc_spe { } {
2159     if { [istarget powerpc*-*-*] } {
2160         return [check_no_compiler_messages powerpc_spe object {
2161             #ifndef __SPE__
2162             #error not SPE
2163             #else
2164             int dummy;
2165             #endif
2166         }]
2167     } else {
2168         return 0
2169     }
2170 }
2171
2172 # Return 1 if this is a PowerPC target with Altivec enabled.
2173
2174 proc check_effective_target_powerpc_altivec { } {
2175     if { [istarget powerpc*-*-*] } {
2176         return [check_no_compiler_messages powerpc_altivec object {
2177             #ifndef __ALTIVEC__
2178             #error not Altivec
2179             #else
2180             int dummy;
2181             #endif
2182         }]
2183     } else {
2184         return 0
2185     }
2186 }
2187
2188 # Return 1 if this is a PowerPC 405 target.  The check includes options
2189 # specified by dg-options for this test, so don't cache the result.
2190
2191 proc check_effective_target_powerpc_405_nocache { } {
2192     if { [istarget powerpc*-*-*] || [istarget rs6000-*-*] } {
2193         return [check_no_compiler_messages_nocache powerpc_405 object {
2194             #ifdef __PPC405__
2195             int dummy;
2196             #else
2197             #error not a PPC405
2198             #endif
2199         } [current_compiler_flags]]
2200     } else {
2201         return 0
2202     }
2203 }
2204
2205 # Return 1 if this is a SPU target with a toolchain that
2206 # supports automatic overlay generation.
2207
2208 proc check_effective_target_spu_auto_overlay { } {
2209     if { [istarget spu*-*-elf*] } {
2210         return [check_no_compiler_messages spu_auto_overlay executable {
2211                 int main (void) { }
2212                 } "-Wl,--auto-overlay" ]
2213     } else {
2214         return 0
2215     }
2216 }
2217
2218 # The VxWorks SPARC simulator accepts only EM_SPARC executables and
2219 # chokes on EM_SPARC32PLUS or EM_SPARCV9 executables.  Return 1 if the
2220 # test environment appears to run executables on such a simulator.
2221
2222 proc check_effective_target_ultrasparc_hw { } {
2223     return [check_runtime ultrasparc_hw {
2224         int main() { return 0; }
2225     } "-mcpu=ultrasparc"]
2226 }
2227
2228 # Return 1 if the target supports hardware vector shift operation.
2229
2230 proc check_effective_target_vect_shift { } {
2231     global et_vect_shift_saved
2232
2233     if [info exists et_vect_shift_saved] {
2234         verbose "check_effective_target_vect_shift: using cached result" 2
2235     } else {
2236         set et_vect_shift_saved 0
2237         if { ([istarget powerpc*-*-*]
2238              && ![istarget powerpc-*-linux*paired*])
2239              || [istarget ia64-*-*]
2240              || [istarget i?86-*-*]
2241              || [istarget x86_64-*-*]
2242              || [check_effective_target_arm32]
2243              || ([istarget mips*-*-*]
2244                  && [check_effective_target_mips_loongson]) } {
2245            set et_vect_shift_saved 1
2246         }
2247     }
2248
2249     verbose "check_effective_target_vect_shift: returning $et_vect_shift_saved" 2
2250     return $et_vect_shift_saved
2251 }
2252
2253 # Return 1 if the target supports hardware vectors of long, 0 otherwise.
2254 #
2255 # This can change for different subtargets so do not cache the result.
2256
2257 proc check_effective_target_vect_long { } {
2258     if { [istarget i?86-*-*]
2259          || (([istarget powerpc*-*-*] 
2260               && ![istarget powerpc-*-linux*paired*]) 
2261               && [check_effective_target_ilp32])
2262          || [istarget x86_64-*-*]
2263          || [check_effective_target_arm32]
2264          || ([istarget sparc*-*-*] && [check_effective_target_ilp32]) } {
2265         set answer 1
2266     } else {
2267         set answer 0
2268     }
2269
2270     verbose "check_effective_target_vect_long: returning $answer" 2
2271     return $answer
2272 }
2273
2274 # Return 1 if the target supports hardware vectors of float, 0 otherwise.
2275 #
2276 # This won't change for different subtargets so cache the result.
2277
2278 proc check_effective_target_vect_float { } {
2279     global et_vect_float_saved
2280
2281     if [info exists et_vect_float_saved] {
2282         verbose "check_effective_target_vect_float: using cached result" 2
2283     } else {
2284         set et_vect_float_saved 0
2285         if { [istarget i?86-*-*]
2286               || [istarget powerpc*-*-*]
2287               || [istarget spu-*-*]
2288               || [istarget mipsisa64*-*-*]
2289               || [istarget x86_64-*-*]
2290               || [istarget ia64-*-*]
2291               || [check_effective_target_arm32] } {
2292            set et_vect_float_saved 1
2293         }
2294     }
2295
2296     verbose "check_effective_target_vect_float: returning $et_vect_float_saved" 2
2297     return $et_vect_float_saved
2298 }
2299
2300 # Return 1 if the target supports hardware vectors of double, 0 otherwise.
2301 #
2302 # This won't change for different subtargets so cache the result.
2303
2304 proc check_effective_target_vect_double { } {
2305     global et_vect_double_saved
2306
2307     if [info exists et_vect_double_saved] {
2308         verbose "check_effective_target_vect_double: using cached result" 2
2309     } else {
2310         set et_vect_double_saved 0
2311         if { [istarget i?86-*-*]
2312               || [istarget x86_64-*-*] 
2313               || [istarget spu-*-*] } {
2314            set et_vect_double_saved 1
2315         }
2316     }
2317
2318     verbose "check_effective_target_vect_double: returning $et_vect_double_saved" 2
2319     return $et_vect_double_saved
2320 }
2321
2322 # Return 1 if the target supports hardware vectors of long long, 0 otherwise.
2323 #
2324 # This won't change for different subtargets so cache the result.
2325
2326 proc check_effective_target_vect_long_long { } {
2327     global et_vect_long_long_saved
2328
2329     if [info exists et_vect_long_long_saved] {
2330         verbose "check_effective_target_vect_long_long: using cached result" 2
2331     } else {
2332         set et_vect_long_long_saved 0
2333         if { [istarget i?86-*-*]
2334               || [istarget x86_64-*-*] } {
2335            set et_vect_long_long_saved 1
2336         }
2337     }
2338
2339     verbose "check_effective_target_vect_long_long: returning $et_vect_long_long_saved" 2
2340     return $et_vect_long_long_saved
2341 }
2342
2343
2344 # Return 1 if the target plus current options does not support a vector
2345 # max instruction on "int", 0 otherwise.
2346 #
2347 # This won't change for different subtargets so cache the result.
2348
2349 proc check_effective_target_vect_no_int_max { } {
2350     global et_vect_no_int_max_saved
2351
2352     if [info exists et_vect_no_int_max_saved] {
2353         verbose "check_effective_target_vect_no_int_max: using cached result" 2
2354     } else {
2355         set et_vect_no_int_max_saved 0
2356         if { [istarget sparc*-*-*]
2357              || [istarget spu-*-*]
2358              || [istarget alpha*-*-*]
2359              || ([istarget mips*-*-*]
2360                  && [check_effective_target_mips_loongson]) } {
2361             set et_vect_no_int_max_saved 1
2362         }
2363     }
2364     verbose "check_effective_target_vect_no_int_max: returning $et_vect_no_int_max_saved" 2
2365     return $et_vect_no_int_max_saved
2366 }
2367
2368 # Return 1 if the target plus current options does not support a vector
2369 # add instruction on "int", 0 otherwise.
2370 #
2371 # This won't change for different subtargets so cache the result.
2372
2373 proc check_effective_target_vect_no_int_add { } {
2374     global et_vect_no_int_add_saved
2375
2376     if [info exists et_vect_no_int_add_saved] {
2377         verbose "check_effective_target_vect_no_int_add: using cached result" 2
2378     } else {
2379         set et_vect_no_int_add_saved 0
2380         # Alpha only supports vector add on V8QI and V4HI.
2381         if { [istarget alpha*-*-*] } {
2382             set et_vect_no_int_add_saved 1
2383         }
2384     }
2385     verbose "check_effective_target_vect_no_int_add: returning $et_vect_no_int_add_saved" 2
2386     return $et_vect_no_int_add_saved
2387 }
2388
2389 # Return 1 if the target plus current options does not support vector
2390 # bitwise instructions, 0 otherwise.
2391 #
2392 # This won't change for different subtargets so cache the result.
2393
2394 proc check_effective_target_vect_no_bitwise { } {
2395     global et_vect_no_bitwise_saved
2396
2397     if [info exists et_vect_no_bitwise_saved] {
2398         verbose "check_effective_target_vect_no_bitwise: using cached result" 2
2399     } else {
2400         set et_vect_no_bitwise_saved 0
2401     }
2402     verbose "check_effective_target_vect_no_bitwise: returning $et_vect_no_bitwise_saved" 2
2403     return $et_vect_no_bitwise_saved
2404 }
2405
2406 # Return 1 if the target plus current options supports vector permutation,
2407 # 0 otherwise.
2408 #
2409 # This won't change for different subtargets so cache the result.
2410
2411 proc check_effective_target_vect_perm { } {
2412     global et_vect_perm
2413
2414     if [info exists et_vect_perm_saved] {
2415         verbose "check_effective_target_vect_perm: using cached result" 2
2416     } else {
2417         set et_vect_perm_saved 0
2418         if { [istarget powerpc*-*-*]
2419              || [istarget spu-*-*] } {
2420             set et_vect_perm_saved 1
2421         }
2422     }
2423     verbose "check_effective_target_vect_perm: returning $et_vect_perm_saved" 2
2424     return $et_vect_perm_saved
2425 }
2426
2427 # Return 1 if the target plus current options supports a vector
2428 # widening summation of *short* args into *int* result, 0 otherwise.
2429 #
2430 # This won't change for different subtargets so cache the result.
2431
2432 proc check_effective_target_vect_widen_sum_hi_to_si_pattern { } {
2433     global et_vect_widen_sum_hi_to_si_pattern
2434
2435     if [info exists et_vect_widen_sum_hi_to_si_pattern_saved] {
2436         verbose "check_effective_target_vect_widen_sum_hi_to_si_pattern: using cached result" 2
2437     } else {
2438         set et_vect_widen_sum_hi_to_si_pattern_saved 0
2439         if { [istarget powerpc*-*-*] } {
2440             set et_vect_widen_sum_hi_to_si_pattern_saved 1
2441         }
2442     }
2443     verbose "check_effective_target_vect_widen_sum_hi_to_si_pattern: returning $et_vect_widen_sum_hi_to_si_pattern_saved" 2
2444     return $et_vect_widen_sum_hi_to_si_pattern_saved
2445 }
2446
2447 # Return 1 if the target plus current options supports a vector
2448 # widening summation of *short* args into *int* result, 0 otherwise.
2449 # A target can also support this widening summation if it can support
2450 # promotion (unpacking) from shorts to ints.
2451 #
2452 # This won't change for different subtargets so cache the result.
2453                                                                                                 
2454 proc check_effective_target_vect_widen_sum_hi_to_si { } {
2455     global et_vect_widen_sum_hi_to_si
2456
2457     if [info exists et_vect_widen_sum_hi_to_si_saved] {
2458         verbose "check_effective_target_vect_widen_sum_hi_to_si: using cached result" 2
2459     } else {
2460         set et_vect_widen_sum_hi_to_si_saved [check_effective_target_vect_unpack]
2461         if { [istarget powerpc*-*-*] 
2462              || [istarget ia64-*-*] } {
2463             set et_vect_widen_sum_hi_to_si_saved 1
2464         }
2465     }
2466     verbose "check_effective_target_vect_widen_sum_hi_to_si: returning $et_vect_widen_sum_hi_to_si_saved" 2
2467     return $et_vect_widen_sum_hi_to_si_saved
2468 }
2469
2470 # Return 1 if the target plus current options supports a vector
2471 # widening summation of *char* args into *short* result, 0 otherwise.
2472 # A target can also support this widening summation if it can support
2473 # promotion (unpacking) from chars to shorts.
2474 #
2475 # This won't change for different subtargets so cache the result.
2476                                                                                                 
2477 proc check_effective_target_vect_widen_sum_qi_to_hi { } {
2478     global et_vect_widen_sum_qi_to_hi
2479
2480     if [info exists et_vect_widen_sum_qi_to_hi_saved] {
2481         verbose "check_effective_target_vect_widen_sum_qi_to_hi: using cached result" 2
2482     } else {
2483         set et_vect_widen_sum_qi_to_hi_saved 0
2484         if { [check_effective_target_vect_unpack] 
2485              || [istarget ia64-*-*] } {
2486             set et_vect_widen_sum_qi_to_hi_saved 1
2487         }
2488     }
2489     verbose "check_effective_target_vect_widen_sum_qi_to_hi: returning $et_vect_widen_sum_qi_to_hi_saved" 2
2490     return $et_vect_widen_sum_qi_to_hi_saved
2491 }
2492
2493 # Return 1 if the target plus current options supports a vector
2494 # widening summation of *char* args into *int* result, 0 otherwise.
2495 #
2496 # This won't change for different subtargets so cache the result.
2497                                                                                                 
2498 proc check_effective_target_vect_widen_sum_qi_to_si { } {
2499     global et_vect_widen_sum_qi_to_si
2500
2501     if [info exists et_vect_widen_sum_qi_to_si_saved] {
2502         verbose "check_effective_target_vect_widen_sum_qi_to_si: using cached result" 2
2503     } else {
2504         set et_vect_widen_sum_qi_to_si_saved 0
2505         if { [istarget powerpc*-*-*] } {
2506             set et_vect_widen_sum_qi_to_si_saved 1
2507         }
2508     }
2509     verbose "check_effective_target_vect_widen_sum_qi_to_si: returning $et_vect_widen_sum_qi_to_si_saved" 2
2510     return $et_vect_widen_sum_qi_to_si_saved
2511 }
2512
2513 # Return 1 if the target plus current options supports a vector
2514 # widening multiplication of *char* args into *short* result, 0 otherwise.
2515 # A target can also support this widening multplication if it can support
2516 # promotion (unpacking) from chars to shorts, and vect_short_mult (non-widening
2517 # multiplication of shorts).
2518 #
2519 # This won't change for different subtargets so cache the result.
2520
2521
2522 proc check_effective_target_vect_widen_mult_qi_to_hi { } {
2523     global et_vect_widen_mult_qi_to_hi
2524
2525     if [info exists et_vect_widen_mult_qi_to_hi_saved] {
2526         verbose "check_effective_target_vect_widen_mult_qi_to_hi: using cached result" 2
2527     } else {
2528         if { [check_effective_target_vect_unpack]
2529              && [check_effective_target_vect_short_mult] } {
2530             set et_vect_widen_mult_qi_to_hi_saved 1
2531         } else {
2532             set et_vect_widen_mult_qi_to_hi_saved 0
2533         }
2534         if { [istarget powerpc*-*-*] } {
2535             set et_vect_widen_mult_qi_to_hi_saved 1
2536         }
2537     }
2538     verbose "check_effective_target_vect_widen_mult_qi_to_hi: returning $et_vect_widen_mult_qi_to_hi_saved" 2
2539     return $et_vect_widen_mult_qi_to_hi_saved
2540 }
2541
2542 # Return 1 if the target plus current options supports a vector
2543 # widening multiplication of *short* args into *int* result, 0 otherwise.
2544 # A target can also support this widening multplication if it can support
2545 # promotion (unpacking) from shorts to ints, and vect_int_mult (non-widening
2546 # multiplication of ints).
2547 #
2548 # This won't change for different subtargets so cache the result.
2549
2550
2551 proc check_effective_target_vect_widen_mult_hi_to_si { } {
2552     global et_vect_widen_mult_hi_to_si
2553
2554     if [info exists et_vect_widen_mult_hi_to_si_saved] {
2555         verbose "check_effective_target_vect_widen_mult_hi_to_si: using cached result" 2
2556     } else {
2557         if { [check_effective_target_vect_unpack]
2558              && [check_effective_target_vect_int_mult] } {
2559           set et_vect_widen_mult_hi_to_si_saved 1
2560         } else {
2561           set et_vect_widen_mult_hi_to_si_saved 0
2562         }
2563         if { [istarget powerpc*-*-*]
2564               || [istarget spu-*-*]
2565               || [istarget i?86-*-*]
2566               || [istarget x86_64-*-*] } {
2567             set et_vect_widen_mult_hi_to_si_saved 1
2568         }
2569     }
2570     verbose "check_effective_target_vect_widen_mult_hi_to_si: returning $et_vect_widen_mult_hi_to_si_saved" 2
2571     return $et_vect_widen_mult_hi_to_si_saved
2572 }
2573
2574 # Return 1 if the target plus current options supports a vector
2575 # dot-product of signed chars, 0 otherwise.
2576 #
2577 # This won't change for different subtargets so cache the result.
2578
2579 proc check_effective_target_vect_sdot_qi { } {
2580     global et_vect_sdot_qi
2581
2582     if [info exists et_vect_sdot_qi_saved] {
2583         verbose "check_effective_target_vect_sdot_qi: using cached result" 2
2584     } else {
2585         set et_vect_sdot_qi_saved 0
2586     }
2587     verbose "check_effective_target_vect_sdot_qi: returning $et_vect_sdot_qi_saved" 2
2588     return $et_vect_sdot_qi_saved
2589 }
2590
2591 # Return 1 if the target plus current options supports a vector
2592 # dot-product of unsigned chars, 0 otherwise.
2593 #
2594 # This won't change for different subtargets so cache the result.
2595
2596 proc check_effective_target_vect_udot_qi { } {
2597     global et_vect_udot_qi
2598
2599     if [info exists et_vect_udot_qi_saved] {
2600         verbose "check_effective_target_vect_udot_qi: using cached result" 2
2601     } else {
2602         set et_vect_udot_qi_saved 0
2603         if { [istarget powerpc*-*-*] } {
2604             set et_vect_udot_qi_saved 1
2605         }
2606     }
2607     verbose "check_effective_target_vect_udot_qi: returning $et_vect_udot_qi_saved" 2
2608     return $et_vect_udot_qi_saved
2609 }
2610
2611 # Return 1 if the target plus current options supports a vector
2612 # dot-product of signed shorts, 0 otherwise.
2613 #
2614 # This won't change for different subtargets so cache the result.
2615
2616 proc check_effective_target_vect_sdot_hi { } {
2617     global et_vect_sdot_hi
2618
2619     if [info exists et_vect_sdot_hi_saved] {
2620         verbose "check_effective_target_vect_sdot_hi: using cached result" 2
2621     } else {
2622         set et_vect_sdot_hi_saved 0
2623         if { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*])
2624              || [istarget i?86-*-*]
2625              || [istarget x86_64-*-*] } {
2626             set et_vect_sdot_hi_saved 1
2627         }
2628     }
2629     verbose "check_effective_target_vect_sdot_hi: returning $et_vect_sdot_hi_saved" 2
2630     return $et_vect_sdot_hi_saved
2631 }
2632
2633 # Return 1 if the target plus current options supports a vector
2634 # dot-product of unsigned shorts, 0 otherwise.
2635 #
2636 # This won't change for different subtargets so cache the result.
2637
2638 proc check_effective_target_vect_udot_hi { } {
2639     global et_vect_udot_hi
2640
2641     if [info exists et_vect_udot_hi_saved] {
2642         verbose "check_effective_target_vect_udot_hi: using cached result" 2
2643     } else {
2644         set et_vect_udot_hi_saved 0
2645         if { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*]) } {
2646             set et_vect_udot_hi_saved 1
2647         }
2648     }
2649     verbose "check_effective_target_vect_udot_hi: returning $et_vect_udot_hi_saved" 2
2650     return $et_vect_udot_hi_saved
2651 }
2652
2653
2654 # Return 1 if the target plus current options supports a vector
2655 # demotion (packing) of shorts (to chars) and ints (to shorts) 
2656 # using modulo arithmetic, 0 otherwise.
2657 #
2658 # This won't change for different subtargets so cache the result.
2659                                                                                 
2660 proc check_effective_target_vect_pack_trunc { } {
2661     global et_vect_pack_trunc
2662                                                                                 
2663     if [info exists et_vect_pack_trunc_saved] {
2664         verbose "check_effective_target_vect_pack_trunc: using cached result" 2
2665     } else {
2666         set et_vect_pack_trunc_saved 0
2667         if { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*])
2668              || [istarget i?86-*-*]
2669              || [istarget x86_64-*-*]
2670              || [istarget spu-*-*] } {
2671             set et_vect_pack_trunc_saved 1
2672         }
2673     }
2674     verbose "check_effective_target_vect_pack_trunc: returning $et_vect_pack_trunc_saved" 2
2675     return $et_vect_pack_trunc_saved
2676 }
2677
2678 # Return 1 if the target plus current options supports a vector
2679 # promotion (unpacking) of chars (to shorts) and shorts (to ints), 0 otherwise.
2680 #
2681 # This won't change for different subtargets so cache the result.
2682                                    
2683 proc check_effective_target_vect_unpack { } {
2684     global et_vect_unpack
2685                                         
2686     if [info exists et_vect_unpack_saved] {
2687         verbose "check_effective_target_vect_unpack: using cached result" 2
2688     } else {
2689         set et_vect_unpack_saved 0
2690         if { ([istarget powerpc*-*-*] && ![istarget powerpc-*paired*])
2691              || [istarget i?86-*-*]
2692              || [istarget x86_64-*-*] 
2693              || [istarget spu-*-*]
2694              || ([istarget arm*-*-*] && [check_effective_target_arm_neon]) } {
2695             set et_vect_unpack_saved 1
2696         }
2697     }
2698     verbose "check_effective_target_vect_unpack: returning $et_vect_unpack_saved" 2  
2699     return $et_vect_unpack_saved
2700 }
2701
2702 # Return 1 if the target plus current options does not guarantee
2703 # that its STACK_BOUNDARY is >= the reguired vector alignment.
2704 #
2705 # This won't change for different subtargets so cache the result.
2706
2707 proc check_effective_target_unaligned_stack { } {
2708     global et_unaligned_stack_saved
2709
2710     if [info exists et_unaligned_stack_saved] {
2711         verbose "check_effective_target_unaligned_stack: using cached result" 2
2712     } else {
2713         set et_unaligned_stack_saved 0
2714     }
2715     verbose "check_effective_target_unaligned_stack: returning $et_unaligned_stack_saved" 2
2716     return $et_unaligned_stack_saved
2717 }
2718
2719 # Return 1 if the target plus current options does not support a vector
2720 # alignment mechanism, 0 otherwise.
2721 #
2722 # This won't change for different subtargets so cache the result.
2723
2724 proc check_effective_target_vect_no_align { } {
2725     global et_vect_no_align_saved
2726
2727     if [info exists et_vect_no_align_saved] {
2728         verbose "check_effective_target_vect_no_align: using cached result" 2
2729     } else {
2730         set et_vect_no_align_saved 0
2731         if { [istarget mipsisa64*-*-*]
2732              || [istarget sparc*-*-*]
2733              || [istarget ia64-*-*]
2734              || [check_effective_target_arm32]
2735              || ([istarget mips*-*-*]
2736                  && [check_effective_target_mips_loongson]) } {
2737             set et_vect_no_align_saved 1
2738         }
2739     }
2740     verbose "check_effective_target_vect_no_align: returning $et_vect_no_align_saved" 2
2741     return $et_vect_no_align_saved
2742 }
2743
2744 # Return 1 if the target supports a vector misalign access, 0 otherwise.
2745 #
2746 # This won't change for different subtargets so cache the result.
2747
2748 proc check_effective_target_vect_hw_misalign { } {
2749     global et_vect_hw_misalign_saved
2750
2751     if [info exists et_vect_hw_misalign_saved] {
2752         verbose "check_effective_target_vect_hw_misalign: using cached result" 2
2753     } else {
2754         set et_vect_hw_misalign_saved 0
2755        if { ([istarget x86_64-*-*] 
2756             || [istarget i?86-*-*]) } {
2757           set et_vect_hw_misalign_saved 1
2758        }
2759     }
2760     verbose "check_effective_target_vect_hw_misalign: returning $et_vect_hw_misalign_saved" 2
2761     return $et_vect_hw_misalign_saved
2762 }
2763
2764
2765 # Return 1 if arrays are aligned to the vector alignment
2766 # boundary, 0 otherwise.
2767 #
2768 # This won't change for different subtargets so cache the result.
2769
2770 proc check_effective_target_vect_aligned_arrays { } {
2771     global et_vect_aligned_arrays
2772
2773     if [info exists et_vect_aligned_arrays_saved] {
2774         verbose "check_effective_target_vect_aligned_arrays: using cached result" 2
2775     } else {
2776         set et_vect_aligned_arrays_saved 0
2777         if { (([istarget x86_64-*-*]
2778               || [istarget i?86-*-*]) && [is-effective-target lp64])
2779               || [istarget spu-*-*] } {
2780             set et_vect_aligned_arrays_saved 1
2781         }
2782     }
2783     verbose "check_effective_target_vect_aligned_arrays: returning $et_vect_aligned_arrays_saved" 2
2784     return $et_vect_aligned_arrays_saved
2785 }
2786
2787 # Return 1 if types of size 32 bit or less are naturally aligned
2788 # (aligned to their type-size), 0 otherwise.
2789 #
2790 # This won't change for different subtargets so cache the result.
2791
2792 proc check_effective_target_natural_alignment_32 { } {
2793     global et_natural_alignment_32
2794
2795     if [info exists et_natural_alignment_32_saved] {
2796         verbose "check_effective_target_natural_alignment_32: using cached result" 2
2797     } else {
2798         # FIXME: 32bit powerpc: guaranteed only if MASK_ALIGN_NATURAL/POWER.
2799         set et_natural_alignment_32_saved 1
2800         if { ([istarget *-*-darwin*] && [is-effective-target lp64]) } {
2801             set et_natural_alignment_32_saved 0
2802         }
2803     }
2804     verbose "check_effective_target_natural_alignment_32: returning $et_natural_alignment_32_saved" 2
2805     return $et_natural_alignment_32_saved
2806 }
2807
2808 # Return 1 if types of size 64 bit or less are naturally aligned (aligned to their
2809 # type-size), 0 otherwise.
2810 #
2811 # This won't change for different subtargets so cache the result.
2812
2813 proc check_effective_target_natural_alignment_64 { } {
2814     global et_natural_alignment_64
2815
2816     if [info exists et_natural_alignment_64_saved] {
2817         verbose "check_effective_target_natural_alignment_64: using cached result" 2
2818     } else {
2819         set et_natural_alignment_64_saved 0
2820         if { ([is-effective-target lp64] && ![istarget *-*-darwin*])
2821              || [istarget spu-*-*] } {
2822             set et_natural_alignment_64_saved 1
2823         }
2824     }
2825     verbose "check_effective_target_natural_alignment_64: returning $et_natural_alignment_64_saved" 2
2826     return $et_natural_alignment_64_saved
2827 }
2828
2829 # Return 1 if vector alignment (for types of size 32 bit or less) is reachable, 0 otherwise.
2830 #
2831 # This won't change for different subtargets so cache the result.
2832
2833 proc check_effective_target_vector_alignment_reachable { } {
2834     global et_vector_alignment_reachable
2835
2836     if [info exists et_vector_alignment_reachable_saved] {
2837         verbose "check_effective_target_vector_alignment_reachable: using cached result" 2
2838     } else {
2839         if { [check_effective_target_vect_aligned_arrays]
2840              || [check_effective_target_natural_alignment_32] } {
2841             set et_vector_alignment_reachable_saved 1
2842         } else {
2843             set et_vector_alignment_reachable_saved 0
2844         }
2845     }
2846     verbose "check_effective_target_vector_alignment_reachable: returning $et_vector_alignment_reachable_saved" 2
2847     return $et_vector_alignment_reachable_saved
2848 }
2849
2850 # Return 1 if vector alignment for 64 bit is reachable, 0 otherwise.
2851 #
2852 # This won't change for different subtargets so cache the result.
2853
2854 proc check_effective_target_vector_alignment_reachable_for_64bit { } {
2855     global et_vector_alignment_reachable_for_64bit
2856
2857     if [info exists et_vector_alignment_reachable_for_64bit_saved] {
2858         verbose "check_effective_target_vector_alignment_reachable_for_64bit: using cached result" 2
2859     } else {
2860         if { [check_effective_target_vect_aligned_arrays] 
2861              || [check_effective_target_natural_alignment_64] } {
2862             set et_vector_alignment_reachable_for_64bit_saved 1
2863         } else {
2864             set et_vector_alignment_reachable_for_64bit_saved 0
2865         }
2866     }
2867     verbose "check_effective_target_vector_alignment_reachable_for_64bit: returning $et_vector_alignment_reachable_for_64bit_saved" 2
2868     return $et_vector_alignment_reachable_for_64bit_saved
2869 }
2870
2871 # Return 1 if the target supports vector conditional operations, 0 otherwise.
2872
2873 proc check_effective_target_vect_condition { } {
2874     global et_vect_cond_saved
2875
2876     if [info exists et_vect_cond_saved] {
2877         verbose "check_effective_target_vect_cond: using cached result" 2
2878     } else {
2879         set et_vect_cond_saved 0
2880         if { [istarget powerpc*-*-*]
2881              || [istarget ia64-*-*]
2882              || [istarget i?86-*-*]
2883              || [istarget spu-*-*]
2884              || [istarget x86_64-*-*] } {
2885            set et_vect_cond_saved 1
2886         }
2887     }
2888
2889     verbose "check_effective_target_vect_cond: returning $et_vect_cond_saved" 2
2890     return $et_vect_cond_saved
2891 }
2892
2893 # Return 1 if the target supports vector char multiplication, 0 otherwise.
2894
2895 proc check_effective_target_vect_char_mult { } {
2896     global et_vect_char_mult_saved
2897
2898     if [info exists et_vect_char_mult_saved] {
2899         verbose "check_effective_target_vect_char_mult: using cached result" 2
2900     } else {
2901         set et_vect_char_mult_saved 0
2902         if { [istarget ia64-*-*]
2903              || [istarget i?86-*-*]
2904              || [istarget x86_64-*-*] } {
2905            set et_vect_char_mult_saved 1
2906         }
2907     }
2908
2909     verbose "check_effective_target_vect_char_mult: returning $et_vect_char_mult_saved" 2
2910     return $et_vect_char_mult_saved
2911 }
2912
2913 # Return 1 if the target supports vector short multiplication, 0 otherwise.
2914
2915 proc check_effective_target_vect_short_mult { } {
2916     global et_vect_short_mult_saved
2917
2918     if [info exists et_vect_short_mult_saved] {
2919         verbose "check_effective_target_vect_short_mult: using cached result" 2
2920     } else {
2921         set et_vect_short_mult_saved 0
2922         if { [istarget ia64-*-*]
2923              || [istarget spu-*-*]
2924              || [istarget i?86-*-*]
2925              || [istarget x86_64-*-*]
2926              || [istarget powerpc*-*-*]
2927              || [check_effective_target_arm32]
2928              || ([istarget mips*-*-*]
2929                  && [check_effective_target_mips_loongson]) } {
2930            set et_vect_short_mult_saved 1
2931         }
2932     }
2933
2934     verbose "check_effective_target_vect_short_mult: returning $et_vect_short_mult_saved" 2
2935     return $et_vect_short_mult_saved
2936 }
2937
2938 # Return 1 if the target supports vector int multiplication, 0 otherwise.
2939
2940 proc check_effective_target_vect_int_mult { } {
2941     global et_vect_int_mult_saved
2942
2943     if [info exists et_vect_int_mult_saved] {
2944         verbose "check_effective_target_vect_int_mult: using cached result" 2
2945     } else {
2946         set et_vect_int_mult_saved 0
2947         if { ([istarget powerpc*-*-*] && ![istarget powerpc-*-linux*paired*])
2948              || [istarget spu-*-*]
2949              || [istarget i?86-*-*]
2950              || [istarget x86_64-*-*]
2951              || [check_effective_target_arm32] } {
2952            set et_vect_int_mult_saved 1
2953         }
2954     }
2955
2956     verbose "check_effective_target_vect_int_mult: returning $et_vect_int_mult_saved" 2
2957     return $et_vect_int_mult_saved
2958 }
2959
2960 # Return 1 if the target supports vector even/odd elements extraction, 0 otherwise.
2961
2962 proc check_effective_target_vect_extract_even_odd { } {
2963     global et_vect_extract_even_odd_saved
2964     
2965     if [info exists et_vect_extract_even_odd_saved] {
2966         verbose "check_effective_target_vect_extract_even_odd: using cached result" 2
2967     } else {
2968         set et_vect_extract_even_odd_saved 0 
2969         if { [istarget powerpc*-*-*] 
2970              || [istarget i?86-*-*]
2971              || [istarget x86_64-*-*]
2972              || [istarget spu-*-*] } {
2973            set et_vect_extract_even_odd_saved 1
2974         }
2975     }
2976
2977     verbose "check_effective_target_vect_extract_even_odd: returning $et_vect_extract_even_odd_saved" 2
2978     return $et_vect_extract_even_odd_saved
2979 }
2980
2981 # Return 1 if the target supports vector even/odd elements extraction of
2982 # vectors with SImode elements or larger, 0 otherwise.
2983
2984 proc check_effective_target_vect_extract_even_odd_wide { } {
2985     global et_vect_extract_even_odd_wide_saved
2986     
2987     if [info exists et_vect_extract_even_odd_wide_saved] {
2988         verbose "check_effective_target_vect_extract_even_odd_wide: using cached result" 2
2989     } else {
2990         set et_vect_extract_even_odd_wide_saved 0 
2991         if { [istarget powerpc*-*-*] 
2992              || [istarget i?86-*-*]
2993              || [istarget x86_64-*-*]
2994              || [istarget spu-*-*] } {
2995            set et_vect_extract_even_odd_wide_saved 1
2996         }
2997     }
2998
2999     verbose "check_effective_target_vect_extract_even_wide_odd: returning $et_vect_extract_even_odd_wide_saved" 2
3000     return $et_vect_extract_even_odd_wide_saved
3001 }
3002
3003 # Return 1 if the target supports vector interleaving, 0 otherwise.
3004
3005 proc check_effective_target_vect_interleave { } {
3006     global et_vect_interleave_saved
3007     
3008     if [info exists et_vect_interleave_saved] {
3009         verbose "check_effective_target_vect_interleave: using cached result" 2
3010     } else {
3011         set et_vect_interleave_saved 0
3012         if { [istarget powerpc*-*-*]
3013              || [istarget i?86-*-*]
3014              || [istarget x86_64-*-*]
3015              || [istarget spu-*-*] } {
3016            set et_vect_interleave_saved 1
3017         }
3018     }
3019
3020     verbose "check_effective_target_vect_interleave: returning $et_vect_interleave_saved" 2
3021     return $et_vect_interleave_saved
3022 }
3023
3024 # Return 1 if the target supports vector interleaving and extract even/odd, 0 otherwise.
3025 proc check_effective_target_vect_strided { } {
3026     global et_vect_strided_saved
3027
3028     if [info exists et_vect_strided_saved] {
3029         verbose "check_effective_target_vect_strided: using cached result" 2
3030     } else {
3031         set et_vect_strided_saved 0
3032         if { [check_effective_target_vect_interleave]
3033              && [check_effective_target_vect_extract_even_odd] } {
3034            set et_vect_strided_saved 1
3035         }
3036     }
3037
3038     verbose "check_effective_target_vect_strided: returning $et_vect_strided_saved" 2
3039     return $et_vect_strided_saved
3040 }
3041
3042 # Return 1 if the target supports vector interleaving and extract even/odd
3043 # for wide element types, 0 otherwise.
3044 proc check_effective_target_vect_strided_wide { } {
3045     global et_vect_strided_wide_saved
3046
3047     if [info exists et_vect_strided_wide_saved] {
3048         verbose "check_effective_target_vect_strided_wide: using cached result" 2
3049     } else {
3050         set et_vect_strided_wide_saved 0
3051         if { [check_effective_target_vect_interleave]
3052              && [check_effective_target_vect_extract_even_odd_wide] } {
3053            set et_vect_strided_wide_saved 1
3054         }
3055     }
3056
3057     verbose "check_effective_target_vect_strided_wide: returning $et_vect_strided_wide_saved" 2
3058     return $et_vect_strided_wide_saved
3059 }
3060
3061 # Return 1 if the target supports section-anchors
3062
3063 proc check_effective_target_section_anchors { } {
3064     global et_section_anchors_saved
3065
3066     if [info exists et_section_anchors_saved] {
3067         verbose "check_effective_target_section_anchors: using cached result" 2
3068     } else {
3069         set et_section_anchors_saved 0
3070         if { [istarget powerpc*-*-*]
3071               || [istarget arm*-*-*] } {
3072            set et_section_anchors_saved 1
3073         }
3074     }
3075
3076     verbose "check_effective_target_section_anchors: returning $et_section_anchors_saved" 2
3077     return $et_section_anchors_saved
3078 }
3079
3080 # Return 1 if the target supports atomic operations on "int" and "long".
3081
3082 proc check_effective_target_sync_int_long { } {
3083     global et_sync_int_long_saved
3084
3085     if [info exists et_sync_int_long_saved] {
3086         verbose "check_effective_target_sync_int_long: using cached result" 2
3087     } else {
3088         set et_sync_int_long_saved 0
3089 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
3090 # load-reserved/store-conditional instructions.
3091         if { [istarget ia64-*-*]
3092              || [istarget i?86-*-*]
3093              || [istarget x86_64-*-*]
3094              || [istarget alpha*-*-*] 
3095              || [istarget arm*-*-linux-gnueabi] 
3096              || [istarget bfin*-*linux*]
3097              || [istarget hppa*-*linux*]
3098              || [istarget s390*-*-*] 
3099              || [istarget powerpc*-*-*]
3100              || [istarget sparc64-*-*]
3101              || [istarget sparcv9-*-*]
3102              || [istarget mips*-*-*] } {
3103            set et_sync_int_long_saved 1
3104         }
3105     }
3106
3107     verbose "check_effective_target_sync_int_long: returning $et_sync_int_long_saved" 2
3108     return $et_sync_int_long_saved
3109 }
3110
3111 # Return 1 if the target supports atomic operations on "char" and "short".
3112
3113 proc check_effective_target_sync_char_short { } {
3114     global et_sync_char_short_saved
3115
3116     if [info exists et_sync_char_short_saved] {
3117         verbose "check_effective_target_sync_char_short: using cached result" 2
3118     } else {
3119         set et_sync_char_short_saved 0
3120 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
3121 # load-reserved/store-conditional instructions.
3122         if { [istarget ia64-*-*]
3123              || [istarget i?86-*-*]
3124              || [istarget x86_64-*-*]
3125              || [istarget alpha*-*-*] 
3126              || [istarget arm*-*-linux-gnueabi] 
3127              || [istarget hppa*-*linux*]
3128              || [istarget s390*-*-*] 
3129              || [istarget powerpc*-*-*]
3130              || [istarget sparc64-*-*]
3131              || [istarget sparcv9-*-*]
3132              || [istarget mips*-*-*] } {
3133            set et_sync_char_short_saved 1
3134         }
3135     }
3136
3137     verbose "check_effective_target_sync_char_short: returning $et_sync_char_short_saved" 2
3138     return $et_sync_char_short_saved
3139 }
3140
3141 # Return 1 if the target uses a ColdFire FPU.
3142
3143 proc check_effective_target_coldfire_fpu { } {
3144     return [check_no_compiler_messages coldfire_fpu assembly {
3145         #ifndef __mcffpu__
3146         #error FOO
3147         #endif
3148     }]
3149 }
3150
3151 # Return true if this is a uClibc target.
3152
3153 proc check_effective_target_uclibc {} {
3154     return [check_no_compiler_messages uclibc object {
3155         #include <features.h>
3156         #if !defined (__UCLIBC__)
3157         #error FOO
3158         #endif
3159     }]
3160 }
3161
3162 # Return true if this is a uclibc target and if the uclibc feature
3163 # described by __$feature__ is not present.
3164
3165 proc check_missing_uclibc_feature {feature} {
3166     return [check_no_compiler_messages $feature object "
3167         #include <features.h>
3168         #if !defined (__UCLIBC) || defined (__${feature}__)
3169         #error FOO
3170         #endif
3171     "]
3172 }
3173
3174 # Return true if this is a Newlib target.
3175
3176 proc check_effective_target_newlib {} {
3177     return [check_no_compiler_messages newlib object {
3178         #include <newlib.h>
3179     }]
3180 }
3181
3182 # Return 1 if
3183 #   (a) an error of a few ULP is expected in string to floating-point
3184 #       conversion functions; and
3185 #   (b) overflow is not always detected correctly by those functions.
3186
3187 proc check_effective_target_lax_strtofp {} {
3188     # By default, assume that all uClibc targets suffer from this.
3189     return [check_effective_target_uclibc]
3190 }
3191
3192 # Return 1 if this is a target for which wcsftime is a dummy
3193 # function that always returns 0.
3194
3195 proc check_effective_target_dummy_wcsftime {} {
3196     # By default, assume that all uClibc targets suffer from this.
3197     return [check_effective_target_uclibc]
3198 }
3199
3200 # Return 1 if constructors with initialization priority arguments are
3201 # supposed on this target.
3202
3203 proc check_effective_target_init_priority {} {
3204     return [check_no_compiler_messages init_priority assembly "
3205         void f() __attribute__((constructor (1000)));
3206         void f() \{\}
3207     "]
3208 }
3209
3210 # Return 1 if the target matches the effective target 'arg', 0 otherwise.
3211 # This can be used with any check_* proc that takes no argument and
3212 # returns only 1 or 0.  It could be used with check_* procs that take
3213 # arguments with keywords that pass particular arguments.
3214
3215 proc is-effective-target { arg } {
3216     set selected 0
3217     if { [info procs check_effective_target_${arg}] != [list] } {
3218         set selected [check_effective_target_${arg}]
3219     } else {
3220         switch $arg {
3221           "vmx_hw"         { set selected [check_vmx_hw_available] }
3222           "vsx_hw"         { set selected [check_vsx_hw_available] }
3223           "ppc_recip_hw"   { set selected [check_ppc_recip_hw_available] }
3224           "named_sections" { set selected [check_named_sections_available] }
3225           "gc_sections"    { set selected [check_gc_sections_available] }
3226           "cxa_atexit"     { set selected [check_cxa_atexit_available] }
3227           default          { error "unknown effective target keyword `$arg'" }
3228         }
3229     }
3230     verbose "is-effective-target: $arg $selected" 2
3231     return $selected
3232 }
3233
3234 # Return 1 if the argument is an effective-target keyword, 0 otherwise.
3235
3236 proc is-effective-target-keyword { arg } {
3237     if { [info procs check_effective_target_${arg}] != [list] } {
3238         return 1
3239     } else {
3240         # These have different names for their check_* procs.
3241         switch $arg {
3242           "vmx_hw"         { return 1 }
3243           "vsx_hw"         { return 1 }
3244           "ppc_recip_hw"   { return 1 }
3245           "named_sections" { return 1 }
3246           "gc_sections"    { return 1 }
3247           "cxa_atexit"     { return 1 }
3248           default          { return 0 }
3249         }
3250     }
3251 }
3252
3253 # Return 1 if target default to short enums
3254
3255 proc check_effective_target_short_enums { } {
3256     return [check_no_compiler_messages short_enums assembly {
3257         enum foo { bar };
3258         int s[sizeof (enum foo) == 1 ? 1 : -1];
3259     }]
3260 }
3261
3262 # Return 1 if target supports merging string constants at link time.
3263
3264 proc check_effective_target_string_merging { } {
3265     return [check_no_messages_and_pattern string_merging \
3266                 "rodata\\.str" assembly {
3267                     const char *var = "String";
3268                 } {-O2}]
3269 }
3270
3271 # Return 1 if target has the basic signed and unsigned types in
3272 # <stdint.h>, 0 otherwise.  This will be obsolete when GCC ensures a
3273 # working <stdint.h> for all targets.
3274
3275 proc check_effective_target_stdint_types { } {
3276     return [check_no_compiler_messages stdint_types assembly {
3277         #include <stdint.h>
3278         int8_t a; int16_t b; int32_t c; int64_t d;
3279         uint8_t e; uint16_t f; uint32_t g; uint64_t h;
3280     }]
3281 }
3282
3283 # Return 1 if target has the basic signed and unsigned types in
3284 # <inttypes.h>, 0 otherwise.  This is for tests that GCC's notions of
3285 # these types agree with those in the header, as some systems have
3286 # only <inttypes.h>.
3287
3288 proc check_effective_target_inttypes_types { } {
3289     return [check_no_compiler_messages inttypes_types assembly {
3290         #include <inttypes.h>
3291         int8_t a; int16_t b; int32_t c; int64_t d;
3292         uint8_t e; uint16_t f; uint32_t g; uint64_t h;
3293     }]
3294 }
3295
3296 # Return 1 if programs are intended to be run on a simulator
3297 # (i.e. slowly) rather than hardware (i.e. fast).
3298
3299 proc check_effective_target_simulator { } {
3300
3301     # All "src/sim" simulators set this one.
3302     if [board_info target exists is_simulator] {
3303         return [board_info target is_simulator]
3304     }
3305
3306     # The "sid" simulators don't set that one, but at least they set
3307     # this one.
3308     if [board_info target exists slow_simulator] {
3309         return [board_info target slow_simulator]
3310     }
3311
3312     return 0
3313 }
3314
3315 # Return 1 if the target is a VxWorks kernel.
3316
3317 proc check_effective_target_vxworks_kernel { } {
3318     return [check_no_compiler_messages vxworks_kernel assembly {
3319         #if !defined __vxworks || defined __RTP__
3320         #error NO
3321         #endif
3322     }]
3323 }
3324
3325 # Return 1 if the target is a VxWorks RTP.
3326
3327 proc check_effective_target_vxworks_rtp { } {
3328     return [check_no_compiler_messages vxworks_rtp assembly {
3329         #if !defined __vxworks || !defined __RTP__
3330         #error NO
3331         #endif
3332     }]
3333 }
3334
3335 # Return 1 if the target is expected to provide wide character support.
3336
3337 proc check_effective_target_wchar { } {
3338     if {[check_missing_uclibc_feature UCLIBC_HAS_WCHAR]} {
3339         return 0
3340     }
3341     return [check_no_compiler_messages wchar assembly {
3342         #include <wchar.h>
3343     }]
3344 }
3345
3346 # Return 1 if the target has <pthread.h>.
3347
3348 proc check_effective_target_pthread_h { } {
3349     return [check_no_compiler_messages pthread_h assembly {
3350         #include <pthread.h>
3351     }]
3352 }
3353
3354 # Return 1 if the target can truncate a file from a file-descriptor,
3355 # as used by libgfortran/io/unix.c:fd_truncate; i.e. ftruncate or
3356 # chsize.  We test for a trivially functional truncation; no stubs.
3357 # As libgfortran uses _FILE_OFFSET_BITS 64, we do too; it'll cause a
3358 # different function to be used.
3359
3360 proc check_effective_target_fd_truncate { } {
3361     set prog {
3362         #define _FILE_OFFSET_BITS 64
3363         #include <unistd.h>
3364         #include <stdio.h>
3365         #include <stdlib.h>
3366         int main ()
3367         {
3368           FILE *f = fopen ("tst.tmp", "wb");
3369           int fd;
3370           const char t[] = "test writing more than ten characters";
3371           char s[11];
3372           fd =  fileno (f);
3373           write (fd, t, sizeof (t) - 1);
3374           lseek (fd, 0, 0);
3375           if (ftruncate (fd, 10) != 0)
3376             exit (1);
3377           close (fd);
3378           f = fopen ("tst.tmp", "rb");
3379           if (fread (s, 1, sizeof (s), f) != 10 || strncmp (s, t, 10) != 0)
3380             exit (1);
3381           exit (0);
3382         }
3383     }
3384
3385     if { [check_runtime ftruncate $prog] } {
3386       return 1;
3387     }
3388
3389     regsub "ftruncate" $prog "chsize" prog
3390     return [check_runtime chsize $prog]
3391 }
3392
3393 # Add to FLAGS all the target-specific flags needed to access the c99 runtime.
3394
3395 proc add_options_for_c99_runtime { flags } {
3396     if { [istarget *-*-solaris2*] } {
3397         return "$flags -std=c99"
3398     }
3399     if { [istarget powerpc-*-darwin*] } {
3400         return "$flags -mmacosx-version-min=10.3"
3401     }
3402     return $flags
3403 }
3404
3405 # Add to FLAGS all the target-specific flags needed to enable
3406 # full IEEE compliance mode.
3407
3408 proc add_options_for_ieee { flags } {
3409     if { [istarget "alpha*-*-*"]
3410          || [istarget "sh*-*-*"] } {
3411        return "$flags -mieee"
3412     }
3413     return $flags
3414 }
3415
3416 # Add to FLAGS the flags needed to enable functions to bind locally
3417 # when using pic/PIC passes in the testsuite.
3418
3419 proc add_options_for_bind_pic_locally { flags } {
3420     if {[check_no_compiler_messages using_pic2 assembly {
3421         #if __PIC__ != 2
3422         #error FOO
3423         #endif
3424     }]} {
3425         return "$flags -fPIE"
3426     }
3427     if {[check_no_compiler_messages using_pic1 assembly {
3428         #if __PIC__ != 1
3429         #error FOO
3430         #endif
3431     }]} {
3432         return "$flags -fpie"
3433     }
3434
3435     return $flags
3436 }
3437
3438 # Return 1 if the target provides a full C99 runtime.
3439
3440 proc check_effective_target_c99_runtime { } {
3441     return [check_cached_effective_target c99_runtime {
3442         global srcdir
3443
3444         set file [open "$srcdir/gcc.dg/builtins-config.h"]
3445         set contents [read $file]
3446         close $file
3447         append contents {
3448             #ifndef HAVE_C99_RUNTIME
3449             #error FOO
3450             #endif
3451         }
3452         check_no_compiler_messages_nocache c99_runtime assembly \
3453             $contents [add_options_for_c99_runtime ""]
3454     }]
3455 }
3456
3457 # Return 1 if  target wchar_t is at least 4 bytes.
3458
3459 proc check_effective_target_4byte_wchar_t { } {
3460     return [check_no_compiler_messages 4byte_wchar_t object {
3461         int dummy[sizeof (__WCHAR_TYPE__) >= 4 ? 1 : -1];
3462     }]
3463 }
3464
3465 # Return 1 if the target supports automatic stack alignment.
3466
3467 proc check_effective_target_automatic_stack_alignment  { } {
3468     if { [istarget i?86*-*-*]
3469          || [istarget x86_64-*-*] } then {
3470         return 1
3471     } else {
3472         return 0
3473     }
3474 }
3475
3476 # Return 1 if avx instructions can be compiled.
3477
3478 proc check_effective_target_avx { } {
3479     return [check_no_compiler_messages avx object {
3480         void _mm256_zeroall (void)
3481         {
3482            __builtin_ia32_vzeroall ();
3483         }
3484     } "-O2 -mavx" ]
3485 }
3486
3487 # Return 1 if sse instructions can be compiled.
3488 proc check_effective_target_sse { } {
3489     return [check_no_compiler_messages sse object {
3490         int main ()
3491         {
3492             __builtin_ia32_stmxcsr ();
3493             return 0;
3494         }
3495     } "-O2 -msse" ]
3496 }
3497
3498 # Return 1 if sse2 instructions can be compiled.
3499 proc check_effective_target_sse2 { } {
3500     return [check_no_compiler_messages sse2 object {
3501         typedef long long __m128i __attribute__ ((__vector_size__ (16)));
3502         
3503         __m128i _mm_srli_si128 (__m128i __A, int __N)
3504         {
3505             return (__m128i)__builtin_ia32_psrldqi128 (__A, 8);
3506         }
3507     } "-O2 -msse2" ]
3508 }
3509
3510 # Return 1 if F16C instructions can be compiled.
3511
3512 proc check_effective_target_f16c { } {
3513     return [check_no_compiler_messages f16c object {
3514         #include "immintrin.h"
3515         float
3516         foo (unsigned short val)
3517         {
3518           return _cvtsh_ss (val);
3519         }
3520     } "-O2 -mf16c" ]
3521 }
3522
3523 # Return 1 if C wchar_t type is compatible with char16_t.
3524
3525 proc check_effective_target_wchar_t_char16_t_compatible { } {
3526     return [check_no_compiler_messages wchar_t_char16_t object {
3527         __WCHAR_TYPE__ wc;
3528         __CHAR16_TYPE__ *p16 = &wc;
3529         char t[(((__CHAR16_TYPE__) -1) < 0 == ((__WCHAR_TYPE__) -1) < 0) ? 1 : -1];
3530     }]
3531 }
3532
3533 # Return 1 if C wchar_t type is compatible with char32_t.
3534
3535 proc check_effective_target_wchar_t_char32_t_compatible { } {
3536     return [check_no_compiler_messages wchar_t_char32_t object {
3537         __WCHAR_TYPE__ wc;
3538         __CHAR32_TYPE__ *p32 = &wc;
3539         char t[(((__CHAR32_TYPE__) -1) < 0 == ((__WCHAR_TYPE__) -1) < 0) ? 1 : -1];
3540     }]
3541 }
3542
3543 # Return 1 if pow10 function exists.
3544
3545 proc check_effective_target_pow10 { } {
3546     return [check_runtime pow10 {
3547         #include <math.h>
3548         int main () {
3549         double x;
3550         x = pow10 (1);
3551         return 0;
3552         }
3553     } "-lm" ]
3554 }
3555
3556 # Return 1 if current options generate DFP instructions, 0 otherwise.
3557
3558 proc check_effective_target_hard_dfp {} {
3559     return [check_no_messages_and_pattern hard_dfp "!adddd3" assembly {
3560         typedef float d64 __attribute__((mode(DD)));
3561         d64 x, y, z;
3562         void foo (void) { z = x + y; }
3563     }]
3564 }
3565
3566 # Return 1 if string.h and wchar.h headers provide C++ requires overloads
3567 # for strchr etc. functions.
3568
3569 proc check_effective_target_correct_iso_cpp_string_wchar_protos { } {
3570     return [check_no_compiler_messages correct_iso_cpp_string_wchar_protos assembly {
3571         #include <string.h>
3572         #include <wchar.h>
3573         #if !defined(__cplusplus) \
3574             || !defined(__CORRECT_ISO_CPP_STRING_H_PROTO) \
3575             || !defined(__CORRECT_ISO_CPP_WCHAR_H_PROTO)
3576         ISO C++ correct string.h and wchar.h protos not supported.
3577         #else
3578         int i;
3579         #endif
3580     }]
3581 }
3582
3583 # Return 1 if GNU as is used.
3584
3585 proc check_effective_target_gas { } {
3586     global use_gas_saved
3587     global tool
3588
3589     if {![info exists use_gas_saved]} {
3590         # Check if the as used by gcc is GNU as.
3591         set gcc_as [lindex [${tool}_target_compile "-print-prog-name=as" "" "none" ""] 0]
3592         # Provide /dev/null as input, otherwise gas times out reading from
3593         # stdin.
3594         set status [remote_exec host "$gcc_as" "-v /dev/null"]
3595         set as_output [lindex $status 1]
3596         if { [ string first "GNU" $as_output ] >= 0 } {
3597             set use_gas_saved 1
3598         } else {
3599             set use_gas_saved 0
3600         }
3601     }
3602     return $use_gas_saved
3603 }
3604
3605 # Return 1 if the compiler has been configure with link-time optimization
3606 # (LTO) support.
3607
3608 proc check_effective_target_lto { } {
3609     global ENABLE_LTO
3610     return [info exists ENABLE_LTO]
3611 }
3612
3613 # Return 1 if the language for the compiler under test is C.
3614
3615 proc check_effective_target_c { } {
3616  global tool
3617     if [string match $tool "gcc"] {
3618    return 1
3619     }
3620  return 0
3621 }
3622
3623 # Return 1 if the language for the compiler under test is C++.
3624
3625 proc check_effective_target_c++ { } {
3626  global tool
3627     if [string match $tool "g++"] {
3628    return 1
3629     }
3630  return 0
3631 }
3632
3633 # Return 1 if expensive testcases should be run.
3634
3635 proc check_effective_target_run_expensive_tests { } {
3636     if { [getenv GCC_TEST_RUN_EXPENSIVE] != "" } {
3637         return 1
3638     }
3639     return 0
3640 }