0ceb306933152ef9f1232cd620209874b8027214
[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         CMEMALLOC;
13 };
14
15 class EncodingValue;
16
17 typedef Hashset<EncodingValue *, uintptr_t, PTRSHIFT> HashsetEncodingValue;
18 typedef SetIterator<EncodingValue *, uintptr_t, PTRSHIFT> SetIteratorEncodingValue;
19
20 class EncodingValue {
21 public:
22         EncodingValue(uint64_t _val) : value(_val), encoding(0), inComparison(false), assigned(false) {}
23         void merge(EncodingValue *value);
24         uint64_t value;
25         uint encoding;
26         bool inComparison;
27         bool assigned;
28         HashsetEncodingNode nodes;
29         HashsetEncodingValue larger;
30         HashsetEncodingValue notequals;
31         CMEMALLOC;
32 };
33
34 uint hashNodeValuePair(NodeValuePair *nvp);
35 bool equalsNodeValuePair(NodeValuePair *nvp1, NodeValuePair *nvp2);
36
37 typedef Hashtable<NodeValuePair *, EncodingValue *, uintptr_t, 0, hashNodeValuePair, equalsNodeValuePair> NVPMap;
38
39 class EncodingSubGraph {
40 public:
41         EncodingSubGraph();
42         ~EncodingSubGraph();
43         void addNode(EncodingNode *n);
44         SetIteratorEncodingNode *nodeIterator();
45         void encode();
46         uint getEncoding(EncodingNode *n, uint64_t val);
47         uint getEncodingMaxVal(EncodingNode *n) { return maxEncodingVal;}
48         double measureSimilarity(EncodingNode *n);
49         double measureSimilarity(EncodingSubGraph *sg);
50         CMEMALLOC;
51 private:
52         uint estimateNewSize(EncodingNode *n);
53         uint estimateNewSize(EncodingSubGraph *sg);
54         void traverseValue(EncodingNode *node, uint64_t value);
55         void computeEncodingValue();
56         void computeComparisons();
57         void computeEqualities();
58         void solveComparisons();
59         void solveEquals();
60         void generateComparison(EncodingNode *left, EncodingNode *right);
61         void generateEquals(EncodingNode *left, EncodingNode *right);
62         void orderEV(EncodingValue *smaller, EncodingValue *larger);
63
64         HashsetEncodingValue values;
65         HashsetEncodingNode nodes;
66         NVPMap map;
67         uint encodingSize;
68         uint numElements;
69         uint maxEncodingVal;
70
71         friend class EncodingGraph;
72 };
73
74 #endif