OSDN Git Service

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