Thanks, I've pushed this to trunk. I'm surprised we forgot to add this configure option for so long :P
On Thu, Nov 27, 2025 at 3:32 AM Charlie Jenkins <[email protected]> wrote: > 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 > > --- > Signed-off-by: Charlie Jenkins <[email protected]> > --- > 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 b46cea869cb..a7a10eb03fc 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 a0ad75c765a..6a3e5372d3b 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 437e4636db3..7f4321c424b 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} > > --- > base-commit: be848078841cbd937ff0ce7bb1564e09d5e2959e > change-id: 20251125-riscv_with_cpu-f9d3466b45ef > -- > - Charlie > >
