OSDN Git Service

* lib/target-supports.exp (check_effective_target_vect_no_int_max):
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / target-supports.exp
1 #   Copyright (C) 1999, 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # gcc-patches@gcc.gnu.org
19
20 # This file defines procs for determining features supported by the target.
21
22 # Try to compile some code and return the messages printed by the compiler.
23 #
24 # BASENAME is a basename to use for temporary files.
25 # TYPE is the type of compilation to perform (see target_compile).
26 # CONTENTS gives the contents of the input file.
27 # The rest is optional:
28 # OPTIONS: additional compiler options to use.
29 proc get_compiler_messages {basename type contents args} {
30     global tool
31
32     if { [llength $args] > 0 } {
33         set options "additional_flags=[lindex $args 0]"
34     } else {
35         set options ""
36     }
37
38     set src ${basename}[pid].c
39     switch $type {
40         assembly { set output ${basename}[pid].s }
41         object { set output ${basename}[pid].o }
42     }
43     set f [open $src "w"]
44     puts $f $contents
45     close $f
46     set lines [${tool}_target_compile $src $output $type "$options"]
47     file delete $src
48     remote_file build delete $output
49
50     return $lines
51 }
52
53 proc current_target_name { } {
54     global target_info
55     if [info exists target_info(target,name)] {
56         set answer $target_info(target,name)
57     } else {
58         set answer ""
59     }
60     return $answer
61 }
62
63 ###############################
64 # proc check_weak_available { }
65 ###############################
66
67 # weak symbols are only supported in some configs/object formats
68 # this proc returns 1 if they're supported, 0 if they're not, or -1 if unsure
69
70 proc check_weak_available { } {
71     global target_triplet
72     global target_cpu
73
74     # All mips targets should support it
75
76     if { [ string first "mips" $target_cpu ] >= 0 } {
77         return 1
78     }
79
80     # All solaris2 targets should support it
81
82     if { [regexp ".*-solaris2.*" $target_triplet] } {
83         return 1
84     }
85
86     # DEC OSF/1/Digital UNIX/Tru64 UNIX supports it
87
88     if { [regexp "alpha.*osf.*" $target_triplet] } {
89         return 1
90     }
91
92     # Windows targets Cygwin and MingW32 support it
93
94     if { [regexp ".*mingw32|.*cygwin" $target_triplet] } {
95         return 1
96     }
97
98     # HP-UX 10.X doesn't support it
99
100     if { [regexp "hppa.*hpux10" $target_triplet] } {
101         return 0
102     }
103
104     # ELF and ECOFF support it. a.out does with gas/gld but may also with
105     # other linkers, so we should try it
106
107     set objformat [gcc_target_object_format]
108
109     switch $objformat {
110         elf      { return 1 }
111         ecoff    { return 1 }
112         a.out    { return 1 }
113         mach-o   { return 1 }
114         som      { return 1 }
115         unknown  { return -1 }
116         default  { return 0 }
117     }
118 }
119
120 ###############################
121 # proc check_visibility_available { what_kind }
122 ###############################
123
124 # The visibility attribute is only support in some object formats
125 # This proc returns 1 if it is supported, 0 if not.
126 # The argument is the kind of visibility, default/protected/hidden/internal.
127
128 proc check_visibility_available { what_kind } {
129     global visibility_available_saved
130     global tool
131     global target_triplet
132
133     # On NetWare, support makes no sense.
134     if { [string match "*-*-netware*" $target_triplet] } {
135         return 0
136     }
137
138     if [string match "" $what_kind] { set what_kind "hidden" }
139
140     if { [info exists visibility_available_saved] } {
141         verbose "Saved result is <$visibility_available_saved>" 1
142         if { [ lsearch -exact $visibility_available_saved $what_kind ] != -1 } {
143             return 1
144         } elseif { [ lsearch -exact $visibility_available_saved "!$what_kind" ] != -1 } {
145             return 0
146         }
147     }
148
149     set lines [get_compiler_messages visibility object "
150         void f() __attribute__((visibility(\"$what_kind\")));
151         void f() {}
152     "]
153     if [string match "" $lines] then {
154         set answer 1
155         lappend visibility_available_saved $what_kind
156     } else {
157         set answer 0
158         lappend visibility_available_saved "!$what_kind"
159     }
160     return $answer
161 }
162
163 ###############################
164 # proc check_alias_available { }
165 ###############################
166
167 # Determine if the target toolchain supports the alias attribute.
168
169 # Returns 2 if the target supports aliases.  Returns 1 if the target
170 # only supports weak aliased.  Returns 0 if the target does not
171 # support aliases at all.  Returns -1 if support for aliases could not
172 # be determined.
173
174 proc check_alias_available { } {
175     global alias_available_saved
176     global tool
177
178     if [info exists alias_available_saved] {
179         verbose "check_alias_available  returning saved $alias_available_saved" 2
180     } else {
181         set src alias[pid].c
182         set obj alias[pid].o
183         verbose "check_alias_available  compiling testfile $src" 2
184         set f [open $src "w"]
185         # Compile a small test program.  The definition of "g" is
186         # necessary to keep the Solaris assembler from complaining
187         # about the program.
188         puts $f "#ifdef __cplusplus\nextern \"C\"\n#endif\n"
189         puts $f "void g() {} void f() __attribute__((alias(\"g\")));"
190         close $f
191         set lines [${tool}_target_compile $src $obj object ""]
192         file delete $src
193         remote_file build delete $obj
194
195         if [string match "" $lines] then {
196             # No error messages, everything is OK.
197             set alias_available_saved 2
198         } else {
199             if [regexp "alias definitions not supported" $lines] {
200                 verbose "check_alias_available  target does not support aliases" 2
201
202                 set objformat [gcc_target_object_format]
203
204                 if { $objformat == "elf" } {
205                     verbose "check_alias_available  but target uses ELF format, so it ought to" 2
206                     set alias_available_saved -1
207                 } else {
208                     set alias_available_saved 0
209                 }
210             } else {
211                 if [regexp "only weak aliases are supported" $lines] {
212                 verbose "check_alias_available  target supports only weak aliases" 2
213                 set alias_available_saved 1
214                 } else {
215                     set alias_available_saved -1
216                 }
217             }
218         }
219
220         verbose "check_alias_available  returning $alias_available_saved" 2
221     }
222
223     return $alias_available_saved
224 }
225
226 # Returns true if --gc-sections is supported on the target.
227
228 proc check_gc_sections_available { } {
229     global gc_sections_available_saved
230     global tool
231
232     if {![info exists gc_sections_available_saved]} {
233         # Some targets don't support gc-sections despite whatever's
234         # advertised by ld's options.
235         if { [istarget alpha*-*-*]
236              || [istarget ia64-*-*] } {
237             set gc_sections_available_saved 0
238             return 0
239         }
240
241         # Check if the ld used by gcc supports --gc-sections.
242         set gcc_spec [${tool}_target_compile "-dumpspecs" "" "none" ""]
243         regsub ".*\n\*linker:\[ \t\]*\n(\[^ \t\n\]*).*" "$gcc_spec" {\1} linker
244         set gcc_ld [lindex [${tool}_target_compile "-print-prog-name=$linker" "" "none" ""] 0]
245         set ld_output [remote_exec host "$gcc_ld" "--help"]
246         if { [ string first "--gc-sections" $ld_output ] >= 0 } {
247             set gc_sections_available_saved 1
248         } else {
249             set gc_sections_available_saved 0
250         }
251     }
252     return $gc_sections_available_saved
253 }
254
255 # Return true if profiling is supported on the target.
256
257 proc check_profiling_available { test_what } {
258     global profiling_available_saved
259
260     verbose "Profiling argument is <$test_what>" 1
261
262     # These conditions depend on the argument so examine them before
263     # looking at the cache variable.
264
265     # Support for -p on solaris2 relies on mcrt1.o which comes with the
266     # vendor compiler.  We cannot reliably predict the directory where the
267     # vendor compiler (and thus mcrt1.o) is installed so we can't
268     # necessarily find mcrt1.o even if we have it.
269     if { [istarget *-*-solaris2*] && [lindex $test_what 1] == "-p" } {
270         return 0
271     }
272
273     # Support for -p on irix relies on libprof1.a which doesn't appear to
274     # exist on any irix6 system currently posting testsuite results.
275     # Support for -pg on irix relies on gcrt1.o which doesn't exist yet.
276     # See: http://gcc.gnu.org/ml/gcc/2002-10/msg00169.html
277     if { [istarget mips*-*-irix*]
278     && ([lindex $test_what 1] == "-p" || [lindex $test_what 1] == "-pg") } {
279         return 0
280     }
281
282     # Now examine the cache variable.
283     if {![info exists profiling_available_saved]} {
284         # Some targets don't have any implementation of __bb_init_func or are
285         # missing other needed machinery.
286         if { [istarget mmix-*-*]
287              || [istarget arm*-*-eabi*]
288              || [istarget arm*-*-elf]
289              || [istarget arm*-*-symbianelf*]
290              || [istarget powerpc-*-eabi*]
291              || [istarget strongarm*-*-elf]
292              || [istarget xscale*-*-elf]
293              || [istarget cris-*-*]
294              || [istarget h8300-*-*]
295              || [istarget mips*-*-elf]
296              || [istarget xtensa-*-elf]
297              || [istarget *-*-windiss] } {
298             set profiling_available_saved 0
299         } else {
300             set profiling_available_saved 1
301         }
302     }
303
304     return $profiling_available_saved
305 }
306
307 # Return 1 if -fpic and -fPIC are supported, as in no warnings or errors
308 # emitted, 0 otherwise.  Whether a shared library can actually be built is
309 # out of scope for this test.
310 #
311 # When the target name changes, replace the cached result.
312
313 proc check_effective_target_fpic { } {
314     global et_fpic_saved
315     global et_fpic_target_name
316
317     if { ![info exists et_fpic_target_name] } {
318         set et_fpic_target_name ""
319     }
320
321     # If the target has changed since we set the cached value, clear it.
322     set current_target [current_target_name]
323     if { $current_target != $et_fpic_target_name } {
324         verbose "check_effective_target_fpic: `$et_fpic_target_name'" 2
325         set et_fpic_target_name $current_target
326         if [info exists et_fpic_saved] {
327             verbose "check_effective_target_fpic: removing cached result" 2
328             unset et_fpic_saved
329         }
330     }
331
332     if [info exists et_fpic_saved] {
333         verbose "check_effective_target_fpic: using cached result" 2
334     } else {
335         verbose "check_effective_target_fpic: compiling source" 2
336
337         # Note that M68K has a multilib that supports -fpic but not
338         # -fPIC, so we need to check both.  We test with a program that
339         # requires GOT references.
340         set et_fpic_saved [string match "" [get_compiler_messages fpic object {
341             extern int foo (void); extern int bar;
342             int baz (void) { return foo () + bar; }
343         } "-fpic"]]
344
345         if { $et_fpic_saved != 0 } {
346             set et_fpic_saved [string match "" [get_compiler_messages fpic object {
347                 extern int foo (void); extern int bar;
348                 int baz (void) { return foo () + bar; }
349             } "-fPIC"]]
350         }
351     }
352     verbose "check_effective_target_fpic: returning $et_fpic_saved" 2
353     return $et_fpic_saved
354 }
355
356 # Return true if iconv is supported on the target. In particular IBM1047.
357
358 proc check_iconv_available { test_what } {
359     global tool
360     global libiconv
361
362     set result ""
363
364     set src iconv[pid].c
365     set exe iconv[pid].x
366     verbose "check_iconv_available compiling testfile $src" 2
367     set f [open $src "w"]
368     # Compile a small test program.
369     puts $f "#include <iconv.h>\n"
370     puts $f "int main (void)\n {\n iconv_t cd; \n"
371     puts $f "cd = iconv_open (\"[lindex $test_what 1]\", \"UTF-8\");\n"
372     puts $f "if (cd == (iconv_t) -1)\n return 1;\n"
373     puts $f "return 0;\n}"
374     close $f
375
376     # If the tool configuration file has not set libiconv, try "-liconv"
377     if { ![info exists libiconv] } {
378         set libiconv "-liconv"
379     }
380     set lines [${tool}_target_compile $src $exe executable "libs=$libiconv" ]
381     file delete $src
382
383     if [string match "" $lines] then {
384         # No error messages, everything is OK.
385
386         set result [${tool}_load "./$exe" "" ""]
387         set status [lindex $result 0]
388         remote_file build delete $exe
389
390         verbose "check_iconv_available status is <$status>" 2
391
392         if { $status == "pass" } then {
393             return 1
394         }
395     }
396
397     return 0
398 }
399
400 # Return true if named sections are supported on this target.
401 # This proc does not cache results, because the answer may vary
402 # when cycling over subtarget options (e.g. irix o32/n32/n64) in
403 # the same test run.
404 proc check_named_sections_available { } {
405     verbose "check_named_sections_available: compiling source" 2
406     set answer [string match "" [get_compiler_messages named object {
407         int __attribute__ ((section("whatever"))) foo;
408     }]]
409     verbose "check_named_sections_available: returning $answer" 2
410     return $answer
411 }
412
413 # Return 1 if the target supports Fortran real kinds larger than real(8),
414 # 0 otherwise.  Cache the result.
415
416 proc check_effective_target_fortran_large_real { } {
417     global et_fortran_large_real_saved
418     global tool
419
420     if [info exists et_fortran_large_real_saved] {
421         verbose "check_effective_target_fortran_large_real returning saved $et_fortran_large_real_saved" 2
422     } else {
423         set et_fortran_large_real_saved 0
424
425         # Set up, compile, and execute a test program using large real
426         # kinds.  Include the current process ID in the file names to
427         # prevent conflicts with invocations for multiple testsuites.
428         set src real[pid].f90
429         set exe real[pid].x
430
431         set f [open $src "w"]
432         puts $f "integer,parameter :: k = &"
433         puts $f "  selected_real_kind (precision (0.0_8) + 1)"
434         puts $f "real(kind=k) :: x"
435         puts $f "end"
436         close $f
437
438         verbose "check_effective_target_fortran_large_real compiling testfile $src" 2
439         set lines [${tool}_target_compile $src $exe executable ""]
440         file delete $src
441
442         if [string match "" $lines] then {
443             # No error message, compilation succeeded.
444             set et_fortran_large_real_saved 1
445         }
446     }
447
448     return $et_fortran_large_real_saved
449 }
450
451 # Return 1 if the target supports Fortran integer kinds larger than
452 # integer(8), 0 otherwise.  Cache the result.
453
454 proc check_effective_target_fortran_large_int { } {
455     global et_fortran_large_int_saved
456     global tool
457
458     if [info exists et_fortran_large_int_saved] {
459         verbose "check_effective_target_fortran_large_int returning saved $et_fortran_large_int_saved" 2
460     } else {
461         set et_fortran_large_int_saved 0
462
463         # Set up, compile, and execute a test program using large integer
464         # kinds.  Include the current process ID in the file names to
465         # prevent conflicts with invocations for multiple testsuites.
466         set src int[pid].f90
467         set exe int[pid].x
468
469         set f [open $src "w"]
470         puts $f "integer,parameter :: k = &"
471         puts $f "  selected_int_kind (range (0_8) + 1)"
472         puts $f "integer(kind=k) :: i"
473         puts $f "end"
474         close $f
475
476         verbose "check_effective_target_fortran_large_int compiling testfile $src" 2
477         set lines [${tool}_target_compile $src $exe executable ""]
478         file delete $src
479
480         if [string match "" $lines] then {
481             # No error message, compilation succeeded.
482             set et_fortran_large_int_saved 1
483         }
484     }
485
486     return $et_fortran_large_int_saved
487 }
488
489 # Return 1 if the target supports executing AltiVec instructions, 0
490 # otherwise.  Cache the result.
491
492 proc check_vmx_hw_available { } {
493     global vmx_hw_available_saved
494     global tool
495
496     if [info exists vmx_hw_available_saved] {
497         verbose "check_hw_available  returning saved $vmx_hw_available_saved" 2
498     } else {
499         set vmx_hw_available_saved 0
500
501         # Some simulators are known to not support VMX instructions.
502         if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
503             verbose "check_hw_available  returning 0" 2
504             return $vmx_hw_available_saved
505         }
506
507         # Set up, compile, and execute a test program containing VMX
508         # instructions.  Include the current process ID in the file
509         # names to prevent conflicts with invocations for multiple
510         # testsuites.
511         set src vmx[pid].c
512         set exe vmx[pid].x
513
514         set f [open $src "w"]
515         puts $f "int main() {"
516         puts $f "#ifdef __MACH__"
517         puts $f "  asm volatile (\"vor v0,v0,v0\");"
518         puts $f "#else"
519         puts $f "  asm volatile (\"vor 0,0,0\");"
520         puts $f "#endif"
521         puts $f "  return 0; }"
522         close $f
523
524         # Most targets don't require special flags for this test case, but
525         # Darwin does.
526         if [istarget *-*-darwin*] {
527           set opts "additional_flags=-maltivec"
528         } else {
529           set opts ""
530         }
531
532         verbose "check_vmx_hw_available  compiling testfile $src" 2
533         set lines [${tool}_target_compile $src $exe executable "$opts"]
534         file delete $src
535
536         if [string match "" $lines] then {
537             # No error message, compilation succeeded.
538             set result [${tool}_load "./$exe" "" ""]
539             set status [lindex $result 0]
540             remote_file build delete $exe
541             verbose "check_vmx_hw_available testfile status is <$status>" 2
542
543             if { $status == "pass" } then {
544                 set vmx_hw_available_saved 1
545             }
546         } else {
547             verbose "check_vmx_hw_availalble testfile compilation failed" 2
548         }
549     }
550
551     return $vmx_hw_available_saved
552 }
553
554 # GCC 3.4.0 for powerpc64-*-linux* included an ABI fix for passing
555 # complex float arguments.  This affects gfortran tests that call cabsf
556 # in libm built by an earlier compiler.  Return 1 if libm uses the same
557 # argument passing as the compiler under test, 0 otherwise.
558 #
559 # When the target name changes, replace the cached result.
560
561 proc check_effective_target_broken_cplxf_arg { } {
562     global et_broken_cplxf_arg_saved
563     global et_broken_cplxf_arg_target_name
564     global tool
565
566     # Skip the work for targets known not to be affected.
567     if { ![istarget powerpc64-*-linux*] } {
568         return 0
569     } elseif { [is-effective-target ilp32] } {
570         return 0
571     }
572
573     if { ![info exists et_broken_cplxf_arg_target_name] } {
574         set et_broken_cplxf_arg_target_name ""
575     }
576
577     # If the target has changed since we set the cached value, clear it.
578     set current_target [current_target_name]
579     if { $current_target != $et_broken_cplxf_arg_target_name } {
580         verbose "check_effective_target_broken_cplxf_arg: `$et_broken_cplxf_arg_target_name'" 2
581         set et_broken_cplxf_arg_target_name $current_target
582         if [info exists et_broken_cplxf_arg_saved] {
583             verbose "check_effective_target_broken_cplxf_arg: removing cached result" 2
584             unset et_broken_cplxf_arg_saved
585         }
586     }
587
588     if [info exists et_broken_cplxf_arg_saved] {
589         verbose "check_effective_target_broken_cplxf_arg: using cached result" 2
590     } else {
591         set et_broken_cplxf_arg_saved 0
592         # This is only known to affect one target.
593         if { ![istarget powerpc64-*-linux*] || ![is-effective-target lp64] } {
594             set et_broken_cplxf_arg_saved 0
595             verbose "check_effective_target_broken_cplxf_arg: caching 0" 2
596             return $et_broken_cplxf_arg_saved
597         }
598
599         # Set up, compile, and execute a C test program that calls cabsf.
600         set src cabsf[pid].c
601         set exe cabsf[pid].x
602
603         set f [open $src "w"]
604         puts $f "#include <complex.h>"
605         puts $f "extern void abort (void);"
606         puts $f "float fabsf (float);"
607         puts $f "float cabsf (_Complex float);"
608         puts $f "int main ()"
609         puts $f "{"
610         puts $f "  _Complex float cf;"
611         puts $f "  float f;"
612         puts $f "  cf = 3 + 4.0fi;"
613         puts $f "  f = cabsf (cf);"
614         puts $f "  if (fabsf (f - 5.0) > 0.0001) abort ();"
615         puts $f "  return 0;"
616         puts $f "}"
617         close $f
618
619         set lines [${tool}_target_compile $src $exe executable "-lm"]
620         file delete $src
621
622         if [string match "" $lines] {
623             # No error message, compilation succeeded.
624             set result [${tool}_load "./$exe" "" ""]
625             set status [lindex $result 0]
626             remote_file build delete $exe
627
628             verbose "check_effective_target_broken_cplxf_arg: status is <$status>" 2
629
630             if { $status != "pass" } {
631                 set et_broken_cplxf_arg_saved 1
632             }
633         } else {
634             verbose "check_effective_target_broken_cplxf_arg: compilation failed" 2
635         }
636     }
637     return $et_broken_cplxf_arg_saved
638 }
639
640 proc check_alpha_max_hw_available { } {
641     global alpha_max_hw_available_saved
642     global tool
643
644     if [info exists alpha_max_hw_available_saved] {
645         verbose "check_alpha_max_hw_available returning saved $alpha_max_hw_available_saved" 2
646     } else {
647         set alpha_max_hw_available_saved 0
648
649         # Set up, compile, and execute a test program probing bit 8 of the
650         # architecture mask, which indicates presence of MAX instructions.
651         set src max[pid].c
652         set exe max[pid].x
653
654         set f [open $src "w"]
655         puts $f "int main() { return __builtin_alpha_amask(1<<8) != 0; }"
656         close $f
657
658         verbose "check_alpha_max_hw_available compiling testfile $src" 2
659         set lines [${tool}_target_compile $src $exe executable ""]
660         file delete $src
661
662         if [string match "" $lines] then {
663             # No error message, compilation succeeded.
664             set result [${tool}_load "./$exe" "" ""]
665             set status [lindex $result 0]
666             remote_file build delete $exe
667             verbose "check_alpha_max_hw_available testfile status is <$status>" 2
668
669             if { $status == "pass" } then {
670                 set alpha_max_hw_available_saved 1
671             }
672         } else {
673             verbose "check_alpha_max_hw_availalble testfile compilation failed" 2
674         }
675     }
676
677     return $alpha_max_hw_available_saved
678 }
679
680 # Returns true iff the FUNCTION is available on the target system.
681 # (This is essentially a Tcl implementation of Autoconf's
682 # AC_CHECK_FUNC.)
683
684 proc check_function_available { function } {
685     set var "${function}_available_saved"
686     global $var
687     global tool
688
689     if {![info exists $var]} {
690         # Assume it exists.
691         set $var 1
692         # Check to make sure.
693         set src "function[pid].c"
694         set exe "function[pid].exe"
695
696         set f [open $src "w"]
697         puts $f "int main () { $function (); }"
698         close $f
699
700         set lines [${tool}_target_compile $src $exe executable ""]
701         file delete $src
702         file delete $exe
703
704         if {![string match "" $lines]} then {
705             set $var 0
706             verbose -log "$function is not available"
707         } else {
708             verbose -log "$function is available"
709         }
710     }
711
712     eval return \$$var
713 }
714
715 # Returns true iff "fork" is available on the target system.
716
717 proc check_fork_available {} {
718     return [check_function_available "fork"]
719 }
720
721 # Returns true iff "mkfifo" is available on the target system.
722
723 proc check_mkfifo_available {} {
724     if {[istarget *-*-cygwin*]} {
725        # Cygwin has mkfifo, but support is incomplete.
726        return 0
727      }
728
729     return [check_function_available "mkfifo"]
730 }
731
732 # Return 1 if we're generating 32-bit code using default options, 0
733 # otherwise.
734 #
735 # When the target name changes, replace the cached result.
736
737 proc check_effective_target_ilp32 { } {
738     global et_ilp32_saved
739     global et_ilp32_target_name
740
741     if { ![info exists et_ilp32_target_name] } {
742         set et_ilp32_target_name ""
743     }
744
745     # If the target has changed since we set the cached value, clear it.
746     set current_target [current_target_name]
747     if { $current_target != $et_ilp32_target_name } {
748         verbose "check_effective_target_ilp32: `$et_ilp32_target_name' `$current_target'" 2
749         set et_ilp32_target_name $current_target
750         if { [info exists et_ilp32_saved] } {
751             verbose "check_effective_target_ilp32: removing cached result" 2
752             unset et_ilp32_saved
753         }
754     }
755
756     if [info exists et_ilp32_saved] {
757         verbose "check-effective_target_ilp32: using cached result" 2
758     } else {
759         verbose "check_effective_target_ilp32: compiling source" 2
760         set et_ilp32_saved [string match "" [get_compiler_messages ilp32 object {
761             int dummy[(sizeof (int) == 4 && sizeof (void *) == 4 && sizeof (long) == 4 ) ? 1 : -1];
762         }]]
763     }
764     verbose "check_effective_target_ilp32: returning $et_ilp32_saved" 2
765     return $et_ilp32_saved
766 }
767
768 # Return 1 if we're generating 64-bit code using default options, 0
769 # otherwise.
770 #
771 # When the target name changes, replace the cached result.
772
773 proc check_effective_target_lp64 { } {
774     global et_lp64_saved
775     global et_lp64_target_name
776
777     if { ![info exists et_lp64_target_name] } {
778         set et_lp64_target_name ""
779     }
780
781     # If the target has changed since we set the cached value, clear it.
782     set current_target [current_target_name]
783     if { $current_target != $et_lp64_target_name } {
784         verbose "check_effective_target_lp64: `$et_lp64_target_name' `$current_target'" 2
785         set et_lp64_target_name $current_target
786         if [info exists et_lp64_saved] {
787             verbose "check_effective_target_lp64: removing cached result" 2
788             unset et_lp64_saved
789         }
790     }
791
792     if [info exists et_lp64_saved] {
793         verbose "check_effective_target_lp64: using cached result" 2
794     } else {
795         verbose "check_effective_target_lp64: compiling source" 2
796         set et_lp64_saved [string match "" [get_compiler_messages lp64 object {
797             int dummy[(sizeof (int) == 4 && sizeof (void *) == 8 && sizeof (long) == 8 ) ? 1 : -1];
798         }]]
799     }
800     verbose "check_effective_target_lp64: returning $et_lp64_saved" 2
801     return $et_lp64_saved
802 }
803
804 # Return 1 if the target needs a command line argument to enable a SIMD
805 # instruction set.
806 #
807 # This won't change for different subtargets so cache the result.
808
809 proc check_effective_target_vect_cmdline_needed { } {
810     global et_vect_cmdline_needed_saved
811
812     if [info exists et_vect_cmdline_needed_saved] {
813         verbose "check_effective_target_vect_cmdline_needed: using cached result" 2
814     } else {
815         set et_vect_cmdline_needed_saved 1
816         if { [istarget ia64-*-*]
817               || [istarget x86_64-*-*] } {
818            set et_vect_cmdline_needed_saved 0
819         }
820     }
821
822     verbose "check_effective_target_vect_cmdline_needed: returning $et_vect_cmdline_needed_saved" 2
823     return $et_vect_cmdline_needed_saved
824 }
825
826 # Return 1 if the target supports hardware vectors of int, 0 otherwise.
827 #
828 # This won't change for different subtargets so cache the result.
829
830 proc check_effective_target_vect_int { } {
831     global et_vect_int_saved
832
833     if [info exists et_vect_int_saved] {
834         verbose "check_effective_target_vect_int: using cached result" 2
835     } else {
836         set et_vect_int_saved 0
837         if { [istarget i?86-*-*]
838               || [istarget powerpc*-*-*]
839               || [istarget x86_64-*-*]
840               || [istarget sparc*-*-*]
841               || [istarget alpha*-*-*]
842               || [istarget ia64-*-*] } {
843            set et_vect_int_saved 1
844         }
845     }
846
847     verbose "check_effective_target_vect_int: returning $et_vect_int_saved" 2
848     return $et_vect_int_saved
849 }
850
851 # Return 1 is this is an arm target using 32-bit instructions
852 proc check_effective_target_arm32 { } {
853     global et_arm32_saved
854     global et_arm32_target_name
855     global compiler_flags
856
857     if { ![info exists et_arm32_target_name] } {
858         set et_arm32_target_name ""
859     }
860
861     # If the target has changed since we set the cached value, clear it.
862     set current_target [current_target_name]
863     if { $current_target != $et_arm32_target_name } {
864         verbose "check_effective_target_arm32: `$et_arm32_target_name' `$current_target'" 2
865         set et_arm32_target_name $current_target
866         if { [info exists et_arm32_saved] } {
867             verbose "check_effective_target_arm32: removing cached result" 2
868             unset et_arm32_saved
869         }
870     }
871
872     if [info exists et_arm32_saved] {
873         verbose "check-effective_target_arm32: using cached result" 2
874     } else {
875         set et_arm32_saved 0
876         if { [istarget arm-*-*]
877               || [istarget strongarm*-*-*]
878               || [istarget xscale-*-*] } {
879             if ![string match "*-mthumb *" $compiler_flags] {
880                 set et_arm32_saved 1
881             }
882         }
883     }
884     verbose "check_effective_target_arm32: returning $et_arm32_saved" 2
885     return $et_arm32_saved
886 }
887
888 # Return 1 if the target supports hardware vector shift operation.
889
890 proc check_effective_target_vect_shift { } {
891     if { [istarget powerpc*-*-*] } {
892         set answer 1
893     } else {
894         set answer 0
895     }
896
897     verbose "check_effective_target_vect_shift: returning $answer" 2
898     return $answer
899 }
900
901 # Return 1 if the target supports hardware vectors of long, 0 otherwise.
902 #
903 # This can change for different subtargets so do not cache the result.
904
905 proc check_effective_target_vect_long { } {
906     if { [istarget i?86-*-*]
907          || ([istarget powerpc*-*-*] && [check_effective_target_ilp32])
908          || [istarget x86_64-*-*]
909          || ([istarget sparc*-*-*] && [check_effective_target_ilp32]) } {
910         set answer 1
911     } else {
912         set answer 0
913     }
914
915     verbose "check_effective_target_vect_long: returning $answer" 2
916     return $answer
917 }
918
919 # Return 1 if the target supports hardware vectors of float, 0 otherwise.
920 #
921 # This won't change for different subtargets so cache the result.
922
923 proc check_effective_target_vect_float { } {
924     global et_vect_float_saved
925
926     if [info exists et_vect_float_saved] {
927         verbose "check_effective_target_vect_float: using cached result" 2
928     } else {
929         set et_vect_float_saved 0
930         if { [istarget i?86-*-*]
931               || [istarget powerpc*-*-*]
932               || [istarget mipsisa64*-*-*]
933               || [istarget x86_64-*-*]
934               || [istarget ia64-*-*] } {
935            set et_vect_float_saved 1
936         }
937     }
938
939     verbose "check_effective_target_vect_float: returning $et_vect_float_saved" 2
940     return $et_vect_float_saved
941 }
942
943 # Return 1 if the target supports hardware vectors of double, 0 otherwise.
944 #
945 # This won't change for different subtargets so cache the result.
946
947 proc check_effective_target_vect_double { } {
948     global et_vect_double_saved
949
950     if [info exists et_vect_double_saved] {
951         verbose "check_effective_target_vect_double: using cached result" 2
952     } else {
953         set et_vect_double_saved 0
954         if { [istarget i?86-*-*]
955               || [istarget x86_64-*-*] } {
956            set et_vect_double_saved 1
957         }
958     }
959
960     verbose "check_effective_target_vect_double: returning $et_vect_double_saved" 2
961     return $et_vect_double_saved
962 }
963
964 # Return 1 if the target plus current options does not support a vector
965 # max instruction on "int", 0 otherwise.
966 #
967 # This won't change for different subtargets so cache the result.
968
969 proc check_effective_target_vect_no_int_max { } {
970     global et_vect_no_int_max_saved
971
972     if [info exists et_vect_no_int_max_saved] {
973         verbose "check_effective_target_vect_no_int_max: using cached result" 2
974     } else {
975         set et_vect_no_int_max_saved 0
976         if { [istarget sparc*-*-*]
977              || [istarget alpha*-*-*] } {
978             set et_vect_no_int_max_saved 1
979         }
980     }
981     verbose "check_effective_target_vect_no_int_max: returning $et_vect_no_int_max_saved" 2
982     return $et_vect_no_int_max_saved
983 }
984
985 # Return 1 if the target plus current options does not support a vector
986 # add instruction on "int", 0 otherwise.
987 #
988 # This won't change for different subtargets so cache the result.
989
990 proc check_effective_target_vect_no_int_add { } {
991     global et_vect_no_int_add_saved
992
993     if [info exists et_vect_no_int_add_saved] {
994         verbose "check_effective_target_vect_no_int_add: using cached result" 2
995     } else {
996         set et_vect_no_int_add_saved 0
997         # Alpha only supports vector add on V8QI and V4HI.
998         if { [istarget alpha*-*-*] } {
999             set et_vect_no_int_add_saved 1
1000         }
1001     }
1002     verbose "check_effective_target_vect_no_int_add: returning $et_vect_no_int_add_saved" 2
1003     return $et_vect_no_int_add_saved
1004 }
1005
1006 # Return 1 if the target plus current options does not support vector
1007 # bitwise instructions, 0 otherwise.
1008 #
1009 # This won't change for different subtargets so cache the result.
1010
1011 proc check_effective_target_vect_no_bitwise { } {
1012     global et_vect_no_bitwise_saved
1013
1014     if [info exists et_vect_no_bitwise_saved] {
1015         verbose "check_effective_target_vect_no_bitwise: using cached result" 2
1016     } else {
1017         set et_vect_no_bitwise_saved 0
1018     }
1019     verbose "check_effective_target_vect_no_bitwise: returning $et_vect_no_bitwise_saved" 2
1020     return $et_vect_no_bitwise_saved
1021 }
1022
1023 # Return 1 if the target plus current options does not support a vector
1024 # alignment mechanism, 0 otherwise.
1025 #
1026 # This won't change for different subtargets so cache the result.
1027
1028 proc check_effective_target_vect_no_align { } {
1029     global et_vect_no_align_saved
1030
1031     if [info exists et_vect_no_align_saved] {
1032         verbose "check_effective_target_vect_no_align: using cached result" 2
1033     } else {
1034         set et_vect_no_align_saved 0
1035         if { [istarget mipsisa64*-*-*]
1036              || [istarget sparc*-*-*]
1037              || [istarget ia64-*-*] } {
1038             set et_vect_no_align_saved 1
1039         }
1040     }
1041     verbose "check_effective_target_vect_no_align: returning $et_vect_no_align_saved" 2
1042     return $et_vect_no_align_saved
1043 }
1044
1045 # Return 1 if the target supports vector conditional operations, 0 otherwise.
1046
1047 proc check_effective_target_vect_condition { } {
1048     global et_vect_cond_saved
1049
1050     if [info exists et_vect_int_cond] {
1051         verbose "check_effective_target_vect_cond: using cached result" 2
1052     } else {
1053         set et_vect_cond_saved 0
1054         if { [istarget powerpc*-*-*]
1055              || [istarget ia64-*-*]
1056              || [istarget i?86-*-*]
1057              || [istarget x86_64-*-*] } {
1058            set et_vect_cond_saved 1
1059         }
1060     }
1061
1062     verbose "check_effective_target_vect_cond: returning $et_vect_cond_saved" 2
1063     return $et_vect_cond_saved
1064 }
1065
1066 # Return 1 if the target supports vector int multiplication, 0 otherwise.
1067
1068 proc check_effective_target_vect_int_mult { } {
1069     global et_vect_int_mult_saved
1070
1071     if [info exists et_vect_int_mult_saved] {
1072         verbose "check_effective_target_vect_int_mult: using cached result" 2
1073     } else {
1074         set et_vect_int_mult_saved 0
1075         if { [istarget powerpc*-*-*]
1076              || [istarget i?86-*-*]
1077              || [istarget x86_64-*-*] } {
1078            set et_vect_int_mult_saved 1
1079         }
1080     }
1081
1082     verbose "check_effective_target_vect_int_mult: returning $et_vect_int_mult_saved" 2
1083     return $et_vect_int_mult_saved
1084 }
1085
1086 # Return 1 if the target supports atomic operations on "int" and "long".
1087
1088 proc check_effective_target_sync_int_long { } {
1089     global et_sync_int_long_saved
1090
1091     if [info exists et_sync_int_long_saved] {
1092         verbose "check_effective_target_sync_int_long: using cached result" 2
1093     } else {
1094         set et_sync_int_long_saved 0
1095 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
1096 # load-reserved/store-conditional instructions.
1097         if { [istarget ia64-*-*]
1098              || [istarget i?86-*-*]
1099              || [istarget x86_64-*-*]
1100              || [istarget alpha*-*-*] 
1101              || [istarget s390*-*-*] 
1102              || [istarget powerpc*-*-*] } {
1103            set et_sync_int_long_saved 1
1104         }
1105     }
1106
1107     verbose "check_effective_target_sync_int_long: returning $et_sync_int_long_saved" 2
1108     return $et_sync_int_long_saved
1109 }
1110
1111 # Return 1 if the target supports atomic operations on "char" and "short".
1112
1113 proc check_effective_target_sync_char_short { } {
1114     global et_sync_char_short_saved
1115
1116     if [info exists et_sync_char_short_saved] {
1117         verbose "check_effective_target_sync_char_short: using cached result" 2
1118     } else {
1119         set et_sync_char_short_saved 0
1120 # This is intentionally powerpc but not rs6000, rs6000 doesn't have the
1121 # load-reserved/store-conditional instructions.
1122         if { [istarget ia64-*-*]
1123              || [istarget i?86-*-*]
1124              || [istarget x86_64-*-*]
1125              || [istarget powerpc*-*-*] } {
1126            set et_sync_char_short_saved 1
1127         }
1128     }
1129
1130     verbose "check_effective_target_sync_char_short: returning $et_sync_char_short_saved" 2
1131     return $et_sync_char_short_saved
1132 }
1133
1134 # Return 1 if the target matches the effective target 'arg', 0 otherwise.
1135 # This can be used with any check_* proc that takes no argument and
1136 # returns only 1 or 0.  It could be used with check_* procs that take
1137 # arguments with keywords that pass particular arguments.
1138
1139 proc is-effective-target { arg } {
1140     set selected 0
1141     if { [info procs check_effective_target_${arg}] != [list] } {
1142         set selected [check_effective_target_${arg}]
1143     } else {
1144         switch $arg {
1145           "vmx_hw"         { set selected [check_vmx_hw_available] }
1146           "named_sections" { set selected [check_named_sections_available] }
1147           "gc_sections"    { set selected [check_gc_sections_available] }
1148           default          { error "unknown effective target keyword `$arg'" }
1149         }
1150     }
1151     verbose "is-effective-target: $arg $selected" 2
1152     return $selected
1153 }
1154
1155 # Return 1 if the argument is an effective-target keyword, 0 otherwise.
1156
1157 proc is-effective-target-keyword { arg } {
1158     if { [info procs check_effective_target_${arg}] != [list] } {
1159         return 1
1160     } else {
1161         # These have different names for their check_* procs.
1162         switch $arg {
1163           "vmx_hw"         { return 1 }
1164           "named_sections" { return 1 }
1165           "gc_sections"    { return 1 }
1166           default          { return 0 }
1167         }
1168     }
1169 }