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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 338, Mon Sep 13 14:49:12 2010 UTC revision 435, Tue Oct 19 13:14:20 2010 UTC
# Line 1  Line 1 
1  (* census-fn.sml  (* census-fn.sml
2   *   *
3   * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)   * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4   * All rights reserved.   * All rights reserved.
5   *   *
6   * Compute use counts for IL variables.   * Compute use counts for IL variables and initialize their bindings.
7   *)   *)
8    
9  functor CensusFn (IL : SSA) : sig  functor CensusFn (IL : SSA) : sig
# Line 12  Line 12 
12    
13      val init : IL.program -> unit      val init : IL.program -> unit
14    
15        val inc : IL.var -> unit
16    
17    end = struct    end = struct
18    
19      structure IL = IL      structure IL = IL
20    
21      fun init (IL.Program{globals, globalInit, actors}) = () (* FIXME *)      fun inc (IL.V{useCnt, ...}) = (useCnt := !useCnt + 1)
22        fun setBinding (IL.V{bind, ...}, vb) = bind := vb
23    
24        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                     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                      | IL.COND{cond, ...} => inc cond
55                      | IL.BLOCK{body, ...} => let
56                          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                          in
65                            List.app incRHS (!body)
66                          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                    fun incMethod (IL.Method{stateIn, stateOut, body, ...}) = (
73                          List.app (fn x => setBinding(x, IL.VB_STATE_VAR)) stateIn;
74                          incList stateOut;
75                          IL.applyToNodes incNode body)
76                    in
77                      List.app (fn x => setBinding(x, IL.VB_PARAM)) params;
78                      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    end    end

Legend:
Removed from v.338  
changed lines
  Added in v.435

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