Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /MLRISC/trunk/gc-safety/gc-liveness.sml
ViewVC logotype

Annotation of /MLRISC/trunk/gc-safety/gc-liveness.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 651 - (view) (download)
Original Path: sml/trunk/src/MLRISC/gc-safety/gc-liveness.sml

1 : monnier 427 (*
2 :     * Compute typed liveness information for garbage collection safety
3 :     *)
4 :     functor GCLiveness
5 :     (structure IR : MLRISC_IR
6 : monnier 475 structure GCMap : GC_MAP
7 : monnier 427 structure InsnProps : INSN_PROPERTIES
8 :     sharing InsnProps.I = IR.I
9 :     ) : GC_LIVENESS =
10 :     struct
11 :    
12 :     structure IR = IR
13 :     structure C = IR.I.C
14 :     structure CFG = IR.CFG
15 : monnier 475 structure GC = GCMap.GC
16 : monnier 427 structure G = Graph
17 :     structure GCTypeMap =
18 :     GCTypeMap(structure C = C
19 :     structure GC = GC)
20 :     structure R = GCTypeMap
21 :     structure A = Array
22 :    
23 :     structure Liveness =
24 : george 545 Dataflow
25 : monnier 427 (structure CFG = CFG
26 :     type domain = R.typemap
27 :     val forward = false
28 :     val bot = R.empty
29 :     val == = R.==
30 : monnier 498 val join = R.joins
31 : monnier 427 type dataflow_info =
32 :     (C.cell -> GC.gctype) *
33 :     (C.cell -> C.cell) *
34 :     { liveIn : R.typemap, liveOut : R.typemap } A.array
35 :     fun mk(gcmap,regmap,regs) =
36 :     R.fromList(map (fn r => (regmap r,gcmap r)) regs)
37 :    
38 : monnier 498 fun liveOut(gcmap,regmap,b as CFG.BLOCK{id,...}) =
39 : monnier 427 let val cellset = CFG.liveOut(b)
40 :     val regs = C.cellsetToCells cellset
41 :     in mk(gcmap,regmap,regs)
42 :     end
43 :    
44 :     val defUseR = InsnProps.defUse C.GP
45 :     val defUseF = InsnProps.defUse C.FP
46 :    
47 :     fun scan(gcmap,regmap,CFG.BLOCK{insns,...}) =
48 :     let fun loop([],def,use) = (def,use)
49 :     | loop(i::is,def,use) =
50 :     let val (d1,u1) = defUseR i
51 :     val (d2,u2) = defUseF i
52 : monnier 498 val d = mk(gcmap,regmap,d1 @ d2)
53 :     val u = mk(gcmap,regmap,u1 @ u2)
54 :     (* val _ = print("d="^R.toString d^" ")
55 :     val _ = print("u="^R.toString u^"\n")
56 :     val _ = print("use-d="^R.toString(R.kill(use,d))^"\n")*)
57 :     val use = R.gen(R.kill(use,d),u)
58 :     val def = R.kill(R.gen(def,d),u)
59 :     (*val _ = print("def="^R.toString def^" ")
60 :     val _ = print("use="^R.toString use^"\n") *)
61 : monnier 427 in loop(is,def,use)
62 :     end
63 :     in loop(!insns,R.empty,R.empty) end
64 :    
65 :     fun prologue (_,(gcmap,regmap,_)) (b,b') =
66 :     let val (def,use) = scan(gcmap,regmap,b')
67 :     val liveOut = liveOut(gcmap,regmap,b')
68 : monnier 498 in (* print("Liveout("^Int.toString b^")="^R.toString liveOut^"\n");
69 :     print("def("^Int.toString b^")="^R.toString def^"\n");
70 :     print("use("^Int.toString b^")="^R.toString use^"\n"); *)
71 :     { input = liveOut,
72 : monnier 427 output = R.gen(R.kill(liveOut,def),use),
73 :     transfer = fn liveOut => R.gen(R.kill(liveOut,def),use)
74 :     }
75 :     end
76 :     fun epilogue (_,(_,_,table))
77 :     {node=(b,_), input=liveOut, output=liveIn } =
78 : monnier 498 ((* print("Livein("^Int.toString b^")="^R.toString liveIn^"\n");
79 :     print("Liveout("^Int.toString b^")="^R.toString liveOut^"\n");*)
80 : monnier 427 A.update(table,b,{liveIn=liveIn,liveOut=liveOut})
81 : monnier 498 )
82 : monnier 427 )
83 :    
84 :     fun liveness (IR as G.GRAPH cfg) =
85 : leunga 624 let val an = !(CFG.annotations IR)
86 :     val gcmap = #lookup GCMap.GCMAP an
87 : monnier 427 val regmap = CFG.regmap IR
88 :     val table = A.array(#capacity cfg (),{liveIn=R.empty,liveOut=R.empty})
89 :     val gclookup = Intmap.mapWithDefault (gcmap,GC.TOP)
90 :     val _ = Liveness.analyze(IR,(gclookup,C.lookup regmap,table))
91 :     in table
92 :     end
93 :    
94 :     end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0