Refactor eager atoms preprocessing pass. (#2318)
authorMathias Preiner <mathias.preiner@gmail.com>
Fri, 17 Aug 2018 06:07:49 +0000 (23:07 -0700)
committerAndres Noetzli <andres.noetzli@gmail.com>
Fri, 17 Aug 2018 06:07:49 +0000 (23:07 -0700)
src/Makefile.am
src/preprocessing/passes/bv_eager_atoms.cpp [new file with mode: 0644]
src/preprocessing/passes/bv_eager_atoms.h [new file with mode: 0644]
src/smt/smt_engine.cpp

index f3737e50675f815d3154ba8a1dfa41f3cc5b2afd..5e52186b9daa903c060c0fead19bd3835be1668a 100644 (file)
@@ -69,6 +69,8 @@ libcvc4_la_SOURCES = \
        preprocessing/passes/bv_abstraction.h \
        preprocessing/passes/bv_ackermann.cpp \
        preprocessing/passes/bv_ackermann.h \
+       preprocessing/passes/bv_eager_atoms.cpp \
+       preprocessing/passes/bv_eager_atoms.h \
        preprocessing/passes/bv_gauss.cpp \
        preprocessing/passes/bv_gauss.h \
        preprocessing/passes/bv_intro_pow2.cpp \
diff --git a/src/preprocessing/passes/bv_eager_atoms.cpp b/src/preprocessing/passes/bv_eager_atoms.cpp
new file mode 100644 (file)
index 0000000..fe43ebc
--- /dev/null
@@ -0,0 +1,47 @@
+/*********************                                                        */
+/*! \file bv_eager_atoms.cpp
+ ** \verbatim
+ ** Top contributors (to current version):
+ **   Mathias Preiner
+ ** This file is part of the CVC4 project.
+ ** Copyright (c) 2009-2018 by the authors listed in the file AUTHORS
+ ** in the top-level source directory) and their institutional affiliations.
+ ** All rights reserved.  See the file COPYING in the top-level source
+ ** directory for licensing information.\endverbatim
+ **
+ ** \brief Wrap assertions in BITVECTOR_EAGER_ATOM nodes.
+ **
+ ** This preprocessing pass wraps all assertions in BITVECTOR_EAGER_ATOM nodes
+ ** and allows to use eager bit-blasting in the BV solver.
+ **/
+
+
+#include "preprocessing/passes/bv_eager_atoms.h"
+
+#include "theory/theory_model.h"
+
+namespace CVC4 {
+namespace preprocessing {
+namespace passes {
+
+BvEagerAtoms::BvEagerAtoms(PreprocessingPassContext* preprocContext)
+    : PreprocessingPass(preprocContext, "bv-eager-atoms"){};
+
+PreprocessingPassResult BvEagerAtoms::applyInternal(
+    AssertionPipeline* assertionsToPreprocess)
+{
+  theory::TheoryModel* tm = d_preprocContext->getTheoryEngine()->getModel();
+  NodeManager* nm = NodeManager::currentNM();
+  for (unsigned i = 0, size = assertionsToPreprocess->size(); i < size; ++i)
+  {
+    TNode atom = (*assertionsToPreprocess)[i];
+    Node eager_atom = nm->mkNode(kind::BITVECTOR_EAGER_ATOM, atom);
+    tm->addSubstitution(eager_atom, atom);
+    assertionsToPreprocess->replace(i, eager_atom);
+  }
+  return PreprocessingPassResult::NO_CONFLICT;
+}
+
+}  // namespace passes
+}  // namespace preprocessing
+}  // namespace CVC4
diff --git a/src/preprocessing/passes/bv_eager_atoms.h b/src/preprocessing/passes/bv_eager_atoms.h
new file mode 100644 (file)
index 0000000..585c108
--- /dev/null
@@ -0,0 +1,44 @@
+/*********************                                                        */
+/*! \file bv_eager_atoms.h
+ ** \verbatim
+ ** Top contributors (to current version):
+ **   Mathias Preiner
+ ** This file is part of the CVC4 project.
+ ** Copyright (c) 2009-2018 by the authors listed in the file AUTHORS
+ ** in the top-level source directory) and their institutional affiliations.
+ ** All rights reserved.  See the file COPYING in the top-level source
+ ** directory for licensing information.\endverbatim
+ **
+ ** \brief Wrap assertions in BITVECTOR_EAGER_ATOM nodes.
+ **
+ ** This preprocessing pass wraps all assertions in BITVECTOR_EAGER_ATOM nodes
+ ** and allows to use eager bit-blasting in the BV solver.
+ **/
+
+#include "cvc4_private.h"
+
+#ifndef __CVC4__PREPROCESSING__PASSES__BV_EAGER_ATOMS_H
+#define __CVC4__PREPROCESSING__PASSES__BV_EAGER_ATOMS_H
+
+#include "preprocessing/preprocessing_pass.h"
+#include "preprocessing/preprocessing_pass_context.h"
+
+namespace CVC4 {
+namespace preprocessing {
+namespace passes {
+
+class BvEagerAtoms : public PreprocessingPass
+{
+ public:
+  BvEagerAtoms(PreprocessingPassContext* preprocContext);
+
+ protected:
+  PreprocessingPassResult applyInternal(
+      AssertionPipeline* assertionsToPreprocess) override;
+};
+
+}  // namespace passes
+}  // namespace preprocessing
+}  // namespace CVC4
+
+#endif /* __CVC4__PREPROCESSING__PASSES__BV_EAGER_ATOMS_H */
index 4c63d6592c4225e6349a8937deef439c3fe19779..34a5a6d5b6cd3f7a981b83e15168b5de451cb1ee 100644 (file)
@@ -74,6 +74,7 @@
 #include "preprocessing/passes/bool_to_bv.h"
 #include "preprocessing/passes/bv_abstraction.h"
 #include "preprocessing/passes/bv_ackermann.h"
+#include "preprocessing/passes/bv_eager_atoms.h"
 #include "preprocessing/passes/bv_gauss.h"
 #include "preprocessing/passes/bv_intro_pow2.h"
 #include "preprocessing/passes/bv_to_bool.h"
@@ -2642,6 +2643,8 @@ void SmtEnginePrivate::finishInit()
       new BoolToBV(d_preprocessingPassContext.get()));
   std::unique_ptr<BvAbstraction> bvAbstract(
       new BvAbstraction(d_preprocessingPassContext.get()));
+  std::unique_ptr<BvEagerAtoms> bvEagerAtoms(
+      new BvEagerAtoms(d_preprocessingPassContext.get()));
   std::unique_ptr<BVAckermann> bvAckermann(
       new BVAckermann(d_preprocessingPassContext.get()));
   std::unique_ptr<BVGauss> bvGauss(
@@ -2684,6 +2687,8 @@ void SmtEnginePrivate::finishInit()
                                            std::move(bvAbstract));
   d_preprocessingPassRegistry.registerPass("bv-ackermann",
                                            std::move(bvAckermann));
+  d_preprocessingPassRegistry.registerPass("bv-eager-atoms",
+                                           std::move(bvEagerAtoms));
   d_preprocessingPassRegistry.registerPass("bv-gauss", std::move(bvGauss));
   d_preprocessingPassRegistry.registerPass("bv-intro-pow2",
                                            std::move(bvIntroPow2));
@@ -4394,16 +4399,9 @@ void SmtEnginePrivate::processAssertions() {
   Trace("smt-proc") << "SmtEnginePrivate::processAssertions() : post-theory-preprocessing" << endl;
   dumpAssertions("post-theory-preprocessing", d_assertions);
 
-  // If we are using eager bit-blasting wrap assertions in fake atom so that
-  // everything gets bit-blasted to internal SAT solver
-  if (options::bitblastMode() == theory::bv::BITBLAST_MODE_EAGER) {
-    for (unsigned i = 0; i < d_assertions.size(); ++i) {
-      TNode atom = d_assertions[i];
-      Node eager_atom = NodeManager::currentNM()->mkNode(kind::BITVECTOR_EAGER_ATOM, atom);
-      d_assertions.replace(i, eager_atom);
-      TheoryModel* m = d_smt.d_theoryEngine->getModel();
-      m->addSubstitution(eager_atom, atom);
-    }
+  if (options::bitblastMode() == theory::bv::BITBLAST_MODE_EAGER)
+  {
+    d_preprocessingPassRegistry.getPass("bv-eager-atoms")->apply(&d_assertions);
   }
 
   //notify theory engine new preprocessed assertions