merge to branch master
[satune.git] / src / ASTAnalyses / Encoding / encodinggraph.cc
index 3e8eec5ba5c20c49aed3f873e6fcde4378d2c414..75a98b1ea7ecc43b66b88700612ab6f4d32032f0 100644 (file)
@@ -7,6 +7,9 @@
 #include "csolver.h"
 #include "tunable.h"
 #include "qsort.h"
+#include "subgraph.h"
+#include "elementencoding.h"
+#include "boolean.h"
 
 EncodingGraph::EncodingGraph(CSolver * _solver) :
        solver(_solver) {
@@ -44,11 +47,39 @@ void EncodingGraph::buildGraph() {
        decideEdges();
 }
 
+void EncodingGraph::encode() {
+       SetIteratorEncodingSubGraph * itesg=subgraphs.iterator();
+       while(itesg->hasNext()) {
+               EncodingSubGraph *sg=itesg->next();
+               sg->encode();
+       }
+       delete itesg;
+
+       ElementIterator it(solver);
+       while(it.hasNext()) {
+               Element * e = it.next();
+               switch(e->type) {
+               case ELEMSET:
+               case ELEMFUNCRETURN: {
+                       ElementEncoding *encoding=e->getElementEncoding();
+                       if (encoding->getElementEncodingType() == ELEM_UNASSIGNED) {
+                               //Do assignment...
+                       }
+                       break;
+               }
+               default:
+                       break;
+               }
+       }
+       
+}
+
 void EncodingGraph::mergeNodes(EncodingNode *first, EncodingNode *second) {
        EncodingSubGraph *graph1=graphMap.get(first);
        EncodingSubGraph *graph2=graphMap.get(second);
        if (graph1 == NULL && graph2 == NULL) {
                graph1 = new EncodingSubGraph();
+               subgraphs.add(graph1);
                graphMap.put(first, graph1);
                graph1->addNode(first);
        }
@@ -66,6 +97,7 @@ void EncodingGraph::mergeNodes(EncodingNode *first, EncodingNode *second) {
                        graph1->addNode(node);
                        graphMap.put(node, graph1);
                }
+               subgraphs.remove(graph2);
                delete nodeit;
                delete graph2;
        } else {
@@ -303,57 +335,4 @@ uint64_t EncodingEdge::getValue() const {
        return numEquals * min + numComparisons * lSize * rSize;
 }
 
-EncodingSubGraph::EncodingSubGraph() :
-       encodingSize(0),
-       numElements(0) {
-}
-
-uint EncodingSubGraph::estimateNewSize(EncodingSubGraph *sg) {
-       uint newSize=0;
-       SetIteratorEncodingNode * nit = sg->nodes.iterator();
-       while(nit->hasNext()) {
-               EncodingNode *en = nit->next();
-               uint size=estimateNewSize(en);
-               if (size > newSize)
-                       newSize = size;
-       }
-       delete nit;
-       return newSize;
-}
-
-uint EncodingSubGraph::estimateNewSize(EncodingNode *n) {
-       SetIteratorEncodingEdge * eeit = n->edges.iterator();
-       uint newsize=n->getSize();
-       while(eeit->hasNext()) {
-               EncodingEdge * ee = eeit->next();
-               if (ee->left != NULL && ee->left != n && nodes.contains(ee->left)) {
-                       uint intersectSize = n->s->getUnionSize(ee->left->s);
-                       if (intersectSize > newsize)
-                               newsize = intersectSize;
-               }
-               if (ee->right != NULL && ee->right != n && nodes.contains(ee->right)) {
-                       uint intersectSize = n->s->getUnionSize(ee->right->s);
-                       if (intersectSize > newsize)
-                               newsize = intersectSize;
-               }
-               if (ee->dst != NULL && ee->dst != n && nodes.contains(ee->dst)) {
-                       uint intersectSize = n->s->getUnionSize(ee->dst->s);
-                       if (intersectSize > newsize)
-                               newsize = intersectSize;
-               }
-       }
-       delete eeit;
-       return newsize;
-}
-
-void EncodingSubGraph::addNode(EncodingNode *n) {
-       nodes.add(n);
-       uint newSize=estimateNewSize(n);
-       numElements += n->elements.getSize();
-       if (newSize > encodingSize)
-               encodingSize=newSize;
-}
 
-SetIteratorEncodingNode * EncodingSubGraph::nodeIterator() {
-       return nodes.iterator();
-}