]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: optimize constraint subsumption [PR118069]
authorPatrick Palka <ppalka@redhat.com>
Thu, 19 Dec 2024 17:00:31 +0000 (12:00 -0500)
committerPatrick Palka <ppalka@redhat.com>
Thu, 19 Dec 2024 17:00:31 +0000 (12:00 -0500)
Since atomic constraints are interned the subsumption machinery can
safely use pointer instead of structural hashing for them.  This speeds
up compilation of the testcase in the PR from ~3s to ~2s.

PR c++/118069

gcc/cp/ChangeLog:

* constraint.cc (atom_hasher): Define here, instead of ...
* cp-tree.h (atom_hasher): ... here.
* logic.cc (clause::m_set): Use pointer instead of structural
hashing.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/constraint.cc
gcc/cp/cp-tree.h
gcc/cp/logic.cc

index 2af1bbc016b9ef4f15440604a4f6028543b17959..c75982d80093ae0f180ace01fb77eddb78acd640 100644 (file)
@@ -512,6 +512,27 @@ normalize_concept_check (tree check, tree args, norm_info info)
   return norm;
 }
 
+/* A structural hasher for ATOMIC_CONSTRs.  */
+
+struct atom_hasher : default_hash_traits<tree>
+{
+  static hashval_t hash (tree t)
+  {
+    ++comparing_specializations;
+    hashval_t val = hash_atomic_constraint (t);
+    --comparing_specializations;
+    return val;
+  }
+
+  static bool equal (tree t1, tree t2)
+  {
+    ++comparing_specializations;
+    bool eq = atomic_constraints_identical_p (t1, t2);
+    --comparing_specializations;
+    return eq;
+  }
+};
+
 /* Used by normalize_atom to cache ATOMIC_CONSTRs.  */
 
 static GTY((deletable)) hash_table<atom_hasher> *atom_cache;
index 6833035664b064ee7afa3d1f175b5deb07036786..32e6b014b67e014ab71b972aedce9ae9f9790728 100644 (file)
@@ -8715,27 +8715,6 @@ extern void diagnose_constraints                (location_t, tree, tree);
 
 extern void note_failed_type_completion_for_satisfaction (tree);
 
-/* A structural hasher for ATOMIC_CONSTRs.  */
-
-struct atom_hasher : default_hash_traits<tree>
-{
-  static hashval_t hash (tree t)
-  {
-    ++comparing_specializations;
-    hashval_t val = hash_atomic_constraint (t);
-    --comparing_specializations;
-    return val;
-  }
-
-  static bool equal (tree t1, tree t2)
-  {
-    ++comparing_specializations;
-    bool eq = atomic_constraints_identical_p (t1, t2);
-    --comparing_specializations;
-    return eq;
-  }
-};
-
 /* in logic.cc */
 extern bool subsumes                            (tree, tree);
 
index a385fb719ecaa8c9176bff6e0168ea639bbe94ac..6b4bf1dfb7dced381191efb51cef9c94db462cc9 100644 (file)
@@ -203,7 +203,7 @@ struct clause
   }
 
   std::list<tree> m_terms; /* The list of terms.  */
-  hash_set<tree, false, atom_hasher> m_set; /* The set of atomic constraints.  */
+  hash_set<tree> m_set; /* The set of atomic constraints.  */
   iterator m_current; /* The current term.  */
 };