OSDN Git Service

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