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 2679, Tue Jul 29 04:18:35 2014 UTC revision 2680, Wed Aug 6 00:51:53 2014 UTC
# Line 8  Line 8 
8      structure SrcTy = LowILTypes      structure SrcTy = LowILTypes
9      structure DstTy = TreeILTypes      structure DstTy = TreeILTypes
10      structure Dst = TreeIL      structure Dst = TreeIL
11    structure VTree = TreeIL.Var
12    structure VLow = LowIL.Var
13    
14  in  in
15    
16      val testing=1      val testing=1
17    
18    
19    
20    
21        (*to string functions *)
22        fun  varToKind(str,t)= (case VTree.kind t
23            of TreeIL.VK_Local => String.concat[str,"(",VTree.toString t, ")- is a local"]
24            | _ => String.concat[str,"(",VTree.toString t, ")-is not a local"]
25            (*end case*))
26    
27        fun  expToKind(str,t)=(case t
28            of Dst.E_Var a => varToKind(str,a)
29            | _ => String.concat[str,"( ---) is not var type"]
30            (*end case*))
31    
32    
33        (*creates a load when it is not a local variable *)
34        fun  getArg(t,count,aligned, vn, origTy,offset)=(case t
35            of Dst.E_Var a => (case VTree.kind a
36                of TreeIL.VK_Local => t
37                | _ =>  (Dst.E_LoadVec(aligned, vn, origTy,t, Dst.E_Lit(Literal.Int offset)))
38                (*end case*))
39            | Dst.E_StoreVectoVec(lhs,aligned,n,origTy, indexAt,splitTy,ops)=> List.nth(ops,count)
40            | _ => t
41            (*end case*))
42    
43        fun getLHS(lhs,aligned,n,origTy,indexAt,splitTy,ops) =(case VTree.kind lhs
44            of TreeIL.VK_Local =>Dst.E_StoreVectoVec(lhs,aligned,n,origTy, Dst.E_Lit(Literal.Int ( indexAt)),splitTy,ops)
45            | _=>Dst.E_StoreVectoArr(lhs,aligned,n,origTy, Dst.E_Lit(Literal.Int ( indexAt)),splitTy,ops)
46            (*end case*))
47    
48    
49    
50    
51      (**************************************)      (**************************************)
52      (*Create Op and Ld expressions*)      (*Create Op and Ld expressions*)
53    
54      fun mkOps1(rator,origTy,pieces,argScas,argVecs,aligned,indexAt)= let      fun mkOps1(rator,origTy,pieces,argScas,argVecs,aligned,indexAt)= let
55          fun createOps ([], _, code) = code          fun createOps ([], _,_, code) = code
56            | createOps (vn::es, offset, code)=let            | createOps (vn::es, count,offset, code)=let
57              val argsLd =List.map (fn a => Dst.E_LoadVec(aligned, vn, origTy, a, Dst.E_Lit(Literal.Int offset))) argVecs              (*val argsLd =List.map (fn a => Dst.E_LoadVec(aligned, vn, origTy, a, Dst.E_Lit(Literal.Int offset))) argVecs*)
58                val argsLd =List.map (fn a =>getArg(a,count, aligned, vn, origTy, offset) )  argVecs
59              val exp = Dst.E_Op(rator vn, argScas@argsLd)              val exp = Dst.E_Op(rator vn, argScas@argsLd)
60              in              in
61                  createOps (es, offset + IntInf.fromInt vn, code@[exp])                  createOps (es, count+1,offset + IntInf.fromInt vn, code@[exp])
62              end              end
63      in      in
64          createOps (pieces, indexAt, [])          createOps (pieces, 0,indexAt, [])
65      end      end
66    
67    (*
68    
69      (*Second Attempt. Creates Loads for each arguement then the rest*)      (*Second Attempt. Creates Loads for each arguement then the rest*)
70      fun mkOps2(rator,origTy, pieces, argScas,argVecs,aligned,indexAt)=let      fun mkOps2(rator,origTy, pieces, argScas,argVecs,aligned,indexAt)=let
# Line 47  Line 83 
83          in          in
84              mkOp(lds,[],pieces)              mkOp(lds,[],pieces)
85          end          end
86    *)
87    
88      (**************************************)      (**************************************)
89      (*mk Vecs*)      (*mk Vecs*)
# Line 58  Line 94 
94      fun addSca [e1]=e1      fun addSca [e1]=e1
95        | 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)
96    
   
97      fun multipleMkVec(lhs,rator,n,origTy,pieces,isFill,aligned,splitTy,ops,indexAt)=let      fun multipleMkVec(lhs,rator,n,origTy,pieces,isFill,aligned,splitTy,ops,indexAt)=let
98          (*make Assign Statements*)          (*make Assign Statements*)
99          fun mkFromP([],_,_,_,_)=[]          fun mkFromP([],_,_,_,_)=[]
# Line 66  Line 101 
101              mkFromP(pieces,indexAt + IntInf.fromInt n, splitTy,es,aligned)@              mkFromP(pieces,indexAt + IntInf.fromInt n, splitTy,es,aligned)@
102              [mkVec(aligned,n,n,indexAt,splitTy,code)]              [mkVec(aligned,n,n,indexAt,splitTy,code)]
103      in (case rator n      in (case rator n
104          of DstOp.sumVec _ => [addSca ops]           of (*DstOp.sumVec _ => [addSca ops]
105            |*) DstOp.dotVec _ => [addSca ops]
106          | _ => (case (isFill,pieces,ops)          | _ => (case (isFill,pieces,ops)
107              of (true,[n],[ops]) =>[mkVec(aligned,n,origTy, indexAt,splitTy,ops)] (*FillVec*)              of (true,[n],[ops]) =>[mkVec(aligned,n,origTy, indexAt,splitTy,ops)] (*FillVec*)
108              |(_,_,_) => mkFromP(pieces, indexAt, splitTy, ops,aligned)              |(_,_,_) => mkFromP(pieces, indexAt, splitTy, ops,aligned)
# Line 87  Line 123 
123    
124      (*This will create a single mkVec*)      (*This will create a single mkVec*)
125      (*x=MkVec [2,4] [Add 2, Add4]:  a single mkVec: pieces, and exp list*)      (*x=MkVec [2,4] [Add 2, Add4]:  a single mkVec: pieces, and exp list*)
126      fun mkAssn(lhs,rator,n,origTy,pieces,isFill,aligned,splitTy,ops,indexAt)=let  
127          val a= Dst.E_mkVec2(aligned,n,origTy, Dst.E_Lit(Literal.Int ( indexAt)),splitTy,ops)  
128      in          (*expression, and statements*)
129          [Dst.S_Assign([lhs],a)]      fun mkAssnAS(lhs,rator,n,origTy,pieces,isFill,aligned,splitTy,ops,indexAt)=(case rator n
130      end          of DstOp.sumVec _ =>(SOME( addSca ops),NONE,NONE)
131            | DstOp.dotVec _ => (SOME( addSca ops),NONE,NONE)
132            | _=>(NONE,SOME(Dst.S_StoreVectoArr(lhs,aligned,n,origTy, Dst.E_Lit(Literal.Int ( indexAt)),splitTy,ops)),
133                SOME(getLHS (lhs,aligned,n,origTy,  indexAt,splitTy,ops)))
134            (*end case*))
135    
136    
137    
138      (* This will create assignments with multiple mkVec*)      (* This will create assignments with multiple mkVec*)
139      (*x=[MkVec 2(Add 2), mkVec 4(Add 4)] Multiple mkVecs *)      (*x=[MkVec 2(Add 2), mkVec 4(Add 4)] Multiple mkVecs *)
140    
141      (**************************************)      (**************************************)
142        (*If it is matrix then we need to add offset to indexAt*)
143        fun matInt( n, m,a, b )=(m*b+a)
144        fun isMatrix2([Dst.E_Op(DstOp.IndexTensor(_,DstTy.TensorTy [_], DstTy.indexTy [fast], DstTy.TensorTy[argTyY,argTyX]),m)],rest)= let
145            val indexAt=matInt(argTyY,argTyX,0,fast)
146            in
147                (indexAt,rest@m)
148            end
149        | isMatrix2(Dst.E_Op(DstOp.IndexTensor(_,DstTy.TensorTy [_], DstTy.indexTy [fast], DstTy.TensorTy[argTyY,argTyX]),m)::es,rest)=
150            isMatrix2(es, rest@m)
151        | isMatrix2(a,[])=(0, a)
152        | isMatrix2 _=raise Fail"Should be projection"
153    
154    
155        (**************************************)
156    
157      fun isAligned isFill = (case isFill      fun isAligned isFill = (case isFill
158          of true=>false          of true=>false
159          | _ => true          | _ => true
# Line 108  Line 164 
164      (*end case*))      (*end case*))
165    
166      (*Main functions*)      (*Main functions*)
167      fun vecToTree(lhs,rator,n,origTy,pieces,argScas,argVecs,isFill,indexAt')= let      fun vecToTree(lhs,rator,n,origTy,pieces,argScas,argV',isFill)= let
168    
169          val splitTy=DstTy.vectorLength pieces          val splitTy=DstTy.vectorLength pieces
170            val (indexAt', argVecs)=isMatrix2(argV',[])
171    
172    
173            val _ =  print(String.concat(["\n\t ",varToKind("lhs",lhs)] @(List.map (fn e => expToKind("\n\t Arg",e)) argVecs)))
174    
175          val aligned= isAligned isFill          val aligned= isAligned isFill
176          val indexAt=IntInf.fromInt indexAt'          val indexAt=IntInf.fromInt indexAt'
177    
178          (*Create Ld Expressions and Tree Ops*)          (*Create Ld Expressions and Tree Ops*)
179          val ops=mkOps1(rator,origTy,pieces,argScas,argVecs,aligned,indexAt)          val ops=mkOps1(rator,origTy,pieces,argScas,argVecs,aligned,indexAt)
180    
181    
182          (*Assign here  and MkVec Expressions*)          (*Assign here  and MkVec Expressions*)
183          val exp1= multipleAssn(lhs,rator,n,origTy,pieces,isFill,aligned,splitTy,ops,indexAt)          (*val exp1= multipleAssn(lhs,rator,n,origTy,pieces,isFill,aligned,splitTy,ops,indexAt)
184          val exp=mkAssn(lhs,rator,n,origTy,pieces,isFill,aligned,splitTy,ops, indexAt)          val exp=mkAssn(lhs,rator,n,origTy,pieces,isFill,aligned,splitTy,ops, indexAt)
185          val _=printExp exp1          val _=printExp exp1*)
186            (*val expA=mkAssnA(rator,n,origTy,pieces,isFill,aligned,splitTy,ops, indexAt)*)
187            val expA=mkAssnAS(lhs,rator,n,origTy,pieces,isFill,aligned,splitTy,ops, indexAt)
188      in      in
189          exp          expA
190      end      end
191    
192          (**************************************)          (**************************************)
# Line 161  Line 227 
227          | SrcOp.LoadVoxels (rty, d ) =>    DstOp.LoadVoxels( rty, d)*)          | SrcOp.LoadVoxels (rty, d ) =>    DstOp.LoadVoxels( rty, d)*)
228    
229    
230          | SrcOp.Kernel h =>    DstOp.Kernel h          (*Maybe should delete?*)
231          | SrcOp.LoadImage info =>    DstOp.LoadImage info        (*  | SrcOp.LoadImage info =>    DstOp.LoadImage info*)
232    
233          | SrcOp.Inside info =>    DstOp.Inside info          | SrcOp.Inside info =>    DstOp.Inside info
234          | SrcOp.Transform V=>    DstOp.Transform V          | SrcOp.Transform V=>    DstOp.Transform V
235          | SrcOp.Translate V=>  DstOp.Translate V          | SrcOp.Translate V=>  DstOp.Translate V
# Line 173  Line 240 
240          | SrcOp.Sqrt =>DstOp.Sqrt          | SrcOp.Sqrt =>DstOp.Sqrt
241          (*Still need to sort *)          (*Still need to sort *)
242          | SrcOp.IndexTensor e=> DstOp.IndexTensor e          | SrcOp.IndexTensor e=> DstOp.IndexTensor e
243    
244          | SrcOp.imgAddr(v,indexAt, dim)=>DstOp.imgAddr(v, indexAt, dim)          | SrcOp.imgAddr(v,indexAt, dim)=>DstOp.imgAddr(v, indexAt, dim)
245          | SrcOp.imgLoad(v,dim,n)=>DstOp.imgLoad(v,dim,n)          | SrcOp.imgLoad(v,dim,n)=>DstOp.imgLoad(v,dim,n)
246    
247    (*Load and Store is not needed *)
248    
249    
250        | SrcOp.prodVec(n,_)   =>  DstOp.prodVec n
251        | SrcOp.sumVec(n,_)   =>   DstOp.sumVec n
252        | SrcOp.dotVec(n ,_)   =>  DstOp.dotVec n
253        | SrcOp.baseAddr V => DstOp.baseAddr V
254          (*EigenVecs,mkDynamic, Append,Prepend, Concat,Length,ImageAddress,LoadVoxel,Inputs, and Pritns*)          (*EigenVecs,mkDynamic, Append,Prepend, Concat,Length,ImageAddress,LoadVoxel,Inputs, and Pritns*)
255          | rator => raise Fail ("bogus operator " ^ SrcOp.toString rator)          | rator => raise Fail ("bogus operator " ^ SrcOp.toString rator)
256    (* end case *))    (* end case *))

Legend:
Removed from v.2679  
changed lines
  Added in v.2680

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