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

SCM Repository

[diderot] Diff of /branches/charisee/src/compiler/high-to-mid/split.sml
ViewVC logotype

Diff of /branches/charisee/src/compiler/high-to-mid/split.sml

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

revision 2922, Tue Mar 3 03:55:09 2015 UTC revision 2923, Tue Mar 3 15:33:44 2015 UTC
# Line 42  Line 42 
42      fun isZero e=handleE.isZero e      fun isZero e=handleE.isZero e
43      fun sweep e=handleE.sweep e      fun sweep e=handleE.sweep e
44      fun itos i =Int.toString i      fun itos i =Int.toString i
45        fun filterSca e=Filter.filterSca e
46      fun err str=raise Fail str      fun err str=raise Fail str
47      val cnt = ref 0      val cnt = ref 0
48      fun genName prefix = let      fun genName prefix = let
# Line 197  Line 198 
198      * calls rewriteOp() lift  on ein_exp      * calls rewriteOp() lift  on ein_exp
199      *)      *)
200      fun handleDiv(y,e1,e2,params,index,args)=let      fun handleDiv(y,e1,e2,params,index,args)=let
201          val (e1',params1',args1',code1')=rewriteOp(DstV.name y,e1,params,index,[],args)          val (e1',params1',args1',code1')=rewriteOp("div-num",e1,params,index,[],args)
202          val (e2',params2',args2',code2')=rewriteOp("div",e2,params1',[],[],args1')          val (e2',params2',args2',code2')=rewriteOp("div-denom",e2,params1',index,[],args1')
203            (*val (e2',params2',args2',code2')=rewriteOp("div-denom",e2,params1',[],[],args1')*)
204          val body =E.Div(e1',e2')          val body =E.Div(e1',e2')
205          val einapp= rewriteOrig(y,body,params2',index,[],args2')          val einapp= rewriteOrig(y,body,params2',index,[],args2')
206          in          in
# Line 243  Line 245 
245        note we leave summation around probe exp        note we leave summation around probe exp
246      *)      *)
247      fun split(y,einapp as DstIL.EINAPP(Ein.EIN{params, index, body},args))=let      fun split(y,einapp as DstIL.EINAPP(Ein.EIN{params, index, body},args))=let
   
248          val zero=   (setEinZero y,[])          val zero=   (setEinZero y,[])
249          val default=((y,einapp),[])          val default=((y,einapp),[])
250          val sumIndex=ref []          val sumIndex=ref []
# Line 268  Line 269 
269              | E.PowReal e1               => handlePowReal(y,e1,params,index,args)              | E.PowReal e1               => handlePowReal(y,e1,params,index,args)
270              | E.Sub (e1,e2)           => handleSub(y,e1,e2,params,index,args)              | E.Sub (e1,e2)           => handleSub(y,e1,e2,params,index,args)
271              | E.Div (e1,e2)           => handleDiv(y,e1,e2,params,index,args)              | E.Div (e1,e2)           => handleDiv(y,e1,e2,params,index,args)
272                | E.Sum(sx,E.Tensor(id,[]))=> rewrite (E.Tensor(id,[]))
273                | E.Sum(sx,E.Const c)      =>rewrite ( E.Const c )
274                | E.Sum(sx,E.ConstR r)    => rewrite (E.ConstR r)
275              | E.Sum(sx,E.Neg n)       => rewrite (E.Neg(E.Sum(sx,n)))              | E.Sum(sx,E.Neg n)       => rewrite (E.Neg(E.Sum(sx,n)))
276              | E.Sum(sx,E.Add a)       => rewrite (E.Add(List.map (fn e=> E.Sum(sx,e)) a))              | E.Sum(sx,E.Add a)       => rewrite (E.Add(List.map (fn e=> E.Sum(sx,e)) a))
277              | E.Sum(sx,E.Sub (e1,e2)) => rewrite (E.Sub(E.Sum(sx,e1),E.Sum(sx,e2)))              | E.Sum(sx,E.Sub (e1,e2)) => rewrite (E.Sub(E.Sum(sx,e1),E.Sum(sx,e2)))
# Line 295  Line 299 
299          end          end
300          |split(y,app) =((y,app),[])          |split(y,app) =((y,app),[])
301    
302    
303        (*Distribute summation if needed*)
304        fun distributeSummation(y,einapp as DstIL.EINAPP(Ein.EIN{params, index, body},args))=let
305        fun rewrite b=(case b
306            of E.Sum(sx,E.Tensor(id,[]))    => E.Tensor(id,[])
307            | E.Sum(sx,E.Const c)           => E.Const c
308            | E.Sum(sx,E.ConstR r)          => E.ConstR r
309            | E.Sum(sx,E.Neg n)             => rewrite(E.Neg(E.Sum(sx,n)))
310            | E.Sum(sx,E.Add a)             => rewrite(E.Add(List.map (fn e=> E.Sum(sx,e)) a))
311            | E.Sum(sx,E.Sub (e1,e2))       => rewrite(E.Sub(E.Sum(sx,e1),E.Sum(sx,e2)))
312            | E.Sum(sx,E.Div(e1,e2))        => rewrite( E.Div(E.Sum(sx,e1),E.Sum(sx,e2)))
313            | E.Sum(sx,E.Lift e )           => rewrite (E.Lift(E.Sum(sx,e)))
314            | E.Sum(sx,E.PowReal(e,n1))     => rewrite(E.PowReal(E.Sum(sx,e),n1))
315            | E.Sum(sx,E.Sqrt e)            => rewrite(E.Sqrt(E.Sum(sx,e)))
316            | E.Sum(sx,E.Sum (c2,e))        => rewrite (E.Sum (sx@c2,e))
317            | E.Sum(sx,E.Prod p)            => let
318                    val (c,e)=filterSca(sx,p)
319                    in e end
320            | E.Div(e1,e2)                  => E.Div(rewrite e1, rewrite e2)
321            | E.Sub(e1,e2)                  => E.Sub(rewrite e1, rewrite e2)
322            | E.Add es                      => E.Add(List.map rewrite es)
323            | E.Prod es                     => E.Prod(List.map rewrite es)
324            | E.Neg e                       => E.Neg(rewrite e)
325            | E.Sqrt e                      => E.Sqrt(rewrite e)
326            | _                             => b
327        (*end case*))
328        val body =rewrite body
329        val ein=SummationEin.cleanSummation(Ein.EIN{params=params, index=index, body=body})
330        val einapp2= (y,DstIL.EINAPP(ein,args))
331        in
332            split(einapp2)
333        end
334        |distributeSummation(y,app) =((y,app),[])
335    
336    
337    
338      (* iterMultiple:code*code=> (code*code)      (* iterMultiple:code*code=> (code*code)
339       * recursively split ein expression into smaller pieces       * recursively split ein expression into smaller pieces
340      *)      *)
341      fun iterMultiple(einapp2,newbies2)=let      fun iterMultiple(einapp2,newbies2)=let
342          fun itercode([],rest,code)=(rest,code)          fun itercode([],rest,code)=(rest,code)
343          | itercode(e1::newbies,rest,code)=let          | itercode(e1::newbies,rest,code)=let
344              val (einapp3,code3) =split(e1)              val (einapp3,code3) =(*split(e1)*) distributeSummation e1
345                val _ =testp["\n\n******* split ***** \n",printEINAPP(e1),"\n=>\n",printEINAPP(einapp3),"\nand\n",(String.concatWith",\n\t"(List.map printEINAPP code3))]
346              val (rest4,code4)=itercode(code3,[],[])              val (rest4,code4)=itercode(code3,[],[])
347              in itercode(newbies,rest@[einapp3],code4@rest4@code)              in itercode(newbies,rest@[einapp3],code4@rest4@code)
348              end              end
# Line 311  Line 352 
352          end          end
353    
354      fun iterSplit(y,einapp as DstIL.EINAPP(Ein.EIN{params, index, body},args))=let      fun iterSplit(y,einapp as DstIL.EINAPP(Ein.EIN{params, index, body},args))=let
355          (*)val _ =print(String.concat["\n******\n",printEINAPP (y,einapp)])*)          val bodysweep=handleE.sweep body
356          val b=handleE.sweep body          val _=testp["\n\n Sweep\n",P.printbody bodysweep,"\n"]
357          val einapp2=assignEinApp(y,params,index,b,args)          val ein=SummationEin.cleanSummation(Ein.EIN{params=params, index=index, body=bodysweep})
358          val (einapp3,newbies2)=split einapp2          val _=testp["\n\n Clean Summation\n",P.printbody(Ein.body ein),"\n"]
359            val einapp2=(y,DstIL.EINAPP(ein, args))
360                (*assignEinApp(y,params,index,body,args)*)
361            val (einapp3,newbies2)=distributeSummation einapp2
362      in      in
363          iterMultiple(einapp3,newbies2)          iterMultiple(einapp3,newbies2)
364      end      end
# Line 326  Line 370 
370          of 0=>iterSplit(einapp)          of 0=>iterSplit(einapp)
371          | _=>let          | _=>let
372              val star="\n************* SPLIT********\n"              val star="\n************* SPLIT********\n"
373              val _ =print(String.concat[star,"\n","start get test",printEINAPP einapp])              val _ =testp[star,"\n","start get test",printEINAPP einapp]
374              val (einapp2,newbies)=iterSplit(einapp)              val (einapp2,newbies)=iterSplit(einapp)
375              (*val a=printEINAPP einapp2              val _ =testp["\n\n Returning \n\n =>",printEINAPP einapp2,
376              val b=String.concatWith",\n\t"(List.map printEINAPP newbies)                      " newbies\n\t",String.concatWith",\n\t"(List.map printEINAPP newbies), "\n",star]
             val _ =print(String.concat[printEINAPP einapp,"=>",a," newbies\n\t",b, "\n",a,star])*)  
377              in              in
378                  (einapp2,newbies)                  (einapp2,newbies)
379              end              end

Legend:
Removed from v.2922  
changed lines
  Added in v.2923

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