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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3595 - (view) (download)

1 : cchiw 2845 (* Expands probe ein
2 :     *
3 : jhr 3349 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     *
5 :     * COPYRIGHT (c) 2015 The University of Chicago
6 : cchiw 2845 * All rights reserved.
7 :     *)
8 :    
9 :     structure handleEin = struct
10 :    
11 :     local
12 :    
13 :     structure E = Ein
14 :     structure DstIL = MidIL
15 :     structure P=Printer
16 :     structure MidToS=MidToString
17 : cchiw 3459 structure L=LiftEin
18 : cchiw 2845 in
19 :    
20 : cchiw 3503 val liftflag=true
21 : cchiw 3557 val splitflag=false
22 : cchiw 3595 val splitlimit=NONE
23 : cchiw 3503 val testinitial=0
24 : cchiw 3259 val testing=0
25 : cchiw 2845 fun testp n=(case testing
26 :     of 0=> 1
27 :     | _ =>(print(String.concat n);1)
28 :     (*end case*))
29 : cchiw 3166 fun test0 n=(case testinitial
30 : cchiw 3203 of 0=>testp n
31 : cchiw 3166 | _ => (print(String.concat n);1))
32 : cchiw 3324 fun toStringBind e= MidToS.toStringBind e
33 : cchiw 3271 fun useCount (HighIL.V{useCnt, ...}) = !useCnt
34 :     fun expandEinOp (srcy,bind00)=let
35 : cchiw 3540 (*val _= raise Fail"development branch- do not use"*)
36 : cchiw 3489
37 : cchiw 3033 val star="************"
38 : cchiw 3415 val _= ("\n Start"^star)
39 : cchiw 3260 val _ =test0[star,"\n Original EinApp",star,"\n\n","start get test",toStringBind bind00]
40 : cchiw 3203 val (y,einapp as DstIL.EINAPP(Ein.EIN{params, index, body},args))=bind00
41 : cchiw 3166
42 : cchiw 3033
43 :     (* ************* Sweep for 0's'*********** *)
44 : cchiw 3441 val _ =testp["Pre Sweep\n",P.printbody body,"\n"]
45 : cchiw 3203 val bodysweep=sweepEin.sweep body
46 : cchiw 3033 val ein1=Ein.EIN{params=params, index=index, body=bodysweep}
47 : cchiw 3441 val _ =testp["Post Sweep\n",P.printbody bodysweep,"\n"]
48 : cchiw 3033
49 :    
50 : cchiw 3203 (* ************** distribute and push Summation*********** *)
51 :     val bind3 = (y,DstIL.EINAPP(SummationEin.main ein1,args))
52 : cchiw 3260 val _ =testp["\n\n summation \n\n =>", toStringBind bind3]
53 : cchiw 3033
54 : cchiw 3472 (* **************** lift - split ************* *)
55 : cchiw 3459 val newbies5= (case (splitflag,liftflag,splitlimit)
56 : cchiw 3472 of (true,false,NONE) => Split.splitEinApp bind3
57 :     (* **************** split phase ************* *)
58 :     | (true,false,SOME limit) =>let
59 : cchiw 3503 val _ = (String.concat["\nSPLit with limit",Int.toString(limit)])
60 : cchiw 3472 in Split.limitSplit(bind3,limit) end
61 : cchiw 3459 | (true,true,SOME limit) => let
62 :     (* **************** lift and split Limit ************* *)
63 : cchiw 3503 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 : cchiw 3540 val _ = testp["\n split made pieces(",Int.toString(length(e2)-length(e2a)),") orig (", Int.toString(length(newbies4)),")"]
71 : cchiw 3459 in (e2@newbies4) end
72 :     | (true,true, NONE) => let
73 :     (* **************** lift and split All ************* *)
74 : cchiw 3503 val (einapp1,e2a,_)=L.testLift bind3
75 : cchiw 3540 val _ = testp["\n **** lift Length"^(Int.toString(length(e2a)))]
76 : cchiw 3503 val e2= List.foldr op@ [] (List.map (fn t=>Split.splitEinApp t) e2a)
77 : cchiw 3459 val newbies4=Split.splitEinApp einapp1
78 : cchiw 3540 val _ = testp["\n split made pieces(",Int.toString(length(e2)-length(e2a)),") orig (", Int.toString(length(newbies4)),")"]
79 : cchiw 3459 in (e2@newbies4) end
80 :     | (false,true,_) => let
81 : cchiw 3573 (*
82 : cchiw 3557 val (einapp1,e2,_)=L.testLift bind3
83 :     val _ = print("\n **** lift Length"^(Int.toString(length(e2))))
84 : cchiw 3459 in (e2@[einapp1]) end
85 : cchiw 3573 *)
86 :     val k=FloatEin.transform bind3
87 :     in List.map (fn MidIL.ASSGN(i)=> i ) k end
88 : cchiw 3459 | (false,false,_)=>Split.splitEinApp bind3
89 : cchiw 3557
90 : cchiw 3459 (* end case *))
91 : cchiw 3503 val _ = "************** TASH"
92 : cchiw 3415 (**************** printing result ***************)
93 : cchiw 3557 val _ =testp["\n\n Returning \n\n =>", String.concatWith",\n\t"(List.map toStringBind newbies5)]
94 : cchiw 3415 val n =length(newbies5)
95 : cchiw 3573 val _ = if (n > 1) then print(String.concat["\n **** SPLIT Length",Int.toString(n)]) else print""
96 : cchiw 3166 (* ************** ProbeEIN *********** *)
97 : cchiw 3189 (*gives probeEIN the set. Could split into a sepearate step*)
98 : cchiw 3503 val fieldset= einVarSet.EinVarSet.empty
99 :     val varset= einVarSet.VarSet.empty
100 : cchiw 3271 val isField = ref 0
101 :     val isFieldR = ref 0
102 :     val isReplaced = ref 0
103 : cchiw 3503 fun iter([],_,_)=[]
104 :     | iter(e1::es,fieldset,varset)= let
105 :     val (e2,fieldset,varset,isFieldt,isReplacedt) = ProbeEin.expandEinOp(e1,fieldset,varset)
106 :     val rtn=[e2]@(iter(es,fieldset,varset))
107 : cchiw 3271 val isFieldRt=if ((isFieldt+isReplacedt)=2) then 1 else 0
108 :     in (isField:=(!isField)+isFieldt;isReplaced:=(!isReplaced )+isReplacedt;
109 :     isFieldR:=(!isFieldR)+isFieldRt;rtn)
110 :     end
111 : cchiw 3503 val code=iter(newbies5, fieldset,varset)
112 :     val flatcode= List.foldr op@ [] code
113 : cchiw 3271
114 :     val n= List.length(code)
115 : cchiw 3503 val m= List.length(flatcode)
116 : cchiw 3540 val _ =(String.concat["\n",HighIL.Var.name srcy ," Pieces",Int.toString (m),"\n"])
117 : cchiw 3503
118 : cchiw 3271 val _ = if (n>5)
119 : cchiw 3540 then testp["\n",star,":Name:",HighIL.Var.name srcy ,
120 : cchiw 3503 ":VarCount(",Int.toString(useCount srcy),")","\n\tPieces now: ",Int.toString (n),"flatcode",Int.toString (m),
121 : cchiw 3271 " Fields:",Int.toString(!isField)," isReplaced:",Int.toString(!isReplaced),
122 : cchiw 3540 " Replaced_Fields:",Int.toString(!isFieldR)] else 1
123 : cchiw 3503
124 : cchiw 3271
125 : cchiw 3540 val flatcode= List.foldr op@ [] code
126 :     (*
127 :     val tbl0= einSet.EinSet.empty
128 :     fun getSet([],done,_,cnt)=(done,cnt)
129 :     | getSet((lhs,rhs)::es,done,opset,cnt)=let
130 :     val (opset,var) = einSet.rtnVarN(opset,(lhs,rhs))
131 :     in (case var
132 :     of NONE => getSet(es,done@[(lhs,rhs)], opset,cnt)
133 :     | SOME v=> (("replacing"^DstIL.Var.toString(lhs));getSet(es,done@[(lhs,DstIL.VAR v)], opset,cnt+1))
134 :     (*end case*))
135 :     end
136 :     val _="creating set"
137 :     val (flatcode,cnt)=getSet(flatcode, [],tbl0,0)
138 :     val _ = " post creating set"
139 :     val n=length(flatcode)
140 :     val _ = (String.concat["\n Length: ",Int.toString n," Replaced: ", Int.toString cnt,"\n"])
141 :     *)
142 : cchiw 3033 in
143 :     List.map (fn (y,rator)=> DstIL.ASSGN(y,rator)) flatcode
144 :     end
145 :    
146 : cchiw 2845 end; (* local *)
147 :    
148 :     end (* local *)

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