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

revision 3304, Fri Oct 16 18:51:09 2015 UTC revision 3557, Fri Jan 8 19:54:58 2016 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 liftflag=true
21        val splitflag=false
22        val splitlimit=SOME 2000
23      val testinitial=0      val testinitial=0
24      val testing=0      val testing=0
25      fun testp n=(case testing      fun testp n=(case testing
# Line 26  Line 29 
29      fun test0 n=(case testinitial      fun test0 n=(case testinitial
30          of 0=>testp n          of 0=>testp n
31          | _ => (print(String.concat n);1))          | _ => (print(String.concat n);1))
32      fun toStringBind e= MidToString.toStringBind e      fun toStringBind e= MidToS.toStringBind e
33      fun useCount (HighIL.V{useCnt, ...}) = !useCnt      fun useCount (HighIL.V{useCnt, ...}) = !useCnt
34      fun expandEinOp (srcy,bind00)=let      fun expandEinOp (srcy,bind00)=let
35             (*val _= raise Fail"development branch- do not use"*)
36    
37          val star="************"          val star="************"
38            val _= ("\n Start"^star)
39          val _ =test0[star,"\n Original EinApp",star,"\n\n","start get test",toStringBind bind00]          val _ =test0[star,"\n Original EinApp",star,"\n\n","start get test",toStringBind bind00]
40          val (y,einapp as DstIL.EINAPP(Ein.EIN{params, index, body},args))=bind00          val (y,einapp as DstIL.EINAPP(Ein.EIN{params, index, body},args))=bind00
41    
42    
43          (* ************* Sweep for 0's'*********** *)          (* ************* Sweep for 0's'*********** *)
44            val _ =testp["Pre Sweep\n",P.printbody body,"\n"]
45          val bodysweep=sweepEin.sweep body          val bodysweep=sweepEin.sweep body
46          val ein1=Ein.EIN{params=params, index=index, body=bodysweep}          val ein1=Ein.EIN{params=params, index=index, body=bodysweep}
47          val _=testp["Post Sweep\n",P.printbody bodysweep,"\n"]          val _=testp["Post Sweep\n",P.printbody bodysweep,"\n"]
# Line 45  Line 51 
51          val bind3 = (y,DstIL.EINAPP(SummationEin.main ein1,args))          val bind3 = (y,DstIL.EINAPP(SummationEin.main ein1,args))
52          val _ =testp["\n\n summation \n\n =>", toStringBind bind3]          val _ =testp["\n\n summation \n\n =>", toStringBind bind3]
53    
54            (* **************** lift - split ************* *)
55            val newbies5=  (case (splitflag,liftflag,splitlimit)
56                of (true,false,NONE) => Split.splitEinApp bind3
57          (* **************** split phase ************* *)          (* **************** split phase ************* *)
58          val (newbies5)= Split.splitEinApp bind3              | (true,false,SOME limit) =>let
59          val _ =test0["\n\n Returning \n\n =>",                  val _ = (String.concat["\nSPLit with limit",Int.toString(limit)])
60              String.concatWith",\n\t"(List.map toStringBind newbies5)]                  in Split.limitSplit(bind3,limit) end
61                | (true,true,SOME limit) =>  let
62                    (* **************** lift and split Limit ************* *)
63                    val (einapp1,e2a,fieldset)=L.testLift  bind3
64                    val _ = (String.concat["\nSPLit with limit",Int.toString(limit),"\n **** lift Length:",Int.toString(length(e2a))])
65    
66                   (* val t2=List.map (fn t=>Split.splitEinApp t) e2*)
67                    val t2=List.map (fn t =>Split.limitSplit2(t,limit,fieldset)) e2a
68                    val e2= List.foldr op@ [] t2
69                    val newbies4=Split.limitSplit2(einapp1,limit,fieldset)
70                    val _ = testp["\n split made pieces(",Int.toString(length(e2)-length(e2a)),") orig (", Int.toString(length(newbies4)),")"]
71                    in (e2@newbies4) end
72                | (true,true, NONE) => let
73                    (* **************** lift and split All ************* *)
74                    val (einapp1,e2a,_)=L.testLift  bind3
75                    val _ =  testp["\n **** lift Length"^(Int.toString(length(e2a)))]
76                    val e2= List.foldr op@ [] (List.map (fn t=>Split.splitEinApp t) e2a)
77                    val newbies4=Split.splitEinApp einapp1
78                    val _ = testp["\n split made pieces(",Int.toString(length(e2)-length(e2a)),") orig (", Int.toString(length(newbies4)),")"]
79                    in (e2@newbies4) end
80                | (false,true,_) => let
81                    val (einapp1,e2,_)=L.testLift  bind3
82                    val _ = print("\n **** lift Length"^(Int.toString(length(e2))))
83                    in (e2@[einapp1]) end
84                |  (false,false,_)=>Split.splitEinApp bind3
85    
86            (* end case *))
87            val _ = "************** TASH"
88            (**************** printing result ***************)
89            val _ =testp["\n\n Returning \n\n =>", String.concatWith",\n\t"(List.map toStringBind newbies5)]
90            val n =length(newbies5)
91            val _ = if (n > 1000) then print(String.concat["\n **** SPLIT Length",Int.toString(n)]) else print""
92           (* ************** ProbeEIN *********** *)           (* ************** ProbeEIN *********** *)
         (*val code=List.map (fn e=>ProbeEin.expandEinOp e) (newbies5)*)  
   
93          (*gives probeEIN the set. Could split into a sepearate step*)          (*gives probeEIN the set. Could split into a sepearate step*)
94          val fieldset= einSet.EinSet.empty          val fieldset= einVarSet.EinVarSet.empty
95            val varset= einVarSet.VarSet.empty
96          val isField = ref 0          val isField = ref 0
97          val isFieldR = ref 0          val isFieldR = ref 0
98          val isReplaced = ref 0          val isReplaced = ref 0
99          fun iter([],_)=[]          fun iter([],_,_)=[]
100           | iter(e1::es,fieldset)= let           | iter(e1::es,fieldset,varset)= let
101              val (e2,fieldset,isFieldt,isReplacedt) = ProbeEin.expandEinOp(e1,fieldset)              val (e2,fieldset,varset,isFieldt,isReplacedt) = ProbeEin.expandEinOp(e1,fieldset,varset)
102              val rtn=[e2]@(iter(es,fieldset))              val rtn=[e2]@(iter(es,fieldset,varset))
103              val isFieldRt=if ((isFieldt+isReplacedt)=2) then 1 else 0              val isFieldRt=if ((isFieldt+isReplacedt)=2) then 1 else 0
104              in (isField:=(!isField)+isFieldt;isReplaced:=(!isReplaced )+isReplacedt;              in (isField:=(!isField)+isFieldt;isReplaced:=(!isReplaced )+isReplacedt;
105              isFieldR:=(!isFieldR)+isFieldRt;rtn)              isFieldR:=(!isFieldR)+isFieldRt;rtn)
106              end              end
107          val code=iter(newbies5, fieldset)          val code=iter(newbies5, fieldset,varset)
108            val flatcode= List.foldr op@ [] code
109    
110          val n= List.length(code)          val n= List.length(code)
111            val m= List.length(flatcode)
112            val _ =(String.concat["\n",HighIL.Var.name srcy ," Pieces",Int.toString (m),"\n"])
113    
114            val _ = if (n>5)            val _ = if (n>5)
115           then  (String.concat["\n\n",star,":Name:",HighIL.Var.name srcy ,            then  testp["\n",star,":Name:",HighIL.Var.name srcy ,
116              ":VarCount(",Int.toString(useCount srcy),")",              ":VarCount(",Int.toString(useCount srcy),")","\n\tPieces now: ",Int.toString (n),"flatcode",Int.toString (m),
                 "\n\t",star,"Pieces now: ",Int.toString (n),  
117              " Fields:",Int.toString(!isField)," isReplaced:",Int.toString(!isReplaced),              " Fields:",Int.toString(!isField)," isReplaced:",Int.toString(!isReplaced),
118              " Replaced_Fields:",Int.toString(!isFieldR)              " Replaced_Fields:",Int.toString(!isFieldR)] else 1
                ,toStringBind bind3])  
             else  ""  
119    
         val flatcode= List.foldr op@ [] code  
         (*val _=List.map (fn(_,DstIL.EINAPP(e,_))=>checkEin.checkEIN e | _=> 1) flatcode*)  
120    
121            val flatcode= List.foldr op@ [] code
122    (*
123            val tbl0= einSet.EinSet.empty
124            fun getSet([],done,_,cnt)=(done,cnt)
125             | getSet((lhs,rhs)::es,done,opset,cnt)=let
126                    val (opset,var) = einSet.rtnVarN(opset,(lhs,rhs))
127                    in  (case var
128                        of NONE => getSet(es,done@[(lhs,rhs)], opset,cnt)
129                        | SOME v=> (("replacing"^DstIL.Var.toString(lhs));getSet(es,done@[(lhs,DstIL.VAR v)], opset,cnt+1))
130                        (*end case*))
131                    end
132            val _="creating set"
133            val (flatcode,cnt)=getSet(flatcode, [],tbl0,0)
134            val _ = " post creating set"
135            val n=length(flatcode)
136            val _ = (String.concat["\n Length: ",Int.toString n," Replaced: ", Int.toString cnt,"\n"])
137    *)
138          in          in
139              List.map (fn (y,rator)=> DstIL.ASSGN(y,rator)) flatcode              List.map (fn (y,rator)=> DstIL.ASSGN(y,rator)) flatcode
140          end          end

Legend:
Removed from v.3304  
changed lines
  Added in v.3557

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