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

SCM Repository

[diderot] Diff of /branches/lamont/src/compiler/tree-il/low-to-tree-fn.sml
ViewVC logotype

Diff of /branches/lamont/src/compiler/tree-il/low-to-tree-fn.sml

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

revision 2297, Fri Mar 15 22:05:31 2013 UTC revision 2298, Fri Mar 15 22:18:22 2013 UTC
# Line 36  Line 36 
36    
37    (* create new tree IL variables *)    (* create new tree IL variables *)
38      local      local
39        fun newVar (name, kind, ty) = T.V{        val newVar = T.Var.new
               name = name,  
               id = Stamp.new(),  
               kind = kind,  
               ty = ty  
             }  
40        val cnt = ref 0        val cnt = ref 0
41        fun genName prefix = let        fun genName prefix = let
42              val n = !cnt              val n = !cnt
# Line 71  Line 66 
66      end      end
67    
68      fun mkBlock stms = T.Block{locals=[], body=stms}      fun mkBlock stms = T.Block{locals=[], body=stms}
69      fun mkForEach (cond,stms,s) = T.S_Foreach(cond,mkBlock stms,s)      fun mkForeach (cond, stms, s) = T.S_Foreach(cond, mkBlock stms, s)
70      fun mkIf (x, stms, []) = T.S_IfThen(x, mkBlock stms)      fun mkIf (x, stms, []) = T.S_IfThen(x, mkBlock stms)
71        | mkIf (x, stms1, stms2) = T.S_IfThenElse(x, mkBlock stms1, mkBlock stms2)        | mkIf (x, stms1, stms2) = T.S_IfThenElse(x, mkBlock stms1, mkBlock stms2)
72    
# Line 118  Line 113 
113             of SOME(GLOB x') => T.E_Var x'             of SOME(GLOB x') => T.E_Var x'
114              | SOME(TREE e) => e              | SOME(TREE e) => e
115              | SOME(DEF e) => e              | SOME(DEF e) => e
116              | NONE => (dumpEnv env;              | NONE => (
117                    dumpEnv env;
118                     raise Fail(concat ["findVarExpr(", V.toString x, ")"]))                     raise Fail(concat ["findVarExpr(", V.toString x, ")"]))
119                    (*end of case*))            (* end case *))
120    
121    (* use a variable.  If it is a pending expression, we remove it from the table *)    (* use a variable.  If it is a pending expression, we remove it from the table *)
122      fun useVar (env as E{tbl, ...}) x = (case VT.find tbl x      fun useVar (env as E{tbl, ...}) x = (case VT.find tbl x
# Line 195  Line 191 
191              (E{tbl=tbl, locals=locals}, stms)              (E{tbl=tbl, locals=locals}, stms)
192            end            end
193    
194  datatype open_loop =      datatype open_loop = OPEN_JOIN_ND | OPEN_STM_BR
           OPEN_JOIN_ND  
         | OPEN_STM_BR  
195    
196      fun processPhis([]) = raise Fail(concat ["processPhis can't find TreeIL variable name"])      fun processPhis [] = raise Fail(concat ["processPhis can't find TreeIL variable name"])
197        | processPhis(t::rest) = (t,rest)        | processPhis(t::rest) = (t,rest)
198    
199      fun addPhis(openTy,[],env,phis,predBlks : T.stm list,varList ) = (env,predBlks,phis,varList)      fun addPhis(openTy,[],env,phis,predBlks : T.stm list,varList ) = (env,predBlks,phis,varList)
200        | addPhis(openTy,(lhs,[])::rest,env,phis,predBlks : T.stm list,varList ) = (env,predBlks,phis,varList)        | addPhis(openTy,(lhs,[])::rest,env,phis,predBlks : T.stm list,varList ) = (env,predBlks,phis,varList)
201        | addPhis(openTy,(lhs,(rhs::r))::rest,env,phis,predBlks : T.stm list,varList) =        | addPhis(openTy,(lhs,(rhs::r))::rest,env,phis,predBlks : T.stm list,varList) =
202            ( if(openTy = OPEN_JOIN_ND) then (let            if (openTy = OPEN_JOIN_ND)
203                then let
204                  val t = newLocal lhs                  val t = newLocal lhs
205                  val lhsTy = IL.Var.ty lhs                  val lhsTy = IL.Var.ty lhs
206                  in                  in
207                        (case lhsTy                  case lhsTy
208                      of Ty.StrandSeqTy _ =>                      of Ty.StrandSeqTy _ =>
209                              addPhis(openTy,rest,rename(addLocal(env, t), lhs, t),(lhs,r)::phis,predBlks,t::varList)                              addPhis(openTy,rest,rename(addLocal(env, t), lhs, t),(lhs,r)::phis,predBlks,t::varList)
210                      | _ =>
211                      | _ => addPhis(openTy,rest,rename(addLocal(env, t), lhs, t),(lhs,r)::phis,T.S_Assign([t], useVar env rhs)::predBlks,t::varList))                        addPhis(openTy,rest,rename(addLocal(env, t), lhs, t),(lhs,r)::phis,T.S_Assign([t], useVar env rhs)::predBlks,t::varList)
212                  end)                  (* end case *)
213              else (let                end
214                  val  (t',varlist_rest) = processPhis(varList)              else let
215                  val (t', varlistRest) = processPhis varList
216                  val  lhsTy = IL.Var.ty lhs                  val  lhsTy = IL.Var.ty lhs
217                  in                  in
218                      (case lhsTy                  case lhsTy
219                      of Ty.StrandSeqTy _ =>                      of Ty.StrandSeqTy _ =>
220                           addPhis(openTy,rest,env,[],predBlks,varlist_rest)                         addPhis(openTy,rest,env,[],predBlks,varlistRest)
221                      | _ =>                      | _ =>
222                          addPhis(openTy,rest,env,[],T.S_Assign([t'], useVar env rhs)::predBlks,varlist_rest)                        addPhis(openTy,rest,env,[],T.S_Assign([t'], useVar env rhs)::predBlks,varlistRest)
223                      (*end of case *))                  (*end of case *)
224                  end))                end
   
   
225    
226      fun doPhi ((lhs, rhs), (env, predBlks : T.stm list list)) = let      fun doPhi ((lhs, rhs), (env, predBlks : T.stm list list)) = let
227          (* t will be the variable in the continuation of the JOIN *)          (* t will be the variable in the continuation of the JOIN *)
# Line 351  Line 345 
345            | IL.VAR x => bindSimple (env, lhs, useVar env x)            | IL.VAR x => bindSimple (env, lhs, useVar env x)
346                | IL.LIT lit => bindSimple (env, lhs, T.E_Lit lit)                | IL.LIT lit => bindSimple (env, lhs, T.E_Lit lit)
347            | IL.SELECTOR (x,f) => bindSimple(env,lhs, T.E_Selector(useVar env x,f))            | IL.SELECTOR (x,f) => bindSimple(env,lhs, T.E_Selector(useVar env x,f))
348            | IL.STRAND_SET(sets) => let                | IL.STRAND_SET sets => let
349                  fun cvtStrandSet(s) = (case s                    fun cvtStrandSet s = (case s
350                    of IL.SS_All => T.SS_All                    of IL.SS_All => T.SS_All
351                     | IL.SS_Active => T.SS_Active                     | IL.SS_Active => T.SS_Active
352                     | IL.SS_Stable => T.SS_Stable                     | IL.SS_Stable => T.SS_Stable
353                    (* end case *))                    (* end case *))
354                    val(env, t) = doLHS()                    val(env, t) = doLHS()
355                    val tTy as Ty.DynSeqTy(ty) = T.Var.ty(t)                    val tTy as Ty.DynSeqTy ty = T.Var.ty t
356                  in                  in
357                  (env, [T.S_Assign([t], T.E_Strand_Set(List.map cvtStrandSet sets,ty))])                  (env, [T.S_Assign([t], T.E_Strand_Set(List.map cvtStrandSet sets,ty))])
358                  end                  end
# Line 496  Line 490 
490                                  let                                  let
491                                  val (env',stmBranch,_,_) = addPhis(OPEN_STM_BR,phis',env,[],stms,varList)                                  val (env',stmBranch,_,_) = addPhis(OPEN_STM_BR,phis',env,[],stms,varList)
492    
493                          val stm''' = mkForEach(cond,List.rev stmBranch,!varStrandName)                                val stm''' = mkForeach(cond,List.rev stmBranch,!varStrandName)
494                               in                               in
495                           doNode(env',stk,stm'''::stms',!succ)                           doNode(env',stk,stm'''::stms',!succ)
496                              end                              end
# Line 660  Line 654 
654            val _ = (* DEBUG *)            val _ = (* DEBUG *)
655                  LowPP.output (Log.logFile(), "LowIL after variable analysis", prog)                  LowPP.output (Log.logFile(), "LowIL after variable analysis", prog)
656            val env = newEnv()            val env = newEnv()
       val globals = (IL.CFG.liveAtExit globalBlock)  
657            val globals = List.map            val globals = List.map
658                  (fn x => let val x' = newGlobal x in global(env, x, x'); x' end)                  (fn x => let val x' = newGlobal x in global(env, x, x'); x' end)
659                    (globals)                    (IL.CFG.liveAtExit globalInit)
660            val {inputInit, globalInit} = splitGlobalInit globalInit            val {inputInit, globalInit} = splitGlobalInit globalInit
661            val strands = List.map (trStrand env) strands            val strands = List.map (trStrand env) strands
662            in            in

Legend:
Removed from v.2297  
changed lines
  Added in v.2298

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