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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2840 - (view) (download)

1 : cchiw 2637 (*This function transitions low-il operators to tree-il operators *)
2 : cchiw 2671 (*creates the Tree-IL operators*)
3 : cchiw 2637 structure LowOpToTreeOp = struct
4 :     local
5 : cchiw 2692 structure Src = LowIL
6 : cchiw 2637 structure SrcOp = LowOps
7 : cchiw 2691 structure SrcTy = LowILTypes
8 : cchiw 2692 structure SrcV = Src.Var
9 : cchiw 2637 structure DstOp = TreeOps
10 :     structure DstTy = TreeILTypes
11 : cchiw 2646 structure Dst = TreeIL
12 : cchiw 2838 structure DstSV=Dst.StateVar
13 : cchiw 2691 structure DstV = Dst.Var
14 : cchiw 2690 structure Ty=TreeIL.Ty
15 : cchiw 2637
16 :     in
17 :    
18 : cchiw 2664 val testing=1
19 : cchiw 2690 fun testp t=(case testing
20 :     of 1=>(print(String.concat t);1)
21 :     |_ =>1
22 : cchiw 2688 (*end case*))
23 : cchiw 2680
24 : cchiw 2691 (**************************************)
25 : cchiw 2791 (*assignment, store-statement*)
26 : cchiw 2795 fun mkStmt(lhs,lhsKind,origrator,isFill,oSize,A,splitTy,ops)= (case origrator
27 :     of SrcOp.sumVec _ => Dst.S_Assign([lhs], addSca ops)
28 :     | _ => (case lhsKind
29 :     of TreeIL.VK_Local => Dst.S_Assign([lhs], Dst.E_Mux(A,isFill,oSize,splitTy,ops))
30 : cchiw 2827 | _ => Dst.S_StoreVec(Dst.E_Var lhs,0,A,isFill,oSize,Ty.TensorTy[oSize],splitTy, ops)
31 : cchiw 2791 (*end case*))
32 : cchiw 2795 (*end case*))
33 : cchiw 2691 and addSca [e1]=e1
34 :     | addSca(e1::e2::es)= addSca([Dst.E_Op(DstOp.addSca,[e1,e2])]@es)
35 : cchiw 2680
36 : cchiw 2838
37 :    
38 :     (*can't use storeAligned when argument is broken into pieces*)
39 :     (*Decides if LoadAligned function is used*)
40 :     (*can't use loadAligned when argument is a matrix'*)
41 :     fun isAlignedLoad(isFill,Ty.TensorTy [_]) =(case isFill
42 :     of true => false
43 :     | _ => true
44 :     (*end case*))
45 :     |isAlignedLoad _ =false
46 :    
47 :     (**************************************)
48 : cchiw 2680 (*creates a load when it is not a local variable *)
49 : cchiw 2838 fun getArg(isFill,lhsKind,t,count, nSize, oSize,offset)=let
50 : cchiw 2830 fun getExp (Dst.E_Var a) =(case (DstV.kind a)
51 :     of TreeIL.VK_Local =>t
52 : cchiw 2838 | _ => Dst.E_LoadArr(isAlignedLoad(isFill,DstV.ty a) ,nSize,oSize,t, Dst.E_Lit(Literal.Int offset))
53 : cchiw 2680 (*end case*))
54 : cchiw 2838 | getExp(Dst.E_State a)= Dst.E_LoadArr(isAlignedLoad(isFill,DstSV.ty a) ,nSize,oSize,t, Dst.E_Lit(Literal.Int offset))
55 : cchiw 2690 | getExp (Dst.E_Mux(_,_,_,_,ops))= List.nth(ops,count)
56 : cchiw 2840 | getExp a1 =( print(String.concat["Warning argument to vector operation is: ",Dst.toString a1]);a1)
57 :     (*| getExp a1 = raise Fail("Arg to vector op is not Mux or Var. Found: "^Dst.toString a1)*)
58 : cchiw 2691 in
59 : cchiw 2789 getExp t
60 : cchiw 2691 end
61 : cchiw 2838 and mkOps(isFill,lhsKind,oldrator,rator,oSize,pieces,argScas,argVecs,indexAt)= let
62 :    
63 : cchiw 2680 fun createOps ([], _,_, code) = code
64 : cchiw 2795 | createOps (nSize::es, count,offset, code)=let
65 : cchiw 2838 val argsLd =List.map (fn a =>getArg(isFill,lhsKind,a,count, nSize, oSize, offset)) argVecs
66 : cchiw 2827 val exp = (nSize, argScas@argsLd)
67 : cchiw 2749 in
68 : cchiw 2795 createOps (es, count+1,offset + IntInf.fromInt nSize, code@[exp])
69 : cchiw 2749 end
70 : cchiw 2827 in (case (oldrator,pieces,argVecs)
71 : cchiw 2838 of (SrcOp.ProjectTensor(_,_,indTy,argTy),_,[a]) => let
72 : cchiw 2827 (*Use Load expression instead of Project Operator *)
73 : cchiw 2838 val shift=(case (indTy,argTy)
74 :     of (Ty.indexTy[i],Ty.TensorTy[_,argTyX])=> i*argTyX
75 :     | (Ty.indexTy[j,i],Ty.TensorTy[_,argTyY,argTyX])=> j*(argTyX*argTyY)+i*argTyX
76 :     | _ =>raise Fail "Project Tensor of a unhandled size"
77 :     (*end case *))
78 : cchiw 2827 fun mkLoad ([], _, code) = code
79 :     | mkLoad (nSize::es, offset, code)=let
80 : cchiw 2838
81 :     val A=(case a
82 :     of Dst.E_Var v =>isAlignedLoad(isFill,DstV.ty v)
83 :     | Dst.E_State v=>isAlignedLoad(isFill,DstSV.ty v)
84 :     (*end case*))
85 :     val exps=[Dst.E_LoadArr(A, nSize,oSize,a, Dst.E_Lit(Literal.Int offset))]
86 : cchiw 2827 in
87 :     mkLoad (es, offset + IntInf.fromInt nSize, code@exps)
88 :     end
89 :     in
90 : cchiw 2838 mkLoad (pieces, IntInf.fromInt shift, [])
91 :     end
92 : cchiw 2827 | (SrcOp.sumVec _,[nSize],[a]) =>
93 : cchiw 2838 [Dst.E_Op(DstOp.sumVec(nSize,oSize), [getArg(isFill,lhsKind,a,0, nSize, oSize, 0)])]
94 : cchiw 2827 | (SrcOp.sumVec _,_,_) =>let
95 :     val code=createOps (pieces, 0,indexAt, [])
96 :     in
97 :     List.map (fn(nSize,args)=> Dst.E_Op(DstOp.sumVec(nSize,nSize),args)) code
98 :     end
99 :     | _ => let
100 :     val code=createOps (pieces, 0,indexAt, [])
101 :     in
102 :     List.map (fn(nSize,args)=> Dst.E_Op(rator nSize,args)) code
103 :     end
104 :     (*end case*))
105 : cchiw 2680 end
106 : cchiw 2795 (**************************************)
107 : cchiw 2680
108 : cchiw 2840 fun (*isAligned(isFill,1) =(case isFill
109 : cchiw 2827 of true => false
110 :     | _ => true
111 : cchiw 2838 (*end case*))
112 : cchiw 2840 |*)isAligned _ =false
113 : cchiw 2680
114 : cchiw 2838
115 :    
116 : cchiw 2690 (**************************************)
117 : cchiw 2671 (*Main functions*)
118 : cchiw 2795 fun vecToTree(lhs,origrator,rator,nSize,oSize,pieces,argScas,argVecs,isFill)= let
119 : cchiw 2637 val splitTy=DstTy.vectorLength pieces
120 : cchiw 2838 val aligned= isAligned(isFill,length pieces)
121 : cchiw 2795
122 : cchiw 2789 val indexAt=IntInf.fromInt 0
123 : cchiw 2676 (*Create Ld Expressions and Tree Ops*)
124 : cchiw 2795 val lhsKind=DstV.kind lhs
125 : cchiw 2838
126 :     val ops=mkOps(isFill,lhsKind,origrator,rator,oSize,pieces,argScas,argVecs,indexAt)
127 : cchiw 2676 in
128 : cchiw 2795 mkStmt(lhs,lhsKind,origrator,isFill,oSize,aligned,splitTy,ops)
129 : cchiw 2676 end
130 : cchiw 2637
131 : cchiw 2795 (* consVecToTree()
132 :     * Takes Cons of a vector and returns Mux Expression
133 :     *)
134 :     fun consVecToTree(_,oSize,[nSize],args,true)= let
135 :     val nArg=length(args)
136 :     val n=nSize-nArg
137 :     val newArgs=List.tabulate(n, (fn _=>Dst.E_Lit(Literal.Int 0)))
138 :     val op1=Dst.E_Cons(nSize, oSize,args@newArgs)
139 : cchiw 2838 val aligned= isAligned(true,1)
140 : cchiw 2789 val splitTy=DstTy.vectorLength [nSize]
141 : cchiw 2791 in
142 : cchiw 2795 Dst.E_Mux(aligned,true,oSize,splitTy,[op1])
143 : cchiw 2791 end
144 : cchiw 2795 | consVecToTree(_,_,_,_,true)= raise Fail"In ConsVecToTree-isFill with more than 1 piece"
145 :     | consVecToTree(nSize,oSize,pieces,args,isFill)= let
146 : cchiw 2838 val aligned= isAligned(isFill,length pieces)
147 : cchiw 2795 val splitTy=DstTy.vectorLength pieces
148 : cchiw 2827 fun createOps ([], _,_,_) = []
149 :     | createOps (nSize::es, offset,arg, code)=
150 : cchiw 2795 [Dst.E_Cons(nSize, nSize,List.take(arg,nSize))]@
151 : cchiw 2827 createOps (es, offset + IntInf.fromInt nSize, List.drop(arg,nSize),code)
152 :     val ops= createOps (pieces, 0,args, [])
153 : cchiw 2795 in
154 :     Dst.E_Mux(aligned,isFill,oSize,splitTy,ops)
155 :     end
156 : cchiw 2671 (**************************************)
157 : cchiw 2637
158 :     (*Low-IL operators to Tree-IL operators*)
159 :     fun expandOp rator=(case rator
160 :     of SrcOp.IAdd => DstOp.IAdd
161 :     | SrcOp.ISub => DstOp.ISub
162 :     | SrcOp.IMul => DstOp.IMul
163 :     | SrcOp.IDiv => DstOp.IDiv
164 :     | SrcOp.INeg => DstOp.INeg
165 :     | SrcOp.Abs ty => DstOp.Abs ty
166 :     | SrcOp.LT ty => DstOp.LT ty
167 :     | SrcOp.LTE ty => DstOp.LTE ty
168 :     | SrcOp.EQ ty => DstOp.EQ ty
169 :     | SrcOp.NEQ ty => DstOp.NEQ ty
170 :     | SrcOp.GT ty => DstOp.GT ty
171 :     | SrcOp.GTE ty => DstOp.GTE ty
172 :     | SrcOp.Not => DstOp.Not
173 :     | SrcOp.Max => DstOp.Max
174 :     | SrcOp.Min => DstOp.Min
175 :     | SrcOp.Clamp ty => DstOp.Clamp ty
176 :     | SrcOp.Lerp ty => DstOp.Lerp ty
177 :     | SrcOp.Zero ty => DstOp.Zero ty
178 :     | SrcOp.PrincipleEvec ty => DstOp.PrincipleEvec ty
179 :     | SrcOp.EigenVals2x2 => DstOp.EigenVals2x2
180 :     | SrcOp.EigenVals3x3 => DstOp.EigenVals3x3
181 : cchiw 2838 | SrcOp.EigenVecs2x2 => DstOp.EigenVecs2x2
182 :     | SrcOp.EigenVecs3x3 => DstOp.EigenVecs3x3
183 : cchiw 2637 | SrcOp.Select(ty as SrcTy.TupleTy tys, i) => DstOp.Select( ty, i)
184 :     | SrcOp.Index (ty, i ) => DstOp.Index ( ty, i)
185 :     | SrcOp.Subscript ty => DstOp.Subscript ty
186 :     | SrcOp.Ceiling d => DstOp.Ceiling d
187 :     | SrcOp.Floor d => DstOp.Floor d
188 :     | SrcOp.Round d => DstOp.Round d
189 :     | SrcOp.Trunc d => DstOp.Trunc d
190 :     | SrcOp.IntToReal => DstOp.IntToReal
191 :     | SrcOp.RealToInt d => DstOp.RealToInt d
192 :     (*| SrcOp.VoxelAddress( info, offset) => expandVoxelAddress (y, info, offset, args')
193 :     | SrcOp.LoadVoxels (rty, d ) => DstOp.LoadVoxels( rty, d)*)
194 : cchiw 2680 (*Maybe should delete?*)
195 : cchiw 2691 (* | SrcOp.LoadImage info => DstOp.LoadImage info*)
196 : cchiw 2637 | SrcOp.Inside info => DstOp.Inside info
197 :     | SrcOp.Translate V=> DstOp.Translate V
198 :     | SrcOp.addSca =>DstOp.addSca
199 :     | SrcOp.subSca=>DstOp.subSca
200 :     | SrcOp.prodSca=>DstOp.prodSca
201 :     | SrcOp.divSca=>DstOp.divSca
202 : cchiw 2838 | SrcOp.Sqrt =>DstOp.Sqrt
203 :     (*| SrcOp.Norm ty => (DstOp.Norm ty)*)
204 :     | SrcOp.Normalize d =>(DstOp.Normalize d)
205 : cchiw 2637 | SrcOp.imgAddr(v,indexAt, dim)=>DstOp.imgAddr(v, indexAt, dim)
206 : cchiw 2691 | SrcOp.baseAddr V => DstOp.baseAddr V
207 : cchiw 2637 (*EigenVecs,mkDynamic, Append,Prepend, Concat,Length,ImageAddress,LoadVoxel,Inputs, and Pritns*)
208 :     | rator => raise Fail ("bogus operator " ^ SrcOp.toString rator)
209 :     (* end case *))
210 :     end;
211 :     end

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