cgraph: cgraph_indirect_call_info into a class hierachy
Currently, an instance of cgraph_indirect_call_info is allocated for
each indirect call and it contains fields which are only usable for
some kinds of calls. The most special are polymorphic calls
representing calls of virtual methods through an OBJ_TYPE_REF and
which need the ipa_polymorphic_context structure, among other data from
the O_T_R itself for devirtualization, which are not needed for other
types of calls.
This patch splits the class into three. A common base which is also
used for calls which we know we cannot do anything about (when the
call statement is not known or when it is a constant integer or
something like that), a (simple) type for calls of SSA_NAMEs and a
type for polymorphic calls. This means we no longer allocate memory
for members which we do not need in a particular situation. Part of
the motivation to write this is also that I have a patch adding fields
to the simple variant and this reorganization makes it doable in a
clean fashion.
The base class retains the param_index field even though it really only
is meaningful in the derived classes. This made conversion of some of
the functions operating on it easier (and I expect that vast majority
of actual instances will fall into one of the two categories anyway).
We already stream information stored in indirect information at two
places, once in call graph streaming and once in ipa-prop streaming.
I am not sure what the reason is (call graph streaming cannot do trees
so we need the ipa-prop one) but this patch preserves this.
The patch also removes a part of the comment in
ipa_make_edge_direct_to_target which said the check for member_ptr was
not necessary. We even have a test in our testsuite showing it is and
we produce wrong code without it.
gcc/ChangeLog:
2025-10-17 Martin Jambor <mjambor@suse.cz>
* cgraph.h (cgraph_node): Adjust the comment of member function
create_indirect_edge.
(enum cgraph_indirect_info_kind): New.
(cgraph_indirect_call_info): Convert into a base class.
(cgraph_simple_indirect_info): New.
(cgraph_polymorphic_indirect_info): Likewise.
(usable_polymorphic_info_p): Likewise.
(is_a_helper <cgraph_simple_indirect_info *>::test): Likewise.
(is_a_helper <cgraph_polymorphic_indirect_info *>::test): Likewise.
(cgraph_allocate_init_indirect_info): Remove declaration.
(ipa_polymorphic_call_context::ipa_polymorphic_call_context): Use the
appropriate derived type of indirect info.
* cgraph.cc (cgraph_allocate_init_indirect_info): Removed.
(cgraph_node::create_indirect_edge): Create an appropriate type of
indirect_info.
(cgraph_node::dump): Dump indirect info using its dump function.
(cgraph_indirect_call_info::dump): New function.
(cgraph_indirect_call_info::debug): Likewise.
* cgraphclones.cc (cgraph_edge::clone): Create an appropriate type of
indirect_info.
* cgraphunit.cc (analyze_functions): Use the appropriate derived type
of indirect info.
* ipa-cp.cc (initialize_node_lattices): Adjust the check for
polymorphic indirect info.
(ipa_get_indirect_edge_target_1): Use the appropriate derived types of
indirect info.
(ipcp_discover_new_direct_edges): Likewise.
* ipa-devirt.cc (ipa_devirt): Use the polymorphis derived type of
indirect info and check that it is usable.
* ipa-inline.cc (dump_inline_stats): Adjust the check for polymorphic
indirect info.
* ipa-profile.cc (ipa_profile): Likewise and check usability.
* ipa-prop.cc (ipa_print_node_jump_functions): Dump indirect info
using its dumping member function.
(ipa_note_param_call): Removed.
(ipa_analyze_indirect_call_uses): Use the appropriate derived type of
indirect info, set all fields of indirect info separately rather than
relying on ipa_note_param_call.
(ipa_analyze_virtual_call_uses): Use the polymorphis derived type of
indirect info and check that it is usable, set all fields of indirect
info separately rather than relying on ipa_note_param_call.
(ipa_analyze_call_uses): Use the appropriate derived type of indirect
info.
(ipa_make_edge_direct_to_target): Use the appropriate derived type of
indirect info. Remove wrong note that member_ptr check was not
needed. Adjust check for polymorphic call when dumping.
(try_make_edge_direct_simple_call): Use the appropriate derived type
of indirect info.
(try_make_edge_direct_virtual_call): Use the polymorphis derived type
of indirect info and check that it is usable.
(update_indirect_edges_after_inlining): Use the appropriate derived
type of indirect info. Define local variables only before their first
use.
(ipa_write_indirect_edge_info): Also stream indirect info kind. Use
the appropriate derived type of indirect info.
(ipa_read_indirect_edge_info): Check that the streamed in indirect
info kind matches rthe structure at hand. Use the appropriate derived
type of indirect info.
* ipa-utils.h (possible_polymorphic_call_targets): Use the
polymorphis derived type of indirect info. Assert it is usable.
(dump_possible_polymorphic_call_targets): Use the polymorphis
derived type of indirect info and check it is usable.
(possible_polymorphic_call_target_p): Likewise.
* ipa.cc (symbol_table::remove_unreachable_nodes): Use
usable_polymorphic_info_p.
* lto-cgraph.cc (lto_output_edge): Stream indirect info kind.
(compute_ltrans_boundary): Use usable_polymorphic_info_p.
(input_edge): Move definition of ecf_flags before its first use.
Pass true as the last parameter to create_indirect_edge. Stream
indirect info kind and create a corresponding type to hold the
information.
* trans-mem.cc (ipa_tm_insert_gettmclone_call): Use the
polymorphis derived type of indirect info.