Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /trunk/src/compiler/IL/census-fn.sml
ViewVC logotype

Annotation of /trunk/src/compiler/IL/census-fn.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 368 - (view) (download)

1 : jhr 338 (* census-fn.sml
2 :     *
3 :     * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *
6 : jhr 368 * Compute use counts for IL variables and initialize their bindings.
7 : jhr 338 *)
8 :    
9 :     functor CensusFn (IL : SSA) : sig
10 :    
11 :     structure IL : SSA
12 :    
13 :     val init : IL.program -> unit
14 :    
15 : jhr 341 val inc : IL.var -> unit
16 :    
17 : jhr 338 end = struct
18 :    
19 :     structure IL = IL
20 :    
21 : jhr 341 fun inc (IL.V{useCnt, ...}) = (useCnt := !useCnt + 1)
22 : jhr 368 fun setBinding (IL.V{bind, ...}, vb) = bind := vb
23 : jhr 338
24 : jhr 341 fun init (IL.Program{globals, globalInit, actors}) = let
25 :     fun clearVar (IL.V{useCnt, ...}) = useCnt := 0
26 :     (* clear the counts of the variables defined in a node *)
27 :     fun clearNode (IL.ND{kind, ...}) = (case kind
28 :     of IL.JOIN{phis, ...} => List.app (fn (x, _) => clearVar x) (!phis)
29 :     | IL.BLOCK{body, ...} => List.app (fn (x, _) => clearVar x) (!body)
30 :     | _ => ()
31 :     (* end case *))
32 :     (* clear the counts of the variables defined in an actor *)
33 :     fun clearActor (IL.Actor{params, state, stateInit, methods, ...}) = let
34 :     fun clearMethod (IL.Method{stateIn, body, ...}) = (
35 :     List.app clearVar stateIn;
36 :     IL.applyToNodes clearNode body)
37 :     in
38 :     List.app clearVar params;
39 :     List.app clearVar state;
40 :     IL.applyToNodes clearNode stateInit;
41 :     List.app clearMethod methods
42 :     end
43 :     (* increment the use counts of a list of variables *)
44 :     val incList = List.app inc
45 :     (* increment the counts of the variables used in a node *)
46 :     fun incNode (IL.ND{kind, ...}) = (case kind
47 : jhr 368 of IL.JOIN{phis, ...} => let
48 :     fun f (y, xs) = (
49 :     setBinding (y, IL.VB_PHI xs);
50 :     incList xs)
51 :     in
52 :     List.app f (!phis)
53 :     end
54 : jhr 341 | IL.COND{cond, ...} => inc cond
55 :     | IL.BLOCK{body, ...} => let
56 : jhr 368 fun incRHS (y, rhs) = (
57 :     setBinding (y, IL.VB_RHS rhs);
58 :     case rhs
59 :     of (IL.VAR x) => inc x
60 :     | (IL.LIT _) => ()
61 :     | (IL.OP(_, args)) => incList args
62 :     | (IL.CONS args) => incList args
63 :     (* end case *))
64 : jhr 341 in
65 : jhr 368 List.app incRHS (!body)
66 : jhr 341 end
67 :     | IL.NEW{args, ...} => incList args
68 :     | _ => ()
69 :     (* end case *))
70 :     (* increment the counts of the variables used in an actor *)
71 :     fun incActor (IL.Actor{params, state, stateInit, methods, ...}) = let
72 : jhr 368 fun incMethod (IL.Method{stateIn, stateOut, body, ...}) = (
73 :     List.app (fn x => setBinding(x, IL.VB_STATE_VAR)) stateIn;
74 : jhr 341 incList stateOut;
75 :     IL.applyToNodes incNode body)
76 :     in
77 : jhr 368 List.app (fn x => setBinding(x, IL.VB_PARAM)) params;
78 : jhr 341 IL.applyToNodes incNode stateInit;
79 :     List.app incMethod methods
80 :     end
81 :     in
82 :     (* first clear the counts of all variables *)
83 :     List.app clearVar globals;
84 :     IL.applyToNodes clearNode globalInit;
85 :     List.app clearActor actors;
86 :     (* then count uses *)
87 :     IL.applyToNodes incNode globalInit;
88 :     List.app incActor actors
89 :     end
90 :    
91 : jhr 338 end

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