[Revised patch] Rework MIPS command-line handling

Richard Sandiford rsandifo@redhat.com
Thu Jul 18 12:27:00 GMT 2002


First, thanks to everyone who responded to my first message.
I've tried to incorporate the feedback into the patch below.

Brief summary of changes:

1) both gcc & gas now accept -march=mipsN
2) gcc defines _MIPS_ARCH and _MIPS_TUNE
3) ELF gccs will always pass an ABI option to the assembler
4) all configs now support -mabi
5) there is now a special 'from-abi' architecture
6) -mabi doesn't change the default architecture (but see below)
7) -march doesn't change the ABI (modulo 32/64-bit selection for EABIs)

More details:

1) Internally, gcc treats -mips1 and -march=mips1 like -march=r2000,
   and similarly for the other ISA levels.

   Question is, what are right values for _MIPS_ARCH and _MIPS_TUNE when
   you use a generic ISA?  It doesn't seem right for them to name a
   processor when the command line and configuration don't specify one.
   So in the patch I've just set them to 0.  It gives users a way of
   distinguishing between -march=mipsN and -march=<processor>, should
   they want to.

2) Each processor has a macro of the form _MIPS_<name>.  As suggested,
   each known processor has distinct macro, even if GCC treats them
   the same way internally.  So there's both a _MIPS_R2000 and
   a _MIPS_R3000, for example.

   Not the biggest issue, I know, but is _MIPS_<foo> OK for the
   processor macros?  I guess other alternatives would be
   _MIPS_PROCESSOR_<foo> or _PROCESSOR_<foo>.

   I guess the values of these macros ought not to change between
   releases, just in case someone stores _MIPS_ARCH in a variable
   in one compilation unit and reads it in another, compiled with
   a different version of gcc.  So I've used a (lame!) convention
   for giving each entry a unique value.  See comment above
   mips_cpu_info_table[] in mips.c for details.

   This should also make it easier to check for a range of
   processors, such as members of a family that have different
   tuning characteristics but the same basic ISA.

3) There seemed to be general agreement that we should record the
   default ABI in ELF objects.  We could teach GAS about the default
   ABI for each target (I left this option open in my earlier patch).
   But I'd really rather not do it that way: it would mean duplicating
   a whole load of config.gcc logic, and it could lead to subtle
   incompatabilities between GCC and GAS in future.

   In this case, I'd rather use gcc specs.  This stands more chance of
   working with non-GAS targets and earlier binutils releases.  It's
   also much cleaner code-wise.  All I'm talking about is

	%{!mabi=*: %(asm_abi_default_spec)}

   in ASM_SPEC (see comments in patch for why ASM_SPEC instead of
   the others).

   There's still the problem that some OSes don't understand
   E_MIPS_ABI_O32.  I've added a way of disabling it for specific
   targets.  So far, irix is the only one to take advantage.

4) After these changes, there doesn't seem any reason to limit
   -mabi to the current handful of targets.  I often hack it in
   to the other targets for testing, and I'm sure others do too.

   Safety might be one concern.  But since ELF targets will always
   pass an ABI flag to the assembler, there should be little chance of
   accidents there.  For COFF targets, the user will get an error if
   they use -mabi with an assembler that doesn't support it (see
   changes to ASM_SPEC).

5) I prefer '-march=from-abi' over '-mstrict-abi' and '-mdeduce-arch'
   (which were the other suggestions I saw).  For one thing, it brings
   all architecture-changing stuff under -march, but more importantly,
   a configuration can then have "from-abi" as its default architecture.
   Which leads on to...

6) The consensus seemed to be that, when using a configuration associated
   with a particular ISA or processor, we should try to stick to the
   default where possible.  So "mips64orion-elf-gcc -mabi=32" would
   generate 32-bit 4600 code rather than than MIPS I code.

   Then, we would only deviate from the default architecture when that
   architecture is a 32-bit one, and the selected ABI requires 64-bit
   registers.  For example, "mipstx39-elf -mabi=o64".  For configs
   like mipstx39-elf that are associated with a particular ISA, I
   think specifying an incompatible ABI should be a hard error.
   The user can of course say "mipstx39-elf -mabi=o64 -mips3" if
   that's what they truly mean.

   The question is, how do people see configs like mips-elf and
   mips64-elf?  Is mips-elf "a target for generating MIPS I code",
   or (by a weaker definition) "a target that generates 32-bit code
   by default".  Similarly mips64-elf, MIPS III and 64-bit code.

   According to the stronger definition, mips-elf-gcc would give
   an error if you pass -mabi=o64 without changing the architecture.
   According to the weaker definition, it should switch to MIPS III,
   since -mabi=o64 obviously overrides the "32-bit" default.  The
   stronger definition implies the default should be -march=mips1,
   while the weaker one implies it should be -march=from-abi.

   Same sort of question for mips64-elf.

   At the moment I'm leaning towards the weaker definition, so the patch
   makes "from-abi" the default for both.  Specifically, instead of
   setting MIPS_ISA_DEFAULT to 3 in elf64.h and 1 in mips.h, there is
   just a default definition of MIPS_CPU_STRING_DEFAULT as "from-abi".
   That means the default behaviour is to select the "most compatible"
   architecture for the given ABI, as Thiemo suggested.

7) [Changing ABI based on architecture.]  This time round there's no
   logic to impliclty switch between {n32,n64,o64} and {o32}.  The
   consensus seemed to be that it should at least produce a warning.
   But if we pass the default ABI to GAS using specs, we would
   also have to use specs to override the default, since GAS can't
   tell the difference between a user-supplied or gcc-supplied option.
   So this time I've removed that functionality entirely.

   The behaviour for the EABIs is the same as before: selecting a 64-bit
   architecture implicitly selects 64-bit code, but you can use -mgp32
   to get 32-bit code instead.  Thus 'mipsisa32-elf-gcc -mips64' selects
   64-bit MEABI and "mipsisa64-elf-gcc -mips32" selects 32-bit MEABI.

GAS patch tested as before.  GCC patch tested on mips64-elf with
and without patched GAS.  Irix bootstrap still ongoing.

How does this version look?

Richard

[include/]
	* opcode/mips.h (CPU_R2000): Remove.

[gas/]
	* doc/c-mips.texi: Remove -mcpu.  Document -mabi.
	* configure.in (MIPS_CPU_STRING_DEFAULT): New configuration macro.
	(USE_E_MIPS_ABI_O32, MIPS_DEFAULT_64BIT): New configuration macros.
	* configure, config.in: Regenerate.
	* config/tc-mips.c (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_cpu): Remove.
	(mips_arch_string, mips_arch_info): New vars.
	(mips_tune_string, mips_tune_info): New vars.
	(ABI_NEEDS_32BIT_REGS, ABI_NEEDS_64BIT_REGS): New macros.
	(HAVE_32BIT_GPRS, HAVE_32BIT_FPRS): Don't check the ABI.
	(mips_isa_to_str, mips_cpu_to_str): Remove.
	(mips_ip): If the selected architecture is a generic ISA rather
	than a processor, only mention the ISA level in error messages.
	(OPTION_MCPU): Remove.
	(OPTION_FP64): New.
	(md_longopts): Add -mfp64, remove -mcpu.
	(mips_set_option_string): New fn.
	(md_parse_option): Make -mipsN update file_mips_isa rather than
	mips_opts.isa.  Use mips_set_option_string to set -march or -mtune.
	Don't let -mgp32 and -mfp32 change the ABI.
	(show): Move to end of file.  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.  -mipsN
	is an alias for -march=mipsN.  Don't change the ABI based on other
	flags.  Infer the register size from the ABI as	well as the
	architecture.  Complain about more conflicting arguments.
	[Logic unified with gcc 3.2.]
	(s_mipsset): Don't change the ABI.
	(mips_elf_final_processing): Check USE_E_MIPS_ABI_O32.
	(mips_cpu_info_table): Remove Generic-MIPS* entries, keeping just
	"mipsN"-type 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_strict_matching_cpu_name_p, mips_matching_cpu_name_p): New fns.
	(mips_parse_cpu): New fn.
	(mips_cpu_info_from_name, mips_cpu_info_from_cpu): Remove.
	(mips_cpu_info_from_isa): Minor formatting tweak.

[gas/testsuite]
	* gas/mips/mips-gp32-fp64.d,
	* gas/mips/mips-gp32-fp64-pic.d: Add -mfp64.

[gcc/]
	* doc/invoke.texi: Document -mabi=meabi, and expand on the EABI
	description.  Document -mips32, -mips64, and the associated -march
	values.  Describe the "mipsN" arguments to -march.  Say that the
	-mipsN options are equivalent to -march.  Reword the description
	of default type sizes.
	* toplev.h (target_flags_explicit): Declare.
	* toplev.c (target_flags_explicit): New var.
	(set_target_switch): Update target_flags_explicit.
	* config/mips/abi64.h (SUBTARGET_TARGET_OPTIONS): Undefine.
	* config/mips/elf64.h (MIPS_ISA_DEFAULT): Undefine.
	* config/mips/iris6.h (SUBTARGET_ASM_SPEC): -mabi=64 implies -mips3.
	* config/mips/isa3264.h (MIPS_ENABLE_EMBEDDED_O32): Undefine.
	* config/mips/mips.h (mips_cpu_info): New struct.
	(mips_cpu_string, mips_explicit_type_size_string): Remove.
	(mips_cpu_info_table, mips_arch_info, mips_tune_info): Declare.
	(MIPS_CPP_SET_PROCESSOR): New macro.
	(TARGET_CPP_BUILTINS): Declare a macro for each supported processor.
	Define _MIPS_ARCH and _MIPS_TUNE.
	(MIPS_ISA_DEFAULT): Don't provide a default value.  Instead...
	(MIPS_CPU_STRING_DEFAULT): Set to "from-abi" if neither it nor
	MIPS_ISA_DEFAULT were already defined.
	(MULTILIB_DEFAULTS): Add MULTILIB_ABI_DEFAULT.
	(TARGET_OPTIONS): Remove -mcpu and -mexplicit-type-size.
	(ABI_NEEDS_32BIT_REGS, ABI_NEEDS_64BIT_REGS): New.
	(GAS_ASM_SPEC): Remove -march, -mcpu, -mgp* and -mabi rules.
	(ABI_GAS_ASM_SPEC): Remove.
	(MULTILIB_ABI_DEFAULT, ASM_ABI_DEFAULT_SPEC): New macros.
	(ASM_SPEC): Add -mgp32, -mgp64, -march, -mabi=eabi and -mabi=o64.
	Invoke %(asm_abi_default_spec) if no ABI was specified.
	(CC1_SPEC): Remove ISA -> register-size rules.
	(EXTRA_SPECS): Remove abi_gas_asm_spec.  Add asm_abi_default_spec.
	* config/mips/mips.c (mips_arch_info, mips_tune_info): New vars.
	(mips_cpu_string, mips_explicit_type_size_string): Remove.
	(mips_cpu_info_table): New array.
	(mips_set_architecture, mips_set_tune): New fns.
	(override_options): Rework to make -mipsN equivalent to -march.
	Detect more erroneous cases, including those removed from CC1_SPEC.
	Don't change the ABI based on architecture, or vice versa.
	Unify logic with GAS 2.14.
	(mips_asm_file_start): Get architecture name from mips_arch_info.
	(mips_strict_matching_cpu_name_p, mips_matching_cpu_name_p): New fns.
	(mips_parse_cpu): Take the name of the option as argument.  Handle
	'from-abi'.  Raise an error if the option is wrong.
	(mips_cpu_info_from_isa): New fn.

[gcc/testsuite]
	* gcc.dg/mips-args-[123].c: New tests.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: mips-config-gas-2.diff
Type: text/x-patch
Size: 61342 bytes
Desc: GAS patch
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20020718/f9d8ab3d/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mips-config-gcc-2.diff
Type: text/x-patch
Size: 58969 bytes
Desc: GCC patch
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20020718/f9d8ab3d/attachment-0001.bin>


More information about the Gcc-patches mailing list