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

SCM Repository

[diderot] Annotation of /branches/charisee/src/compiler/low-il/low-il.sml
ViewVC logotype

Annotation of /branches/charisee/src/compiler/low-il/low-il.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1640 - (view) (download)
Original Path: trunk/src/compiler/low-il/low-il.sml

1 : jhr 458 (* low-il.in
2 :     *
3 :     * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *
6 :     * Lower-level version of the Diderot IL input file.
7 :     *
8 :     *)
9 :    
10 :     structure LowOps =
11 :     struct
12 :    
13 : jhr 1640 (* required helper functions for types *)
14 : jhr 458 type ty = LowILTypes.ty
15 :     val samety = LowILTypes.same
16 :     val hashty = LowILTypes.hash
17 :     val tyToString = LowILTypes.toString
18 :    
19 : jhr 1640 (* required helper functions for type lists *)
20 :     type tys = ty list
21 :     fun sametys (tys1, tys2) = ListPair.allEq samety (tys1, tys2)
22 :     fun hashtys tys = List.foldl (fn (ty, s) => hashty ty + 0w3 * s) 0w0 tys
23 :     fun tysToString tys = String.concat["[", String.concatWith "," (List.map tyToString tys), "]" ]
24 :    
25 :     (* required helper functions for the int type *)
26 : jhr 458 fun sameint (i1 : int, i2) = (i1 = i2)
27 :     fun hashint i = Word.fromInt i
28 :     fun intToString i = Int.toString i
29 :    
30 : jhr 1640 (* required helper functions for the string type *)
31 : jhr 458 fun samestring (s1 : string, s2) = (s1 = s2)
32 :     val hashstring = HashString.hashString
33 :     fun stringToString s = String.concat["\"", s, "\""]
34 :    
35 :     datatype rator
36 :     = Add of ty
37 :     | Sub of ty
38 :     | Mul of ty
39 :     | Div of ty
40 :     | Neg of ty
41 : jhr 1116 | Abs of ty
42 : jhr 458 | LT of ty
43 :     | LTE of ty
44 :     | EQ of ty
45 :     | NEQ of ty
46 :     | GT of ty
47 :     | GTE of ty
48 :     | Not
49 :     | Max
50 :     | Min
51 : jhr 1295 | Clamp of ty
52 : jhr 1116 | Lerp of ty
53 : jhr 458 | Dot of int
54 : jhr 1116 | MulVecMat of int * int
55 :     | MulMatVec of int * int
56 :     | MulMatMat of int * int * int
57 : jhr 458 | Cross
58 : jhr 1116 | Norm of ty
59 :     | Normalize of int
60 :     | Scale of ty
61 : jhr 458 | PrincipleEvec of ty
62 : jhr 1640 | EigenVecs2x2
63 :     | EigenVecs3x3
64 :     | EigenVals2x2
65 :     | EigenVals3x3
66 : jhr 1116 | Identity of int
67 :     | Zero of ty
68 : jhr 1640 | Select of ty * int
69 :     | Index of ty * int
70 : jhr 458 | Subscript of ty
71 : jhr 1116 | Ceiling of int
72 : jhr 458 | Floor of int
73 : jhr 1116 | Round of int
74 :     | Trunc of int
75 : jhr 458 | IntToReal
76 : jhr 1116 | RealToInt of int
77 : jhr 511 | ImageAddress of ImageInfo.info
78 : jhr 1116 | LoadVoxels of ImageInfo.info * int
79 : jhr 458 | PosToImgSpace of ImageInfo.info
80 : jhr 1116 | TensorToWorldSpace of ImageInfo.info * ty
81 : jhr 458 | LoadImage of ImageInfo.info
82 : jhr 1116 | Inside of ImageInfo.info * int
83 : jhr 1301 | Input of ty * string * string
84 :     | InputWithDefault of ty * string * string
85 : jhr 1640 | Print of tys
86 : jhr 458
87 : jhr 1640 fun resultArity (Add _) = 1
88 :     | resultArity (Sub _) = 1
89 :     | resultArity (Mul _) = 1
90 :     | resultArity (Div _) = 1
91 :     | resultArity (Neg _) = 1
92 :     | resultArity (Abs _) = 1
93 :     | resultArity (LT _) = 1
94 :     | resultArity (LTE _) = 1
95 :     | resultArity (EQ _) = 1
96 :     | resultArity (NEQ _) = 1
97 :     | resultArity (GT _) = 1
98 :     | resultArity (GTE _) = 1
99 :     | resultArity Not = 1
100 :     | resultArity Max = 1
101 :     | resultArity Min = 1
102 :     | resultArity (Clamp _) = 1
103 :     | resultArity (Lerp _) = 1
104 :     | resultArity (Dot _) = 1
105 :     | resultArity (MulVecMat _) = 1
106 :     | resultArity (MulMatVec _) = 1
107 :     | resultArity (MulMatMat _) = 1
108 :     | resultArity Cross = 1
109 :     | resultArity (Norm _) = 1
110 :     | resultArity (Normalize _) = 1
111 :     | resultArity (Scale _) = 1
112 :     | resultArity (PrincipleEvec _) = 1
113 :     | resultArity EigenVecs2x2 = 1
114 :     | resultArity EigenVecs3x3 = 1
115 :     | resultArity EigenVals2x2 = 1
116 :     | resultArity EigenVals3x3 = 1
117 :     | resultArity (Identity _) = 1
118 :     | resultArity (Zero _) = 1
119 :     | resultArity (Select _) = 1
120 :     | resultArity (Index _) = 1
121 :     | resultArity (Subscript _) = 1
122 :     | resultArity (Ceiling _) = 1
123 :     | resultArity (Floor _) = 1
124 :     | resultArity (Round _) = 1
125 :     | resultArity (Trunc _) = 1
126 :     | resultArity IntToReal = 1
127 :     | resultArity (RealToInt _) = 1
128 :     | resultArity (ImageAddress _) = 1
129 :     | resultArity (LoadVoxels _) = 1
130 :     | resultArity (PosToImgSpace _) = 1
131 :     | resultArity (TensorToWorldSpace _) = 1
132 :     | resultArity (LoadImage _) = 1
133 :     | resultArity (Inside _) = 1
134 :     | resultArity (Input _) = 1
135 :     | resultArity (InputWithDefault _) = 1
136 :     | resultArity (Print _) = 0
137 :    
138 : jhr 458 fun arity (Add _) = 2
139 :     | arity (Sub _) = 2
140 :     | arity (Mul _) = 2
141 :     | arity (Div _) = 2
142 :     | arity (Neg _) = 1
143 : jhr 1116 | arity (Abs _) = 1
144 : jhr 458 | arity (LT _) = 2
145 :     | arity (LTE _) = 2
146 :     | arity (EQ _) = 2
147 :     | arity (NEQ _) = 2
148 :     | arity (GT _) = 2
149 :     | arity (GTE _) = 2
150 :     | arity Not = 1
151 :     | arity Max = 2
152 :     | arity Min = 2
153 : jhr 1295 | arity (Clamp _) = 3
154 : jhr 1116 | arity (Lerp _) = 3
155 : jhr 458 | arity (Dot _) = 2
156 : jhr 1116 | arity (MulVecMat _) = 2
157 :     | arity (MulMatVec _) = 2
158 :     | arity (MulMatMat _) = 2
159 : jhr 458 | arity Cross = 2
160 :     | arity (Norm _) = 1
161 : jhr 1116 | arity (Normalize _) = 1
162 : jhr 458 | arity (Scale _) = 2
163 :     | arity (PrincipleEvec _) = 2
164 : jhr 1640 | arity EigenVecs2x2 = 1
165 :     | arity EigenVecs3x3 = 1
166 :     | arity EigenVals2x2 = 1
167 :     | arity EigenVals3x3 = 1
168 : jhr 1116 | arity (Identity _) = 0
169 :     | arity (Zero _) = 0
170 : jhr 1640 | arity (Select _) = 1
171 :     | arity (Index _) = 1
172 : jhr 458 | arity (Subscript _) = 2
173 : jhr 1116 | arity (Ceiling _) = 1
174 : jhr 458 | arity (Floor _) = 1
175 : jhr 1116 | arity (Round _) = 1
176 :     | arity (Trunc _) = 1
177 : jhr 458 | arity IntToReal = 1
178 : jhr 1116 | arity (RealToInt _) = 1
179 :     | arity (ImageAddress _) = 1
180 : jhr 458 | arity (LoadVoxels _) = 1
181 : jhr 1116 | arity (PosToImgSpace _) = 2
182 :     | arity (TensorToWorldSpace _) = 2
183 :     | arity (LoadImage _) = 1
184 :     | arity (Inside _) = 2
185 : jhr 458 | arity (Input _) = 0
186 :     | arity (InputWithDefault _) = 1
187 : jhr 1640 | arity (Print _) = ~1
188 : jhr 458
189 :     fun same (Add(a0), Add(b0)) = samety(a0, b0)
190 :     | same (Sub(a0), Sub(b0)) = samety(a0, b0)
191 :     | same (Mul(a0), Mul(b0)) = samety(a0, b0)
192 :     | same (Div(a0), Div(b0)) = samety(a0, b0)
193 :     | same (Neg(a0), Neg(b0)) = samety(a0, b0)
194 : jhr 1116 | same (Abs(a0), Abs(b0)) = samety(a0, b0)
195 : jhr 458 | same (LT(a0), LT(b0)) = samety(a0, b0)
196 :     | same (LTE(a0), LTE(b0)) = samety(a0, b0)
197 :     | same (EQ(a0), EQ(b0)) = samety(a0, b0)
198 :     | same (NEQ(a0), NEQ(b0)) = samety(a0, b0)
199 :     | same (GT(a0), GT(b0)) = samety(a0, b0)
200 :     | same (GTE(a0), GTE(b0)) = samety(a0, b0)
201 :     | same (Not, Not) = true
202 :     | same (Max, Max) = true
203 :     | same (Min, Min) = true
204 : jhr 1295 | same (Clamp(a0), Clamp(b0)) = samety(a0, b0)
205 : jhr 1116 | same (Lerp(a0), Lerp(b0)) = samety(a0, b0)
206 : jhr 458 | same (Dot(a0), Dot(b0)) = sameint(a0, b0)
207 : jhr 1116 | same (MulVecMat(a0,a1), MulVecMat(b0,b1)) = sameint(a0, b0) andalso sameint(a1, b1)
208 :     | same (MulMatVec(a0,a1), MulMatVec(b0,b1)) = sameint(a0, b0) andalso sameint(a1, b1)
209 :     | same (MulMatMat(a0,a1,a2), MulMatMat(b0,b1,b2)) = sameint(a0, b0) andalso sameint(a1, b1) andalso sameint(a2, b2)
210 : jhr 458 | same (Cross, Cross) = true
211 : jhr 1116 | same (Norm(a0), Norm(b0)) = samety(a0, b0)
212 :     | same (Normalize(a0), Normalize(b0)) = sameint(a0, b0)
213 :     | same (Scale(a0), Scale(b0)) = samety(a0, b0)
214 : jhr 458 | same (PrincipleEvec(a0), PrincipleEvec(b0)) = samety(a0, b0)
215 : jhr 1640 | same (EigenVecs2x2, EigenVecs2x2) = true
216 :     | same (EigenVecs3x3, EigenVecs3x3) = true
217 :     | same (EigenVals2x2, EigenVals2x2) = true
218 :     | same (EigenVals3x3, EigenVals3x3) = true
219 : jhr 1116 | same (Identity(a0), Identity(b0)) = sameint(a0, b0)
220 :     | same (Zero(a0), Zero(b0)) = samety(a0, b0)
221 : jhr 1640 | same (Select(a0,a1), Select(b0,b1)) = samety(a0, b0) andalso sameint(a1, b1)
222 :     | same (Index(a0,a1), Index(b0,b1)) = samety(a0, b0) andalso sameint(a1, b1)
223 : jhr 458 | same (Subscript(a0), Subscript(b0)) = samety(a0, b0)
224 : jhr 1116 | same (Ceiling(a0), Ceiling(b0)) = sameint(a0, b0)
225 : jhr 458 | same (Floor(a0), Floor(b0)) = sameint(a0, b0)
226 : jhr 1116 | same (Round(a0), Round(b0)) = sameint(a0, b0)
227 :     | same (Trunc(a0), Trunc(b0)) = sameint(a0, b0)
228 : jhr 458 | same (IntToReal, IntToReal) = true
229 : jhr 1116 | same (RealToInt(a0), RealToInt(b0)) = sameint(a0, b0)
230 : jhr 511 | same (ImageAddress(a0), ImageAddress(b0)) = ImageInfo.same(a0, b0)
231 : jhr 1116 | same (LoadVoxels(a0,a1), LoadVoxels(b0,b1)) = ImageInfo.same(a0, b0) andalso sameint(a1, b1)
232 : jhr 458 | same (PosToImgSpace(a0), PosToImgSpace(b0)) = ImageInfo.same(a0, b0)
233 : jhr 1116 | same (TensorToWorldSpace(a0,a1), TensorToWorldSpace(b0,b1)) = ImageInfo.same(a0, b0) andalso samety(a1, b1)
234 : jhr 458 | same (LoadImage(a0), LoadImage(b0)) = ImageInfo.same(a0, b0)
235 : jhr 1116 | same (Inside(a0,a1), Inside(b0,b1)) = ImageInfo.same(a0, b0) andalso sameint(a1, b1)
236 : jhr 1301 | same (Input(a0,a1,a2), Input(b0,b1,b2)) = samety(a0, b0) andalso samestring(a1, b1) andalso samestring(a2, b2)
237 :     | same (InputWithDefault(a0,a1,a2), InputWithDefault(b0,b1,b2)) = samety(a0, b0) andalso samestring(a1, b1) andalso samestring(a2, b2)
238 : jhr 1640 | same (Print(a0), Print(b0)) = sametys(a0, b0)
239 : jhr 458 | same _ = false
240 :    
241 :     fun hash (Add(a0)) = 0w3 + hashty a0
242 :     | hash (Sub(a0)) = 0w5 + hashty a0
243 :     | hash (Mul(a0)) = 0w7 + hashty a0
244 :     | hash (Div(a0)) = 0w11 + hashty a0
245 :     | hash (Neg(a0)) = 0w13 + hashty a0
246 : jhr 1116 | hash (Abs(a0)) = 0w17 + hashty a0
247 :     | hash (LT(a0)) = 0w19 + hashty a0
248 :     | hash (LTE(a0)) = 0w23 + hashty a0
249 :     | hash (EQ(a0)) = 0w29 + hashty a0
250 :     | hash (NEQ(a0)) = 0w31 + hashty a0
251 :     | hash (GT(a0)) = 0w37 + hashty a0
252 :     | hash (GTE(a0)) = 0w41 + hashty a0
253 :     | hash Not = 0w43
254 :     | hash Max = 0w47
255 :     | hash Min = 0w53
256 : jhr 1295 | hash (Clamp(a0)) = 0w59 + hashty a0
257 :     | hash (Lerp(a0)) = 0w61 + hashty a0
258 :     | hash (Dot(a0)) = 0w67 + hashint a0
259 :     | hash (MulVecMat(a0,a1)) = 0w71 + hashint a0 + hashint a1
260 :     | hash (MulMatVec(a0,a1)) = 0w73 + hashint a0 + hashint a1
261 :     | hash (MulMatMat(a0,a1,a2)) = 0w79 + hashint a0 + hashint a1 + hashint a2
262 :     | hash Cross = 0w83
263 : jhr 1640 | hash (Norm(a0)) = 0w89 + hashty a0
264 :     | hash (Normalize(a0)) = 0w97 + hashint a0
265 :     | hash (Scale(a0)) = 0w101 + hashty a0
266 :     | hash (PrincipleEvec(a0)) = 0w103 + hashty a0
267 :     | hash EigenVecs2x2 = 0w107
268 :     | hash EigenVecs3x3 = 0w109
269 :     | hash EigenVals2x2 = 0w113
270 :     | hash EigenVals3x3 = 0w127
271 :     | hash (Identity(a0)) = 0w131 + hashint a0
272 :     | hash (Zero(a0)) = 0w137 + hashty a0
273 :     | hash (Select(a0,a1)) = 0w139 + hashty a0 + hashint a1
274 :     | hash (Index(a0,a1)) = 0w149 + hashty a0 + hashint a1
275 :     | hash (Subscript(a0)) = 0w151 + hashty a0
276 :     | hash (Ceiling(a0)) = 0w157 + hashint a0
277 :     | hash (Floor(a0)) = 0w163 + hashint a0
278 :     | hash (Round(a0)) = 0w167 + hashint a0
279 :     | hash (Trunc(a0)) = 0w173 + hashint a0
280 :     | hash IntToReal = 0w179
281 :     | hash (RealToInt(a0)) = 0w181 + hashint a0
282 :     | hash (ImageAddress(a0)) = 0w191 + ImageInfo.hash a0
283 :     | hash (LoadVoxels(a0,a1)) = 0w193 + ImageInfo.hash a0 + hashint a1
284 :     | hash (PosToImgSpace(a0)) = 0w197 + ImageInfo.hash a0
285 :     | hash (TensorToWorldSpace(a0,a1)) = 0w199 + ImageInfo.hash a0 + hashty a1
286 :     | hash (LoadImage(a0)) = 0w211 + ImageInfo.hash a0
287 :     | hash (Inside(a0,a1)) = 0w223 + ImageInfo.hash a0 + hashint a1
288 :     | hash (Input(a0,a1,a2)) = 0w227 + hashty a0 + hashstring a1 + hashstring a2
289 :     | hash (InputWithDefault(a0,a1,a2)) = 0w229 + hashty a0 + hashstring a1 + hashstring a2
290 :     | hash (Print(a0)) = 0w233 + hashtys a0
291 : jhr 458
292 :     fun toString (Add(a0)) = concat["Add<", tyToString a0, ">"]
293 :     | toString (Sub(a0)) = concat["Sub<", tyToString a0, ">"]
294 :     | toString (Mul(a0)) = concat["Mul<", tyToString a0, ">"]
295 :     | toString (Div(a0)) = concat["Div<", tyToString a0, ">"]
296 :     | toString (Neg(a0)) = concat["Neg<", tyToString a0, ">"]
297 : jhr 1116 | toString (Abs(a0)) = concat["Abs<", tyToString a0, ">"]
298 : jhr 458 | toString (LT(a0)) = concat["LT<", tyToString a0, ">"]
299 :     | toString (LTE(a0)) = concat["LTE<", tyToString a0, ">"]
300 :     | toString (EQ(a0)) = concat["EQ<", tyToString a0, ">"]
301 :     | toString (NEQ(a0)) = concat["NEQ<", tyToString a0, ">"]
302 :     | toString (GT(a0)) = concat["GT<", tyToString a0, ">"]
303 :     | toString (GTE(a0)) = concat["GTE<", tyToString a0, ">"]
304 :     | toString Not = "Not"
305 :     | toString Max = "Max"
306 :     | toString Min = "Min"
307 : jhr 1295 | toString (Clamp(a0)) = concat["Clamp<", tyToString a0, ">"]
308 : jhr 1116 | toString (Lerp(a0)) = concat["Lerp<", tyToString a0, ">"]
309 : jhr 458 | toString (Dot(a0)) = concat["Dot<", intToString a0, ">"]
310 : jhr 1116 | toString (MulVecMat(a0,a1)) = concat["MulVecMat<", intToString a0, ",", intToString a1, ">"]
311 :     | toString (MulMatVec(a0,a1)) = concat["MulMatVec<", intToString a0, ",", intToString a1, ">"]
312 :     | toString (MulMatMat(a0,a1,a2)) = concat["MulMatMat<", intToString a0, ",", intToString a1, ",", intToString a2, ">"]
313 : jhr 458 | toString Cross = "Cross"
314 : jhr 1116 | toString (Norm(a0)) = concat["Norm<", tyToString a0, ">"]
315 :     | toString (Normalize(a0)) = concat["Normalize<", intToString a0, ">"]
316 :     | toString (Scale(a0)) = concat["Scale<", tyToString a0, ">"]
317 : jhr 458 | toString (PrincipleEvec(a0)) = concat["PrincipleEvec<", tyToString a0, ">"]
318 : jhr 1640 | toString EigenVecs2x2 = "EigenVecs2x2"
319 :     | toString EigenVecs3x3 = "EigenVecs3x3"
320 :     | toString EigenVals2x2 = "EigenVals2x2"
321 :     | toString EigenVals3x3 = "EigenVals3x3"
322 : jhr 1116 | toString (Identity(a0)) = concat["Identity<", intToString a0, ">"]
323 :     | toString (Zero(a0)) = concat["Zero<", tyToString a0, ">"]
324 : jhr 1640 | toString (Select(a0,a1)) = concat["Select<", tyToString a0, ",", intToString a1, ">"]
325 :     | toString (Index(a0,a1)) = concat["Index<", tyToString a0, ",", intToString a1, ">"]
326 : jhr 458 | toString (Subscript(a0)) = concat["Subscript<", tyToString a0, ">"]
327 : jhr 1116 | toString (Ceiling(a0)) = concat["Ceiling<", intToString a0, ">"]
328 : jhr 458 | toString (Floor(a0)) = concat["Floor<", intToString a0, ">"]
329 : jhr 1116 | toString (Round(a0)) = concat["Round<", intToString a0, ">"]
330 :     | toString (Trunc(a0)) = concat["Trunc<", intToString a0, ">"]
331 : jhr 458 | toString IntToReal = "IntToReal"
332 : jhr 1116 | toString (RealToInt(a0)) = concat["RealToInt<", intToString a0, ">"]
333 : jhr 511 | toString (ImageAddress(a0)) = concat["ImageAddress<", ImageInfo.toString a0, ">"]
334 : jhr 1116 | toString (LoadVoxels(a0,a1)) = concat["LoadVoxels<", ImageInfo.toString a0, ",", intToString a1, ">"]
335 : jhr 458 | toString (PosToImgSpace(a0)) = concat["PosToImgSpace<", ImageInfo.toString a0, ">"]
336 : jhr 1116 | toString (TensorToWorldSpace(a0,a1)) = concat["TensorToWorldSpace<", ImageInfo.toString a0, ",", tyToString a1, ">"]
337 : jhr 458 | toString (LoadImage(a0)) = concat["LoadImage<", ImageInfo.toString a0, ">"]
338 : jhr 1116 | toString (Inside(a0,a1)) = concat["Inside<", ImageInfo.toString a0, ",", intToString a1, ">"]
339 : jhr 1301 | toString (Input(a0,a1,a2)) = concat["Input<", tyToString a0, ",", stringToString a1, ",", stringToString a2, ">"]
340 :     | toString (InputWithDefault(a0,a1,a2)) = concat["InputWithDefault<", tyToString a0, ",", stringToString a1, ",", stringToString a2, ">"]
341 : jhr 1640 | toString (Print(a0)) = concat["Print<", tysToString a0, ">"]
342 : jhr 458
343 :     end
344 :    
345 :     structure LowIL = SSAFn(
346 : jhr 1232 val ilName = "low-il"
347 : jhr 458 structure Ty = LowILTypes
348 :     structure Op = LowOps)
349 : jhr 1116
350 :     structure LowILCensus = CensusFn(LowIL)
351 :    

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