2 #include "graphSorting.hh"
5 * Set the order of a loop and place it to appropriate set
7 static void setOrder(Loop
* l
, int order
, lgraph
& V
)
11 if (l
->fOrder
>= 0) { V
[l
->fOrder
].erase(l
); }
12 l
->fOrder
= order
; V
[order
].insert(l
);
16 * Set the order of T1's loops and collect there sons into T2
18 static void setLevel(int order
, const lset
& T1
, lset
& T2
, lgraph
& V
)
20 for (lset::const_iterator p
= T1
.begin(); p
!=T1
.end(); p
++) {
21 setOrder(*p
, order
, V
);
22 T2
.insert((*p
)->fBackwardLoopDependencies
.begin(), (*p
)->fBackwardLoopDependencies
.end());
27 static void resetOrder(Loop
* l
)
30 for (lset::const_iterator p
= l
->fBackwardLoopDependencies
.begin(); p
!=l
->fBackwardLoopDependencies
.end(); p
++) {
35 * Topological sort of an acyclic graph of loops. The loops
36 * are collect in an lgraph : a vector of sets of loops
38 void sortGraph(Loop
* root
, lgraph
& V
)
45 T1
.insert(root
); level
=0; V
.clear();
47 setLevel(level
, T1
, T2
, V
);
48 T1
=T2
; T2
.clear(); level
++;
49 } while (T1
.size()>0);
52 lgraph::iterator p
= V
.begin();
53 while (p
!= V
.end()) {
54 if ((*p
).size() == 1 && (*(*p
).begin())->isEmpty()) {