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 475 - (view) (download)
Original Path: sml/branches/SMLNJ/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 :     DataflowFn
25 :     (structure CFG = CFG
26 :     type domain = R.typemap
27 :     val forward = false
28 :     val bot = R.empty
29 :     val == = R.==
30 :     val join = R.meets
31 :     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 :     fun liveOut(gcmap,regmap,b) =
39 :     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 :     val d' = mk(gcmap,regmap,d1 @ d2)
53 :     val u' = mk(gcmap,regmap,u1 @ u2)
54 :     val use = R.gen(R.kill(use,d'),u')
55 :     val def = R.kill(R.gen(def,d'),u')
56 :     in loop(is,def,use)
57 :     end
58 :     in loop(!insns,R.empty,R.empty) end
59 :    
60 :     fun prologue (_,(gcmap,regmap,_)) (b,b') =
61 :     let val (def,use) = scan(gcmap,regmap,b')
62 :     val liveOut = liveOut(gcmap,regmap,b')
63 :     in { input = liveOut,
64 :     output = R.gen(R.kill(liveOut,def),use),
65 :     transfer = fn liveOut => R.gen(R.kill(liveOut,def),use)
66 :     }
67 :     end
68 :     fun epilogue (_,(_,_,table))
69 :     {node=(b,_), input=liveOut, output=liveIn } =
70 :     A.update(table,b,{liveIn=liveIn,liveOut=liveOut})
71 :     )
72 :    
73 :     fun liveness (IR as G.GRAPH cfg) =
74 :     let val an = CFG.getAnnotations IR
75 : monnier 475 val gcmap = #lookup GCMap.GCMAP (CFG.getAnnotations IR)
76 : monnier 427 val regmap = CFG.regmap IR
77 :     val table = A.array(#capacity cfg (),{liveIn=R.empty,liveOut=R.empty})
78 :     val gclookup = Intmap.mapWithDefault (gcmap,GC.TOP)
79 :     val _ = Liveness.analyze(IR,(gclookup,C.lookup regmap,table))
80 :     in table
81 :     end
82 :    
83 :     end

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