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

SCM Repository

[diderot] Diff of /branches/vis15/src/compiler/simplify/simplify.sml
ViewVC logotype

Diff of /branches/vis15/src/compiler/simplify/simplify.sml

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

revision 3463, Sun Nov 29 15:07:26 2015 UTC revision 3464, Sun Nov 29 17:38:34 2015 UTC
# Line 245  Line 245 
245                    in                    in
246                      (stms, S.E_Select(x, cvtVar fld))                      (stms, S.E_Select(x, cvtVar fld))
247                    end                    end
248                | AST.E_Prim(rator, tyArgs, args as [AST.E_Lit(Literal.Int n)], ty) =>                | AST.E_Prim(rator, tyArgs, args as [e], ty) => (case e
249                  (* constant-fold negation of integer literals *)                     of AST.E_Lit(Literal.Int n) => if Var.same(BasisVars.neg_i, rator)
250                    if Var.same(BasisVars.neg_i, rator)                          then (stms, S.E_Lit(Literal.Int(~n))) (* constant-fold negation of integer literals *)
                     then (stms, S.E_Lit(Literal.Int(~n)))  
251                      else doPrimApply (rator, tyArgs, args, ty)                      else doPrimApply (rator, tyArgs, args, ty)
252                | AST.E_Prim(rator, tyArgs, args as [AST.E_Lit(Literal.Real f)], ty as Types.T_Tensor sh) =>                      | AST.E_Lit(Literal.Real f) =>
253                  (* constant-fold negation of real literals *)                          if Var.same(BasisVars.neg_t, rator)
254                    if Var.same(BasisVars.neg_i, rator) andalso List.null(TU.monoShape sh)                            then (stms, S.E_Lit(Literal.Real(RealLit.negate f))) (* constant-fold negation of real literals *)
                     then (stms, S.E_Lit(Literal.Real(RealLit.negate f)))  
255                      else doPrimApply (rator, tyArgs, args, ty)                      else doPrimApply (rator, tyArgs, args, ty)
256                        | AST.E_Comprehension(e', (x, e''), seqTy) => if Basis.isReductionOp rator
257                            then let
258                              val {rator, init, mvs} = Util.reductionInfo rator
259                              val (stms, xs) = simplifyExpToVar (errStrm, e'', stms)
260                              val (bodyStms, bodyResult) = simplifyExpToVar (errStrm, e, [])
261                              val acc = SimpleVar.new ("accum", Var.LocalVar, cvtTy ty)
262                              val seqTy' as STy.T_Sequence(elemTy, NONE) = cvtTy seqTy
263                              val initStm = S.S_Assign(acc, S.E_Lit init)
264                              val updateStm = S.S_Assign(acc,
265                                    S.E_Prim(rator, mvs, [acc, bodyResult], seqTy'))
266                              val foreachStm = S.S_Foreach(cvtVar x, xs, mkBlock(updateStm :: bodyStms))
267                              in
268                                (foreachStm :: initStm :: stms, S.E_Var acc)
269                              end
270                            else doPrimApply (rator, tyArgs, args, ty)
271                        | AST.E_ParallelMap(e', x, xs, _) =>
272                            if Basis.isReductionOp rator
273                              then raise Fail "FIXME"
274                              else raise Fail "unsupported operation on parallel map"
275                        | _ => doPrimApply (rator, tyArgs, args, ty)
276                      (* end case *))
277                | AST.E_Prim(f, tyArgs, args, ty) => doPrimApply (f, tyArgs, args, ty)                | AST.E_Prim(f, tyArgs, args, ty) => doPrimApply (f, tyArgs, args, ty)
278                | AST.E_Apply((f, _), args, ty) => let                | AST.E_Apply((f, _), args, ty) => let
279                    val (stms, xs) = simplifyExpsToVars (errStrm, args, stms)                    val (stms, xs) = simplifyExpsToVars (errStrm, args, stms)
# Line 264  Line 283 
283                        | _ => raise Fail "bogus application"                        | _ => raise Fail "bogus application"
284                      (* end case *)                      (* end case *)
285                    end                    end
286                | AST.E_Comprehension(e, (x, e'), ty) => raise Fail "FIXME"                | AST.E_Comprehension(e, (x, e'), seqTy) => let
287                    (* convert a comprehension to a foreach loop over the sequence defined by e' *)
288                      val (stms, xs) = simplifyExpToVar (errStrm, e', stms)
289                      val (bodyStms, bodyResult) = simplifyExpToVar (errStrm, e, [])
290                      val seqTy' as STy.T_Sequence(elemTy, NONE) = cvtTy seqTy
291                      val acc = SimpleVar.new ("accum", Var.LocalVar, seqTy')
292                      val initStm = S.S_Assign(acc, S.E_Seq([], seqTy'))
293                      val updateStm = S.S_Assign(acc,
294                            S.E_Prim(BasisVars.at_dT, [S.TY elemTy], [acc, bodyResult], seqTy'))
295                      val foreachStm = S.S_Foreach(cvtVar x, xs, mkBlock(updateStm :: bodyStms))
296                      in
297                        (foreachStm :: initStm :: stms, S.E_Var acc)
298                      end
299                  | AST.E_ParallelMap(e, x, xs, ty) => raise Fail "FIXME"
300                | AST.E_Tensor(es, ty) => let                | AST.E_Tensor(es, ty) => let
301                    val (stms, xs) = simplifyExpsToVars (errStrm, es, stms)                    val (stms, xs) = simplifyExpsToVars (errStrm, es, stms)
302                    in                    in

Legend:
Removed from v.3463  
changed lines
  Added in v.3464

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