GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arrays/array_info.h Lines: 14 14 100.0 %
Date: 2021-09-17 Branches: 22 56 39.3 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Morgan Deters, Clark Barrett, Tim King
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
 * Contains additional classes to store context dependent information
14
 * for each term of type array.
15
 */
16
17
#include "cvc5_private.h"
18
19
#ifndef CVC5__THEORY__ARRAYS__ARRAY_INFO_H
20
#define CVC5__THEORY__ARRAYS__ARRAY_INFO_H
21
22
#include <tuple>
23
#include <unordered_map>
24
25
#include "context/cdlist.h"
26
#include "context/cdo.h"
27
#include "expr/node.h"
28
#include "util/statistics_stats.h"
29
30
namespace cvc5 {
31
namespace theory {
32
namespace arrays {
33
34
typedef context::CDList<TNode> CTNodeList;
35
using RowLemmaType = std::tuple<TNode, TNode, TNode, TNode>;
36
37
struct RowLemmaTypeHashFunction {
38
92295
  size_t operator()(const RowLemmaType& q) const {
39
184590
    TNode n1, n2, n3, n4;
40
92295
    std::tie(n1, n2, n3, n4) = q;
41
92295
    return (size_t) (n1.getId()*0x9e3779b9 + n2.getId()*0x30000059 +
42
184590
        n3.getId()*0x60000005 + n4.getId()*0x07FFFFFF);
43
44
  }
45
};/* struct RowLemmaTypeHashFunction */
46
47
void printList (CTNodeList* list);
48
49
bool inList(const CTNodeList* l, const TNode el);
50
51
/**
52
 * Small class encapsulating the information
53
 * in the map. It's a class and not a struct to
54
 * call the destructor.
55
 */
56
57
class Info {
58
public:
59
  context::CDO<bool> isNonLinear;
60
  context::CDO<bool> rIntro1Applied;
61
  context::CDO<TNode> modelRep;
62
  context::CDO<TNode> constArr;
63
  context::CDO<TNode> weakEquivPointer;
64
  context::CDO<TNode> weakEquivIndex;
65
  context::CDO<TNode> weakEquivSecondary;
66
  context::CDO<TNode> weakEquivSecondaryReason;
67
  CTNodeList* indices;
68
  CTNodeList* stores;
69
  CTNodeList* in_stores;
70
71
  Info(context::Context* c);
72
  ~Info();
73
74
  /**
75
   * prints the information
76
   */
77
164
  void print() const {
78
164
    Assert(indices != NULL && stores != NULL && in_stores != NULL);
79
164
    Trace("arrays-info")<<"  indices   ";
80
164
    printList(indices);
81
164
    Trace("arrays-info")<<"  stores ";
82
164
    printList(stores);
83
164
    Trace("arrays-info")<<"  in_stores ";
84
164
    printList(in_stores);
85
164
  }
86
};/* class Info */
87
88
typedef std::unordered_map<Node, Info*> CNodeInfoMap;
89
90
/**
91
 * Class keeping track of the following information for canonical
92
 * representatives of type array [a] :
93
 *    indices at which it is being read (all i for which there is a
94
 *            term of the form SELECT a i)
95
 *    all store terms in the congruence class
96
 *    stores in which it appears (terms of the form STORE a _ _ )
97
 *
98
 */
99
class ArrayInfo {
100
private:
101
  context::Context* ct;
102
  CNodeInfoMap info_map;
103
104
  CTNodeList* emptyList;
105
106
  /* == STATISTICS == */
107
108
  /** time spent in preregisterTerm() */
109
  TimerStat d_mergeInfoTimer;
110
  AverageStat d_avgIndexListLength;
111
  AverageStat d_avgStoresListLength;
112
  AverageStat d_avgInStoresListLength;
113
  IntStat d_listsCount;
114
  IntStat d_callsMergeInfo;
115
  IntStat d_maxList;
116
  SizeStat<CNodeInfoMap> d_tableSize;
117
118
  /**
119
   * checks if a certain element is in the list l
120
   * FIXME: better way to check for duplicates?
121
   */
122
123
  /**
124
   * helper method that merges two lists into the first
125
   * without adding duplicates
126
   */
127
  void mergeLists(CTNodeList* la, const CTNodeList* lb) const;
128
129
public:
130
  const Info* emptyInfo;
131
132
  ArrayInfo(context::Context* c, std::string statisticsPrefix = "");
133
134
  ~ArrayInfo();
135
136
  /**
137
   * adds the node a to the map if it does not exist
138
   * and it initializes the info. checks for duplicate i's
139
   */
140
  void addIndex(const Node a, const TNode i);
141
  void addStore(const Node a, const TNode st);
142
  void addInStore(const TNode a, const TNode st);
143
144
  void setNonLinear(const TNode a);
145
  void setRIntro1Applied(const TNode a);
146
  void setModelRep(const TNode a, const TNode rep);
147
148
  void setConstArr(const TNode a, const TNode constArr);
149
  void setWeakEquivPointer(const TNode a, const TNode pointer);
150
  void setWeakEquivIndex(const TNode a, const TNode index);
151
  void setWeakEquivSecondary(const TNode a, const TNode secondary);
152
  void setWeakEquivSecondaryReason(const TNode a, const TNode reason);
153
  /**
154
   * Returns the information associated with TNode a
155
   */
156
157
  const Info* getInfo(const TNode a) const;
158
159
  const bool isNonLinear(const TNode a) const;
160
161
  const bool rIntro1Applied(const TNode a) const;
162
163
  const TNode getModelRep(const TNode a) const;
164
165
  const TNode getConstArr(const TNode a) const;
166
  const TNode getWeakEquivPointer(const TNode a) const;
167
  const TNode getWeakEquivIndex(const TNode a) const;
168
  const TNode getWeakEquivSecondary(const TNode a) const;
169
  const TNode getWeakEquivSecondaryReason(const TNode a) const;
170
171
  const CTNodeList* getIndices(const TNode a) const;
172
173
  const CTNodeList* getStores(const TNode a) const;
174
175
  const CTNodeList* getInStores(const TNode a) const;
176
177
  /**
178
   * merges the information of  nodes a and b
179
   * the nodes do not have to actually be in the map.
180
   * pre-condition
181
   *  a should be the canonical representative of b
182
   */
183
  void mergeInfo(const TNode a, const TNode b);
184
};/* class ArrayInfo */
185
186
}  // namespace arrays
187
}  // namespace theory
188
}  // namespace cvc5
189
190
#endif /* CVC5__THEORY__ARRAYS__ARRAY_INFO_H */