GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/bv/bv_solver_layered.h Lines: 0 21 0.0 %
Date: 2021-09-17 Branches: 0 42 0.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Mathias Preiner, Liana Hadarean, 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
 * Layered bit-vector solver.
14
 */
15
16
#include "cvc5_private.h"
17
18
#ifndef CVC5__THEORY__BV__BV_SOLVER_LAYERED_H
19
#define CVC5__THEORY__BV__BV_SOLVER_LAYERED_H
20
21
#include <unordered_map>
22
#include <unordered_set>
23
24
#include "context/cdhashset.h"
25
#include "context/cdlist.h"
26
#include "context/context.h"
27
#include "smt/env_obj.h"
28
#include "theory/bv/bv_solver.h"
29
#include "theory/bv/bv_subtheory.h"
30
#include "theory/bv/theory_bv.h"
31
#include "util/hash.h"
32
33
namespace cvc5 {
34
namespace theory {
35
namespace bv {
36
37
class CoreSolver;
38
class InequalitySolver;
39
class AlgebraicSolver;
40
class BitblastSolver;
41
class EagerBitblastSolver;
42
class AbstractionModule;
43
44
class BVSolverLayered : public BVSolver
45
{
46
  /** Back reference to TheoryBV */
47
  TheoryBV& d_bv;
48
49
  /** The context we are using */
50
  context::Context* d_context;
51
52
  /** Context dependent set of atoms we already propagated */
53
  context::CDHashSet<Node> d_alreadyPropagatedSet;
54
  context::CDHashSet<Node> d_sharedTermsSet;
55
56
  std::vector<std::unique_ptr<SubtheorySolver>> d_subtheories;
57
  std::unordered_map<SubTheory, SubtheorySolver*, std::hash<int>>
58
      d_subtheoryMap;
59
60
 public:
61
  BVSolverLayered(Env& env,
62
                  TheoryBV& bv,
63
                  context::Context* c,
64
                  context::UserContext* u,
65
                  ProofNodeManager* pnm = nullptr,
66
                  std::string name = "");
67
68
  ~BVSolverLayered();
69
70
  //--------------------------------- initialization
71
72
  /**
73
   * Returns true if we need an equality engine. If so, we initialize the
74
   * information regarding how it should be setup. For details, see the
75
   * documentation in Theory::needsEqualityEngine.
76
   */
77
  bool needsEqualityEngine(EeSetupInfo& esi) override;
78
79
  /** finish initialization */
80
  void finishInit() override;
81
  //--------------------------------- end initialization
82
83
  void preRegisterTerm(TNode n) override;
84
85
  bool preCheck(Theory::Effort e) override;
86
87
  void propagate(Theory::Effort e) override;
88
89
  TrustNode explain(TNode n) override;
90
91
  bool collectModelValues(TheoryModel* m,
92
                          const std::set<Node>& termSet) override;
93
94
  std::string identify() const override
95
  {
96
    return std::string("BVSolverLayered");
97
  }
98
99
  TrustNode ppRewrite(TNode t) override;
100
101
  void ppStaticLearn(TNode in, NodeBuilder& learned) override;
102
103
  void presolve() override;
104
105
  bool applyAbstraction(const std::vector<Node>& assertions,
106
                        std::vector<Node>& new_assertions) override;
107
108
  bool isLeaf(TNode node) { return d_bv.isLeaf(node); }
109
110
 private:
111
  class Statistics
112
  {
113
   public:
114
    AverageStat d_avgConflictSize;
115
    TimerStat d_solveTimer;
116
    IntStat d_numCallsToCheckFullEffort;
117
    IntStat d_numCallsToCheckStandardEffort;
118
    TimerStat d_weightComputationTimer;
119
    IntStat d_numMultSlice;
120
    Statistics();
121
  };
122
123
  Statistics d_statistics;
124
125
  void check(Theory::Effort e);
126
  void spendResource(Resource r);
127
128
  typedef std::unordered_set<TNode> TNodeSet;
129
  typedef std::unordered_set<Node> NodeSet;
130
  NodeSet d_staticLearnCache;
131
132
  typedef std::unordered_map<Node, Node> NodeToNode;
133
134
  context::CDO<bool> d_lemmasAdded;
135
136
  // Are we in conflict?
137
  context::CDO<bool> d_conflict;
138
139
  // Invalidate the model cache if check was called
140
  context::CDO<bool> d_invalidateModelCache;
141
142
  /** The conflict node */
143
  Node d_conflictNode;
144
145
  /** Literals to propagate */
146
  context::CDList<Node> d_literalsToPropagate;
147
148
  /** Index of the next literal to propagate */
149
  context::CDO<unsigned> d_literalsToPropagateIndex;
150
151
  /**
152
   * Keeps a map from nodes to the subtheory that propagated it so that we can
153
   * explain it properly.
154
   */
155
  typedef context::CDHashMap<Node, SubTheory> PropagatedMap;
156
  PropagatedMap d_propagatedBy;
157
158
  std::unique_ptr<EagerBitblastSolver> d_eagerSolver;
159
  std::unique_ptr<AbstractionModule> d_abstractionModule;
160
  bool d_calledPreregister;
161
162
  bool wasPropagatedBySubtheory(TNode literal) const
163
  {
164
    return d_propagatedBy.find(literal) != d_propagatedBy.end();
165
  }
166
167
  SubTheory getPropagatingSubtheory(TNode literal) const
168
  {
169
    Assert(wasPropagatedBySubtheory(literal));
170
    PropagatedMap::const_iterator find = d_propagatedBy.find(literal);
171
    return (*find).second;
172
  }
173
174
  /** Should be called to propagate the literal.  */
175
  bool storePropagation(TNode literal, SubTheory subtheory);
176
177
  /**
178
   * Explains why this literal (propagated by subtheory) is true by adding
179
   * assumptions.
180
   */
181
  void explain(TNode literal, std::vector<TNode>& assumptions);
182
183
  void notifySharedTerm(TNode t) override;
184
185
  bool isSharedTerm(TNode t) { return d_sharedTermsSet.contains(t); }
186
187
  EqualityStatus getEqualityStatus(TNode a, TNode b) override;
188
189
  Node getModelValue(TNode var);
190
191
  inline std::string indent()
192
  {
193
    std::string indentStr(d_context->getLevel(), ' ');
194
    return indentStr;
195
  }
196
197
  void setConflict(Node conflict = Node::null());
198
199
  bool inConflict() { return d_conflict; }
200
201
  void sendConflict();
202
203
  void lemma(TNode node)
204
  {
205
    d_im.lemma(node, InferenceId::BV_LAYERED_LEMMA);
206
    d_lemmasAdded = true;
207
  }
208
209
  void checkForLemma(TNode node);
210
211
  size_t numAssertions() { return d_bv.numAssertions(); }
212
213
  theory::Assertion get() { return d_bv.get(); }
214
215
  bool done() { return d_bv.done(); }
216
217
  friend class LazyBitblaster;
218
  friend class TLazyBitblaster;
219
  friend class EagerBitblaster;
220
  friend class BitblastSolver;
221
  friend class EqualitySolver;
222
  friend class CoreSolver;
223
  friend class InequalitySolver;
224
  friend class AlgebraicSolver;
225
  friend class EagerBitblastSolver;
226
}; /* class BVSolverLayered */
227
228
}  // namespace bv
229
}  // namespace theory
230
231
}  // namespace cvc5
232
233
#endif /* CVC5__THEORY__BV__BV_SOLVER_LAZY_H */