On 9/30/24 8:16 AM, Yangyu Chen wrote:
Currently, we lack support for TARGET_CAN_INLINE_P on the RISC-V
ISA. As a result, certain functions cannot be optimized with inlining
when specific options, such as __attribute__((target("arch=+v"))) .
This can lead to potential performance issues when building
retargetable binaries for RISC-V.

To address this, I have implemented the riscv_can_inline_p function.
This addition enables inlining when the callee either has no special
options or when the some options match, and also ensuring that the
callee's ISA is a subset of the caller's. I also check some other
options when there is no always_inline set.

gcc/ChangeLog:

         * common/config/riscv/riscv-common.cc (cl_opt_var_ref_t): Add
         cl_opt_var_ref_t pointer to member of cl_target_option.
         (struct riscv_ext_flag_table_t): Add new cl_opt_var_ref_t field.
         (RISCV_EXT_FLAG_ENTRY): New macro to simplify the definition of
         riscv_ext_flag_table.
         (riscv_ext_is_subset): New function to check if the callee's ISA
         is a subset of the caller's.
         (riscv_x_target_flags_isa_mask): New function to get the mask of
         ISA extension in x_target_flags of gcc_options.
         * config/riscv/riscv-subset.h (riscv_ext_is_subset): Declare
         riscv_ext_is_subset function.
         (riscv_x_target_flags_isa_mask): Declare
         riscv_x_target_flags_isa_mask function.
         * config/riscv/riscv.cc (riscv_can_inline_p): New function.
         (TARGET_CAN_INLINE_P): Implement TARGET_CAN_INLINE_P.

Signed-off-by: Yangyu Chen <chenyan...@isrc.iscas.ac.cn>
---
  gcc/common/config/riscv/riscv-common.cc | 370 +++++++++++++-----------
  gcc/config/riscv/riscv-subset.h         |   3 +
  gcc/config/riscv/riscv.cc               |  59 ++++
  3 files changed, 267 insertions(+), 165 deletions(-)


@@ -1783,6 +1788,41 @@ riscv_set_arch_by_subset_list (riscv_subset_list 
*subset_list,
      }
  }
+/* Check if the ISA extension of subset is a subset of opts. */
+
+bool
+riscv_ext_is_subset (struct cl_target_option *opts,
+                    struct cl_target_option *subset)
+{
+  const riscv_ext_flag_table_t *arch_ext_flag_tab;
+  for (arch_ext_flag_tab = &riscv_ext_flag_table[0]; arch_ext_flag_tab->ext;
+       ++arch_ext_flag_tab)
Minor formatting nit. Generally when we need to break a FOR line, we'd do it like

  for (init;
       test;
       update)

This formatting nit shows up in riscv_x_target_flags_isa_mask as well.


diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 7be3939a7f9..f20090c4f01 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -7654,6 +7654,62 @@ riscv_compute_frame_info (void)
    /* Next points the incoming stack pointer and any incoming arguments. */
  }
+/* Implement TARGET_CAN_INLINE_P. */
+
+static bool
+riscv_can_inline_p (tree caller, tree callee)
I would improve the function comment a little. Specifically with some note about the intent.

We reject cases like callee/caller mismatch on things like the code model, tls dialect, etc.

We allow integration when the callee's ISA is a subset of the caller's ISA.

That way if someone has to adjust this code in the future (or thinks they have such a need), they'll have some guidance on what the basic behavior is supposed to be.

With the comment fix and formatting nits fixed, this will be OK for the trunk. Post the final version and I (or one of the other maintainers) can commit it for you.

Thanks,
Jeff


Reply via email to