>On 9/16/21 05:25, Feng Xue OS via Gcc-patches wrote: >> This and following patches are composed to enable full devirtualization >> under whole program assumption (so also called whole-program >> devirtualization, WPD for short), which is an enhancement to current >> speculative devirtualization. The base of the optimization is how to >> identify class type that is local in terms of whole-program scope, at >> least those class types in libstdc++ must be excluded in some way. >> Our means is to use typeinfo symbol as identity marker of a class since >> it is unique and always generated once the class or its derived type >> is instantiated somewhere, and rely on symbol resolution by >> lto-linker-plugin to detect whether a typeinfo is referenced by regular >> object/library, which indirectly tells class types are escaped or not. >> The RFC at https://gcc.gnu.org/pipermail/gcc/2021-August/237132.html >> gives more details on that. >> >> Bootstrapped/regtested on x86_64-linux and aarch64-linux. >> >> Thanks, >> Feng >> >> ---- >> 2021-09-07 Feng Xue <f...@os.amperecomputing.com> >> >> gcc/ >> * common.opt (-fdevirtualize-fully): New option. >> * class.c (build_rtti_vtbl_entries): Force generation of typeinfo >> even -fno-rtti is specificied under full devirtualization. > >This makes -fno-rtti useless; rather than this, you should warn about >the combination of flags and force flag_rtti on. It also sounds like >you depend on the library not being built with -fno-rtti.
Although rtti is generated by front-end, we will remove it after lto symtab merge, which is meant to keep same behavior as -fno-rtti. Yes, regular library to be linked with should contain rtti data, otherwise WPD could not deduce class type usage safely. By default, we can think that it should work for libstdc++, but it probably becomes a problem for user library, which might be avoided if we properly document this requirement and suggest user doing that when using WPD. Thanks Feng > >> * cgraph.c (cgraph_update_edges_for_call_stmt): Add an assertion >> to check node to be traversed. >> * cgraphclones.c (cgraph_node::find_replacement): Record >> former_clone_of on replacement node. >> * cgraphunit.c (symtab_node::needed_p): Always output vtable for >> full devirtualization. >> (analyze_functions): Force generation of primary vtables for all >> base classes. >> * ipa-devirt.c (odr_type_d::whole_program_local): New field. >> (odr_type_d::has_virtual_base): Likewise. >> (odr_type_d::all_derivations_known): Removed. >> (odr_type_d::whole_program_local_p): New member function. >> (odr_type_d::all_derivations_known_p): Likewise. >> (odr_type_d::possibly_instantiated_p): Likewise. >> (odr_type_d::set_has_virtual_base): Likewise. >> (get_odr_type): Set "whole_program_local" and "has_virtual_base" >> when adding a type. >> (type_all_derivations_known_p): Replace implementation by a call >> to odr_type_d::all_derivations_known_p. >> (type_possibly_instantiated_p): Replace implementation by a call >> to odr_type_d::possibly_instantiated_p. >> (type_known_to_have_no_derivations_p): Replace call to >> type_possibly_instantiated_p with call to >> odr_type_d::possibly_instantiated_p. >> (type_all_ctors_visible_p): Removed. >> (type_whole_program_local_p): New function. >> (get_type_vtable): Likewise. >> (extract_typeinfo_in_vtable): Likewise. >> (identify_whole_program_local_types): Likewise. >> (dump_odr_type): Dump has_virtual_base and whole_program_local_p() >> of type. >> (maybe_record_node): Resort to type_whole_program_local_p to >> check whether a class has been optimized away. >> (record_target_from_binfo): Remove parameter "anonymous", add >> a new parameter "possibly_instantiated", and adjust code >> accordingly. >> (devirt_variable_node_removal_hook): Replace call to >> "type_in_anonymous_namespace_p" with "type_whole_program_local_p". >> (possible_polymorphic_call_targets): Replace call to >> "type_possibly_instantiated_p" with "possibly_instantiated_p", >> replace flag check on "all_derivations_known" with call to >> "all_derivations_known_p". >> * ipa-icf.c (filter_removed_items): Disable folding on vtable >> under full devirtualization. >> * ipa-polymorphic-call.c (restrict_to_inner_class): Move odr >> type check to type_known_to_have_no_derivations_p. >> * ipa-utils.h (identify_whole_program_local_types): New >> declaration. >> (type_all_derivations_known_p): Parameter type adjustment. >> * ipa.c (walk_polymorphic_call_targets): Do not mark vcall >> targets as reachable for full devirtualization. >> (can_remove_vtable_if_no_refs_p): New function. >> (symbol_table::remove_unreachable_nodes): Add defined vtables >> to reachable list under full devirtualization. >> * lto-symtab.c (lto_symtab_merge_symbols): Identify whole >> program local types after symbol table merge. >> --- >>