5296a15f616fedb839ff12289692bc4e6d653c28
[platform/upstream/gcc.git] / gcc / testsuite / gcc.target / mips / mips.exp
1 # Copyright (C) 1997-2017 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 #   isa=p5600
146 #      select a P5600 processor
147 #
148 #   addressing=absolute
149 #       force absolute addresses to be used
150 #
151 #   forbid_cpu=REGEXP
152 #       forbid processors that match the given regexp; choose a
153 #       generic ISA instead.
154 #
155 #
156 # In summary:
157 #
158 #   (1) Try to avoid { target ... } requirements wherever possible.
159 #       Specify the requirements as dg-options instead.
160 #
161 #   (2) Don't worry about the consequences of (1) for link and run tests.
162 #       If the test uses { dg-do link } or { dg-do run }, and its
163 #       dg-options are incompatible with the current target, the
164 #       testsuite will downgrade them where necessary.
165 #
166 #   (3) Try to use the bare minimum of options and leave dg-options
167 #       to work out the dependencies.  For example, if you want
168 #       a MIPS-3D test, you should generally just specify -mips3d.
169 #       Don't specify an architecture option like -mips64 unless
170 #       the test really doesn't work with -mips32r2, -mips64r2,
171 #       -march=sb1, etc.
172 #
173 #   (4) If you want something compatible with a particular option,
174 #       but don't want to pass the option itself, wrap that option
175 #       in parentheses.  In particular, pass '(-mips16)' if you
176 #       want to use "mips16" attributes.
177 #
178 #   (5) When testing a feature of a generic ISA (as opposed to a
179 #       processor-specific extension), try to use the "isa" and
180 #       "isa_rev" pseudo-options instead of specific architecture
181 #       options.  For example, if the feature is present on revision 2
182 #       processors and above, try to use "isa_rev>=2" instead of
183 #       "-mips32r2" or "-mips64r2".
184 #
185 #   (6) If you need to disable processor-specific extensions use
186 #       forbid_cpu=REGEXP instead of forcing a generic ISA.
187 #
188 #
189 # Terminology
190 #
191 #   Option group or just group:
192 #      See comment before mips_option_groups.
193 #
194 #   Test options:
195 #      The options specified in dg-options.
196 #
197 #   Explicit options:
198 #      The options that were either passed to runtest as "multilib" options
199 #      (e.g. -mips4 in --target_board=mips-sim-idt/-mips4) or specified as
200 #      test options.  Note that options in parenthesis (i.e. (-mips16)) are
201 #      not explicit and can be omitted depending on the base options.
202 #
203 #   Base options:
204 #      Options that are on by default without being specified in dg-options,
205 #      e.g. -march=mips64r2 for mipsisa64r2-elf or because they've been
206 #      passed to runtest as "multilib" options.
207 #
208 #   Option array:
209 #      Many functions in this file work with option arrays.  These are
210 #      two-dimensional Tcl arrays where the first dimension can have three
211 #      values: option, explicit_p or test_option_p.  The second dimension is
212 #      the name of the option group.  "option" contains the name of the
213 #      option that is in effect from this group.  If no option is active it
214 #      contains the empty string.  The flags "explicit_p" and "test_option_p"
215 #      are set for explicit and test options.
216
217 # Exit immediately if this isn't a MIPS target.
218 if ![istarget mips*-*-*] {
219     return
220 }
221
222 # Load support procs.
223 load_lib gcc-dg.exp
224
225 # A list of GROUP REGEXP pairs.  Each GROUP represents a logical group of
226 # options from which only one option should be chosen.  REGEXP matches all
227 # the options in that group; it is implicitly wrapped in "^(...)$".
228 #
229 # Note that -O* is deliberately omitted from this list.  Tests in this
230 # directory are run at various optimisation levels and should use
231 # dg-skip-if to skip any incompatible levels.
232 set mips_option_groups {
233     abi "-mabi=.*"
234     addressing "addressing=.*"
235     arch "-mips([1-5]|32.*|64.*)|-march=.*|isa(|_rev)(=|<=|>=).*"
236     debug "-g.*"
237     dump_pattern "-dp"
238     endianness "-E(L|B)|-me(l|b)"
239     float "-m(hard|soft)-float"
240     fpu "-m(double|single)-float"
241     forbid_cpu "forbid_cpu=.*"
242     fp "-mfp(32|xx|64)"
243     gp "-mgp(32|64)"
244     long "-mlong(32|64)"
245     micromips "-mmicromips|-mno-micromips"
246     mips16 "-mips16|-mno-mips16|-mflip-mips16"
247     mips3d "-mips3d|-mno-mips3d"
248     pic "-f(no-|)(pic|PIC)"
249     cb "-mcompact-branches=.*"
250     profiling "-pg"
251     small-data "-G[0-9]+"
252     warnings "-w"
253     dump "-fdump-.*"
254     ins "HAS_INS"
255     dmul "NOT_HAS_DMUL"
256     ldc "HAS_LDC"
257     movn "HAS_MOVN"
258     madd "HAS_MADD"
259     maddps "HAS_MADDPS"
260     lsa "(|!)HAS_LSA"
261     lxc1 "HAS_LXC1"
262     section_start "-Wl,--section-start=.*"
263     frame-header "-mframe-header-opt|-mno-frame-header-opt"
264     stack-protector "-fstack-protector"
265     stdlib "REQUIRES_STDLIB"
266 }
267
268 for { set option 0 } { $option < 32 } { incr option } {
269     lappend mips_option_groups "fixed-f$option" "-ffixed-f$option"
270 }
271
272 # Add -mfoo/-mno-foo options to mips_option_groups.
273 foreach option {
274     abicalls
275     branch-likely
276     dsp
277     dspr2
278     explicit-relocs
279     extern-sdata
280     fix-r4000
281     fix-r10000
282     fix-vr4130
283     gpopt
284     local-sdata
285     long-calls
286     lxc1-sxc1
287     paired-single
288     plt
289     shared
290     smartmips
291     sym32
292     synci
293     relax-pic-calls
294     mcount-ra-address
295     odd-spreg
296     msa
297 } {
298     lappend mips_option_groups $option "-m(no-|)$option"
299 }
300
301 # Add -mfoo= options to mips_option_groups.
302 foreach option {
303     abs
304     branch-cost
305     code-readable
306     nan
307     r10k-cache-barrier
308     tune
309 } {
310     lappend mips_option_groups $option "-m$option=.*"
311 }
312
313 # Add -ffoo/-fno-foo options to mips_option_groups.
314 foreach option {
315     common
316     delayed-branch
317     expensive-optimizations
318     fast-math
319     fat-lto-objects
320     finite-math-only
321     fixed-hi
322     fixed-lo
323     lax-vector-conversions
324     omit-frame-pointer
325     optimize-sibling-calls
326     peephole2
327     schedule-insns2
328     split-wide-types
329     tree-vectorize
330     unroll-all-loops
331     unroll-loops
332     ipa-ra
333 } {
334     lappend mips_option_groups $option "-f(no-|)$option"
335 }
336
337 # A list of option groups that have an impact on the ABI.
338 set mips_abi_groups {
339     abi
340     abicalls
341     arch
342     endianness
343     float
344     fp
345     gp
346     gpopt
347     long
348     pic
349     small-data
350 }
351
352 # mips_option_tests(OPTION) is some assembly code that will run to completion
353 # on a target that supports OPTION.
354 set mips_option_tests(-mips16) {
355     move $2,$31
356     bal 1f
357     .set mips16
358     jr $31
359     .set nomips16
360     .align 2
361 1:
362     ori $3,$31,1
363     jalr $3
364     move $31,$2
365 }
366 set mips_option_tests(-mmicromips) {
367     move $2,$31
368     bal 1f
369     .set push
370     .set micromips
371     jraddiusp 0
372     .set pop
373     .align 2
374 1:
375     ori $3,$31,1
376     jalr $3
377     move $31,$2
378 }
379 set mips_option_tests(-mpaired-single) {
380     .set mips64
381     lui $2,0x3f80
382     mtc1 $2,$f0
383     cvt.ps.s $f2,$f0,$f0
384 }
385 set mips_option_tests(-mips3d) {
386     .set mips64
387     .set mips3d
388     lui $2,0x3f80
389     mtc1 $2,$f0
390     cvt.ps.s $f2,$f0,$f0
391     mulr.ps $f2,$f2,$f2
392     rsqrt1.s $f2,$f0
393     mul.s $f4,$f2,$f0
394     rsqrt2.s $f4,$f4,$f2
395     madd.s $f4,$f2,$f2,$f4
396 }
397 set mips_option_tests(-mdsp) {
398     .set mips64r2
399     .set dsp
400     addsc $2,$2,$2
401 }
402 set mips_option_tests(-mdspr2) {
403     .set mips64r2
404     .set dspr2
405     prepend $2,$3,11
406 }
407 set mips_option_tests(-mcode-readable=yes) {
408     move $2,$31
409     bal 1f
410     .set mips16
411     la $3,0f
412     lw $3,($3)
413     jr $31
414 0:
415     .word 0xfacebead
416     .set nomips16
417     .align 2
418 1:
419     ori $3,$31,1
420     jalr $3
421     li $4,0xfacebead
422     beq $3,$4,2f
423     break
424     b .
425 2:
426     move $31,$2
427 }
428
429 # Canonicalize command-line option OPTION.
430 proc mips_canonicalize_option { option } {
431     regsub {^-mips([1-5]|32*|64*)$} $option {-march=mips\1} option
432
433     regsub {^-mel$} $option {-EL} option
434     regsub {^-meb$} $option {-EB} option
435
436     regsub {^-O$} $option {-O1} option
437
438     # MIPS doesn't use -fpic and -fPIC to distinguish between code models.
439     regsub {^-f(no-|)PIC} $option {-f\1pic} option
440
441     return $option
442 }
443
444 # Return true if OPTION1 and OPTION2 represent the same command-line option.
445 proc mips_same_option_p { option1 option2 } {
446     return [string equal \
447                 [mips_canonicalize_option $option1] \
448                 [mips_canonicalize_option $option2]]
449 }
450
451 # Preprocess CODE using target_compile options OPTIONS.  Return the
452 # compiler output.
453 proc mips_preprocess { options code ignore_output } {
454     global tool
455
456     set src dummy[pid].c
457     set f [open $src "w"]
458     puts $f $code
459     close $f
460     if { $ignore_output } {
461         set output [${tool}_target_compile $src dummy[pid].i preprocess $options]
462         file delete dummy[pid].i
463     } else {
464         set output [${tool}_target_compile $src "" preprocess $options]
465     }
466     file delete $src
467
468     return $output
469 }
470
471 # Set the target board's command-line options to NEW_OPTIONS, storing the
472 # old values in UPVAR.
473 proc mips_push_test_options { upvar new_options } {
474     upvar $upvar var
475     global board_info
476
477     array unset var
478     set var(name) board_info([target_info name],multilib_flags)
479     if { [info exists $var(name)] } {
480         set var(old_options) [set $var(name)]
481         set $var(name) [join $new_options " "]
482     }
483 }
484
485 # Undo the effects of [mips_push_test_options UPVAR ...]
486 proc mips_pop_test_options { upvar } {
487     upvar $upvar var
488     global board_info
489
490     if { [info exists var(old_options)] } {
491         set $var(name) $var(old_options)
492     }
493 }
494
495 # Return property PROP for architecture option ARCH (which belongs to
496 # the "arch" group in mips_option_groups).  See the comment at the
497 # top of the file for the valid property names.
498 #
499 # Cache the results in mips_arch_info (which can be reused between test
500 # variants).
501 proc mips_arch_info { arch prop } {
502     global mips_arch_info
503     global board_info
504
505     set arch [mips_canonicalize_option $arch]
506     if { ![info exists mips_arch_info($arch,$prop)] } {
507         mips_push_test_options saved_options {}
508         set output [mips_preprocess [list "additional_flags=$arch -mabi=32"] {
509             int isa = __mips;
510             #ifdef __mips_isa_rev
511             int isa_rev = __mips_isa_rev;
512             #else
513             int isa_rev = 0;
514             #endif
515         } 0]
516         foreach lhs { isa isa_rev } {
517             regsub ".*$lhs = (\[^;\]*).*" $output {\1} rhs
518             verbose -log "Architecture $arch has $lhs $rhs"
519             set mips_arch_info($arch,$lhs) $rhs
520         }
521         mips_pop_test_options saved_options
522     }
523     return $mips_arch_info($arch,$prop)
524 }
525
526 # Return the option group associated with OPTION, or "" if none.
527 proc mips_option_maybe_group { option } {
528     global mips_option_groups
529
530     foreach { group regexp } $mips_option_groups {
531         if { [regexp -- "^($regexp)\$" $option] } {
532             return $group
533         }
534     }
535     return ""
536 }
537
538 # Return the option group associated with OPTION.  Raise an error if
539 # there is none.
540 proc mips_option_group { option } {
541     set group [mips_option_maybe_group $option]
542     if { [string equal $group ""] } {
543         error "Unrecognised option: $option"
544     }
545     return $group
546 }
547
548 # Return the option for option group GROUP, or "" if no option in that
549 # group has been chosen.  UPSTATUS describes the option status.
550 proc mips_option { upstatus group } {
551     upvar $upstatus status
552
553     return $status(option,$group)
554 }
555
556 # If the base options for this test run include an option in group GROUP,
557 # return that option, otherwise return "".
558 proc mips_original_option { group } {
559     global mips_base_options
560
561     return [mips_option mips_base_options $group]
562 }
563
564 # Return true if the test described by UPSTATUS requires a specific
565 # option in group GROUP.  UPSTATUS describes the option status.
566 proc mips_test_option_p { upstatus group } {
567     upvar $upstatus status
568
569     return $status(test_option_p,$group)
570 }
571
572 # If the test described by UPSTATUS requires a particular option in group
573 # GROUP, return that option, otherwise return "".
574 proc mips_test_option { upstatus group } {
575     upvar $upstatus status
576
577     if { [mips_test_option_p status $group] } {
578         return [mips_option status $group]
579     } else {
580         return ""
581     }
582 }
583
584 # Return true if the options described by UPSTATUS include OPTION.
585 proc mips_have_option_p { upstatus option } {
586     upvar $upstatus status
587
588     return [mips_same_option_p \
589                 [mips_option status [mips_option_group $option]] \
590                 $option]
591 }
592
593 # Return true if the options described by UPSTATUS require MIPS16 support.
594 proc mips_using_mips16_p { upstatus } {
595     upvar $upstatus status
596
597     return [expr { [mips_have_option_p status "-mips16"]
598                    || [mips_have_option_p status "-mflip-mips16"] }]
599 }
600
601 # Return true if the test described by UPSTATUS requires option OPTION.
602 proc mips_have_test_option_p { upstatus option } {
603     upvar $upstatus status
604
605     set group [mips_option_group $option]
606     return [mips_same_option_p [mips_test_option status $group] $option]
607 }
608
609 # If the test described by UPSTATUS does not specify an option in
610 # OPTION's group, act as though it had specified OPTION.
611 #
612 # The first optional argument indicates whether the option should be
613 # treated as though it were wrapped in parentheses; see the comment at
614 # the top of the file for details about this convention.  The default is 0.
615 proc mips_make_test_option { upstatus option args } {
616     upvar $upstatus status
617
618     set group [mips_option_group $option]
619     if { ![mips_test_option_p status $group] } {
620         set status(option,$group) $option
621         set status(test_option_p,$group) 1
622         if { [llength $args] == 0 || ![lindex $args 0] } {
623             set status(explicit_p,$group) 1
624         }
625     }
626 }
627
628 # If the test described by UPSTATUS requires option FROM, assume that
629 # it implicitly requires option TO.
630 proc mips_option_dependency { upstatus from to } {
631     upvar $upstatus status
632
633     if { [mips_have_test_option_p status $from] } {
634         mips_make_test_option status $to
635     }
636 }
637
638 # Return true if the given arch-group option specifies a 32-bit ISA.
639 proc mips_32bit_arch_p { option } {
640     set isa [mips_arch_info $option isa]
641     return [expr { $isa < 3 || $isa == 32 }]
642 }
643
644 # Return true if the given arch-group option specifies a 64-bit ISA.
645 proc mips_64bit_arch_p { option } {
646     return [expr { ![mips_32bit_arch_p $option] }]
647 }
648
649 # Return true if the given abi-group option implicitly requires -mgp32.
650 proc mips_32bit_abi_p { option } {
651     switch -glob -- $option {
652         -mabi=32 {
653             return 1
654         }
655     }
656     return 0
657 }
658
659 # Return true if the given abi-group option implicitly requires -mgp64.
660 proc mips_64bit_abi_p { option } {
661     switch -glob -- $option {
662         -mabi=o64 -
663         -mabi=n32 -
664         -mabi=64 {
665             return 1
666         }
667     }
668     return 0
669 }
670
671 # Return true if the given abi-group option implicitly requires -mlong32.
672 # o64 requires this for -mabicalls, but not otherwise; pick the conservative
673 # case for simplicity.
674 proc mips_long32_abi_p { option } {
675     switch -glob -- $option {
676         -mabi=o64 -
677         -mabi=n32 -
678         -mabi=32 {
679             return 1
680         }
681     }
682     return 0
683 }
684
685 # Return true if the given abi-group option implicitly requires -mlong64.
686 proc mips_long64_abi_p { option } {
687     switch -glob -- $option {
688         -mabi=64 {
689             return 1
690         }
691     }
692     return 0
693 }
694
695 # Check whether the current target supports all the options that the
696 # current test requires.  Return "" if so, otherwise return one of
697 # the incompatible options.  UPSTATUS describes the option status.
698 proc mips_first_unsupported_option { upstatus } {
699     global mips_option_tests
700     upvar $upstatus status
701
702     foreach { option code } [array get mips_option_tests] {
703         if { [mips_have_test_option_p status $option] } {
704             regsub -all "\n" $code "\\n\\\n" asm
705             # Use check_runtime from target-supports.exp, which caches
706             # the result for us.
707             if { ![check_runtime mips_option_$option [subst {
708                 __attribute__((nomips16)) int
709                 main (void)
710                 {
711                     asm (".set push\
712                     $asm\
713                     .set pop");
714                     return 0;
715                 }
716             }]] } {
717                 return $option
718             }
719         }
720     }
721     return ""
722 }
723
724 # Initialize this testsuite for a new test variant.
725 proc mips-dg-init {} {
726     # Invariant information.
727     global mips_option_groups
728
729     # Internally-generated information about this run.
730     global mips_base_options
731     global mips_extra_options
732
733     # Override dg-options with our mips-dg-options routine.
734     rename dg-options mips-old-dg-options
735     rename mips-dg-options dg-options
736
737     # Start with a fresh option status.
738     array unset mips_base_options
739     foreach { group regexp } $mips_option_groups {
740         set mips_base_options(option,$group) ""
741         set mips_base_options(explicit_p,$group) 0
742         set mips_base_options(test_option_p,$group) 0
743     }
744
745     # Use preprocessor macros to work out as many implicit options as we can.
746     set output [mips_preprocess "" {
747         const char *options[] = {
748             #if !defined _MIPS_SIM
749             "-mabi=eabi",
750             #elif _MIPS_SIM==_ABIO32
751             "-mabi=32",
752             #elif _MIPS_SIM==_ABIO64
753             "-mabi=o64",
754             #elif _MIPS_SIM==_ABIN32
755             "-mabi=n32",
756             #else
757             "-mabi=64",
758             #endif
759
760             "-march=" _MIPS_ARCH,
761
762             #ifdef _MIPSEB
763             "-EB",
764             #else
765             "-EL",
766             #endif
767
768             #ifdef __mips_hard_float
769             "-mhard-float",
770             #else
771             "-msoft-float",
772             #endif
773
774             #ifdef __mips_abs2008
775             "-mabs=2008",
776             #else
777             "-mabs=legacy",
778             #endif
779
780             #ifdef __mips_nan2008
781             "-mnan=2008",
782             #else
783             "-mnan=legacy",
784             #endif
785
786             #if __mips_fpr == 64
787             "-mfp64",
788             #else
789             #if __mips_fpr == 0
790             "-mfpxx",
791             #else
792             "-mfp32",
793             #endif
794             #endif
795
796             #ifdef __mips64
797             "-mgp64",
798             #else
799             "-mgp32",
800             #endif
801
802             #if _MIPS_SZLONG == 64
803             "-mlong64",
804             #else
805             "-mlong32",
806             #endif
807
808             #ifdef __mips16
809             "-mips16",
810             #else
811             "-mno-mips16",
812             #endif
813
814             #ifdef __mips3d
815             "-mips3d",
816             #else
817             "-mno-mips3d",
818             #endif
819
820             #ifdef __mips_paired_single_float
821             "-mpaired-single",
822             #else
823             "-mno-paired-single",
824             #endif
825
826             #if _MIPS_SPFPSET == 32
827             "-modd-spreg",
828             #else
829             "-mno-odd-spreg",
830             #endif
831
832             #if __mips_abicalls
833             "-mabicalls",
834             #else
835             "-mno-abicalls",
836             #endif
837
838             #if __mips_dsp_rev >= 2
839             "-mdspr2",
840             #else
841             "-mno-dspr2",
842             #endif
843
844             #if __mips_dsp_rev >= 1
845             "-mdsp",
846             #else
847             "-mno-dsp",
848             #endif
849
850             #ifndef __PIC__
851             "addressing=absolute",
852             #endif
853
854             #ifdef __mips_smartmips
855             "-msmartmips",
856             #else
857             "-mno-smartmips",
858             #endif
859
860             #ifdef __mips_no_lxc1_sxc1
861             "-mno-lxc1-sxc1",
862             #else
863             "-mlxc1-sxc1"
864             #endif
865
866             #ifdef __mips_synci
867             "-msynci",
868             #else
869             "-mno-synci",
870             #endif
871
872             #ifdef __mips_msa
873             "-mmsa"
874             #else
875             "-mno-msa"
876             #endif
877
878             0
879         };
880     } 0]
881     foreach line [split $output "\r\n"] {
882         # Poor man's string concatenation.
883         regsub -all {" "} $line "" line
884         if { [regexp {"(.*)",} $line dummy option] } {
885             set group [mips_option_group $option]
886             set mips_base_options(option,$group) $option
887         }
888     }
889
890     # Process the target's multilib options, saving any unrecognized
891     # ones in mips_extra_options.
892     set mips_extra_options {}
893     foreach option [split [board_info target multilib_flags]] {
894         set group [mips_option_maybe_group $option]
895         if { ![string equal $group ""] } {
896             set mips_base_options(option,$group) $option
897             set mips_base_options(explicit_p,$group) 1
898         } else {
899             lappend mips_extra_options $option
900         }
901     }
902 }
903
904 # Finish a test run started by mips-dg-init.
905 proc mips-dg-finish {} {
906     rename dg-options mips-dg-options
907     rename mips-old-dg-options dg-options
908 }
909
910 # Override dg-options so that we can do some MIPS-specific processing.
911 # All options used in this testsuite must appear in mips_option_groups.
912 #
913 # Test options override multilib options.  Certain test options can
914 # also imply other test options, which also override multilib options.
915 # These dependencies are ordered as follows:
916 #
917 #          START                        END
918 #            |                           |
919 #         -mips16/-mflip-mips16       -mno-mips16
920 #            |                           |
921 #         -micromips                  -mno-micromips
922 #            |                           |
923 #         -mips3d                     -mno-mips3d
924 #            |                           |
925 #         -mpaired-single             -mno-paired-single
926 #            |                           |
927 #         -mfp64                      -mfp32
928 #            |                           |
929 #         -modd-spreg                 -mno-odd-spreg
930 #            |                           |
931 #         -mdouble-float              -msingle-float
932 #            |                           |
933 #         -mabs=2008/-mabs=legacy     <no option>
934 #            |                           |
935 #         -mhard-float                -msoft-float
936 #            |                           |
937 #         -mno-sym32                  -msym32
938 #            |                           |
939 #         -mrelax-pic-calls           -mno-relax-pic-calls
940 #            |                           |
941 #         -fpic                       -fno-pic
942 #            |                           |
943 #         -mshared                    -mno-shared
944 #            |                           |
945 #         -mno-plt                    -mplt
946 #            |                           |
947 #         addressing=unknown          addressing=absolute
948 #            |                           |
949 #         -mabicalls                  -mno-abicalls
950 #            |                           |
951 #         -G0                         <other value>
952 #            |                           |
953 #         <other value>               -mr10k-cache-barrier=none
954 #            |                           |
955 #         -mfix-r10000                -mno-fix-r10000
956 #            |                           |
957 #         -mbranch-likely             -mno-branch-likely
958 #            |                           |
959 #         -msmartmips                 -mno-smartmips
960 #            |                           |
961 #         -mno-gpopt                  -mgpopt
962 #            |                           |
963 #         -mexplicit-relocs           -mno-explicit-relocs
964 #            |                           |
965 #         -mdspr2                     -mno-dspr2
966 #            |                           |
967 #         -mdsp                       -mno-dsp
968 #            |                           |
969 #         -msynci                     -mno-synci
970 #            |                           |
971 #            +-- gp, abi & arch ---------+
972 #
973 # For these purposes, the "gp", "abi" & "arch" option groups are treated
974 # as a single node.
975 proc mips-dg-options { args } {
976     # dg.exp variables.
977     upvar dg-extra-tool-flags extra_tool_flags
978     upvar dg-do-what do_what
979
980     # Invariant information.
981     global mips_option_groups
982     global mips_abi_groups
983
984     # Information about this run.
985     global mips_base_options
986
987     if { [llength $args] >= 3 } {
988         switch { [dg-process-target [lindex $args 2]] } {
989             "S" { }
990             "N" { return }
991             "F" { error "[lindex $args 0]: `xfail' not allowed here" }
992             "P" { error "[lindex $args 0]: `xfail' not allowed here" }
993         }
994     }
995
996     # Start out with the default option state.
997     array set options [array get mips_base_options]
998
999     # Record the options that this test explicitly needs.
1000     foreach option [lindex $args 1] {
1001         set all_but_p [regexp {^\((.*)\)$} $option dummy option]
1002         set group [mips_option_group $option]
1003         if { [mips_test_option_p options $group] } {
1004             set old [mips_option options $group]
1005             error "Inconsistent $group option: $old vs. $option"
1006         } else {
1007             mips_make_test_option options $option $all_but_p
1008         }
1009     }
1010
1011     # Handle dependencies between the test options and the optimization ones.
1012     mips_option_dependency options "-fno-unroll-loops" "-fno-unroll-all-loops"
1013     mips_option_dependency options "-pg" "-fno-omit-frame-pointer"
1014
1015     # Handle dependencies between options on the left of the
1016     # dependency diagram.
1017     mips_option_dependency options "-mips16" "-mno-micromips"
1018     mips_option_dependency options "-mmicromips" "-mno-mips16"
1019     mips_option_dependency options "-mips3d" "-mpaired-single"
1020     mips_option_dependency options "-mips3d" "-mno-micromips"
1021     mips_option_dependency options "-mpaired-single" "-mfp64"
1022     mips_option_dependency options "-mfp64" "-mhard-float"
1023     mips_option_dependency options "-mfp32" "-mhard-float"
1024     mips_option_dependency options "-mfpxx" "-mhard-float"
1025     mips_option_dependency options "-mfp64" "-modd-spreg"
1026     mips_option_dependency options "-mfp64" "-mdouble-float"
1027     mips_option_dependency options "-mfp32" "-mdouble-float"
1028     mips_option_dependency options "-mfpxx" "-mdouble-float"
1029     mips_option_dependency options "-mabs=2008" "-mhard-float"
1030     mips_option_dependency options "-mabs=legacy" "-mhard-float"
1031     mips_option_dependency options "-mrelax-pic-calls" "-mno-plt"
1032     mips_option_dependency options "-mrelax-pic-calls" "-mabicalls"
1033     mips_option_dependency options "-mrelax-pic-calls" "-mexplicit-relocs"
1034     mips_option_dependency options "-fpic" "-mshared"
1035     mips_option_dependency options "-mshared" "-mno-plt"
1036     mips_option_dependency options "-mshared" "-mabicalls"
1037     mips_option_dependency options "-mno-plt" "addressing=unknown"
1038     mips_option_dependency options "-mabicalls" "-G0"
1039     mips_option_dependency options "-mno-gpopt" "-mexplicit-relocs"
1040
1041     # Work out information about the current ABI.
1042     set abi_test_option_p [mips_test_option_p options abi]
1043     set abi [mips_option options abi]
1044     set eabi_p [mips_same_option_p $abi "-mabi=eabi"]
1045
1046     # If the test forces a particular ABI, set the register size
1047     # accordingly.
1048     if { $abi_test_option_p } {
1049         if { [mips_32bit_abi_p $abi] } {
1050             mips_make_test_option options "-mgp32"
1051         } elseif { [mips_64bit_abi_p $abi] } {
1052             mips_make_test_option options "-mgp64"
1053         }
1054     }
1055
1056     # See whether forbid_cpu forces us to choose a new architecture.
1057     set arch [mips_option mips_base_options arch]
1058     set force_generic_isa_p [expr {
1059         [regexp "forbid_cpu=(.*)" [mips_option options forbid_cpu] dummy spec]
1060         && [regexp -- "^-march=$spec\$" $arch]
1061     }]
1062
1063     # Interpret the special "isa" and "isa_rev" options.  If we have
1064     # a choice of a 32-bit or a 64-bit architecture, prefer to keep
1065     # the -mgp setting the same.
1066     set spec [mips_option options arch]
1067     if { [regexp {^[^-]} $spec] } {
1068         if { [string equal $spec "isa=loongson"] } {
1069             if { ![regexp {^-march=loongson} $arch] } {
1070                 set arch "-march=loongson2f"
1071             }
1072         } elseif { [string equal $spec "isa=p5600"] } {
1073             if { ![regexp {^-march=p5600} $arch] } {
1074                 set arch "-march=p5600"
1075             }
1076         } else {
1077             if { ![regexp {^(isa(?:|_rev))(=|<=|>=)([0-9]*)$} \
1078                        $spec dummy prop relation value nocpus] } {
1079                 error "Unrecognized isa specification: $spec"
1080             }
1081             set current [mips_arch_info $arch $prop]
1082             if { $force_generic_isa_p
1083                  || ($current < $value && ![string equal $relation "<="])
1084                  || ($current > $value && ![string equal $relation ">="])
1085                  || ([mips_have_test_option_p options "-mgp64"]
1086                      && [mips_32bit_arch_p $arch]) } {
1087                 # The current setting is out of range; it cannot
1088                 # possibly be used.  Find a replacement that can.
1089                 if { [string equal $prop "isa"] } {
1090                     set arch "-mips$value"
1091                 } elseif { $value == 0 } {
1092                     set arch "-mips4"
1093                 } else {
1094                     if { [mips_have_option_p options "-mgp32"] } {
1095                         set arch "-mips32"
1096                     } else {
1097                         set arch "-mips64"
1098                     }
1099                     if { $value > 1 } {
1100                         append arch "r$value"
1101                     }
1102                 }
1103             }
1104         }
1105         set options(option,arch) $arch
1106     }
1107
1108     # Work out information about the current architecture.
1109     set arch_test_option_p [mips_test_option_p options arch]
1110     set arch [mips_option options arch]
1111     set isa [mips_arch_info $arch isa]
1112     set isa_rev [mips_arch_info $arch isa_rev]
1113     set orig_isa_rev $isa_rev
1114
1115     # If the test forces a 32-bit architecture, force -mgp32.
1116     # Force the current -mgp setting otherwise; if we don't,
1117     # some configurations would make a 64-bit architecture
1118     # imply -mgp64.
1119     if { $arch_test_option_p } {
1120         if { [mips_32bit_arch_p $arch] } {
1121             mips_make_test_option options "-mgp32"
1122         } else {
1123             mips_make_test_option options [mips_option options gp]
1124         }
1125     }
1126
1127     # We've now fixed the GP register size.  Make it easily available.
1128     set gp_size [expr { [mips_have_option_p options "-mgp32"] ? 32 : 64 }]
1129
1130     # Handle dependencies between the pre-arch options and the arch option.
1131     # This should mirror the arch and post-arch code below.
1132     if { !$arch_test_option_p } {
1133         # We need a revision 6 or better ISA for:
1134         #
1135         #   - When the LSA instruction is required
1136         #   - When only using compact branches
1137         if { $isa_rev < 6
1138              && ([mips_have_test_option_p options "HAS_LSA"]
1139                  || [mips_have_test_option_p options "-mcompact-branches=always"]) } {
1140             if { $gp_size == 32 } {
1141                 mips_make_test_option options "-mips32r6"
1142             } else {
1143                 mips_make_test_option options "-mips64r6"
1144             }
1145         # We need a revision 2 or better ISA for:
1146         #
1147         #   - the combination of -mgp32 -mfp64
1148         #   - the DSP ASE
1149         } elseif { $isa_rev < 2
1150              && (($gp_size == 32 && [mips_have_test_option_p options "-mfp64"])
1151                  || [mips_have_test_option_p options "-msynci"]
1152                  || [mips_have_test_option_p options "-mdsp"]
1153                  || [mips_have_test_option_p options "HAS_INS"]
1154                  || [mips_have_test_option_p options "HAS_MADD"]
1155                  || [mips_have_test_option_p options "HAS_MADDPS"]
1156                  || [mips_have_test_option_p options "-mdspr2"]
1157                  || [mips_have_test_option_p options "-mnan=2008"]
1158                  || [mips_have_test_option_p options "-mabs=2008"]
1159                  || [mips_have_test_option_p options "-mmicromips"]) } {
1160             if { $gp_size == 32 } {
1161                 mips_make_test_option options "-mips32r2"
1162             } else {
1163                 mips_make_test_option options "-mips64r2"
1164             }
1165         # We need a MIPS32 or MIPS64 ISA for:
1166         #
1167         #   - paired-single instructions(*)
1168         #   - odd numbered single precision registers
1169         #
1170         # (*) Note that we don't support MIPS V at the moment.
1171         } elseif { $isa_rev < 1
1172                    && ([mips_have_test_option_p options "-mpaired-single"]
1173                        || ([mips_have_test_option_p options "-modd-spreg"]
1174                            && ![mips_have_test_option_p options "-mfp64"]))} {
1175             if { $gp_size == 32 } {
1176                 mips_make_test_option options "-mips32"
1177             } else {
1178                 mips_make_test_option options "-mips64"
1179             }
1180         # We need MIPS IV or higher for:
1181         #
1182         #
1183         } elseif { $isa < 4
1184                    && ([mips_have_test_option_p options "HAS_LXC1"]
1185                        || [mips_have_test_option_p options "HAS_MOVN"]) } {
1186             mips_make_test_option options "-mips4"
1187         # We need MIPS III or higher for:
1188         #
1189         #   - the "cache" instruction
1190         } elseif { $isa < 3
1191                    && ([mips_have_test_option_p options \
1192                             "-mr10k-cache-barrier=load-store"]
1193                        || [mips_have_test_option_p options \
1194                                "-mr10k-cache-barrier=store"]) } {
1195             mips_make_test_option options "-mips3"
1196         # We need MIPS II or higher for:
1197         #
1198         #   - branch-likely instructions(*)
1199         #
1200         # (*) needed by both -mbranch-likely and -mfix-r10000
1201         } elseif { $isa < 2
1202                    && ([mips_have_test_option_p options "-mbranch-likely"]
1203                        || [mips_have_test_option_p options "-mfix-r10000"]
1204                        || ($gp_size == 32
1205                            && ([mips_have_test_option_p options "-mfpxx"]
1206                                || [mips_have_test_option_p options "HAS_LDC"]))) } {
1207             mips_make_test_option options "-mips2"
1208         # We need to use octeon's base ISA if a test must not run with an
1209         # architecture that supports dmul.
1210         } elseif { [regexp -- "^-march=octeon.*\$" $arch]
1211                    && [mips_have_test_option_p options "NOT_HAS_DMUL"] } {
1212             mips_make_test_option options "-mips${isa}r${isa_rev}"
1213         # Check whether we need to switch from mips*r6 down to mips*r5 due
1214         # to options that are incompatible with mips*r6.  If we do, use
1215         # -mnan=2008 because r6 is nan2008 by default and without this flag
1216         # tests that include stdlib.h will fail due to not finding
1217         # stubs-o32_hard.h  (r6 compilers only have stubs-o32_hard_2008.h)
1218         } elseif { $isa_rev > 5
1219                    && ([mips_have_test_option_p options "-mdsp"]
1220                        || [mips_have_test_option_p options "-mdspr2"]
1221                        || [mips_have_test_option_p options "-mips16"]
1222                        || [mips_have_test_option_p options "-mmicromips"]
1223                        || [mips_have_test_option_p options "-mfp32"]
1224                        || [mips_have_test_option_p options "-mfix-r10000"]
1225                        || [mips_have_test_option_p options "NOT_HAS_DMUL"]
1226                        || [mips_have_test_option_p options "HAS_LXC1"]
1227                        || [mips_have_test_option_p options "HAS_MOVN"]
1228                        || [mips_have_test_option_p options "HAS_MADD"]
1229                        || [mips_have_test_option_p options "-mpaired-single"]
1230                        || [mips_have_test_option_p options "-mnan=legacy"]
1231                        || [mips_have_test_option_p options "-mabs=legacy"]
1232                        || [mips_have_test_option_p options "!HAS_LSA"]
1233                        || [mips_have_test_option_p options "-mbranch-likely"]) } {
1234             if { $gp_size == 32 } {
1235                 mips_make_test_option options "-mips32r5"
1236             } else {
1237                 mips_make_test_option options "-mips64r5"
1238             }
1239             mips_make_test_option options "-mnan=2008"
1240             if { [mips_have_option_p options "-mcompact-branches=always"] } {
1241                 mips_make_test_option options "-mcompact-branches=optimal"
1242             }
1243         # Check whether we need to switch from a 32-bit processor to the
1244         # "nearest" 64-bit processor.
1245         } elseif { $gp_size == 64 && [mips_32bit_arch_p $arch] } {
1246             if { $isa_rev == 0 } {
1247                 mips_make_test_option options "-mips3"
1248             } elseif { $isa_rev == 1 } {
1249                 mips_make_test_option options "-mips64"
1250             } else {
1251                 mips_make_test_option options "-mips64r$isa_rev"
1252             }
1253         # Otherwise, if the current choice of architecture is unacceptable,
1254         # choose the equivalent generic architecture.
1255         } elseif { $force_generic_isa_p } {
1256             set arch "-mips[mips_arch_info $arch isa]"
1257             if { $isa_rev > 1 } {
1258                 append arch "r$isa_rev"
1259             }
1260             mips_make_test_option options $arch
1261         }
1262         unset arch
1263         unset isa
1264         unset isa_rev
1265     }
1266
1267     # Re-calculate the isa_rev for use in the abi handling code below
1268     set arch [mips_option options arch]
1269     set isa [mips_arch_info $arch isa]
1270     set isa_rev [mips_arch_info $arch isa_rev]
1271
1272     # Set an appropriate ABI, handling dependencies between the pre-abi
1273     # options and the abi options.  This should mirror the abi and post-abi
1274     # code below.
1275     if { !$abi_test_option_p } {
1276         if { ($eabi_p
1277               && ([mips_have_option_p options "-mabicalls"]
1278                   || ($gp_size == 32
1279                       && [mips_have_option_p options "-mfp64"]))) } {
1280             # EABI doesn't support -mabicalls.
1281             # EABI doesn't support the combination -mgp32 -mfp64.
1282             set force_abi 1
1283         } elseif { [mips_using_mips16_p options]
1284                    && ![mips_same_option_p $abi "-mabi=32"]
1285                    && ![mips_same_option_p $abi "-mabi=o64"]
1286                    && (![mips_have_option_p options "addressing=absolute"]
1287                        || [mips_have_option_p options "-mhard-float"]) } {
1288             # -mips16 -mhard-float requires o32 or o64.
1289             # -mips16 PIC requires o32 or o64.
1290             set force_abi 1
1291         } elseif { [mips_have_test_option_p options "-mlong32"]
1292                    && [mips_long64_abi_p $abi] } {
1293             set force_abi 1
1294         } elseif { [mips_have_test_option_p options "-mlong64"]
1295                    && [mips_long32_abi_p $abi] } {
1296             set force_abi 1
1297         } elseif { [mips_have_test_option_p options "-mfpxx"]
1298                    && ![mips_same_option_p $abi "-mabi=32"] } {
1299             set force_abi 1
1300         } else {
1301             set force_abi 0
1302         }
1303         if { $gp_size == 32 } {
1304             if { $force_abi || [mips_64bit_abi_p $abi] } {
1305                 if { [mips_have_test_option_p options "-mlong64"] } {
1306                     mips_make_test_option options "-mabi=eabi"
1307                     mips_make_test_option options "-mgp32"
1308                 } else {
1309                     mips_make_test_option options "-mabi=32"
1310                 }
1311             }
1312         } else {
1313             if { $force_abi || [mips_32bit_abi_p $abi] } {
1314                 if { [mips_have_test_option_p options "-mlong64"] } {
1315                     mips_make_test_option options "-mabi=eabi"
1316                     mips_make_test_option options "-mgp64"
1317                 } else {
1318                     # All configurations should have an assembler that
1319                     # supports o64, since it requires the same BFD target
1320                     # vector as o32.  In contrast, many assembler
1321                     # configurations do not have n32 or n64 support.
1322                     mips_make_test_option options "-mabi=o64"
1323                 }
1324             }
1325         }
1326         set abi_test_option_p [mips_test_option_p options abi]
1327         set abi [mips_option options abi]
1328         set eabi_p [mips_same_option_p $abi "-mabi=eabi"]
1329     }
1330
1331     # Handle dependencies between the abi options and the post-abi options.
1332     # This should mirror the abi and pre-abi code above.
1333     if { $abi_test_option_p } {
1334         if { $eabi_p } {
1335             mips_make_test_option options "-mno-abicalls"
1336             if { $isa_rev < 6 && $gp_size == 32 } {
1337                     mips_make_test_option options "-mfp32"
1338             }
1339         }
1340         if { [mips_using_mips16_p options]
1341              && ![mips_same_option_p $abi "-mabi=32"]
1342              && ![mips_same_option_p $abi "-mabi=o64"]
1343              && ([mips_have_option_p options "-mabicalls"]
1344                  || [mips_have_option_p options "-mhard-float"]) } {
1345             if { [mips_test_option_p options mips16] } {
1346                 mips_make_test_option options "addressing=absolute"
1347                 mips_make_test_option options "-msoft-float"
1348             } else {
1349                 mips_make_test_option options "-mno-mips16"
1350             }
1351         }
1352         if { [mips_long32_abi_p $abi] } {
1353             mips_make_test_option options "-mlong32"
1354         } elseif { [mips_long64_abi_p $abi] } {
1355             mips_make_test_option options "-mlong64"
1356         }
1357     }
1358
1359     # Handle dependencies between the arch option and the post-arch options.
1360     # This should mirror the arch and pre-arch code above.  For pre-r6
1361     # architectures this only needs to be done when we've moved down
1362     # to a lower architecture and might need to turn features off,
1363     # but moving up from pre-r6 to r6 can remove features too.
1364     if { $arch_test_option_p || ($orig_isa_rev < 6 && $isa_rev >= 6) } {
1365         if { $isa < 2 } {
1366             mips_make_test_option options "-mno-branch-likely"
1367             mips_make_test_option options "-mno-fix-r10000"
1368         }
1369         if { $isa < 3 } {
1370             mips_make_test_option options "-mr10k-cache-barrier=none"
1371         }
1372         if { $isa_rev < 1 } {
1373             mips_make_test_option options "-mno-paired-single"
1374             if { ![mips_have_test_option_p options "-mgp64"] } {
1375                 mips_make_test_option options "-mno-odd-spreg"
1376             }
1377         }
1378         if { $isa_rev < 2 } {
1379             if { $gp_size == 32 } {
1380                 mips_make_test_option options "-mfp32"
1381             }
1382             mips_make_test_option options "-mno-dsp"
1383             mips_make_test_option options "-mno-synci"
1384             mips_make_test_option options "-mno-micromips"
1385             mips_make_test_option options "-mnan=legacy"
1386         }
1387         if { $isa_rev < 6 } {
1388             if { [mips_have_option_p options "-mcompact-branches=always"] } {
1389                 mips_make_test_option options "-mcompact-branches=optimal"
1390             }
1391         }
1392         if { $isa_rev > 5 } {
1393             mips_make_test_option options "-mno-dsp"
1394             mips_make_test_option options "-mno-mips16"
1395             if { [mips_have_test_option_p options "-mdsp"] } {
1396                 mips_make_test_option options "-mfp64"
1397             }
1398             mips_make_test_option options "-mno-fix-r10000"
1399             mips_make_test_option options "-mno-paired-single"
1400             mips_make_test_option options "-mnan=2008"
1401             mips_make_test_option options "-mabs=2008"
1402             mips_make_test_option options "-mno-branch-likely"
1403         }
1404         if { [regexp {^-march=(octeon|loongson)} $arch] } {
1405             mips_make_test_option options "-mno-micromips"
1406         }
1407
1408         unset arch
1409         unset isa
1410         unset isa_rev
1411     }
1412
1413     # Handle dependencies between options on the right of the diagram.
1414     mips_option_dependency options "-mno-dsp" "-mno-dspr2"
1415     mips_option_dependency options "-mno-explicit-relocs" "-mgpopt"
1416     switch -- [mips_test_option options small-data] {
1417         "" -
1418         -G0 {}
1419         default {
1420             mips_make_test_option options "-mno-abicalls"
1421         }
1422     }
1423     if { [mips_have_option_p options "-mabicalls"] } {
1424         mips_option_dependency options "addressing=absolute" "-mplt"
1425     }
1426     mips_option_dependency options "-mplt" "-msym32"
1427     mips_option_dependency options "-mplt" "-mno-shared"
1428     mips_option_dependency options "-mno-shared" "-fno-pic"
1429     mips_option_dependency options "-mfp32" "-mno-paired-single"
1430     mips_option_dependency options "-mfpxx" "-mno-paired-single"
1431     mips_option_dependency options "-msoft-float" "-mno-paired-single"
1432     mips_option_dependency options "-mno-paired-single" "-mno-mips3d"
1433     mips_option_dependency options "-mmsa" "-mno-mips16"
1434
1435     # If the test requires an unsupported option, change run tests
1436     # to link tests.
1437
1438     switch -- [lindex $do_what 0] {
1439         run {
1440             set option [mips_first_unsupported_option options]
1441             if { ![string equal $option ""] } {
1442                 set do_what [lreplace $do_what 0 0 link]
1443                 verbose -log "Downgraded to a 'link' test due to unsupported option '$option'"
1444             }
1445         }
1446     }
1447
1448     # If the test has overridden a option that changes the ABI,
1449     # downgrade a link or execution test to an assembler test.
1450     foreach group $mips_abi_groups {
1451         set old_option [mips_original_option $group]
1452         set new_option [mips_option options $group]
1453         if { ![mips_same_option_p $old_option $new_option]
1454              && ![mips_same_option_p $old_option "-mfpxx"]
1455              && ![mips_same_option_p $new_option "-mfpxx"] } {
1456             switch -- [lindex $do_what 0] {
1457                 link -
1458                 run {
1459                     set do_what [lreplace $do_what 0 0 assemble]
1460                     verbose -log "Downgraded to an 'assemble' test due to incompatible $group option ($old_option changed to $new_option)"
1461                 }
1462             }
1463             break
1464         }
1465     }
1466
1467     # Add all options to the dg variable.
1468     set options(explicit_p,addressing) 0
1469     set options(explicit_p,forbid_cpu) 0
1470     foreach { group regexp } $mips_option_groups {
1471         if { $options(explicit_p,$group) } {
1472             append extra_tool_flags " " $options(option,$group)
1473         }
1474     }
1475
1476     # If the test is marked as requiring standard libraries check
1477     # that the sysroot has support for the current set of test options.
1478     if { [mips_have_test_option_p options "REQUIRES_STDLIB"] } {
1479         mips_push_test_options saved_options $extra_tool_flags
1480         set output [mips_preprocess "" {
1481               #include <stdlib.h>
1482         } 1]
1483         mips_pop_test_options saved_options
1484
1485         # If the preprocessing of the stdlib.h file produced errors,
1486         # mark the test as unsupported by changing the second element of
1487         # do_what to "N".
1488         # The second element of do_what holds information about test selection
1489         # and it can have one of two values:
1490         # "S" - the test is selected and will be run
1491         # "N" - the test is not selected and will not be run
1492         # This mirrors the format of dg-do-what from lib/dg.exp in DejaGNU.
1493         if { ![string equal $output ""] } {
1494             set do_what [lreplace $do_what 1 1 "N"]
1495         }
1496     }
1497
1498     # If the test is MIPS16-compatible, provide a counterpart to the
1499     # NOMIPS16 convenience macro.
1500     if { [mips_have_test_option_p options "-mips16"] } {
1501         append extra_tool_flags " -DMIPS16=__attribute__((mips16))"
1502     }
1503
1504     if { [mips_have_test_option_p options "-mmicromips"] } {
1505         append extra_tool_flags " -DMICROMIPS=__attribute__((micromips))"
1506     }
1507
1508     # Use our version of gcc-dg-test for this test.
1509     if { ![string equal [info procs "mips-gcc-dg-test"] ""] } {
1510         rename gcc-dg-test mips-old-gcc-dg-test
1511         rename mips-gcc-dg-test gcc-dg-test
1512     }
1513 }
1514
1515 # A version of gcc-dg-test that is used by dg-options tests.
1516 proc mips-gcc-dg-test { prog do_what extra_tool_flags } {
1517     global board_info
1518     global mips_extra_options
1519
1520     # Override the user's chosen test options with the combined test/user
1521     # version.
1522     mips_push_test_options saved_options $mips_extra_options
1523     set result [gcc-dg-test-1 gcc_target_compile $prog \
1524                     $do_what $extra_tool_flags]
1525     mips_pop_test_options saved_options
1526
1527     # Restore the usual gcc-dg-test.
1528     rename gcc-dg-test mips-gcc-dg-test
1529     rename mips-old-gcc-dg-test gcc-dg-test
1530
1531     return $result
1532 }
1533
1534 dg-init
1535 mips-dg-init
1536 gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.c]] \
1537     "" "-DNOMIPS16=__attribute__((nomips16)) -DNOMICROMIPS=__attribute__((nomicromips)) -DNOCOMPRESSION=__attribute__((nocompression))"
1538 mips-dg-finish
1539 dg-finish