diff mbox series

[1/2] ipa-devirt: Expand check that an odr_type cannot have derivations

Message ID ri6zevob4pp.fsf@virgil.suse.cz
State New
Headers show
Series [1/2] ipa-devirt: Expand check that an odr_type cannot have derivations | expand

Commit Message

Martin Jambor Nov. 4, 2026, 10:40 p.m. UTC
Hi,

in the pursuit of commonizing the places where we check for
TYPE_FINAL_P in ipa-devirt, I have found out that
possible_polymorphic_call_targets we check it right after obtaining
the corresponding odr_type of the given type and with that structure
we can rely on its field all_derivations_known being set up and if it
is set that all derived classes known.  So let's use that information
instead using a new predicate.

With that predicate, type_known_to_have_no_derivations_p can be
made to use it too with the same benefits (and a quicker check for
just TYPE_FINAL_P when odr_hash is not available).

In possible_polymorphic_call_targets_1 and
possible_polymorphic_call_targets, we can use the result of previous
invocation of type_all_derivations_known_p instead of calling it
again.

Bootstrapped and tested on x86_64-linux.  OK for master?

Thanks,

Martin


gcc/ChangeLog:

2026-10-21  Martin Jambor  <mjambor@suse.cz>

	* ipa-devirt.cc (odr_type_known_to_have_no_derivations_p): New function.
	(type_known_to_have_no_derivations_p): Use it.
	(possible_polymorphic_call_targets): Likewise.
	(possible_polymorphic_call_targets_1): Use all_derivations_known field
	instead of type_all_derivations_known_p.
	(possible_polymorphic_call_targets): Likewise.
---
 gcc/ipa-devirt.cc | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/gcc/ipa-devirt.cc b/gcc/ipa-devirt.cc
index 872dfc2216a..0695bf9e52e 100644
--- a/gcc/ipa-devirt.cc
+++ b/gcc/ipa-devirt.cc
@@ -2203,15 +2203,26 @@  register_odr_type (tree type)
     }
 }
 
+/* Return true if the type represented by OT is known to have no
+   derivations.  */
+
+static bool
+odr_type_known_to_have_no_derivations_p (odr_type ot)
+{
+  return (ot->all_derivations_known
+	  && ot->derived_types.is_empty ());
+}
+
 /* Return true if type is known to have no derivations.  */
 
 bool
 type_known_to_have_no_derivations_p (tree t)
 {
-  return (type_all_derivations_known_p (t)
-	  && (TYPE_FINAL_P (t)
-	      || (odr_hash
-		  && !get_odr_type (t, true)->derived_types.length())));
+  if (TYPE_FINAL_P (t))
+    return true;
+  if (!odr_hash)
+    return false;
+  return odr_type_known_to_have_no_derivations_p (get_odr_type (t, true));
 }
 
 /* Dump ODR type T and all its derived types.  INDENT specifies indentation for
@@ -2721,7 +2732,7 @@  possible_polymorphic_call_targets_1 (vec <cgraph_node *> &nodes,
     {
       record_target_from_binfo (nodes,
 				(!possibly_instantiated
-				 && type_all_derivations_known_p (type->type))
+				 && type->all_derivations_known)
 				? &bases_to_consider : NULL,
 				binfo, otr_type, type_binfos, otr_token,
 				outer_type, offset,
@@ -3183,7 +3194,7 @@  possible_polymorphic_call_targets (tree otr_type,
   /* We need to update our hierarchy if the type does not exist.  */
   outer_type = get_odr_type (context.outer_type, true);
   /* If the type is complete, there are no derivations.  */
-  if (TYPE_FINAL_P (outer_type->type))
+  if (odr_type_known_to_have_no_derivations_p (outer_type))
     context.maybe_derived_type = false;
 
   /* Initialize query cache.  */
@@ -3272,7 +3283,7 @@  possible_polymorphic_call_targets (tree otr_type,
       /* First insert target from type itself and check if it may have
 	 derived types.  */
       speculative_outer_type = get_odr_type (context.speculative_outer_type, true);
-      if (TYPE_FINAL_P (speculative_outer_type->type))
+      if (odr_type_known_to_have_no_derivations_p (speculative_outer_type))
 	context.speculative_maybe_derived_type = false;
       binfo = get_binfo_at_offset (TYPE_BINFO (speculative_outer_type->type),
 				   context.speculative_offset, otr_type);
@@ -3427,7 +3438,7 @@  possible_polymorphic_call_targets (tree otr_type,
 	      if (type != outer_type
 		  && (!skipped
 		      || (context.maybe_derived_type
-			  && !type_all_derivations_known_p (outer_type->type))))
+			  && !outer_type->all_derivations_known)))
 		record_targets_from_bases (otr_type, otr_token, outer_type->type,
 					   context.offset, nodes, &inserted,
 					   &matched_vtables, &complete);