From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9371 invoked by alias); 30 Jul 2002 21:58:26 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 9362 invoked from network); 30 Jul 2002 21:58:24 -0000 Received: from unknown (HELO crack.them.org) (65.125.64.184) by sources.redhat.com with SMTP; 30 Jul 2002 21:58:24 -0000 Received: from dsl254-114-118.nyc1.dsl.speakeasy.net ([216.254.114.118] helo=nevyn.them.org ident=mail) by crack.them.org with asmtp (Exim 3.12 #1 (Debian)) id 17Zf0c-0006nv-00; Tue, 30 Jul 2002 16:58:26 -0500 Received: from drow by nevyn.them.org with local (Exim 3.35 #1 (Debian)) id 17Zf0a-0000Tw-00; Tue, 30 Jul 2002 17:58:24 -0400 Date: Tue, 30 Jul 2002 15:27:00 -0000 From: Daniel Jacobowitz To: gcc-patches@sources.redhat.com, echristo@redhat.com Subject: RFC: New approach to --with-cpu Message-ID: <20020730215824.GA21681@nevyn.them.org> Mail-Followup-To: gcc-patches@sources.redhat.com, echristo@redhat.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.1i X-SW-Source: 2002-07/txt/msg01828.txt.bz2 This patch changes the way --with-cpu is implemented, mostly implements it for more targets, and adds --with-float. Instead of being controlled by defining flags in the backend, the driver synthesizes -mcpu (or -mschedule for HPPA, or -march/-mtune for MIPS) onto the command line. This improves behavior with multilibs, predefined macros, and anything else that conditionalizes based on the processor option. My goal was to make --with-cpu= no different from -mcpu= (or the appropriate option). While I was in there, I did the same thing with -msoft-float/-mhard-float/-msingle-float and added --with-float=[hard,soft,single]. Targets with a different range of floating point options can easily add more. It still behaves a little oddly with multilibs (because it changes how multilibs which do not specify a float type or a cpu type are built) but it should interact with them adequately well. I think. Configuring with --with-cpu makes the "right" behavior of multilibs a bit less obvious. I've built xgcc and cc1 and verified the option-passing behavior on hppa1.1-proelf, hppa2.0-linux, strongarm-elf, i386-linux, and mips-elf. I'm pretty sure I didn't break any target, but of course more eyes are welcome. Any comments? Is this OK? Anyone have a better idea on how to do this? -- Daniel Jacobowitz Carnegie Mellon University MontaVista Software Debian GNU/Linux Developer 2002-07-30 Daniel Jacobowitz * Makefile.in (DRIVER_DEFINES): Add @target_default_options@ * configure.in: Add @target_default_options@. Document --with-cpu and --with-float. * config.gcc: Reorganize $with_cpu logic. Set target_default_options according to the default CPU, $with_cpu, and $with_float. * gcc.c (default_options, add_option, option_present): New functions. (process_command): Call default_options. * doc/install.texi: Update --with-cpu documentation. Mention --with-float. Index: Makefile.in =================================================================== RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v retrieving revision 1.919 diff -u -p -r1.919 Makefile.in --- Makefile.in 29 Jul 2002 19:31:23 -0000 1.919 +++ Makefile.in 30 Jul 2002 21:36:00 -0000 @@ -1251,6 +1251,7 @@ c-dump.o : c-dump.c $(CONFIG_H) $(SYSTEM # Language-independent files. DRIVER_DEFINES = \ + @target_default_options@ \ -DSTANDARD_STARTFILE_PREFIX=\"$(unlibsubdir)/\" \ -DSTANDARD_EXEC_PREFIX=\"$(libdir)/gcc-lib/\" \ -DDEFAULT_TARGET_VERSION=\"$(version)\" \ Index: config.gcc =================================================================== RCS file: /cvs/gcc/gcc/gcc/config.gcc,v retrieving revision 1.229 diff -u -p -r1.229 config.gcc --- config.gcc 29 Jul 2002 22:21:40 -0000 1.229 +++ config.gcc 30 Jul 2002 21:36:02 -0000 @@ -2770,173 +2770,178 @@ case $machine in ;; esac -# Distinguish i[34567]86 -# Also, do not run mips-tfile on MIPS if using gas. -# Process --with-cpu= for PowerPC/rs6000 -target_cpu_default2= -case $machine in -i486-*-*) - target_cpu_default2=TARGET_CPU_DEFAULT_i486 - ;; -i586-*-*) - case $target_alias in - k6_2-*) - target_cpu_default2=TARGET_CPU_DEFAULT_k6_2 - ;; - k6_3-*) - target_cpu_default2=TARGET_CPU_DEFAULT_k6_3 - ;; - k6-*) - target_cpu_default2=TARGET_CPU_DEFAULT_k6 - ;; - pentium_mmx-*) - target_cpu_default2=TARGET_CPU_DEFAULT_pentium_mmx - ;; - *) - target_cpu_default2=TARGET_CPU_DEFAULT_pentium - ;; - esac - ;; -i686-*-* | i786-*-*) - case $target_alias in - athlon_xp-*|athlon_mp-*|athlon_4-*) - target_cpu_default2=TARGET_CPU_DEFAULT_athlon_sse - ;; - athlon_tbird-*|athlon-*) - target_cpu_default2=TARGET_CPU_DEFAULT_athlon - ;; - pentium2-*) - target_cpu_default2=TARGET_CPU_DEFAULT_pentium2 - ;; - pentium3-*) - target_cpu_default2=TARGET_CPU_DEFAULT_pentium3 - ;; - pentium4-*) - target_cpu_default2=TARGET_CPU_DEFAULT_pentium4 - ;; - *) - target_cpu_default2=TARGET_CPU_DEFAULT_pentiumpro +if test x$pass2done = xyes +then + case "x$with_cpu" in + xyes | xno) + echo "--with-cpu must be passed a value" 1>&2 + exit 1 ;; esac - ;; -x86_64-*-*) - # We should have hammer chip here, but it does not exist yet and - # thus it is not supported. Athlon_SSE is probably equivalent feature - # wise to hammer from our point of view except for 64bit mode. - target_cpu_default2=TARGET_CPU_DEFAULT_athlon_sse - ;; -alpha*-*-*) - case $machine in - alphaev6[78]*) - target_cpu_default2="MASK_CPU_EV6|MASK_BWX|MASK_MAX|MASK_FIX|MASK_CIX" - ;; - alphaev6*) - target_cpu_default2="MASK_CPU_EV6|MASK_BWX|MASK_MAX|MASK_FIX" - ;; - alphapca56*) - target_cpu_default2="MASK_CPU_EV5|MASK_BWX|MASK_MAX" - ;; - alphaev56*) - target_cpu_default2="MASK_CPU_EV5|MASK_BWX" + + # If there is no $with_cpu option, try to infer one from ${machine}. + if test x$with_cpu = x + then + case $machine in + i486-*-*) + with_cpu=i486 + ;; + i586-*-*) + case $target_alias in + k6_2-*) + with_cpu=k6-2 + ;; + k6_3-*) + with_cpu=k6-3 + ;; + k6-*) + with_cpu=k6 + ;; + pentium_mmx-*) + with_cpu=pentium-mmx + ;; + *) + with_cpu=pentium + ;; + esac + ;; + i686-*-* | i786-*-*) + case $target_alias in + athlon_xp-*|athlon_mp-*|athlon_4-*) + with_cpu=athlon-4 + ;; + athlon_tbird-*|athlon-*) + with_cpu=athlon + ;; + pentium2-*) + with_cpu=pentium2 + ;; + pentium3-*) + with_cpu=pentium3 + ;; + pentium4-*) + with_cpu=pentium4 + ;; + *) + with_cpu=pentiumpro + ;; + esac + ;; + x86_64-*-*) + # We should have hammer chip here, but it does not + # exist yet and thus it is not supported. Athlon_SSE + # is probably equivalent feature wise to hammer from + # our point of view except for 64bit mode. + with_cpu=athlon-sse + ;; + alpha*-*-*) + case $machine in + alphaev6[78]*) + with_cpu=ev67 + ;; + alphaev6*) + with_cpu=ev6 + ;; + alphapca56*) + with_cpu=pca56 + ;; + alphaev56*) + with_cpu=ev56 + ;; + alphaev5*) + with_cpu=ev5 + ;; + esac ;; - alphaev5*) - target_cpu_default2="MASK_CPU_EV5" + sparc*-*-*) + with_cpu="`echo $machine | sed 's/-.*$//'`" ;; - esac + esac + fi - if test x$gas = xyes - then - if test "$target_cpu_default2" = "" + case "$machine" in + alpha*-*-*) + if test x$gas = xyes then - target_cpu_default2="MASK_GAS" - else - target_cpu_default2="${target_cpu_default2}|MASK_GAS" + if test "$target_cpu_default2" = "" + then + target_cpu_default2="MASK_GAS" + else + target_cpu_default2="${target_cpu_default2}|MASK_GAS" + fi fi - fi - ;; -arm*-*-*) - case "x$with_cpu" in - x) - # The most generic - target_cpu_default2="TARGET_CPU_generic" - ;; - + ;; + arm*-*-*) + # Start with the most generic. + target_cpu_default2="TARGET_CPU_generic" # Distinguish cores, and major variants # arm7m doesn't exist, but D & I don't affect code + case "x$with_cpu" in xarm[236789] | xarm250 | xarm[67][01]0 \ | xarm7m | xarm7dm | xarm7dmi | xarm[79]tdmi \ | xarm7100 | xarm7500 | xarm7500fe | xarm810 \ | xxscale \ | xstrongarm | xstrongarm110 | xstrongarm1100) - target_cpu_default2="TARGET_CPU_$with_cpu" + # OK ;; - xyes | xno) - echo "--with-cpu must be passed a value" 1>&2 + *) + echo "Unknown cpu used with --with-cpu=$with_cpu" 1>&2 exit 1 ;; - - *) - if test x$pass2done = xyes + esac + ;; + hppa*-*-* | parisc*-*-*) + if test x$gas = xyes + then + target_cpu_default2="MASK_GAS|MASK_JUMP_IN_DELAY" + fi + case $machine in + hppa1* | parisc1*) + with_cpu=7100LC + ;; + esac + ;; + mips*-*-*) + case $machine in + mips*-*-ecoff* | mips*-*-elf*) + if test x$gas = xyes then - echo "Unknown cpu used with --with-cpu=$with_cpu" 1>&2 - exit 1 + if test x$gnu_ld = xyes + then + target_cpu_default2="MASK_GAS|MASK_SPLIT_ADDR" + else + target_cpu_default2="MASK_GAS" + fi fi ;; - esac - ;; - -hppa*-*-* | parisc*-*-*) - if test x$gas = xyes - then - target_cpu_default2="MASK_GAS|MASK_JUMP_IN_DELAY" - fi - case $machine in - hppa1* | parisc1*) - tm_defines="TARGET_SCHED_DEFAULT=\\\"7100LC\\\"" - ;; - esac - ;; -mips*-*-*) - case $machine in - mips*-*-ecoff* | mips*-*-elf*) - if test x$gas = xyes - then - if test x$gnu_ld = xyes + mips*-*-*) + if test x$gas = xyes then - target_cpu_default2="MASK_GAS|MASK_SPLIT_ADDR" - else target_cpu_default2="MASK_GAS" fi - fi - ;; - mips*-*-*) - if test x$gas = xyes + ;; + esac + case $machine in + mips*el-*-*) + tm_defines="TARGET_ENDIAN_DEFAULT=0 $tm_defines" + ;; + esac + if test "x$enable_gofast" = xyes then - target_cpu_default2="MASK_GAS" + tm_defines="INIT_SUBTARGET_OPTABS=INIT_GOFAST_OPTABS $tm_defines" + tm_file="gofast.h $tm_file" + tmake_file="mips/t-gofast $tmake_file" + else + tmake_file="mips/t-mips $tmake_file" fi ;; - esac - case $machine in - mips*el-*-*) - tm_defines="TARGET_ENDIAN_DEFAULT=0 $tm_defines" - ;; - esac - if test "x$enable_gofast" = xyes - then - tm_defines="INIT_SUBTARGET_OPTABS=INIT_GOFAST_OPTABS $tm_defines" - tm_file="gofast.h $tm_file" - tmake_file="mips/t-gofast $tmake_file" - else - tmake_file="mips/t-mips $tmake_file" - fi - ;; -powerpc*-*-* | rs6000-*-*) - if test x$enable_altivec = xyes - then - tm_file="$tm_file rs6000/altivec-defs.h" - fi - case "x$with_cpu" in + powerpc*-*-* | rs6000-*-*) + if test x$enable_altivec = xyes + then + tm_file="$tm_file rs6000/altivec-defs.h" + fi + case "x$with_cpu" in x) ;; @@ -2951,49 +2956,56 @@ powerpc*-*-* | rs6000-*-*) target_cpu_default2="\\\"$with_cpu\\\"" ;; - xyes | xno) - echo "--with-cpu must be passed a value" 1>&2 + *) + echo "Unknown cpu used with --with-cpu=$with_cpu" 1>&2 exit 1 ;; - + esac + c_target_objs="${c_target_objs} rs6000-c.o" + cxx_target_objs="${cxx_target_objs} rs6000-c.o" + tmake_file="${tmake_file} rs6000/t-rs6000-c-rule" + ;; + sparc*-*-*) + case .$with_cpu in + .supersparc | .hypersparc | .ultrasparc | .v7 | .v8 | .v9) + target_cpu_default2="TARGET_CPU_$with_cpu" + ;; *) - if test x$pass2done = xyes - then - echo "Unknown cpu used with --with-cpu=$with_cpu" 1>&2 - exit 1 - fi + echo "Unknown cpu used with --with-cpu=$with_cpu" 1>&2 + exit 1 ;; + esac + ;; esac - c_target_objs="${c_target_objs} rs6000-c.o" - cxx_target_objs="${cxx_target_objs} rs6000-c.o" - tmake_file="${tmake_file} rs6000/t-rs6000-c-rule" - ;; -sparc*-*-*) - case ".$with_cpu" in - .) - target_cpu_default2=TARGET_CPU_"`echo $machine | sed 's/-.*$//'`" + + if test x$with_cpu != x + then + case "$machine" in + hppa*-*-* | parisc*-*-*) + target_default_options="-DTARGET_DEFAULT_OPTION_SCHEDULE=$with_cpu" ;; - .supersparc | .hypersparc | .ultrasparc | .v7 | .v8 | .v9) - target_cpu_default2="TARGET_CPU_$with_cpu" + mips*-*-*) + target_default_options="-DTARGET_DEFAULT_OPTION_ARCH=$with_cpu -DTARGET_DEFAULT_OPTION_TUNE=$with_tune" ;; *) - if test x$pass2done = xyes - then - echo "Unknown cpu used with --with-cpu=$with_cpu" 1>&2 - exit 1 - fi + target_default_options="-DTARGET_DEFAULT_OPTION_CPU=$with_cpu" ;; - esac - ;; -esac + esac + fi -if test "$target_cpu_default2" != "" -then - if test "$target_cpu_default" != "" + if test -n "$with_float" then - target_cpu_default="(${target_cpu_default}|${target_cpu_default2})" - else - target_cpu_default=$target_cpu_default2 + target_default_options="${target_default_options} -DTARGET_DEFAULT_OPTION_FLOAT=\"$with_float\"" + fi + + if test "$target_cpu_default2" != "" + then + if test "$target_cpu_default" != "" + then + target_cpu_default="(${target_cpu_default}|${target_cpu_default2})" + else + target_cpu_default=$target_cpu_default2 + fi fi fi Index: configure.in =================================================================== RCS file: /cvs/gcc/gcc/gcc/configure.in,v retrieving revision 1.612 diff -u -p -r1.612 configure.in --- configure.in 29 Jul 2002 22:07:27 -0000 1.612 +++ configure.in 30 Jul 2002 21:36:10 -0000 @@ -136,6 +136,14 @@ AC_ARG_WITH(elf, elf="$with_elf", elf=no) +# With a particular CPU +AC_ARG_WITH(cpu, +[ --with-cpu default to the specified CPU],,) + +# Default floating-point setting +AC_ARG_WITH(float, +[ --with-float default to the specified type of floating point],,) + # Specify the local prefix local_prefix= AC_ARG_WITH(local-prefix, @@ -2694,6 +2702,7 @@ AC_SUBST(target_alias) AC_SUBST(c_target_objs) AC_SUBST(cxx_target_objs) AC_SUBST(target_cpu_default) +AC_SUBST(target_default_options) AC_SUBST_FILE(target_overrides) AC_SUBST_FILE(host_overrides) Index: gcc.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/gcc.c,v retrieving revision 1.331 diff -u -p -r1.331 gcc.c --- gcc.c 25 Jul 2002 18:48:42 -0000 1.331 +++ gcc.c 30 Jul 2002 21:36:15 -0000 @@ -990,6 +990,90 @@ static const struct option_map option_ma }; +static int option_present PARAMS ((int, const char *const *, const char *)); +static void add_option PARAMS ((int *, const char *const **, const char *)); +static void default_options PARAMS ((int *, const char *const **)); + +static int +option_present (argc, argv, option) + int argc; + const char *const *argv; + const char *option; +{ + int i; + int len; + + len = strlen (option); + + for (i = 0; i < argc; i++) + if (option[len - 1] == '=') + { + if (strncmp (argv[i], option, len) == 0) + return 1; + } + else + { + if (strcmp (argv[i], option) == 0) + return 1; + } + + return 0; +} + +static void +add_option (argcp, argvp, option) + int *argcp; + const char *const **argvp; + const char *option; +{ + const char **newargv = (const char **) xmalloc ((*argcp + 2) * sizeof (char *)); + int i; + + newargv[0] = (*argvp)[0]; + newargv[1] = option; + for (i = 1; i < *argcp; i++) + newargv[i + 1] = (*argvp)[i]; + newargv[i + 1] = NULL; + + *argvp = newargv; + (*argcp)++; +} + +static void +default_options (argcp, argvp) + int *argcp ATTRIBUTE_UNUSED; + const char *const **argvp ATTRIBUTE_UNUSED; +{ +#ifdef TARGET_DEFAULT_OPTION_CPU + if (! option_present (*argcp, *argvp, "-mcpu=")) + add_option (argcp, argvp, "-mcpu=" XSTRING (TARGET_DEFAULT_OPTION_CPU)); +#endif + +#ifdef TARGET_DEFAULT_OPTION_ARCH + if (! option_present (*argcp, *argvp, "-march=")) + add_option (argcp, argvp, "-march=" XSTRING (TARGET_DEFAULT_OPTION_ARCH)); +#endif + +#ifdef TARGET_DEFAULT_OPTION_TUNE + if (! option_present (*argcp, *argvp, "-mtune=")) + add_option (argcp, argvp, "-mtune=" XSTRING (TARGET_DEFAULT_OPTION_TUNE)); +#endif + +#ifdef TARGET_DEFAULT_OPTION_SCHEDULE + if (! option_present (*argcp, *argvp, "-mschedule=")) + add_option (argcp, argvp, "-mschedule=" XSTRING (TARGET_DEFAULT_OPTION_SCHEDULE)); +#endif + +#ifdef TARGET_DEFAULT_OPTION_FLOAT + /* Add other mutually exclusive floating point options as necessary. */ + if (! option_present (*argcp, *argvp, "-msoft-float") + && ! option_present (*argcp, *argvp, "-mhard-float") + && ! option_present (*argcp, *argvp, "-msingle-float")) + add_option (argcp, argvp, "-m" XSTRING (TARGET_DEFAULT_OPTION_FLOAT) "-float"); +#endif +} + + #ifdef TARGET_OPTION_TRANSLATE_TABLE static const struct { const char *const option_found; @@ -3374,6 +3458,9 @@ process_command (argc, argv) /* Convert new-style -- options to old-style. */ translate_options (&argc, &argv); + + /* Add any default options. */ + default_options (&argc, &argv); /* Do language-specific adjustment/addition of flags. */ lang_specific_driver (&argc, &argv, &added_libraries); Index: doc/install.texi =================================================================== RCS file: /cvs/gcc/gcc/gcc/doc/install.texi,v retrieving revision 1.128 diff -u -p -r1.128 install.texi --- doc/install.texi 30 Jun 2002 19:27:48 -0000 1.128 +++ doc/install.texi 30 Jul 2002 21:49:18 -0000 @@ -672,10 +672,15 @@ Microsoft Win32 API thread support. @item --with-cpu=@var{cpu} Specify which cpu variant the compiler should generate code for by default. This is currently -only supported on the some ports, specifically arm, powerpc, and +only supported on some ports, including arm, i386, powerpc, MIPS, PA, and SPARC@. If configure does not recognize the model name (e.g.@: arm700, 603e, or ultrasparc) you provide, please check the configure script for a complete list of supported models. + +@item --with-float=@var{type} +Specify the default form of floating point. The choices are hard, soft, +and single. Which (if any) choices are recognized depends on the port +you configure for. @item --enable-altivec Specify that the target supports AltiVec vector enhancements. This