Debian Codegraph @

lib/mlrisc-lib/MLRISC/IR/mlrisc-liveness.sml

raw
1 (*
2 * This module performs liveness analysis.
3 * It is implemented by instantiating the data flow analyzer module.
4 *
5 * -- Allen
6 *)
7
8 signature LIVENESS_ANALYSIS =
9 sig
10
11 structure CFG : CONTROL_FLOW_GRAPH
12 structure I : INSTRUCTIONS
13 sharing CFG.I = I
14
15 val liveness :
16 { cfg : CFG.cfg,
17 liveOut : CFG.block Graph.node -> I.C.cell list,
18 defUse : CFG.block Graph.node -> I.C.cell list * I.C.cell list,
19 result : {block: CFG.block Graph.node,
20 liveIn: I.C.cell list, liveOut: I.C.cell list} -> unit
21 } -> unit
22
23 end
24
25 functor LivenessAnalysis(CFG : CONTROL_FLOW_GRAPH) : LIVENESS_ANALYSIS =
26 struct
27
28 structure CFG = CFG
29 structure I = CFG.I
30 structure C = I.C
31 structure A = Annotations
32 structure SL = C.SortedCells
33 structure G = Graph
34
35 structure Liveness =
36 Dataflow
37 (struct
38 structure CFG = CFG
39 type domain = SL.sorted_cells
40 val forward = false
41 val bot = SL.empty
42 val == = SL.eq
43 val join = List.foldr SL.union SL.empty
44 val op + = SL.union
45 val op - = SL.difference
46 type dataflow_info =
47 { liveOut : CFG.block Graph.node -> C.cell list,
48 defUse : CFG.block Graph.node ->
49 C.cell list * C.cell list,
50 result : {block: CFG.block Graph.node,
51 liveIn: I.C.cell list,
52 liveOut: I.C.cell list} -> unit
53 }
54
55 fun prologue(cfg,{defUse,liveOut,...}:dataflow_info) (b,b') =
56 let val (def,use) = defUse(b,b')
57 val def = SL.uniq def
58 val use = SL.uniq use
59 val live_out = SL.uniq(liveOut(b,b'))
60 in { input = live_out,
61 output = (live_out - def) + use,
62 transfer = fn live_out => (live_out - def) + use
63 }
64 end
65
66 fun epilogue(cfg,{result, ...}:dataflow_info)
67 { node, input=liveOut, output=liveIn } =
68 result{block=node, liveIn=SL.return liveIn,
69 liveOut=SL.return liveOut}
70 end
71 )
72
73 fun liveness {cfg,liveOut,defUse,result} =
74 (Liveness.analyze(cfg, {liveOut=liveOut,defUse=defUse,result=result});
75 ()
76 )
77
78 end