RISC-V: Support zicsr and zifencei extension for -march.
authorKito Cheng <kito.cheng@sifive.com>
Wed, 11 Nov 2020 06:04:34 +0000 (14:04 +0800)
committerKito Cheng <kito.cheng@sifive.com>
Wed, 18 Nov 2020 07:02:22 +0000 (15:02 +0800)
 - 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.

gcc/common/config/riscv/riscv-common.c
gcc/config/riscv/riscv-opts.h
gcc/config/riscv/riscv.md
gcc/config/riscv/riscv.opt
gcc/testsuite/gcc.target/riscv/arch-8.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/attribute-14.c [new file with mode: 0644]

index f5f7be3cfffb297485440916e919d3cf08208fa6..ca88ca1dacd1fb035109525a70fcff67ec539db1 100644 (file)
@@ -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}
 };
 
@@ -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}
 };
 
index 2a3f9d9eef57aeabe6bff7530522b74ee7a59a79..de8ac0e038d94c194c394b9a7494c4129d078a4c 100644 (file)
@@ -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 */
index f15bad3b29eaee4de8eac907c77bec4a7c5c72e4..254147c112a34ae810e53bffaa788b66f208102b 100644 (file)
                     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;
 })
 
 (define_insn "fence_i"
   [(unspec_volatile [(const_int 0)] UNSPECV_FENCE_I)]
-  ""
+  "TARGET_ZIFENCEI"
   "fence.i")
 
 ;;
index 808b4a04405487db49aeaf91cb442772db36e102..ca2fc7c80219d411808b4f9d78a1e90cea5d497d 100644 (file)
@@ -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
diff --git a/gcc/testsuite/gcc.target/riscv/arch-8.c b/gcc/testsuite/gcc.target/riscv/arch-8.c
new file mode 100644 (file)
index 0000000..d7760fc
--- /dev/null
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+/* { dg-options "-O -march=rv32id_zicsr_zifence -mabi=ilp32" } */
+int foo()
+{
+}
diff --git a/gcc/testsuite/gcc.target/riscv/attribute-14.c b/gcc/testsuite/gcc.target/riscv/attribute-14.c
new file mode 100644 (file)
index 0000000..4845627
--- /dev/null
@@ -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\"" } } */