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