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

SCM Repository

[diderot] View of /branches/charisee/src/compiler/tree-il/lowOp-to-treeOp.sml
ViewVC logotype

View of /branches/charisee/src/compiler/tree-il/lowOp-to-treeOp.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2671 - (download) (annotate)
Fri Jul 18 18:57:06 2014 UTC (5 years ago) by cchiw
File size: 6806 byte(s)
MkVec2, takes multiple expressions
(*This function transitions low-il operators to tree-il operators *)
 (*creates the Tree-IL operators*)
structure LowOpToTreeOp = struct
local

    structure SrcOp = LowOps
    structure DstOp = TreeOps
    structure SrcTy = LowILTypes
    structure DstTy = TreeILTypes
    structure Dst = TreeIL

in

    val testing=1

   
    (**************************************)
    (*Create Op and Ld expressions*)
   
    fun mkOps1(rator,origTy,pieces,argScas,argVecs,aligned)= let
        fun createOps ([], _, code) = code
          | createOps (vn::es, offset, code)=let
            val argsLd =List.map (fn a => Dst.E_LoadVec(aligned, vn, origTy, a, Dst.E_Lit(Literal.Int offset))) argVecs
            val exp = Dst.E_Op(rator vn, argScas@argsLd)
            in
                createOps (es, offset + IntInf.fromInt vn, code@[exp])
            end
    in
        createOps (pieces, 0, [])
    end


    (*Second Attempt. Creates Loads for each arguement then the rest*)
    fun mkOps2(rator,origTy, pieces, argScas,argVecs,aligned)=let
        fun inc ([],_,_)=[]
          | inc(vn::es, offset,a) =
            [Dst.E_LoadVec(aligned, vn, origTy, a, Dst.E_Lit(Literal.Int offset))]@
            inc(es, offset+ IntInf.fromInt vn,a)
        val lds=List.map (fn a => inc(pieces, 0,a)) argVecs
        fun mkOp([]::_, exps,_)=List.rev exps
          | mkOp (args, exps,p::ps)= let
            val (args'', rest)=List.foldr
            (fn (x::xs,(args', rest))=> (x::args',xs::rest)) ([],[]) args
            in
                mkOp(rest, [Dst.E_Op(rator p, args'')]@exps,ps)
            end
        in
            mkOp(lds,[],pieces)
        end


    (**************************************)
    (*mk Vecs*)
    fun mkVec(aligned,from,to,indexAt,splitTy,code) =
        Dst.E_mkVec(aligned,from,to, Dst.E_Lit(Literal.Int indexAt),splitTy,code)

    (*addSca function used for sumVec function *)
    fun addSca [e1]=e1
      | addSca(e1::e2::es)= addSca([Dst.E_Op(DstOp.addSca,[e1,e2])]@es)


    fun multipleMkVec(lhs,rator,n,origTy,pieces,isFill,aligned,splitTy,ops)=let
        (*make Assign Statements*)
        fun mkFromP([],_,_,_,_)=[]
          | mkFromP(n::pieces,indexAt,splitTy, code::es,aligned)=
            mkFromP(pieces,indexAt + IntInf.fromInt n, splitTy,es,aligned)@
            [mkVec(aligned,n,n,indexAt,splitTy,code)]
    in (case rator n
        of DstOp.sumVec _ => [addSca ops]
        | _ => (case (isFill,pieces,ops)
            of (true,[n],[ops]) =>[mkVec(aligned,n,origTy,0,splitTy,ops)] (*FillVec*)
            |(_,_,_) => mkFromP(pieces, 0, splitTy, ops,aligned)
            (*end case*))
        (*end case*))
    end

    (**************************************)
    (*mk Assignments*)

    (*Creates Multiple Assignments*)
    (*This will create an assign for each mkVec*)
    fun multipleAssn(lhs,rator,n,origTy,pieces,isFill,aligned,splitTy,ops)=let
        val mk=multipleMkVec(lhs,rator,n,origTy,pieces,isFill,aligned,splitTy,ops)
    in
        List.map (fn a=> Dst.S_Assign([lhs],a)) mk
    end

    (*This will create a single mkVec*)
    (*x=MkVec [2,4] [Add 2, Add4]:  a single mkVec: pieces, and exp list*)
    fun mkAssn(lhs,rator,n,origTy,pieces,isFill,aligned,splitTy,ops)=let
        val a= Dst.E_mkVec2(aligned,n,n, Dst.E_Lit(Literal.Int 0),splitTy,ops)
    in
        [Dst.S_Assign([lhs],a)]
    end


    (* This will create assignments with multiple mkVec*)
    (*x=[MkVec 2(Add 2), mkVec 4(Add 4)] Multiple mkVecs *)

    (**************************************)
    fun isAligned isFill = (case isFill
        of true=>false
        | _ => true
    (*end case*))
    fun printExp exp=(case testing
        of 1=>(print((String.concatWith "," (List.map Dst.toStringS exp))^"\n\n");1)
        |_ =>1
    (*end case*))

    (*Main functions*)
    fun vecToTree(lhs,rator,n,origTy,pieces,argScas,argVecs,isFill)= let
        val splitTy=DstTy.vectorLength pieces
        val aligned= isAligned isFill
        val ops=mkOps2(rator,origTy,pieces,argScas,argVecs,aligned)

        (*Assign here *)
        val exp1= multipleAssn(lhs,rator,n,origTy,pieces,isFill,aligned,splitTy,ops)
        val exp=mkAssn(lhs,rator,n,origTy,pieces,isFill,aligned,splitTy,ops)
        val _=printExp exp
        in
            exp
        end

        (**************************************)

    (*Low-IL operators to Tree-IL operators*)
    fun expandOp rator=(case rator
        of SrcOp.IAdd  =>    DstOp.IAdd
        | SrcOp.ISub  =>    DstOp.ISub
        | SrcOp.IMul  =>    DstOp.IMul
        | SrcOp.IDiv  =>    DstOp.IDiv
        | SrcOp.INeg  =>    DstOp.INeg
        | SrcOp.Abs ty =>    DstOp.Abs ty
        | SrcOp.LT ty =>    DstOp.LT  ty
        | SrcOp.LTE ty =>    DstOp.LTE  ty
        | SrcOp.EQ ty =>    DstOp.EQ  ty
        | SrcOp.NEQ ty =>    DstOp.NEQ  ty
        | SrcOp.GT ty =>    DstOp.GT  ty
        | SrcOp.GTE ty =>    DstOp.GTE  ty
        | SrcOp.Not =>    DstOp.Not
        | SrcOp.Max =>    DstOp.Max
        | SrcOp.Min =>    DstOp.Min
        | SrcOp.Clamp ty =>    DstOp.Clamp ty
        | SrcOp.Lerp ty =>    DstOp.Lerp  ty
        | SrcOp.Zero ty =>    DstOp.Zero  ty
        | SrcOp.PrincipleEvec ty =>    DstOp.PrincipleEvec ty
        | SrcOp.EigenVals2x2 =>    DstOp.EigenVals2x2
        | SrcOp.EigenVals3x3 =>    DstOp.EigenVals3x3
        | SrcOp.Select(ty as SrcTy.TupleTy tys, i)  =>    DstOp.Select( ty, i)
        | SrcOp.Index (ty, i ) =>    DstOp.Index ( ty, i)
        | SrcOp.Subscript ty =>    DstOp.Subscript  ty
        | SrcOp.Ceiling d =>    DstOp.Ceiling d
        | SrcOp.Floor d =>    DstOp.Floor d
        | SrcOp.Round d =>    DstOp.Round d
        | SrcOp.Trunc d =>    DstOp.Trunc d
        | SrcOp.IntToReal =>    DstOp.IntToReal
        | SrcOp.RealToInt d =>    DstOp.RealToInt d
        (*| SrcOp.VoxelAddress( info, offset)  => expandVoxelAddress  (y, info, offset, args')
        | SrcOp.LoadVoxels (rty, d ) =>    DstOp.LoadVoxels( rty, d)*)
        | SrcOp.Kernel h =>    DstOp.Kernel h
        | SrcOp.LoadImage info =>    DstOp.LoadImage info
        | SrcOp.Inside info =>    DstOp.Inside info
        | SrcOp.Transform V=>    DstOp.Transform V
        | SrcOp.Translate V=>  DstOp.Translate V
        | SrcOp.addSca =>DstOp.addSca
        | SrcOp.subSca=>DstOp.subSca
        | SrcOp.prodSca=>DstOp.prodSca
        | SrcOp.divSca=>DstOp.divSca
        | SrcOp.Sqrt =>DstOp.Sqrt
        (*Still need to sort *)
        | SrcOp.IndexTensor e=> DstOp.IndexTensor e
        | SrcOp.imgAddr(v,indexAt, dim)=>DstOp.imgAddr(v, indexAt, dim)
        | SrcOp.imgLoad(v,dim,n)=>DstOp.imgLoad(v,dim,n)

        (*EigenVecs,mkDynamic, Append,Prepend, Concat,Length,ImageAddress,LoadVoxel,Inputs, and Pritns*)
        | rator => raise Fail ("bogus operator " ^ SrcOp.toString rator)
  (* end case *))
end;
end

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