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

SCM Repository

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

Diff of /branches/vis15/src/compiler/low-to-tree/low-to-tree.sml

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

revision 3855, Fri May 13 20:47:16 2016 UTC revision 3856, Sat May 14 12:49:20 2016 UTC
# Line 71  Line 71 
71      local      local
72        val {peekFn : IR.var -> eq_var_rep option, setFn, ...} =        val {peekFn : IR.var -> eq_var_rep option, setFn, ...} =
73              V.newProp (fn x => raise Fail(V.toString x))              V.newProp (fn x => raise Fail(V.toString x))
74      in  
75      fun eqClassRepOf (env, x) = (case UnifyVars.eqClassOf x        fun repOf (env, x, x') = (case peekFn x'
            of SOME x' => (case peekFn x'  
76                   of SOME b => b                   of SOME b => b
77                    | NONE => let                    | NONE => let
78                        val rep = (case V.ty x'                    val rep = (case V.ty x
79                               of Ty.TensorTy[d] => VEC(Util.newVectorVars(Env.layoutVec env d))                               of Ty.TensorTy[d] => VEC(Util.newVectorVars(Env.layoutVec env d))
80                                | ty => VAR(Util.newLocalVar x)                                | ty => VAR(Util.newLocalVar x)
81                              (* end case *))                              (* end case *))
# Line 85  Line 84 
84                          rep                          rep
85                        end                        end
86                  (* end case *))                  (* end case *))
87        in
88    
89        fun eqClassRepOf (env, x) = (case UnifyVars.eqClassOf x
90               of SOME x' => repOf (env, x, x')
91              | NONE => NOEQ              | NONE => NOEQ
92            (* end case *))            (* end case *))
93    
94        fun useVar env = let
95              val useV = Env.useVar env
96              in
97                fn x => (case UnifyVars.eqClassOf x
98                      of SOME x' => (case repOf (env, x, x')
99                           of VAR x => Env.TREE(T.E_Var x)
100                            | VEC xs => let
101                                val Ty.TensorTy[d] = V.ty x
102                                in
103                                  Env.VEC(Env.layoutVec env d, List.map T.E_Var xs)
104                                end
105                            | NOEQ => raise Fail "impossible"
106                          (* end case *))
107                       | NONE => useV x
108                     (* end case *))
109              end
110      end      end
111    
112      fun mkBlock stms = T.Block{locals = ref [], body = stms}      fun mkBlock stms = T.Block{locals = ref [], body = stms}
# Line 101  Line 121 
121    (* get a variable's binding as a single argument expression.  This means that    (* get a variable's binding as a single argument expression.  This means that
122     * if x is bound to a vector of expressions, then we need to pack it.     * if x is bound to a vector of expressions, then we need to pack it.
123     *)     *)
124      fun singleArg env x = (case Env.useVar env x      fun singleArg env x = (case useVar env x
125             of Env.TREE e => e             of Env.TREE e => e
126              | Env.VEC(layout, es) => T.E_Pack(layout, es)              | Env.VEC(layout, es) => T.E_Pack(layout, es)
127            (* end case *))            (* end case *))
128    
129      fun scalarArg env x = (case Env.useVar env x      fun scalarArg env x = (case useVar env x
130             of Env.TREE e => e             of Env.TREE e => e
131              | _ => raise Fail("expected scalar binding for " ^ IR.Var.toString x)              | _ => raise Fail("expected scalar binding for " ^ IR.Var.toString x)
132            (* end case *))            (* end case *))
133    
134      fun vectorArg (env, x) = (case Env.useVar env x      fun vectorArg (env, x) = (case useVar env x
135             of Env.TREE e => (case V.ty x             of Env.TREE e => (case V.ty x
136                   of Ty.TensorTy[d] => let                   of Ty.TensorTy[d] => let
137                        val layout = Env.layoutVec env d                        val layout = Env.layoutVec env d
# Line 198  Line 218 
218                    end                    end
219                | Op.VMul _ => bindVOp TOp.VMul                | Op.VMul _ => bindVOp TOp.VMul
220                | Op.VNeg _ => bindVOp TOp.VNeg                | Op.VNeg _ => bindVOp TOp.VNeg
221                | Op.VSum _ => raise Fail "FIXME: VSum"                | Op.VSum _ => let
222                      val [v] = args
223                      val ({pieces, ...}, es) = vectorArg (env, v)
224                      val e::es = ListPair.map (fn (w, v) => T.E_Op(TOp.VSum w, [v])) (pieces, es)
225                      in
226                        Env.TREE(List.foldr (fn (e, es) => T.E_Op(TOp.RAdd, [e, es])) e es)
227                      end
228                | Op.VIndex(_, i) => let                | Op.VIndex(_, i) => let
229                      val [v] = args
230  (* FIXME: more efficient to lookup the variable and avoid expanding TREE args *)  (* FIXME: more efficient to lookup the variable and avoid expanding TREE args *)
231                    val ({pieces, ...}, es) = vectorArg (env, hd args)                    val ({pieces, ...}, es) = vectorArg (env, v)
232                    fun select (i, w::ws, e::es) =                    fun select (i, w::ws, e::es) =
233                          if (i < w)                          if (i < w)
234  (* FIXME: what if lhs is used more than once? *)  (* FIXME: what if lhs is used more than once? *)
# Line 374  Line 401 
401                | rhs => raise Fail(concat["unexpected ", IR.RHS.toString rhs, " in LowIR code"])                | rhs => raise Fail(concat["unexpected ", IR.RHS.toString rhs, " in LowIR code"])
402              (* end case *)              (* end case *)
403            end            end
404    handle ex => (
405    print(concat["trAssign: ", V.toString lhs, " = ", IR.RHS.toString rhs, "\n"]);
406    raise ex)
407    
408    (* In order to reconstruct the block-structure from the CFG, we keep a stack of open ifs.    (* In order to reconstruct the block-structure from the CFG, we keep a stack of open ifs.
409     * the items on this stack distinguish between when we are processing the then and else     * the items on this stack distinguish between when we are processing the then and else
# Line 391  Line 421 
421        | ELSE_BR of T.stm list * T.exp * T.stm list * IR.node_kind        | ELSE_BR of T.stm list * T.exp * T.stm list * IR.node_kind
422    
423      fun trCFGWithEnv (env, cfg) = let      fun trCFGWithEnv (env, cfg) = let
424            fun useScalar x = (case Env.useVar env x            fun useScalar x = (case useVar env x
425                   of Env.TREE e => e                   of Env.TREE e => e
426                    | _ => raise Fail("expected scalar binding for " ^ V.toString x)                    | _ => raise Fail("expected scalar binding for " ^ V.toString x)
427                  (* end case *))                  (* end case *))
# Line 446  Line 476 
476                        end                        end
477                    | IR.FOREACH{var, src, bodyEntry, succ, ...} => let                    | IR.FOREACH{var, src, bodyEntry, succ, ...} => let
478                        val src = useScalar (!src)                        val src = useScalar (!src)
479                        val var = Util.newIterVar var                        val var' = Util.newIterVar var
480                        val stms = Env.flushPending (env, stms)                        val stms = Env.flushPending (env, stms)
481                          val _ = Env.bindSimple (env, var, Env.TREE(T.E_Var var'))
482                        val body = doNode (!bodyEntry, [], [])                        val body = doNode (!bodyEntry, [], [])
483                        val stm = T.S_Foreach(var, src, body)                        val stm = T.S_Foreach(var', src, body)
484                        in                        in
485                          doNode (!succ, ifStk, stm::stms)                          doNode (!succ, ifStk, stm::stms)
486                        end                        end

Legend:
Removed from v.3855  
changed lines
  Added in v.3856

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