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

SCM Repository

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

Diff of /branches/charisee_dev/src/compiler/high-to-mid/handleEin.sml

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

branches/charisee/src/compiler/high-to-mid/handleEin.sml revision 2847, Mon Dec 15 02:17:32 2014 UTC branches/charisee_dev/src/compiler/high-to-mid/handleEin.sml revision 3369, Mon Nov 2 19:38:34 2015 UTC
# Line 1  Line 1 
1  (* Expands probe ein  (* Expands probe ein
2   *   *
3   * COPYRIGHT (c) 2012 The Diderot Project (http://diderot-language.cs.uchicago.edu)   * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
4     *
5     * COPYRIGHT (c) 2015 The University of Chicago
6   * All rights reserved.   * All rights reserved.
7   *)   *)
8    
# Line 10  Line 12 
12    
13      structure E = Ein      structure E = Ein
14      structure DstIL = MidIL      structure DstIL = MidIL
     structure DstOp = MidOps  
15      structure P=Printer      structure P=Printer
     structure T=TransformEin  
16      structure MidToS=MidToString      structure MidToS=MidToString
17      structure DstV = DstIL.Var      structure L=LiftEin
18      in      in
19    
20        val testinitial=0
21      val testing=0      val testing=0
     fun setEin(params,index,body)=Ein.EIN{params=params, index=index, body=body}  
     fun assignEinApp(y,params,index,body,args)= (y,DstIL.EINAPP(setEin(params,index,body),args))  
     fun assignEinApp(y,params,index,body,args)= (y,DstIL.EINAPP(setEin(params,index,body),args))  
       fun iTos i =Int.toString i  
22      fun testp n=(case testing      fun testp n=(case testing
23          of 0=> 1          of 0=> 1
24          | _ =>(print(String.concat n);1)          | _ =>(print(String.concat n);1)
25          (*end case*))          (*end case*))
26      val einappzero=DstIL.EINAPP(setEin([],[],E.Const 0),[])      fun test0 n=(case testinitial
27      fun setEinZero y=  (y,einappzero)          of 0=>testp n
28            | _ => (print(String.concat n);1))
29      (* isZero:ein_exp->int      fun toStringBind e= MidToS.toStringBind e
30      *  Checks to see if the entire body is 0. If so returns 1.      fun useCount (HighIL.V{useCnt, ...}) = !useCnt
31        fun expandEinOp (srcy,bind00)=let
32            (*val _=raise Fail"development branch- do not use"*)
33            val star="************"
34            val _=("\n Start"^star)
35            val _ =test0[star,"\n Original EinApp",star,"\n\n","start get test",toStringBind bind00]
36            val (y,einapp as DstIL.EINAPP(Ein.EIN{params, index, body},args))=bind00
37    
38    
39            (* ************* Sweep for 0's'*********** *)
40            val bodysweep=sweepEin.sweep body
41            val ein1=Ein.EIN{params=params, index=index, body=bodysweep}
42            val _=testp["Post Sweep\n",P.printbody bodysweep,"\n"]
43    
44    
45            (* ************** distribute and push Summation*********** *)
46            val bind3 = (y,DstIL.EINAPP(SummationEin.main ein1,args))
47            val _ =testp["\n\n summation \n\n =>", toStringBind bind3]
48    
49    (* **************** lift no split ************* *)
50    (*
51     val (einapp1,e2)=L.testLift  bind3
52    val newbies5=e2@[einapp1]
53       val _ =  print("\n **** lift Length"^(Int.toString(length(e2))))
54      *)      *)
55      fun isZero e=let      (* **************** lift field phase ************* *)
56          val _=testp["\n Started Zero",P.printbody e]  (*
57          fun iterList []= 1           val (einapp1,e2)=L.testLift  bind3
58              | iterList(e1::list)=(case (isZero e1)          val newbies5=  Split.iterAll2(einapp1,e2)
59              of 0=>0          val n =length(newbies5)
60              | _ => iterList list          val _ = if (n > 10) then print("\n **** SPLIT Length"^(Int.toString(n))) else print ""
             (*end case*))  
         fun iterProdList []= 0  
         | iterProdList(e1::list)=(case (isZero e1)  
             of 1=>1  
             | _ => iterList list  
             (*end case*))  
         val z=(case e  
             of E.Add e             => iterList e  
             | E.Sub(e1,e2)         => iterList [e1,e2]  
             | E.Div(e1,e2)         => isZero e1  
             | E.Sum(_ ,e)          => isZero e  
             | E.Prod e             => iterProdList e  
             | E.Neg e              => isZero e  
             | E.Probe(E.Conv _,_)         => 0  
             | E.Const 0            => 1  
             | E.Field _            => 1  
             | E.Partial _          => 1  
             | E.Apply _            => 1  
             | E.Lift _             => 1  
             | E.Conv _             => 1  
             | _                    => 0  
             (*end case*))  
         val _=testp["\n Is it Zero",P.printbody e,"--", iTos z]  
         in  
             z  
         end  
61    
     (*isZero: var* einapp params*index list*mid-il vars  
         When the operation is zero then we return a real.  
62          *)          *)
63      fun zeroSweep(y,einapp as DstIL.EINAPP(ein,_))=let  
64              val _ =testp["\n Starting is zero for var-",DstV.name y]          (* **************** split phase ************* *)
65              in (case (isZero(E.body ein))  
66                  of 1=>  setEinZero y          val (newbies5)= Split.splitEinApp(bind3,9)
67                  | _ =>(y,einapp)          val _ =test0["\n\n Returning \n\n =>",
68                  (*end case*))          String.concatWith",\n\t"(List.map toStringBind newbies5)]
69    
70             (* ************** ProbeEIN *********** *)
71            (*gives probeEIN the set. Could split into a sepearate step*)
72            val fieldset= einSet.EinSet.empty
73            val isField = ref 0
74            val isFieldR = ref 0
75            val isReplaced = ref 0
76            fun iter([],_)=[]
77             | iter(e1::es,fieldset)= let
78                val (e2,fieldset,isFieldt,isReplacedt) = ProbeEin.expandEinOp(e1,fieldset)
79                val rtn=[e2]@(iter(es,fieldset))
80                val isFieldRt=if ((isFieldt+isReplacedt)=2) then 1 else 0
81                in (isField:=(!isField)+isFieldt;isReplaced:=(!isReplaced )+isReplacedt;
82                isFieldR:=(!isFieldR)+isFieldRt;rtn)
83              end              end
84            val code=iter(newbies5, fieldset)
85    
86            val n= List.length(code)
87    
88              val _ = if (n>5)
89             then  print(String.concat["\n\n",star,":Name:",HighIL.Var.name srcy ,
90                ":VarCount(",Int.toString(useCount srcy),")",
91                    "\n\t",star,"Pieces now: ",Int.toString (n),
92                " Fields:",Int.toString(!isField)," isReplaced:",Int.toString(!isReplaced),
93                " Replaced_Fields:",Int.toString(!isFieldR)])
94                else  print""
95    
96    
97            val flatcode= List.foldr op@ [] code
98            (*val _=List.map (fn(_,DstIL.EINAPP(e,_))=>checkEin.checkEIN e | _=> 1) flatcode*)
99            val _=(star^"end")
100            in
101                List.map (fn (y,rator)=> DstIL.ASSGN(y,rator)) flatcode
102            end
103    
104    end; (* local *)    end; (* local *)
105    

Legend:
Removed from v.2847  
changed lines
  Added in v.3369

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