https://gcc.gnu.org/g:00b77db92e3e549750050323a50e2cc7977d69cc

commit r15-6722-g00b77db92e3e549750050323a50e2cc7977d69cc
Author: xuli <xu...@eswincomputing.com>
Date:   Wed Jan 8 04:11:30 2025 +0000

    RISC-V: Refine registered_functions list for rvv overloaded intrinsics.
    
    Before this patch, each rvv overloaded intrinsic was registered twice,
    both in gcc and g++.
    
    Take vint8mf8_t __riscv_vle8(vbool64_t vm, const int8_t *rs1, size_t vl)
    as an example.
    
    For gcc, one decl is void __riscv_vle8(void), and the other is
    integer_zero_node, which is redundant.
    For g++, one decl is integer_zero_node, which is redundant.
    The other is vint8mf8_t __riscv_vle8(vbool64_t vm, const int8_t *rs1, 
size_t vl).
    Additionally, rfn is saved in the non_overloaded_function_table, which is 
also redundant.
    
    After this patch, both gcc and g++ regiter each rvv overloaded intrinsic 
once.
    Only gcc's rfn will be added to the non_overloaded_function_table.
    
    Passed the rv64gcv regression test.
    
    Signed-off-by: Li Xu <xu...@eswincomputing.com>
    
    gcc/ChangeLog:
    
            * config/riscv/riscv-vector-builtins.cc 
(function_builder::add_unique_function):
            Only register overloaded intrinsic for g++.
            Only insert non_overloaded_function_table for gcc.
            (function_builder::add_overloaded_function): Only register 
overloaded intrinsic for gcc.
            (handle_pragma_vector): Only initialize 
non_overloaded_function_table for gcc.

Diff:
---
 gcc/config/riscv/riscv-vector-builtins.cc | 34 +++++++++++++++++++------------
 1 file changed, 21 insertions(+), 13 deletions(-)

diff --git a/gcc/config/riscv/riscv-vector-builtins.cc 
b/gcc/config/riscv/riscv-vector-builtins.cc
index f442005bfed5..844b922efbf5 100644
--- a/gcc/config/riscv/riscv-vector-builtins.cc
+++ b/gcc/config/riscv/riscv-vector-builtins.cc
@@ -3997,16 +3997,23 @@ function_builder::add_unique_function (const 
function_instance &instance,
     {
       /* Attribute lists shouldn't be shared.  */
       tree attrs = get_attributes (instance);
-      bool placeholder_p = !m_direct_overloads;
-      add_function (instance, overload_name, fntype, attrs, placeholder_p, 
NULL,
-                   vNULL, required);
-
-      /* Enter the function into the non-overloaded hash table.  */
-      hash = rfn.overloaded_hash ();
-      rfn_slot = non_overloaded_function_table->find_slot_with_hash (&rfn, 
hash,
-                                                                    INSERT);
-      gcc_assert (!*rfn_slot);
-      *rfn_slot = &rfn;
+      if (m_direct_overloads)
+       add_function (instance, overload_name, fntype, attrs, false, NULL,
+                     vNULL, required);
+      else
+       {
+         if (!non_overloaded_function_table)
+           non_overloaded_function_table
+             = new hash_table<non_overloaded_registered_function_hasher> (
+               1023);
+         /* Enter the function into the non-overloaded hash table.  */
+         hash = rfn.overloaded_hash ();
+         rfn_slot
+           = non_overloaded_function_table->find_slot_with_hash (&rfn, hash,
+                                                                 INSERT);
+         gcc_assert (!*rfn_slot);
+         *rfn_slot = &rfn;
+       }
     }
   obstack_free (&m_string_obstack, name);
 }
@@ -4017,6 +4024,9 @@ function_builder::add_overloaded_function (const 
function_instance &instance,
                                           const function_shape *shape,
                                           enum required_ext required)
 {
+  if (m_direct_overloads)
+    return;
+
   if (!check_required_extensions (instance))
     return;
 
@@ -4027,7 +4037,7 @@ function_builder::add_overloaded_function (const 
function_instance &instance,
       /* To avoid API conflicting, take void return type and void argument
         for the overloaded function.  */
       tree fntype = build_function_type (void_type_node, void_list_node);
-      add_function (instance, name, fntype, NULL_TREE, m_direct_overloads, 
name,
+      add_function (instance, name, fntype, NULL_TREE, false, name,
                    vNULL, required, true);
       obstack_free (&m_string_obstack, name);
     }
@@ -4817,8 +4827,6 @@ handle_pragma_vector ()
 
   /* Define the functions.  */
   function_table = new hash_table<registered_function_hasher> (1023);
-  non_overloaded_function_table
-    = new hash_table<non_overloaded_registered_function_hasher> (1023);
   function_builder builder;
   for (unsigned int i = 0; i < ARRAY_SIZE (function_groups); ++i)
   {

Reply via email to