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 2668 - (download) (annotate)
Thu Jun 12 03:29:04 2014 UTC (5 years, 2 months ago) by cchiw
File size: 4923 byte(s)
Change global types to arrays and print them
(*This function transitions low-il operators to 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

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

    fun mkLd(aligned,vn, origTy,offset, args)=
        List.map (fn a => Dst.E_LoadVec(aligned, vn, origTy, a, Dst.E_Lit(Literal.Int offset))) args


    fun getLd(pieces, 0, rator, argsS, args, origTy,aligned)= let
        fun createOps ([], _, code) = code
          | createOps (vn::es, offset, code)=let
            val args' =mkLd(aligned,vn, origTy, offset, args)
            val exp = Dst.E_Op(rator vn, argsS@args')
            in
                createOps (es, offset + IntInf.fromInt vn, code@[exp])
            end
        in
            createOps (pieces, 0, [])
        end

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


    fun mkFromP([],_,lhs, aligned,splitTy, _)=[]
      | mkFromP(n::pieces,indexAt,lhs,aligned,splitTy, code::es)=
        mkFromP(pieces,indexAt + IntInf.fromInt n, lhs, aligned,splitTy,es)@
        [Dst.S_Assign([lhs],mkVec(aligned,n,n,indexAt,splitTy,code))]
    


    fun filled([n],lhs, aligned,origTy,splitTy, [code])=
        [Dst.S_Assign([lhs],mkVec(aligned,n,origTy,0,splitTy,code))]
      | filled _=raise Fail"Too man pieces for fillVec"


    fun creatLd(lhs,rator,n,origTy,pieces,argsS,args,f)= let
        val splitTy=DstTy.vectorLength pieces
        val aligned=(case f
            of true=>false
            | _ => true (*add more here *)
            (**))

        val code=getLd(pieces, 0,rator,argsS,args,origTy,aligned)
        
        val exp=(case (rator n)
            of DstOp.sumVec _ => [Dst.S_Assign([lhs],addSca code)]
                (*already checked for vector types*)
            | _ => (case f
                    of true =>filled(pieces,lhs,aligned,origTy,splitTy, code)
                    |_ => mkFromP(pieces, 0,lhs, aligned,  splitTy, code)
            (*end case*)))
        val _=(case testing
            of 1=>(print((String.concatWith "," (List.map Dst.toStringS exp))^"\n\n");1)
            |_ =>1)
        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