OSDN Git Service

Fix $prop argument in last delta.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / target-supports.exp
1 #   Copyright (C) 1999, 2001, 2003, 2004, 2005, 2006
2 #   Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 # Please email any bugs, comments, and/or additions to this file to:
19 # gcc-patches@gcc.gnu.org
20
21 # This file defines procs for determining features supported by the target.
22
23 # Try to compile some code and return the messages printed by the compiler.
24 #
25 # BASENAME is a basename to use for temporary files.
26 # TYPE is the type of compilation to perform (see target_compile).
27 # CONTENTS gives the contents of the input file.
28 # The rest is optional:
29 # OPTIONS: additional compiler options to use.
30 proc get_compiler_messages {basename type contents args} {
31     global tool
32
33     if { [llength $args] > 0 } {
34         set options "additional_flags=[lindex $args 0]"
35     } else {
36         set options ""
37     }
38
39     set src ${basename}[pid].c
40     switch $type {
41         assembly { set output ${basename}[pid].s }
42         object { set output ${basename}[pid].o }
43     }
44     set f [open $src "w"]
45     puts $f $contents
46     close $f
47     set lines [${tool}_target_compile $src $output $type "$options"]
48     file delete $src
49     remote_file build delete $output
50
51     return $lines
52 }
53
54 proc current_target_name { } {
55     global target_info
56     if [info exists target_info(target,name)] {
57         set answer $target_info(target,name)
58     } else {
59         set answer ""
60     }
61     return $answer
62 }
63
64 # Implement an effective-target check for property PROP by invoking
65 # the compiler and seeing if it prints any messages.  Assume that the
66 # property holds if the compiler doesn't print anything.  The other
67 # arguments are as for get_compiler_messages, starting with TYPE.
68 proc check_no_compiler_messages {prop args} {
69     global et_cache
70
71     set target [current_target_name]
72     if {![info exists et_cache($prop,target)]
73         || $et_cache($prop,target) != $target} {
74         verbose "check_effective_target $prop: compiling source for $target" 2
75         set et_cache($prop,target) $target
76         set et_cache($prop,value) \
77             [string match "" [eval get_compiler_messages $prop $args]]
78     }
79     set value $et_cache($prop,value)
80     verbose "check_effective_target $prop: returning $value for $target" 2
81     return $value
82 }
83
84 ###############################
85 # proc check_weak_available { }
86 ###############################
87
88 # weak symbols are only supported in some configs/object formats
89 # this proc returns 1 if they're supported, 0 if they're not, or -1 if unsure
90
91 proc check_weak_available { } {
92     global target_triplet
93     global target_cpu
94
95     # All mips targets should support it
96
97     if { [ string first "mips" $target_cpu ] >= 0 } {
98         return 1
99     }
100
101     # All solaris2 targets should support it
102
103     if { [regexp ".*-solaris2.*" $target_triplet] } {
104         return 1
105     }
106
107     # DEC OSF/1/Digital UNIX/Tru64 UNIX supports it
108
109     if { [regexp "alpha.*osf.*" $target_triplet] } {
110         return 1
111     }
112
113     # Windows targets Cygwin and MingW32 support it
114
115     if { [regexp ".*mingw32|.*cygwin" $target_triplet] } {
116         return 1
117     }
118
119     # HP-UX 10.X doesn't support it
120
121     if { [regexp "hppa.*hpux10" $target_triplet] } {
122         return 0
123     }
124
125     # ELF and ECOFF support it. a.out does with gas/gld but may also with
126     # other linkers, so we should try it
127
128     set objformat [gcc_target_object_format]
129
130     switch $objformat {
131         elf      { return 1 }
132         ecoff    { return 1 }
133         a.out    { return 1 }
134         mach-o   { return 1 }
135         som      { return 1 }
136         unknown  { return -1 }
137         default  { return 0 }
138     }
139 }
140
141 ###############################
142 # proc check_visibility_available { what_kind }
143 ###############################
144
145 # The visibility attribute is only support in some object formats
146 # This proc returns 1 if it is supported, 0 if not.
147 # The argument is the kind of visibility, default/protected/hidden/internal.
148
149 proc check_visibility_available { what_kind } {
150     global tool
151     global target_triplet
152
153     # On NetWare, support makes no sense.
154     if { [istarget *-*-netware*] } {
155         return 0
156     }
157
158     if [string match "" $what_kind] { set what_kind "hidden" }
159
160     return [check_no_compiler_messages visibility_available_$what_kind object "
161         void f() __attribute__((visibility(\"$what_kind\")));
162         void f() {}
163     "]
164 }
165
166 ###############################
167 # proc check_alias_available { }
168 ###############################
169
170 # Determine if the target toolchain supports the alias attribute.
171
172 # Returns 2 if the target supports aliases.  Returns 1 if the target
173 # only supports weak aliased.  Returns 0 if the target does not
174 # support aliases at all.  Returns -1 if support for aliases could not
175 # be determined.
176
177 proc check_alias_available { } {
178     global alias_available_saved
179     global tool
180
181     if [info exists alias_available_saved] {
182         verbose "check_alias_available  returning saved $alias_available_saved" 2
183     } else {
184         set src alias[pid].c
185         set obj alias[pid].o
186         verbose "check_alias_available  compiling testfile $src" 2
187         set f [open $src "w"]
188         # Compile a small test program.  The definition of "g" is
189         # necessary to keep the Solaris assembler from complaining
190         # about the program.
191         puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
192         puts $f "void g() {} void f() __attribute__((alias(\"g\")));"
193         close $f
194         set lines [${tool}_target_compile $src $obj object ""]
195         file delete $src
196         remote_file build delete $obj
197
198         if [string match "" $lines] then {
199             # No error messages, everything is OK.
200             set alias_available_saved 2
201         } else {
202             if [regexp "alias definitions not supported" $lines] {
203                 verbose "check_alias_available  target does not support aliases" 2
204
205                 set objformat [gcc_target_object_format]
206
207                 if { $objformat == "elf" } {
208                     verbose "check_alias_available  but target uses ELF format, so it ought to" 2
209                     set alias_available_saved -1
210                 } else {
211                     set alias_available_saved 0
212                 }
213             } else {
214                 if [regexp "only weak aliases are supported" $lines] {
215                 verbose "check_alias_available  target supports only weak aliases" 2
216                 set alias_available_saved 1
217                 } else {
218                     set alias_available_saved -1
219                 }
220             }
221         }
222
223         verbose "check_alias_available  returning $alias_available_saved" 2
224     }
225
226     return $alias_available_saved
227 }
228
229 # Returns true if --gc-sections is supported on the target.
230
231 proc check_gc_sections_available { } {
232     global gc_sections_available_saved
233     global tool
234
235     if {![info exists gc_sections_available_saved]} {
236         # Some targets don't support gc-sections despite whatever's
237         # advertised by ld's options.
238         if { [istarget alpha*-*-*]
239              || [istarget ia64-*-*] } {
240             set gc_sections_available_saved 0
241             return 0
242         }
243
244         # Check if the ld used by gcc supports --gc-sections.
245         set gcc_spec [${tool}_target_compile "-dumpspecs" "" "none" ""]
246         regsub ".*\n\*linker:\[ \t\]*\n(\[^ \t\n\]*).*" "$gcc_spec" {\1} linker
247         set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=$linker" "" "none" ""] 0]
248         set ld_output [remote_exec host "$gcc_ld" "--help"]
249         if { [ string first "--gc-sections" $ld_output ] >= 0 } {
250             set gc_sections_available_saved 1
251         } else {
252             set gc_sections_available_saved 0
253         }
254     }
255     return $gc_sections_available_saved
256 }
257
258 # Return true if profiling is supported on the target.
259
260 proc check_profiling_available { test_what } {
261     global profiling_available_saved
262
263     verbose "Profiling argument is <$test_what>" 1
264
265     # These conditions depend on the argument so examine them before
266     # looking at the cache variable.
267
268     # Support for -p on solaris2 relies on mcrt1.o which comes with the
269     # vendor compiler.  We cannot reliably predict the directory where the
270     # vendor compiler (and thus mcrt1.o) is installed so we can't
271     # necessarily find mcrt1.o even if we have it.
272     if { [istarget *-*-solaris2*] && [lindex $test_what 1] == "-p" } {
273         return 0
274     }
275
276     # Support for -p on irix relies on libprof1.a which doesn't appear to
277     # exist on any irix6 system currently posting testsuite results.
278     # Support for -pg on irix relies on gcrt1.o which doesn't exist yet.
279     # See: http://gcc.gnu.org/ml/gcc/2002-10/msg00169.html
280     if { [istarget mips*-*-irix*]
281     && ([lindex $test_what 1] == "-p" || [lindex $test_what 1] == "-pg") } {
282         return 0
283     }
284
285     # At present, there is no profiling support on NetWare.
286     if { [istarget *-*-netware*] } {
287         return 0
288     }
289
290     # Now examine the cache variable.
291     if {![info exists profiling_available_saved]} {
292         # Some targets don't have any implementation of __bb_init_func or are
293         # missing other needed machinery.
294         if { [istarget mmix-*-*]
295              || [istarget arm*-*-eabi*]
296              || [istarget arm*-*-elf]
297              || [istarget arm*-*-symbianelf*]
298              || [istarget powerpc-*-eabi*]
299              || [istarget strongarm*-*-elf]
300              || [istarget xscale*-*-elf]
301              || [istarget cris-*-*]
302              || [istarget h8300-*-*]
303              || [istarget m32c-*-elf]
304              || [istarget m68k-*-elf]
305              || [istarget mips*-*-elf]
306              || [istarget xtensa-*-elf]
307              || [istarget *-*-windiss] } {
308             set profiling_available_saved 0
309         } else {
310             set profiling_available_saved 1
311         }
312     }
313
314     return $profiling_available_saved
315 }
316
317 # Return 1 if target has packed layout of structure members by
318 # default, 0 otherwise.  Note that this is slightly different than
319 # whether the target has "natural alignment": both attributes may be
320 # false.
321
322 proc check_effective_target_default_packed { } {
323     return [check_no_compiler_messages default_packed assembly {
324         struct x { char a; long b; } c;
325         int s[sizeof (c) == sizeof (char) + sizeof (long) ? 1 : -1];
326     }]
327 }
328
329 # Return 1 if target has PCC_BITFIELD_TYPE_MATTERS defined.  See
330 # documentation, where the test also comes from.
331
332 proc check_effective_target_pcc_bitfield_type_matters { } {
333     # PCC_BITFIELD_TYPE_MATTERS isn't just about unnamed or empty
334     # bitfields, but let's stick to the example code from the docs.
335     return [check_no_compiler_messages pcc_bitfield_type_matters assembly {
336         struct foo1 { char x; char :0; char y; };
337         struct foo2 { char x; int :0; char y; };
338         int s[sizeof (struct foo1) != sizeof (struct foo2) ? 1 : -1];
339     }]
340 }
341
342 # Return 1 if thread local storage (TLS) is supported, 0 otherwise.
343 #
344 # This won't change for different subtargets so cache the result.
345
346 proc check_effective_target_tls {} {
347     global et_tls_saved
348
349     if [info exists et_tls_saved] {
350         verbose "check_effective_target_tls: using cached result" 2
351     } else {
352         set et_tls_saved 1
353
354         set src tls[pid].c
355         set asm tls[pid].S
356         verbose "check_effective_target_tls: compiling testfile $src" 2
357         set f [open $src "w"]
358         # Compile a small test program.
359         puts $f "__thread int i;\n"
360         close $f
361
362         # Test for thread-local data supported by the platform.
363         set comp_output \
364             [target_compile $src $asm assembly ""]
365         file delete $src
366         if { [string match "*not supported*" $comp_output] } {
367             set et_tls_saved 0
368         }
369         remove-build-file $asm
370     }
371     verbose "check_effective_target_tls: returning $et_tls_saved" 2
372     return $et_tls_saved
373 }
374
375 # Return 1 if TLS executables can run correctly, 0 otherwise.
376 #
377 # This won't change for different subtargets so cache the result.
378
379 proc check_effective_target_tls_runtime {} {
380     global et_tls_runtime_saved
381
382     if [info exists et_tls_runtime_saved] {
383         verbose "check_effective_target_tls_runtime: using cached result" 2
384     } else {
385         set et_tls_runtime_saved 0
386
387         set src tls_runtime[pid].c
388         set exe tls_runtime[pid].x
389         verbose "check_effective_target_tls_runtime: compiling testfile $src" 2
390         set f [open $src "w"]
391         # Compile a small test program.
392         puts $f "__thread int thr = 0;\n"
393         puts $f "int main(void)\n {\n return thr;\n}"
394         close $f
395
396         set comp_output \
397             [target_compile $src $exe executable ""]
398         file delete $src
399
400         if [string match "" $comp_output] then {
401             # No error messages, everything is OK.
402
403             set result [remote_load target "./$exe" "" ""]
404             set status [lindex $result 0]
405             remote_file build delete $exe
406
407             verbose "check_effective_target_tls_runtime status is <$status>" 2
408
409             if { $status == "pass" } {
410                 set et_tls_runtime_saved 1
411             }
412
413             verbose "check_effective_target_tls_runtime: returning $et_tls_runtime_saved" 2
414         }
415     }
416
417     return $et_tls_runtime_saved
418 }
419
420 # Return 1 if compilation with -fopenmp is error-free for trivial
421 # code, 0 otherwise.
422
423 proc check_effective_target_fopenmp {} {
424     return [check_no_compiler_messages fopenmp object {
425         void foo (void) { }
426     } "-fopenmp"]
427 }
428
429 # Return 1 if compilation with -freorder-blocks-and-partition is error-free
430 # for trivial code, 0 otherwise.
431
432 proc check_effective_target_freorder {} {
433     return [check_no_compiler_messages freorder object {
434         void foo (void) { }
435     } "-freorder-blocks-and-partition"]
436 }
437
438 # Return 1 if -fpic and -fPIC are supported, as in no warnings or errors
439 # emitted, 0 otherwise.  Whether a shared library can actually be built is
440 # out of scope for this test.
441
442 proc check_effective_target_fpic { } {
443     # Note that M68K has a multilib that supports -fpic but not
444     # -fPIC, so we need to check both.  We test with a program that
445     # requires GOT references.
446     foreach arg {fpic fPIC} {
447         if [check_no_compiler_messages $arg object {
448             extern int foo (void); extern int bar;
449             int baz (void) { return foo () + bar; }
450         } "-$arg"] {
451             return 1
452         }
453     }
454     return 0
455 }
456
457 # Return true if the target supports -mpaired-single (as used on MIPS).
458
459 proc check_effective_target_mpaired_single { } {
460     return [check_no_compiler_messages mpaired_single object {
461         void foo (void) { }
462     } "-mpaired-single"]
463 }
464
465 # Return true if iconv is supported on the target. In particular IBM1047.
466
467 proc check_iconv_available { test_what } {
468     global tool
469     global libiconv
470
471     set result ""
472
473     set src iconv[pid].c
474     set exe iconv[pid].x
475     verbose "check_iconv_available compiling testfile $src" 2
476     set f [open $src "w"]
477     # Compile a small test program.
478     puts $f "#include <iconv.h>\n"
479     puts $f "int main (void)\n {\n iconv_t cd; \n"
480     puts $f "cd = iconv_open (\"[lindex $test_what 1]\", \"UTF-8\");\n"
481     puts $f "if (cd == (iconv_t) -1)\n return 1;\n"
482     puts $f "return 0;\n}"
483     close $f
484
485     # If the tool configuration file has not set libiconv, try "-liconv"
486     if { ![info exists libiconv] } {
487         set libiconv "-liconv"
488     }
489     set lines [${tool}_target_compile $src $exe executable "libs=$libiconv" ]
490     file delete $src
491
492     if [string match "" $lines] then {
493         # No error messages, everything is OK.
494
495         set result [${tool}_load "./$exe" "" ""]
496         set status [lindex $result 0]
497         remote_file build delete $exe
498
499         verbose "check_iconv_available status is <$status>" 2
500
501         if { $status == "pass" } then {
502             return 1
503         }
504     }
505
506     return 0
507 }
508
509 # Return true if named sections are supported on this target.
510
511 proc check_named_sections_available { } {
512     return [check_no_compiler_messages named_sections assembly {
513         int __attribute__ ((section("whatever"))) foo;
514     }]
515 }
516
517 # Return 1 if the target supports Fortran real kinds larger than real(8),
518 # 0 otherwise.
519 #
520 # When the target name changes, replace the cached result.
521
522 proc check_effective_target_fortran_large_real { } {
523     global et_fortran_large_real_saved
524     global et_fortran_large_real_target_name
525     global tool
526
527     if { ![info exists et_fortran_large_real_target_name] } {
528         set et_fortran_large_real_target_name ""
529     }
530
531     # If the target has changed since we set the cached value, clear it.
532     set current_target [current_target_name]
533     if { $current_target != $et_fortran_large_real_target_name } {
534         verbose "check_effective_target_fortran_large_real: `$et_fortran_large_real_target_name' `$current_target'" 2
535         set et_fortran_large_real_target_name $current_target
536         if [info exists et_fortran_large_real_saved] {
537             verbose "check_effective_target_fortran_large_real: removing cached result" 2
538             unset et_fortran_large_real_saved
539         }
540     }
541
542     if [info exists et_fortran_large_real_saved] {
543         verbose "check_effective_target_fortran_large_real returning saved $et_fortran_large_real_saved" 2
544     } else {
545         set et_fortran_large_real_saved 0
546
547         # Set up, compile, and execute a test program using large real
548         # kinds.  Include the current process ID in the file names to
549         # prevent conflicts with invocations for multiple testsuites.
550         set src real[pid].f90
551         set exe real[pid].x
552
553         set f [open $src "w"]
554         puts $f "integer,parameter :: k = &"
555         puts $f "  selected_real_kind (precision (0.0_8) + 1)"
556         puts $f "real(kind=k) :: x"
557         puts $f "x = cos (x);"
558         puts $f "end"
559         close $f
560
561         verbose "check_effective_target_fortran_large_real compiling testfile $src" 2
562         set lines [${tool}_target_compile $src $exe executable ""]
563         file delete $src
564
565         if [string match "" $lines] then {
566             # No error message, compilation succeeded.
567             set et_fortran_large_real_saved 1
568         }
569     }
570
571     return $et_fortran_large_real_saved
572 }
573
574 # Return 1 if the target supports Fortran integer kinds larger than
575 # integer(8), 0 otherwise.
576 #
577 # When the target name changes, replace the cached result.
578
579 proc check_effective_target_fortran_large_int { } {
580     global et_fortran_large_int_saved
581     global et_fortran_large_int_target_name
582     global tool
583
584     if { ![info exists et_fortran_large_int_target_name] } {
585         set et_fortran_large_int_target_name ""
586     }
587
588     # If the target has changed since we set the cached value, clear it.
589     set current_target [current_target_name]
590     if { $current_target != $et_fortran_large_int_target_name } {
591         verbose "check_effective_target_fortran_large_int: `$et_fortran_large_int_target_name' `$current_target'" 2
592         set et_fortran_large_int_target_name $current_target
593         if [info exists et_fortran_large_int_saved] {
594             verbose "check_effective_target_fortran_large_int: removing cached result" 2
595             unset et_fortran_large_int_saved
596         }
597     }
598
599     if [info exists et_fortran_large_int_saved] {
600         verbose "check_effective_target_fortran_large_int returning saved $et_fortran_large_int_saved" 2
601     } else {
602         set et_fortran_large_int_saved 0
603
604         # Set up, compile, and execute a test program using large integer
605         # kinds.  Include the current process ID in the file names to
606         # prevent conflicts with invocations for multiple testsuites.
607         set src int[pid].f90
608         set exe int[pid].x
609
610         set f [open $src "w"]
611         puts $f "integer,parameter :: k = &"
612         puts $f "  selected_int_kind (range (0_8) + 1)"
613         puts $f "integer(kind=k) :: i"
614         puts $f "end"
615         close $f
616
617         verbose "check_effective_target_fortran_large_int compiling testfile $src" 2
618         set lines [${tool}_target_compile $src $exe executable ""]
619         file delete $src
620
621         if [string match "" $lines] then {
622             # No error message, compilation succeeded.
623             set et_fortran_large_int_saved 1
624         }
625     }
626
627     return $et_fortran_large_int_saved
628 }
629
630 # Return 1 if we can statically link libgfortran, 0 otherwise.
631 #
632 # When the target name changes, replace the cached result.
633
634 proc check_effective_target_static_libgfortran { } {
635     global et_static_libgfortran
636     global et_static_libgfortran_target_name
637     global tool
638
639     if { ![info exists et_static_libgfortran_target_name] } {
640        set et_static_libgfortran_target_name ""
641     }
642
643     # If the target has changed since we set the cached value, clear it.
644     set current_target [current_target_name]
645     if { $current_target != $et_static_libgfortran_target_name } {
646        verbose "check_effective_target_static_libgfortran: `$et_static_libgfortran_target_name' `$current_target'" 2
647        set et_static_libgfortran_target_name $current_target
648        if [info exists et_static_libgfortran_saved] {
649            verbose "check_effective_target_static_libgfortran: removing cached result" 2
650            unset et_static_libgfortran_saved
651        }
652     }
653
654     if [info exists et_static_libgfortran_saved] {
655        verbose "check_effective_target_static_libgfortran returning saved $et_static_libgfortran_saved" 2
656     } else {
657        set et_static_libgfortran_saved 0
658
659        # Set up, compile, and execute a test program using static linking.
660        # Include the current process ID in the file names to prevent
661        # conflicts with invocations for multiple testsuites.
662        set opts "additional_flags=-static"
663        set src static[pid].f
664        set exe static[pid].x
665
666        set f [open $src "w"]
667        puts $f "      print *, 'test'"
668        puts $f "      end"
669        close $f
670
671        verbose "check_effective_target_static_libgfortran compiling testfile $src" 2
672        set lines [${tool}_target_compile $src $exe executable "$opts"]
673        file delete $src
674
675        if [string match "" $lines] then {
676            # No error message, compilation succeeded.
677            set et_static_libgfortran_saved 1
678        }
679     }
680
681     return $et_static_libgfortran_saved
682 }
683
684 # Return 1 if the target supports executing AltiVec instructions, 0
685 # otherwise.  Cache the result.
686
687 proc check_vmx_hw_available { } {
688     global vmx_hw_available_saved
689     global tool
690
691     if [info exists vmx_hw_available_saved] {
692         verbose "check_hw_available  returning saved $vmx_hw_available_saved" 2
693     } else {
694         set vmx_hw_available_saved 0
695
696         # Some simulators are known to not support VMX instructions.
697         if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
698             verbose "check_hw_available  returning 0" 2
699             return $vmx_hw_available_saved
700         }
701
702         # Set up, compile, and execute a test program containing VMX
703         # instructions.  Include the current process ID in the file
704         # names to prevent conflicts with invocations for multiple
705         # testsuites.
706         set src vmx[pid].c
707         set exe vmx[pid].x
708
709         set f [open $src "w"]
710         puts $f "int main() {"
711         puts $f "#ifdef __MACH__"
712         puts $f "  asm volatile (\"vor v0,v0,v0\");"
713         puts $f "#else"
714         puts $f "  asm volatile (\"vor 0,0,0\");"
715         puts $f "#endif"
716         puts $f "  return 0; }"
717         close $f
718
719         # Most targets don't require special flags for this test case, but
720         # Darwin does.
721         if [istarget *-*-darwin*] {
722           set opts "additional_flags=-maltivec"
723         } else {
724           set opts ""
725         }
726
727         verbose "check_vmx_hw_available  compiling testfile $src" 2
728         set lines [${tool}_target_compile $src $exe executable "$opts"]
729         file delete $src
730
731         if [string match "" $lines] then {
732             # No error message, compilation succeeded.
733             set result [${tool}_load "./$exe" "" ""]
734             set status [lindex $result 0]
735             remote_file build delete $exe
736             verbose "check_vmx_hw_available testfile status is <$status>" 2
737
738             if { $status == "pass" } then {
739                 set vmx_hw_available_saved 1
740             }
741         } else {
742             verbose "check_vmx_hw_availalble testfile compilation failed" 2
743         }
744     }
745
746     return $vmx_hw_available_saved
747 }
748
749 # GCC 3.4.0 for powerpc64-*-linux* included an ABI fix for passing
750 # complex float arguments.  This affects gfortran tests that call cabsf
751 # in libm built by an earlier compiler.  Return 1 if libm uses the same
752 # argument passing as the compiler under test, 0 otherwise.
753 #
754 # When the target name changes, replace the cached result.
755
756 proc check_effective_target_broken_cplxf_arg { } {
757     global et_broken_cplxf_arg_saved
758     global et_broken_cplxf_arg_target_name
759     global tool
760
761     # Skip the work for targets known not to be affected.
762     if { ![istarget powerpc64-*-linux*] } {
763         return 0
764     } elseif { [is-effective-target ilp32] } {
765         return 0
766     }
767
768     if { ![info exists et_broken_cplxf_arg_target_name] } {
769         set et_broken_cplxf_arg_target_name ""
770     }
771
772     # If the target has changed since we set the cached value, clear it.
773     set current_target [current_target_name]
774     if { $current_target != $et_broken_cplxf_arg_target_name } {
775         verbose "check_effective_target_broken_cplxf_arg: `$et_broken_cplxf_arg_target_name'" 2
776         set et_broken_cplxf_arg_target_name $current_target
777         if [info exists et_broken_cplxf_arg_saved] {
778             verbose "check_effective_target_broken_cplxf_arg: removing cached result" 2
779             unset et_broken_cplxf_arg_saved
780         }
781     }
782
783     if [info exists et_broken_cplxf_arg_saved] {
784         verbose "check_effective_target_broken_cplxf_arg: using cached result" 2
785     } else {
786         set et_broken_cplxf_arg_saved 0
787         # This is only known to affect one target.
788         if { ![istarget powerpc64-*-linux*] || ![is-effective-target lp64] } {
789             set et_broken_cplxf_arg_saved 0
790             verbose "check_effective_target_broken_cplxf_arg: caching 0" 2
791             return $et_broken_cplxf_arg_saved
792         }
793
794         # Set up, compile, and execute a C test program that calls cabsf.
795         set src cabsf[pid].c
796         set exe cabsf[pid].x
797
798         set f [open $src "w"]
799         puts $f "#include <complex.h>"
800         puts $f "extern void abort (void);"
801         puts $f "float fabsf (float);"
802         puts $f "float cabsf (_Complex float);"
803         puts $f "int main ()"
804         puts $f "{"
805         puts $f "  _Complex float cf;"
806         puts $f "  float f;"
807         puts $f "  cf = 3 + 4.0fi;"
808         puts $f "  f = cabsf (cf);"
809         puts $f "  if (fabsf (f - 5.0) > 0.0001) abort ();"
810         puts $f "  return 0;"
811         puts $f "}"
812         close $f
813
814         set lines [${tool}_target_compile $src $exe executable "-lm"]
815         file delete $src
816
817         if [string match "" $lines] {
818             # No error message, compilation succeeded.
819             set result [${tool}_load "./$exe" "" ""]
820             set status [lindex $result 0]
821             remote_file build delete $exe
822
823             verbose "check_effective_target_broken_cplxf_arg: status is <$status>" 2
824
825             if { $status != "pass" } {
826                 set et_broken_cplxf_arg_saved 1
827             }
828         } else {
829             verbose "check_effective_target_broken_cplxf_arg: compilation failed" 2
830         }
831     }
832     return $et_broken_cplxf_arg_saved
833 }
834
835 proc check_alpha_max_hw_available { } {
836     global alpha_max_hw_available_saved
837     global tool
838
839     if [info exists alpha_max_hw_available_saved] {
840         verbose "check_alpha_max_hw_available returning saved $alpha_max_hw_available_saved" 2
841     } else {
842         set alpha_max_hw_available_saved 0
843
844         # Set up, compile, and execute a test program probing bit 8 of the
845         # architecture mask, which indicates presence of MAX instructions.
846         set src max[pid].c
847         set exe max[pid].x
848
849         set f [open $src "w"]
850         puts $f "int main() { return __builtin_alpha_amask(1<<8) != 0; }"
851         close $f
852
853         verbose "check_alpha_max_hw_available compiling testfile $src" 2
854         set lines [${tool}_target_compile $src $exe executable ""]
855         file delete $src
856
857         if [string match "" $lines] then {
858             # No error message, compilation succeeded.
859             set result [${tool}_load "./$exe" "" ""]
860             set status [lindex $result 0]
861             remote_file build delete $exe
862             verbose "check_alpha_max_hw_available testfile status is <$status>" 2
863
864             if { $status == "pass" } then {
865                 set alpha_max_hw_available_saved 1
866             }
867         } else {
868             verbose "check_alpha_max_hw_availalble testfile compilation failed" 2
869         }
870     }
871
872     return $alpha_max_hw_available_saved
873 }
874
875 # Returns true iff the FUNCTION is available on the target system.
876 # (This is essentially a Tcl implementation of Autoconf's
877 # AC_CHECK_FUNC.)
878
879 proc check_function_available { function } {
880     set var "${function}_available_saved"
881     global $var
882     global tool
883
884     if {![info exists $var]} {
885         # Assume it exists.
886         set $var 1
887         # Check to make sure.
888         set src "function[pid].c"
889         set exe "function[pid].exe"
890
891         set f [open $src "w"]
892         puts $f "int main () { $function (); }"
893         close $f
894
895         set lines [${tool}_target_compile $src $exe executable ""]
896         file delete $src
897         file delete $exe
898
899         if {![string match "" $lines]} then {
900             set $var 0
901             verbose -log "$function is not available"
902         } else {
903             verbose -log "$function is available"
904         }
905     }
906
907     eval return \$$var
908 }
909
910 # Returns true iff "fork" is available on the target system.
911
912 proc check_fork_available {} {
913     return [check_function_available "fork"]
914 }
915
916 # Returns true iff "mkfifo" is available on the target system.
917
918 proc check_mkfifo_available {} {
919     if {[istarget *-*-cygwin*]} {
920        # Cygwin has mkfifo, but support is incomplete.
921        return 0
922      }
923
924     return [check_function_available "mkfifo"]
925 }
926
927 # Returns true iff "__cxa_atexit" is used on the target system.
928
929 proc check_cxa_atexit_available { } {
930     global et_cxa_atexit
931     global et_cxa_atexit_target_name
932     global tool 
933
934     if { ![info exists et_cxa_atexit_target_name] } {
935         set et_cxa_atexit_target_name ""
936     }
937
938     # If the target has changed since we set the cached value, clear it.
939     set current_target [current_target_name]
940     if { $current_target != $et_cxa_atexit_target_name } {
941         verbose "check_cxa_atexit_available: `$et_cxa_atexit_target_name'" 2
942         set et_cxa_atexit_target_name $current_target
943         if [info exists et_cxa_atexit] {
944             verbose "check_cxa_atexit_available: removing cached result" 2
945             unset et_cxa_atexit
946         }
947     }
948
949     if [info exists et_cxa_atexit] {
950         verbose "check_cxa_atexit_available: using cached result" 2
951     } else {
952         set et_cxa_atexit 0
953
954         # Set up, compile, and execute a C++ test program that depends
955         # on correct ordering of static object destructors. This is
956         # indicative of the presence and use of __cxa_atexit.
957         set src cxaatexit[pid].cc
958         set exe cxaatexit[pid].x
959
960         set f [open $src "w"]
961         puts $f "#include <stdlib.h>"
962         puts $f "static unsigned int count;"
963         puts $f "struct X"
964         puts $f "{"
965         puts $f "  X() { count = 1; }"
966         puts $f "  ~X()"
967         puts $f "  {"
968         puts $f "    if (count != 3)"
969         puts $f "      exit(1);"
970         puts $f "    count = 4;"
971         puts $f "  }"
972         puts $f "};"
973         puts $f "void f()"
974         puts $f "{"
975         puts $f "  static X x;"
976         puts $f "}"
977         puts $f "struct Y"
978         puts $f "{"
979         puts $f "  Y() { f(); count = 2; }"
980         puts $f "  ~Y()"
981         puts $f "  {"
982         puts $f "    if (count != 2)"
983         puts $f "      exit(1);"
984         puts $f "    count = 3;"
985         puts $f "  }"
986         puts $f "};"
987         puts $f "Y y;"
988         puts $f "int main()"
989         puts $f "{ return 0; }"
990         close $f
991
992         set lines [${tool}_target_compile $src $exe executable ""]
993         file delete $src
994
995         if [string match "" $lines] {
996             # No error message, compilation succeeded.
997             set result [${tool}_load "./$exe" "" ""]
998             set status [lindex $result 0]
999             remote_file build delete $exe
1000
1001             verbose "check_cxa_atexit_available: status is <$status>" 2
1002
1003             if { $status == "pass" } {
1004                 set et_cxa_atexit 1
1005             }
1006         } else {
1007             verbose "check_cxa_atexit_available: compilation failed" 2
1008         }
1009     }
1010     return $et_cxa_atexit
1011 }
1012
1013
1014 # Return 1 if we're generating 32-bit code using default options, 0
1015 # otherwise.
1016
1017 proc check_effective_target_ilp32 { } {
1018     return [check_no_compiler_messages ilp32 object {
1019         int dummy[sizeof (int) == 4
1020                   && sizeof (void *) == 4
1021                   && sizeof (long) == 4 ? 1 : -1];
1022     }]
1023 }
1024
1025 # Return 1 if we're generating 32-bit or larger integers using default
1026 # options, 0 otherwise.
1027
1028 proc check_effective_target_int32plus { } {
1029     return [check_no_compiler_messages int32plus object {
1030         int dummy[sizeof (int) >= 4 ? 1 : -1];
1031     }]
1032 }
1033
1034 # Return 1 if we're generating 32-bit or larger pointers using default
1035 # options, 0 otherwise.
1036
1037 proc check_effective_target_ptr32plus { } {
1038     return [check_no_compiler_messages ptr32plus object {
1039         int dummy[sizeof (void *) >= 4 ? 1 : -1];
1040     }]
1041 }
1042
1043 # Return 1 if we support 32-bit or larger array and structure sizes
1044 # using default options, 0 otherwise.
1045
1046 proc check_effective_target_size32plus { } {
1047     return [check_no_compiler_messages size32plus object {
1048         char dummy[65537];
1049     }]
1050 }
1051
1052 # Returns 1 if we're generating 16-bit or smaller integers with the
1053 # default options, 0 otherwise.
1054
1055 proc check_effective_target_int16 { } {
1056     return [check_no_compiler_messages int16 object {
1057         int dummy[sizeof (int) < 4 ? 1 : -1];
1058     }]
1059 }
1060
1061 # Return 1 if we're generating 64-bit code using default options, 0
1062 # otherwise.
1063
1064 proc check_effective_target_lp64 { } {
1065     return [check_no_compiler_messages lp64 object {
1066         int dummy[sizeof (int) == 4
1067                   && sizeof (void *) == 8
1068                   && sizeof (long) == 8 ? 1 : -1];
1069     }]
1070 }
1071
1072 # Return 1 if the target supports compiling decimal floating point,
1073 # 0 otherwise.
1074
1075 proc check_effective_target_dfp_nocache { } {
1076     verbose "check_effective_target_dfp_nocache: compiling source" 2
1077     set ret [string match "" [get_compiler_messages dfp object {
1078         _Decimal32 x; _Decimal64 y; _Decimal128 z;
1079     }]]
1080     verbose "check_effective_target_dfp_nocache: returning $ret" 2
1081     return $ret
1082 }
1083
1084 proc check_effective_target_dfprt_nocache { } {
1085     global tool
1086
1087     set ret 0
1088
1089     verbose "check_effective_target_dfprt_nocache: compiling source" 2
1090     # Set up, compile, and execute a test program containing decimal
1091     # float operations.
1092     set src dfprt[pid].c
1093     set exe dfprt[pid].x
1094
1095     set f [open $src "w"]
1096     puts $f "_Decimal32 x = 1.2df; _Decimal64 y = 2.3dd; _Decimal128 z;"
1097     puts $f "int main () { z = x + y; return 0; }"
1098     close $f
1099
1100     verbose "check_effective_target_dfprt_nocache: compiling testfile $src" 2
1101     set lines [${tool}_target_compile $src $exe executable ""]
1102     file delete $src
1103
1104     if [string match "" $lines] then {
1105         # No error message, compilation succeeded.
1106         set result [${tool}_load "./$exe" "" ""]
1107         set status [lindex $result 0]
1108         remote_file build delete $exe
1109         verbose "check_effective_target_dfprt_nocache: testfile status is <$status>" 2
1110         if { $status == "pass" } then {
1111             set ret 1
1112         }
1113     }
1114     return $ret
1115     verbose "check_effective_target_dfprt_nocache: returning $ret" 2
1116 }
1117
1118 # Return 1 if the target supports compiling Decimal Floating Point,
1119 # 0 otherwise.
1120 #
1121 # This won't change for different subtargets so cache the result.
1122
1123 proc check_effective_target_dfp { } {
1124     global et_dfp_saved
1125
1126     if [info exists et_dfp_saved] {
1127         verbose "check_effective_target_dfp: using cached result" 2
1128     } else {
1129         set et_dfp_saved [check_effective_target_dfp_nocache]
1130     }
1131     verbose "check_effective_target_dfp: returning $et_dfp_saved" 2
1132     return $et_dfp_saved
1133 }
1134
1135 # Return 1 if the target supports linking and executing Decimal Floating
1136 # Point, # 0 otherwise.
1137 #
1138 # This won't change for different subtargets so cache the result.
1139
1140 proc check_effective_target_dfprt { } {
1141     global et_dfprt_saved
1142     global tool
1143
1144     if [info exists et_dfprt_saved] {
1145         verbose "check_effective_target_dfprt: using cached result" 2
1146     } else {
1147         set et_dfprt_saved [check_effective_target_dfprt_nocache]
1148     }
1149     verbose "check_effective_target_dfprt: returning $et_dfprt_saved" 2
1150     return $et_dfprt_saved
1151 }
1152
1153 # Return 1 if the target needs a command line argument to enable a SIMD
1154 # instruction set.
1155 #
1156 # This won't change for different subtargets so cache the result.
1157
1158 proc check_effective_target_vect_cmdline_needed { } {
1159     global et_vect_cmdline_needed_saved
1160
1161     if [info exists et_vect_cmdline_needed_saved] {
1162         verbose "check_effective_target_vect_cmdline_needed: using cached result" 2
1163     } else {
1164         set et_vect_cmdline_needed_saved 1
1165         if { [istarget ia64-*-*]
1166               || [istarget x86_64-*-*] } {
1167            set et_vect_cmdline_needed_saved 0
1168         }
1169     }
1170
1171     verbose "check_effective_target_vect_cmdline_needed: returning $et_vect_cmdline_needed_saved" 2
1172     return $et_vect_cmdline_needed_saved
1173 }
1174
1175 # Return 1 if the target supports hardware vectors of int, 0 otherwise.
1176 #
1177 # This won't change for different subtargets so cache the result.
1178
1179 proc check_effective_target_vect_int { } {
1180     global et_vect_int_saved
1181
1182     if [info exists et_vect_int_saved] {
1183         verbose "check_effective_target_vect_int: using cached result" 2
1184     } else {
1185         set et_vect_int_saved 0
1186         if { [istarget i?86-*-*]
1187               || [istarget powerpc*-*-*]
1188               || [istarget x86_64-*-*]
1189               || [istarget sparc*-*-*]
1190               || [istarget alpha*-*-*]
1191               || [istarget ia64-*-*] } {
1192            set et_vect_int_saved 1
1193         }
1194     }
1195
1196     verbose "check_effective_target_vect_int: returning $et_vect_int_saved" 2
1197     return $et_vect_int_saved
1198 }
1199
1200 # Return 1 is this is an arm target using 32-bit instructions
1201 proc check_effective_target_arm32 { } {
1202     global et_arm32_saved
1203     global et_arm32_target_name
1204     global compiler_flags
1205
1206     if { ![info exists et_arm32_target_name] } {
1207         set et_arm32_target_name ""
1208     }
1209
1210     # If the target has changed since we set the cached value, clear it.
1211     set current_target [current_target_name]
1212     if { $current_target != $et_arm32_target_name } {
1213         verbose "check_effective_target_arm32: `$et_arm32_target_name' `$current_target'" 2
1214         set et_arm32_target_name $current_target
1215         if { [info exists et_arm32_saved] } {
1216             verbose "check_effective_target_arm32: removing cached result" 2
1217             unset et_arm32_saved
1218         }
1219     }
1220
1221     if [info exists et_arm32_saved] {
1222         verbose "check-effective_target_arm32: using cached result" 2
1223     } else {
1224         set et_arm32_saved 0
1225         if { [istarget arm-*-*]
1226               || [istarget strongarm*-*-*]
1227               || [istarget xscale-*-*] } {
1228             if ![string match "*-mthumb *" $compiler_flags] {
1229                 set et_arm32_saved 1
1230             }
1231         }
1232     }
1233     verbose "check_effective_target_arm32: returning $et_arm32_saved" 2
1234     return $et_arm32_saved
1235 }
1236
1237 # Return 1 if this is a PowerPC target with floating-point registers.
1238
1239 proc check_effective_target_powerpc_fprs { } {
1240     if { [istarget powerpc*-*-*]
1241          || [istarget rs6000-*-*] } {
1242         return [check_no_compiler_messages powerpc_fprs object {
1243             #ifdef __NO_FPRS__
1244             #error no FPRs
1245             #else
1246             int dummy;
1247             #endif
1248         }]
1249     } else {
1250         return 0
1251     }
1252 }
1253
1254 # Return 1 if this is a PowerPC target supporting -maltivec.
1255
1256 proc check_effective_target_powerpc_altivec_ok { } {
1257     if { [istarget powerpc*-*-*]
1258          || [istarget rs6000-*-*] } {
1259         # AltiVec is not supported on Aix.
1260         if { [istarget powerpc*-*-aix*] } {
1261             return 0
1262         }
1263         return [check_no_compiler_messages powerpc_altivec_ok object {
1264             int dummy;
1265         } "-maltivec"]
1266     } else {
1267         return 0
1268     }
1269 }
1270
1271 # Return 1 if the target supports hardware vector shift operation.
1272
1273 proc check_effective_target_vect_shift { } {
1274     global et_vect_shift_saved
1275
1276     if [info exists et_vect_shift_saved] {
1277         verbose "check_effective_target_vect_shift: using cached result" 2
1278     } else {
1279         set et_vect_shift_saved 0
1280         if { [istarget powerpc*-*-*]
1281              || [istarget ia64-*-*]
1282              || [istarget i?86-*-*]
1283              || [istarget x86_64-*-*] } {
1284            set et_vect_shift_saved 1
1285         }
1286     }
1287
1288     verbose "check_effective_target_vect_shift: returning $et_vect_shift_saved" 2
1289     return $et_vect_shift_saved
1290 }
1291
1292 # Return 1 if the target supports hardware vectors of long, 0 otherwise.
1293 #
1294 # This can change for different subtargets so do not cache the result.
1295
1296 proc check_effective_target_vect_long { } {
1297     if { [istarget i?86-*-*]
1298          || ([istarget powerpc*-*-*] && [check_effective_target_ilp32])
1299          || [istarget x86_64-*-*]
1300          || ([istarget sparc*-*-*] && [check_effective_target_ilp32]) } {
1301         set answer 1
1302     } else {
1303         set answer 0
1304     }
1305
1306     verbose "check_effective_target_vect_long: returning $answer" 2
1307     return $answer
1308 }
1309
1310 # Return 1 if the target supports hardware vectors of float, 0 otherwise.
1311 #
1312 # This won't change for different subtargets so cache the result.
1313
1314 proc check_effective_target_vect_float { } {
1315     global et_vect_float_saved
1316
1317     if [info exists et_vect_float_saved] {
1318         verbose "check_effective_target_vect_float: using cached result" 2
1319     } else {
1320         set et_vect_float_saved 0
1321         if { [istarget i?86-*-*]
1322               || [istarget powerpc*-*-*]
1323               || [istarget mipsisa64*-*-*]
1324               || [istarget x86_64-*-*]
1325               || [istarget ia64-*-*] } {
1326            set et_vect_float_saved 1
1327         }
1328     }
1329
1330     verbose "check_effective_target_vect_float: returning $et_vect_float_saved" 2
1331     return $et_vect_float_saved
1332 }
1333
1334 # Return 1 if the target supports hardware vectors of double, 0 otherwise.
1335 #
1336 # This won't change for different subtargets so cache the result.
1337
1338 proc check_effective_target_vect_double { } {
1339     global et_vect_double_saved
1340
1341     if [info exists et_vect_double_saved] {
1342         verbose "check_effective_target_vect_double: using cached result" 2
1343     } else {
1344         set et_vect_double_saved 0
1345         if { [istarget i?86-*-*]
1346               || [istarget x86_64-*-*] } {
1347            set et_vect_double_saved 1
1348         }
1349     }
1350
1351     verbose "check_effective_target_vect_double: returning $et_vect_double_saved" 2
1352     return $et_vect_double_saved
1353 }
1354
1355 # Return 1 if the target plus current options does not support a vector
1356 # max instruction on "int", 0 otherwise.
1357 #
1358 # This won't change for different subtargets so cache the result.
1359
1360 proc check_effective_target_vect_no_int_max { } {
1361     global et_vect_no_int_max_saved
1362
1363     if [info exists et_vect_no_int_max_saved] {
1364         verbose "check_effective_target_vect_no_int_max: using cached result" 2
1365     } else {
1366         set et_vect_no_int_max_saved 0
1367         if { [istarget sparc*-*-*]
1368              || [istarget alpha*-*-*] } {
1369             set et_vect_no_int_max_saved 1
1370         }
1371     }
1372     verbose "check_effective_target_vect_no_int_max: returning $et_vect_no_int_max_saved" 2
1373     return $et_vect_no_int_max_saved
1374 }
1375
1376 # Return 1 if the target plus current options does not support a vector
1377 # add instruction on "int", 0 otherwise.
1378 #
1379 # This won't change for different subtargets so cache the result.
1380
1381 proc check_effective_target_vect_no_int_add { } {
1382     global et_vect_no_int_add_saved
1383
1384     if [info exists et_vect_no_int_add_saved] {
1385         verbose "check_effective_target_vect_no_int_add: using cached result" 2
1386     } else {
1387         set et_vect_no_int_add_saved 0
1388         # Alpha only supports vector add on V8QI and V4HI.
1389         if { [istarget alpha*-*-*] } {
1390             set et_vect_no_int_add_saved 1
1391         }
1392     }
1393     verbose "check_effective_target_vect_no_int_add: returning $et_vect_no_int_add_saved" 2
1394     return $et_vect_no_int_add_saved
1395 }
1396
1397 # Return 1 if the target plus current options does not support vector
1398 # bitwise instructions, 0 otherwise.
1399 #
1400 # This won't change for different subtargets so cache the result.
1401
1402 proc check_effective_target_vect_no_bitwise { } {
1403     global et_vect_no_bitwise_saved
1404
1405     if [info exists et_vect_no_bitwise_saved] {
1406         verbose "check_effective_target_vect_no_bitwise: using cached result" 2
1407     } else {
1408         set et_vect_no_bitwise_saved 0
1409     }
1410     verbose "check_effective_target_vect_no_bitwise: returning $et_vect_no_bitwise_saved" 2
1411     return $et_vect_no_bitwise_saved
1412 }
1413
1414 # Return 1 if the target plus current options supports a vector
1415 # widening summation of *short* args into *int* result, 0 otherwise.
1416 #
1417 # This won't change for different subtargets so cache the result.
1418                                                                                                 
1419 proc check_effective_target_vect_widen_sum_hi_to_si { } {
1420     global et_vect_widen_sum_hi_to_si
1421                                                                                                 
1422     if [info exists et_vect_widen_sum_hi_to_si_saved] {
1423         verbose "check_effective_target_vect_widen_sum_hi_to_si: using cached result" 2
1424     } else {
1425         set et_vect_widen_sum_hi_to_si_saved 0
1426         if { [istarget powerpc*-*-*]
1427              || [istarget ia64-*-*] } {
1428             set et_vect_widen_sum_hi_to_si_saved 1
1429         }
1430     }
1431     verbose "check_effective_target_vect_widen_sum_hi_to_si: returning $et_vect_widen_sum_hi_to_si_saved" 2
1432     return $et_vect_widen_sum_hi_to_si_saved
1433 }
1434
1435 # Return 1 if the target plus current options supports a vector
1436 # widening summation of *char* args into *short* result, 0 otherwise.
1437 #
1438 # This won't change for different subtargets so cache the result.
1439                                                                                                 
1440 proc check_effective_target_vect_widen_sum_qi_to_hi { } {
1441     global et_vect_widen_sum_qi_to_hi
1442                                                                                                 
1443     if [info exists et_vect_widen_sum_qi_to_hi_saved] {
1444         verbose "check_effective_target_vect_widen_sum_qi_to_hi: using cached result" 2
1445     } else {
1446         set et_vect_widen_sum_qi_to_hi_saved 0
1447         if { [istarget ia64-*-*] } {
1448             set et_vect_widen_sum_qi_to_hi_saved 1
1449         }
1450     }
1451     verbose "check_effective_target_vect_widen_sum_qi_to_hi: returning $et_vect_widen_sum_qi_to_hi_saved" 2
1452     return $et_vect_widen_sum_qi_to_hi_saved
1453 }
1454
1455 # Return 1 if the target plus current options supports a vector
1456 # widening summation of *char* args into *int* result, 0 otherwise.
1457 #
1458 # This won't change for different subtargets so cache the result.
1459                                                                                                 
1460 proc check_effective_target_vect_widen_sum_qi_to_si { } {
1461     global et_vect_widen_sum_qi_to_si
1462                                                                                                 
1463     if [info exists et_vect_widen_sum_qi_to_si_saved] {
1464         verbose "check_effective_target_vect_widen_sum_qi_to_si: using cached result" 2
1465     } else {
1466         set et_vect_widen_sum_qi_to_si_saved 0
1467         if { [istarget powerpc*-*-*] } {
1468             set et_vect_widen_sum_qi_to_si_saved 1
1469         }
1470     }
1471     verbose "check_effective_target_vect_widen_sum_qi_to_si: returning $et_vect_widen_sum_qi_to_si_saved" 2
1472     return $et_vect_widen_sum_qi_to_si_saved
1473 }
1474
1475 # Return 1 if the target plus current options supports a vector
1476 # widening summation, 0 otherwise.
1477 #
1478 # This won't change for different subtargets so cache the result.
1479                                                                                                 
1480 proc check_effective_target_vect_widen_sum { } {
1481     global et_vect_widen_sum
1482                                                                                                 
1483     if [info exists et_vect_widen_sum_saved] {
1484         verbose "check_effective_target_vect_widen_sum: using cached result" 2
1485     } else {
1486         set et_vect_widen_sum_saved 0
1487         if { [istarget powerpc*-*-*]
1488              || [istarget ia64-*-*] } {
1489             set et_vect_widen_sum_saved 1
1490         }
1491     }
1492     verbose "check_effective_target_vect_widen_sum: returning $et_vect_widen_sum_saved" 2
1493     return $et_vect_widen_sum_saved
1494 }
1495
1496 # Return 1 if the target plus current options supports a vector
1497 # dot-product of signed chars, 0 otherwise.
1498 #
1499 # This won't change for different subtargets so cache the result.
1500
1501 proc check_effective_target_vect_sdot_qi { } {
1502     global et_vect_sdot_qi
1503
1504     if [info exists et_vect_sdot_qi_saved] {
1505         verbose "check_effective_target_vect_sdot_qi: using cached result" 2
1506     } else {
1507         set et_vect_sdot_qi_saved 0
1508         if { [istarget ia64-*-*] } {
1509             set et_vect_sdot_qi_saved 1
1510         }
1511     }
1512     verbose "check_effective_target_vect_sdot_qi: returning $et_vect_sdot_qi_saved" 2
1513     return $et_vect_sdot_qi_saved
1514 }
1515
1516 # Return 1 if the target plus current options supports a vector
1517 # dot-product of unsigned chars, 0 otherwise.
1518 #
1519 # This won't change for different subtargets so cache the result.
1520
1521 proc check_effective_target_vect_udot_qi { } {
1522     global et_vect_udot_qi
1523
1524     if [info exists et_vect_udot_qi_saved] {
1525         verbose "check_effective_target_vect_udot_qi: using cached result" 2
1526     } else {
1527         set et_vect_udot_qi_saved 0
1528         if { [istarget powerpc*-*-*]
1529              || [istarget ia64-*-*] } {
1530             set et_vect_udot_qi_saved 1
1531         }
1532     }
1533     verbose "check_effective_target_vect_udot_qi: returning $et_vect_udot_qi_saved" 2
1534     return $et_vect_udot_qi_saved
1535 }
1536
1537 # Return 1 if the target plus current options supports a vector
1538 # dot-product of signed shorts, 0 otherwise.
1539 #
1540 # This won't change for different subtargets so cache the result.
1541
1542 proc check_effective_target_vect_sdot_hi { } {
1543     global et_vect_sdot_hi
1544
1545     if [info exists et_vect_sdot_hi_saved] {
1546         verbose "check_effective_target_vect_sdot_hi: using cached result" 2
1547     } else {
1548         set et_vect_sdot_hi_saved 0
1549         if { [istarget powerpc*-*-*] 
1550              || [istarget i?86-*-*]
1551              || [istarget x86_64-*-*]
1552              || [istarget ia64-*-*] } {
1553             set et_vect_sdot_hi_saved 1
1554         }
1555     }
1556     verbose "check_effective_target_vect_sdot_hi: returning $et_vect_sdot_hi_saved" 2
1557     return $et_vect_sdot_hi_saved
1558 }
1559
1560 # Return 1 if the target plus current options supports a vector
1561 # dot-product of unsigned shorts, 0 otherwise.
1562 #
1563 # This won't change for different subtargets so cache the result.
1564
1565 proc check_effective_target_vect_udot_hi { } {
1566     global et_vect_udot_hi
1567
1568     if [info exists et_vect_udot_hi_saved] {
1569         verbose "check_effective_target_vect_udot_hi: using cached result" 2
1570     } else {
1571         set et_vect_udot_hi_saved 0
1572         if { [istarget powerpc*-*-*] } {
1573             set et_vect_udot_hi_saved 1
1574         }
1575     }
1576     verbose "check_effective_target_vect_udot_hi: returning $et_vect_udot_hi_saved" 2
1577     return $et_vect_udot_hi_saved
1578 }
1579
1580
1581 # Return 1 if the target plus current options does not support a vector
1582 # alignment mechanism, 0 otherwise.
1583 #
1584 # This won't change for different subtargets so cache the result.
1585
1586 proc check_effective_target_vect_no_align { } {
1587     global et_vect_no_align_saved
1588
1589     if [info exists et_vect_no_align_saved] {
1590         verbose "check_effective_target_vect_no_align: using cached result" 2
1591     } else {
1592         set et_vect_no_align_saved 0
1593         if { [istarget mipsisa64*-*-*]
1594              || [istarget sparc*-*-*]
1595              || [istarget ia64-*-*] } {
1596             set et_vect_no_align_saved 1
1597         }
1598     }
1599     verbose "check_effective_target_vect_no_align: returning $et_vect_no_align_saved" 2
1600     return $et_vect_no_align_saved
1601 }
1602
1603 # Return 1 if the target supports vector conditional operations, 0 otherwise.
1604
1605 proc check_effective_target_vect_condition { } {
1606     global et_vect_cond_saved
1607
1608     if [info exists et_vect_cond_saved] {
1609         verbose "check_effective_target_vect_cond: using cached result" 2
1610     } else {
1611         set et_vect_cond_saved 0
1612         if { [istarget powerpc*-*-*]
1613              || [istarget ia64-*-*]
1614              || [istarget i?86-*-*]
1615              || [istarget x86_64-*-*] } {
1616            set et_vect_cond_saved 1
1617         }
1618     }
1619
1620     verbose "check_effective_target_vect_cond: returning $et_vect_cond_saved" 2
1621     return $et_vect_cond_saved
1622 }
1623
1624 # Return 1 if the target supports vector char multiplication, 0 otherwise.
1625
1626 proc check_effective_target_vect_char_mult { } {
1627     global et_vect_char_mult_saved
1628
1629     if [info exists et_vect_char_mult_saved] {
1630         verbose "check_effective_target_vect_char_mult: using cached result" 2
1631     } else {
1632         set et_vect_char_mult_saved 0
1633         if { [istarget ia64-*-*]
1634              || [istarget i?86-*-*]
1635              || [istarget x86_64-*-*] } {
1636            set et_vect_char_mult_saved 1
1637         }
1638     }
1639
1640     verbose "check_effective_target_vect_char_mult: returning $et_vect_char_mult_saved" 2
1641     return $et_vect_char_mult_saved
1642 }
1643
1644 # Return 1 if the target supports vector short multiplication, 0 otherwise.
1645
1646 proc check_effective_target_vect_short_mult { } {
1647     global et_vect_short_mult_saved
1648
1649     if [info exists et_vect_short_mult_saved] {
1650         verbose "check_effective_target_vect_short_mult: using cached result" 2
1651     } else {
1652         set et_vect_short_mult_saved 0
1653         if { [istarget ia64-*-*]
1654              || [istarget i?86-*-*]
1655              || [istarget x86_64-*-*] } {
1656            set et_vect_short_mult_saved 1
1657         }
1658     }
1659
1660     verbose "check_effective_target_vect_short_mult: returning $et_vect_short_mult_saved" 2
1661     return $et_vect_short_mult_saved
1662 }
1663
1664 # Return 1 if the target supports vector int multiplication, 0 otherwise.
1665
1666 proc check_effective_target_vect_int_mult { } {
1667     global et_vect_int_mult_saved
1668
1669     if [info exists et_vect_int_mult_saved] {
1670         verbose "check_effective_target_vect_int_mult: using cached result" 2
1671     } else {
1672         set et_vect_int_mult_saved 0
1673         if { [istarget powerpc*-*-*]
1674              || [istarget i?86-*-*]
1675              || [istarget x86_64-*-*] } {
1676            set et_vect_int_mult_saved 1
1677         }
1678     }
1679
1680     verbose "check_effective_target_vect_int_mult: returning $et_vect_int_mult_saved" 2
1681     return $et_vect_int_mult_saved
1682 }
1683
1684 # Return 1 if the target supports atomic operations on "int" and "long".
1685
1686 proc check_effective_target_sync_int_long { } {
1687     global et_sync_int_long_saved
1688
1689     if [info exists et_sync_int_long_saved] {
1690         verbose "check_effective_target_sync_int_long: using cached result" 2
1691     } else {
1692         set et_sync_int_long_saved 0
1693 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
1694 # load-reserved/store-conditional instructions.
1695         if { [istarget ia64-*-*]
1696              || [istarget i?86-*-*]
1697              || [istarget x86_64-*-*]
1698              || [istarget alpha*-*-*] 
1699              || [istarget s390*-*-*] 
1700              || [istarget powerpc*-*-*]
1701              || [istarget sparc64-*-*]
1702              || [istarget sparcv9-*-*] } {
1703            set et_sync_int_long_saved 1
1704         }
1705     }
1706
1707     verbose "check_effective_target_sync_int_long: returning $et_sync_int_long_saved" 2
1708     return $et_sync_int_long_saved
1709 }
1710
1711 # Return 1 if the target supports atomic operations on "char" and "short".
1712
1713 proc check_effective_target_sync_char_short { } {
1714     global et_sync_char_short_saved
1715
1716     if [info exists et_sync_char_short_saved] {
1717         verbose "check_effective_target_sync_char_short: using cached result" 2
1718     } else {
1719         set et_sync_char_short_saved 0
1720 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
1721 # load-reserved/store-conditional instructions.
1722         if { [istarget ia64-*-*]
1723              || [istarget i?86-*-*]
1724              || [istarget x86_64-*-*]
1725              || [istarget alpha*-*-*] 
1726              || [istarget s390*-*-*] 
1727              || [istarget powerpc*-*-*]
1728              || [istarget sparc64-*-*]
1729              || [istarget sparcv9-*-*] } {
1730            set et_sync_char_short_saved 1
1731         }
1732     }
1733
1734     verbose "check_effective_target_sync_char_short: returning $et_sync_char_short_saved" 2
1735     return $et_sync_char_short_saved
1736 }
1737
1738 # Return 1 if the target matches the effective target 'arg', 0 otherwise.
1739 # This can be used with any check_* proc that takes no argument and
1740 # returns only 1 or 0.  It could be used with check_* procs that take
1741 # arguments with keywords that pass particular arguments.
1742
1743 proc is-effective-target { arg } {
1744     set selected 0
1745     if { [info procs check_effective_target_${arg}] != [list] } {
1746         set selected [check_effective_target_${arg}]
1747     } else {
1748         switch $arg {
1749           "vmx_hw"         { set selected [check_vmx_hw_available] }
1750           "named_sections" { set selected [check_named_sections_available] }
1751           "gc_sections"    { set selected [check_gc_sections_available] }
1752           default          { error "unknown effective target keyword `$arg'" }
1753         }
1754     }
1755     verbose "is-effective-target: $arg $selected" 2
1756     return $selected
1757 }
1758
1759 # Return 1 if the argument is an effective-target keyword, 0 otherwise.
1760
1761 proc is-effective-target-keyword { arg } {
1762     if { [info procs check_effective_target_${arg}] != [list] } {
1763         return 1
1764     } else {
1765         # These have different names for their check_* procs.
1766         switch $arg {
1767           "vmx_hw"         { return 1 }
1768           "named_sections" { return 1 }
1769           "gc_sections"    { return 1 }
1770           default          { return 0 }
1771         }
1772     }
1773 }
1774
1775 # Return 1 if target default to short enums
1776
1777 proc check_effective_target_short_enums { } {
1778     return [check_no_compiler_messages short_enums assembly {
1779         enum foo { bar };
1780         int s[sizeof (enum foo) == 1 ? 1 : -1];
1781     }]
1782 }
1783