Fixing bugs
[satune.git] / src / ASTTransform / analyzer.cc
1 #include "analyzer.h"
2 #include "common.h"
3 #include "order.h"
4 #include "boolean.h"
5 #include "ordergraph.h"
6 #include "ordernode.h"
7 #include "rewriter.h"
8 #include "orderedge.h"
9 #include "mutableset.h"
10 #include "ops.h"
11 #include "csolver.h"
12 #include "orderencoder.h"
13 #include "tunable.h"
14 #include "transform.h"
15 #include "element.h"
16 #include "integerencoding.h"
17 #include "decomposeordertransform.h"
18
19 void orderAnalysis(CSolver *This) {
20         Vector<Order *> *orders = This->getOrders();
21         uint size = orders->getSize();
22         for (uint i = 0; i < size; i++) {
23                 Order *order = orders->get(i);
24                 DecomposeOrderTransform* decompose = new DecomposeOrderTransform(This, order, DECOMPOSEORDER, &onoff);
25                 if (!decompose->canExecuteTransform())
26                         continue;
27
28                 OrderGraph *graph = buildOrderGraph(order);
29                 if (order->type == PARTIAL) {
30                         //Required to do SCC analysis for partial order graphs.  It
31                         //makes sure we don't incorrectly optimize graphs with negative
32                         //polarity edges
33                         completePartialOrderGraph(graph);
34                 }
35
36
37                 bool mustReachGlobal = GETVARTUNABLE(This->getTuner(), order->type, MUSTREACHGLOBAL, &onoff);
38
39                 if (mustReachGlobal)
40                         reachMustAnalysis(This, graph, false);
41
42                 bool mustReachLocal = GETVARTUNABLE(This->getTuner(), order->type, MUSTREACHLOCAL, &onoff);
43
44                 if (mustReachLocal) {
45                         //This pair of analysis is also optional
46                         if (order->type == PARTIAL) {
47                                 localMustAnalysisPartial(This, graph);
48                         } else {
49                                 localMustAnalysisTotal(This, graph);
50                         }
51                 }
52
53                 bool mustReachPrune = GETVARTUNABLE(This->getTuner(), order->type, MUSTREACHPRUNE, &onoff);
54
55                 if (mustReachPrune)
56                         removeMustBeTrueNodes(This, graph);
57
58                 //This is needed for splitorder
59                 computeStronglyConnectedComponentGraph(graph);
60                 decompose->setOrderGraph(graph);
61                 decompose->doTransform();
62                 delete decompose;
63                 delete graph;
64
65                 
66                 IntegerEncodingTransform* integerEncoding = new IntegerEncodingTransform(This, order, ORDERINTEGERENCODING, &offon);
67                 if(!integerEncoding->canExecuteTransform())
68                         continue;
69                 integerEncoding->doTransform();
70                 delete integerEncoding;
71         }
72 }
73
74