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/tree-to-opr.sml
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2695 - (download) (annotate)
Fri Sep 12 01:55:00 2014 UTC (4 years, 11 months ago) by cchiw
File size: 4106 byte(s)
change to vector ops
(* TreeIL stmt to (types, opr) sets *)

structure TreeToOpr= struct

    structure Op = TreeOps
    structure Ty = TreeILTypes
    structure IL=TreeIL
    structure Fnc=TreeFunc
    structure TySet=Fnc.TySet
    structure OprSet=Fnc.OprSet
     structure V = IL.Var

    fun vecTy n= Ty.TensorTy[n]

  (* GetTypes TreeIL operator. *)
    val default=([],[])

    (*stmt-> sets(TySet, OprSet)*)
    fun TypeofOp rator = (case rator
        of  Op.IndexTensor(a,RTy,b,c)=>([RTy],    [])
        | Op.addVec d               => ([vecTy d],[Fnc.OP(Op.addVec d)])
        | Op.subVec d               => ([vecTy d],[Fnc.OP(Op.subVec d)])
        | Op.prodVec d              => ([vecTy d],[Fnc.OP(Op.prodVec d)])
        | Op.prodScaV d             => ([vecTy d],[Fnc.CONSV d,Fnc.OP(Op.prodScaV d)])
        | Op.dotVec d               => ([vecTy d],[Fnc.OP(Op.dotVec d)]) 
        | Op.Floor d                => ([vecTy d],[Fnc.OP(Op.Floor d)])
        | Op.imgLoad(_,_,d)         => ([vecTy d],[Fnc.CONS(vecTy d)])
        | Op.sumVec d               => (([Ty.unionTy d],[Fnc.OP(Op.sumVec d)]))
        | _ => default
        (* end case *))
    and getKind [x] =SOME(V.kind x)
      | getKind _= NONE

    and expToOpr(v,set1,exp)=(case exp
        of IL.E_State _                 => set1
        | IL.E_Var _                    => set1
        | IL.E_Lit _                    => set1
        | IL.E_Mux _                    => set1
        | IL.E_Apply (_, exps)          => addToSet(v,set1,default,exps)
        | IL.E_Cons (ty as Ty.TensorTy[n], exps)         => addToSet(v,set1,([ty], [Fnc.CONSV n]),exps)
        | IL.E_Cons (ty, exps)         => addToSet(v,set1,([ty], []),exps)

        | IL.E_LoadArr(A,fTy,oTy,exp,_) => let
                (*addToSet(v,set1,([vecTy fTy],[Fnc.LDArr(A,fTy,oTy,true)]),[exp])*)
            val rtntype =(case (getKind v)
                of SOME(TreeIL.VK_Local) =>false
                | _=> false
                (*end case*))
            in
                addToSet(v,set1,([vecTy fTy],[Fnc.LDArr(A,fTy,oTy,true)]),[exp])
            end
         | IL.E_LoadVec(A,fTy,oTy,exp,_) =>  addToSet(v,set1,([vecTy fTy],[Fnc.LDArr(A,fTy,oTy,false)]),[exp])
        | IL.E_Op(Op, exps)             => addToSet(v,set1,TypeofOp Op, exps)
        (*end case*))
    and addToSet(v,set1,(typ,cfn),rest)= let
        val (ty1,opr1)=set1
        val opr2=List.foldr (fn(e1,e2) =>OprSet.add(e2,e1)) opr1 cfn
        val ty2=List.foldr (fn(e1,e2) =>TySet.add(e2,e1)) ty1 typ
        val sets2=(ty2,opr2)
        in
             List.foldr (fn(e1,e2) => expToOpr(v,e2,e1)) sets2 rest
        end
    and stmtToOpr(set1,stmt)=(case stmt
        of IL.S_Input (_,_,_, NONE)     => set1
        |  IL.S_Assign ([x],IL.E_Cons(ty as Ty.TensorTy[n], exp))=> addToSet([x],set1, ([ty],[Fnc.CONSV n]),exp)
        |  IL.S_Assign (v,exp)          => expToOpr(v,set1,exp)
        | IL.S_IfThen(exp,_)            => expToOpr([],set1,exp)
        | IL.S_IfThenElse( exp,_,_)     => expToOpr([],set1,exp)
        | IL.S_LoadImage(v,_, exp)      => expToOpr([],set1,exp)
        | IL.S_Input (v,_,_, SOME exp ) => expToOpr([v],set1,exp)
        | IL.S_Save(_,exp)              => expToOpr([],set1,exp) (*FIX ME*)
        | IL.S_New (_, exps)            => List.foldr (fn(e1,e2)=> expToOpr([],e2,e1)) set1 exps
        | IL.S_Exit exps                => List.foldr (fn(e1,e2)=> expToOpr([],e2,e1)) set1 exps
        | IL.S_StoreVec(_,A,nSize,oSize,Ty.vectorLength pieces,exps) => let
            val typ=[vecTy oSize,Ty.unionTy oSize]
            val fnc=List.map (fn p => Fnc.STORE (A,p,oSize)) pieces
            in
                addToSet([],set1, (typ,fnc),exps)
            end
        | IL.S_Cons(x,origTy,ty, exp)=>addToSet([x],set1,([],[Fnc.CONS(ty)]),exp) (*calls array function*)
        | _                             => set1
    (*end case*))
(*
and stmtToOpr(set1,stmt)= let
   
        val (tset,fset)=stmtToOpr2(set1,stmt)
        val _ =print (String.concat["\n in tree to oprs: ",IL.toStringS stmt,"\n\t",Fnc.setToString(tset,fset,"\nFresh")])
        in (tset,fset)
        end
*)
end

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