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