Fix BV inequality solver caching.
authorMorgan Deters <mdeters@cs.nyu.edu>
Wed, 12 Nov 2014 12:46:02 +0000 (07:46 -0500)
committerMorgan Deters <mdeters@cs.nyu.edu>
Thu, 13 Nov 2014 00:27:16 +0000 (19:27 -0500)
src/theory/bv/bv_subtheory_inequality.cpp
src/theory/bv/bv_subtheory_inequality.h

index 4f9eb082366fdea2e6c3cc80dcbdf0f1e87338e4..917b10c334b74766e7847d5b097981d693262579 100644 (file)
@@ -137,14 +137,14 @@ void InequalitySolver::assertFact(TNode fact) {
 }
 
 bool InequalitySolver::isInequalityOnly(TNode node) {
-  if (d_ineqOnlyCache.find(node) != d_ineqOnlyCache.end()) {
-    return d_ineqOnlyCache[node];
-  }
-
   if (node.getKind() == kind::NOT) {
     node = node[0];
   }
 
+  if (node.getAttribute(IneqOnlyComputedAttribute())) {
+    return node.getAttribute(IneqOnlyAttribute());
+  }
+
   if (node.getKind() != kind::EQUAL &&
       node.getKind() != kind::BITVECTOR_ULT &&
       node.getKind() != kind::BITVECTOR_ULE &&
@@ -152,13 +152,15 @@ bool InequalitySolver::isInequalityOnly(TNode node) {
       node.getKind() != kind::SELECT &&
       node.getKind() != kind::STORE &&
       node.getMetaKind() != kind::metakind::VARIABLE) {
+    // not worth caching
     return false;
   }
   bool res = true;
-  for (unsigned i = 0; i < node.getNumChildren(); ++i) {
+  for (unsigned i = 0; res && i < node.getNumChildren(); ++i) {
     res = res && isInequalityOnly(node[i]);
   }
-  d_ineqOnlyCache[node] = res;
+  node.setAttribute(IneqOnlyComputedAttribute(), true);
+  node.setAttribute(IneqOnlyAttribute(), res);
   return res;
 }
 
index b9195c7d187e363c9ba70eb9dc43795eaba5c023..c9d9dabd388e96f8c2f3cac9755986c515ae9275 100644 (file)
 #include "theory/bv/bv_subtheory.h"
 #include "theory/bv/bv_inequality_graph.h"
 #include "context/cdhashset.h"
+#include "expr/attribute.h"
 
 namespace CVC4 {
 namespace theory {
 namespace bv {
 
+/** Cache for InequalitySolver::isInequalityOnly() */
+struct IneqOnlyAttributeId {};
+typedef expr::Attribute<IneqOnlyAttributeId, bool> IneqOnlyAttribute;
+
+/** Whether the above has been computed yet or not for an expr */
+struct IneqOnlyComputedAttributeId {};
+typedef expr::Attribute<IneqOnlyComputedAttributeId, bool> IneqOnlyComputedAttribute;
+
 class InequalitySolver: public SubtheorySolver {
   struct Statistics {
     IntStat d_numCallstoCheck;
@@ -38,7 +47,6 @@ class InequalitySolver: public SubtheorySolver {
   InequalityGraph d_inequalityGraph;
   context::CDHashMap<Node, TNode, NodeHashFunction> d_explanations;
   context::CDO<bool> d_isComplete;
-  __gnu_cxx::hash_map<TNode, bool, TNodeHashFunction> d_ineqOnlyCache;
   typedef __gnu_cxx::hash_set<TNode, TNodeHashFunction> TNodeSet;
   TNodeSet d_ineqTerms;
   bool isInequalityOnly(TNode node);
@@ -51,7 +59,6 @@ public:
       d_inequalityGraph(c),
       d_explanations(c),
       d_isComplete(c, true),
-      d_ineqOnlyCache(),
       d_ineqTerms(),
       d_statistics()
   {}