summaryrefslogtreecommitdiff
path: root/src/theory/arrays/array_info.h
blob: d1c435b481aec13b1177db380cdf1fe093fab4e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/*********************                                                        */
/*! \file array_info.h
 ** \verbatim
 ** Original author: lianah
 ** Major contributors: none
 ** Minor contributors (to current version): mdeters
 ** This file is part of the CVC4 prototype.
 ** Copyright (c) 2009, 2010, 2011  The Analysis of Computer Systems Group (ACSys)
 ** Courant Institute of Mathematical Sciences
 ** New York University
 ** See the file COPYING in the top-level source directory for licensing
 ** information.\endverbatim
 **
 ** \brief [[ Add one-line brief description here ]]
 **
 ** [[ Add lengthier description here ]]
 ** \todo document this file
 **/

/*! \file array_info.h
 ** \verbatim
 ** Original author: lianah
 ** Major contributors: none
 ** Minor contributors (to current version): none
 ** This file is part of the CVC4 prototype.
 ** Copyright (c) 2009, 2010  The Analysis of Computer Systems Group (ACSys)
 ** Courant Institute of Mathematical Sciences
 ** New York University
 ** See the file COPYING in the top-level source directory for licensing
 ** information.\endverbatim
 **
 ** \brief Contains additional classes to store context dependent information
 ** for each term of type array
 **
 **
 **/

#include "cvc4_private.h"

#ifndef __CVC4__THEORY__ARRAYS__ARRAY_INFO_H
#define __CVC4__THEORY__ARRAYS__ARRAY_INFO_H
#include "util/backtrackable.h"
#include "context/cdlist.h"
#include "context/cdhashmap.h"
#include "expr/node.h"
#include "util/stats.h"
#include "util/ntuple.h"
#include <ext/hash_set>
#include <ext/hash_map>
#include <iostream>
#include <map>

namespace CVC4 {
namespace theory {
namespace arrays {

typedef context::CDList<TNode> CTNodeList;

struct TNodeQuadHashFunction {
  size_t operator()(const quad<CVC4::TNode, CVC4::TNode, CVC4::TNode, CVC4::TNode>& q ) const {
    TNode n1 = q.first;
    TNode n2 = q.second;
    TNode n3 = q.third;
    TNode n4 = q.fourth;
    return (size_t) (n1.getId()*0x9e3779b9 + n2.getId()*0x30000059 +
        n3.getId()*0x60000005 + n4.getId()*0x07FFFFFF);

  }
};/* struct TNodeQuadHashFunction */

void printList (CTNodeList* list);
void printList( List<TNode>* list);

bool inList(const CTNodeList* l, const TNode el);

/**
 * Small class encapsulating the information
 * in the map. It's a class and not a struct to
 * call the destructor.
 */

class Info {
public:
  List<TNode>* indices;
  CTNodeList* stores;
  CTNodeList* in_stores;

  Info(context::Context* c, Backtracker<TNode>* bck) {
    indices = new List<TNode>(bck);
    stores = new(true)CTNodeList(c);
    in_stores = new(true)CTNodeList(c);

  }

  ~Info() {
    //FIXME!
    //indices->deleteSelf();
    stores->deleteSelf();
    in_stores->deleteSelf();
  }

  /**
   * prints the information
   */
  void print() const {
    Assert(indices != NULL && stores!= NULL); // && equals != NULL);
    Trace("arrays-info")<<"  indices   ";
    printList(indices);
    Trace("arrays-info")<<"  stores ";
    printList(stores);
    Trace("arrays-info")<<"  in_stores ";
    printList(in_stores);
  }
};


typedef __gnu_cxx::hash_map<Node, Info*, NodeHashFunction> CNodeInfoMap;

/**
 * Class keeping track of the following information for canonical
 * representatives of type array [a] :
 *    indices at which it is being read (all i for which there is a
 *            term of the form SELECT a i)
 *    all store terms in the congruence class
 *    stores in which it appears (terms of the form STORE a _ _ )
 *
 */
class ArrayInfo {
private:
  context::Context* ct;
  Backtracker<TNode>* bck;
  CNodeInfoMap info_map;

  CTNodeList* emptyList;
  List<TNode>* emptyListI;


  /* == STATISTICS == */

  /** time spent in preregisterTerm() */
  TimerStat d_mergeInfoTimer;
  AverageStat d_avgIndexListLength;
  AverageStat d_avgStoresListLength;
  AverageStat d_avgInStoresListLength;
  IntStat d_listsCount;
  IntStat d_callsMergeInfo;
  IntStat d_maxList;
  SizeStat<CNodeInfoMap > d_tableSize;

  /**
   * checks if a certain element is in the list l
   * FIXME: better way to check for duplicates?
   */

  /**
   * helper method that merges two lists into the first
   * without adding duplicates
   */
  void mergeLists(CTNodeList* la, const CTNodeList* lb) const;

public:
  const Info* emptyInfo;
/*
  ArrayInfo(): ct(NULl), info
    d_mergeInfoTimer("theory::arrays::mergeInfoTimer"),
    d_avgIndexListLength("theory::arrays::avgIndexListLength"),
    d_avgStoresListLength("theory::arrays::avgStoresListLength"),
    d_avgInStoresListLength("theory::arrays::avgInStoresListLength"),
    d_listsCount("theory::arrays::listsCount",0),
    d_callsMergeInfo("theory::arrays::callsMergeInfo",0),
    d_maxList("theory::arrays::maxList",0),
    d_tableSize("theory::arrays::infoTableSize", info_map) {
  StatisticsRegistry::registerStat(&d_mergeInfoTimer);
  StatisticsRegistry::registerStat(&d_avgIndexListLength);
  StatisticsRegistry::registerStat(&d_avgStoresListLength);
  StatisticsRegistry::registerStat(&d_avgInStoresListLength);
  StatisticsRegistry::registerStat(&d_listsCount);
  StatisticsRegistry::registerStat(&d_callsMergeInfo);
  StatisticsRegistry::registerStat(&d_maxList);
  StatisticsRegistry::registerStat(&d_tableSize);
  }*/
  ArrayInfo(context::Context* c, Backtracker<TNode>* b): ct(c), bck(b), info_map(),
      d_mergeInfoTimer("theory::arrays::mergeInfoTimer"),
      d_avgIndexListLength("theory::arrays::avgIndexListLength"),
      d_avgStoresListLength("theory::arrays::avgStoresListLength"),
      d_avgInStoresListLength("theory::arrays::avgInStoresListLength"),
      d_listsCount("theory::arrays::listsCount",0),
      d_callsMergeInfo("theory::arrays::callsMergeInfo",0),
      d_maxList("theory::arrays::maxList",0),
      d_tableSize("theory::arrays::infoTableSize", info_map) {
    emptyList = new(true) CTNodeList(ct);
    emptyListI = new List<TNode>(bck);
    emptyInfo = new Info(ct, bck);
    StatisticsRegistry::registerStat(&d_mergeInfoTimer);
    StatisticsRegistry::registerStat(&d_avgIndexListLength);
    StatisticsRegistry::registerStat(&d_avgStoresListLength);
    StatisticsRegistry::registerStat(&d_avgInStoresListLength);
    StatisticsRegistry::registerStat(&d_listsCount);
    StatisticsRegistry::registerStat(&d_callsMergeInfo);
    StatisticsRegistry::registerStat(&d_maxList);
    StatisticsRegistry::registerStat(&d_tableSize);
  }

  ~ArrayInfo(){
    CNodeInfoMap::iterator it = info_map.begin();
    for( ; it != info_map.end(); it++ ) {
      if((*it).second!= emptyInfo) {
        delete (*it).second;
      }
    }
    emptyList->deleteSelf();
    delete emptyInfo;
    StatisticsRegistry::unregisterStat(&d_mergeInfoTimer);
    StatisticsRegistry::unregisterStat(&d_avgIndexListLength);
    StatisticsRegistry::unregisterStat(&d_avgStoresListLength);
    StatisticsRegistry::unregisterStat(&d_avgInStoresListLength);
    StatisticsRegistry::unregisterStat(&d_listsCount);
    StatisticsRegistry::unregisterStat(&d_callsMergeInfo);
    StatisticsRegistry::unregisterStat(&d_maxList);
    StatisticsRegistry::unregisterStat(&d_tableSize);
  };

  /**
   * adds the node a to the map if it does not exist
   * and it initializes the info. checks for duplicate i's
   */
  void addIndex(const Node a, const TNode i);
  void addStore(const Node a, const TNode st);
  void addInStore(const TNode a, const TNode st);


  /**
   * Returns the information associated with TNode a
   */

  const Info* getInfo(const TNode a) const;

  List<TNode>* getIndices(const TNode a) const;

  const CTNodeList* getStores(const TNode a) const;

  const CTNodeList* getInStores(const TNode a) const;

  /**
   * merges the information of  nodes a and b
   * the nodes do not have to actually be in the map.
   * pre-condition
   *  a should be the canonical representative of b
   */
  void mergeInfo(const TNode a, const TNode b);
};


}/* CVC4::theory::arrays namespace */
}/* CVC4::theory namespace */
}/* CVC4 namespace */

#endif /* __CVC4__THEORY__ARRAYS__ARRAY_INFO_H */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback