Skip to content

Commit

Permalink
RISC-V: Support zicsr and zifencei extension for -march.
Browse files Browse the repository at this point in the history
 - CSR related instructions and fence instructions has to be splitted from
   baseline ISA, zicsr and zifencei are corresponding sub-extension.

gcc/ChangeLog:

	* common/config/riscv/riscv-common.c (riscv_implied_info):
	d and f implied zicsr.
	(riscv_ext_flag_table): Handle zicsr and zifencei.
	* config/riscv/riscv-opts.h (MASK_ZICSR): New.
	(MASK_ZIFENCEI): Ditto.
	(TARGET_ZICSR): Ditto.
	(TARGET_ZIFENCEI): Ditto.
	* config/riscv/riscv.md (clear_cache): Check TARGET_ZIFENCEI.
	(fence_i): Ditto.
	* config/riscv/riscv.opt (riscv_zi_subext): New.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/arch-8.c: New.
	* gcc.target/riscv/attribute-14.c: Ditto.
  • Loading branch information
kito-cheng committed Nov 18, 2020
1 parent 6a5bb47 commit b03be74
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
6 changes: 6 additions & 0 deletions gcc/common/config/riscv/riscv-common.c
Expand Up @@ -57,6 +57,8 @@ struct riscv_implied_info_t
static const riscv_implied_info_t riscv_implied_info[] =
{
{"d", "f"},
{"f", "zicsr"},
{"d", "zicsr"},
{NULL, NULL}
};

Expand Down Expand Up @@ -812,6 +814,10 @@ static const riscv_ext_flag_table_t riscv_ext_flag_table[] =
{"f", &gcc_options::x_target_flags, MASK_HARD_FLOAT},
{"d", &gcc_options::x_target_flags, MASK_DOUBLE_FLOAT},
{"c", &gcc_options::x_target_flags, MASK_RVC},

{"zicsr", &gcc_options::x_riscv_zi_subext, MASK_ZICSR},
{"zifencei", &gcc_options::x_riscv_zi_subext, MASK_ZIFENCEI},

{NULL, NULL, 0}
};

Expand Down
6 changes: 6 additions & 0 deletions gcc/config/riscv/riscv-opts.h
Expand Up @@ -57,4 +57,10 @@ enum stack_protector_guard {
SSP_GLOBAL /* global canary */
};

#define MASK_ZICSR (1 << 0)
#define MASK_ZIFENCEI (1 << 1)

#define TARGET_ZICSR ((riscv_zi_subext & MASK_ZICSR) != 0)
#define TARGET_ZIFENCEI ((riscv_zi_subext & MASK_ZIFENCEI) != 0)

#endif /* ! GCC_RISCV_OPTS_H */
5 changes: 3 additions & 2 deletions gcc/config/riscv/riscv.md
Expand Up @@ -1543,7 +1543,8 @@
LCT_NORMAL, VOIDmode, operands[0], Pmode,
operands[1], Pmode, const0_rtx, Pmode);
#else
emit_insn (gen_fence_i ());
if (TARGET_ZIFENCEI)
emit_insn (gen_fence_i ());
#endif
DONE;
})
Expand All @@ -1555,7 +1556,7 @@

(define_insn "fence_i"
[(unspec_volatile [(const_int 0)] UNSPECV_FENCE_I)]
""
"TARGET_ZIFENCEI"
"fence.i")

;;
Expand Down
3 changes: 3 additions & 0 deletions gcc/config/riscv/riscv.opt
Expand Up @@ -183,3 +183,6 @@ Use the given offset for addressing the stack-protector guard.

TargetVariable
long riscv_stack_protector_guard_offset = 0

TargetVariable
int riscv_zi_subext
5 changes: 5 additions & 0 deletions gcc/testsuite/gcc.target/riscv/arch-8.c
@@ -0,0 +1,5 @@
/* { dg-do compile } */
/* { dg-options "-O -march=rv32id_zicsr_zifence -mabi=ilp32" } */
int foo()
{
}
6 changes: 6 additions & 0 deletions gcc/testsuite/gcc.target/riscv/attribute-14.c
@@ -0,0 +1,6 @@
/* { dg-do compile } */
/* { dg-options "-O -mriscv-attribute -march=rv32if -mabi=ilp32" } */
int foo()
{
}
/* { dg-final { scan-assembler ".attribute arch, \"rv32i2p0_f2p0_zicsr2p0\"" } } */

0 comments on commit b03be74

Please sign in to comment.