From 0c1d68d80bf0f95947d82e20120f68ddf54f4e89 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Tue, 19 Sep 2017 14:07:30 -0700 Subject: [PATCH 1/1] More code --- src/ASTAnalyses/Encoding/encodinggraph.cc | 30 +++++++++++++++++++++++ src/ASTAnalyses/Encoding/encodinggraph.h | 4 ++- src/ASTAnalyses/Encoding/graphstructs.h | 2 ++ src/ASTAnalyses/Encoding/subgraph.cc | 7 +++++- src/ASTAnalyses/Encoding/subgraph.h | 3 ++- 5 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/ASTAnalyses/Encoding/encodinggraph.cc b/src/ASTAnalyses/Encoding/encodinggraph.cc index e0cc869..08db96d 100644 --- a/src/ASTAnalyses/Encoding/encodinggraph.cc +++ b/src/ASTAnalyses/Encoding/encodinggraph.cc @@ -8,6 +8,7 @@ #include "tunable.h" #include "qsort.h" #include "subgraph.h" +#include "elementencoding.h" EncodingGraph::EncodingGraph(CSolver * _solver) : solver(_solver) { @@ -45,11 +46,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=getElementEncoding(e); + 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); } @@ -67,6 +96,7 @@ void EncodingGraph::mergeNodes(EncodingNode *first, EncodingNode *second) { graph1->addNode(node); graphMap.put(node, graph1); } + subgraphs.remove(graph2); delete nodeit; delete graph2; } else { diff --git a/src/ASTAnalyses/Encoding/encodinggraph.h b/src/ASTAnalyses/Encoding/encodinggraph.h index 2fd4b37..5fe6d2a 100644 --- a/src/ASTAnalyses/Encoding/encodinggraph.h +++ b/src/ASTAnalyses/Encoding/encodinggraph.h @@ -8,6 +8,7 @@ class EncodingGraph { public: EncodingGraph(CSolver * solver); void buildGraph(); + void encode(); CMEMALLOC; private: @@ -17,7 +18,8 @@ class EncodingGraph { Vector edgeVector; HashsetElement discovered; HashtableNodeToSubGraph graphMap; - + HashsetEncodingSubGraph subgraphs; + void decideEdges(); void mergeNodes(EncodingNode *first, EncodingNode *second); void processElement(Element *e); diff --git a/src/ASTAnalyses/Encoding/graphstructs.h b/src/ASTAnalyses/Encoding/graphstructs.h index 3a54a81..89add61 100644 --- a/src/ASTAnalyses/Encoding/graphstructs.h +++ b/src/ASTAnalyses/Encoding/graphstructs.h @@ -15,4 +15,6 @@ typedef Hashset HashsetEncodingEdge; typedef SetIterator SetIteratorEncodingEdge; typedef Hashtable HashtableNodeToSubGraph; +typedef Hashset HashsetEncodingSubGraph; +typedef SetIterator SetIteratorEncodingSubGraph; #endif diff --git a/src/ASTAnalyses/Encoding/subgraph.cc b/src/ASTAnalyses/Encoding/subgraph.cc index 3690ea7..f75d7c8 100644 --- a/src/ASTAnalyses/Encoding/subgraph.cc +++ b/src/ASTAnalyses/Encoding/subgraph.cc @@ -5,7 +5,8 @@ EncodingSubGraph::EncodingSubGraph() : encodingSize(0), - numElements(0) { + numElements(0), + maxEncodingVal(0) { } uint hashNodeValuePair(NodeValuePair *nvp) { @@ -60,6 +61,8 @@ void EncodingSubGraph::solveEquals() { if (!encodingArray.get(encoding)) break; } + if (encoding > maxEncodingVal) + maxEncodingVal = encoding; ev->encoding = encoding; ev->assigned = true; } @@ -80,6 +83,8 @@ void EncodingSubGraph::solveComparisons() { while(nextIt->hasNext()) { EncodingValue *nextVal=nextIt->next(); if (nextVal->encoding < minVal) { + if (minVal > maxEncodingVal) + maxEncodingVal = minVal; nextVal->encoding = minVal; discovered.add(nextVal); tovisit.push(nextVal); diff --git a/src/ASTAnalyses/Encoding/subgraph.h b/src/ASTAnalyses/Encoding/subgraph.h index 4f19eb1..7738445 100644 --- a/src/ASTAnalyses/Encoding/subgraph.h +++ b/src/ASTAnalyses/Encoding/subgraph.h @@ -60,7 +60,8 @@ class EncodingSubGraph { NVPMap map; uint encodingSize; uint numElements; - + uint maxEncodingVal; + friend class EncodingGraph; }; -- 2.34.1