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

SCM Repository

[diderot] Diff of /branches/vis15/src/compiler/cfg-ir/census-fn.sml
ViewVC logotype

Diff of /branches/vis15/src/compiler/cfg-ir/census-fn.sml

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

revision 3474, Wed Dec 2 18:26:40 2015 UTC revision 3475, Wed Dec 2 18:48:58 2015 UTC
# Line 5  Line 5 
5   * COPYRIGHT (c) 2015 The University of Chicago   * COPYRIGHT (c) 2015 The University of Chicago
6   * All rights reserved.   * All rights reserved.
7   *   *
8   * Compute use counts for IL variables and initialize their bindings.   * Compute use counts for IR variables and initialize their bindings.
9   *)   *)
10    
11  functor CensusFn (IL : SSA) : sig  functor CensusFn (IR : SSA) : sig
12    
13      structure IL : SSA      structure IR : SSA
14    
15      val init : IL.program -> unit      val init : IR.program -> unit
16    
17      val inc : IL.var -> unit      val inc : IR.var -> unit
18      val dec : IL.var -> unit      val dec : IR.var -> unit
19    
20    end = struct    end = struct
21    
22      structure IL = IL      structure IR = IR
23    
24      fun inc (IL.V{useCnt, ...}) = (useCnt := !useCnt + 1)      fun inc (IR.V{useCnt, ...}) = (useCnt := !useCnt + 1)
25      fun dec (IL.V{useCnt, ...}) = (useCnt := !useCnt - 1)      fun dec (IR.V{useCnt, ...}) = (useCnt := !useCnt - 1)
26    
27      fun init (IL.Program{globals, inputInit, globalInit, initially, strands, ...}) = let      fun init (IR.Program{globals, inputInit, globalInit, initially, strands, ...}) = let
28            fun clearVar (IL.V{useCnt, ...}) = useCnt := 0            fun clearVar (IR.V{useCnt, ...}) = useCnt := 0
29          (* clear the counts of the variables defined in a node *)          (* clear the counts of the variables defined in a node *)
30            fun clearNode (IL.ND{kind, ...}) = (case kind            fun clearNode (IR.ND{kind, ...}) = (case kind
31                   of IL.JOIN{phis, ...} => List.app (fn (x, _) => clearVar x) (!phis)                   of IR.JOIN{phis, ...} => List.app (fn (x, _) => clearVar x) (!phis)
32                    | IL.FOREACH{var, phis, ...} => (                    | IR.FOREACH{var, phis, ...} => (
33                        clearVar var;                        clearVar var;
34                        List.app (fn (x, _) => clearVar x) (!phis))                        List.app (fn (x, _) => clearVar x) (!phis))
35                    | IL.ASSIGN{stm=(x, _), ...} => clearVar x                    | IR.ASSIGN{stm=(x, _), ...} => clearVar x
36                    | IL.MASSIGN{stm=(xs, _, _), ...} => List.app clearVar xs                    | IR.MASSIGN{stm=(xs, _, _), ...} => List.app clearVar xs
37                    | _ => ()                    | _ => ()
38                  (* end case *))                  (* end case *))
39          (* clear the counts of the initially code *)          (* clear the counts of the initially code *)
40            fun clearInitially (IL.Initially{rangeInit, iters, create, ...}) = let            fun clearInitially (IR.Initially{rangeInit, iters, create, ...}) = let
41                  fun clearIter (param, lo, hi) = clearVar param                  fun clearIter (param, lo, hi) = clearVar param
42                  in                  in
43                    IL.CFG.apply clearNode rangeInit;                    IR.CFG.apply clearNode rangeInit;
44                    List.app clearIter iters;                    List.app clearIter iters;
45                    IL.CFG.apply clearNode (#1 create)                    IR.CFG.apply clearNode (#1 create)
46                  end                  end
47          (* clear the counts of the variables defined in an strand *)          (* clear the counts of the variables defined in an strand *)
48            fun clearStrand (IL.Strand{params, state, stateInit, methods, ...}) = let            fun clearStrand (IR.Strand{params, state, stateInit, methods, ...}) = let
49                  fun clearMethod (IL.Method{body, ...}) = IL.CFG.apply clearNode body                  fun clearMethod (IR.Method{body, ...}) = IR.CFG.apply clearNode body
50                  in                  in
51                    List.app clearVar params;                    List.app clearVar params;
52                    IL.CFG.apply clearNode stateInit;                    IR.CFG.apply clearNode stateInit;
53                    List.app clearMethod methods                    List.app clearMethod methods
54                  end                  end
55          (* increment the use counts of a list of variables *)          (* increment the use counts of a list of variables *)
# Line 60  Line 60 
60           * is used to count the live variables at exits, since the context affects the           * is used to count the live variables at exits, since the context affects the
61           * treatment of these.           * treatment of these.
62           *)           *)
63            fun incNode exitCount (IL.ND{kind, ...}) = (case kind            fun incNode exitCount (IR.ND{kind, ...}) = (case kind
64                   of IL.JOIN{phis, ...} => List.app incPhi (!phis)                   of IR.JOIN{phis, ...} => List.app incPhi (!phis)
65                    | IL.COND{cond, ...} => inc cond                    | IR.COND{cond, ...} => inc cond
66                    | IL.FOREACH{src, phis, ...} => (                    | IR.FOREACH{src, phis, ...} => (
67                        inc src;                        inc src;
68                        List.app incPhi (!phis))                        List.app incPhi (!phis))
69                    | IL.ASSIGN{stm = (y, IL.GLOBAL gv), ...} => ()                    | IR.ASSIGN{stm = (y, IR.GLOBAL gv), ...} => ()
70                    | IL.ASSIGN{stm = (y, rhs), ...} => IL.RHS.app inc rhs                    | IR.ASSIGN{stm = (y, rhs), ...} => IR.RHS.app inc rhs
71                    | IL.MASSIGN{stm = (ys, rator, xs), ...} => List.app inc xs                    | IR.MASSIGN{stm = (ys, rator, xs), ...} => List.app inc xs
72                    | IL.GASSIGN{rhs, ...} => inc rhs                    | IR.GASSIGN{rhs, ...} => inc rhs
73                    | IL.NEW{args, ...} => incList args                    | IR.NEW{args, ...} => incList args
74                    | IL.SAVE{rhs, ...} => inc rhs                    | IR.SAVE{rhs, ...} => inc rhs
75                    | IL.EXIT{live, ...} => exitCount live                    | IR.EXIT{live, ...} => exitCount live
76                    | _ => ()                    | _ => ()
77                  (* end case *))                  (* end case *))
78          (* increment the counts of variables used in the initially code *)          (* increment the counts of variables used in the initially code *)
79            fun incInitially (IL.Initially{create, rangeInit, iters, ...}) = let            fun incInitially (IR.Initially{create, rangeInit, iters, ...}) = let
80                  fun incIter (param, lo, hi) = (inc lo; inc hi)                  fun incIter (param, lo, hi) = (inc lo; inc hi)
81                  in                  in
82                    IL.CFG.apply (incNode (fn live => incList live)) rangeInit;                    IR.CFG.apply (incNode (fn live => incList live)) rangeInit;
83                    List.app incIter iters;                    List.app incIter iters;
84                    IL.CFG.apply (incNode (fn _ => ())) (#1 create);                    IR.CFG.apply (incNode (fn _ => ())) (#1 create);
85                    List.app inc (#3 create)                    List.app inc (#3 create)
86                  end                  end
87          (* increment the counts of the variables used in a strand *)          (* increment the counts of the variables used in a strand *)
88            fun incStrand (IL.Strand{params, state, stateInit, methods, ...}) = let            fun incStrand (IR.Strand{params, state, stateInit, methods, ...}) = let
89                  fun incMethod (IL.Method{body, ...}) =                  fun incMethod (IR.Method{body, ...}) =
90                        IL.CFG.apply (incNode (fn live => incList live)) body                        IR.CFG.apply (incNode (fn live => incList live)) body
91                  in                  in
92                    IL.CFG.apply (incNode (fn live => incList live)) stateInit;                    IR.CFG.apply (incNode (fn live => incList live)) stateInit;
93                    List.app incMethod methods                    List.app incMethod methods
94                  end                  end
95            in            in
96            (* first clear the counts of all variables *)            (* first clear the counts of all variables *)
97              IL.CFG.apply clearNode inputInit;              IR.CFG.apply clearNode inputInit;
98              IL.CFG.apply clearNode globalInit;              IR.CFG.apply clearNode globalInit;
99              clearInitially initially;              clearInitially initially;
100              List.app clearStrand strands;              List.app clearStrand strands;
101            (* then count uses *)            (* then count uses *)
102              IL.CFG.apply (incNode (fn _ => ())) inputInit;              IR.CFG.apply (incNode (fn _ => ())) inputInit;
103              IL.CFG.apply (incNode (fn _ => ())) globalInit;              IR.CFG.apply (incNode (fn _ => ())) globalInit;
104              incInitially initially;              incInitially initially;
105              List.app incStrand strands              List.app incStrand strands
106            end            end

Legend:
Removed from v.3474  
changed lines
  Added in v.3475

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