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

SCM Repository

[diderot] Diff of /trunk/src/compiler/simplify/lift.sml
ViewVC logotype

Diff of /trunk/src/compiler/simplify/lift.sml

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

revision 181, Wed Jul 28 14:37:42 2010 UTC revision 234, Thu Aug 5 21:34:29 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   * Lift field operations to global scope.   * Lift field operations to global scope and split global initialization to
7     * pre and post image loading phases.
8   *)   *)
9    
10  structure Lift : sig  structure Lift : sig
# Line 13  Line 14 
14    end = struct    end = struct
15    
16      structure BV = BasisVars      structure BV = BasisVars
17        structure S = Simple
18        structure VSet = Var.Set
19        structure VMap = Var.Map
20    
21  (*  (*
22      BV.op_at      BV.op_at
# Line 21  Line 25 
25      BV.fn_load      BV.fn_load
26  *)  *)
27    
28      fun transform prog = prog    (* the kinds of things a variable in Simple AST can be bound to *)
29        datatype var_binding
30          = RHS of S.exp
31          | Param
32    
33      (* identify the image load operations and lift them and their antecedents; in terms of BTA,
34       * this phase is essentially determining what must be static in order to get the image
35       * info needed for the rest of the compile.
36       *)
37        fun liftLoads block = let
38            (* analysis to compute the set of static variables *)
39              fun mkStatic (env, statics, x) = if VSet.member(statics, x)
40                    then statics
41                    else let
42                      val statics = VSet.add(statics, x)
43                      in
44                        case VMap.find(env, x)
45                         of SOME(S.E_Var y) => mkStatic (env, statics, y)
46                          | SOME(S.E_Tuple ys) => mkStatics (env, statics, ys)
47                          | SOME(S.E_Apply(_, _, ys, _)) => mkStatics (env, statics, ys)
48                          | SOME(S.E_Cons ys) => mkStatics (env, statics, ys)
49                          | SOME(S.E_Input(_, _, SOME y)) => mkStatic (env, statics, y)
50                          | SOME _ => statics
51                          | NONE => raise Fail(concat["variable ", Var.uniqueNameOf x, " has no binding"])
52                        (* end case *)
53                      end
54              and mkStatics (env, statics, xs) =
55                    List.foldl (fn (x, statics) => mkStatic(env, statics, x)) statics xs
56              fun doBlock (env, statics, S.Block stms) = let
57                    fun doStmts (env, statics, []) = statics
58                      | doStmts (env, statics, stm::stms) = let
59                          val (env, statics) = doStmt (env, statics, stm)
60                          in
61                            doStmts (env, statics, stms)
62                          end
63                    in
64                      doStmts (env, statics, stms)
65                    end
66              and doStmt (env, statics, stm) = (case stm
67                     of S.S_Assign(x, e) => let
68                          val env = VMap.insert(env, x, e)
69                          in
70                            case e
71                             of S.E_Apply(f, _, xs, _) =>
72                                  if Var.same(f, BV.fn_load)
73                                    then (env, mkStatic(env, statics, x))
74                                    else (env, statics)
75                              | _ => (env, statics)
76                            (* end case *)
77                          end
78                      | S.S_IfThenElse(x, b1, b2) => let
79                          val statics1 = doBlock (env, statics, b1)
80                          val statics2 = doBlock (env, statics, b2)
81                          val n = VSet.numItems statics
82                          in
83                            if ((n <> VSet.numItems statics1) orelse (n <> VSet.numItems statics2))
84                              then (env, mkStatic(env, statics, x))
85                              else (env, statics)
86                          end
87                      | _ => (env, statics)
88                    (* end case *))
89              val statics = doBlock (VMap.empty, VSet.empty, block)
90            (* lift out the static code *)
91              fun doBlock (S.Block stms) = let
92                    fun doStmts ([], staticStms) = S.Block(List.rev staticStms)
93                      | doStmts (stm::stms, staticStms) = (case doStmt stm
94                           of SOME stm => doStmts (stms, stm::staticStms)
95                            | NONE => doStmts (stms, staticStms)
96                          (* end case *))
97                    in
98                      doStmts (stms, [])
99                    end
100              and doStmt stm = (case stm
101                     of S.S_Assign(x, e) => if VSet.member(statics, x)
102                          then SOME stm
103                          else NONE
104                      | S.S_IfThenElse(x, b1, b2) => if VSet.member(statics, x)
105                          then SOME(S.S_IfThenElse(x, doBlock b1, doBlock b2))
106                          else NONE
107                      | _ => NONE
108                    (* end case *))
109              val staticBlock = doBlock block
110              in
111    print "**** static variables: ";
112    VSet.app (fn x => print(" "^Var.uniqueNameOf x)) statics;
113    print "\n";
114                staticBlock
115              end
116    
117        fun transform (prog as S.Program{globals, staticInit, globalInit, actors}) = let
118              val staticInit = liftLoads globalInit
119              in
120                S.Program{
121                    globals = globals,
122                    staticInit = staticInit,
123                    globalInit = globalInit,
124                    actors = actors
125                  }
126              end
127    
128    end    end

Legend:
Removed from v.181  
changed lines
  Added in v.234

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