Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Commit

Permalink
RISC-V: Support version controling for ISA standard extensions
Browse files Browse the repository at this point in the history
 - New option -misa-spec support: -misa-spec=[2.2|20190608|20191213] and
   corresponding configuration option --with-isa-spec.

 - Current default ISA spec set to 2.2, but we intend to bump this to
   20191213 or later in next release.

gcc/ChangeLog:

	* common/config/riscv/riscv-common.c (riscv_ext_version): New.
	(riscv_ext_version_table): Ditto.
	(get_default_version): Ditto.
	(riscv_subset_t::implied_p): New field.
	(riscv_subset_t::riscv_subset_t): Init implied_p.
	(riscv_subset_list::add): New.
	(riscv_subset_list::handle_implied_ext): Pass riscv_subset_t
	instead of separated argument.
	(riscv_subset_list::to_string): Handle zifencei and zicsr, and
	omit version if version is unknown.
	(riscv_subset_list::parsing_subset_version): New argument `ext`,
	remove default_major_version and default_minor_version, get
	default version info via get_default_version.
	(riscv_subset_list::parse_std_ext): Update argument for
	parsing_subset_version calls.
	Handle 2.2 ISA spec, always enable zicsr and zifencei, they are
	included in baseline ISA in that time.
	(riscv_subset_list::parse_multiletter_ext): Update argument for
	`parsing_subset_version` and `add` calls.
	(riscv_subset_list::parse): Adjust argument for
	riscv_subset_list::handle_implied_ext call.
	* config.gcc (riscv*-*-*): Handle --with-isa-spec=.
	* config.in (HAVE_AS_MISA_SPEC): New.
	(HAVE_AS_MARCH_ZIFENCEI): Ditto.
	* config/riscv/riscv-opts.h (riscv_isa_spec_class): New.
	(riscv_isa_spec): Ditto.
	* config/riscv/riscv.h (HAVE_AS_MISA_SPEC): New.
	(ASM_SPEC): Pass -misa-spec if gas supported.
	* config/riscv/riscv.opt (riscv_isa_spec_class) New.
	* configure.ac (HAVE_AS_MARCH_ZIFENCEI): New test.
	(HAVE_AS_MISA_SPEC): Ditto.
	* configure: Regen.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/arch-9.c: New.
	* gcc.target/riscv/arch-10.c: Ditto.
	* gcc.target/riscv/arch-11.c: Ditto.
	* gcc.target/riscv/attribute-6.c: Remove, we don't support G
	with version anymore.
	* gcc.target/riscv/attribute-8.c: Reorder arch string to fit canonical
	ordering.
	* gcc.target/riscv/attribute-9.c: We don't emit version for
	unknown extensions now.
	* gcc.target/riscv/attribute-11.c: Add -misa-spec=2.2 flags.
	* gcc.target/riscv/attribute-12.c: Ditto.
	* gcc.target/riscv/attribute-13.c: Ditto.
	* gcc.target/riscv/attribute-14.c: Ditto.
	* gcc.target/riscv/attribute-15.c: New.
	* gcc.target/riscv/attribute-16.c: Ditto.
	* gcc.target/riscv/attribute-17.c: Ditto.
  • Loading branch information
kito-cheng committed Nov 18, 2020
1 parent b03be74 commit 4b81528
Show file tree
Hide file tree
Showing 21 changed files with 393 additions and 88 deletions.
287 changes: 215 additions & 72 deletions gcc/common/config/riscv/riscv-common.c

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion gcc/config.gcc
Original file line number Diff line number Diff line change
Expand Up @@ -4541,14 +4541,29 @@ case "${target}" in
;;

riscv*-*-*)
supported_defaults="abi arch tune riscv_attribute"
supported_defaults="abi arch tune riscv_attribute isa_spec"

case "${target}" in
riscv-* | riscv32*) xlen=32 ;;
riscv64*) xlen=64 ;;
*) echo "Unsupported RISC-V target ${target}" 1>&2; exit 1 ;;
esac

case "${with_isa_spec}" in
""|default|2.2)
tm_defines="${tm_defines} TARGET_DEFAULT_ISA_SPEC=ISA_SPEC_CLASS_2P2"
;;
20191213 | 201912)
tm_defines="${tm_defines} TARGET_DEFAULT_ISA_SPEC=ISA_SPEC_CLASS_20191213"
;;
20190608 | 201906)
tm_defines="${tm_defines} TARGET_DEFAULT_ISA_SPEC=ISA_SPEC_CLASS_20190608"
;;
*)
echo "--with-isa-spec only accept 2.2, 20191213, 201912, 20190608 or 201906" 1>&2
exit 1
esac

case "${with_riscv_attribute}" in
yes)
tm_defines="${tm_defines} TARGET_RISCV_ATTRIBUTE=1"
Expand Down
12 changes: 12 additions & 0 deletions gcc/config.in
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,18 @@
#endif


/* Define if your assembler supports -misa-spec=. */
#ifndef USED_FOR_TARGET
#undef HAVE_AS_MISA_SPEC
#endif


/* Define if your assembler supports -march=rv*_zifencei. */
#ifndef USED_FOR_TARGET
#undef HAVE_AS_MARCH_ZIFENCEI
#endif


/* Define if your assembler supports relocs needed by -fpic. */
#ifndef USED_FOR_TARGET
#undef HAVE_AS_SMALL_PIC_RELOCS
Expand Down
10 changes: 10 additions & 0 deletions gcc/config/riscv/riscv-opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ enum riscv_code_model {
};
extern enum riscv_code_model riscv_cmodel;

enum riscv_isa_spec_class {
ISA_SPEC_CLASS_NONE,

ISA_SPEC_CLASS_2P2,
ISA_SPEC_CLASS_20190608,
ISA_SPEC_CLASS_20191213
};

extern enum riscv_isa_spec_class riscv_isa_spec;

/* Keep this list in sync with define_attr "tune" in riscv.md. */
enum riscv_microarchitecture_type {
generic,
Expand Down
9 changes: 8 additions & 1 deletion gcc/config/riscv/riscv.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,20 @@ extern const char *riscv_default_mtune (int argc, const char **argv);
#define TARGET_64BIT (__riscv_xlen == 64)
#endif /* IN_LIBGCC2 */

#ifdef HAVE_AS_MISA_SPEC
#define ASM_MISA_SPEC "%{misa-spec=*}"
#else
#define ASM_MISA_SPEC ""
#endif

#undef ASM_SPEC
#define ASM_SPEC "\
%(subtarget_asm_debugging_spec) \
%{" FPIE_OR_FPIC_SPEC ":-fpic} \
%{march=*} \
%{mabi=*} \
%(subtarget_asm_spec)"
%(subtarget_asm_spec)" \
ASM_MISA_SPEC

#undef DRIVER_SELF_SPECS
#define DRIVER_SELF_SPECS \
Expand Down
17 changes: 17 additions & 0 deletions gcc/config/riscv/riscv.opt
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,20 @@ long riscv_stack_protector_guard_offset = 0

TargetVariable
int riscv_zi_subext

Enum
Name(isa_spec_class) Type(enum riscv_isa_spec_class)
Supported ISA specs (for use with the -misa-spec= option):

EnumValue
Enum(isa_spec_class) String(2.2) Value(ISA_SPEC_CLASS_2P2)

EnumValue
Enum(isa_spec_class) String(20190608) Value(ISA_SPEC_CLASS_20190608)

EnumValue
Enum(isa_spec_class) String(20191213) Value(ISA_SPEC_CLASS_20191213)

misa-spec=
Target Report RejectNegative Joined Enum(isa_spec_class) Var(riscv_isa_spec) Init(TARGET_DEFAULT_ISA_SPEC)
Set the version of RISC-V ISA spec.
62 changes: 62 additions & 0 deletions gcc/configure
Original file line number Diff line number Diff line change
Expand Up @@ -28136,6 +28136,68 @@ if test $gcc_cv_as_riscv_attribute = yes; then

$as_echo "#define HAVE_AS_RISCV_ATTRIBUTE 1" >>confdefs.h

fi

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for -misa-spec= support" >&5
$as_echo_n "checking assembler for -misa-spec= support... " >&6; }
if ${gcc_cv_as_riscv_isa_spec+:} false; then :
$as_echo_n "(cached) " >&6
else
gcc_cv_as_riscv_isa_spec=no
if test x$gcc_cv_as != x; then
$as_echo '' > conftest.s
if { ac_try='$gcc_cv_as $gcc_cv_as_flags -misa-spec=2.2 -o conftest.o conftest.s >&5'
{ { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
(eval $ac_try) 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; }
then
gcc_cv_as_riscv_isa_spec=yes
else
echo "configure: failed program was" >&5
cat conftest.s >&5
fi
rm -f conftest.o conftest.s
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_riscv_isa_spec" >&5
$as_echo "$gcc_cv_as_riscv_isa_spec" >&6; }
if test $gcc_cv_as_riscv_isa_spec = yes; then

$as_echo "#define HAVE_AS_MISA_SPEC 1" >>confdefs.h

fi

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for -march=rv32i_zifencei support" >&5
$as_echo_n "checking assembler for -march=rv32i_zifencei support... " >&6; }
if ${gcc_cv_as_riscv_march_zifencei+:} false; then :
$as_echo_n "(cached) " >&6
else
gcc_cv_as_riscv_march_zifencei=no
if test x$gcc_cv_as != x; then
$as_echo '' > conftest.s
if { ac_try='$gcc_cv_as $gcc_cv_as_flags -march=rv32i_zifencei -o conftest.o conftest.s >&5'
{ { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
(eval $ac_try) 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; }
then
gcc_cv_as_riscv_march_zifencei=yes
else
echo "configure: failed program was" >&5
cat conftest.s >&5
fi
rm -f conftest.o conftest.s
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_riscv_march_zifencei" >&5
$as_echo "$gcc_cv_as_riscv_march_zifencei" >&6; }
if test $gcc_cv_as_riscv_march_zifencei = yes; then

$as_echo "#define HAVE_AS_MARCH_ZIFENCEI 1" >>confdefs.h

fi

;;
Expand Down
10 changes: 10 additions & 0 deletions gcc/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -5111,6 +5111,16 @@ configured with --enable-newlib-nano-formatted-io.])
[.attribute stack_align,4],,
[AC_DEFINE(HAVE_AS_RISCV_ATTRIBUTE, 1,
[Define if your assembler supports .attribute.])])
gcc_GAS_CHECK_FEATURE([-misa-spec= support],
gcc_cv_as_riscv_isa_spec,,
[-misa-spec=2.2],,,
[AC_DEFINE(HAVE_AS_MISA_SPEC, 1,
[Define if the assembler understands -misa-spec=.])])
gcc_GAS_CHECK_FEATURE([-march=rv32i_zifencei support],
gcc_cv_as_riscv_march_zifencei,,
[-march=rv32i_zifencei],,,
[AC_DEFINE(HAVE_AS_MARCH_ZIFENCEI, 1,
[Define if the assembler understands -march=rv*_zifencei.])])
;;
s390*-*-*)
gcc_GAS_CHECK_FEATURE([.gnu_attribute support],
Expand Down
6 changes: 6 additions & 0 deletions gcc/testsuite/gcc.target/riscv/arch-10.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* { dg-do compile } */
/* { dg-options "-O2 -march=rv32gf2 -mabi=ilp32" } */
int foo()
{
}
/* { dg-error "Extension `f' appear more than one time." "" { target *-*-* } 0 } */
5 changes: 5 additions & 0 deletions gcc/testsuite/gcc.target/riscv/arch-11.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* { dg-do compile } */
/* { dg-options "-O2 -march=rv32g_zicsr2 -mabi=ilp32" } */
int foo()
{
}
6 changes: 6 additions & 0 deletions gcc/testsuite/gcc.target/riscv/arch-9.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* { dg-do compile } */
/* { dg-options "-O2 -march=rv32g2 -mabi=ilp32" } */
int foo()
{
}
/* { dg-warning "version of `g` will be omitted, please specify version for individual extension." "" { target *-*-* } 0 } */
2 changes: 1 addition & 1 deletion gcc/testsuite/gcc.target/riscv/attribute-11.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* { dg-do compile } */
/* { dg-options "-O -mriscv-attribute -march=rv32id -mabi=ilp32" } */
/* { dg-options "-O -mriscv-attribute -march=rv32id -mabi=ilp32 -misa-spec=2.2" } */
int foo()
{
}
Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/gcc.target/riscv/attribute-12.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* { dg-do compile } */
/* { dg-options "-O -mriscv-attribute -march=rv32ifd -mabi=ilp32" } */
/* { dg-options "-O -mriscv-attribute -march=rv32ifd -mabi=ilp32 -misa-spec=2.2" } */
int foo()
{
}
Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/gcc.target/riscv/attribute-13.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* { dg-do compile } */
/* { dg-options "-O -mriscv-attribute -march=rv32if3d -mabi=ilp32" } */
/* { dg-options "-O -mriscv-attribute -march=rv32if3d -mabi=ilp32 -misa-spec=2.2" } */
int foo()
{
}
Expand Down
4 changes: 2 additions & 2 deletions gcc/testsuite/gcc.target/riscv/attribute-14.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* { dg-do compile } */
/* { dg-options "-O -mriscv-attribute -march=rv32if -mabi=ilp32" } */
/* { dg-options "-O -mriscv-attribute -march=rv32if -mabi=ilp32 -misa-spec=20190608" } */
int foo()
{
}
/* { dg-final { scan-assembler ".attribute arch, \"rv32i2p0_f2p0_zicsr2p0\"" } } */
/* { dg-final { scan-assembler ".attribute arch, \"rv32i2p1_f2p2_zicsr2p0\"" } } */
6 changes: 6 additions & 0 deletions gcc/testsuite/gcc.target/riscv/attribute-15.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* { dg-do compile } */
/* { dg-options "-O -mriscv-attribute -march=rv32gc -mabi=ilp32 -misa-spec=2.2" } */
int foo()
{
}
/* { dg-final { scan-assembler ".attribute arch, \"rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0\"" } } */
6 changes: 6 additions & 0 deletions gcc/testsuite/gcc.target/riscv/attribute-16.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* { dg-do compile } */
/* { dg-options "-O -mriscv-attribute -march=rv32gc -mabi=ilp32 -misa-spec=20190608" } */
int foo()
{
}
/* { dg-final { scan-assembler ".attribute arch, \"rv32i2p1_m2p0_a2p0_f2p2_d2p2_c2p0_zicsr2p0" } } */
6 changes: 6 additions & 0 deletions gcc/testsuite/gcc.target/riscv/attribute-17.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* { dg-do compile } */
/* { dg-options "-O -mriscv-attribute -march=rv32gc -mabi=ilp32 -misa-spec=20191213" } */
int foo()
{
}
/* { dg-final { scan-assembler ".attribute arch, \"rv32i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0" } } */
6 changes: 0 additions & 6 deletions gcc/testsuite/gcc.target/riscv/attribute-6.c

This file was deleted.

4 changes: 2 additions & 2 deletions gcc/testsuite/gcc.target/riscv/attribute-8.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* { dg-do compile } */
/* { dg-options "-O -mriscv-attribute -march=rv32i2p0xv5_xabc -mabi=ilp32" } */
/* { dg-options "-O -mriscv-attribute -march=rv32i2p0xabc_xv5 -mabi=ilp32" } */
int foo()
{
}
/* { dg-final { scan-assembler ".attribute arch, \"rv32i2p0_xv5p0_xabc2p0\"" } } */
/* { dg-final { scan-assembler ".attribute arch, \"rv32i2p0_xabc_xv5p0\"" } } */
2 changes: 1 addition & 1 deletion gcc/testsuite/gcc.target/riscv/attribute-9.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
int foo()
{
}
/* { dg-final { scan-assembler ".attribute arch, \"rv32i2p0_sabc2p0_xbar2p0\"" } } */
/* { dg-final { scan-assembler ".attribute arch, \"rv32i2p0_sabc_xbar\"" } } */

0 comments on commit 4b81528

Please sign in to comment.