OSDN Git Service

gcc/testsuite/
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.target / mips / mips.exp
1 # Copyright (C) 1997, 2007, 2008, 2009 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 set mips_option_groups {
226     abi "-mabi=.*"
227     addressing "addressing=.*"
228     arch "-mips([1-5]|32.*|64.*)|-march=.*|isa(|_rev)(=|<=|>=).*"
229     dump_pattern "-dp"
230     endianness "-E(L|B)|-me(l|b)"
231     float "-m(hard|soft)-float"
232     forbid_cpu "forbid_cpu=.*"
233     fp "-mfp(32|64)"
234     gp "-mgp(32|64)"
235     long "-mlong(32|64)"
236     mips16 "-mips16|-mno-mips16"
237     mips3d "-mips3d|-mno-mips3d"
238     optimization "-O(|[0-3s])"
239     pic "-f(no-|)(pic|PIC)"
240     profiling "-pg"
241     small-data "-G[0-9]+"
242     warnings "-w"
243 }
244
245 # Add -mfoo/-mno-foo options to mips_option_groups.
246 foreach option {
247     abicalls
248     branch-likely
249     dsp
250     dspr2
251     explicit-relocs
252     extern-sdata
253     fix-r4000
254     fix-r10000
255     fix-vr4130
256     gpopt
257     local-sdata
258     long-calls
259     paired-single
260     plt
261     shared
262     smartmips
263     sym32
264     synci
265 } {
266     lappend mips_option_groups $option "-m(no-|)$option"
267 }
268
269 # Add -mfoo= options to mips_option_groups.
270 foreach option {
271     branch-cost
272     code-readable
273     r10k-cache-barrier
274     tune
275 } {
276     lappend mips_option_groups $option "-m$option=.*"
277 }
278
279 # Add -ffoo/-fno-foo options to mips_option_groups.
280 foreach option {
281     delayed-branch
282     fast-math
283     finite-math-only
284     fixed-hi
285     fixed-lo
286     lax-vector-conversions
287     split-wide-types
288     tree-vectorize
289 } {
290     lappend mips_option_groups $option "-f(no-|)$option"
291 }
292
293 # A list of option groups that have an impact on the ABI.
294 set mips_abi_groups {
295     abi
296     abicalls
297     arch
298     endianness
299     float
300     fp
301     gp
302     gpopt
303     long
304     pic
305     small-data
306 }
307
308 # mips_option_tests(OPTION) is some assembly code that will run to completion
309 # on a target that supports OPTION.
310 set mips_option_tests(-mips16) {
311     move $2,$31
312     bal 1f
313     .set mips16
314     jr $31
315     .set nomips16
316     .align 2
317 1:
318     ori $3,$31,1
319     jalr $3
320     move $31,$2
321 }
322 set mips_option_tests(-mpaired-single) {
323     .set mips64
324     lui $2,0x3f80
325     mtc1 $2,$f0
326     cvt.ps.s $f2,$f0,$f0
327 }
328 set mips_option_tests(-mips3d) {
329     .set mips64
330     .set mips3d
331     lui $2,0x3f80
332     mtc1 $2,$f0
333     cvt.ps.s $f2,$f0,$f0
334     mulr.ps $f2,$f2,$f2
335     rsqrt1.s $f2,$f0
336     mul.s $f4,$f2,$f0
337     rsqrt2.s $f4,$f4,$f2
338     madd.s $f4,$f2,$f2,$f4
339 }
340 set mips_option_tests(-mdsp) {
341     .set mips64r2
342     .set dsp
343     addsc $2,$2,$2
344 }
345 set mips_option_tests(-mdspr2) {
346     .set mips64r2
347     .set dspr2
348     prepend $2,$3,11
349 }
350
351 # Canonicalize command-line option OPTION.
352 proc mips_canonicalize_option { option } {
353     regsub {^-mips([1-5]|32*|64*)$} $option {-march=mips\1} option
354
355     regsub {^-mel$} $option {-EL} option
356     regsub {^-meb$} $option {-EB} option
357
358     regsub {^-O$} $option {-O1} option
359
360     # MIPS doesn't use -fpic and -fPIC to distinguish between code models.
361     regsub {^-f(no-|)PIC} $option {-f\1pic} option
362
363     return $option
364 }
365
366 # Return true if OPTION1 and OPTION2 represent the same command-line option.
367 proc mips_same_option_p { option1 option2 } {
368     return [string equal \
369                 [mips_canonicalize_option $option1] \
370                 [mips_canonicalize_option $option2]]
371 }
372
373 # Preprocess CODE using target_compile options OPTIONS.  Return the
374 # compiler output.
375 proc mips_preprocess { options code } {
376     global tool
377
378     set src dummy[pid].c
379     set f [open $src "w"]
380     puts $f $code
381     close $f
382     set output [${tool}_target_compile $src "" preprocess $options]
383     file delete $src
384
385     return $output
386 }
387
388 # Set the target board's command-line options to NEW_OPTIONS, storing the
389 # old values in UPVAR.
390 proc mips_push_test_options { upvar new_options } {
391     upvar $upvar var
392     global board_info
393
394     array unset var
395     set var(name) board_info([target_info name],multilib_flags)
396     if { [info exists $var(name)] } {
397         set var(old_options) [set $var(name)]
398         set $var(name) [join $new_options " "]
399     }
400 }
401
402 # Undo the effects of [mips_push_test_options UPVAR ...]
403 proc mips_pop_test_options { upvar } {
404     upvar $upvar var
405     global board_info
406
407     if { [info exists var(old_options)] } {
408         set $var(name) $var(old_options)
409     }
410 }
411
412 # Return property PROP for architecture option ARCH (which belongs to
413 # the "arch" group in mips_option_groups).  See the comment at the
414 # top of the file for the valid property names.
415 #
416 # Cache the results in mips_arch_info (which can be reused between test
417 # variants).
418 proc mips_arch_info { arch prop } {
419     global mips_arch_info
420     global board_info
421
422     set arch [mips_canonicalize_option $arch]
423     if { ![info exists mips_arch_info($arch,$prop)] } {
424         mips_push_test_options saved_options {}
425         set output [mips_preprocess [list "additional_flags=$arch -mabi=32"] {
426             int isa = __mips;
427             #ifdef __mips_isa_rev
428             int isa_rev = __mips_isa_rev;
429             #else
430             int isa_rev = 0;
431             #endif
432         }]
433         foreach lhs { isa isa_rev } {
434             regsub ".*$lhs = (\[^;\]*).*" $output {\1} rhs
435             verbose -log "Architecture $arch has $lhs $rhs"
436             set mips_arch_info($arch,$lhs) $rhs
437         }
438         mips_pop_test_options saved_options
439     }
440     return $mips_arch_info($arch,$prop)
441 }
442
443 # Return the option group associated with OPTION, or "" if none.
444 proc mips_option_maybe_group { option } {
445     global mips_option_groups
446
447     foreach { group regexp } $mips_option_groups {
448         if { [regexp -- "^($regexp)\$" $option] } {
449             return $group
450         }
451     }
452     return ""
453 }
454
455 # Return the option group associated with OPTION.  Raise an error if
456 # there is none.
457 proc mips_option_group { option } {
458     set group [mips_option_maybe_group $option]
459     if { [string equal $group ""] } {
460         error "Unrecognised option: $option"
461     }
462     return $group
463 }
464
465 # Return the option for option group GROUP, or "" if no option in that
466 # group has been chosen.  UPSTATUS describes the option status.
467 proc mips_option { upstatus group } {
468     upvar $upstatus status
469
470     return $status(option,$group)
471 }
472
473 # If the base options for this test run include an option in group GROUP,
474 # return that option, otherwise return "".
475 proc mips_original_option { group } {
476     global mips_base_options
477
478     return [mips_option mips_base_options $group]
479 }
480
481 # Return true if the test described by UPSTATUS requires a specific
482 # option in group GROUP.  UPSTATUS describes the option status.
483 proc mips_test_option_p { upstatus group } {
484     upvar $upstatus status
485
486     return $status(test_option_p,$group)
487 }
488
489 # If the test described by UPSTATUS requires a particular option in group
490 # GROUP, return that option, otherwise return "".
491 proc mips_test_option { upstatus group } {
492     upvar $upstatus status
493
494     if { [mips_test_option_p status $group] } {
495         return [mips_option status $group]
496     } else {
497         return ""
498     }
499 }
500
501 # Return true if the options described by UPSTATUS include OPTION.
502 proc mips_have_option_p { upstatus option } {
503     upvar $upstatus status
504
505     return [mips_same_option_p \
506                 [mips_option status [mips_option_group $option]] \
507                 $option]
508 }
509
510 # Return true if the test described by UPSTATUS requires option OPTION.
511 proc mips_have_test_option_p { upstatus option } {
512     upvar $upstatus status
513
514     set group [mips_option_group $option]
515     return [mips_same_option_p [mips_test_option status $group] $option]
516 }
517
518 # If the test described by UPSTATUS does not specify an option in
519 # OPTION's group, act as though it had specified OPTION.
520 #
521 # The first optional argument indicates whether the option should be
522 # treated as though it were wrapped in parentheses; see the comment at
523 # the top of the file for details about this convention.  The default is 0.
524 proc mips_make_test_option { upstatus option args } {
525     upvar $upstatus status
526
527     set group [mips_option_group $option]
528     if { ![mips_test_option_p status $group] } {
529         set status(option,$group) $option
530         set status(test_option_p,$group) 1
531         if { [llength $args] == 0 || ![lindex $args 0] } {
532             set status(explicit_p,$group) 1
533         }
534     }
535 }
536
537 # If the test described by UPSTATUS requires option FROM, assume that
538 # it implicitly requires option TO.
539 proc mips_option_dependency { upstatus from to } {
540     upvar $upstatus status
541
542     if { [mips_have_test_option_p status $from] } {
543         mips_make_test_option status $to
544     }
545 }
546
547 # Return true if the given arch-group option specifies a 32-bit ISA.
548 proc mips_32bit_arch_p { option } {
549     set isa [mips_arch_info $option isa]
550     return [expr { $isa < 3 || $isa == 32 }]
551 }
552
553 # Return true if the given arch-group option specifies a 64-bit ISA.
554 proc mips_64bit_arch_p { option } {
555     return [expr { ![mips_32bit_arch_p $option] }]
556 }
557
558 # Return true if the given abi-group option implicitly requires -mgp32.
559 proc mips_32bit_abi_p { option } {
560     switch -glob -- $option {
561         -mabi=32 {
562             return 1
563         }
564     }
565     return 0
566 }
567
568 # Return true if the given abi-group option implicitly requires -mgp64.
569 proc mips_64bit_abi_p { option } {
570     switch -glob -- $option {
571         -mabi=o64 -
572         -mabi=n32 -
573         -mabi=64 {
574             return 1
575         }
576     }
577     return 0
578 }
579
580 # Check whether the current target supports all the options that the
581 # current test requires.  Return "" if so, otherwise return one of
582 # the incompatible options.  UPSTATUS describes the option status.
583 proc mips_first_unsupported_option { upstatus } {
584     global mips_option_tests
585     upvar $upstatus status
586
587     foreach { option code } [array get mips_option_tests] {
588         if { [mips_have_test_option_p status $option] } {
589             regsub -all "\n" $code "\\n\\\n" asm
590             # Use check_runtime from target-supports.exp, which caches
591             # the result for us.
592             if { ![check_runtime mips_option_$option [subst {
593                 __attribute__((nomips16)) int
594                 main (void)
595                 {
596                     asm (".set push\
597                     $asm\
598                     .set pop");
599                     return 0;
600                 }
601             }]] } {
602                 return $option
603             }
604         }
605     }
606     return ""
607 }
608
609 # Initialize this testsuite for a new test variant.
610 proc mips-dg-init {} {
611     # Invariant information.
612     global mips_option_groups
613
614     # Internally-generated information about this run.
615     global mips_base_options
616     global mips_extra_options
617
618     # Override dg-options with our mips-dg-options routine.
619     rename dg-options mips-old-dg-options
620     rename mips-dg-options dg-options
621
622     # Start with a fresh option status.
623     array unset mips_base_options
624     foreach { group regexp } $mips_option_groups {
625         set mips_base_options(option,$group) ""
626         set mips_base_options(explicit_p,$group) 0
627         set mips_base_options(test_option_p,$group) 0
628     }
629
630     # Use preprocessor macros to work out as many implicit options as we can.
631     set output [mips_preprocess "" {
632         const char *options[] = {
633             #if !defined _MIPS_SIM
634             "-mabi=eabi",
635             #elif _MIPS_SIM==_ABIO32
636             "-mabi=32",
637             #elif _MIPS_SIM==_ABIO64
638             "-mabi=o64",
639             #elif _MIPS_SIM==_ABIN32
640             "-mabi=n32",
641             #else
642             "-mabi=64",
643             #endif
644
645             "-march=" _MIPS_ARCH,
646
647             #ifdef _MIPSEB
648             "-EB",
649             #else
650             "-EL",
651             #endif
652
653             #ifdef __mips_hard_float
654             "-mhard-float",
655             #else
656             "-msoft-float",
657             #endif
658
659             #if __mips_fpr == 64
660             "-mfp64",
661             #else
662             "-mfp32",
663             #endif
664
665             #ifdef __mips64
666             "-mgp64",
667             #else
668             "-mgp32",
669             #endif
670
671             #if _MIPS_SZLONG == 64
672             "-mlong64",
673             #else
674             "-mlong32",
675             #endif
676
677             #ifdef __mips16
678             "-mips16",
679             #else
680             "-mno-mips16",
681             #endif
682
683             #ifdef __mips3d
684             "-mips3d",
685             #else
686             "-mno-mips3d",
687             #endif
688
689             #ifdef __mips_paired_single_float
690             "-mpaired-single",
691             #else
692             "-mno-paired-single",
693             #endif
694
695             #if __mips_abicalls
696             "-mabicalls",
697             #else
698             "-mno-abicalls",
699             #endif
700
701             #if __mips_dsp_rev >= 2
702             "-mdspr2",
703             #else
704             "-mno-dspr2",
705             #endif
706
707             #if __mips_dsp_rev >= 1
708             "-mdsp",
709             #else
710             "-mno-dsp",
711             #endif
712
713             #ifndef __PIC__
714             "addressing=absolute",
715             #endif
716
717             #ifdef __mips_smartmips
718             "-msmartmips",
719             #else
720             "-mno-smartmips",
721             #endif
722
723             0
724         };
725     }]
726     foreach line [split $output "\r\n"] {
727         # Poor man's string concatenation.
728         regsub -all {" "} $line "" line
729         if { [regexp {"(.*)",} $line dummy option] } {
730             set group [mips_option_group $option]
731             set mips_base_options(option,$group) $option
732         }
733     }
734
735     # Process the target's multilib options, saving any unrecognized
736     # ones in mips_extra_options.
737     set mips_extra_options {}
738     foreach option [split [board_info target multilib_flags]] {
739         set group [mips_option_maybe_group $option]
740         if { ![string equal $group ""] } {
741             set mips_base_options(option,$group) $option
742             set mips_base_options(explicit_p,$group) 1
743         } else {
744             lappend mips_extra_options $option
745         }
746     }
747 }
748
749 # Finish a test run started by mips-dg-init.
750 proc mips-dg-finish {} {
751     rename dg-options mips-dg-options
752     rename mips-old-dg-options dg-options
753 }
754
755 # Override dg-options so that we can do some MIPS-specific processing.
756 # All options used in this testsuite must appear in mips_option_groups.
757 #
758 # Test options override multilib options.  Certain test options can
759 # also imply other test options, which also override multilib options.
760 # These dependencies are ordered as follows:
761 #
762 #          START                        END
763 #            |                           |
764 #         -mips16                     -mno-mips16
765 #            |                           |
766 #         -mips3d                     -mno-mips3d
767 #            |                           |
768 #         -mpaired-single             -mno-paired-single
769 #            |                           |
770 #         -mfp64                      -mfp32
771 #            |                           |
772 #         -mhard-float                -msoft-float
773 #            |                           |
774 #         -mno-sym32                  -msym32
775 #            |                           |
776 #         -fpic                       -fno-pic
777 #            |                           |
778 #         -mshared                    -mno-shared
779 #            |                           |
780 #         -mno-plt                    -mplt
781 #            |                           |
782 #         addressing=unknown          addressing=absolute
783 #            |                           |
784 #         -mabicalls                  -mno-abicalls
785 #            |                           |
786 #         -G0                         <other value>
787 #            |                           |
788 #         <other value>               -mr10k-cache-barrier=none
789 #            |                           |
790 #         -mfix-r10000                -mno-fix-r10000
791 #            |                           |
792 #         -mbranch-likely             -mno-branch-likely
793 #            |                           |
794 #         -msmartmips                 -mno-smartmips
795 #            |                           |
796 #         -mno-gpopt                  -mgpopt
797 #            |                           |
798 #         -mexplicit-relocs           -mno-explicit-relocs
799 #            |                           |
800 #            +-- gp, abi & arch ---------+
801 #
802 # For these purposes, the "gp", "abi" & "arch" option groups are treated
803 # as a single node.
804 proc mips-dg-options { args } {
805     # dg.exp variables.
806     upvar dg-extra-tool-flags extra_tool_flags
807     upvar dg-do-what do_what
808
809     # Invariant information.
810     global mips_option_groups
811     global mips_abi_groups
812
813     # Information about this run.
814     global mips_base_options
815
816     # Start out with the default option state.
817     array set options [array get mips_base_options]
818
819     # Record the options that this test explicitly needs.
820     foreach option [lindex $args 1] {
821         set all_but_p [regexp {^\((.*)\)$} $option dummy option]
822         set group [mips_option_group $option]
823         if { [mips_test_option_p options $group] } {
824             set old [mips_option options $group]
825             error "Inconsistent $group option: $old vs. $option"
826         } else {
827             mips_make_test_option options $option $all_but_p
828         }
829     }
830
831     # Handle dependencies between options on the left of the
832     # dependency diagram.
833     mips_option_dependency options "-mips3d" "-mpaired-single"
834     mips_option_dependency options "-mpaired-single" "-mfp64"
835     mips_option_dependency options "-mfp64" "-mhard-float"
836     mips_option_dependency options "-fpic" "-mshared"
837     mips_option_dependency options "-mshared" "-mno-plt"
838     mips_option_dependency options "-mno-plt" "addressing=unknown"
839     mips_option_dependency options "-mabicalls" "-G0"
840     mips_option_dependency options "-mno-gpopt" "-mexplicit-relocs"
841
842     # Work out information about the current ABI.
843     set abi_test_option_p [mips_test_option_p options abi]
844     set abi [mips_option options abi]
845     set eabi_p [mips_same_option_p $abi "-mabi=eabi"]
846
847     # If the test forces a particular ABI, set the register size
848     # accordingly.
849     if { $abi_test_option_p } {
850         if { [mips_32bit_abi_p $abi] } {
851             mips_make_test_option options "-mgp32"
852         } elseif { [mips_64bit_abi_p $abi] } {
853             mips_make_test_option options "-mgp64"
854         }
855     }
856
857     # See whether forbid_cpu forces us to choose a new architecture.
858     set arch [mips_option mips_base_options arch]
859     set force_generic_isa_p [expr {
860         [regexp "forbid_cpu=(.*)" [mips_option options forbid_cpu] dummy spec]
861         && [regexp -- "^-march=$spec\$" $arch]
862     }]
863
864     # Interpret the special "isa" and "isa_rev" options.  If we have
865     # a choice of a 32-bit or a 64-bit architecture, prefer to keep
866     # the -mgp setting the same.
867     set spec [mips_option options arch]
868     if { [regexp {^[^-]} $spec] } {
869         if { [string equal $spec "isa=loongson"] } {
870             if { ![regexp {^-march=loongson} $arch] } {
871                 set arch "-march=loongson2f"
872             }
873         } else {
874             if { ![regexp {^(isa(?:|_rev))(=|<=|>=)([0-9]*)$} \
875                        $spec dummy prop relation value nocpus] } {
876                 error "Unrecognized isa specification: $spec"
877             }
878             set current [mips_arch_info $arch $prop]
879             if { $force_generic_isa_p
880                  || ($current < $value && ![string equal $relation "<="])
881                  || ($current > $value && ![string equal $relation ">="])
882                  || ([mips_have_test_option_p options "-mgp64"]
883                      && [mips_32bit_arch_p $arch]) } {
884                 # The current setting is out of range; it cannot
885                 # possibly be used.  Find a replacement that can.
886                 if { [string equal $prop "isa"] } {
887                     set arch "-mips$value"
888                 } elseif { $value == 0 } {
889                     set arch "-mips4"
890                 } else {
891                     if { [mips_have_option_p options "-mgp32"] } {
892                         set arch "-mips32"
893                     } else {
894                         set arch "-mips64"
895                     }
896                     if { $value > 1 } {
897                         append arch "r$value"
898                     }
899                 }
900             }
901         }
902         set options(option,arch) $arch
903     }
904
905     # Work out information about the current architecture.
906     set arch_test_option_p [mips_test_option_p options arch]
907     set arch [mips_option options arch]
908     set isa [mips_arch_info $arch isa]
909     set isa_rev [mips_arch_info $arch isa_rev]
910
911     # If the test forces a 32-bit architecture, force -mgp32.
912     # Force the current -mgp setting otherwise; if we don't,
913     # some configurations would make a 64-bit architecture
914     # imply -mgp64.
915     if { $arch_test_option_p } {
916         if { [mips_32bit_arch_p $arch] } {
917             mips_make_test_option options "-mgp32"
918         } else {
919             mips_make_test_option options [mips_option options gp]
920         }
921     }
922
923     # We've now fixed the GP register size.  Make it easily available.
924     set gp_size [expr { [mips_have_option_p options "-mgp32"] ? 32 : 64 }]
925
926     # Handle dependencies between the pre-arch options and the arch option.
927     # This should mirror the arch and post-arch code below.
928     if { !$arch_test_option_p } {
929         # We need a revision 2 or better ISA for:
930         #
931         #   - the combination of -mgp32 -mfp64
932         #   - the DSP ASE
933         if { $isa_rev < 2
934              && (($gp_size == 32 && [mips_have_test_option_p options "-mfp64"])
935                  || [mips_have_test_option_p options "-mdsp"]
936                  || [mips_have_test_option_p options "-mdspr2"]) } {
937             if { $gp_size == 32 } {
938                 mips_make_test_option options "-mips32r2"
939             } else {
940                 mips_make_test_option options "-mips64r2"
941             }
942         # We need a MIPS32 or MIPS64 ISA for:
943         #
944         #   - paired-single instructions(*)
945         #
946         # (*) Note that we don't support MIPS V at the moment.
947         } elseif { $isa_rev < 1
948                    && [mips_have_test_option_p options "-mpaired-single"] } {
949             if { $gp_size == 32 } {
950                 mips_make_test_option options "-mips32"
951             } else {
952                 mips_make_test_option options "-mips64"
953             }
954         # We need MIPS III or higher for:
955         #
956         #   - the "cache" instruction
957         } elseif { $isa < 3
958                    && ([mips_have_test_option_p options \
959                             "-mr10k-cache-barrier=load-store"]
960                        || [mips_have_test_option_p options \
961                                "-mr10k-cache-barrier=store"]) } {
962             mips_make_test_option options "-mips3"
963         # We need MIPS II or higher for:
964         #
965         #   - branch-likely instructions(*)
966         #
967         # (*) needed by both -mbranch-likely and -mfix-r10000
968         } elseif { $isa < 2
969                    && ([mips_have_test_option_p options "-mbranch-likely"]
970                        || [mips_have_test_option_p options "-mfix-r10000"]) } {
971             mips_make_test_option options "-mips2"
972         # Check whether we need to switch from a 32-bit processor to the
973         # "nearest" 64-bit processor.
974         } elseif { $gp_size == 64 && [mips_32bit_arch_p $arch] } {
975             if { $isa_rev == 0 } {
976                 mips_make_test_option options "-mips3"
977             } elseif { $isa_rev == 1 } {
978                 mips_make_test_option options "-mips64"
979             } else {
980                 mips_make_test_option options "-mips64r$isa_rev"
981             }
982         # Otherwise, if the current choice of architecture is unacceptable,
983         # choose the equivalent generic architecture.
984         } elseif { $force_generic_isa_p } {
985             set arch "-mips[mips_arch_info $arch isa]"
986             if { $isa_rev > 1 } {
987                 append arch "r$isa_rev"
988             }
989             mips_make_test_option options $arch
990         }
991         unset arch
992         unset isa
993         unset isa_rev
994     }
995
996     # Set an appropriate ABI, handling dependencies between the pre-abi
997     # options and the abi options.  This should mirror the abi and post-abi
998     # code below.
999     if { !$abi_test_option_p } {
1000         if { ($eabi_p
1001               && ([mips_have_option_p options "-mabicalls"]
1002                   || ($gp_size == 32
1003                       && [mips_have_option_p options "-mfp64"]))) } {
1004             # EABI doesn't support -mabicalls.
1005             # EABI doesn't support the combination -mgp32 -mfp64.
1006             set force_abi 1
1007         } elseif { [mips_have_option_p options "-mips16"]
1008                    && ![mips_same_option_p $abi "-mabi=32"]
1009                    && ![mips_same_option_p $abi "-mabi=o64"]
1010                    && (![mips_have_option_p options "addressing=absolute"]
1011                        || [mips_have_option_p options "-mhard-float"]) } {
1012             # -mips16 -mhard-float requires o32 or o64.
1013             # -mips16 PIC requires o32 or o64.
1014             set force_abi 1
1015         } else {
1016             set force_abi 0
1017         }
1018         if { $gp_size == 32 } {
1019             if { $force_abi || [mips_64bit_abi_p $abi] } {
1020                 mips_make_test_option options "-mabi=32"
1021             }
1022         } else {
1023             if { $force_abi || [mips_32bit_abi_p $abi] } {
1024                 # All configurations should have an assembler that
1025                 # supports o64, since it requires the same BFD target
1026                 # vector as o32.  In contrast, many assembler
1027                 # configurations do not have n32 or n64 support.
1028                 mips_make_test_option options "-mabi=o64"
1029             }
1030         }
1031         unset abi
1032         unset eabi_p
1033     }
1034
1035     # Handle dependencies between the abi options and the post-abi options.
1036     # This should mirror the abi and pre-abi code above.
1037     if { $abi_test_option_p } {
1038         if { $eabi_p } {
1039             mips_make_test_option options "-mno-abicalls"
1040             if { $gp_size == 32 } {
1041                 mips_make_test_option options "-mfp32"
1042             }
1043         }
1044         if { [mips_have_option_p options "-mips16"]
1045              && ![mips_same_option_p $abi "-mabi=32"]
1046              && ![mips_same_option_p $abi "-mabi=o64"]
1047              && (![mips_have_option_p options "addressing=absolute"]
1048                  || [mips_have_option_p options "-mhard-float"]) } {
1049             if { [mips_test_option_p options mips16] } {
1050                 mips_make_test_option options "addressing=absolute"
1051                 mips_make_test_option options "-msoft-float"
1052             } else {
1053                 mips_make_test_option options "-mno-mips16"
1054             }
1055         }
1056         unset abi
1057         unset eabi_p
1058     }
1059
1060     # Handle dependencies between the arch option and the post-arch options.
1061     # This should mirror the arch and pre-arch code above.
1062     if { $arch_test_option_p } {
1063         if { $isa < 2 } {
1064             mips_make_test_option options "-mno-branch-likely"
1065             mips_make_test_option options "-mno-fix-r10000"
1066         }
1067         if { $isa < 3 } {
1068             mips_make_test_option options "-mr10k-cache-barrier=none"
1069         }
1070         if { $isa_rev < 1 } {
1071             mips_make_test_option options "-mno-paired-single"
1072         }
1073         if { $isa_rev < 2 } {
1074             if { $gp_size == 32 } {
1075                 mips_make_test_option options "-mfp32"
1076             }
1077             mips_make_test_option options "-mno-dsp"
1078             mips_make_test_option options "-mno-dspr2"
1079         }
1080         unset arch
1081         unset isa
1082         unset isa_rev
1083     }
1084
1085     # Handle dependencies between options on the right of the diagram.
1086     mips_option_dependency options "-mno-explicit-relocs" "-mgpopt"
1087     switch -- [mips_test_option options small-data] {
1088         "" -
1089         -G0 {}
1090         default {
1091             mips_make_test_option options "-mno-abicalls"
1092         }
1093     }
1094     if { [mips_have_option_p options "-mabicalls"] } {
1095         mips_option_dependency options "addressing=absolute" "-mplt"
1096     }
1097     mips_option_dependency options "-mplt" "-msym32"
1098     mips_option_dependency options "-mplt" "-mno-shared"
1099     mips_option_dependency options "-mno-shared" "-fno-pic"
1100     mips_option_dependency options "-mfp32" "-mno-paired-single"
1101     mips_option_dependency options "-msoft-float" "-mno-paired-single"
1102     mips_option_dependency options "-mno-paired-single" "-mno-mips3d"
1103
1104     # If the test requires an unsupported option, change run tests
1105     # to link tests.
1106
1107     switch -- [lindex $do_what 0] {
1108         run {
1109             set option [mips_first_unsupported_option options]
1110             if { ![string equal $option ""] } {
1111                 set do_what [lreplace $do_what 0 0 link]
1112                 verbose -log "Downgraded to a 'link' test due to unsupported option '$option'"
1113             }
1114         }
1115     }
1116
1117     # If the test has overridden a option that changes the ABI,
1118     # downgrade a link or execution test to an assembler test.
1119     foreach group $mips_abi_groups {
1120         set old_option [mips_original_option $group]
1121         set new_option [mips_option options $group]
1122         if { ![mips_same_option_p $old_option $new_option] } {
1123             switch -- [lindex $do_what 0] {
1124                 link -
1125                 run {
1126                     set do_what [lreplace $do_what 0 0 assemble]
1127                     verbose -log "Downgraded to an 'assemble' test due to incompatible $group option ($old_option changed to $new_option)"
1128                 }
1129             }
1130             break
1131         }
1132     }
1133
1134     # Add all options to the dg variable.
1135     set options(explicit_p,addressing) 0
1136     set options(explicit_p,forbid_cpu) 0
1137     foreach { group regexp } $mips_option_groups {
1138         if { $options(explicit_p,$group) } {
1139             append extra_tool_flags " " $options(option,$group)
1140         }
1141     }
1142
1143     # If the test is MIPS16-compatible, provide a counterpart to the
1144     # NOMIPS16 convenience macro.
1145     if { [mips_have_test_option_p options "-mips16"] } {
1146         append extra_tool_flags " -DMIPS16=__attribute__((mips16))"
1147     }
1148
1149     # Use our version of gcc-dg-test for this test.
1150     if { ![string equal [info procs "mips-gcc-dg-test"] ""] } {
1151         rename gcc-dg-test mips-old-gcc-dg-test
1152         rename mips-gcc-dg-test gcc-dg-test
1153     }
1154 }
1155
1156 # A version of gcc-dg-test that is used by dg-options tests.
1157 proc mips-gcc-dg-test { prog do_what extra_tool_flags } {
1158     global board_info
1159     global mips_extra_options
1160
1161     # Override the user's chosen test options with the combined test/user
1162     # version.
1163     mips_push_test_options saved_options $mips_extra_options
1164     set result [gcc-dg-test-1 gcc_target_compile $prog \
1165                     $do_what $extra_tool_flags]
1166     mips_pop_test_options saved_options
1167
1168     # Restore the usual gcc-dg-test.
1169     rename gcc-dg-test mips-gcc-dg-test
1170     rename mips-old-gcc-dg-test gcc-dg-test
1171
1172     return $result
1173 }
1174
1175 dg-init
1176 mips-dg-init
1177 # MIPS16 is defined by "-mips16" or "(-mips16)" in dg-options.
1178 dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.c]] "" \
1179     "-DNOMIPS16=__attribute__((nomips16))"
1180 mips-dg-finish
1181 dg-finish