Merge
[satune.git] / src / ASTAnalyses / Encoding / subgraph.h
1 #ifndef SUBGRAPH_H
2 #define SUBGRAPH_H
3 #include "classlist.h"
4 #include "structs.h"
5 #include "graphstructs.h"
6
7 class NodeValuePair {
8  public:
9  NodeValuePair(EncodingNode *n, uint64_t val) : node(n), value(val) {}
10         EncodingNode *node;
11         uint64_t value;
12 };
13
14 class EncodingValue {
15  public:
16  EncodingValue(uint64_t _val) : value(_val), inComparison(false) {}
17         void merge(EncodingValue *value);
18         uint64_t value;
19         bool inComparison;
20         HashsetEncodingNode nodes;
21         Vector<EncodingValue *> larger;
22 };
23
24 uint hashNodeValuePair(NodeValuePair *nvp);
25 bool equalsNodeValuePair(NodeValuePair *nvp1, NodeValuePair *nvp2);
26
27 typedef Hashtable<NodeValuePair *, EncodingValue *, uintptr_t, 4, hashNodeValuePair, equalsNodeValuePair> NVPMap;
28
29 class EncodingSubGraph {
30  public:
31         EncodingSubGraph();
32         void addNode(EncodingNode *n);
33         SetIteratorEncodingNode * nodeIterator();
34         void encode();
35         
36         CMEMALLOC;
37  private:
38         uint estimateNewSize(EncodingNode *n);
39         uint estimateNewSize(EncodingSubGraph *sg);
40         void traverseValue(EncodingNode *node, uint64_t value);
41         void computeEncodingValue();
42         void computeInequalities();
43         void generateComparison(EncodingNode *left, EncodingNode *right);
44
45         HashsetEncodingNode nodes;
46         NVPMap map;
47         uint encodingSize;
48         uint numElements;
49
50         friend class EncodingGraph;
51 };
52
53 #endif