RFC & patch: Rework MIPS command-line handling
Richard Sandiford
rsandifo@redhat.com
Fri Jul 12 10:16:00 GMT 2002
[cross-posted to binutils & gcc]
The patch below tries to make MIPS GCC and GAS more consistent in
the way they handle command-line options. This message is really a
RFC on whether it's the right way to go, although the patch has
been tested in the usual way.
I'll use numbers to break things up...
(1) The main discrepancy I see with the current set-up is in the handling
of -march. In GAS, it fully controls the ISA, much like -mipsN does,
but in GCC it only controls the use of processor-specific extensions.
So, for example,
mips-elf-as -march=r8000
selects MIPS IV code but
mips-elf-gcc -march=r8000
selects MIPS I code. I'd like to make it so that both cc1 and gas treat
-march like a more descriptive version of -mipsN. -march=r8000 would
be equivalent to -mips4, -march=r4000 would be equivalent to -mips3,
and so on.
(2) Traditionally, GCC has tried to infer sensible things from a sparse
command line. Passing -mipsN would select a suitable ABI for ISA N,
passing -mabi=FOO would select a suitable ISA for ABI FOO, and so on.
Lately, gas has done the same thing, although the assumptions are
slightly different (more later).
If -march is going to act like -mipsN, then it ought to choose the
ABI as well. For example, if "mips64-elf-gcc -mips1" chooses o32 code
(as it does now) then "mips64-elf-gcc -march=r3000" should do the same.
(3) The GCC code to infer an ABI from an ISA looks like this:
/* A specified ISA defaults the ABI if it was not specified. */
if (mips_abi_string == 0 && mips_isa_string
&& mips_abi != ABI_EABI
&& mips_abi != ABI_O64
&& mips_abi != ABI_MEABI)
{
if (mips_isa == 64)
mips_abi = ABI_O64;
else
{
if (! ISA_HAS_64BIT_REGS)
mips_abi = ABI_32;
else
mips_abi = ABI_64;
}
}
Some problems here:
(a) The o64 exclusion seems strange. Passing -mips1 or -mips2 to
an o64-configured GCC will generate "32-bit o64" code (we get
the 32-bit register size from CC1_SPEC). It turns out to be
almost the same as O32 code, except you get an .mdebug.abiO64
section instead of an .mdebug.abi32 section.
(b) Passing -mips3 to an n32 MIPS III config (e.g. mips-sgi-irix6)
will select n64, which seems counter-intuitive.
(c) The code takes no account of the -mgp32 option. "-mips4 -mgp32"
will set the ABI to n64 without complaint, but generate odd code.
o32 would be a more sensible choice, especially in cases where
o32 is the default anyway.
(d) GAS 2.12 selects o64 (not n64) for -mips3 and -mips4.
The proposed new rule is:
(i) If the default ABI requires 32-bit registers [o32 only] then
switch to o64 when generating 64-bit code.
(ii) If the default ABI requires 64-bit registers [o64, n32 and 64]
then switch to o32 when generating 32-bit code.
Here, "generating X-bit code" takes into account the ISA and
-mgp32 option.
For (i), o64 seems a better choice than n64. Historical precedent
might be one reason to keep n64, but GAS prior to 2.12 didn't support
it and (like (d) says) gas 2.12 would assume you meant o64 instead
of n64. So I can't see the n64 choice would ever have worked
well when using GAS.
Choosing o64 shouldn't hurt mips-sgi-irix6. Since its default ABI
is n32, (i) would mean you still get n32 code after passing -mips3
or -mips4. You can switch to n64 using -mabi=64 in the usual way.
(4) The code to infer an ISA from an ABI is:
/* A specified ABI defaults the ISA if it was not specified. */
else if (mips_isa_string == 0 && mips_abi_string
&& mips_abi != ABI_EABI && mips_abi != ABI_O64)
{
if (mips_abi == ABI_32)
mips_isa = 1;
else if (mips_abi == ABI_N32)
mips_isa = 3;
else
mips_isa = 4;
}
Problems here:
(a) It seems counter-intuitive for -mabi to override the default
architecture even when that default was compatible. For
example, "mipsisa32-elf-gcc -mabi=o32" would generate
MIPS I code rather than MIPS 32 code.
(b) MIPS III and MIPS IV processors can run o32 too, and you can
sometimes get the benefit of extra instructions (like
conditional moves, and sometimes multiply-add). It seems
more appropriate to generate 32-bit code for the default
architecture when passed -mabi=o32, rather than blindly
switching to MIPS I.
(b) There seems no good reason why we should choose MIPS IV over
MIPS III for n64. People have complained: see PR #5938.
Proposed rule in this case:
(i) If the default architecture is 64-bit, -mabi=32 selects
32-bit registers, but keeps the current architecture.
(ii) If the default architecture is MIPS I or MIPS II, selecting
a 64-bit ABI will switch to MIPS III.
(iii) If the default architecture is MIPS 32, selecting a 64-bit
ABI will switch to MIPS 64.
(5) GCC has some code to infer register size from the architecture
and ABI, but it's spread over specs and override_options. I've
moved it all to override_options so that the register size can
depend on -march too.
A few other sundry things:
- -mcpu was deprecated in the last GCC and GAS releases. This
patch removes it.
- Both GCC and GAS could be better at detecting meaningless
combinations. I've tried to catch a few more.
- include/opcode/mips.h defines CPU_R2000, but there's no associated
BFD arch, so -march=r2000 doesn't work. It seems daft to add a 2000
entry at this stage, so I've just mapped it to CPU_R3000 (like GCC).
- There's interim code in TARGET_CPP_BUILTINS that defines _R4000
for 64-bit code and _R3000 for 32-bit code. The patch tries to
fix it.
- GAS and GCC didn't have quite the same -march arguments. For
example, GCC accepts -march=r4kc, but GAS insists on -march=4kc.
To avoid that sort of thing in future, I've written a function
that tries all the variations, using a table of just the
"canonical" names.
I've tried to give the same structure to the GAS and GCC code,
so it's easy to compare and update. A lot of the code is shared
outright.
A few other notes about the GAS changes:
With (5), it's no longer necessary for GAS to check the ABI in
the HAVE_32BIT_* macros, since the register size is always set.
That means we can remove the ABI field from mips_opts. Also, the
new error checking means we can get rid of the ABI-killing code
for -mgp32, -mgp64 and -mfp32:
case OPTION_GP32:
file_mips_gp32 = 1;
if (mips_opts.abi != O32_ABI)
mips_opts.abi = NO_ABI;
break;
This code seems suspect anyway: it's order-dependent, it silently
ignores incompatible options, and it means we ignore "-mabi=eabi" if
followed by "-mgp32" (despite it being a valid combination).
I'd prefer to choose the default CPU in configure: that way, we'd
get a compile-time error over missing entries, plus we can use globs.
Before 2.12, we only set EF_MIPS_ABI when -mabi was given on
the command line. Since EF_MIPS_ABI is a GNU extension, the
onus seems to be on proving that it's safe to use it by default,
rather than the other way about. So the patch uses NO_ABI as
the default for all configurations, but leaves open the possibility
of setting the default to something else on a per-configuration
basis.
And if you read all that, thanks for your patience.
The GAS part was tested on: mips-ecoff, mipsel-ecoff, mips-elf,
mipstx39-elf, mips64-elf, mips64orion-elf, mipsisa32-elf,
mipsisa64-elf, mipsel-linux-gnu and mips-sgi-irix6.5. No
regressions.
GCC part was bootstrapped on mips-sgi-irix6.5, no regressions.
Also tested on mips64-elf, both with and without the GAS part
applied.
One part needs the other, really. If the GCC patch is OK, I was
hoping to apply it before 3.2. The GAS stuff is probably too
invasive for 2.13, though.
Thoughts?
Richard
[include/]
* opcode/mips.h (CPU_R2000): Remove.
[gas/]
* doc/c-mips.texi: Remove -mcpu. Document -mabi.
* configure.in: Work out the default MIPS ABI and architecture.
* configure, config.in: Regenerate.
* config/tc-mips.c (UNSET_ABI): New mips_abi_level.
(file_mips_abi): Rename to mips_abi.
(mips_set_options): Remove "abi" field.
(mips_opts): Update accordingly. Replace all uses of mips_opts.abi
with mips_abi.
(mips_arch_string, user_selected_mips_arch_p): New vars.
(ABI_NEEDS_32BIT_REGS, ABI_NEEDS_64BIT_REGS): New macros.
(HAVE_32BIT_GPRS, HAVE_32BIT_FPRS): Don't check the ABI.
(mips_cpu_info): Remove "is_isa" field.
(mips_isa_to_str, mips_cpu_to_str): Remove.
(mips_ip): Read the processor name from mips_arch_string. Use
mips_isa_level to get the current ISA level.
(OPTION_MCPU): Remove.
(OPTION_FP64): New.
(md_longopts): Add -mfp64, remove -mcpu.
(md_parse_option): Make -mipsN update file_mips_isa rather than
mips_opts.isa. Use mips_parse_cpu. Don't let -mgp32 and -mfp32
change the ABI here.
(show): Constify string argument.
(md_show_usage): Move to the end of the file. Read available
architectures from mips_cpu_info_table.
(mips_set_architecture): New fn.
(mips_after_parse_args): Rework. Remove -mcpu handling. Treat
-march and -mipsN equally when inferring an ABI or register size.
Look at the register size when inferring the ABI, and vice versa.
Complain about more conflicting arguments. (Logic unified
with gcc 3.2.)
(s_mipsset): Don't change the ABI.
(mips_cpu_info_table): Remove is_isa field. Remove ISA-level
entries. Remove entries that vary only in the manufacturer's prefix,
or that have "000" replaced by "k". Remove TARGET_CPU entries.
Make r2000 entry use CPU_R3000.
(mips_cpu_info_from_name): Remove.
(mips_strict_matching_cpu_name_p, mips_matching_cpu_name_p): New fns.
(mips_parse_cpu, mips_isa_level): New fns.
[gas/testsuite]
* gas/mips-gp32-fp64.d,
* gas/mips-gp32-fp64-pic.d: Add -mfp64.
[gcc/]
* doc/invoke.texi: Document -mabi=meabi. Document -mips32, -mips64,
and the associated -march values. Be more careful about what the
default is. Mention the side-effects of -march and -mabi. Say
that the -mipsN options are equivalent to -march.
* toplev.h (target_flags_explicit): Declare.
* toplev.c (target_flags_explicit): New var.
(set_target_switch): Update target_flags_explicit.
* config/mips/isa3264.h (MIPS_ENABLE_EMBEDDED_O32): Undefine.
* config/mips/iris6.h (SUBTARGET_ASM_SPEC): -mabi=64 implies
-mips3 instead of -mips4.
* config/mips/elforion.h, config/mips/r3900.h: Define
MIPS_CPU_DEFAULT instead of MIPS_CPU_STRING_DEFAULT.
* config/mips/mips.h (mips_cpu_string): Remove.
(mips_explicit_type_size_string): Remove.
(mips_cpp_processor_macro): Declare.
(TARGET_CPP_BUILTINS): Use mips_cpp_processor_macro.
(TARGET_OPTIONS): Remove -mcpu and -mexplicit-type-size.
(ABI_NEEDS_32BIT_REGS, ABI_NEEDS_64BIT_REGS): New.
(GAS_ASM_SPEC): Remove -mabi=32 -> -mipsN rule.
(CC1_SPEC): Remove ISA -> register-size rules.
* config/mips/mips.c (user_selected_mips_arch_p): New var.
(mips_cpu_string, mips_explicit_type_size_string): Remove.
(mips_cpp_processor_macro): New var.
(struct mips_processor): New.
(mips_processors): New array.
(mips_set_architecture): New fn.
(override_options): Rework to make -mipsN equivalent to -march.
Detect more erroneous cases, including those removed from CC1_SPEC.
Make o64 the default 64-bit ABI when selecting a 64-bit processor
for a 32-bit config. Make -mips3 the default for -mabi=64.
Unify logic with GAS 2.14.
(mips_strict_matching_cpu_name_p, mips_matching_cpu_name_p): New fns.
(mips_parse_cpu): Take the name of the option as argument. Raise
an error if the option is wrong.
(mips_cpu_from_isa_level): New fn.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mips-config-gas.diff
Type: text/x-patch
Size: 59549 bytes
Desc: GAS patch
URL: <https://sourceware.org/pipermail/binutils/attachments/20020712/de30a49a/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mips-config-gcc.diff
Type: text/x-patch
Size: 48102 bytes
Desc: GCC patch
URL: <https://sourceware.org/pipermail/binutils/attachments/20020712/de30a49a/attachment-0001.bin>
More information about the Binutils
mailing list