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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [gcc.target/] [mips/] [mips.exp] - Blame information for rev 704

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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