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

SCM Repository

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

View of /branches/charisee_dev/src/compiler/mid-to-low/current.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3595 - (download) (annotate)
Sat Jan 16 05:48:18 2016 UTC (4 years, 4 months ago) by cchiw
File size: 3056 byte(s)
setting 1
(*
* genfn-Does preliminary scan of the body of EIN.EIN for vectorization potential
* If there is a field then passes to FieldToLow
* If there is a tensor then passes to handle*() functions to check if indices match
* i.e. <A_ij+B_ij>_ij vs.<A_ji+B_ij>_ij
*
*     (1) If indices match then passes to Iter->VecToLow functions.
*            Creates LowIL vector operators.
*     (2) Iter->ScaToLow
*           Creates Low-IL scalar operators
* Note. The Iter function creates LowIL.CONS and therefore binds the indices in the EIN.body 
*)
structure Curent = struct
    local

    structure Var = LowIL.Var
    structure E = Ein
    structure P=Printer

    in
    
    fun testp p=(String.concat p)

    
    (*scan:var*E.Ein*Var list * Var list-> Var*LowIL.Assgn list
    *scans body  for vectorization potential
    *)
    fun scan(y,e:Ein.ein,args:LowIL.var list)= let

        val b=Ein.body e
        fun incUse (LowIL.V{useCnt, ...}) = (useCnt := !useCnt + 1)
        fun getUse (LowIL.V{useCnt, ...}) =Int.toString(!useCnt)
        fun orig()=let
            val _ =testp["\n---not generated \n\t",LowIL.Var.toString(y),"(",getUse(y),")=",P.printerE(e)]
            val _= testp (List.map (fn e=> (LowIL.Var.toString(e)^"("^ getUse(e)^"),")) args)
           (* val _ =List.map incUse args*)
            in [LowIL.ASSGN(y,LowIL.EINAPP(e,args))] end
         
         
        val _=testp["\n\n****",
            LowIL.Var.toString(y),"(",getUse(y),")=",P.printerE(e),
            String.concat(List.map (fn e=> (LowIL.Var.toString(e)^"("^ getUse(e)^"),")) args)]
        
        fun findField b=(case b
            of E.Img _ =>true
            | E.Krn _ => true
            | E.Opn(E.Prod,es)=>(case (List.find findField es)
                of NONE=> false
                | SOME _ => true)
            | E.Sum(_,e)=> findField e
            |  _ => false
            (*end case*))
        (* val _ =List.map incUse (args@[y,y])*)
        
        val rtn = (case b
            of E.Holder _ => [LowIL.ASSGN(y,LowIL.EINAPP(e,args))]
            |   _ =>
                let
                    val  (_,_,code)=    EinToLowSet.q(y,e,args)
                    (* val _=List.map (fn LowIL.ASSGN(y,_)=>incUse y) code (*fixme*)*)
                    (*need to reassign the last assgn*)
                    in (case (List.rev(code))
                    of [] => (("No code for..:"^P.printerE(e));[LowIL.ASSGN(y,LowIL.VAR(List.hd(args)))])
                    | [LowIL.ASSGN(_,B)]=>code@[LowIL.ASSGN (y,B)](* causes error without code*)
                    | (LowIL.ASSGN (a1,A)::_)   =>  (case b
                        of  (*E.Op2 (E.Sub,_,_)    => orig()
                        | E.Opn _               => orig()
                        | E.Sum(_,e)=> if(findField e) then code@[LowIL.ASSGN (y,A)] else orig()
                        |*) _ =>code@[LowIL.ASSGN (y,A)]
                        (*end case*))
                    (*end case*))
                end
        (*end case*))
            
        in rtn end
        
        

end (* local *)

end

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