]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gcc.target/mips/mips.exp
extend.texi: (micromips, nomicromips, nocompression): Document new function attributes.
[thirdparty/gcc.git] / gcc / testsuite / gcc.target / mips / mips.exp
1 # Copyright (C) 1997-2013 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with GCC; see the file COPYING3. If not see
15 # <http://www.gnu.org/licenses/>.
16
17 # A MIPS version of the GCC dg.exp driver.
18 #
19 # There are many MIPS features that we want to test, and many of those
20 # features are specific to certain architectures, certain ABIs and so on.
21 # There are therefore many cases in which we want to test something that
22 # is incompatible with the user's chosen test options.
23 #
24 # In most dg testsuites, the options added by dg-options have a lower
25 # priority than the options chosen by the user. For example, if a test
26 # specifies:
27 #
28 # { dg-options "-mips1" }
29 #
30 # and the user passes the following option to runtest:
31 #
32 # --target_board unix/-mips3
33 #
34 # the test would be compiled as MIPS III rather than MIPS I. If the
35 # test really wouldn't work with -mips3, normal practice would be to
36 # have something like:
37 #
38 # { dg-do compile { target can_force_mips1 } }
39 #
40 # so that the test is skipped when an option like -mips3 is passed.
41 #
42 # Sticking to the same approach here would cause us to skip many tests,
43 # even though the toolchain can generate the required code. For example,
44 # there are 6 MIPS ABIs, plus variants. Some configurations support
45 # more than one ABI, so it is natural to use something like:
46 #
47 # --target_board unix{-mabi=n32,-mabi=32,-mabi=64}
48 #
49 # when testing them. But these -mabi=* options would normally prevent any
50 # EABI and o64 tests from running.
51 #
52 # This testsuite therefore defines a local version of dg-options that
53 # overrides any user options that are incompatible with the test options.
54 # It tries to keep the other user options intact.
55 #
56 #
57 # Most of the tests in this testsuite are scan-assembler tests, but
58 # sometimes we need a link test instead. In these cases, we must not
59 # try to link code with options that are incompatible with the current
60 # multilib, because xgcc is passed -L and -B options that are specific
61 # to that multilib.
62 #
63 # Normal GCC practice would be to skip incompatible link tests as
64 # unsupported, but in this particular case, it seems better to downgrade
65 # them to an assemble test instead. At least that way we get some
66 # test-for-ICE and code-sanity coverage.
67 #
68 # The same problem applies to run tests. If a test requires runtime
69 # support for a particular feature, and if the current target does not
70 # provide that support, normal practice would be to skip the test.
71 # But in this case it seems better to downgrade it to a link test instead.
72 # (We might then have to downgrade it to an assembler test according to
73 # the constraints just mentioned.)
74 #
75 # The local dg-options therefore checks whether the new options are
76 # link-compatiable with the user's options. If not, it automatically
77 # downgrades link tests to assemble tests. It does the same for run
78 # tests, but in addition, it downgrades run tests to link tests if the
79 # target does not provide runtime support for a required feature or ASE.
80 #
81 #
82 # Another problem is that many of the options we want to test require
83 # certain other features. For example, -mips3d requires both 64-bit
84 # FPRs and a MIPS32 or MIPS64 target; -mfix-r10000 requires branch-
85 # likely instructions; and so on. We could handle this by specifying
86 # a set of options that are guaranteed to give us what we want, such as:
87 #
88 # dg-options "-mips3d -mpaired-single -mhard-float -mgp64 -mfp64 -mabi=n32 -march=mips64 -mips64"
89 #
90 # With the new dg-options semantics, this would override any troublesome
91 # user options like -mips3, -march=vr4100, -mfp32, -mgp32, -msoft-float,
92 # -mno-paired-single and so on. But there are three major problems with
93 # this:
94 #
95 # - It is easy to forget options.
96 #
97 # - If a new option is added, all tests that are incompatible with that
98 # option must be updated.
99 #
100 # - We want to be able to test MIPS-3D with things like -march=mips32,
101 # -march=mips64r2, -march=sb1, and so on.
102 #
103 # The local version of dg-options therefore works out the requirements
104 # of each test option. As with the test options themselves, the local
105 # dg-options overrides any user options that incompatible with these
106 # requirements, but it keeps the other user options the same.
107 #
108 # For example, if the user passes -mips3, a MIPS-3D test will choose
109 # a different architecture like -mips64 instead. But if the user
110 # passes -march=sb1, MIPS-3D tests will be run with that option.
111 #
112 #
113 # Sometimes it is useful to say "I want an environment that is compatible
114 # with option X, but I don't want to pass option X itself". The main example
115 # of this is -mips16: we want to be able to test __attribute__((mips16))
116 # without requiring the test itself to be compiled as -mips16. The local
117 # version of dg-options lets you do this by putting X in parentheses.
118 # For example:
119 #
120 # { dg-options "(-mips16)" }
121 #
122 # selects a MIPS16-compatible target without passing -mips16 itself.
123 #
124 # It is also useful to say "any architecture within this ISA range is fine".
125 # This can be done using special pseudo-options of the form:
126 #
127 # PROP=VALUE PROP<=VALUE PROP>=VALUE
128 #
129 # where PROP can be:
130 #
131 # isa:
132 # the value of the __mips macro.
133 #
134 # isa_rev:
135 # the value of the __mips_isa_rev macro, or 0 if it isn't defined.
136 #
137 # For example, "isa_rev>=1" selects a MIPS32 or MIPS64 processor,
138 # "isa=4" selects a MIPS IV processor, and so on.
139 #
140 # There are also the following special pseudo-options:
141 #
142 # isa=loongson
143 # select a Loongson processor
144 #
145 # addressing=absolute
146 # force absolute addresses to be used
147 #
148 # forbid_cpu=REGEXP
149 # forbid processors that match the given regexp; choose a
150 # generic ISA instead.
151 #
152 #
153 # In summary:
154 #
155 # (1) Try to avoid { target ... } requirements wherever possible.
156 # Specify the requirements as dg-options instead.
157 #
158 # (2) Don't worry about the consequences of (1) for link and run tests.
159 # If the test uses { dg-do link } or { dg-do run }, and its
160 # dg-options are incompatible with the current target, the
161 # testsuite will downgrade them where necessary.
162 #
163 # (3) Try to use the bare minimum of options and leave dg-options
164 # to work out the dependencies. For example, if you want
165 # a MIPS-3D test, you should generally just specify -mips3d.
166 # Don't specify an architecture option like -mips64 unless
167 # the test really doesn't work with -mips32r2, -mips64r2,
168 # -march=sb1, etc.
169 #
170 # (4) If you want something compatible with a particular option,
171 # but don't want to pass the option itself, wrap that option
172 # in parentheses. In particular, pass '(-mips16)' if you
173 # want to use "mips16" attributes.
174 #
175 # (5) When testing a feature of a generic ISA (as opposed to a
176 # processor-specific extension), try to use the "isa" and
177 # "isa_rev" pseudo-options instead of specific architecture
178 # options. For example, if the feature is present on revision 2
179 # processors and above, try to use "isa_rev>=2" instead of
180 # "-mips32r2" or "-mips64r2".
181 #
182 # (6) If you need to disable processor-specific extensions use
183 # forbid_cpu=REGEXP instead of forcing a generic ISA.
184 #
185 #
186 # Terminology
187 #
188 # Option group or just group:
189 # See comment before mips_option_groups.
190 #
191 # Test options:
192 # The options specified in dg-options.
193 #
194 # Explicit options:
195 # The options that were either passed to runtest as "multilib" options
196 # (e.g. -mips4 in --target_board=mips-sim-idt/-mips4) or specified as
197 # test options. Note that options in parenthesis (i.e. (-mips16)) are
198 # not explicit and can be omitted depending on the base options.
199 #
200 # Base options:
201 # Options that are on by default without being specified in dg-options,
202 # e.g. -march=mips64r2 for mipsisa64r2-elf or because they've been
203 # passed to runtest as "multilib" options.
204 #
205 # Option array:
206 # Many functions in this file work with option arrays. These are
207 # two-dimensional Tcl arrays where the first dimension can have three
208 # values: option, explicit_p or test_option_p. The second dimension is
209 # the name of the option group. "option" contains the name of the
210 # option that is in effect from this group. If no option is active it
211 # contains the empty string. The flags "explicit_p" and "test_option_p"
212 # are set for explicit and test options.
213
214 # Exit immediately if this isn't a MIPS target.
215 if ![istarget mips*-*-*] {
216 return
217 }
218
219 # Load support procs.
220 load_lib gcc-dg.exp
221
222 # A list of GROUP REGEXP pairs. Each GROUP represents a logical group of
223 # options from which only one option should be chosen. REGEXP matches all
224 # the options in that group; it is implicitly wrapped in "^(...)$".
225 #
226 # Note that -O* is deliberately omitted from this list. Tests in this
227 # directory are run at various optimisation levels and should use
228 # dg-skip-if to skip any incompatible levels.
229 set mips_option_groups {
230 abi "-mabi=.*"
231 addressing "addressing=.*"
232 arch "-mips([1-5]|32.*|64.*)|-march=.*|isa(|_rev)(=|<=|>=).*"
233 debug "-g.*"
234 dump_pattern "-dp"
235 endianness "-E(L|B)|-me(l|b)"
236 float "-m(hard|soft)-float"
237 forbid_cpu "forbid_cpu=.*"
238 fp "-mfp(32|64)"
239 gp "-mgp(32|64)"
240 long "-mlong(32|64)"
241 micromips "-mmicromips|-mno-micromips"
242 mips16 "-mips16|-mno-mips16|-mflip-mips16"
243 mips3d "-mips3d|-mno-mips3d"
244 pic "-f(no-|)(pic|PIC)"
245 profiling "-pg"
246 small-data "-G[0-9]+"
247 warnings "-w"
248 dump "-fdump-.*"
249 }
250
251 # Add -mfoo/-mno-foo options to mips_option_groups.
252 foreach option {
253 abicalls
254 branch-likely
255 dsp
256 dspr2
257 explicit-relocs
258 extern-sdata
259 fix-r4000
260 fix-r10000
261 fix-vr4130
262 gpopt
263 local-sdata
264 long-calls
265 paired-single
266 plt
267 shared
268 smartmips
269 sym32
270 synci
271 relax-pic-calls
272 mcount-ra-address
273 } {
274 lappend mips_option_groups $option "-m(no-|)$option"
275 }
276
277 # Add -mfoo= options to mips_option_groups.
278 foreach option {
279 branch-cost
280 code-readable
281 r10k-cache-barrier
282 tune
283 } {
284 lappend mips_option_groups $option "-m$option=.*"
285 }
286
287 # Add -ffoo/-fno-foo options to mips_option_groups.
288 foreach option {
289 delayed-branch
290 expensive-optimizations
291 fast-math
292 fat-lto-objects
293 finite-math-only
294 fixed-hi
295 fixed-lo
296 lax-vector-conversions
297 omit-frame-pointer
298 optimize-sibling-calls
299 peephole2
300 schedule-insns2
301 split-wide-types
302 tree-vectorize
303 unroll-all-loops
304 unroll-loops
305 } {
306 lappend mips_option_groups $option "-f(no-|)$option"
307 }
308
309 # A list of option groups that have an impact on the ABI.
310 set mips_abi_groups {
311 abi
312 abicalls
313 arch
314 endianness
315 float
316 fp
317 gp
318 gpopt
319 long
320 pic
321 small-data
322 }
323
324 # mips_option_tests(OPTION) is some assembly code that will run to completion
325 # on a target that supports OPTION.
326 set mips_option_tests(-mips16) {
327 move $2,$31
328 bal 1f
329 .set mips16
330 jr $31
331 .set nomips16
332 .align 2
333 1:
334 ori $3,$31,1
335 jalr $3
336 move $31,$2
337 }
338 set mips_option_tests(-mpaired-single) {
339 .set mips64
340 lui $2,0x3f80
341 mtc1 $2,$f0
342 cvt.ps.s $f2,$f0,$f0
343 }
344 set mips_option_tests(-mips3d) {
345 .set mips64
346 .set mips3d
347 lui $2,0x3f80
348 mtc1 $2,$f0
349 cvt.ps.s $f2,$f0,$f0
350 mulr.ps $f2,$f2,$f2
351 rsqrt1.s $f2,$f0
352 mul.s $f4,$f2,$f0
353 rsqrt2.s $f4,$f4,$f2
354 madd.s $f4,$f2,$f2,$f4
355 }
356 set mips_option_tests(-mdsp) {
357 .set mips64r2
358 .set dsp
359 addsc $2,$2,$2
360 }
361 set mips_option_tests(-mdspr2) {
362 .set mips64r2
363 .set dspr2
364 prepend $2,$3,11
365 }
366
367 # Canonicalize command-line option OPTION.
368 proc mips_canonicalize_option { option } {
369 regsub {^-mips([1-5]|32*|64*)$} $option {-march=mips\1} option
370
371 regsub {^-mel$} $option {-EL} option
372 regsub {^-meb$} $option {-EB} option
373
374 regsub {^-O$} $option {-O1} option
375
376 # MIPS doesn't use -fpic and -fPIC to distinguish between code models.
377 regsub {^-f(no-|)PIC} $option {-f\1pic} option
378
379 return $option
380 }
381
382 # Return true if OPTION1 and OPTION2 represent the same command-line option.
383 proc mips_same_option_p { option1 option2 } {
384 return [string equal \
385 [mips_canonicalize_option $option1] \
386 [mips_canonicalize_option $option2]]
387 }
388
389 # Preprocess CODE using target_compile options OPTIONS. Return the
390 # compiler output.
391 proc mips_preprocess { options code } {
392 global tool
393
394 set src dummy[pid].c
395 set f [open $src "w"]
396 puts $f $code
397 close $f
398 set output [${tool}_target_compile $src "" preprocess $options]
399 file delete $src
400
401 return $output
402 }
403
404 # Set the target board's command-line options to NEW_OPTIONS, storing the
405 # old values in UPVAR.
406 proc mips_push_test_options { upvar new_options } {
407 upvar $upvar var
408 global board_info
409
410 array unset var
411 set var(name) board_info([target_info name],multilib_flags)
412 if { [info exists $var(name)] } {
413 set var(old_options) [set $var(name)]
414 set $var(name) [join $new_options " "]
415 }
416 }
417
418 # Undo the effects of [mips_push_test_options UPVAR ...]
419 proc mips_pop_test_options { upvar } {
420 upvar $upvar var
421 global board_info
422
423 if { [info exists var(old_options)] } {
424 set $var(name) $var(old_options)
425 }
426 }
427
428 # Return property PROP for architecture option ARCH (which belongs to
429 # the "arch" group in mips_option_groups). See the comment at the
430 # top of the file for the valid property names.
431 #
432 # Cache the results in mips_arch_info (which can be reused between test
433 # variants).
434 proc mips_arch_info { arch prop } {
435 global mips_arch_info
436 global board_info
437
438 set arch [mips_canonicalize_option $arch]
439 if { ![info exists mips_arch_info($arch,$prop)] } {
440 mips_push_test_options saved_options {}
441 set output [mips_preprocess [list "additional_flags=$arch -mabi=32"] {
442 int isa = __mips;
443 #ifdef __mips_isa_rev
444 int isa_rev = __mips_isa_rev;
445 #else
446 int isa_rev = 0;
447 #endif
448 }]
449 foreach lhs { isa isa_rev } {
450 regsub ".*$lhs = (\[^;\]*).*" $output {\1} rhs
451 verbose -log "Architecture $arch has $lhs $rhs"
452 set mips_arch_info($arch,$lhs) $rhs
453 }
454 mips_pop_test_options saved_options
455 }
456 return $mips_arch_info($arch,$prop)
457 }
458
459 # Return the option group associated with OPTION, or "" if none.
460 proc mips_option_maybe_group { option } {
461 global mips_option_groups
462
463 foreach { group regexp } $mips_option_groups {
464 if { [regexp -- "^($regexp)\$" $option] } {
465 return $group
466 }
467 }
468 return ""
469 }
470
471 # Return the option group associated with OPTION. Raise an error if
472 # there is none.
473 proc mips_option_group { option } {
474 set group [mips_option_maybe_group $option]
475 if { [string equal $group ""] } {
476 error "Unrecognised option: $option"
477 }
478 return $group
479 }
480
481 # Return the option for option group GROUP, or "" if no option in that
482 # group has been chosen. UPSTATUS describes the option status.
483 proc mips_option { upstatus group } {
484 upvar $upstatus status
485
486 return $status(option,$group)
487 }
488
489 # If the base options for this test run include an option in group GROUP,
490 # return that option, otherwise return "".
491 proc mips_original_option { group } {
492 global mips_base_options
493
494 return [mips_option mips_base_options $group]
495 }
496
497 # Return true if the test described by UPSTATUS requires a specific
498 # option in group GROUP. UPSTATUS describes the option status.
499 proc mips_test_option_p { upstatus group } {
500 upvar $upstatus status
501
502 return $status(test_option_p,$group)
503 }
504
505 # If the test described by UPSTATUS requires a particular option in group
506 # GROUP, return that option, otherwise return "".
507 proc mips_test_option { upstatus group } {
508 upvar $upstatus status
509
510 if { [mips_test_option_p status $group] } {
511 return [mips_option status $group]
512 } else {
513 return ""
514 }
515 }
516
517 # Return true if the options described by UPSTATUS include OPTION.
518 proc mips_have_option_p { upstatus option } {
519 upvar $upstatus status
520
521 return [mips_same_option_p \
522 [mips_option status [mips_option_group $option]] \
523 $option]
524 }
525
526 # Return true if the options described by UPSTATUS require MIPS16 support.
527 proc mips_using_mips16_p { upstatus } {
528 upvar $upstatus status
529
530 return [expr { [mips_have_option_p status "-mips16"]
531 || [mips_have_option_p status "-mflip-mips16"] }]
532 }
533
534 # Return true if the test described by UPSTATUS requires option OPTION.
535 proc mips_have_test_option_p { upstatus option } {
536 upvar $upstatus status
537
538 set group [mips_option_group $option]
539 return [mips_same_option_p [mips_test_option status $group] $option]
540 }
541
542 # If the test described by UPSTATUS does not specify an option in
543 # OPTION's group, act as though it had specified OPTION.
544 #
545 # The first optional argument indicates whether the option should be
546 # treated as though it were wrapped in parentheses; see the comment at
547 # the top of the file for details about this convention. The default is 0.
548 proc mips_make_test_option { upstatus option args } {
549 upvar $upstatus status
550
551 set group [mips_option_group $option]
552 if { ![mips_test_option_p status $group] } {
553 set status(option,$group) $option
554 set status(test_option_p,$group) 1
555 if { [llength $args] == 0 || ![lindex $args 0] } {
556 set status(explicit_p,$group) 1
557 }
558 }
559 }
560
561 # If the test described by UPSTATUS requires option FROM, assume that
562 # it implicitly requires option TO.
563 proc mips_option_dependency { upstatus from to } {
564 upvar $upstatus status
565
566 if { [mips_have_test_option_p status $from] } {
567 mips_make_test_option status $to
568 }
569 }
570
571 # Return true if the given arch-group option specifies a 32-bit ISA.
572 proc mips_32bit_arch_p { option } {
573 set isa [mips_arch_info $option isa]
574 return [expr { $isa < 3 || $isa == 32 }]
575 }
576
577 # Return true if the given arch-group option specifies a 64-bit ISA.
578 proc mips_64bit_arch_p { option } {
579 return [expr { ![mips_32bit_arch_p $option] }]
580 }
581
582 # Return true if the given abi-group option implicitly requires -mgp32.
583 proc mips_32bit_abi_p { option } {
584 switch -glob -- $option {
585 -mabi=32 {
586 return 1
587 }
588 }
589 return 0
590 }
591
592 # Return true if the given abi-group option implicitly requires -mgp64.
593 proc mips_64bit_abi_p { option } {
594 switch -glob -- $option {
595 -mabi=o64 -
596 -mabi=n32 -
597 -mabi=64 {
598 return 1
599 }
600 }
601 return 0
602 }
603
604 # Return true if the given abi-group option implicitly requires -mlong32.
605 # o64 requires this for -mabicalls, but not otherwise; pick the conservative
606 # case for simplicity.
607 proc mips_long32_abi_p { option } {
608 switch -glob -- $option {
609 -mabi=o64 -
610 -mabi=n32 -
611 -mabi=32 {
612 return 1
613 }
614 }
615 return 0
616 }
617
618 # Return true if the given abi-group option implicitly requires -mlong64.
619 proc mips_long64_abi_p { option } {
620 switch -glob -- $option {
621 -mabi=64 {
622 return 1
623 }
624 }
625 return 0
626 }
627
628 # Check whether the current target supports all the options that the
629 # current test requires. Return "" if so, otherwise return one of
630 # the incompatible options. UPSTATUS describes the option status.
631 proc mips_first_unsupported_option { upstatus } {
632 global mips_option_tests
633 upvar $upstatus status
634
635 foreach { option code } [array get mips_option_tests] {
636 if { [mips_have_test_option_p status $option] } {
637 regsub -all "\n" $code "\\n\\\n" asm
638 # Use check_runtime from target-supports.exp, which caches
639 # the result for us.
640 if { ![check_runtime mips_option_$option [subst {
641 __attribute__((nomips16)) int
642 main (void)
643 {
644 asm (".set push\
645 $asm\
646 .set pop");
647 return 0;
648 }
649 }]] } {
650 return $option
651 }
652 }
653 }
654 return ""
655 }
656
657 # Initialize this testsuite for a new test variant.
658 proc mips-dg-init {} {
659 # Invariant information.
660 global mips_option_groups
661
662 # Internally-generated information about this run.
663 global mips_base_options
664 global mips_extra_options
665
666 # Override dg-options with our mips-dg-options routine.
667 rename dg-options mips-old-dg-options
668 rename mips-dg-options dg-options
669
670 # Start with a fresh option status.
671 array unset mips_base_options
672 foreach { group regexp } $mips_option_groups {
673 set mips_base_options(option,$group) ""
674 set mips_base_options(explicit_p,$group) 0
675 set mips_base_options(test_option_p,$group) 0
676 }
677
678 # Use preprocessor macros to work out as many implicit options as we can.
679 set output [mips_preprocess "" {
680 const char *options[] = {
681 #if !defined _MIPS_SIM
682 "-mabi=eabi",
683 #elif _MIPS_SIM==_ABIO32
684 "-mabi=32",
685 #elif _MIPS_SIM==_ABIO64
686 "-mabi=o64",
687 #elif _MIPS_SIM==_ABIN32
688 "-mabi=n32",
689 #else
690 "-mabi=64",
691 #endif
692
693 "-march=" _MIPS_ARCH,
694
695 #ifdef _MIPSEB
696 "-EB",
697 #else
698 "-EL",
699 #endif
700
701 #ifdef __mips_hard_float
702 "-mhard-float",
703 #else
704 "-msoft-float",
705 #endif
706
707 #if __mips_fpr == 64
708 "-mfp64",
709 #else
710 "-mfp32",
711 #endif
712
713 #ifdef __mips64
714 "-mgp64",
715 #else
716 "-mgp32",
717 #endif
718
719 #if _MIPS_SZLONG == 64
720 "-mlong64",
721 #else
722 "-mlong32",
723 #endif
724
725 #ifdef __mips16
726 "-mips16",
727 #else
728 "-mno-mips16",
729 #endif
730
731 #ifdef __mips3d
732 "-mips3d",
733 #else
734 "-mno-mips3d",
735 #endif
736
737 #ifdef __mips_paired_single_float
738 "-mpaired-single",
739 #else
740 "-mno-paired-single",
741 #endif
742
743 #if __mips_abicalls
744 "-mabicalls",
745 #else
746 "-mno-abicalls",
747 #endif
748
749 #if __mips_dsp_rev >= 2
750 "-mdspr2",
751 #else
752 "-mno-dspr2",
753 #endif
754
755 #if __mips_dsp_rev >= 1
756 "-mdsp",
757 #else
758 "-mno-dsp",
759 #endif
760
761 #ifndef __PIC__
762 "addressing=absolute",
763 #endif
764
765 #ifdef __mips_smartmips
766 "-msmartmips",
767 #else
768 "-mno-smartmips",
769 #endif
770
771 #ifdef __mips_synci
772 "-msynci",
773 #else
774 "-mno-synci",
775 #endif
776
777 0
778 };
779 }]
780 foreach line [split $output "\r\n"] {
781 # Poor man's string concatenation.
782 regsub -all {" "} $line "" line
783 if { [regexp {"(.*)",} $line dummy option] } {
784 set group [mips_option_group $option]
785 set mips_base_options(option,$group) $option
786 }
787 }
788
789 # Process the target's multilib options, saving any unrecognized
790 # ones in mips_extra_options.
791 set mips_extra_options {}
792 foreach option [split [board_info target multilib_flags]] {
793 set group [mips_option_maybe_group $option]
794 if { ![string equal $group ""] } {
795 set mips_base_options(option,$group) $option
796 set mips_base_options(explicit_p,$group) 1
797 } else {
798 lappend mips_extra_options $option
799 }
800 }
801 }
802
803 # Finish a test run started by mips-dg-init.
804 proc mips-dg-finish {} {
805 rename dg-options mips-dg-options
806 rename mips-old-dg-options dg-options
807 }
808
809 # Override dg-options so that we can do some MIPS-specific processing.
810 # All options used in this testsuite must appear in mips_option_groups.
811 #
812 # Test options override multilib options. Certain test options can
813 # also imply other test options, which also override multilib options.
814 # These dependencies are ordered as follows:
815 #
816 # START END
817 # | |
818 # -mips16/-mflip-mips16 -mno-mips16
819 # | |
820 # -micromips -mno-micromips
821 # | |
822 # -mips3d -mno-mips3d
823 # | |
824 # -mpaired-single -mno-paired-single
825 # | |
826 # -mfp64 -mfp32
827 # | |
828 # -mhard-float -msoft-float
829 # | |
830 # -mno-sym32 -msym32
831 # | |
832 # -mrelax-pic-calls -mno-relax-pic-calls
833 # | |
834 # -fpic -fno-pic
835 # | |
836 # -mshared -mno-shared
837 # | |
838 # -mno-plt -mplt
839 # | |
840 # addressing=unknown addressing=absolute
841 # | |
842 # -mabicalls -mno-abicalls
843 # | |
844 # -G0 <other value>
845 # | |
846 # <other value> -mr10k-cache-barrier=none
847 # | |
848 # -mfix-r10000 -mno-fix-r10000
849 # | |
850 # -mbranch-likely -mno-branch-likely
851 # | |
852 # -msmartmips -mno-smartmips
853 # | |
854 # -mno-gpopt -mgpopt
855 # | |
856 # -mexplicit-relocs -mno-explicit-relocs
857 # | |
858 # -mdspr2 -mno-dspr2
859 # | |
860 # -mdsp -mno-dsp
861 # | |
862 # -msynci -mno-synci
863 # | |
864 # +-- gp, abi & arch ---------+
865 #
866 # For these purposes, the "gp", "abi" & "arch" option groups are treated
867 # as a single node.
868 proc mips-dg-options { args } {
869 # dg.exp variables.
870 upvar dg-extra-tool-flags extra_tool_flags
871 upvar dg-do-what do_what
872
873 # Invariant information.
874 global mips_option_groups
875 global mips_abi_groups
876
877 # Information about this run.
878 global mips_base_options
879
880 if { [llength $args] >= 3 } {
881 switch { [dg-process-target [lindex $args 2]] } {
882 "S" { }
883 "N" { return }
884 "F" { error "[lindex $args 0]: `xfail' not allowed here" }
885 "P" { error "[lindex $args 0]: `xfail' not allowed here" }
886 }
887 }
888
889 # Start out with the default option state.
890 array set options [array get mips_base_options]
891
892 # Record the options that this test explicitly needs.
893 foreach option [lindex $args 1] {
894 set all_but_p [regexp {^\((.*)\)$} $option dummy option]
895 set group [mips_option_group $option]
896 if { [mips_test_option_p options $group] } {
897 set old [mips_option options $group]
898 error "Inconsistent $group option: $old vs. $option"
899 } else {
900 mips_make_test_option options $option $all_but_p
901 }
902 }
903
904 # Handle dependencies between the test options and the optimization ones.
905 mips_option_dependency options "-fno-unroll-loops" "-fno-unroll-all-loops"
906 mips_option_dependency options "-pg" "-fno-omit-frame-pointer"
907
908 # Handle dependencies between options on the left of the
909 # dependency diagram.
910 mips_option_dependency options "-mips16" "-mno-micromips"
911 mips_option_dependency options "-mmicromips" "-mno-mips16"
912 mips_option_dependency options "-mips3d" "-mpaired-single"
913 mips_option_dependency options "-mpaired-single" "-mfp64"
914 mips_option_dependency options "-mfp64" "-mhard-float"
915 mips_option_dependency options "-mrelax-pic-calls" "-mno-plt"
916 mips_option_dependency options "-mrelax-pic-calls" "-mabicalls"
917 mips_option_dependency options "-mrelax-pic-calls" "-mexplicit-relocs"
918 mips_option_dependency options "-fpic" "-mshared"
919 mips_option_dependency options "-mshared" "-mno-plt"
920 mips_option_dependency options "-mshared" "-mabicalls"
921 mips_option_dependency options "-mno-plt" "addressing=unknown"
922 mips_option_dependency options "-mabicalls" "-G0"
923 mips_option_dependency options "-mno-gpopt" "-mexplicit-relocs"
924
925 # Work out information about the current ABI.
926 set abi_test_option_p [mips_test_option_p options abi]
927 set abi [mips_option options abi]
928 set eabi_p [mips_same_option_p $abi "-mabi=eabi"]
929
930 # If the test forces a particular ABI, set the register size
931 # accordingly.
932 if { $abi_test_option_p } {
933 if { [mips_32bit_abi_p $abi] } {
934 mips_make_test_option options "-mgp32"
935 } elseif { [mips_64bit_abi_p $abi] } {
936 mips_make_test_option options "-mgp64"
937 }
938 }
939
940 # See whether forbid_cpu forces us to choose a new architecture.
941 set arch [mips_option mips_base_options arch]
942 set force_generic_isa_p [expr {
943 [regexp "forbid_cpu=(.*)" [mips_option options forbid_cpu] dummy spec]
944 && [regexp -- "^-march=$spec\$" $arch]
945 }]
946
947 # Interpret the special "isa" and "isa_rev" options. If we have
948 # a choice of a 32-bit or a 64-bit architecture, prefer to keep
949 # the -mgp setting the same.
950 set spec [mips_option options arch]
951 if { [regexp {^[^-]} $spec] } {
952 if { [string equal $spec "isa=loongson"] } {
953 if { ![regexp {^-march=loongson} $arch] } {
954 set arch "-march=loongson2f"
955 }
956 } else {
957 if { ![regexp {^(isa(?:|_rev))(=|<=|>=)([0-9]*)$} \
958 $spec dummy prop relation value nocpus] } {
959 error "Unrecognized isa specification: $spec"
960 }
961 set current [mips_arch_info $arch $prop]
962 if { $force_generic_isa_p
963 || ($current < $value && ![string equal $relation "<="])
964 || ($current > $value && ![string equal $relation ">="])
965 || ([mips_have_test_option_p options "-mgp64"]
966 && [mips_32bit_arch_p $arch]) } {
967 # The current setting is out of range; it cannot
968 # possibly be used. Find a replacement that can.
969 if { [string equal $prop "isa"] } {
970 set arch "-mips$value"
971 } elseif { $value == 0 } {
972 set arch "-mips4"
973 } else {
974 if { [mips_have_option_p options "-mgp32"] } {
975 set arch "-mips32"
976 } else {
977 set arch "-mips64"
978 }
979 if { $value > 1 } {
980 append arch "r$value"
981 }
982 }
983 }
984 }
985 set options(option,arch) $arch
986 }
987
988 # Work out information about the current architecture.
989 set arch_test_option_p [mips_test_option_p options arch]
990 set arch [mips_option options arch]
991 set isa [mips_arch_info $arch isa]
992 set isa_rev [mips_arch_info $arch isa_rev]
993
994 # If the test forces a 32-bit architecture, force -mgp32.
995 # Force the current -mgp setting otherwise; if we don't,
996 # some configurations would make a 64-bit architecture
997 # imply -mgp64.
998 if { $arch_test_option_p } {
999 if { [mips_32bit_arch_p $arch] } {
1000 mips_make_test_option options "-mgp32"
1001 } else {
1002 mips_make_test_option options [mips_option options gp]
1003 }
1004 }
1005
1006 # We've now fixed the GP register size. Make it easily available.
1007 set gp_size [expr { [mips_have_option_p options "-mgp32"] ? 32 : 64 }]
1008
1009 # Handle dependencies between the pre-arch options and the arch option.
1010 # This should mirror the arch and post-arch code below.
1011 if { !$arch_test_option_p } {
1012 # We need a revision 2 or better ISA for:
1013 #
1014 # - the combination of -mgp32 -mfp64
1015 # - the DSP ASE
1016 if { $isa_rev < 2
1017 && (($gp_size == 32 && [mips_have_test_option_p options "-mfp64"])
1018 || [mips_have_test_option_p options "-msynci"]
1019 || [mips_have_test_option_p options "-mdsp"]
1020 || [mips_have_test_option_p options "-mdspr2"]) } {
1021 if { $gp_size == 32 } {
1022 mips_make_test_option options "-mips32r2"
1023 } else {
1024 mips_make_test_option options "-mips64r2"
1025 }
1026 # We need a MIPS32 or MIPS64 ISA for:
1027 #
1028 # - paired-single instructions(*)
1029 #
1030 # (*) Note that we don't support MIPS V at the moment.
1031 } elseif { $isa_rev < 1
1032 && [mips_have_test_option_p options "-mpaired-single"] } {
1033 if { $gp_size == 32 } {
1034 mips_make_test_option options "-mips32"
1035 } else {
1036 mips_make_test_option options "-mips64"
1037 }
1038 # We need MIPS III or higher for:
1039 #
1040 # - the "cache" instruction
1041 } elseif { $isa < 3
1042 && ([mips_have_test_option_p options \
1043 "-mr10k-cache-barrier=load-store"]
1044 || [mips_have_test_option_p options \
1045 "-mr10k-cache-barrier=store"]) } {
1046 mips_make_test_option options "-mips3"
1047 # We need MIPS II or higher for:
1048 #
1049 # - branch-likely instructions(*)
1050 #
1051 # (*) needed by both -mbranch-likely and -mfix-r10000
1052 } elseif { $isa < 2
1053 && ([mips_have_test_option_p options "-mbranch-likely"]
1054 || [mips_have_test_option_p options "-mfix-r10000"]) } {
1055 mips_make_test_option options "-mips2"
1056 # Check whether we need to switch from a 32-bit processor to the
1057 # "nearest" 64-bit processor.
1058 } elseif { $gp_size == 64 && [mips_32bit_arch_p $arch] } {
1059 if { $isa_rev == 0 } {
1060 mips_make_test_option options "-mips3"
1061 } elseif { $isa_rev == 1 } {
1062 mips_make_test_option options "-mips64"
1063 } else {
1064 mips_make_test_option options "-mips64r$isa_rev"
1065 }
1066 # Otherwise, if the current choice of architecture is unacceptable,
1067 # choose the equivalent generic architecture.
1068 } elseif { $force_generic_isa_p } {
1069 set arch "-mips[mips_arch_info $arch isa]"
1070 if { $isa_rev > 1 } {
1071 append arch "r$isa_rev"
1072 }
1073 mips_make_test_option options $arch
1074 }
1075 unset arch
1076 unset isa
1077 unset isa_rev
1078 }
1079
1080 # Set an appropriate ABI, handling dependencies between the pre-abi
1081 # options and the abi options. This should mirror the abi and post-abi
1082 # code below.
1083 if { !$abi_test_option_p } {
1084 if { ($eabi_p
1085 && ([mips_have_option_p options "-mabicalls"]
1086 || ($gp_size == 32
1087 && [mips_have_option_p options "-mfp64"]))) } {
1088 # EABI doesn't support -mabicalls.
1089 # EABI doesn't support the combination -mgp32 -mfp64.
1090 set force_abi 1
1091 } elseif { [mips_using_mips16_p options]
1092 && ![mips_same_option_p $abi "-mabi=32"]
1093 && ![mips_same_option_p $abi "-mabi=o64"]
1094 && (![mips_have_option_p options "addressing=absolute"]
1095 || [mips_have_option_p options "-mhard-float"]) } {
1096 # -mips16 -mhard-float requires o32 or o64.
1097 # -mips16 PIC requires o32 or o64.
1098 set force_abi 1
1099 } elseif { [mips_have_test_option_p options "-mlong32"]
1100 && [mips_long64_abi_p $abi] } {
1101 set force_abi 1
1102 } elseif { [mips_have_test_option_p options "-mlong64"]
1103 && [mips_long32_abi_p $abi] } {
1104 set force_abi 1
1105 } else {
1106 set force_abi 0
1107 }
1108 if { $gp_size == 32 } {
1109 if { $force_abi || [mips_64bit_abi_p $abi] } {
1110 if { [mips_have_test_option_p options "-mlong64"] } {
1111 mips_make_test_option options "-mabi=eabi"
1112 mips_make_test_option options "-mgp32"
1113 } else {
1114 mips_make_test_option options "-mabi=32"
1115 }
1116 }
1117 } else {
1118 if { $force_abi || [mips_32bit_abi_p $abi] } {
1119 if { [mips_have_test_option_p options "-mlong64"] } {
1120 mips_make_test_option options "-mabi=eabi"
1121 mips_make_test_option options "-mgp64"
1122 } else {
1123 # All configurations should have an assembler that
1124 # supports o64, since it requires the same BFD target
1125 # vector as o32. In contrast, many assembler
1126 # configurations do not have n32 or n64 support.
1127 mips_make_test_option options "-mabi=o64"
1128 }
1129 }
1130 }
1131 set abi_test_option_p [mips_test_option_p options abi]
1132 set abi [mips_option options abi]
1133 set eabi_p [mips_same_option_p $abi "-mabi=eabi"]
1134 }
1135
1136 # Handle dependencies between the abi options and the post-abi options.
1137 # This should mirror the abi and pre-abi code above.
1138 if { $abi_test_option_p } {
1139 if { $eabi_p } {
1140 mips_make_test_option options "-mno-abicalls"
1141 if { $gp_size == 32 } {
1142 mips_make_test_option options "-mfp32"
1143 }
1144 }
1145 if { [mips_using_mips16_p options]
1146 && ![mips_same_option_p $abi "-mabi=32"]
1147 && ![mips_same_option_p $abi "-mabi=o64"]
1148 && (![mips_have_option_p options "addressing=absolute"]
1149 || [mips_have_option_p options "-mhard-float"]) } {
1150 if { [mips_test_option_p options mips16] } {
1151 mips_make_test_option options "addressing=absolute"
1152 mips_make_test_option options "-msoft-float"
1153 } else {
1154 mips_make_test_option options "-mno-mips16"
1155 }
1156 }
1157 if { [mips_long32_abi_p $abi] } {
1158 mips_make_test_option options "-mlong32"
1159 } elseif { [mips_long64_abi_p $abi] } {
1160 mips_make_test_option options "-mlong64"
1161 }
1162 }
1163
1164 # Handle dependencies between the arch option and the post-arch options.
1165 # This should mirror the arch and pre-arch code above.
1166 if { $arch_test_option_p } {
1167 if { $isa < 2 } {
1168 mips_make_test_option options "-mno-branch-likely"
1169 mips_make_test_option options "-mno-fix-r10000"
1170 }
1171 if { $isa < 3 } {
1172 mips_make_test_option options "-mr10k-cache-barrier=none"
1173 }
1174 if { $isa_rev < 1 } {
1175 mips_make_test_option options "-mno-paired-single"
1176 }
1177 if { $isa_rev < 2 } {
1178 if { $gp_size == 32 } {
1179 mips_make_test_option options "-mfp32"
1180 }
1181 mips_make_test_option options "-mno-dsp"
1182 mips_make_test_option options "-mno-synci"
1183 }
1184 unset arch
1185 unset isa
1186 unset isa_rev
1187 }
1188
1189 # Handle dependencies between options on the right of the diagram.
1190 mips_option_dependency options "-mno-dsp" "-mno-dspr2"
1191 mips_option_dependency options "-mno-explicit-relocs" "-mgpopt"
1192 switch -- [mips_test_option options small-data] {
1193 "" -
1194 -G0 {}
1195 default {
1196 mips_make_test_option options "-mno-abicalls"
1197 }
1198 }
1199 if { [mips_have_option_p options "-mabicalls"] } {
1200 mips_option_dependency options "addressing=absolute" "-mplt"
1201 }
1202 mips_option_dependency options "-mplt" "-msym32"
1203 mips_option_dependency options "-mplt" "-mno-shared"
1204 mips_option_dependency options "-mno-shared" "-fno-pic"
1205 mips_option_dependency options "-mfp32" "-mno-paired-single"
1206 mips_option_dependency options "-msoft-float" "-mno-paired-single"
1207 mips_option_dependency options "-mno-paired-single" "-mno-mips3d"
1208
1209 # If the test requires an unsupported option, change run tests
1210 # to link tests.
1211
1212 switch -- [lindex $do_what 0] {
1213 run {
1214 set option [mips_first_unsupported_option options]
1215 if { ![string equal $option ""] } {
1216 set do_what [lreplace $do_what 0 0 link]
1217 verbose -log "Downgraded to a 'link' test due to unsupported option '$option'"
1218 }
1219 }
1220 }
1221
1222 # If the test has overridden a option that changes the ABI,
1223 # downgrade a link or execution test to an assembler test.
1224 foreach group $mips_abi_groups {
1225 set old_option [mips_original_option $group]
1226 set new_option [mips_option options $group]
1227 if { ![mips_same_option_p $old_option $new_option] } {
1228 switch -- [lindex $do_what 0] {
1229 link -
1230 run {
1231 set do_what [lreplace $do_what 0 0 assemble]
1232 verbose -log "Downgraded to an 'assemble' test due to incompatible $group option ($old_option changed to $new_option)"
1233 }
1234 }
1235 break
1236 }
1237 }
1238
1239 # Add all options to the dg variable.
1240 set options(explicit_p,addressing) 0
1241 set options(explicit_p,forbid_cpu) 0
1242 foreach { group regexp } $mips_option_groups {
1243 if { $options(explicit_p,$group) } {
1244 append extra_tool_flags " " $options(option,$group)
1245 }
1246 }
1247
1248 # If the test is MIPS16-compatible, provide a counterpart to the
1249 # NOMIPS16 convenience macro.
1250 if { [mips_have_test_option_p options "-mips16"] } {
1251 append extra_tool_flags " -DMIPS16=__attribute__((mips16))"
1252 }
1253
1254 if { [mips_have_test_option_p options "-mmicromips"] } {
1255 append extra_tool_flags " -DMICROMIPS=__attribute__((micromips))"
1256 }
1257
1258 # Use our version of gcc-dg-test for this test.
1259 if { ![string equal [info procs "mips-gcc-dg-test"] ""] } {
1260 rename gcc-dg-test mips-old-gcc-dg-test
1261 rename mips-gcc-dg-test gcc-dg-test
1262 }
1263 }
1264
1265 # A version of gcc-dg-test that is used by dg-options tests.
1266 proc mips-gcc-dg-test { prog do_what extra_tool_flags } {
1267 global board_info
1268 global mips_extra_options
1269
1270 # Override the user's chosen test options with the combined test/user
1271 # version.
1272 mips_push_test_options saved_options $mips_extra_options
1273 set result [gcc-dg-test-1 gcc_target_compile $prog \
1274 $do_what $extra_tool_flags]
1275 mips_pop_test_options saved_options
1276
1277 # Restore the usual gcc-dg-test.
1278 rename gcc-dg-test mips-gcc-dg-test
1279 rename mips-old-gcc-dg-test gcc-dg-test
1280
1281 return $result
1282 }
1283
1284 dg-init
1285 mips-dg-init
1286 gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.c]] \
1287 "-DNOMIPS16=__attribute__((nomips16)) -DNOMICROMIPS=__attribute__((nomicromips)) -DNOCOMPRESSION=__attribute__((nocompression))"
1288 mips-dg-finish
1289 dg-finish