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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2794, Tue Nov 4 20:04:14 2014 UTC revision 2795, Tue Nov 4 21:58:11 2014 UTC
# Line 21  Line 21 
21           |_ =>1           |_ =>1
22      (*end case*))      (*end case*))
23    
24    
25    fun pisAligned true=print "\n isAligned is true"
26    |pisAligned  _ =print "\n isAligned is false"
27      (**************************************)      (**************************************)
28      (*assignment, store-statement*)      (*assignment, store-statement*)
29      fun mkStmt(lhs,lhsKind,rator,nSize,oSize,A,splitTy,ops)= (case (rator nSize)  
30          of DstOp.sumVec _ => Dst.S_Assign([lhs], addSca ops)      fun mkStmt(lhs,lhsKind,origrator,isFill,oSize,A,splitTy,ops)= (case origrator
31          | DstOp.dotVec _  => Dst.S_Assign([lhs], addSca ops)          of SrcOp.sumVec _ => Dst.S_Assign([lhs], addSca ops)
32              | _               => (case (lhsKind,ops,nSize=oSize)          | SrcOp.dotVec _  => Dst.S_Assign([lhs], addSca ops)
33              of(TreeIL.VK_Local,_,_) =>  Dst.S_Assign([lhs], Dst.E_Mux(A,nSize,oSize,splitTy,ops))          | _               => (case lhsKind
34              | (_,_,_)=> Dst.S_StoreVec(Dst.E_Var lhs,A,nSize,oSize,splitTy,ops)              of TreeIL.VK_Local  =>  Dst.S_Assign([lhs], Dst.E_Mux(A,isFill,oSize,splitTy,ops))
35                | _ => Dst.S_StoreVec(Dst.E_Var lhs,A,isFill,oSize,Ty.TensorTy[oSize],splitTy, ops)
36              (*end case*))              (*end case*))
37              (*end case*))              (*end case*))
   
38      and addSca [e1]=e1      and addSca [e1]=e1
39      | addSca(e1::e2::es)= addSca([Dst.E_Op(DstOp.addSca,[e1,e2])]@es)      | addSca(e1::e2::es)= addSca([Dst.E_Op(DstOp.addSca,[e1,e2])]@es)
40    
# Line 41  Line 44 
44          fun getExp (Dst.E_Var a) =(case ( DstV.kind a,DstV.ty a)          fun getExp (Dst.E_Var a) =(case ( DstV.kind a,DstV.ty a)
45              of (TreeIL.VK_Local,Ty.TensorTy [nv]) =>              of (TreeIL.VK_Local,Ty.TensorTy [nv]) =>
46                  if (nv=nSize) then t                  if (nv=nSize) then t
47                  else (*raise Fail "Vector operation is not the right size"*)                  else  raise Fail "Vector operation is not the right size"
                    Dst.E_LoadVec(aligned, nSize, oSize,t, Dst.E_Lit(Literal.Int offset))  
             | (TreeIL.VK_Local,_) => t  
48              | (_,_) => Dst.E_LoadArr(aligned, nSize,oSize,t, Dst.E_Lit(Literal.Int offset))              | (_,_) => Dst.E_LoadArr(aligned, nSize,oSize,t, Dst.E_Lit(Literal.Int offset))
49              (*end case*))              (*end case*))
50          | getExp (Dst.E_Mux(_,_,_,_,ops))= List.nth(ops,count)          | getExp (Dst.E_Mux(_,_,_,_,ops))= List.nth(ops,count)
51            | getExp _ = raise Fail"Arg is not Mux or Var"
         | getExp(Dst.E_Holder(arrVar,[v1]))=Dst.E_Var arrVar (*Actually shouldn't happen for matrices. Projection(Holder)=>Vector*)  
                                                             (*so must only have vectors *)  
         | getExp _ = t  
52      in      in
53          getExp t          getExp t
54      end      end
55      and mkOps(lhsKind,rator,oSize,pieces,argScas,argVecs,aligned,indexAt)= let      and mkOps(lhsKind,SrcOp.ProjectTensor(_,_,Ty.indexTy[i],Ty.TensorTy[_,argTyX]),_,oSize,pieces,[],argVecs,aligned,indexAt)=let
56            (*Use Load expression instead of Project Operator *)
57             val j=i*argTyX
58            fun createOps ([], _,_, code) = code
59              | createOps (nSize::es, count,offset, code)=let
60                    val exps=List.map (fn a =>Dst.E_LoadArr(aligned, nSize,oSize,a, Dst.E_Lit(Literal.Int offset)))  argVecs
61                in
62                    createOps (es, count+1,offset + IntInf.fromInt nSize, code@exps)
63                end
64        in
65            createOps (pieces, 0,IntInf.fromInt j, [])
66        end
67        | mkOps(lhsKind,SrcOp.sumVec _,_,oSize,[nSize],argScas,argVecs,aligned,indexAt)=let
68            val argsLd =List.map (fn a =>getArg(lhsKind,a,0, aligned, nSize, oSize, 0))  argVecs
69            in
70                [Dst.E_Op(DstOp.sumVec(nSize,oSize), argScas@argsLd)]
71            end
72        | mkOps(lhsKind,SrcOp.sumVec _,_,oSize,pieces,argScas,argVecs,aligned,indexAt)=let
73          fun createOps ([], _,_, code) = code          fun createOps ([], _,_, code) = code
74            | createOps (nSize::es, count,offset, code)=let            | createOps (nSize::es, count,offset, code)=let
75              val argsLd =List.map (fn a =>getArg(lhsKind,a,count, aligned, nSize, oSize, offset))  argVecs              val argsLd =List.map (fn a =>getArg(lhsKind,a,count, aligned, nSize, oSize, offset))  argVecs
76              val exp = Dst.E_Op(rator nSize, argScas@argsLd)              val exp = Dst.E_Op(DstOp.sumVec(nSize,nSize), argScas@argsLd)
77              in              in
78                  createOps (es, count+1,offset + IntInf.fromInt nSize, code@[exp])                  createOps (es, count+1,offset + IntInf.fromInt nSize, code@[exp])
79              end              end
80      in      in
81          createOps (pieces, 0,indexAt, [])          createOps (pieces, 0,indexAt, [])
82      end      end
83      and mkCons(pieces,args)= let      | mkOps(lhsKind,_,rator,oSize,pieces,argScas,argVecs,aligned,indexAt)= let
84          fun createOps ([], _,_, _,_) = []          fun createOps ([], _,_, code) = code
85          | createOps (nSize::es, count,offset,arg, code)=          | createOps (nSize::es, count,offset, code)=let
86              [Dst.E_Cons(Ty.TensorTy [nSize], nSize,List.take(arg,nSize))]@              val argsLd =List.map (fn a =>getArg(lhsKind,a,count, aligned ,nSize, oSize, offset))  argVecs
87                  createOps (es, count+1,offset + IntInf.fromInt nSize, List.drop(arg,nSize),code)              val exp = Dst.E_Op(rator nSize, argScas@argsLd)
88          in          in
89              createOps (pieces, 0,0,args, [])                      createOps (es, count+1,offset + IntInf.fromInt nSize, code@[exp])
90          end          end
     and mkFillCons(nSize,nOrig,args)=let  
         val nArg=length(args)  
         in if(nSize>nArg) then let  
             val n=nSize-nArg  
             val newArgs=List.tabulate(n, (fn _=>Dst.E_Lit(Literal.Int 0)))  
91              in              in
92                  Dst.E_Cons(Ty.TensorTy [nSize], nOrig,args@newArgs)              createOps (pieces, 0,indexAt, [])
             end  
             else raise Fail( "more args then new size")  
93          end          end
   
   
   
   
   
   
94      (**************************************)      (**************************************)
     (*If it is matrix then we need to add offset to indexAt*)  
     fun matInt( n, m,a, b )=(m*b+a)  
     fun isMatrix2([Dst.E_Op(DstOp.IndexTensor(_,DstTy.TensorTy [_], DstTy.indexTy [fast], DstTy.TensorTy[argTyY,argTyX]),m)],rest)= let  
         val indexAt=matInt(argTyY,argTyX,0,fast)  
         in  
             (indexAt,rest@m)  
         end  
     | isMatrix2(Dst.E_Op(DstOp.IndexTensor(_,DstTy.TensorTy [_], DstTy.indexTy [fast], DstTy.TensorTy[argTyY,argTyX]),m)::es,rest)=  
         isMatrix2(es, rest@m)  
     | isMatrix2(a,[])=(0, a)  
     | isMatrix2 _=raise Fail"Should be projection"  
95    
96    
     (**************************************)  
   
97      fun isAligned isFill = (case isFill      fun isAligned isFill = (case isFill
98          of true=>false  of true=>(print "isAligned is false";false)
99          | _ => true  | _ =>(print "isAligned is true" ;true)
100      (*end case*))      (*end case*))
   
101          (**************************************)          (**************************************)
102      (*Main functions*)      (*Main functions*)
103      fun vecToTree(lhs,rator,nSize,oSize,pieces,argScas,argVecs,isFill)= let      fun vecToTree(lhs,origrator,rator,nSize,oSize,pieces,argScas,argVecs,isFill)= let
   
104          val splitTy=DstTy.vectorLength pieces          val splitTy=DstTy.vectorLength pieces
   
         (*val (indexAt', argVecs)=isMatrix2(argV',[])*)  
   
         val lhsKind=DstV.kind lhs  
         val _ =testp ["\n\t LHS ",Dst.kindToString lhsKind,"- Var:",DstV.name lhs]  
105          val aligned= isAligned isFill          val aligned= isAligned isFill
         val indexAt=IntInf.fromInt 0  
106    
107            val indexAt=IntInf.fromInt 0
108          (*Create Ld Expressions and Tree Ops*)          (*Create Ld Expressions and Tree Ops*)
109          val ops=mkOps(lhsKind,rator,oSize,pieces,argScas,argVecs,aligned,indexAt)          val lhsKind=DstV.kind lhs
110            val ops=mkOps(lhsKind,origrator,rator,oSize,pieces,argScas,argVecs,aligned,indexAt)
111      in      in
112          mkStmt( lhs,lhsKind,rator,nSize,oSize,aligned,splitTy,ops)          mkStmt(lhs,lhsKind,origrator,isFill,oSize,aligned,splitTy,ops)
113      end      end
114    
115    
116      (*isFIll is true, and there is one piece, use mkFillCons*)      (* consVecToTree()
117      fun consVecToTree(nSize,oSize,[piece],args,true)= let       * Takes Cons of a vector and returns Mux Expression
118          val _ =print "\n in consVecToTree isFull true \n"       *)
119          val op1= mkFillCons(piece,oSize,args)      fun consVecToTree(_,oSize,[nSize],args,true)= let
120            val nArg=length(args)
121            val n=nSize-nArg
122            val newArgs=List.tabulate(n, (fn _=>Dst.E_Lit(Literal.Int 0)))
123            val op1=Dst.E_Cons(nSize, oSize,args@newArgs)
124          val aligned= isAligned true          val aligned= isAligned true
125          val splitTy=DstTy.vectorLength [nSize]          val splitTy=DstTy.vectorLength [nSize]
126          in          in
127                  Dst.E_Mux(aligned,nSize,oSize,splitTy,[op1])              Dst.E_Mux(aligned,true,oSize,splitTy,[op1])
128          end          end
129      | consVecToTree(_,_,_,_,true)= raise Fail"isFill with more than 1 piece"      | consVecToTree(_,_,_,_,true)= raise Fail"In ConsVecToTree-isFill with more than 1 piece"
130      | consVecToTree(nSize,oSize,pieces,args,isFill)= (case mkCons(pieces,args)      | consVecToTree(nSize,oSize,pieces,args,isFill)= let
         of (*[op1]=>op1  
         | *)ops => let  
131              val aligned= isAligned isFill              val aligned= isAligned isFill
132              val splitTy=DstTy.vectorLength pieces              val splitTy=DstTy.vectorLength pieces
133            fun createOps ([], _,_, _,_) = []
134            | createOps (nSize::es, count,offset,arg, code)=
135                [Dst.E_Cons(nSize, nSize,List.take(arg,nSize))]@
136                createOps (es, count+1,offset + IntInf.fromInt nSize, List.drop(arg,nSize),code)
137            val ops= createOps (pieces, 0,0,args, [])
138              in              in
139                  Dst.E_Mux(aligned,nSize,oSize,splitTy,ops)              Dst.E_Mux(aligned,isFill,oSize,splitTy,ops)
140              end              end
         (*end case*))  
   
141    
142          (**************************************)          (**************************************)
143    

Legend:
Removed from v.2794  
changed lines
  Added in v.2795

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