OSDN Git Service

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