1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Mathias Preiner, Andrew Reynolds |
4 |
|
* |
5 |
|
* This file is part of the cvc5 project. |
6 |
|
* |
7 |
|
* Copyright (c) 2009-2021 by the authors listed in the file AUTHORS |
8 |
|
* in the top-level source directory and their institutional affiliations. |
9 |
|
* All rights reserved. See the file COPYING in the top-level source |
10 |
|
* directory for licensing information. |
11 |
|
* **************************************************************************** |
12 |
|
* |
13 |
|
* Bit-blasting solver that supports multiple SAT back ends. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "cvc5_private.h" |
17 |
|
|
18 |
|
#ifndef CVC5__THEORY__BV__BV_SOLVER_BITBLAST_H |
19 |
|
#define CVC5__THEORY__BV__BV_SOLVER_BITBLAST_H |
20 |
|
|
21 |
|
#include <unordered_map> |
22 |
|
|
23 |
|
#include "context/cdqueue.h" |
24 |
|
#include "proof/eager_proof_generator.h" |
25 |
|
#include "prop/cnf_stream.h" |
26 |
|
#include "prop/sat_solver.h" |
27 |
|
#include "theory/bv/bitblast/node_bitblaster.h" |
28 |
|
#include "theory/bv/bv_solver.h" |
29 |
|
#include "theory/bv/proof_checker.h" |
30 |
|
|
31 |
|
namespace cvc5 { |
32 |
|
|
33 |
|
namespace theory { |
34 |
|
namespace bv { |
35 |
|
|
36 |
|
class NotifyResetAssertions; |
37 |
|
class BBRegistrar; |
38 |
|
|
39 |
|
/** |
40 |
|
* Bit-blasting solver with support for different SAT back ends. |
41 |
|
*/ |
42 |
|
class BVSolverBitblast : public BVSolver |
43 |
|
{ |
44 |
|
public: |
45 |
|
BVSolverBitblast(Env& env, |
46 |
|
TheoryState* state, |
47 |
|
TheoryInferenceManager& inferMgr, |
48 |
|
ProofNodeManager* pnm); |
49 |
12290 |
~BVSolverBitblast() = default; |
50 |
|
|
51 |
6148 |
bool needsEqualityEngine(EeSetupInfo& esi) override { return true; } |
52 |
|
|
53 |
137273 |
void preRegisterTerm(TNode n) override {} |
54 |
|
|
55 |
|
void postCheck(Theory::Effort level) override; |
56 |
|
|
57 |
|
bool preNotifyFact(TNode atom, |
58 |
|
bool pol, |
59 |
|
TNode fact, |
60 |
|
bool isPrereg, |
61 |
|
bool isInternal) override; |
62 |
|
|
63 |
|
TrustNode explain(TNode n) override; |
64 |
|
|
65 |
|
std::string identify() const override { return "BVSolverBitblast"; }; |
66 |
|
|
67 |
|
void computeRelevantTerms(std::set<Node>& termSet) override; |
68 |
|
|
69 |
|
bool collectModelValues(TheoryModel* m, |
70 |
|
const std::set<Node>& termSet) override; |
71 |
|
|
72 |
|
/** |
73 |
|
* Get the current value of `node`. |
74 |
|
* |
75 |
|
* The `initialize` flag indicates whether bits should be zero-initialized |
76 |
|
* if they were not bit-blasted yet. |
77 |
|
*/ |
78 |
|
Node getValue(TNode node, bool initialize) override; |
79 |
|
|
80 |
|
private: |
81 |
|
/** Initialize SAT solver and CNF stream. */ |
82 |
|
void initSatSolver(); |
83 |
|
|
84 |
|
/** |
85 |
|
* Handle BITVECTOR_EAGER_ATOM atoms and assert/assume to CnfStream. |
86 |
|
* |
87 |
|
* @param assertFact: Indicates whether the fact should be asserted (true) or |
88 |
|
* assumed (false). |
89 |
|
*/ |
90 |
|
void handleEagerAtom(TNode fact, bool assertFact); |
91 |
|
|
92 |
|
/** Bit-blaster used to bit-blast atoms/terms. */ |
93 |
|
std::unique_ptr<NodeBitblaster> d_bitblaster; |
94 |
|
|
95 |
|
/** Used for initializing `d_cnfStream`. */ |
96 |
|
std::unique_ptr<BBRegistrar> d_bbRegistrar; |
97 |
|
std::unique_ptr<context::Context> d_nullContext; |
98 |
|
|
99 |
|
/** SAT solver back end (configured via options::bvSatSolver. */ |
100 |
|
std::unique_ptr<prop::SatSolver> d_satSolver; |
101 |
|
/** CNF stream. */ |
102 |
|
std::unique_ptr<prop::CnfStream> d_cnfStream; |
103 |
|
|
104 |
|
/** |
105 |
|
* Bit-blast queue for facts sent to this solver. |
106 |
|
* |
107 |
|
* Gets populated on preNotifyFact(). |
108 |
|
*/ |
109 |
|
context::CDQueue<Node> d_bbFacts; |
110 |
|
|
111 |
|
/** |
112 |
|
* Bit-blast queue for user-level 0 input facts sent to this solver. |
113 |
|
* |
114 |
|
* Get populated on preNotifyFact(). |
115 |
|
*/ |
116 |
|
context::CDQueue<Node> d_bbInputFacts; |
117 |
|
|
118 |
|
/** Corresponds to the SAT literals of the currently asserted facts. */ |
119 |
|
context::CDList<prop::SatLiteral> d_assumptions; |
120 |
|
|
121 |
|
/** Stores the current input assertions. */ |
122 |
|
context::CDList<Node> d_assertions; |
123 |
|
|
124 |
|
/** Proof generator that manages proofs for lemmas generated by this class. */ |
125 |
|
std::unique_ptr<EagerProofGenerator> d_epg; |
126 |
|
|
127 |
|
BVProofRuleChecker d_bvProofChecker; |
128 |
|
|
129 |
|
/** Stores the SatLiteral for a given fact. */ |
130 |
|
context::CDHashMap<Node, prop::SatLiteral> d_factLiteralCache; |
131 |
|
|
132 |
|
/** Reverse map of `d_factLiteralCache`. */ |
133 |
|
context::CDHashMap<prop::SatLiteral, Node, prop::SatLiteralHashFunction> |
134 |
|
d_literalFactCache; |
135 |
|
|
136 |
|
/** Option to enable/disable bit-level propagation. */ |
137 |
|
bool d_propagate; |
138 |
|
|
139 |
|
/** Notifies when reset-assertion was called. */ |
140 |
|
std::unique_ptr<NotifyResetAssertions> d_resetNotify; |
141 |
|
}; |
142 |
|
|
143 |
|
} // namespace bv |
144 |
|
} // namespace theory |
145 |
|
} // namespace cvc5 |
146 |
|
|
147 |
|
#endif |