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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3557 - (download) (annotate)
Fri Jan 8 19:54:58 2016 UTC (3 years, 9 months ago) by cchiw
File size: 6280 byte(s)
added hard limit to float size
(* Expands probe ein
 *
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 *
 * COPYRIGHT (c) 2015 The University of Chicago
 * All rights reserved.
 *)

structure handleEin = struct

    local
   
    structure E = Ein
    structure DstIL = MidIL
    structure P=Printer
    structure MidToS=MidToString
    structure L=LiftEin
    in

    val liftflag=true
    val splitflag=false
    val splitlimit=SOME 2000
    val testinitial=0
    val testing=0
    fun testp n=(case testing
        of 0=> 1
        | _ =>(print(String.concat n);1)
        (*end case*))
    fun test0 n=(case testinitial
        of 0=>testp n
        | _ => (print(String.concat n);1))
    fun toStringBind e= MidToS.toStringBind e
    fun useCount (HighIL.V{useCnt, ...}) = !useCnt
    fun expandEinOp (srcy,bind00)=let
         (*val _= raise Fail"development branch- do not use"*)

        val star="************"
        val _= ("\n Start"^star)
        val _ =test0[star,"\n Original EinApp",star,"\n\n","start get test",toStringBind bind00]
        val (y,einapp as DstIL.EINAPP(Ein.EIN{params, index, body},args))=bind00
      

        (* ************* Sweep for 0's'*********** *)
        val _ =testp["Pre Sweep\n",P.printbody body,"\n"]
        val bodysweep=sweepEin.sweep body
        val ein1=Ein.EIN{params=params, index=index, body=bodysweep}
        val _ =testp["Post Sweep\n",P.printbody bodysweep,"\n"]


        (* ************** distribute and push Summation*********** *)
        val bind3 = (y,DstIL.EINAPP(SummationEin.main ein1,args))
        val _ =testp["\n\n summation \n\n =>", toStringBind bind3]

        (* **************** lift - split ************* *)
        val newbies5=  (case (splitflag,liftflag,splitlimit)
            of (true,false,NONE) => Split.splitEinApp bind3
            (* **************** split phase ************* *)
            | (true,false,SOME limit) =>let
                val _ = (String.concat["\nSPLit with limit",Int.toString(limit)])
                in Split.limitSplit(bind3,limit) end
            | (true,true,SOME limit) =>  let
                (* **************** lift and split Limit ************* *)
                val (einapp1,e2a,fieldset)=L.testLift  bind3
                val _ = (String.concat["\nSPLit with limit",Int.toString(limit),"\n **** lift Length:",Int.toString(length(e2a))])

               (* val t2=List.map (fn t=>Split.splitEinApp t) e2*)
                val t2=List.map (fn t =>Split.limitSplit2(t,limit,fieldset)) e2a
                val e2= List.foldr op@ [] t2
                val newbies4=Split.limitSplit2(einapp1,limit,fieldset)
                val _ = testp["\n split made pieces(",Int.toString(length(e2)-length(e2a)),") orig (", Int.toString(length(newbies4)),")"]
                in (e2@newbies4) end
            | (true,true, NONE) => let
                (* **************** lift and split All ************* *)
                val (einapp1,e2a,_)=L.testLift  bind3
                val _ =  testp["\n **** lift Length"^(Int.toString(length(e2a)))]
                val e2= List.foldr op@ [] (List.map (fn t=>Split.splitEinApp t) e2a)
                val newbies4=Split.splitEinApp einapp1
                val _ = testp["\n split made pieces(",Int.toString(length(e2)-length(e2a)),") orig (", Int.toString(length(newbies4)),")"]
                in (e2@newbies4) end
            | (false,true,_) => let
                val (einapp1,e2,_)=L.testLift  bind3
                val _ = print("\n **** lift Length"^(Int.toString(length(e2))))
                in (e2@[einapp1]) end
            |  (false,false,_)=>Split.splitEinApp bind3

        (* end case *))
        val _ = "************** TASH"
        (**************** printing result ***************)
        val _ =testp["\n\n Returning \n\n =>", String.concatWith",\n\t"(List.map toStringBind newbies5)]
        val n =length(newbies5)
        val _ = if (n > 1000) then print(String.concat["\n **** SPLIT Length",Int.toString(n)]) else print""
         (* ************** ProbeEIN *********** *)
        (*gives probeEIN the set. Could split into a sepearate step*)
        val fieldset= einVarSet.EinVarSet.empty
        val varset= einVarSet.VarSet.empty
        val isField = ref 0
        val isFieldR = ref 0
        val isReplaced = ref 0
        fun iter([],_,_)=[]
         | iter(e1::es,fieldset,varset)= let
            val (e2,fieldset,varset,isFieldt,isReplacedt) = ProbeEin.expandEinOp(e1,fieldset,varset)
            val rtn=[e2]@(iter(es,fieldset,varset))
            val isFieldRt=if ((isFieldt+isReplacedt)=2) then 1 else 0
            in (isField:=(!isField)+isFieldt;isReplaced:=(!isReplaced )+isReplacedt;
            isFieldR:=(!isFieldR)+isFieldRt;rtn)
            end
        val code=iter(newbies5, fieldset,varset)
        val flatcode= List.foldr op@ [] code

        val n= List.length(code)
        val m= List.length(flatcode)
        val _ =(String.concat["\n",HighIL.Var.name srcy ," Pieces",Int.toString (m),"\n"])

          val _ = if (n>5)
          then  testp["\n",star,":Name:",HighIL.Var.name srcy ,
            ":VarCount(",Int.toString(useCount srcy),")","\n\tPieces now: ",Int.toString (n),"flatcode",Int.toString (m),
            " Fields:",Int.toString(!isField)," isReplaced:",Int.toString(!isReplaced),
            " Replaced_Fields:",Int.toString(!isFieldR)] else 1


        val flatcode= List.foldr op@ [] code
(*
        val tbl0= einSet.EinSet.empty
        fun getSet([],done,_,cnt)=(done,cnt)
         | getSet((lhs,rhs)::es,done,opset,cnt)=let
                val (opset,var) = einSet.rtnVarN(opset,(lhs,rhs))
                in  (case var
                    of NONE => getSet(es,done@[(lhs,rhs)], opset,cnt)
                    | SOME v=> (("replacing"^DstIL.Var.toString(lhs));getSet(es,done@[(lhs,DstIL.VAR v)], opset,cnt+1))
                    (*end case*))
                end
        val _="creating set"
        val (flatcode,cnt)=getSet(flatcode, [],tbl0,0)
        val _ = " post creating set"
        val n=length(flatcode)
        val _ = (String.concat["\n Length: ",Int.toString n," Replaced: ", Int.toString cnt,"\n"])
*)
        in
            List.map (fn (y,rator)=> DstIL.ASSGN(y,rator)) flatcode
        end

  end; (* local *)

end (* local *)

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