Debian Codegraph @

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

raw
1 functor LocalCriticalPath
2 (DDG : SCHEDULER_DDG) : SCHEDULING_RANKS where type edge = DDG.latency =
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.latency
11
12 fun rank(DDG as G.GRAPH ddg) =
13 let val N = #capacity ddg ()
14 val len = A.array(N,0)
15 val parents = A.tabulate(N,fn i => length(#in_edges ddg i))
16 fun process i =
17 let fun g((i,j,l)::es,n) = g(es,Int.max(A.sub(len,j) + l + 1,n))
18 | g([],n) = n
19 in A.update(len,i,g(#out_edges ddg i,0))
20 end
21 fun order((i,_),(j,_)) =
22 case Int.compare(A.sub(len,i),A.sub(len,j)) of
23 EQUAL => A.sub(parents,i) > A.sub(parents,j)
24 | LESS => false
25 | GREATER => true
26 in app process (rev (GraphTopsort.topsort DDG (map #1 (#nodes ddg ()))));
27 order
28 end
29
30 end