Skip to content

Commit

Permalink
RISC-V: Refine registered_functions list for rvv overloaded intrinsics.
Browse files Browse the repository at this point in the history
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 <[email protected]>

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.
  • Loading branch information
xuli committed Jan 9, 2025
1 parent 1bb367b commit 00b77db
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions gcc/config/riscv/riscv-vector-builtins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;

Expand All @@ -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);
}
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 00b77db

Please sign in to comment.