https://gcc.gnu.org/g:5be645aae5b261cb238a2a8a953c12eea2bc01b1

commit r16-5689-g5be645aae5b261cb238a2a8a953c12eea2bc01b1
Author: Charlie Jenkins <[email protected]>
Date:   Wed Nov 26 11:29:51 2025 -0800

    RISC-V: Support --with-cpu
    
    The --with-cpu will allow riscv compilers to have a default mcpu flag.
    Setting -mcpu or -march at compile time will override the configured
    --with-cpu.
    
    gcc/ChangeLog:
    
            * config.gcc: Add cpu to supported configure options
            * config/riscv/riscv.h (riscv_arch_help): Use --with-cpu during
            compilation
            * doc/install.texi: Mention in docs that --with-cpu is supported

Diff:
---
 gcc/config.gcc           | 2 +-
 gcc/config/riscv/riscv.h | 5 +++--
 gcc/doc/install.texi     | 8 ++++----
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 6ac00ebdcb30..703554263969 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -4753,7 +4753,7 @@ case "${target}" in
                ;;
 
        riscv*-*-*)
-               supported_defaults="abi arch tune riscv_attribute isa_spec tls 
cmodel"
+               supported_defaults="abi arch cpu tune riscv_attribute isa_spec 
tls cmodel"
 
                case "${target}" in
                riscv-* | riscv32*) xlen=32 ;;
diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h
index a0ad75c765a1..6a3e5372d3b5 100644
--- a/gcc/config/riscv/riscv.h
+++ b/gcc/config/riscv/riscv.h
@@ -60,17 +60,18 @@ extern const char *riscv_arch_help (int argc, const char 
**argv);
   { "riscv_arch_help", riscv_arch_help },
 
 /* Support for a compile-time default CPU, et cetera.  The rules are:
-   --with-arch is ignored if -march or -mcpu is specified.
+   --with-arch and --with-cpu are ignored if -march or -mcpu is specified.
    --with-abi is ignored if -mabi is specified.
    --with-tune is ignored if -mtune or -mcpu is specified.
    --with-isa-spec is ignored if -misa-spec is specified.
    --with-tls is ignored if -mtls-dialect is specified.
 
-   But using default -march/-mtune value if -mcpu don't have valid option.  */
+   Uses default values if -mcpu doesn't have a valid option.  */
 #define OPTION_DEFAULT_SPECS \
   {"tune", "%{!mtune=*:"                                               \
           "  %{!mcpu=*:-mtune=%(VALUE)}"                               \
           "  %{mcpu=*:-mtune=%:riscv_default_mtune(%* %(VALUE))}}" },  \
+  {"cpu", "%{!march=*:%{!mcpu=*:%:riscv_expand_arch_from_cpu(%(VALUE))}}" }, \
   {"arch", "%{!march=*|march=unset:"                                   \
           "  %{!mcpu=*:-march=%(VALUE)}"                               \
           "  %{mcpu=*:%:riscv_expand_arch_from_cpu(%* %(VALUE))}}" },  \
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 437e4636db33..7f4321c424b9 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -1687,10 +1687,10 @@ not use transactional memory.
 Specify which cpu variant the compiler should generate code for by default.
 @var{cpu} will be used as the default value of the @option{-mcpu=} switch.
 This option is only supported on some targets, including ARC, ARM, i386, M68k,
-PowerPC, and SPARC@.  It is mandatory for ARC@.  The @option{--with-cpu-32} and
-@option{--with-cpu-64} options specify separate default CPUs for
-32-bit and 64-bit modes; these options are only supported for aarch64, i386,
-x86-64, PowerPC, and SPARC@.
+PowerPC, RISC-V, and SPARC@.  It is mandatory for ARC@.  The
+@option{--with-cpu-32} and @option{--with-cpu-64} options specify separate
+default CPUs for 32-bit and 64-bit modes; these options are only supported for
+aarch64, i386, x86-64, PowerPC, and SPARC@.
 
 @item --with-schedule=@var{cpu}
 @itemx --with-arch=@var{cpu}

Reply via email to