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 2845, Fri Dec 12 06:46:23 2014 UTC branches/charisee_dev/src/compiler/high-to-mid/handleEin.sml revision 3383, Mon Nov 9 02:39:26 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 testing=1      val testinitial=0
21      fun setEin(params,index,body)=Ein.EIN{params=params, index=index, body=body}      val testing=0
     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        fun toStringBind e= MidToS.toStringBind e
30        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 _=print ("\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 _ =(String.concat["Pre Sweep\n",P.printbody body,"\n"])
41            val bodysweep=sweepEin.sweep body
42            val ein1=Ein.EIN{params=params, index=index, body=bodysweep}
43            val _ =(String.concat["Post Sweep\n",P.printbody bodysweep,"\n"])
44    
45    
46            (* ************** distribute and push Summation*********** *)
47            val bind3 = (y,DstIL.EINAPP(SummationEin.main ein1,args))
48            val _ =testp["\n\n summation \n\n =>", toStringBind bind3]
49    
50    (* **************** lift no split ************* *)
51    (*
52     val (einapp1,e2)=L.testLift  bind3
53    val newbies5=e2@[einapp1]
54       val _ =  print("\n **** lift Length"^(Int.toString(length(e2))))
55    *)
56    
57        (* **************** lift field phase ************* *)
58    
59             val (einapp1,e2)=L.testLift  bind3
60       val _ =  print("\n **** lift Length"^(Int.toString(length(e2))))
61            val newbies5=  Split.iterAll2(einapp1,e2)
62            val n =length(newbies5)
63            val _ = if (n > 10) then print("\n **** SPLIT Length"^(Int.toString(n))) else print ""
64    
65    
66      (* isZero:ein_exp->int  
67      *  Checks to see if the entire body is 0. If so returns 1.          (* **************** split phase ************* *)
68    (*
69            val (newbies5)= Split.splitEinApp(bind3,9)
70            val _ =test0["\n\n Returning \n\n =>",
71            String.concatWith",\n\t"(List.map toStringBind newbies5)]
72      *)      *)
73      fun isZero e=let  val _=print"probein\n"
74          val _=print(String.concat["\n Started Zero",P.printbody e])           (* ************** ProbeEIN *********** *)
75          fun iterList []= 1          (*gives probeEIN the set. Could split into a sepearate step*)
76              | iterList(e1::list)=(case (isZero e1)          val fieldset= einSet.EinSet.empty
77              of 0=>0          val isField = ref 0
78              | _ => iterList list          val isFieldR = ref 0
79              (*end case*))          val isReplaced = ref 0
80          fun iterProdList []= 0          fun iter([],_)=[]
81          | iterProdList(e1::list)=(case (isZero e1)           | iter(e1::es,fieldset)= let
82              of 1=>1              val (e2,fieldset,isFieldt,isReplacedt) = ProbeEin.expandEinOp(e1,fieldset)
83              | _ => iterList list              val rtn=[e2]@(iter(es,fieldset))
84              (*end case*))              val isFieldRt=if ((isFieldt+isReplacedt)=2) then 1 else 0
85          val z=(case e              in (isField:=(!isField)+isFieldt;isReplaced:=(!isReplaced )+isReplacedt;
86              of E.Add e             => iterList e              isFieldR:=(!isFieldR)+isFieldRt;rtn)
             | 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 _=print(String.concat["\n Is it Zero",P.printbody e,"--", iTos z])  
         in  
             z  
87          end          end
88            val code=iter(newbies5, fieldset)
89    
90      (*isZero: var* einapp params*index list*mid-il vars          val n= List.length(code)
91          When the operation is zero then we return a real.  
92          *)            val _ = if (n>5)
93      fun zeroSweep(y,einapp as DstIL.EINAPP(ein,_))=let            then  print(String.concat["\n\n",star,":Name:",HighIL.Var.name srcy ,
94              val _ =testp["\n Starting is zero for var-",DstV.name y]              ":VarCount(",Int.toString(useCount srcy),")",
95              in (case (isZero(E.body ein))                  "\n\t",star,"Pieces now: ",Int.toString (n),
96                  of 1=>  setEinZero y              " Fields:",Int.toString(!isField)," isReplaced:",Int.toString(!isReplaced),
97                  | _ =>(y,einapp)              " Replaced_Fields:",Int.toString(!isFieldR)])
98                else print ""
99    
100        val flatcode= List.foldr op@ [] code
101    
102    (*
103        (*added extra step*)
104        val tbl0= einSet.EinSet.empty
105        fun getSet([],done,_,cnt)=(done,cnt)
106          | getSet((lhs,rhs)::es,done,opset,cnt)=let
107            val (opset,var) = einSet.rtnVarN(opset,(lhs,rhs))
108            in  (case var
109                of NONE => getSet(es,done@[(lhs,rhs)], opset,cnt)
110                | SOME v=> getSet(es,done@[(lhs,DstIL.VAR v)], opset,cnt+1)
111                  (*end case*))                  (*end case*))
112              end              end
113    
114           val (flatcode,cnt)=getSet(flatcode, [],tbl0,0)
115    
116           val n=length(flatcode)
117            val _ =print(String.concat["\n Length: ",Int.toString n," Replaced: ", Int.toString cnt,
118                    "\n",DstIL.Var.toString(y),"\n"])
119    
120    *)
121            (*val _=List.map (fn(_,DstIL.EINAPP(e,_))=>checkEin.checkEIN e | _=> 1) flatcode*)
122            val _=(star^"end")
123            in
124                List.map (fn (y,rator)=> DstIL.ASSGN(y,rator)) flatcode
125            end
126    
127    end; (* local *)    end; (* local *)
128    

Legend:
Removed from v.2845  
changed lines
  Added in v.3383

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