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

SCM Repository

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

Annotation of /trunk/src/compiler/high-il/high-il.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1640 - (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 : jhr 1116 | Kernel of Kernel.kernel * int
89 : jhr 186 | LoadImage of ImageInfo.info
90 : jhr 1116 | Inside of int
91 :     | Field of int
92 :     | Probe of ty * ty
93 : jhr 195 | AddField
94 : jhr 1116 | SubField
95 : jhr 195 | ScaleField
96 :     | NegField
97 :     | DiffField
98 : jhr 1301 | Input of ty * string * string
99 :     | InputWithDefault of ty * string * string
100 : jhr 1640 | Print of tys
101 : jhr 166
102 : jhr 1640 fun resultArity (Add _) = 1
103 :     | resultArity (Sub _) = 1
104 :     | resultArity (Mul _) = 1
105 :     | resultArity (Div _) = 1
106 :     | resultArity (Neg _) = 1
107 :     | resultArity (Abs _) = 1
108 :     | resultArity (LT _) = 1
109 :     | resultArity (LTE _) = 1
110 :     | resultArity (EQ _) = 1
111 :     | resultArity (NEQ _) = 1
112 :     | resultArity (GT _) = 1
113 :     | resultArity (GTE _) = 1
114 :     | resultArity Power = 1
115 :     | resultArity Not = 1
116 :     | resultArity Max = 1
117 :     | resultArity Min = 1
118 :     | resultArity (Clamp _) = 1
119 :     | resultArity (Lerp _) = 1
120 :     | resultArity (Dot _) = 1
121 :     | resultArity (MulVecMat _) = 1
122 :     | resultArity (MulMatVec _) = 1
123 :     | resultArity (MulMatMat _) = 1
124 :     | resultArity Cross = 1
125 :     | resultArity (Outer _) = 1
126 :     | resultArity (Norm _) = 1
127 :     | resultArity (Normalize _) = 1
128 :     | resultArity (Scale _) = 1
129 :     | resultArity (PrincipleEvec _) = 1
130 :     | resultArity Eigen2x2 = 1
131 :     | resultArity Eigen3x3 = 1
132 :     | resultArity (Identity _) = 1
133 :     | resultArity (Zero _) = 1
134 :     | resultArity (Trace _) = 1
135 :     | resultArity (Slice _) = 1
136 :     | resultArity (TensorSub _) = 1
137 :     | resultArity (Select _) = 1
138 :     | resultArity (SeqSub _) = 1
139 :     | resultArity IntToReal = 1
140 :     | resultArity TruncToInt = 1
141 :     | resultArity RoundToInt = 1
142 :     | resultArity CeilToInt = 1
143 :     | resultArity FloorToInt = 1
144 :     | resultArity (Kernel _) = 1
145 :     | resultArity (LoadImage _) = 1
146 :     | resultArity (Inside _) = 1
147 :     | resultArity (Field _) = 1
148 :     | resultArity (Probe _) = 1
149 :     | resultArity AddField = 1
150 :     | resultArity SubField = 1
151 :     | resultArity ScaleField = 1
152 :     | resultArity NegField = 1
153 :     | resultArity DiffField = 1
154 :     | resultArity (Input _) = 1
155 :     | resultArity (InputWithDefault _) = 1
156 :     | resultArity (Print _) = 0
157 :    
158 : jhr 166 fun arity (Add _) = 2
159 :     | arity (Sub _) = 2
160 :     | arity (Mul _) = 2
161 :     | arity (Div _) = 2
162 :     | arity (Neg _) = 1
163 : jhr 1116 | arity (Abs _) = 1
164 : jhr 180 | arity (LT _) = 2
165 :     | arity (LTE _) = 2
166 :     | arity (EQ _) = 2
167 :     | arity (NEQ _) = 2
168 :     | arity (GT _) = 2
169 :     | arity (GTE _) = 2
170 : jhr 1116 | arity Power = 2
171 :     | arity Not = 1
172 : jhr 400 | arity Max = 2
173 :     | arity Min = 2
174 : jhr 1295 | arity (Clamp _) = 3
175 : jhr 1116 | arity (Lerp _) = 3
176 : jhr 166 | arity (Dot _) = 2
177 : jhr 1116 | arity (MulVecMat _) = 2
178 :     | arity (MulMatVec _) = 2
179 :     | arity (MulMatMat _) = 2
180 : jhr 166 | arity Cross = 2
181 : jhr 1116 | arity (Outer _) = 2
182 : jhr 166 | arity (Norm _) = 1
183 : jhr 1116 | arity (Normalize _) = 1
184 : jhr 166 | arity (Scale _) = 2
185 : jhr 186 | arity (PrincipleEvec _) = 2
186 : jhr 1640 | arity Eigen2x2 = 1
187 :     | arity Eigen3x3 = 1
188 : jhr 1116 | arity (Identity _) = 0
189 :     | arity (Zero _) = 0
190 :     | arity (Trace _) = 1
191 : jhr 400 | arity (Slice _) = 1
192 : jhr 1640 | arity (TensorSub _) = ~1
193 :     | arity (Select _) = 1
194 :     | arity (SeqSub _) = 2
195 : jhr 166 | arity IntToReal = 1
196 :     | arity TruncToInt = 1
197 :     | arity RoundToInt = 1
198 :     | arity CeilToInt = 1
199 :     | arity FloorToInt = 1
200 : jhr 195 | arity (Kernel _) = 0
201 : jhr 1116 | arity (LoadImage _) = 1
202 : jhr 407 | arity (Inside _) = 2
203 : jhr 1116 | arity (Field _) = 2
204 :     | arity (Probe _) = 2
205 : jhr 195 | arity AddField = 2
206 : jhr 1116 | arity SubField = 2
207 : jhr 195 | arity ScaleField = 2
208 :     | arity NegField = 1
209 :     | arity DiffField = 1
210 : jhr 226 | arity (Input _) = 0
211 :     | arity (InputWithDefault _) = 1
212 : jhr 1640 | arity (Print _) = ~1
213 : jhr 166
214 : jhr 282 fun same (Add(a0), Add(b0)) = samety(a0, b0)
215 :     | same (Sub(a0), Sub(b0)) = samety(a0, b0)
216 :     | same (Mul(a0), Mul(b0)) = samety(a0, b0)
217 :     | same (Div(a0), Div(b0)) = samety(a0, b0)
218 :     | same (Neg(a0), Neg(b0)) = samety(a0, b0)
219 : jhr 1116 | same (Abs(a0), Abs(b0)) = samety(a0, b0)
220 : jhr 282 | same (LT(a0), LT(b0)) = samety(a0, b0)
221 :     | same (LTE(a0), LTE(b0)) = samety(a0, b0)
222 :     | same (EQ(a0), EQ(b0)) = samety(a0, b0)
223 :     | same (NEQ(a0), NEQ(b0)) = samety(a0, b0)
224 :     | same (GT(a0), GT(b0)) = samety(a0, b0)
225 :     | same (GTE(a0), GTE(b0)) = samety(a0, b0)
226 : jhr 1116 | same (Power, Power) = true
227 :     | same (Not, Not) = true
228 : jhr 400 | same (Max, Max) = true
229 :     | same (Min, Min) = true
230 : jhr 1295 | same (Clamp(a0), Clamp(b0)) = samety(a0, b0)
231 : jhr 1116 | same (Lerp(a0), Lerp(b0)) = samety(a0, b0)
232 : jhr 282 | same (Dot(a0), Dot(b0)) = samety(a0, b0)
233 : jhr 1116 | same (MulVecMat(a0), MulVecMat(b0)) = samety(a0, b0)
234 :     | same (MulMatVec(a0), MulMatVec(b0)) = samety(a0, b0)
235 :     | same (MulMatMat(a0,a1), MulMatMat(b0,b1)) = samety(a0, b0) andalso samety(a1, b1)
236 : jhr 166 | same (Cross, Cross) = true
237 : jhr 1116 | same (Outer(a0), Outer(b0)) = samety(a0, b0)
238 : jhr 282 | same (Norm(a0), Norm(b0)) = samety(a0, b0)
239 : jhr 1116 | same (Normalize(a0), Normalize(b0)) = samety(a0, b0)
240 : jhr 282 | same (Scale(a0), Scale(b0)) = samety(a0, b0)
241 :     | same (PrincipleEvec(a0), PrincipleEvec(b0)) = samety(a0, b0)
242 : jhr 1640 | same (Eigen2x2, Eigen2x2) = true
243 :     | same (Eigen3x3, Eigen3x3) = true
244 : jhr 1116 | same (Identity(a0), Identity(b0)) = sameint(a0, b0)
245 :     | same (Zero(a0), Zero(b0)) = samety(a0, b0)
246 :     | same (Trace(a0), Trace(b0)) = samety(a0, b0)
247 : jhr 400 | same (Slice(a0,a1), Slice(b0,b1)) = samety(a0, b0) andalso samemask(a1, b1)
248 : jhr 1640 | same (TensorSub(a0), TensorSub(b0)) = samety(a0, b0)
249 :     | same (Select(a0,a1), Select(b0,b1)) = samety(a0, b0) andalso sameint(a1, b1)
250 :     | same (SeqSub(a0), SeqSub(b0)) = samety(a0, b0)
251 : jhr 166 | same (IntToReal, IntToReal) = true
252 :     | same (TruncToInt, TruncToInt) = true
253 :     | same (RoundToInt, RoundToInt) = true
254 :     | same (CeilToInt, CeilToInt) = true
255 :     | same (FloorToInt, FloorToInt) = true
256 : jhr 1116 | same (Kernel(a0,a1), Kernel(b0,b1)) = Kernel.same(a0, b0) andalso sameint(a1, b1)
257 : jhr 282 | same (LoadImage(a0), LoadImage(b0)) = ImageInfo.same(a0, b0)
258 : jhr 1116 | same (Inside(a0), Inside(b0)) = sameint(a0, b0)
259 :     | same (Field(a0), Field(b0)) = sameint(a0, b0)
260 :     | same (Probe(a0,a1), Probe(b0,b1)) = samety(a0, b0) andalso samety(a1, b1)
261 : jhr 195 | same (AddField, AddField) = true
262 : jhr 1116 | same (SubField, SubField) = true
263 : jhr 195 | same (ScaleField, ScaleField) = true
264 :     | same (NegField, NegField) = true
265 :     | same (DiffField, DiffField) = true
266 : jhr 1301 | same (Input(a0,a1,a2), Input(b0,b1,b2)) = samety(a0, b0) andalso samestring(a1, b1) andalso samestring(a2, b2)
267 :     | same (InputWithDefault(a0,a1,a2), InputWithDefault(b0,b1,b2)) = samety(a0, b0) andalso samestring(a1, b1) andalso samestring(a2, b2)
268 : jhr 1640 | same (Print(a0), Print(b0)) = sametys(a0, b0)
269 : jhr 166 | same _ = false
270 :    
271 : jhr 282 fun hash (Add(a0)) = 0w3 + hashty a0
272 :     | hash (Sub(a0)) = 0w5 + hashty a0
273 :     | hash (Mul(a0)) = 0w7 + hashty a0
274 :     | hash (Div(a0)) = 0w11 + hashty a0
275 :     | hash (Neg(a0)) = 0w13 + hashty a0
276 : jhr 1116 | hash (Abs(a0)) = 0w17 + hashty a0
277 :     | hash (LT(a0)) = 0w19 + hashty a0
278 :     | hash (LTE(a0)) = 0w23 + hashty a0
279 :     | hash (EQ(a0)) = 0w29 + hashty a0
280 :     | hash (NEQ(a0)) = 0w31 + hashty a0
281 :     | hash (GT(a0)) = 0w37 + hashty a0
282 :     | hash (GTE(a0)) = 0w41 + hashty a0
283 :     | hash Power = 0w43
284 :     | hash Not = 0w47
285 :     | hash Max = 0w53
286 :     | hash Min = 0w59
287 : jhr 1295 | hash (Clamp(a0)) = 0w61 + hashty a0
288 :     | hash (Lerp(a0)) = 0w67 + hashty a0
289 :     | hash (Dot(a0)) = 0w71 + hashty a0
290 :     | hash (MulVecMat(a0)) = 0w73 + hashty a0
291 :     | hash (MulMatVec(a0)) = 0w79 + hashty a0
292 :     | hash (MulMatMat(a0,a1)) = 0w83 + hashty a0 + hashty a1
293 :     | hash Cross = 0w89
294 :     | hash (Outer(a0)) = 0w97 + hashty a0
295 :     | hash (Norm(a0)) = 0w101 + hashty a0
296 :     | hash (Normalize(a0)) = 0w103 + hashty a0
297 :     | hash (Scale(a0)) = 0w107 + hashty a0
298 : jhr 1444 | hash (PrincipleEvec(a0)) = 0w109 + hashty a0
299 : jhr 1640 | hash Eigen2x2 = 0w113
300 :     | hash Eigen3x3 = 0w127
301 :     | hash (Identity(a0)) = 0w131 + hashint a0
302 :     | hash (Zero(a0)) = 0w137 + hashty a0
303 :     | hash (Trace(a0)) = 0w139 + hashty a0
304 :     | hash (Slice(a0,a1)) = 0w149 + hashty a0 + hashmask a1
305 :     | hash (TensorSub(a0)) = 0w151 + hashty a0
306 :     | hash (Select(a0,a1)) = 0w157 + hashty a0 + hashint a1
307 :     | hash (SeqSub(a0)) = 0w163 + hashty a0
308 :     | hash IntToReal = 0w167
309 :     | hash TruncToInt = 0w173
310 :     | hash RoundToInt = 0w179
311 :     | hash CeilToInt = 0w181
312 :     | hash FloorToInt = 0w191
313 :     | hash (Kernel(a0,a1)) = 0w193 + Kernel.hash a0 + hashint a1
314 :     | hash (LoadImage(a0)) = 0w197 + ImageInfo.hash a0
315 :     | hash (Inside(a0)) = 0w199 + hashint a0
316 :     | hash (Field(a0)) = 0w211 + hashint a0
317 :     | hash (Probe(a0,a1)) = 0w223 + hashty a0 + hashty a1
318 :     | hash AddField = 0w227
319 :     | hash SubField = 0w229
320 :     | hash ScaleField = 0w233
321 :     | hash NegField = 0w239
322 :     | hash DiffField = 0w241
323 :     | hash (Input(a0,a1,a2)) = 0w251 + hashty a0 + hashstring a1 + hashstring a2
324 :     | hash (InputWithDefault(a0,a1,a2)) = 0w257 + hashty a0 + hashstring a1 + hashstring a2
325 :     | hash (Print(a0)) = 0w263 + hashtys a0
326 : jhr 166
327 : jhr 282 fun toString (Add(a0)) = concat["Add<", tyToString a0, ">"]
328 :     | toString (Sub(a0)) = concat["Sub<", tyToString a0, ">"]
329 :     | toString (Mul(a0)) = concat["Mul<", tyToString a0, ">"]
330 :     | toString (Div(a0)) = concat["Div<", tyToString a0, ">"]
331 :     | toString (Neg(a0)) = concat["Neg<", tyToString a0, ">"]
332 : jhr 1116 | toString (Abs(a0)) = concat["Abs<", tyToString a0, ">"]
333 : jhr 282 | toString (LT(a0)) = concat["LT<", tyToString a0, ">"]
334 :     | toString (LTE(a0)) = concat["LTE<", tyToString a0, ">"]
335 :     | toString (EQ(a0)) = concat["EQ<", tyToString a0, ">"]
336 :     | toString (NEQ(a0)) = concat["NEQ<", tyToString a0, ">"]
337 :     | toString (GT(a0)) = concat["GT<", tyToString a0, ">"]
338 :     | toString (GTE(a0)) = concat["GTE<", tyToString a0, ">"]
339 : jhr 1116 | toString Power = "Power"
340 :     | toString Not = "Not"
341 : jhr 400 | toString Max = "Max"
342 :     | toString Min = "Min"
343 : jhr 1295 | toString (Clamp(a0)) = concat["Clamp<", tyToString a0, ">"]
344 : jhr 1116 | toString (Lerp(a0)) = concat["Lerp<", tyToString a0, ">"]
345 : jhr 282 | toString (Dot(a0)) = concat["Dot<", tyToString a0, ">"]
346 : jhr 1116 | toString (MulVecMat(a0)) = concat["MulVecMat<", tyToString a0, ">"]
347 :     | toString (MulMatVec(a0)) = concat["MulMatVec<", tyToString a0, ">"]
348 :     | toString (MulMatMat(a0,a1)) = concat["MulMatMat<", tyToString a0, ",", tyToString a1, ">"]
349 : jhr 186 | toString Cross = "Cross"
350 : jhr 1116 | toString (Outer(a0)) = concat["Outer<", tyToString a0, ">"]
351 : jhr 282 | toString (Norm(a0)) = concat["Norm<", tyToString a0, ">"]
352 : jhr 1116 | toString (Normalize(a0)) = concat["Normalize<", tyToString a0, ">"]
353 : jhr 282 | toString (Scale(a0)) = concat["Scale<", tyToString a0, ">"]
354 :     | toString (PrincipleEvec(a0)) = concat["PrincipleEvec<", tyToString a0, ">"]
355 : jhr 1640 | toString Eigen2x2 = "Eigen2x2"
356 :     | toString Eigen3x3 = "Eigen3x3"
357 : jhr 1116 | toString (Identity(a0)) = concat["Identity<", intToString a0, ">"]
358 :     | toString (Zero(a0)) = concat["Zero<", tyToString a0, ">"]
359 :     | toString (Trace(a0)) = concat["Trace<", tyToString a0, ">"]
360 : jhr 400 | toString (Slice(a0,a1)) = concat["Slice<", tyToString a0, ",", maskToString a1, ">"]
361 : jhr 1640 | toString (TensorSub(a0)) = concat["TensorSub<", tyToString a0, ">"]
362 :     | toString (Select(a0,a1)) = concat["Select<", tyToString a0, ",", intToString a1, ">"]
363 :     | toString (SeqSub(a0)) = concat["SeqSub<", tyToString a0, ">"]
364 : jhr 186 | toString IntToReal = "IntToReal"
365 :     | toString TruncToInt = "TruncToInt"
366 :     | toString RoundToInt = "RoundToInt"
367 :     | toString CeilToInt = "CeilToInt"
368 :     | toString FloorToInt = "FloorToInt"
369 : jhr 1116 | toString (Kernel(a0,a1)) = concat["Kernel<", Kernel.toString a0, ",", intToString a1, ">"]
370 : jhr 282 | toString (LoadImage(a0)) = concat["LoadImage<", ImageInfo.toString a0, ">"]
371 : jhr 1116 | toString (Inside(a0)) = concat["Inside<", intToString a0, ">"]
372 :     | toString (Field(a0)) = concat["Field<", intToString a0, ">"]
373 :     | toString (Probe(a0,a1)) = concat["Probe<", tyToString a0, ",", tyToString a1, ">"]
374 : jhr 195 | toString AddField = "AddField"
375 : jhr 1116 | toString SubField = "SubField"
376 : jhr 195 | toString ScaleField = "ScaleField"
377 :     | toString NegField = "NegField"
378 :     | toString DiffField = "DiffField"
379 : jhr 1301 | toString (Input(a0,a1,a2)) = concat["Input<", tyToString a0, ",", stringToString a1, ",", stringToString a2, ">"]
380 :     | toString (InputWithDefault(a0,a1,a2)) = concat["InputWithDefault<", tyToString a0, ",", stringToString a1, ",", stringToString a2, ">"]
381 : jhr 1640 | toString (Print(a0)) = concat["Print<", tysToString a0, ">"]
382 : jhr 166
383 :     end
384 :    
385 : jhr 392 structure HighIL = SSAFn(
386 : jhr 1232 val ilName = "high-il"
387 : jhr 392 structure Ty = HighILTypes
388 :     structure Op = HighOps)
389 : jhr 1116
390 :     structure HighILCensus = CensusFn(HighIL)
391 :    

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