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

SCM Repository

[diderot] Annotation of /branches/lamont_dev/src/compiler/high-il/high-il.sml
ViewVC logotype

Annotation of /branches/lamont_dev/src/compiler/high-il/high-il.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2039 - (view) (download)

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

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