From: Mathias Preiner Date: Fri, 17 Aug 2018 06:07:49 +0000 (-0700) Subject: Refactor eager atoms preprocessing pass. (#2318) X-Git-Tag: cvc5-1.0.0~4768 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=420f25b1c8103bec7d5fd63a8ade2d9373395e55;p=cvc5.git Refactor eager atoms preprocessing pass. (#2318) --- diff --git a/src/Makefile.am b/src/Makefile.am index f3737e506..5e52186b9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 index 000000000..fe43ebcd0 --- /dev/null +++ b/src/preprocessing/passes/bv_eager_atoms.cpp @@ -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 index 000000000..585c108fc --- /dev/null +++ b/src/preprocessing/passes/bv_eager_atoms.h @@ -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 */ diff --git a/src/smt/smt_engine.cpp b/src/smt/smt_engine.cpp index 4c63d6592..34a5a6d5b 100644 --- a/src/smt/smt_engine.cpp +++ b/src/smt/smt_engine.cpp @@ -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 bvAbstract( new BvAbstraction(d_preprocessingPassContext.get())); + std::unique_ptr bvEagerAtoms( + new BvEagerAtoms(d_preprocessingPassContext.get())); std::unique_ptr bvAckermann( new BVAckermann(d_preprocessingPassContext.get())); std::unique_ptr 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