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

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