Debian Codegraph @

lib/mlrisc-lib/MLRISC/ir-archive/test2.sml

raw
1 (*
2 * This example is from the paper
3 * ``A New Frameowrk for Elimination Based Data Flow Analysis using DJ Graphs''
4 * By Sreedhar et. al.
5 *)
6 structure TestDJDataflow =
7 struct
8 structure Graph = Graph;
9 val CFG as Graph.GRAPH cfg = DirectedGraph.graph("cfg",(),10) :
10 (string,unit,unit) Graph.graph
11 structure Viewer = GraphViewer(AllDisplays)
12 structure L = GraphLayout
13 structure Dom = DominatorTree(DirectedGraph)
14 structure DJ = DJGraph(Dom)
15 structure Dataflow = DJDataflow(Dom)
16
17 val _ = app (#add_node cfg)
18 [(0,"0"),
19 (1,"1"),
20 (2,"2"),
21 (3,"3"),
22 (4,"4"),
23 (5,"5"),
24 (6,"6"),
25 (7,"7"),
26 (8,"8"),
27 (9,"9")
28 ]
29 val _ = #set_entries cfg [0]
30 val _ = #set_exits cfg [9]
31 val _ = app (#add_edge cfg)
32 [(0,1,()),
33 (1,2,()),
34 (2,3,()),
35 (2,8,()),
36 (3,4,()),
37 (3,5,()),
38 (4,6,()),
39 (4,9,()),
40 (5,6,()),
41 (6,2,()),
42 (6,7,()),
43 (7,9,()),
44 (8,1,()),
45 (8,9,()),
46 (9,0,())
47 ]
48
49 val Dom = Dom.makeDominator CFG
50
51 fun viewCFG _ =
52 Viewer.view(L.makeLayout
53 {graph = fn _ => [],
54 node = fn (i,_) => [L.LABEL(Int.toString i)],
55 edge = fn (i,j,_) => [L.COLOR "red"]
56 } CFG)
57 fun viewDom _ =
58 Viewer.view(L.makeLayout
59 {graph = fn _ => [],
60 node = fn (i,_) => [L.LABEL(Int.toString i)],
61 edge = fn (i,j,_) => [L.COLOR "red"]
62 } Dom)
63 fun viewDJ _ =
64 let fun iso kind G =
65 IsomorphicGraphView.map (fn x => x) (fn x => kind) (fn g => ()) G
66 val idom = Dom.immediately_dominates Dom
67 val Dom = iso [L.COLOR "red"] Dom
68 val CFG = iso [L.COLOR "green"] CFG
69 val CFG' = SubgraphView.subgraph_view
70 (map #1 (#nodes cfg ()))
71 (fn (i,j,_) => not(idom(i,j))) CFG
72 val DJ = UnionGraphView.union_view (fn _ => ()) (Dom,CFG')
73 in Viewer.view(L.makeLayout
74 {graph = fn _ => [],
75 node = fn (i,_) => [L.LABEL(Int.toString i)],
76 edge = fn (i,j,e) => e
77 } DJ)
78 end
79
80 fun testDataflow() =
81 let fun closure{y} = print("Closure "^Int.toString y^"\n")
82 fun var_elim{y,z} = print("Variable elim "^Int.toString y^
83 "->"^Int.toString z^"\n")
84 fun fixpoint{scc} = ()
85 fun compute{y,z} = ()
86 in Dataflow.analyze{closure=closure, var_elim=var_elim,
87 fixpoint=fixpoint, compute=compute} Dom
88 end
89
90 end
91