Debian Codegraph @

lib/mlrisc-lib/MLRISC/scheduling/globalCP.sml

raw
1 functor GlobalCriticalPath
2 (DDG : SCHEDULER_DDG) : SCHEDULING_RANKS where type edge = DDG.edge =
3 struct
4
5 structure DDG = DDG
6 structure I = DDG.I
7 structure G = Graph
8 structure A = Array
9
10 type edge = DDG.edge
11
12 fun rank(DDG as G.GRAPH ddg) =
13 let val N = #capacity ddg ()
14 val len = A.array(N,0)
15 val children = A.tabulate(N,fn i => length(#out_edges ddg i))
16 fun process i =
17 let fun g((i,j,DDG.EDGE{l,...})::es,n) =
18 g(es,Int.max(A.sub(len,j) + l + 1,n))
19 | g([],n) = n
20 in A.update(len,i,g(#out_edges ddg i,0))
21 end
22 fun order((i,_),(j,_)) =
23 case Int.compare(A.sub(len,i),A.sub(len,j)) of
24 EQUAL => A.sub(children,i) > A.sub(children,j)
25 | LESS => false
26 | GREATER => true
27 in app process (rev (GraphTopsort.topsort DDG (map #1 (#nodes ddg ()))));
28 order
29 end
30
31 end