00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include<omp.h>
00013 #include <boost/regex.hpp>
00014 #include <iostream>
00015 #include <fstream>
00016 #include <string>
00017
00071 #include "staticCFG.h"
00072 #include <vector>
00073 #include <algorithm>
00074 #include <utility>
00075 #include <iostream>
00076 #include <sys/time.h>
00077 #include <sys/resource.h>
00078
00079
00080
00081
00082
00083
00084 struct Bot {
00085 std::vector<std::vector<SgGraphNode*> > path;
00086 std::vector<std::set<SgGraphNode*> > pthloops;
00087 std::vector<SgGraphNode*> currpth;
00088 std::vector<std::pair<SgGraphNode*, int> > nodelst;
00089 bool on;
00090 bool remove;
00091 };
00092
00093 double timeDifference(const struct timeval& end, const struct timeval& begin)
00094 {
00095 return (end.tv_sec + end.tv_usec / 1.0e6) - (begin.tv_sec + begin.tv_usec / 1.0e6);
00096 }
00097
00098 static inline timeval getCPUTime() {
00099 rusage ru;
00100 getrusage(RUSAGE_SELF, &ru);
00101 return ru.ru_utime;
00102 }
00103
00104
00105 struct compareSgGraphNode {
00106 bool operator()(const SgGraphNode* a, const SgGraphNode* b) const
00107 {
00108 return a==b;
00109 }
00110 };
00111
00112
00113
00114
00115 template <class InheritedAttributeType, class SynthesizedAttributeType>
00116 class SgGraphTraversal
00117 {
00118 public:
00119 std::set<std::map<int, std::set<int> > > subpathmap;
00120 int loopNum;
00121 int nullNum;
00122 std::set<SgDirectedGraphEdge*> nullEdgesOrdered;
00123 std::map<SgGraphNode*, int> loopNumMap;
00124 std::map<SgGraphNode*, int> pathValMap;
00125 int nullloops;
00126 std::vector<std::vector<SgGraphNode*> > looppaths;
00127 std::vector<std::vector<SgGraphNode*> > iLoops;
00128 std::vector<SgGraphNode*> ifstatements;
00129 virtual ~SgGraphTraversal();
00130 SgGraphTraversal();
00131
00132 int nullEdgesPaths;
00133 int turns;
00134 SgGraphTraversal(const SgGraphTraversal &);
00135 const SgGraphTraversal &operator=(const SgGraphTraversal &);
00136
00137 typedef StackFrameVector<SynthesizedAttributeType> SynthesizedAttributesList;
00138
00139
00140
00141
00142 int numnodes;
00143
00144
00145 SgGraphNode* nullnode;
00146 std::map<SgGraphNode*, int> primenode;
00147 bool done;
00148
00149 std::set<SgGraphNode*> lstN;
00150 std::map<SgGraphNode*, std::vector<std::set<int> > > lstordmap;
00151 std::set<SgGraphNode*> solvedLoops;
00152 std::map<SgGraphNode*, std::vector<SgGraphNode*> > checkednodes;
00153 std::map<SgGraphNode*, std::set<SgGraphNode*> > downed;
00154
00155
00156
00157 InheritedAttributeType nullInherit;
00158
00159 InheritedAttributeType traverse(SgGraphNode* basenode, SgIncidenceDirectedGraph* g,
00160 InheritedAttributeType inheritedValue, InheritedAttributeType nullInherit,
00161 SgGraphNode* endnode, bool insep = false, bool pcHk = false);
00162 std::set<SgGraphNode*> loopSet;
00163
00164 protected:
00165
00166
00167
00168 virtual InheritedAttributeType evaluateInheritedAttribute(SgGraphNode* n,
00169 std::vector<InheritedAttributeType> inheritedValues) = 0;
00170
00171 virtual SynthesizedAttributeType evaluateSynthesizedAttribute(SgGraphNode* n,
00172 InheritedAttributeType in,
00173 SynthesizedAttributesList l) = 0;
00174
00175 #if !USE_ROSE
00176
00177
00178
00179 virtual void pathAnalyze(std::vector<SgGraphNode*>& pth, bool loop=false, std::set<std::vector<SgGraphNode*> >& incloops=NULL) = 0;
00180 #else
00181 virtual void pathAnalyze(std::vector<SgGraphNode*>& pth, bool loop, std::set<std::vector<SgGraphNode*> >& incloops) = 0;
00182 #endif
00183
00184
00185 SynthesizedAttributeType defaultSynthesizedAttribute(InheritedAttributeType);
00186 private:
00187 double distime;
00188
00189
00190 std::set<SgGraphNode*> ploops;
00191 std::map<SgGraphNode*, std::set<std::vector<SgGraphNode*> > > lpbegins;
00192 std::map<SgGraphNode*, int> frksLeft;
00193 int currm;
00194 int dpMax;
00195 int repEval;
00196 bool pathCheck;
00197 int pathsSize;
00198
00199
00200
00201 std::map<SgGraphNode*, InheritedAttributeType> known;
00202 std::vector<InheritedAttributeType> connectNodes;
00203 std::map<SgGraphNode*, bool> solved;
00204 std::set<SgGraphNode*> solvedset;
00205
00206 SynthesizedAttributesList *synthesizedAttributes;
00207 SynthesizedAttributeType traversalResult();
00208
00209
00210
00211
00212
00213 std::map<SgGraphNode*, int> nodeInEdgesNum;
00214 int currprime;
00215 std::vector<SgGraphNode*> endnodefakes;
00216 std::map<SgGraphNode*, std::vector<std::vector<SgGraphNode*> > > pathsAtMk;
00217 std::set<SgGraphNode*> mkloops;
00218 std::map<SgGraphNode*, std::set<std::vector<SgGraphNode*> > > mkloopmap;
00219 std::map<SgGraphNode*, std::set<std::vector<SgGraphNode*> > > subPathsAtMk;
00220 std::vector<SgGraphNode*> mkglobal;
00221 std::vector<SgGraphNode*> clglobal;
00222 bool inseparable;
00223 void solvePaths(SgIncidenceDirectedGraph* g, SgGraphNode* n, SgGraphNode* endnode);
00224 std::vector<std::set<SgGraphNode*> > closuresVec;
00225 void evaluatePaths(SgIncidenceDirectedGraph* g, SgGraphNode* realstartnode, SgGraphNode* endnode);
00226 void evaluatePathsPar(SgIncidenceDirectedGraph* g, SgGraphNode* realstartnode, SgGraphNode* endnode);
00227 bool disjoint(std::vector<SgGraphNode*>& path, std::vector<SgGraphNode*>& vec2) const;
00228 std::set<std::vector<SgGraphNode*> > flatpaths;
00229
00230 bool canSolve(SgIncidenceDirectedGraph* g, SgGraphNode* n);
00231 std::map<SgGraphNode*, InheritedAttributeType> inhVals;
00232 std::set<SgDirectedGraphEdge*> seenEdges;
00233 std::set<SgDirectedGraphEdge*> nullEdges;
00234 std::set<SgGraphNode*> clsT;
00235 void computeOrder(SgIncidenceDirectedGraph* g, SgGraphNode* n, SgGraphNode* endnode);
00236 void computeInheritedOrdered(SgIncidenceDirectedGraph* g, SgGraphNode* n);
00237 std::pair<bool, SgGraphNode*> getNextPar(SgIncidenceDirectedGraph* g, SgGraphNode* n);
00238 std::pair<bool, SgGraphNode*> getNextChild(SgIncidenceDirectedGraph* g, SgGraphNode* n);
00239 bool computable(SgIncidenceDirectedGraph* g, SgGraphNode* n);
00240 void evalNodeOrdered(SgIncidenceDirectedGraph* g, SgGraphNode* n);
00241 std::map<SgGraphNode*, int> oVals;
00242 bool canEval(SgIncidenceDirectedGraph* g, SgGraphNode* n);
00243 void setPathVal(SgIncidenceDirectedGraph*g, SgGraphNode* n);
00244 void printNodePlusEdgesForAnalysis(SgIncidenceDirectedGraph* g, SgGraphNode* n, int loopNum, int pathVal, std::ofstream& ss);
00245 void printNodePlusEdgesForAnalysisPath(SgIncidenceDirectedGraph* g, std::vector<SgGraphNode*> n, int loopNum, int pathVal, std::ofstream& ss);
00246 void printNodeForAnalysis(SgGraphNode* n, int loopNum, int pathNum, std::ofstream& ss);
00247 std::set<SgGraphNode*> completedNodesPath;
00248 std::set<std::pair<SgGraphNode*, SgGraphNode*> > completedEdgesPath;
00249 void printEdgeForAnalysis(SgDirectedGraphEdge* e, bool isNullEdge, std::ofstream& ss);
00250 void printEdgeForAnalysisPath(SgGraphNode* g1, SgGraphNode* g2, std::ofstream& ss);
00251 std::map<int, SgGraphNode*> iVals;
00252
00253 std::set<SgDirectedGraphEdge*> nullEdgesOrderedOut;
00254 std::set<SgDirectedGraphEdge*> completedEdgesOut;
00255 std::set<SgDirectedGraphEdge*> completedEdges;
00256 std::set<SgGraphNode*> compPar;
00257 std::set<SgGraphNode*> compChild;
00258 std::set<SgGraphNode*> computedNodes;
00259 SgGraphNode* st;
00260 SgGraphNode* en;
00261 double fllp;
00262 int loopnum;
00263
00264
00265
00266
00267
00268 };
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306 template<class InheritedAttributeType, class SynthesizedAttributeType>
00307 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
00308 SgGraphTraversal()
00309 : synthesizedAttributes(new SynthesizedAttributesList())
00310 {
00311 }
00312
00313 #ifndef SWIG
00314
00315 template<class InheritedAttributeType, class SynthesizedAttributeType>
00316 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
00317 ~SgGraphTraversal()
00318 {
00319 ROSE_ASSERT(synthesizedAttributes != NULL);
00320 delete synthesizedAttributes;
00321 synthesizedAttributes = NULL;
00322 }
00323
00324 #endif
00325
00326
00327 template<class InheritedAttributeType, class SynthesizedAttributeType>
00328 const SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType> &
00329 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
00330 operator=(const SgGraphTraversal &other)
00331 {
00332
00333 ROSE_ASSERT(synthesizedAttributes != NULL);
00334 delete synthesizedAttributes;
00335 synthesizedAttributes = other.synthesizedAttributes->deepCopy();
00336
00337 return *this;
00338 }
00339
00357 template<class InheritedAttributeType, class SynthesizedAttributeType>
00358 InheritedAttributeType
00359 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
00360 traverse(SgGraphNode* n, SgIncidenceDirectedGraph* g, InheritedAttributeType inheritedValue, InheritedAttributeType nullI, SgGraphNode* endnode, bool insep, bool pCh) {
00361
00362
00363 looppaths.clear();
00364 iLoops.clear();
00365 completedEdgesPath.clear();
00366 pathValMap.clear();
00367 loopNumMap.clear();
00368 nullloops = 0;
00369 nullEdgesPaths = 0;
00370 fllp = 0.0;
00371 mkglobal.clear();
00372 clglobal.clear();
00373
00374 lpbegins.clear();
00375
00376 inhVals.clear();
00377 iVals.clear();
00378 oVals.clear();
00379
00380 completedEdges.clear();
00381 completedEdgesOut.clear();
00382
00383 computedNodes.clear();
00384 nullEdgesOrdered.clear();
00385 nullEdgesOrderedOut.clear();
00386 loopSet.clear();
00387 pathsAtMk.clear();
00388
00389 st = n;
00390 en = endnode;
00391 distime = 0.0;
00392 int currm = 1;
00393 int turns = 0;
00394 pathsSize = 0;
00395 done = false;
00396 numnodes = 1;
00397 std::cout << "starting traversal" << std::endl;
00398 pathCheck = pCh;
00399 currprime = 1;
00400 inseparable = insep;
00401 synthesizedAttributes->resetStack();
00402 ROSE_ASSERT(synthesizedAttributes->debugSize() == 0);
00403
00404 inhVals[n] = inheritedValue;
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415 nullInherit = nullI;
00416 InheritedAttributeType inh;
00417 struct timeval t1, t2, t3, t4, t5, t6, t7, t8;
00418
00419 loopnum = 0;
00420
00421 t1 = getCPUTime();
00422
00423
00424 solvePaths(g, n, endnode);
00425
00426 t2 = getCPUTime();
00427
00428
00429 ROSE_ASSERT(inhVals.find(endnode) == inhVals.end());
00430
00431 std::cout << "solvePaths done" << std::endl;
00432 double diff = timeDifference(t2, t1);
00433 t5 = getCPUTime();
00434
00435 oVals[n] = 0;
00436 iVals[0] = n;
00437 pathValMap[n] = 1;
00438
00439 computedNodes.insert(n);
00440
00441 computeOrder(g, n, endnode);
00442 std::cout << "order computed" << std::endl;
00443
00444 computeInheritedOrdered(g, n);
00445 std::cout << "inheritance computed" << std::endl;
00446 ROSE_ASSERT(oVals.find(endnode) != oVals.end());
00447 ROSE_ASSERT(inhVals.find(endnode) != inhVals.end());
00448
00449 InheritedAttributeType pthgraphinherit = inhVals[endnode];
00450
00451 t6 = getCPUTime();
00452 std::cout << "evaluateGraph done" << std::endl;
00453 double diff3 = timeDifference(t6, t5);
00454 t3 = getCPUTime();
00455
00456
00457 evaluatePaths(g, n, endnode);
00458
00459 t4 = getCPUTime();
00460
00461 t7 = getCPUTime();
00462
00463 t8 = getCPUTime();
00464
00465 std::cout << "evaluatePaths done " << std::endl;
00466 double diff2 = timeDifference(t4, t3);
00467 double diff2Par = timeDifference(t8, t7);
00468 std::cout << "pathsolve took: " << diff << std::endl;
00469 std::cout << "patheval took: " << diff2 << std::endl;
00470 std::cout << "parpatheval took: " << diff2Par << std::endl;
00471 std::cout << "grapheval took: " << diff3 << std::endl;
00472 std::cout << "entire pathsolve took: " << diff+diff2+diff3+diff2Par << std::endl;
00473 std::cout << "potential loops: " << nullEdgesOrdered.size() << std::endl;
00474 std::cout << "nullNum: " << nullNum << std::endl;
00475
00476
00477 std::cout << "mkloops: " << mkloops.size() << std::endl;
00478 std::cout << "distime: " << distime << std::endl;
00479 std::cout << "fllp: " << fllp << std::endl;
00480 return pthgraphinherit;
00481
00482
00483
00484
00485
00486
00487
00488
00489 }
00490
00491
00492
00493
00494
00495
00496
00497 bool is_disjoint(std::set<SgGraphNode*> set1, std::set<SgGraphNode*> set2) {
00498
00499 if (set1.empty() || set2.empty()) {
00500 return true;
00501 }
00502 std::set<SgGraphNode*>::iterator it1 = set1.begin();
00503 std::set<SgGraphNode*>::iterator it2 = set2.begin();
00504 std::set<SgGraphNode*>::iterator it1End = set1.end();
00505 std::set<SgGraphNode*>::iterator it2End = set2.end();
00506
00507 if (*it1 > *set2.rbegin() || *it2 > *set1.rbegin()) {
00508 return true;
00509 }
00510
00511 while (it1 != it1End && it2 != it2End) {
00512 if (*it1 == *it2) {
00513 return false;
00514 }
00515 if (*it1 < *it2) {
00516 it1++;
00517 }
00518 else {
00519 it2++;
00520 }
00521 }
00522 return true;
00523 }
00524
00525
00526
00527
00528 template<class InheritedAttributeType, class SynthesizedAttributeType>
00529 bool
00530 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
00531 disjoint(std::vector<SgGraphNode*>& pthloops, std::vector<SgGraphNode*>& vec2) const {
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556 for (int i = 0; i < pthloops.size(); i++) {
00557 if (find(vec2.begin(), vec2.end(), pthloops[i]) != vec2.end()) {
00558 return false;
00559 }
00560 }
00561 return true;
00562 }
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669 template<class InheritedAttributeType, class SynthesizedAttributeType>
00670 bool
00671 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
00672 canSolve(SgIncidenceDirectedGraph* g, SgGraphNode* n) {
00673 bool loop = false;
00674 if (inhVals.find(n) != inhVals.end()) {
00675 return true;
00676 }
00677 std::set<SgDirectedGraphEdge*> oed = g->computeEdgeSetIn(n);
00678 if (oed.size() == 0) {
00679 return false;
00680 }
00681 for (std::set<SgDirectedGraphEdge*>::iterator i = oed.begin(); i != oed.end(); i++) {
00682 if (inhVals.find((*i)->get_from()) == inhVals.end() && nullEdges.find(*i) == nullEdges.end()) {
00683 return false;
00684 }
00685 }
00686 return true;
00687 }
00688
00689
00690
00691 template<class InheritedAttributeType, class SynthesizedAttributeType>
00692 void
00693 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
00694 evaluatePathsPar(SgIncidenceDirectedGraph* g, SgGraphNode* realstartnode, SgGraphNode* endnode) {
00695 std::vector<std::vector<SgGraphNode*> > path;
00696 std::vector<SgGraphNode*> spath;
00697 SgGraphNode* n = realstartnode;
00698 int successes = 0;
00699 int failures = 0;
00700 int j = 0;
00701 std::vector<SgGraphNode*> currpthorg;
00702 int currint = 0;
00703 std::map<SgGraphNode*, int> intPath;
00704 intPath[n] = currint;
00705 currint++;
00706 std::map<SgGraphNode*, int> currents;
00707 SgGraphNode* currnode;
00708 bool step = false;
00709 bool midstep = false;
00710
00711
00712
00713 std::vector<std::vector<SgGraphNode*> > pth = pathsAtMk[realstartnode];
00714 std::vector<std::vector<SgGraphNode*> > cpth = pathsAtMk[realstartnode];
00715 path.clear();
00716 int disjoints = 0;
00717 int disjointtrues = 0;
00718 currpthorg = pth[0];
00719 intPath[pth[0].front()] = currint;
00720 std::set<SgGraphNode*> pthloopstmp;
00721 SgGraphNode* fakenode;
00722 pthloopstmp.insert(fakenode);
00723 std::vector<std::set<SgGraphNode*> > pthloops;
00724 pthloops.push_back(pthloopstmp);
00725 pthloopstmp.clear();
00726 currint++;
00727
00728 int stepnum = 0;
00729 std::vector<SgGraphNode*> rs;
00730 rs.push_back(realstartnode);
00731 path.push_back(rs);
00732 currents.clear();
00733
00734 step = false;
00735 std::vector<SgGraphNode*> sub;
00736
00737
00738 std::set<std::vector<SgGraphNode*> > nullIncLoops;
00739 std::vector<struct Bot*> todobotlst;
00740 std::vector<struct Bot*> botlst;
00741 struct Bot* rootBot = new Bot;
00742 rootBot->remove = false;
00743
00744 rootBot->path = path;
00745 rootBot->currpth = currpthorg;
00746 rootBot->pthloops = pthloops;
00747 rootBot->on = true;
00748 botlst.push_back(rootBot);
00749 int tip = 1;
00750 int ti = 1;
00751 std::vector<std::pair<std::vector<SgGraphNode*>, std::vector<std::set<SgGraphNode*> > > > collectedPaths;
00752 int maxlst = 0;
00753 while (true) {
00754 if (todobotlst.size()+botlst.size() > maxlst) {
00755 maxlst = todobotlst.size()+botlst.size();
00756 std::cout << "maxlst: " << maxlst << std::endl;
00757 std::cout << "todobotlst.size(): " << todobotlst.size() << std::endl;
00758 std::cout << "botlst.size(): " << botlst.size() << std::endl;
00759 }
00760 int MAXBOTS = 10000;
00761 int MINPATHS = 1000;
00762 int LOCALMAXBOTS = 10;
00763 int LOCALMAXNODES = 0;
00764 std::vector<struct Bot*> lstnullbot;
00765 std::vector<std::vector<struct Bot*> > newbotlsts (MAXBOTS, lstnullbot);
00766
00767
00768
00769 ROSE_ASSERT(botlst.size() >= 0);
00770 if (botlst.size() == 0) {
00771 if (todobotlst.size() != 0) {
00772 while (todobotlst.size() > 0 && botlst.size() < MAXBOTS) {
00773 todobotlst.back()->on = true;
00774 botlst.push_back(todobotlst.back());
00775 todobotlst.pop_back();
00776 }
00777 }
00778 else {
00779 if (collectedPaths.size() > 0) {
00780 for (int i = 0; i < collectedPaths.size(); i++) {
00781 std::set<std::vector<SgGraphNode*> > incloops;
00782 std::vector<std::set<SgGraphNode*> > pthloops = collectedPaths[i].second;
00783 for (int q = 0; q < pthloops.size(); q++) {
00784 for (std::set<SgGraphNode*>::iterator p = pthloops[q].begin(); p != pthloops[q].end(); p++) {
00785 for (std::set<std::vector<SgGraphNode*> >::iterator o = mkloopmap[*p].begin(); o != mkloopmap[*p].end(); o++) {
00786 incloops.insert(*o);
00787 }
00788 }
00789 }
00790
00791
00792 pathAnalyze(collectedPaths[i].first, false, incloops);
00793 }
00794 collectedPaths.clear();
00795 }
00796 break;
00797 }
00798 }
00799 if (botlst.size() > 0) {
00800 std::pair<std::vector<SgGraphNode*>, std::vector<std::set<SgGraphNode*> > > nullpr;
00801 std::vector<std::pair<std::vector<SgGraphNode*>, std::vector<std::set<SgGraphNode*> > > > newpathslst (MAXBOTS, nullpr);
00802 #pragma omp parallel for
00803 for (int i = 0; i < botlst.size(); i++) {
00804
00805 std::vector<struct Bot*> localbotlst;
00806 std::pair<std::vector<SgGraphNode*>, std::vector<std::set<SgGraphNode*> > > localnewpath;
00807 struct Bot* currBot = botlst[i];
00808 if (currBot->on) {
00809 std::vector<SgGraphNode*> currpth = currBot->currpth;
00810 std::vector<std::vector<SgGraphNode*> > path = currBot->path;
00811 std::vector<std::set<SgGraphNode*> > pthloops = currBot->pthloops;
00812
00813 if (currpth.back() == endnode) {
00814 path.push_back(currpth);
00815 std::vector<SgGraphNode*> flatpath;
00816 std::set<std::vector<SgGraphNode*> > incloops;
00817 struct timeval q1, q2;
00818 ROSE_ASSERT(path.size() == pthloops.size() + 1);
00819 q1 = getCPUTime();
00820 for (unsigned int q = 0; q < pthloops.size(); q++) {
00821 for (unsigned int r = 0; r < path[q].size(); r++) {
00822 flatpath.push_back(path[q][r]);
00823 }
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836 }
00837
00838 for (unsigned int pt2 = 0; pt2 < path[path.size()-1].size(); pt2++) {
00839 flatpath.push_back(path[path.size()-1][pt2]);
00840 }
00841 q2 = getCPUTime();
00842 fllp += timeDifference(q2,q1);
00843 flatpath.push_back(endnode);
00844
00845
00846
00847
00848
00849
00850
00851 std::pair<std::vector<SgGraphNode*> , std::vector<std::set<SgGraphNode*> > > newcol;
00852 newcol.first = flatpath;
00853 newcol.second = pthloops;
00854 localnewpath = newcol;
00855 incloops.clear();
00856
00857 int pts = pathsSize++;
00858 pathsSize += 1;
00859
00860 flatpath.clear();
00861 path.pop_back();
00862 int rounds = 0;
00863 bool starter = false;
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883 currBot->remove = true;
00884 localbotlst.push_back(currBot);
00885
00886 }
00887 else {
00888
00889
00890 bool disj = true;
00891 struct timeval tdisb, tdise;
00892
00893 for (int x = 0; x < pthloops.size(); x++) {
00894 for (std::set<SgGraphNode*>::iterator j = pthloops[x].begin(); j != pthloops[x].end(); j++) {
00895 if (find(currpth.begin(), currpth.end(), *j) != currpth.end()) {
00896 disj = false;
00897 }
00898 }
00899 }
00900
00901
00902 if (disj) {
00903
00904 disjointtrues++;
00905
00906 midstep = false;
00907 std::set<SgGraphNode*> pthloopstmp;
00908 pthloopstmp.clear();
00909 for (int i = 0; i < currpth.size(); i++) {
00910
00911 if (mkloops.find(currpth[i]) != mkloops.end()) {
00912 pthloopstmp.insert(currpth[i]);
00913 }
00914 }
00915 pthloops.push_back(pthloopstmp);
00916 path.push_back(currpth);
00917 pthloopstmp.clear();
00918
00919
00920 std::vector<SgGraphNode*> oldcurrpth = currpth;
00921 currpth.clear();
00922 SgGraphNode* frontnode = (path.back()).front();
00923 SgGraphNode* backnode = (path.back()).back();
00924
00925 ROSE_ASSERT(pathsAtMk.find(backnode) != pathsAtMk.end() || backnode == endnode);
00926 ROSE_ASSERT(pathsAtMk.find(frontnode) != pathsAtMk.end());
00927 std::vector<std::vector<SgGraphNode*> > tmppths = pathsAtMk[backnode];
00928 currBot->currpth = tmppths[0];
00929 currBot->path = path;
00930 currBot->pthloops = pthloops;
00931
00932 for (int tp = 1; tp < tmppths.size(); tp++) {
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943 struct Bot* newBot = new Bot;
00944 newBot->remove = false;
00945 newBot->currpth = tmppths[tp];
00946 newBot->path = path;
00947 newBot->pthloops = pthloops;
00948 localbotlst.push_back(newBot);
00949
00950
00951 }
00952 localbotlst.push_back(currBot);
00953
00954 }
00955 else {
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974 currBot->remove = true;
00975 localbotlst.push_back(currBot);
00976
00977
00978
00979 }
00980 }
00981 newpathslst[i] = localnewpath;
00982 newbotlsts[i] = localbotlst;
00983 }
00984 }
00985 botlst.clear();
00986 int num = 0;
00987
00988 for (int i = 0; i < newbotlsts.size(); i++) {
00989 if (newpathslst[i].first.size() > 0) {
00990 collectedPaths.push_back(newpathslst[i]);
00991 }
00992 for (int j = 0; j < newbotlsts[i].size(); j++) {
00993 if (newbotlsts[i][j]->remove == true) {
00994 delete newbotlsts[i][j];
00995 }
00996 else if (num < MAXBOTS) {
00997 newbotlsts[i][j]->on = true;
00998 botlst.push_back(newbotlsts[i][j]);
00999 num++;
01000 }
01001 else {
01002 newbotlsts[i][j]->on = false;
01003 todobotlst.push_back(newbotlsts[i][j]);
01004 }
01005 }
01006 }
01007
01008 if (collectedPaths.size() > MINPATHS) {
01009
01010 for (int i = 0; i < collectedPaths.size(); i++) {
01011 std::vector<std::set<SgGraphNode*> > pthloops;
01012 std::set<std::vector<SgGraphNode*> > incloops;
01013 pthloops = collectedPaths[i].second;
01014 for (int q = 0; q < pthloops.size(); q++) {
01015 for (std::set<SgGraphNode*>::iterator p = pthloops[q].begin(); p != pthloops[q].end(); p++) {
01016 for (std::set<std::vector<SgGraphNode*> >::iterator o = mkloopmap[*p].begin(); o != mkloopmap[*p].end(); o++) {
01017 incloops.insert(*o);
01018 }
01019 }
01020 }
01021
01022 pathAnalyze(collectedPaths[i].first, false, incloops);
01023 }
01024 collectedPaths.clear();
01025 }
01026 }
01027 else {
01028 if (collectedPaths.size() > 0) {
01029 for (int i = 0; i < collectedPaths.size(); i++) {
01030 std::set<std::vector<SgGraphNode*> > incloops;
01031 pthloops = collectedPaths[i].second;
01032 for (int q = 0; q < pthloops.size(); q++) {
01033 for (std::set<SgGraphNode*>::iterator p = pthloops[q].begin(); p != pthloops[q].end(); p++) {
01034 for (std::set<std::vector<SgGraphNode*> >::iterator o = mkloopmap[*p].begin(); o != mkloopmap[*p].end(); o++) {
01035 incloops.insert(*o);
01036 }
01037 }
01038 }
01039
01040 pathAnalyze(collectedPaths[i].first, false, incloops);
01041 }
01042 }
01043 collectedPaths.clear();
01044 break;
01045 }
01046 }
01047
01048 std::cout << "successes: " << successes << std::endl;
01049 std::cout << "failures: " << failures << std::endl;
01050 std::cout << "maxlst: " << maxlst << std::endl;
01051 return;
01052 }
01053
01054
01055
01056 template<class InheritedAttributeType, class SynthesizedAttributeType>
01057 void
01058 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01059 evaluatePaths(SgIncidenceDirectedGraph* g, SgGraphNode* realstartnode, SgGraphNode* endnode) {
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076 std::vector<std::vector<SgGraphNode*> > path;
01077 std::vector<SgGraphNode*> spath;
01078 SgGraphNode* n = realstartnode;
01079 int successes = 0;
01080 int failures = 0;
01081 int j = 0;
01082 std::vector<SgGraphNode*> currpth;
01083 int currint = 0;
01084 std::map<SgGraphNode*, int> intPath;
01085 intPath[n] = currint;
01086 currint++;
01087 std::map<SgGraphNode*, int> currents;
01088 SgGraphNode* currnode;
01089 bool step = false;
01090 bool midstep = false;
01091
01092
01093
01094 std::vector<std::vector<SgGraphNode*> > pth = pathsAtMk[realstartnode];
01095 std::vector<std::vector<SgGraphNode*> > cpth = pathsAtMk[realstartnode];
01096 path.clear();
01097 int disjoints = 0;
01098 int disjointtrues = 0;
01099 currpth = pth[0];
01100 intPath[pth[0].front()] = currint;
01101 std::set<SgGraphNode*> pthloopstmp;
01102 SgGraphNode* fakenode;
01103 pthloopstmp.insert(fakenode);
01104 std::vector<std::set<SgGraphNode*> > pthloops;
01105 pthloops.push_back(pthloopstmp);
01106 pthloopstmp.clear();
01107 currint++;
01108
01109 int stepnum = 0;
01110 std::vector<SgGraphNode*> rs;
01111 rs.push_back(realstartnode);
01112 path.push_back(rs);
01113
01114 currents.clear();
01115
01116 step = false;
01117
01118 std::vector<SgGraphNode*> sub;
01119
01120
01121
01122
01123
01124
01125 std::set<std::vector<SgGraphNode*> > nullIncLoops;
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144
01145
01146
01147
01148
01149
01150
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167 while (step == false) {
01168 stepnum++;
01169
01170 if (currpth.back() == endnode) {
01171 path.push_back(currpth);
01172
01173
01174
01175 std::vector<SgGraphNode*> flatpath;
01176
01177 std::set<std::vector<SgGraphNode*> > incloops;
01178 struct timeval q1, q2;
01179
01180
01181 ROSE_ASSERT(path.size() == pthloops.size() + 1);
01182 q1 = getCPUTime();
01183 for (unsigned int q = 0; q < pthloops.size(); q++) {
01184
01185
01186 for (unsigned int r = 0; r < path[q].size(); r++) {
01187 flatpath.push_back(path[q][r]);
01188 }
01189 for (std::set<SgGraphNode*>::iterator p = pthloops[q].begin(); p != pthloops[q].end(); p++) {
01190 for (std::set<std::vector<SgGraphNode*> >::iterator o = mkloopmap[*p].begin(); o != mkloopmap[*p].end(); o++) {
01191 incloops.insert(*o);
01192 }
01193 }
01194 }
01195 for (unsigned int pt2 = 0; pt2 < path[path.size()-1].size(); pt2++) {
01196 flatpath.push_back(path[path.size()-1][pt2]);
01197 }
01198
01199 q2 = getCPUTime();
01200 fllp += timeDifference(q2,q1);
01201 flatpath.push_back(endnode);
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212 pathAnalyze(flatpath, false, incloops);
01213 incloops.clear();
01214
01215
01216 int pts = pathsSize++;
01217 pathsSize += 1;
01218
01219 flatpath.clear();
01220 path.pop_back();
01221 int rounds = 0;
01222 bool starter = false;
01223
01224
01225
01226
01227
01228 while (true) {
01229 rounds++;
01230 ROSE_ASSERT(pathsAtMk.find((path.back()).back()) != pathsAtMk.end());
01231 if ((path.back()).front() == realstartnode) {
01232 starter = true;
01233 }
01234 if (currents[(path.back()).back()] < (pathsAtMk[(path.back()).back()].size()) ) {
01235 std::vector<std::vector<SgGraphNode*> > cpths = pathsAtMk[(path.back()).back()];
01236 currpth = cpths[currents[(path.back()).back()]];
01237 currents[(path.back()).back()]++;
01238 break;
01239 }
01240 else {
01241 currents[(path.back()).back()] = 0;
01242 path.pop_back();
01243 pthloops.pop_back();
01244 }
01245 if (starter == true) {
01246 step = true;
01247 break;
01248 }
01249
01250 }
01251 }
01252 else {
01253
01254
01255 bool disj = true;
01256 struct timeval tdisb, tdise;
01257 tdisb = getCPUTime();
01258 for (int i = 0; i < pthloops.size(); i++) {
01259 for (std::set<SgGraphNode*>::iterator j = pthloops[i].begin(); j != pthloops[i].end(); j++) {
01260 if (find(currpth.begin(), currpth.end(), *j) != currpth.end()) {
01261 disj = false;
01262 }
01263 }
01264 }
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279 tdise = getCPUTime();
01280 distime += timeDifference(tdise, tdisb);
01281 if (disj) {
01282
01283 disjointtrues++;
01284
01285 midstep = false;
01286 std::set<SgGraphNode*> pthloopstmp;
01287 pthloopstmp.clear();
01288 for (int i = 0; i < currpth.size(); i++) {
01289
01290 if (mkloops.find(currpth[i]) != mkloops.end()) {
01291 pthloopstmp.insert(currpth[i]);
01292 }
01293 }
01294 pthloops.push_back(pthloopstmp);
01295 path.push_back(currpth);
01296 pthloopstmp.clear();
01297
01298
01299 std::vector<SgGraphNode*> oldcurrpth = currpth;
01300 currpth.clear();
01301 if (currents.find((path.back()).back()) == currents.end()) {
01302 currents[(path.back()).back()] = 0;
01303 }
01304 SgGraphNode* frontnode = (path.back()).front();
01305 SgGraphNode* backnode = (path.back()).back();
01306
01307 ROSE_ASSERT(pathsAtMk.find(backnode) != pathsAtMk.end() || backnode == endnode);
01308 ROSE_ASSERT(pathsAtMk.find(frontnode) != pathsAtMk.end());
01309 if (currents.find(backnode) == currents.end()) {
01310 currents[backnode] = 0;
01311 }
01312 else {
01313 ROSE_ASSERT(currents[backnode] == 0);
01314 }
01315 std::vector<std::vector<SgGraphNode*> > tmppths = pathsAtMk[backnode];
01316
01317 currpth = tmppths[currents[backnode]];
01318 ROSE_ASSERT(currpth != oldcurrpth);
01319 currents[backnode]++;
01320 }
01321 else {
01322 disjoints++;
01323
01324
01325 while (true) {
01326 if (currents[(path.back()).back()] < pathsAtMk[(path.back()).back()].size() || path.back().back() == realstartnode) {
01327 break;
01328 }
01329 currents[(path.back()).back()] = 0;
01330 path.pop_back();
01331 pthloops.pop_back();
01332 }
01333 if ((path.back()).back() != realstartnode) {
01334 currpth = (pathsAtMk[(path.back()).back()])[currents[(path.back()).back()]];
01335 currents[(path.back()).back()]++;
01336 }
01337 else {
01338 step = true;
01339 }
01340 }
01341 }
01342 }
01343 std::cout << "successes: " << successes << std::endl;
01344 std::cout << "failures: " << failures << std::endl;
01345
01346 return;
01347 }
01348
01349
01350
01351
01352
01353
01354
01355 template<class InheritedAttributeType, class SynthesizedAttributeType>
01356 void
01357 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01358 printNodePlusEdgesForAnalysis(SgIncidenceDirectedGraph* g, SgGraphNode* n, int loopNum, int pathVal, std::ofstream& ss) {
01359 printNodeForAnalysis(n, loopNum, pathVal, ss);
01360 std::set<SgDirectedGraphEdge*> outEdges = g->computeEdgeSetOut(n);
01361 for (std::set<SgDirectedGraphEdge*>::iterator i = outEdges.begin(); i != outEdges.end(); i++) {
01362 if (nullEdgesOrdered.find(*i) == nullEdgesOrdered.end()) {
01363 printEdgeForAnalysis(*i, false, ss);
01364 }
01365 else {
01366 printEdgeForAnalysis(*i, true, ss);
01367 }
01368 }
01369 }
01370
01371 template<class InheritedAttributeType, class SynthesizedAttributeType>
01372 void
01373 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01374 printNodePlusEdgesForAnalysisPath(SgIncidenceDirectedGraph* g, std::vector<SgGraphNode*> n, int loopNum, int pathVal, std::ofstream& ss) {
01375 for (unsigned int i = 0; i < n.size()-1; i++) {
01376 if (completedNodesPath.find(n[i]) == completedNodesPath.end()) {
01377 printNodeForAnalysis(n[i], loopNum, pathVal, ss);
01378 completedNodesPath.insert(n[i]);
01379 }
01380 std::pair<SgGraphNode*, SgGraphNode*> prnod;
01381 prnod.first = n[i+1];
01382 prnod.second = n[i];
01383 if (completedEdgesPath.find(prnod) == completedEdgesPath.end()) {
01384 printEdgeForAnalysisPath(n[i+1], n[i], ss);
01385 completedEdgesPath.insert(prnod);
01386 }
01387 }
01388 if (completedNodesPath.find(n[n.size() - 1]) == completedNodesPath.end()) {
01389 printNodeForAnalysis(n[n.size()-1], loopNum, pathVal, ss);
01390 completedNodesPath.insert(n[n.size() - 1]);
01391 }
01392
01393 }
01394
01395
01396 template<class InheritedAttributeType, class SynthesizedAttributeType>
01397 void
01398 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01399 printNodeForAnalysis(SgGraphNode* n, int loopNum, int pathNum, std::ofstream &ss) {
01400 int id = n->get_index();
01401 std::string nodeColor = "black";
01402 if (loopNum != 0) {
01403 ss << id << " [label=\"" << "LoopNumS" << loopNum << "\", color=\"" << "green" << "\", style=\"" << "solid" << "\"];\n";
01404 }
01405 else {
01406 ss << id << " [label=\"" << "pathNumS" << pathNum << "\", color=\"" << "black" << "\", style=\"" << "dotted" << "\"];\n";
01407 }
01408
01409 }
01410 template<class InheritedAttributeType, class SynthesizedAttributeType>
01411 void
01412 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01413 printEdgeForAnalysis(SgDirectedGraphEdge* e, bool isNullEdge, std::ofstream &ss) {
01414 if (isNullEdge) {
01415 ss << e->get_from()->get_index() << " -> " << e->get_to()->get_index() << " [label=\"" << "NullEdge" << "\", style=\"" << "dotted" << "\"];\n";
01416 }
01417 else {
01418 ss << e->get_from()->get_index() << " -> " << e->get_to()->get_index() << " [label=\"" << "\", style=\"" << "solid" << "\"];\n";
01419 }
01420 }
01421 template<class InheritedAttributeType, class SynthesizedAttributeType>
01422 void
01423 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01424 printEdgeForAnalysisPath(SgGraphNode* g1, SgGraphNode* g2, std::ofstream &ss) {
01425 ss << g2->get_index() << " -> " << g1->get_index() << " [label=\"" << "Edge" << "\", style=\"" << "solid" << "\"];\n";
01426 }
01427
01428
01429
01430
01431
01432 template<class InheritedAttributeType, class SynthesizedAttributeType>
01433 void
01434 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01435 solvePaths(SgIncidenceDirectedGraph* g, SgGraphNode* n, SgGraphNode* endnode) {
01436 bool done = false;
01437 bool edges = true;
01438 bool tookone = false;
01439 std::vector<SgGraphNode*> mkpath;
01440 std::vector<SgGraphNode*> marks;
01441 marks.push_back(n);
01442 mkglobal.push_back(n);
01443 SgGraphNode* currn = n;
01444 SgGraphNode* took;
01445 std::set<SgDirectedGraphEdge*> taken;
01446 std::vector<SgGraphNode*> toTake;
01447 std::vector<SgGraphNode*> path;
01448 path.push_back(n);
01449 mkpath.push_back(n);
01450 int itr = 0;
01451 int bifurcations = 0;
01452 std::map<SgGraphNode*, bool> completed;
01453 while (done == false) {
01454 ROSE_ASSERT(currn != NULL);
01455
01456 if (currn == endnode || completed.find(currn) != completed.end()) {
01457 if (pathsAtMk.find(marks.back()) == pathsAtMk.end()) {
01458 std::vector<std::vector<SgGraphNode*> > emptypath;
01459 pathsAtMk[marks.back()] = emptypath;
01460 }
01461 edges = false;
01462 pathsAtMk[marks.back()].push_back(mkpath);
01463
01464
01465
01466
01467
01468
01469 ROSE_ASSERT(mkpath.front() == marks.back());
01470 if (marks.size() == 0) {
01471 return;
01472 }
01473 mkpath.clear();
01474 bool y = true;
01475 bool haventtaken = false;
01476 bool p = true;
01477 int place;
01478 bool found = false;
01479 while (found == false) {
01480 if (marks.size() == 0) {
01481 return;
01482 }
01483 SgDirectedGraphEdge* tooked;
01484 SgGraphNode* mark1 = marks.back();
01485 std::set<SgDirectedGraphEdge*> oedg = g->computeEdgeSetOut(mark1);
01486 ROSE_ASSERT(oedg.size() > 1 || mark1 == n);
01487 for (std::set<SgDirectedGraphEdge*>::iterator j = oedg.begin(); j != oedg.end(); j++) {
01488 if (taken.find(*j) == taken.end() && haventtaken == false) {
01489 tooked = *j;
01490 haventtaken = true;
01491 }
01492 }
01493 if (haventtaken == true) {
01494 if (marks.back() == n) {
01495 path.clear();
01496 }
01497 path.push_back(marks.back());
01498 if ( mkpath.empty() || (mkpath.back() != marks.back()) ) {
01499 ROSE_ASSERT(!marks.empty());
01500 mkpath.push_back(marks.back());
01501 }
01502 taken.insert(tooked);
01503 took = tooked->get_to();
01504 found = true;
01505 }
01506 else {
01507 completed[marks.back()] = true;
01508 bifurcations++;
01509 marks.pop_back();
01510 }
01511 }
01512 if (marks.size() == 0) {
01513 return;
01514 }
01515 haventtaken = false;
01516 found = false;
01517
01518 }
01519
01520 else {
01521 std::set<SgDirectedGraphEdge*> oedg = g->computeEdgeSetOut(currn);
01522 std::set<SgDirectedGraphEdge*> iedg = g->computeEdgeSetIn(currn);
01523 if (oedg.size() > 1) {
01524 if (mkpath.back() != currn) {
01525 mkpath.push_back(currn);
01526 }
01527 pathsAtMk[marks.back()].push_back(mkpath);
01528 mkpath.clear();
01529 mkpath.push_back(currn);
01530 marks.push_back(currn);
01531 if (find(mkglobal.begin(), mkglobal.end(), currn) == mkglobal.end()) {
01532 mkglobal.push_back(currn);
01533 }
01534 for (std::set<SgDirectedGraphEdge*>::iterator i = oedg.begin(); i != oedg.end(); i++) {
01535 if (taken.find(*i) == taken.end() && tookone == false) {
01536 taken.insert(*i);
01537 tookone = true;
01538 took = (*i)->get_to();
01539 }
01540 else if (taken.find(*i) == taken.end() && tookone == true) {
01541
01542 }
01543 }
01544 tookone = false;
01545 }
01546 else {
01547 took = (*(oedg.begin()))->get_to();
01548 }
01549 }
01550 itr++;
01551
01552 if (find(path.begin(), path.end(), took) == path.end()) {
01553 mkpath.push_back(took);
01554 path.push_back(took);
01555 currn = took;
01556 }
01557 else {
01558 mkloops.insert(took);
01559 std::vector<SgGraphNode*> lptemp;
01560 lptemp.clear();
01561 lptemp.push_back(took);
01562 while (path.back() != took) {
01563
01564 path.pop_back();
01565
01566 lptemp.push_back(path.back());
01567
01568 }
01569 (mkloopmap[took]).insert(lptemp);
01570
01571
01572
01573
01574
01575
01576
01577
01578
01579
01580
01581 path.push_back(took);
01582 currn = path.back();
01583 mkpath.push_back(took);
01584 }
01585
01586
01587 }
01588 return;
01589 }
01590
01591
01592 template <class InheritedAttributeType, class SynthesizedAttributeType>
01593 SynthesizedAttributeType
01594 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01595 defaultSynthesizedAttribute(InheritedAttributeType inh)
01596 {
01597 SynthesizedAttributeType s = SynthesizedAttributeType();
01598 return s;
01599 }
01600
01601
01602
01603
01604 template <class InheritedAttributeType, class SynthesizedAttributeType>
01605 void
01606 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01607 computeOrder(SgIncidenceDirectedGraph* g, SgGraphNode* n, SgGraphNode* endnode) {
01608 std::map<SgGraphNode*, int> incomputables;
01609 std::set<SgGraphNode*> lpposs;
01610
01611 SgGraphNode* currn;
01612 currn = n;
01613 int orders = 0;
01614 while (true) {
01615 if (orders % 10000 == 0) {
01616 std::cout << "orders: " << orders << std::endl;
01617 }
01618 orders++;
01619 if (currn == endnode) {
01620 }
01621 if (computable(g, currn) || currn == n) {
01622 int mp;
01623 if (oVals.find(currn) == oVals.end()) {
01624 oVals[currn] = currm++;
01625 iVals[currm++] = currn;
01626 currm += 1;
01627 }
01628 if (currn == endnode) {
01629
01630 break;
01631 }
01632 std::pair<bool, SgGraphNode*> pbs = getNextChild(g, currn);
01633 computedNodes.insert(currn);
01634 ROSE_ASSERT(pbs.first == true);
01635 currn = pbs.second;
01636 }
01637 else {
01638 std::pair<bool, SgGraphNode*> pbp = getNextPar(g, currn);
01639 ROSE_ASSERT(pbp.first == true);
01640 currn = pbp.second;
01641
01642 }
01643
01644 }
01645 std::cout << "required orders" << orders << std::endl;
01646 std::cout << "incomputables.size() " << incomputables.size() << std::endl;
01647 }
01648
01649
01650 template <class InheritedAttributeType, class SynthesizedAttributeType>
01651 bool
01652 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01653 computable(SgIncidenceDirectedGraph* g, SgGraphNode* n) {
01654 if (computedNodes.find(n) != computedNodes.end()) {
01655 return true;
01656 }
01657 std::set<SgDirectedGraphEdge*> ed = g->computeEdgeSetIn(n);
01658 bool comp = true;
01659 for (std::set<SgDirectedGraphEdge*>::iterator i = ed.begin(); i != ed.end(); i++) {
01660 if (oVals.find((*i)->get_from()) == oVals.end() && nullEdgesOrdered.find(*i) == nullEdgesOrdered.end()) {
01661 comp = false;
01662 }
01663 }
01664 return comp;
01665 }
01666
01667
01668
01669
01670 template <class InheritedAttributeType, class SynthesizedAttributeType>
01671 void
01672 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01673 computeInheritedOrdered(SgIncidenceDirectedGraph* g, SgGraphNode* n) {
01674 int runs = 0;
01675
01676
01677
01678 for (std::map<int, SgGraphNode*>::iterator i = iVals.begin(); i != iVals.end(); i++) {
01679 runs++;
01680 ROSE_ASSERT(canEval(g, (*i).second));
01681 setPathVal(g, n);
01682
01683 evalNodeOrdered(g, (*i).second);
01684 }
01685 }
01686
01687
01688 template <class InheritedAttributeType, class SynthesizedAttributeType>
01689 bool
01690 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01691 canEval(SgIncidenceDirectedGraph* g, SgGraphNode* n) {
01692 bool evaled = true;
01693 if (inhVals.find(n) == inhVals.end()) {
01694 std::set<SgDirectedGraphEdge*> ins = g->computeEdgeSetIn(n);
01695 for (std::set<SgDirectedGraphEdge*>::iterator i = ins.begin(); i != ins.end(); i++) {
01696 if (inhVals.find((*i)->get_from()) == inhVals.end() && nullEdgesOrdered.find(*i) == nullEdgesOrdered.end()) {
01697 evaled = false;
01698 }
01699 }
01700 }
01701 return evaled;
01702 }
01703
01704
01705
01706 template <class InheritedAttributeType, class SynthesizedAttributeType>
01707 void
01708 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01709 evalNodeOrdered(SgIncidenceDirectedGraph* g, SgGraphNode* n) {
01710 if (inhVals.find(n) != inhVals.end()) {
01711 return;
01712 }
01713 std::set<SgDirectedGraphEdge*> par = g->computeEdgeSetIn(n);
01714 std::vector<InheritedAttributeType> inh;
01715 for (std::set<SgDirectedGraphEdge*>::iterator i = par.begin(); i != par.end(); i++) {
01716 if (inhVals.find((*i)->get_from()) != inhVals.end()) {
01717 inh.push_back(inhVals[(*i)->get_from()]);
01718 }
01719 }
01720
01721 if (n != st || inh.size() > 0) {
01722 InheritedAttributeType inhX;
01723 inhX = evaluateInheritedAttribute(n, inh);
01724 inhVals[n] = inhX;
01725 }
01726
01727
01728 }
01729
01730
01731
01732 template <class InheritedAttributeType, class SynthesizedAttributeType>
01733 void
01734 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01735 setPathVal(SgIncidenceDirectedGraph* g, SgGraphNode* currn) {
01736 if (pathValMap.find(currn) != pathValMap.end()) {
01737 return;
01738 }
01739 std::set<SgDirectedGraphEdge*> ined = g->computeEdgeSetIn(currn);
01740 int tmppathcount = 0;
01741 for (std::set<SgDirectedGraphEdge*>::iterator i = ined.begin(); i != ined.end(); i++) {
01742 ROSE_ASSERT(pathValMap.find((*i)->get_from()) != pathValMap.end() );
01743
01744
01745
01746 int pv = pathValMap[(*i)->get_from()];
01747 if (pv != 0) {
01748 tmppathcount += pv;
01749 }
01750 }
01751 pathValMap[currn] = tmppathcount;
01752 return;
01753 }
01754
01755
01756 template <class InheritedAttributeType, class SynthesizedAttributeType>
01757 std::pair<bool, SgGraphNode*>
01758 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01759 getNextChild(SgIncidenceDirectedGraph* g, SgGraphNode* n) {
01760 bool nullPoss = false;
01761
01762 std::set<SgDirectedGraphEdge*> outs = g->computeEdgeSetOut(n);
01763
01764
01765 SgGraphNode* nextNode;
01766 SgGraphNode* nullNode;
01767 bool completed = false;
01768 bool completeNull = false;
01769
01770 for (std::set<SgDirectedGraphEdge*>::iterator i = outs.begin(); i != outs.end(); i++) {
01771
01772 if (outs.size() == 1) {
01773 nextNode = (*i)->get_to();
01774 if (nullEdgesOrdered.find(*i) != nullEdgesOrdered.end()) {
01775 nullNum++;
01776 }
01777
01778 completed = true;
01779 }
01780 else if (completed == false && computedNodes.find((*i)->get_to()) == computedNodes.end()) {
01781 completed = true;
01782 nextNode = (*i)->get_to();
01783 if (nullEdgesOrdered.find(*i) != nullEdgesOrdered.end()) {
01784 nullNum++;
01785 }
01786 completedEdgesOut.insert(*i);
01787 }
01788
01789
01790 }
01791 std::pair<bool, SgGraphNode*> pr;
01792 ROSE_ASSERT (completed == true || completeNull == true);
01793 if (completed == true) {
01794 pr.first = completed;
01795 pr.second = nextNode;
01796 return pr;
01797 }
01798 else {
01799 pr.first = true;
01800 pr.second = nullNode;
01801 return pr;
01802 }
01803
01804 }
01805
01806
01807 template <class InheritedAttributeType, class SynthesizedAttributeType>
01808 std::pair<bool, SgGraphNode*>
01809 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01810 getNextPar(SgIncidenceDirectedGraph* g, SgGraphNode* n) {
01811 std::set<SgDirectedGraphEdge*> ins = g->computeEdgeSetIn(n);
01812 SgGraphNode* nextPar;
01813 SgDirectedGraphEdge* nullEdgeO;
01814 bool completed = false;
01815 bool completeNull = false;
01816 for (std::set<SgDirectedGraphEdge*>::iterator i = ins.begin(); i != ins.end(); i++) {
01817
01818 if (ins.size() == 1 ) {
01819 completed = true;
01820 completedEdges.insert(*i);
01821 nextPar = (*i)->get_from();
01822 }
01823
01824 else if (completedEdges.find(*i) == completedEdges.end() && completed == false) {
01825 completed = true;
01826 nextPar = (*i)->get_from();
01827 completedEdges.insert(*i);
01828 }
01829
01830 else if (completedEdges.find(*i) != completedEdges.end() && computedNodes.find((*i)->get_from()) == computedNodes.end() && completed == false ) {
01831 completeNull = true;
01832 std::pair<SgGraphNode*, SgGraphNode*> lpp;
01833 nextPar = n;
01834 nullEdgesOrdered.insert(*i);
01835 nullEdgesPaths++;
01836
01837 }
01838 }
01839 ROSE_ASSERT(completed == true || completeNull == true);
01840 std::pair<bool, SgGraphNode*> pr;
01841 pr.first = completed;
01842 pr.second = nextPar;
01843
01844 if (completeNull == true && completed == false) {
01845 pr.first = completeNull;
01846 pr.second = nextPar;
01847 }
01848
01849 return pr;
01850 }
01851
01852
01853
01854
01855
01856
01857
01858
01859
01860
01861
01862
01863
01864
01865