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 2126 - (view) (download)

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

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