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

SCM Repository

[diderot] Diff of /branches/lamont/src/compiler/simplify/reduction-lift.sml
ViewVC logotype

Diff of /branches/lamont/src/compiler/simplify/reduction-lift.sml

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

branches/lamont/src/compiler/simplify/reduction_lift.sml revision 2257, Wed Mar 6 11:25:43 2013 UTC branches/lamont/src/compiler/simplify/reduction-lift.sml revision 2298, Fri Mar 15 22:18:22 2013 UTC
# Line 1  Line 1 
1  (* reduction_lift.sml  (* reduction-lift.sml
2   *   *
3   * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)   * COPYRIGHT (c) 2013 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4   * All rights reserved.   * All rights reserved.
5   *   *
6   * Lift reduction operations into its own block.   * Lift reduction operations into its own block.
# Line 29  Line 29 
29              end              end
30      in      in
31        fun newGlobalR (r,ty) = Var.new (Atom.atom (genName(String.concat["r_",r])), AST.GlobalVar,ty)        fun newGlobalR (r,ty) = Var.new (Atom.atom (genName(String.concat["r_",r])), AST.GlobalVar,ty)
32      end      end (* local *)
33    
34      fun reductionToString(r) = (case r      fun reductionToString(r) = (case r
35       of S.R_Max => "max"       of S.R_Max => "max"
# Line 39  Line 39 
39        | S.R_Product => "product"        | S.R_Product => "product"
40        | S.R_Mean => "mean"        | S.R_Mean => "mean"
41        | S.R_Variance => "variance"        | S.R_Variance => "variance"
42        | S.R_Sum => "sum")              | S.R_Sum => "sum"
43              (* end case *))
44    
45      fun transform (errStrm,prog as S.Program{globals,globalInit as S.Block(globalInitStms), init, strands,globalBlock,inputs,...}) = let      fun transform (errStrm, prog) = let
46              val S.Program{
47                      globals, globalInit as S.Block globalInitStms,
48                      init, strands, globalBlock, inputs, ...
49                    } = prog
50      val globals' = ref []      val globals' = ref []
51      val globalReduc = ref []      val globalReduc = ref []
52      val newGlobalBlock = ref []      val newGlobalBlock = ref []
53      val globalInit' = ref[]      val globalInit' = ref[]
   
54      fun reduceBlock (S.Block stms) = S.Block(List.rev (reduceStmts(stms,[])))      fun reduceBlock (S.Block stms) = S.Block(List.rev (reduceStmts(stms,[])))
   
55      and reduceStmts ((stm::stms),stms') = (case stm      and reduceStmts ((stm::stms),stms') = (case stm
56            of S.S_Foreach(v,e,b) => reduceStmts(stms,S.S_Foreach(v, e, reduceBlock b)::stms')            of S.S_Foreach(v,e,b) => reduceStmts(stms,S.S_Foreach(v, e, reduceBlock b)::stms')
57             | S.S_IfThenElse(v,b1,b2) => reduceStmts(stms,S.S_IfThenElse(v,reduceBlock b1, reduceBlock b2)::stms')             | S.S_IfThenElse(v,b1,b2) => reduceStmts(stms,S.S_IfThenElse(v,reduceBlock b1, reduceBlock b2)::stms')
58             | S.S_Assign (lhs,rhs) =>  reduceStmts(stms,S.S_Assign(lhs,reduceAssign(rhs))::stms')                    | S.S_Assign(lhs, rhs) => reduceStmts(stms, S.S_Assign(lhs, reduceAssign rhs)::stms')
59             | _ => reduceStmts(stms,stm::stms')             | _ => reduceStmts(stms,stm::stms')
60              (*end case *))              (*end case *))
61        | reduceStmts ([],stms') = stms'        | reduceStmts ([],stms') = stms'
   
   
62    and reduceAssign rhs = (case rhs    and reduceAssign rhs = (case rhs
63          of S.E_Reduction(r,sv,reduceStms,x'',ty,argTy) => let          of S.E_Reduction(r,sv,reduceStms,x'',ty,argTy) => let
64             fun initReduction(r) = (case r                        fun initReduction r = (case r
65              of S.R_All => S.E_Lit(Literal.Bool(true))                               of S.R_All => S.E_Lit(Literal.Bool true)
66               | S.R_Exists => S.E_Lit(Literal.Bool(false))                                | S.R_Exists => S.E_Lit(Literal.Bool false)
67               | S.R_Min => S.E_Lit(Literal.Float(FloatLit.posInf))               | S.R_Min => S.E_Lit(Literal.Float(FloatLit.posInf))
68               | S.R_Max => S.E_Lit(Literal.Float(FloatLit.negInf))               | S.R_Max => S.E_Lit(Literal.Float(FloatLit.negInf))
69               | S.R_Product => S.E_Lit(Literal.Float(FloatLit.fromInt 1))               | S.R_Product => S.E_Lit(Literal.Float(FloatLit.fromInt 1))
# Line 70  Line 71 
71               | S.R_Mean => S.E_Lit(Literal.Float (FloatLit.fromInt 0))               | S.R_Mean => S.E_Lit(Literal.Float (FloatLit.fromInt 0))
72               | S.R_Variance => S.E_Lit(Literal.Float (FloatLit.fromInt 0))               | S.R_Variance => S.E_Lit(Literal.Float (FloatLit.fromInt 0))
73               (* end case *))               (* end case *))
74                          val newGlobalVar = newGlobalR(reductionToString r, argTy)
            val newGlobalVar = newGlobalR(reductionToString(r),argTy)  
75             val reductionStm = S.S_Assign(newGlobalVar,S.E_Reduction(r,sv,reduceStms,x'',ty,argTy))             val reductionStm = S.S_Assign(newGlobalVar,S.E_Reduction(r,sv,reduceStms,x'',ty,argTy))
76             in             in
77                globals' := newGlobalVar::(!globals');                globals' := newGlobalVar::(!globals');
# Line 80  Line 80 
80                newGlobalBlock := (!newGlobalBlock) @ List.rev(reduceStms);                newGlobalBlock := (!newGlobalBlock) @ List.rev(reduceStms);
81                S.E_Var(newGlobalVar)                S.E_Var(newGlobalVar)
82             end             end
83           | _ => rhs)                    | _ => rhs
84                    (* end case *))
85      val S.Block(globalInit'') = globalInit      val S.Block(globalInit'') = globalInit
86      val S.Block(globalBlock') =  reduceBlock(globalBlock)      val S.Block(globalBlock') =  reduceBlock(globalBlock)
87      val globalBlock' = (!newGlobalBlock)@((!globalReduc) @ globalBlock')      val globalBlock' = (!newGlobalBlock)@((!globalReduc) @ globalBlock')
88          val prog' =            val prog' = S.Program{
           S.Program{  
89                  strands = strands,                  strands = strands,
90                  globals = globals@ (!globals'),                  globals = globals@ (!globals'),
91                  globalInit = S.Block(globalInit'' @ (!globalInit')),                  globalInit = S.Block(globalInit'' @ (!globalInit')),
92          globalBlock = S.Block(globalBlock'),          globalBlock = S.Block(globalBlock'),
         globalReduce = S.Block([]),  
93                  init = init,                  init = init,
94          inputs = inputs          inputs = inputs
95              }              }

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

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