From: Patrick Palka Date: Thu, 19 Dec 2024 17:00:31 +0000 (-0500) Subject: c++: optimize constraint subsumption [PR118069] X-Git-Tag: basepoints/gcc-16~3178 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7eac34a6c793540606a50e20c4c56bd98476d3a1;p=thirdparty%2Fgcc.git 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 --- 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 +{ + 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_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 -{ - 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 m_terms; /* The list of terms. */ - hash_set m_set; /* The set of atomic constraints. */ + hash_set m_set; /* The set of atomic constraints. */ iterator m_current; /* The current term. */ };