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

SCM Repository

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

Annotation of /branches/pure-cfg/src/compiler/IL/census-fn.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 501 - (view) (download)

1 : jhr 338 (* census-fn.sml
2 :     *
3 : jhr 435 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 : jhr 338 * 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 499 fun init (IL.Program{globals, globalInit, strands}) = let
25 : jhr 341 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 : jhr 491 | IL.ASSIGN{stm=(x, _), ...} => clearVar x
30 : jhr 341 | _ => ()
31 :     (* end case *))
32 : jhr 499 (* clear the counts of the variables defined in an strand *)
33 :     fun clearStrand (IL.Strand{params, state, stateInit, methods, ...}) = let
34 : jhr 341 fun clearMethod (IL.Method{stateIn, body, ...}) = (
35 :     List.app clearVar stateIn;
36 : jhr 491 IL.CFG.apply clearNode body)
37 : jhr 341 in
38 :     List.app clearVar params;
39 :     List.app clearVar state;
40 : jhr 491 IL.CFG.apply clearNode stateInit;
41 : jhr 341 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 : jhr 491 | IL.ASSIGN{stm = (y, rhs), ...} => (
56 :     setBinding (y, IL.VB_RHS rhs);
57 :     case rhs
58 :     of (IL.VAR x) => inc x
59 :     | (IL.LIT _) => ()
60 :     | (IL.OP(_, args)) => incList args
61 :     | (IL.CONS args) => incList args
62 :     (* end case *))
63 : jhr 341 | IL.NEW{args, ...} => incList args
64 :     | _ => ()
65 :     (* end case *))
66 : jhr 501 (* increment the counts of the variables used in a strand *)
67 : jhr 499 fun incStrand (IL.Strand{params, state, stateInit, methods, ...}) = let
68 : jhr 368 fun incMethod (IL.Method{stateIn, stateOut, body, ...}) = (
69 :     List.app (fn x => setBinding(x, IL.VB_STATE_VAR)) stateIn;
70 : jhr 341 incList stateOut;
71 : jhr 491 IL.CFG.apply incNode body)
72 : jhr 341 in
73 : jhr 368 List.app (fn x => setBinding(x, IL.VB_PARAM)) params;
74 : jhr 491 IL.CFG.apply incNode stateInit;
75 : jhr 341 List.app incMethod methods
76 :     end
77 :     in
78 :     (* first clear the counts of all variables *)
79 :     List.app clearVar globals;
80 : jhr 491 IL.CFG.apply clearNode globalInit;
81 : jhr 499 List.app clearStrand strands;
82 : jhr 341 (* then count uses *)
83 : jhr 491 IL.CFG.apply incNode globalInit;
84 : jhr 499 List.app incStrand strands
85 : jhr 341 end
86 :    
87 : jhr 338 end

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