Re: [PATCH 2/2] RISC-V: Add ldr/str instruction for T-HEAD.
On Tue, 29 Jun 2021 01:11:07 PDT (-0700), gcc-patches@gcc.gnu.org wrote: gcc/ * gcc/config/riscv/riscv-opts.h (TARGET_LDR): New. (TARGET_LDUR): Likewise. * gcc/config/riscv/riscv.h (INDEX_REG_CLASS): Use TARGET_LDR. (REGNO_OK_FOR_INDEX_P): Use TARGET_LDR. (REG_OK_FOR_INDEX_P): Use REGNO_OK_FOR_INDEX_P. * gcc/config/riscv/riscv.c (riscv_address_type): Add ADDRESS_REG_REG, ADDRESS_REG_UREG. (riscv_address_info): Add shift. (riscv_classify_address_index): New. (riscv_classify_address): Use riscv_classify_address_index. (riscv_legitimize_address_index_p): New. (riscv_output_move_index): New. (riscv_output_move): Add parameter, Use riscv_output_move_index. (riscv_print_operand_address): Use ADDRESS_REG_REG, ADDRESS_REG_UREG. * gcc/config/riscv/riscv-protos.h (riscv_output_move): Update riscv_output_move. * gcc/config/riscv/riscv.md (zero_extendsidi2): Use riscv_output_move. (zero_extendhi2): Likewise. (zero_extendqi2): Likewise. (extendsidi2): Likewise. (extend2): Likewise. * gcc/config/riscv/predicates.md (sync_memory_operand): New. * gcc/config/riscv/sync.md (atomic_store): Use sync_memory_operand. (atomic_): Likewise. (atomic_fetch_): Likewise. (atomic_exchange): Likewise. (atomic_cas_value_strong): Likewise. (atomic_compare_and_swap): Likewise. (atomic_test_and_set): Likewise. gcc/testsuite/ * gcc.target/riscv/xthead/riscv-xthead.exp: New. * gcc.target/riscv/xthead/ldr.c: Likewise. --- gcc/config/riscv/predicates.md| 4 + gcc/config/riscv/riscv-opts.h | 3 + gcc/config/riscv/riscv-protos.h | 2 +- gcc/config/riscv/riscv.c | 234 -- gcc/config/riscv/riscv.h | 7 +- gcc/config/riscv/riscv.md | 50 ++-- gcc/config/riscv/sync.md | 14 +- gcc/testsuite/gcc.target/riscv/xthead/ldr.c | 34 +++ .../gcc.target/riscv/xthead/riscv-xthead.exp | 41 +++ 9 files changed, 348 insertions(+), 41 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/xthead/ldr.c create mode 100644 gcc/testsuite/gcc.target/riscv/xthead/riscv-xthead.exp diff --git a/gcc/config/riscv/predicates.md b/gcc/config/riscv/predicates.md index 232115135544..802e7a40e880 100644 --- a/gcc/config/riscv/predicates.md +++ b/gcc/config/riscv/predicates.md @@ -217,3 +217,7 @@ { return riscv_gpr_save_operation_p (op); }) + +(define_predicate "sync_memory_operand" + (and (match_operand 0 "memory_operand") + (match_code "reg" "0"))) This should be split out into a standalone patch: it's really preparatory work for the reg/reg instructions, having it standalone will make it easier to review. diff --git a/gcc/config/riscv/riscv-opts.h b/gcc/config/riscv/riscv-opts.h index a2d84a66f037..d3163cb2377c 100644 --- a/gcc/config/riscv/riscv-opts.h +++ b/gcc/config/riscv/riscv-opts.h @@ -76,4 +76,7 @@ enum stack_protector_guard { #define MASK_XTHEAD_C (1 << 0) #define TARGET_XTHEAD_C ((riscv_x_subext & MASK_XTHEAD_C) != 0) +#define TARGET_LDR (TARGET_XTHEAD_C) +#define TARGET_LDUR (TARGET_XTHEAD_C) + #endif /* ! GCC_RISCV_OPTS_H */ diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h index 43d7224d6941..3a218f327c42 100644 --- a/gcc/config/riscv/riscv-protos.h +++ b/gcc/config/riscv/riscv-protos.h @@ -52,9 +52,9 @@ extern bool riscv_legitimize_move (machine_mode, rtx, rtx); extern rtx riscv_subword (rtx, bool); extern bool riscv_split_64bit_move_p (rtx, rtx); extern void riscv_split_doubleword_move (rtx, rtx); -extern const char *riscv_output_move (rtx, rtx); extern const char *riscv_output_return (); #ifdef RTX_CODE +extern const char *riscv_output_move (rtx, rtx, rtx_code outer = UNKNOWN); extern void riscv_expand_int_scc (rtx, enum rtx_code, rtx, rtx); extern void riscv_expand_float_scc (rtx, enum rtx_code, rtx, rtx); extern void riscv_expand_conditional_branch (rtx, enum rtx_code, rtx, rtx); diff --git a/gcc/config/riscv/riscv.c b/gcc/config/riscv/riscv.c index 576960bb37cb..7d321826f669 100644 --- a/gcc/config/riscv/riscv.c +++ b/gcc/config/riscv/riscv.c @@ -80,6 +80,12 @@ along with GCC; see the file COPYING3. If not see A natural register + offset address. The register satisfies riscv_valid_base_register_p and the offset is a const_arith_operand. + ADDRESS_REG_REG + A base register indexed by (optionally scaled) register. + + ADDRESS_REG_UREG + A base register indexed by (optionally scaled) zero-extended register. + ADDRESS_LO_SUM A LO_SUM rtx. The first operand is a valid base register and the second operand is a symbolic address. @@ -91,6 +97,8 @@ along with GCC; see the file COPYING3. If not see A constant symbolic
[PATCH 2/2] RISC-V: Add ldr/str instruction for T-HEAD.
gcc/ * gcc/config/riscv/riscv-opts.h (TARGET_LDR): New. (TARGET_LDUR): Likewise. * gcc/config/riscv/riscv.h (INDEX_REG_CLASS): Use TARGET_LDR. (REGNO_OK_FOR_INDEX_P): Use TARGET_LDR. (REG_OK_FOR_INDEX_P): Use REGNO_OK_FOR_INDEX_P. * gcc/config/riscv/riscv.c (riscv_address_type): Add ADDRESS_REG_REG, ADDRESS_REG_UREG. (riscv_address_info): Add shift. (riscv_classify_address_index): New. (riscv_classify_address): Use riscv_classify_address_index. (riscv_legitimize_address_index_p): New. (riscv_output_move_index): New. (riscv_output_move): Add parameter, Use riscv_output_move_index. (riscv_print_operand_address): Use ADDRESS_REG_REG, ADDRESS_REG_UREG. * gcc/config/riscv/riscv-protos.h (riscv_output_move): Update riscv_output_move. * gcc/config/riscv/riscv.md (zero_extendsidi2): Use riscv_output_move. (zero_extendhi2): Likewise. (zero_extendqi2): Likewise. (extendsidi2): Likewise. (extend2): Likewise. * gcc/config/riscv/predicates.md (sync_memory_operand): New. * gcc/config/riscv/sync.md (atomic_store): Use sync_memory_operand. (atomic_): Likewise. (atomic_fetch_): Likewise. (atomic_exchange): Likewise. (atomic_cas_value_strong): Likewise. (atomic_compare_and_swap): Likewise. (atomic_test_and_set): Likewise. gcc/testsuite/ * gcc.target/riscv/xthead/riscv-xthead.exp: New. * gcc.target/riscv/xthead/ldr.c: Likewise. --- gcc/config/riscv/predicates.md| 4 + gcc/config/riscv/riscv-opts.h | 3 + gcc/config/riscv/riscv-protos.h | 2 +- gcc/config/riscv/riscv.c | 234 -- gcc/config/riscv/riscv.h | 7 +- gcc/config/riscv/riscv.md | 50 ++-- gcc/config/riscv/sync.md | 14 +- gcc/testsuite/gcc.target/riscv/xthead/ldr.c | 34 +++ .../gcc.target/riscv/xthead/riscv-xthead.exp | 41 +++ 9 files changed, 348 insertions(+), 41 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/xthead/ldr.c create mode 100644 gcc/testsuite/gcc.target/riscv/xthead/riscv-xthead.exp diff --git a/gcc/config/riscv/predicates.md b/gcc/config/riscv/predicates.md index 232115135544..802e7a40e880 100644 --- a/gcc/config/riscv/predicates.md +++ b/gcc/config/riscv/predicates.md @@ -217,3 +217,7 @@ { return riscv_gpr_save_operation_p (op); }) + +(define_predicate "sync_memory_operand" + (and (match_operand 0 "memory_operand") + (match_code "reg" "0"))) diff --git a/gcc/config/riscv/riscv-opts.h b/gcc/config/riscv/riscv-opts.h index a2d84a66f037..d3163cb2377c 100644 --- a/gcc/config/riscv/riscv-opts.h +++ b/gcc/config/riscv/riscv-opts.h @@ -76,4 +76,7 @@ enum stack_protector_guard { #define MASK_XTHEAD_C (1 << 0) #define TARGET_XTHEAD_C ((riscv_x_subext & MASK_XTHEAD_C) != 0) +#define TARGET_LDR (TARGET_XTHEAD_C) +#define TARGET_LDUR (TARGET_XTHEAD_C) + #endif /* ! GCC_RISCV_OPTS_H */ diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h index 43d7224d6941..3a218f327c42 100644 --- a/gcc/config/riscv/riscv-protos.h +++ b/gcc/config/riscv/riscv-protos.h @@ -52,9 +52,9 @@ extern bool riscv_legitimize_move (machine_mode, rtx, rtx); extern rtx riscv_subword (rtx, bool); extern bool riscv_split_64bit_move_p (rtx, rtx); extern void riscv_split_doubleword_move (rtx, rtx); -extern const char *riscv_output_move (rtx, rtx); extern const char *riscv_output_return (); #ifdef RTX_CODE +extern const char *riscv_output_move (rtx, rtx, rtx_code outer = UNKNOWN); extern void riscv_expand_int_scc (rtx, enum rtx_code, rtx, rtx); extern void riscv_expand_float_scc (rtx, enum rtx_code, rtx, rtx); extern void riscv_expand_conditional_branch (rtx, enum rtx_code, rtx, rtx); diff --git a/gcc/config/riscv/riscv.c b/gcc/config/riscv/riscv.c index 576960bb37cb..7d321826f669 100644 --- a/gcc/config/riscv/riscv.c +++ b/gcc/config/riscv/riscv.c @@ -80,6 +80,12 @@ along with GCC; see the file COPYING3. If not see A natural register + offset address. The register satisfies riscv_valid_base_register_p and the offset is a const_arith_operand. + ADDRESS_REG_REG + A base register indexed by (optionally scaled) register. + + ADDRESS_REG_UREG + A base register indexed by (optionally scaled) zero-extended register. + ADDRESS_LO_SUM A LO_SUM rtx. The first operand is a valid base register and the second operand is a symbolic address. @@ -91,6 +97,8 @@ along with GCC; see the file COPYING3. If not see A constant symbolic address. */ enum riscv_address_type { ADDRESS_REG, + ADDRESS_REG_REG, + ADDRESS_REG_UREG, ADDRESS_LO_SUM, ADDRESS_CONST_INT, ADDRESS_SYMBOLIC @@ -175,6 +183,11 @@ struct riscv_arg_info { ADDRESS_REG REG is the base