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

SCM Repository

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

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

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

revision 3977, Wed Jun 15 19:06:30 2016 UTC revision 3982, Thu Jun 16 15:16:17 2016 UTC
# Line 50  Line 50 
50              | (Ty.TensorTy dd) => CL.T_Array(Env.realTy env, SOME(List.foldl Int.* 1 dd))              | (Ty.TensorTy dd) => CL.T_Array(Env.realTy env, SOME(List.foldl Int.* 1 dd))
51              | (Ty.TensorRefTy _) => CL.constPtrTy(Env.realTy env)              | (Ty.TensorRefTy _) => CL.constPtrTy(Env.realTy env)
52              | (Ty.TupleTy tys) => raise Fail "FIXME: TupleTy"              | (Ty.TupleTy tys) => raise Fail "FIXME: TupleTy"
53              | (Ty.SeqTy(t, NONE)) => CL.T_Template("diderot::dynseq", [trType(env, t)])              | (Ty.SeqTy(ty, NONE)) => dynseqTy (env, ty)
54              | (Ty.SeqTy(t, SOME n)) => CL.T_Array(trType(env, t), SOME n)              | (Ty.SeqTy(ty, SOME n)) => CL.T_Array(trType(env, ty), SOME n)
55              | (Ty.ImageTy info) =>              | (Ty.ImageTy info) =>
56                  CL.T_Template(                  CL.T_Template(
57                    concat["diderot::image", Int.toString(ImageInfo.dim info), "d"],                    concat["diderot::image", Int.toString(ImageInfo.dim info), "d"],
# Line 59  Line 59 
59              | (Ty.StrandTy name) => CL.T_Named("strand_" ^ Atom.toString name)              | (Ty.StrandTy name) => CL.T_Named("strand_" ^ Atom.toString name)
60            (* end case *))            (* end case *))
61    
62      (* dynamic sequence of the specified element type *)
63        and dynseqTy (env, ty) = CL.T_Template("diderot::dynseq", [trType(env, ty)])
64    
65    (* translate a local variable that occurs in an l-value context *)    (* translate a local variable that occurs in an l-value context *)
66      fun lvalueVar (env, x) = CL.mkVar(Env.lookup(env, x))      fun lvalueVar (env, x) = CL.mkVar(Env.lookup(env, x))
67    (* translate a variable that occurs in an r-value context *)    (* translate a variable that occurs in an r-value context *)
# Line 80  Line 83 
83      val freshVar = CodeGenUtil.freshVar      val freshVar = CodeGenUtil.freshVar
84    
85    (* integer literal expression *)    (* integer literal expression *)
86      fun intExp (i : int) = CL.mkInt(IntInf.fromInt i)      fun mkInt (i : int) = CL.mkInt(IntInf.fromInt i)
87    
88      val zero = CL.mkInt 0      val zero = CL.mkInt 0
89    
# Line 92  Line 95 
95    (* make an application of a function from the "diderot" namespace *)    (* make an application of a function from the "diderot" namespace *)
96      fun mkDiderotApply (f, args) = CL.mkApply("diderot::" ^ f, args)      fun mkDiderotApply (f, args) = CL.mkApply("diderot::" ^ f, args)
97      fun mkDiderotCall (f, args) = CL.mkCall("diderot::" ^ f, args)      fun mkDiderotCall (f, args) = CL.mkCall("diderot::" ^ f, args)
98        fun mkDynseqApply (env, ty, f, args) = CL.mkTemplateApply(f, [dynseqTy(env, ty)], args)
99    
100    (* Translate a TreeIR operator application to a CLang expression *)    (* Translate a TreeIR operator application to a CLang expression *)
101      fun trOp (env, rator, args) = (case (rator, args)      fun trOp (env, rator, args) = (case (rator, args)
# Line 129  Line 133 
133              | (Op.VMul d, [a, b]) => CL.mkBinOp(a, CL.#*, b)              | (Op.VMul d, [a, b]) => CL.mkBinOp(a, CL.#*, b)
134              | (Op.VNeg d, [a]) => CL.mkUnOp(CL.%-, a)              | (Op.VNeg d, [a]) => CL.mkUnOp(CL.%-, a)
135              | (Op.VSum(w, _), [a]) => CL.mkApply(RN.vsum w, [a])              | (Op.VSum(w, _), [a]) => CL.mkApply(RN.vsum w, [a])
136              | (Op.VIndex(w, p, i), [a]) => CL.mkSubscript(a, intExp i)              | (Op.VIndex(w, p, i), [a]) => CL.mkSubscript(a, mkInt i)
137              | (Op.VClamp(w, _), [a, b, c]) => CL.mkApply("vclamp", [a, b, c])              | (Op.VClamp(w, _), [a, b, c]) => CL.mkApply("vclamp", [a, b, c])
138              | (Op.VMapClamp(w, _), [a, b, c]) => CL.mkApply("vclamp", [a, b, c])              | (Op.VMapClamp(w, _), [a, b, c]) => CL.mkApply("vclamp", [a, b, c])
139              | (Op.VLerp(w, _), [a, b, c]) => CL.mkApply("vlerp", [a, b, c])              | (Op.VLerp(w, _), [a, b, c]) => CL.mkApply("vlerp", [a, b, c])
# Line 142  Line 146 
146                  fun index ([], [i], acc) = acc + i                  fun index ([], [i], acc) = acc + i
147                    | index (d::dd, i::ii, acc) = index (dd, ii, d * (acc + i))                    | index (d::dd, i::ii, acc) = index (dd, ii, d * (acc + i))
148                  in                  in
149                    CL.mkSubscript(a, intExp(index (dd, idxs, 0)))                    CL.mkSubscript(a, mkInt(index (dd, idxs, 0)))
150                  end                  end
151              | (Op.ProjectLast(Ty.TensorRefTy(_::dd), idxs), [a]) => let              | (Op.ProjectLast(Ty.TensorRefTy(_::dd), idxs), [a]) => let
152                (* dimensions/indices are slowest to fastest *)                (* dimensions/indices are slowest to fastest *)
153                  fun index ([], [], acc) = acc                  fun index ([], [], acc) = acc
154                    | index (d::dd, i::ii, acc) = index (dd, ii, d * (acc + i))                    | index (d::dd, i::ii, acc) = index (dd, ii, d * (acc + i))
155                  in                  in
156                    CL.mkAddrOf(CL.mkSubscript(a, intExp(index (dd, idxs, 0))))                    CL.mkAddrOf(CL.mkSubscript(a, mkInt(index (dd, idxs, 0))))
157                  end                  end
158              | (Op.EigenVals2x2, [a]) => raise Fail "FIXME: EigenVals2x2"              | (Op.EigenVals2x2, [a]) => raise Fail "FIXME: EigenVals2x2"
159              | (Op.EigenVals3x3, [a]) => raise Fail "FIXME: EigenVals3x3"              | (Op.EigenVals3x3, [a]) => raise Fail "FIXME: EigenVals3x3"
160              | (Op.Select(ty, i), [a]) => raise Fail "FIXME: Select"              | (Op.Select(ty, i), [a]) => raise Fail "FIXME: Select"
161              | (Op.Subscript ty, [a, b]) => CL.mkSubscript(a, b)              | (Op.Subscript ty, [a, b]) => CL.mkSubscript(a, b)
162              | (Op.MkDynamic(ty, i), [a]) => raise Fail "FIXME: MkDynamic"              | (Op.MkDynamic(ty, n), [a]) => CL.mkCons(dynseqTy(env, ty), [mkInt n, a])
163              | (Op.Append ty, [a, b]) => raise Fail "FIXME: Append"  (* FIXME: eventually we should do some kind of liveness analysis to enable in situ operations *)
164              | (Op.Prepend ty, [a, b]) => raise Fail "FIXME: Prepend"              | (Op.Append ty, [a, b]) => mkDynseqApply (env, ty, "append", [a, b])
165              | (Op.Concat ty, [a, b]) => raise Fail "FIXME: Concat"              | (Op.Prepend ty, [a, b]) => mkDynseqApply (env, ty, "prepend", [a, b])
166              | (Op.Range, [a, b]) => raise Fail "FIXME: Range"              | (Op.Concat ty, [a, b]) => mkDynseqApply (env, ty, "concat", [a, b])
167              | (Op.Length ty, [a]) => raise Fail "FIXME: Length"              | (Op.Range, [a, b]) => CL.mkCons(dynseqTy(env, Ty.IntTy), [a, b])
168                | (Op.Length ty, [a]) => CL.mkDispatch(a, "length", [])
169              | (Op.SphereQuery(ty1, ty2), []) => raise Fail "FIXME: SphereQuery"              | (Op.SphereQuery(ty1, ty2), []) => raise Fail "FIXME: SphereQuery"
170              | (Op.Sqrt, [a]) => mkStdApply("sqrt", [a])              | (Op.Sqrt, [a]) => mkStdApply("sqrt", [a])
171              | (Op.Cos, [a]) => mkStdApply("cos", [a])              | (Op.Cos, [a]) => mkStdApply("cos", [a])
# Line 185  Line 190 
190              | (Op.Translate info, [img]) => CL.mkDispatch(img, "translate", [])              | (Op.Translate info, [img]) => CL.mkDispatch(img, "translate", [])
191              | (Op.BaseAddress info, [img]) => CL.mkDispatch(img, "base_addr", [])              | (Op.BaseAddress info, [img]) => CL.mkDispatch(img, "base_addr", [])
192              | (Op.ControlIndex(info, ctl, d), [img, idx]) =>              | (Op.ControlIndex(info, ctl, d), [img, idx]) =>
193                  CL.mkDispatch(img, IndexCtl.toString ctl, [intExp d, idx])                  CL.mkDispatch(img, IndexCtl.toString ctl, [mkInt d, idx])
194              | (Op.LoadVoxel info, [addr, offp]) => let              | (Op.LoadVoxel info, [addr, offp]) => let
195                  val voxel = CL.mkSubscript(addr, offp)                  val voxel = CL.mkSubscript(addr, offp)
196                  in                  in
# Line 193  Line 198 
198                      then voxel                      then voxel
199                      else CL.mkStaticCast(Env.realTy env, voxel)                      else CL.mkStaticCast(Env.realTy env, voxel)
200                  end                  end
201              | (Op.Inside(info, s), [pos, img]) => CL.mkDispatch(img, "inside", [pos, intExp s])              | (Op.Inside(info, s), [pos, img]) => CL.mkDispatch(img, "inside", [pos, mkInt s])
202              | (Op.ImageDim(info, i), [img]) => CL.mkDispatch(img, "size", [intExp i])              | (Op.ImageDim(info, i), [img]) => CL.mkDispatch(img, "size", [mkInt i])
203              | (Op.MathFn f, args) => mkStdApply(MathFns.toString f, args)              | (Op.MathFn f, args) => mkStdApply(MathFns.toString f, args)
204              | _ => raise Fail(concat[              | _ => raise Fail(concat[
205                     "unknown or incorrect operator ", Op.toString rator                     "unknown or incorrect operator ", Op.toString rator
# Line 218  Line 223 
223  (* FIXME: check if e is aligned and use "vload_aligned" in that case *)  (* FIXME: check if e is aligned and use "vload_aligned" in that case *)
224              | IR.E_VLoad(layout, e, i) =>              | IR.E_VLoad(layout, e, i) =>
225                  CL.mkApply(RN.vload(Ty.nthWidth(layout, i)),                  CL.mkApply(RN.vload(Ty.nthWidth(layout, i)),
226                    [CL.mkBinOp(trExp(env, e), CL.#+, intExp(Ty.offsetOf(layout, i)))])                    [CL.mkBinOp(trExp(env, e), CL.#+, mkInt(Ty.offsetOf(layout, i)))])
227              | _ => raise Fail "trExp"              | _ => raise Fail "trExp"
228            (* end case *))            (* end case *))
229    
# Line 240  Line 245 
245     *)     *)
246      fun trAssign (env, lhs, rhs, stms) = let      fun trAssign (env, lhs, rhs, stms) = let
247            fun trArg (i, arg, stms) =            fun trArg (i, arg, stms) =
248                  CL.mkAssign(CL.mkSubscript(lhs, intExp i), trExp (env, arg)) :: stms                  CL.mkAssign(CL.mkSubscript(lhs, mkInt i), trExp (env, arg)) :: stms
249            in            in
250              case rhs              case rhs
251               of IR.E_Op(Op.VToInt _, [a]) =>               of IR.E_Op(Op.VToInt _, [a]) =>

Legend:
Removed from v.3977  
changed lines
  Added in v.3982

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