https://gcc.gnu.org/g:7eac34a6c793540606a50e20c4c56bd98476d3a1

commit r15-6375-g7eac34a6c793540606a50e20c4c56bd98476d3a1
Author: Patrick Palka <ppa...@redhat.com>
Date:   Thu Dec 19 12:00:31 2024 -0500

    c++: optimize constraint subsumption [PR118069]
    
    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 <ja...@redhat.com>

Diff:
---
 gcc/cp/constraint.cc | 21 +++++++++++++++++++++
 gcc/cp/cp-tree.h     | 21 ---------------------
 gcc/cp/logic.cc      |  2 +-
 3 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 2af1bbc016b9..c75982d80093 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -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;
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 6833035664b0..32e6b014b67e 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -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);
 
diff --git a/gcc/cp/logic.cc b/gcc/cp/logic.cc
index a385fb719eca..6b4bf1dfb7dc 100644
--- a/gcc/cp/logic.cc
+++ b/gcc/cp/logic.cc
@@ -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.  */
 };

Reply via email to