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 341 - (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 :     * Compute use counts for IL variables.
7 :     *)
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 338
23 : jhr 341 fun init (IL.Program{globals, globalInit, actors}) = let
24 :     fun clearVar (IL.V{useCnt, ...}) = useCnt := 0
25 :     (* clear the counts of the variables defined in a node *)
26 :     fun clearNode (IL.ND{kind, ...}) = (case kind
27 :     of IL.JOIN{phis, ...} => List.app (fn (x, _) => clearVar x) (!phis)
28 :     | IL.BLOCK{body, ...} => List.app (fn (x, _) => clearVar x) (!body)
29 :     | _ => ()
30 :     (* end case *))
31 :     (* clear the counts of the variables defined in an actor *)
32 :     fun clearActor (IL.Actor{params, state, stateInit, methods, ...}) = let
33 :     fun clearMethod (IL.Method{stateIn, body, ...}) = (
34 :     List.app clearVar stateIn;
35 :     IL.applyToNodes clearNode body)
36 :     in
37 :     List.app clearVar params;
38 :     List.app clearVar state;
39 :     IL.applyToNodes clearNode stateInit;
40 :     List.app clearMethod methods
41 :     end
42 :     (* increment the use counts of a list of variables *)
43 :     val incList = List.app inc
44 :     (* increment the counts of the variables used in a node *)
45 :     fun incNode (IL.ND{kind, ...}) = (case kind
46 :     of IL.JOIN{phis, ...} => List.app (fn (_, xs) => incList xs) (!phis)
47 :     | IL.COND{cond, ...} => inc cond
48 :     | IL.BLOCK{body, ...} => let
49 :     fun incRHS (IL.VAR x) = inc x
50 :     | incRHS (IL.LIT _) = ()
51 :     | incRHS (IL.OP(_, args)) = incList args
52 :     | incRHS (IL.CONS args) = incList args
53 :     in
54 :     List.app (fn (_, rhs) => incRHS rhs) (!body)
55 :     end
56 :     | IL.NEW{args, ...} => incList args
57 :     | _ => ()
58 :     (* end case *))
59 :     (* increment the counts of the variables used in an actor *)
60 :     fun incActor (IL.Actor{params, state, stateInit, methods, ...}) = let
61 :     fun incMethod (IL.Method{stateOut, body, ...}) = (
62 :     incList stateOut;
63 :     IL.applyToNodes incNode body)
64 :     in
65 :     IL.applyToNodes incNode stateInit;
66 :     List.app incMethod methods
67 :     end
68 :     in
69 :     (* first clear the counts of all variables *)
70 :     List.app clearVar globals;
71 :     IL.applyToNodes clearNode globalInit;
72 :     List.app clearActor actors;
73 :     (* then count uses *)
74 :     IL.applyToNodes incNode globalInit;
75 :     List.app incActor actors
76 :     end
77 :    
78 : jhr 338 end

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