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 234, Thu Aug 5 21:34:29 2010 UTC revision 246, Fri Aug 6 15:32:26 2010 UTC
# Line 5  Line 5 
5   *   *
6   * Lift field operations to global scope and split global initialization to   * Lift field operations to global scope and split global initialization to
7   * pre and post image loading phases.   * pre and post image loading phases.
8     *
9     * NOTE: this process can be streamlined as follows:
10     *      1) identify the static variables
11     *      2) evaluate eagerly, with the proviso that if the lhs is not static, then
12     *         only evaluate if the rhs is static and the operation is supported
13     *      3) reduce code
14     * This evaluation process could be extended to the body of the actors too.
15   *)   *)
16    
17  structure Lift : sig  structure Lift : sig
# Line 18  Line 25 
25      structure VSet = Var.Set      structure VSet = Var.Set
26      structure VMap = Var.Map      structure VMap = Var.Map
27    
 (*  
     BV.op_at  
     BV.op_D  
     BV.fn_convolve  
     BV.fn_load  
 *)  
   
28    (* the kinds of things a variable in Simple AST can be bound to *)    (* the kinds of things a variable in Simple AST can be bound to *)
29      datatype var_binding      datatype var_binding
30        = RHS of S.exp        = RHS of S.exp
# Line 108  Line 108 
108                  (* end case *))                  (* end case *))
109            val staticBlock = doBlock block            val staticBlock = doBlock block
110            in            in
111  print "**** static variables: ";  Log.msg "**** static variables: ";
112  VSet.app (fn x => print(" "^Var.uniqueNameOf x)) statics;  VSet.app (fn x => Log.msg(" "^Var.uniqueNameOf x)) statics;
113  print "\n";  Log.msg "\n";
114              staticBlock              staticBlock
115            end            end
116    
117      fun transform (prog as S.Program{globals, staticInit, globalInit, actors}) = let    (* given values for the static variables; reduce the static initialization code *)
118        fun reduce (env, blk) = let
119              fun doBlock (S.Block stms) =
120                    List.foldr (fn (stm, stms) => doStmt stm @ stms) [] stms
121              and doStmt stm = (case stm
122                     of S.S_Assign(x, e) => (case Var.Map.find(env, x)
123                           of SOME v => let
124                                val rhs = (case v
125                                       of (Eval.BV b) => S.E_Lit(Literal.Bool b)
126                                        | (Eval.SV s) => S.E_Lit(Literal.String s)
127                                        | (Eval.IV i) => S.E_Lit(Literal.Int i)
128                                        | (Eval.TV _) => e
129                                        | (Eval.FV fld) => S.E_Field fld
130                                        | (Eval.Img info) => S.E_LoadImage info
131                                        | (Eval.KV h) => e
132                                      (* end case *))
133                                in
134                                  [S.S_Assign(x, rhs)]
135                                end
136                            | NONE => [stm]
137                          (* end case *))
138                      | S.S_IfThenElse(x, b1, b2) => (case Var.Map.find(env, x)
139                           of SOME(Eval.BV b) => if b then doBlock b1 else doBlock b2
140                            | NONE => [stm]
141                          (* end case *))
142                      | _ => [stm]
143                    (* end case *))
144              in
145                S.Block(doBlock blk)
146              end
147    
148        fun transform (prog as S.Program{globals, globalInit, actors}) = let
149            val staticInit = liftLoads globalInit            val staticInit = liftLoads globalInit
150              val staticEnv = Eval.evalStatics staticInit
151              val globalInit = reduce (staticEnv, globalInit)
152            in            in
153              S.Program{              S.Program{
154                  globals = globals,                  globals = globals,
                 staticInit = staticInit,  
155                  globalInit = globalInit,                  globalInit = globalInit,
156                  actors = actors                  actors = actors
157                }                }

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

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