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 511, Tue Feb 8 17:01:43 2011 UTC
# Line 1  Line 1 
1  (* lift.sml  (* lift.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   * 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 strands 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    
28  (*    (* identify the image load operations and their antecedents; in terms of BTA,
     BV.op_at  
     BV.op_D  
     BV.fn_convolve  
     BV.fn_load  
 *)  
   
   (* the kinds of things a variable in Simple AST can be bound to *)  
     datatype var_binding  
       = RHS of S.exp  
       | Param  
   
   (* identify the image load operations and lift them and their antecedents; in terms of BTA,  
29     * this phase is essentially determining what must be static in order to get the image     * this phase is essentially determining what must be static in order to get the image
30     * info needed for the rest of the compile.     * info needed for the rest of the compile.
31     *)     *)
32      fun liftLoads block = let      fun findStatics block = let
33          (* analysis to compute the set of static variables *)          (* analysis to compute the set of static variables *)
34            fun mkStatic (env, statics, x) = if VSet.member(statics, x)            fun mkStatic (env, statics, x) = if VSet.member(statics, x)
35                  then statics                  then statics
# Line 87  Line 82 
82                    | _ => (env, statics)                    | _ => (env, statics)
83                  (* end case *))                  (* end case *))
84            val statics = doBlock (VMap.empty, VSet.empty, block)            val statics = doBlock (VMap.empty, VSet.empty, block)
         (* lift out the static code *)  
           fun doBlock (S.Block stms) = let  
                 fun doStmts ([], staticStms) = S.Block(List.rev staticStms)  
                   | doStmts (stm::stms, staticStms) = (case doStmt stm  
                        of SOME stm => doStmts (stms, stm::staticStms)  
                         | NONE => doStmts (stms, staticStms)  
                       (* end case *))  
85                  in                  in
86                    doStmts (stms, [])  Log.msg "**** static variables: ";
87    VSet.app (fn x => Log.msg(" "^Var.uniqueNameOf x)) statics;
88    Log.msg "\n";
89                statics
90                  end                  end
91    
92      (* given values for the static variables; reduce the static initialization code *)
93        fun reduce (env, blk) = let
94              fun doBlock (S.Block stms) =
95                    List.foldr (fn (stm, stms) => doStmt stm @ stms) [] stms
96            and doStmt stm = (case stm            and doStmt stm = (case stm
97                   of S.S_Assign(x, e) => if VSet.member(statics, x)                   of S.S_Assign(x, e) => (case Var.Map.find(env, x)
98                        then SOME stm                         of SOME v => let
99                        else NONE                              val rhs = (case v
100                    | S.S_IfThenElse(x, b1, b2) => if VSet.member(statics, x)                                     of (Eval.BV b) => S.E_Lit(Literal.Bool b)
101                        then SOME(S.S_IfThenElse(x, doBlock b1, doBlock b2))                                      | (Eval.SV s) => S.E_Lit(Literal.String s)
102                        else NONE                                      | (Eval.IV i) => S.E_Lit(Literal.Int i)
103                    | _ => NONE                                      | (Eval.TV _) => e
104                                        | (Eval.FV fld) => S.E_Field fld
105                                        | (Eval.Img info) => S.E_LoadImage info
106                                        | (Eval.KV h) => e
107                                      (* end case *))
108                                in
109                                  [S.S_Assign(x, rhs)]
110                                end
111                            | NONE => [stm]
112                          (* end case *))
113                      | S.S_IfThenElse(x, b1, b2) => (case Var.Map.find(env, x)
114                           of SOME(Eval.BV b) => if b then doBlock b1 else doBlock b2
115                            | NONE => [stm]
116                          (* end case *))
117                      | _ => [stm]
118                  (* end case *))                  (* end case *))
           val staticBlock = doBlock block  
119            in            in
120  print "**** static variables: ";              S.Block(doBlock blk)
 VSet.app (fn x => print(" "^Var.uniqueNameOf x)) statics;  
 print "\n";  
             staticBlock  
121            end            end
122    
123      fun transform (prog as S.Program{globals, staticInit, globalInit, actors}) = let      fun transform (prog as S.Program{globals, globalInit, strands}) = let
124            val staticInit = liftLoads globalInit            val statics = findStatics globalInit
125              val staticEnv = Eval.evalStatics (statics, globalInit)
126              val globalInit = reduce (staticEnv, globalInit)
127            in            in
128              S.Program{              S.Program{
129                  globals = globals,                  globals = globals,
                 staticInit = staticInit,  
130                  globalInit = globalInit,                  globalInit = globalInit,
131                  actors = actors                  strands = strands
132                }                }
133            end            end
134    

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

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