OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [testsuite/] [gcc.target/] [mips/] [mips.exp] - Blame information for rev 321

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.