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 341, Mon Sep 13 17:14:24 2010 UTC revision 368, Fri Oct 1 18:17:34 2010 UTC
# Line 3  Line 3 
3   * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)   * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.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 19  Line 19 
19      structure IL = IL      structure IL = IL
20    
21      fun inc (IL.V{useCnt, ...}) = (useCnt := !useCnt + 1)      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      fun init (IL.Program{globals, globalInit, actors}) = let
25            fun clearVar (IL.V{useCnt, ...}) = useCnt := 0            fun clearVar (IL.V{useCnt, ...}) = useCnt := 0
# Line 43  Line 44 
44            val incList = List.app inc            val incList = List.app inc
45          (* increment the counts of the variables used in a node *)          (* increment the counts of the variables used in a node *)
46            fun incNode (IL.ND{kind, ...}) = (case kind            fun incNode (IL.ND{kind, ...}) = (case kind
47                   of IL.JOIN{phis, ...} => List.app (fn (_, xs) => incList xs) (!phis)                   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                    | IL.COND{cond, ...} => inc cond
55                    | IL.BLOCK{body, ...} => let                    | IL.BLOCK{body, ...} => let
56                        fun incRHS (IL.VAR x) = inc x                        fun incRHS (y, rhs) = (
57                          | incRHS (IL.LIT _) = ()                              setBinding (y, IL.VB_RHS rhs);
58                          | incRHS (IL.OP(_, args)) = incList args                              case rhs
59                          | incRHS (IL.CONS args) = incList args                               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                        in
65                          List.app (fn (_, rhs) => incRHS rhs) (!body)                          List.app incRHS (!body)
66                        end                        end
67                    | IL.NEW{args, ...} => incList args                    | IL.NEW{args, ...} => incList args
68                    | _ => ()                    | _ => ()
69                  (* end case *))                  (* end case *))
70          (* increment the counts of the variables used in an actor *)          (* increment the counts of the variables used in an actor *)
71            fun incActor (IL.Actor{params, state, stateInit, methods, ...}) = let            fun incActor (IL.Actor{params, state, stateInit, methods, ...}) = let
72                  fun incMethod (IL.Method{stateOut, body, ...}) = (                  fun incMethod (IL.Method{stateIn, stateOut, body, ...}) = (
73                          List.app (fn x => setBinding(x, IL.VB_STATE_VAR)) stateIn;
74                        incList stateOut;                        incList stateOut;
75                        IL.applyToNodes incNode body)                        IL.applyToNodes incNode body)
76                  in                  in
77                      List.app (fn x => setBinding(x, IL.VB_PARAM)) params;
78                    IL.applyToNodes incNode stateInit;                    IL.applyToNodes incNode stateInit;
79                    List.app incMethod methods                    List.app incMethod methods
80                  end                  end

Legend:
Removed from v.341  
changed lines
  Added in v.368

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