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

SCM Repository

[diderot] Annotation of /branches/vis15/src/compiler/high-ir/high-ir.sml
ViewVC logotype

Annotation of /branches/vis15/src/compiler/high-ir/high-ir.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3506 - (view) (download)

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

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