diff options
author | Andrew Sutton <asutton@lock3software.com> | 2019-10-24 15:03:49 +0000 |
---|---|---|
committer | Andrew Sutton <asutton@gcc.gnu.org> | 2019-10-24 15:03:49 +0000 |
commit | 79c05c2bc49b4880ec4789d4078178e27821f268 (patch) | |
tree | e26a1b04787b484f4bffdf08b8b1ebb70414beb5 /gcc/cp/logic.cc | |
parent | 4352288a3df915575a2b820f702242908740106f (diff) | |
download | gcc-79c05c2bc49b4880ec4789d4078178e27821f268.zip gcc-79c05c2bc49b4880ec4789d4078178e27821f268.tar.gz gcc-79c05c2bc49b4880ec4789d4078178e27821f268.tar.bz2 |
Finish moving constraint and logic functionality of out pt.c.
Also, reimplement and re-enable subsumption caching.
gcc/cp/
* config-lang.in (gtfiles): Add logic.cc.
* constraint.cc (atomic_constraints_identical_p): Add assertions.
(hash_atomic_constraint): Likewise.
(constraints_equivalent_p): New.
(inchash::add_constraint): New.
(iterative_hash_constraint): New.
(decl_constraints): Moved from pt.c.
(get_constraints): Likewise.
(set_constraints): Likewise.
(remove_constraints): Likewise.
* cp-tree.h (CONSTR_P): New.
(init_constraint_processing): Remove.
(constraints_equivalent_p, iterative_hash_constraint): Declare.
* decl.c (cxx_init_decl_processing): Don't initialize constraints.
* logic.cc (subsumption_entry): Moved from pt.c.
(subsumption_hasher): Likewise.
(subsumption_cache): Likewise.
(lookup_subsumption): Likewise.
(save_subsumption): Likewise.
(subsumes_constraints_nonnull): Use subsumption cache.
* pt.c: Move aforementioned declarations out of this file.
(init_constraint_processing): Remove.
From-SVN: r277407
Diffstat (limited to 'gcc/cp/logic.cc')
-rw-r--r-- | gcc/cp/logic.cc | 83 |
1 files changed, 78 insertions, 5 deletions
diff --git a/gcc/cp/logic.cc b/gcc/cp/logic.cc index 2d4abaf..ee68b54 100644 --- a/gcc/cp/logic.cc +++ b/gcc/cp/logic.cc @@ -780,6 +780,73 @@ diagnose_constraint_size (tree t) return false; } +/* Key/value pair for caching subsumption results. This associates a pair of + constraints with a boolean value indicating the result. */ + +struct GTY((for_user)) subsumption_entry +{ + tree lhs; + tree rhs; + bool result; +}; + +/* Hashing function and equality for constraint entries. */ + +struct subsumption_hasher : ggc_ptr_hash<subsumption_entry> +{ + static hashval_t hash (subsumption_entry *e) + { + hashval_t val = 0; + val = iterative_hash_constraint (e->lhs, val); + val = iterative_hash_constraint (e->rhs, val); + return val; + } + + static bool equal (subsumption_entry *e1, subsumption_entry *e2) + { + if (!constraints_equivalent_p (e1->lhs, e2->lhs)) + return false; + if (!constraints_equivalent_p (e1->rhs, e2->rhs)) + return false; + return true; + } +}; + +/* Caches the results of subsumes_non_null(t1, t1). */ + +static GTY ((deletable)) hash_table<subsumption_hasher> *subsumption_cache; + +/* Search for a previously cached subsumption result. */ + +static bool* +lookup_subsumption (tree t1, tree t2) +{ + if (!subsumption_cache) + return NULL; + subsumption_entry elt = { t1, t2, false }; + subsumption_entry* found = subsumption_cache->find (&elt); + if (found) + return &found->result; + else + return 0; +} + +/* Save a subsumption result. */ + +static bool +save_subsumption (tree t1, tree t2, bool result) +{ + if (!subsumption_cache) + subsumption_cache = hash_table<subsumption_hasher>::create_ggc(31); + subsumption_entry elt = {t1, t2, result}; + subsumption_entry** slot = subsumption_cache->find_slot (&elt, INSERT); + subsumption_entry* entry = ggc_alloc<subsumption_entry> (); + *entry = elt; + *slot = entry; + return result; +} + + /* Returns true if the LEFT constraint subsume the RIGHT constraints. This is done by deriving a proof of the conclusions on the RIGHT from the assumptions on the LEFT assumptions. */ @@ -789,6 +856,9 @@ subsumes_constraints_nonnull (tree lhs, tree rhs) { auto_timevar time (TV_CONSTRAINT_SUB); + if (bool *b = lookup_subsumption(lhs, rhs)) + return *b; + int n1 = dnf_size (lhs); int n2 = cnf_size (rhs); @@ -803,19 +873,20 @@ subsumes_constraints_nonnull (tree lhs, tree rhs) } /* Decompose the smaller of the two formulas, and recursively - check the implication using the larger. Note that for - constraints that are largely comprised of conjunctions the - it will usually be the case that n1 <= n2. */ + check for implication of the larger. */ + bool result; if (n1 <= n2) { formula dnf = decompose_antecedents (lhs); - return derive_proofs (dnf, rhs, left); + result = derive_proofs (dnf, rhs, left); } else { formula cnf = decompose_consequents (rhs); - return derive_proofs (cnf, lhs, right); + result = derive_proofs (cnf, lhs, right); } + + return save_subsumption (lhs, rhs, result); } /* Returns true if the LEFT constraints subsume the RIGHT @@ -832,3 +903,5 @@ subsumes (tree lhs, tree rhs) return true; return subsumes_constraints_nonnull (lhs, rhs); } + +#include "gt-cp-logic.h" |