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 469 - (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 :     structure GC : GC_TYPE
7 :     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 :     structure GC = GC
16 :     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 :     fun error msg = MLRiscErrorMsg.error("GCLiveness",msg)
24 :    
25 :     structure Liveness =
26 :     DataflowFn
27 :     (structure CFG = CFG
28 :     type domain = R.typemap
29 :     val forward = false
30 :     val bot = R.empty
31 :     val == = R.==
32 :     val join = R.meets
33 :     type dataflow_info =
34 :     (C.cell -> GC.gctype) *
35 :     (C.cell -> C.cell) *
36 :     { liveIn : R.typemap, liveOut : R.typemap } A.array
37 :     fun mk(gcmap,regmap,regs) =
38 :     R.fromList(map (fn r => (regmap r,gcmap r)) regs)
39 :    
40 :     fun liveOut(gcmap,regmap,b) =
41 :     let val cellset = CFG.liveOut(b)
42 :     val regs = C.cellsetToCells cellset
43 :     in mk(gcmap,regmap,regs)
44 :     end
45 :    
46 :     val defUseR = InsnProps.defUse C.GP
47 :     val defUseF = InsnProps.defUse C.FP
48 :    
49 :     fun scan(gcmap,regmap,CFG.BLOCK{insns,...}) =
50 :     let fun loop([],def,use) = (def,use)
51 :     | loop(i::is,def,use) =
52 :     let val (d1,u1) = defUseR i
53 :     val (d2,u2) = defUseF i
54 :     val d' = mk(gcmap,regmap,d1 @ d2)
55 :     val u' = mk(gcmap,regmap,u1 @ u2)
56 :     val use = R.gen(R.kill(use,d'),u')
57 :     val def = R.kill(R.gen(def,d'),u')
58 :     in loop(is,def,use)
59 :     end
60 :     in loop(!insns,R.empty,R.empty) end
61 :    
62 :     fun prologue (_,(gcmap,regmap,_)) (b,b') =
63 :     let val (def,use) = scan(gcmap,regmap,b')
64 :     val liveOut = liveOut(gcmap,regmap,b')
65 :     in { input = liveOut,
66 :     output = R.gen(R.kill(liveOut,def),use),
67 :     transfer = fn liveOut => R.gen(R.kill(liveOut,def),use)
68 :     }
69 :     end
70 :     fun epilogue (_,(_,_,table))
71 :     {node=(b,_), input=liveOut, output=liveIn } =
72 :     A.update(table,b,{liveIn=liveIn,liveOut=liveOut})
73 :     )
74 :    
75 :     fun liveness (IR as G.GRAPH cfg) =
76 :     let val an = CFG.getAnnotations IR
77 : monnier 469 val gcmap = case #get GC.GCMAP (CFG.getAnnotations IR) of
78 :     SOME gcmap => gcmap
79 :     | NONE => error "no gc map"
80 : monnier 427 val regmap = CFG.regmap IR
81 :     val table = A.array(#capacity cfg (),{liveIn=R.empty,liveOut=R.empty})
82 :     val gclookup = Intmap.mapWithDefault (gcmap,GC.TOP)
83 :     val _ = Liveness.analyze(IR,(gclookup,C.lookup regmap,table))
84 :     in table
85 :     end
86 :    
87 :     end

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