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 3383 - (download) (annotate)
Mon Nov 9 02:39:26 2015 UTC (3 years, 10 months ago) by cchiw
File size: 4449 byte(s)
cut vector fields
(* 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 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 _=print ("\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 _ =(String.concat["Pre Sweep\n",P.printbody body,"\n"])
        val bodysweep=sweepEin.sweep body
        val ein1=Ein.EIN{params=params, index=index, body=bodysweep}
        val _ =(String.concat["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 no split ************* *)
(*
 val (einapp1,e2)=L.testLift  bind3
val newbies5=e2@[einapp1]
   val _ =  print("\n **** lift Length"^(Int.toString(length(e2))))
*)

    (* **************** lift field phase ************* *)

         val (einapp1,e2)=L.testLift  bind3
   val _ =  print("\n **** lift Length"^(Int.toString(length(e2))))
        val newbies5=  Split.iterAll2(einapp1,e2)
        val n =length(newbies5)
        val _ = if (n > 10) then print("\n **** SPLIT Length"^(Int.toString(n))) else print ""



        (* **************** split phase ************* *)
(*
        val (newbies5)= Split.splitEinApp(bind3,9)
        val _ =test0["\n\n Returning \n\n =>",
        String.concatWith",\n\t"(List.map toStringBind newbies5)]
*)
val _=print"probein\n"
         (* ************** ProbeEIN *********** *)
        (*gives probeEIN the set. Could split into a sepearate step*)
        val fieldset= einSet.EinSet.empty
        val isField = ref 0
        val isFieldR = ref 0
        val isReplaced = ref 0
        fun iter([],_)=[]
         | iter(e1::es,fieldset)= let
            val (e2,fieldset,isFieldt,isReplacedt) = ProbeEin.expandEinOp(e1,fieldset)
            val rtn=[e2]@(iter(es,fieldset))
            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)

        val n= List.length(code)

          val _ = if (n>5)
          then  print(String.concat["\n\n",star,":Name:",HighIL.Var.name srcy ,
            ":VarCount(",Int.toString(useCount srcy),")",
                "\n\t",star,"Pieces now: ",Int.toString (n),
            " Fields:",Int.toString(!isField)," isReplaced:",Int.toString(!isReplaced),
            " Replaced_Fields:",Int.toString(!isFieldR)])
            else print ""

    val flatcode= List.foldr op@ [] code

(*
    (*added extra step*)
    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=> getSet(es,done@[(lhs,DstIL.VAR v)], opset,cnt+1)
            (*end case*))
        end
     
       val (flatcode,cnt)=getSet(flatcode, [],tbl0,0)

       val n=length(flatcode)
        val _ =print(String.concat["\n Length: ",Int.toString n," Replaced: ", Int.toString cnt,
                "\n",DstIL.Var.toString(y),"\n"])

*)
        (*val _=List.map (fn(_,DstIL.EINAPP(e,_))=>checkEin.checkEIN e | _=> 1) flatcode*)
        val _=(star^"end")
        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