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 5307 - (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 : jhr 3652 fun tysToString tys = String.concat["[", String.concatWithMap "," tyToString tys, "]" ]
27 : jhr 3474
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 : jhr 3797 (* required helper functions for the shape type *)
39 :     type shape = TensorShape.t
40 :     val sameshape = TensorShape.same
41 :     val hashshape = TensorShape.hash
42 :     val shapeToString = TensorShape.toString
43 :    
44 : jhr 3474 datatype rator
45 :     = IAdd
46 :     | ISub
47 :     | IMul
48 :     | IDiv
49 :     | IMod
50 :     | INeg
51 : jhr 5307 | IAbs
52 : jhr 3474 | LT of ty
53 :     | LTE of ty
54 :     | EQ of ty
55 :     | NEQ of ty
56 :     | GT of ty
57 :     | GTE of ty
58 :     | Power
59 : jhr 4434 | BAnd
60 :     | BOr
61 :     | BNot
62 : jhr 3483 | Max of ty
63 :     | Min of ty
64 : jhr 3474 | Eigen2x2
65 :     | Eigen3x3
66 : jhr 3493 | Zero of ty
67 : jhr 3797 | TensorIndex of ty * shape
68 : jhr 3474 | Select of ty * int
69 : jhr 3508 | Subscript of ty
70 : jhr 3474 | MkDynamic of ty * int
71 :     | Append of ty
72 :     | Prepend of ty
73 :     | Concat of ty
74 : jhr 3508 | Range
75 :     | Length of ty
76 : jhr 4349 | SphereQuery of int * ty
77 : jhr 3474 | IntToReal
78 :     | TruncToInt
79 :     | RoundToInt
80 :     | CeilToInt
81 :     | FloorToInt
82 : jhr 4394 | NumStrands of StrandSets.t
83 : jhr 4362 | Strands of ty * StrandSets.t
84 : jhr 4043 | Kernel of Kernel.t * int
85 : jhr 4432 | Inside of ImageInfo.t * int
86 :     | ImageDim of ImageInfo.t * int
87 :     | BorderCtlDefault of ImageInfo.t
88 :     | BorderCtlClamp of ImageInfo.t
89 :     | BorderCtlMirror of ImageInfo.t
90 :     | BorderCtlWrap of ImageInfo.t
91 : jhr 3474 | LoadSeq of ty * string
92 :     | LoadImage of ty * string
93 : jhr 4628 | KillAll
94 : jhr 4480 | StabilizeAll
95 : jhr 3474 | Print of tys
96 : jhr 3511 | MathFn of MathFns.t
97 : jhr 3474
98 :     fun resultArity IAdd = 1
99 :     | resultArity ISub = 1
100 :     | resultArity IMul = 1
101 :     | resultArity IDiv = 1
102 :     | resultArity IMod = 1
103 :     | resultArity INeg = 1
104 : jhr 5307 | resultArity IAbs = 1
105 : jhr 3474 | resultArity (LT _) = 1
106 :     | resultArity (LTE _) = 1
107 :     | resultArity (EQ _) = 1
108 :     | resultArity (NEQ _) = 1
109 :     | resultArity (GT _) = 1
110 :     | resultArity (GTE _) = 1
111 :     | resultArity Power = 1
112 : jhr 4434 | resultArity BAnd = 1
113 :     | resultArity BOr = 1
114 :     | resultArity BNot = 1
115 : jhr 3483 | resultArity (Max _) = 1
116 :     | resultArity (Min _) = 1
117 : jhr 4265 | resultArity Eigen2x2 = 2
118 :     | resultArity Eigen3x3 = 2
119 : jhr 3493 | resultArity (Zero _) = 1
120 : jhr 3508 | resultArity (TensorIndex _) = 1
121 : jhr 3474 | resultArity (Select _) = 1
122 : jhr 3508 | resultArity (Subscript _) = 1
123 : jhr 3474 | resultArity (MkDynamic _) = 1
124 : jhr 3866 | resultArity (Append _) = 1
125 :     | resultArity (Prepend _) = 1
126 :     | resultArity (Concat _) = 1
127 :     | resultArity Range = 1
128 : jhr 3508 | resultArity (Length _) = 1
129 : jhr 3474 | resultArity (SphereQuery _) = 1
130 :     | resultArity IntToReal = 1
131 :     | resultArity TruncToInt = 1
132 :     | resultArity RoundToInt = 1
133 :     | resultArity CeilToInt = 1
134 :     | resultArity FloorToInt = 1
135 : jhr 4394 | resultArity (NumStrands _) = 1
136 : jhr 4362 | resultArity (Strands _) = 1
137 : jhr 3474 | resultArity (Kernel _) = 1
138 :     | resultArity (Inside _) = 1
139 :     | resultArity (ImageDim _) = 1
140 :     | resultArity (BorderCtlDefault _) = 1
141 :     | resultArity (BorderCtlClamp _) = 1
142 :     | resultArity (BorderCtlMirror _) = 1
143 :     | resultArity (BorderCtlWrap _) = 1
144 :     | resultArity (LoadSeq _) = 1
145 :     | resultArity (LoadImage _) = 1
146 : jhr 4628 | resultArity KillAll = 0
147 : jhr 4480 | resultArity StabilizeAll = 0
148 : jhr 3474 | resultArity (Print _) = 0
149 : jhr 3511 | resultArity (MathFn _) = 1
150 : jhr 3474
151 :     fun arity IAdd = 2
152 :     | arity ISub = 2
153 :     | arity IMul = 2
154 :     | arity IDiv = 2
155 :     | arity IMod = 2
156 :     | arity INeg = 1
157 : jhr 5307 | arity IAbs = 1
158 : jhr 3474 | arity (LT _) = 2
159 :     | arity (LTE _) = 2
160 :     | arity (EQ _) = 2
161 :     | arity (NEQ _) = 2
162 :     | arity (GT _) = 2
163 :     | arity (GTE _) = 2
164 :     | arity Power = 2
165 : jhr 4434 | arity BAnd = 2
166 :     | arity BOr = 2
167 :     | arity BNot = 1
168 : jhr 3483 | arity (Max _) = 2
169 :     | arity (Min _) = 2
170 : jhr 3474 | arity Eigen2x2 = 1
171 :     | arity Eigen3x3 = 1
172 : jhr 3493 | arity (Zero _) = 0
173 : jhr 3797 | arity (TensorIndex _) = 1
174 : jhr 3474 | arity (Select _) = 1
175 : jhr 3508 | arity (Subscript _) = 2
176 : jhr 3474 | arity (MkDynamic _) = 1
177 : jhr 3866 | arity (Append _) = 2
178 :     | arity (Prepend _) = 2
179 :     | arity (Concat _) = 2
180 :     | arity Range = 2
181 : jhr 3508 | arity (Length _) = 1
182 : jhr 3474 | arity (SphereQuery _) = 2
183 :     | arity IntToReal = 1
184 :     | arity TruncToInt = 1
185 :     | arity RoundToInt = 1
186 :     | arity CeilToInt = 1
187 :     | arity FloorToInt = 1
188 : jhr 4394 | arity (NumStrands _) = 0
189 : jhr 4362 | arity (Strands _) = 0
190 : jhr 3474 | arity (Kernel _) = 0
191 :     | arity (Inside _) = 2
192 :     | arity (ImageDim _) = 1
193 :     | arity (BorderCtlDefault _) = 2
194 :     | arity (BorderCtlClamp _) = 1
195 :     | arity (BorderCtlMirror _) = 1
196 :     | arity (BorderCtlWrap _) = 1
197 :     | arity (LoadSeq _) = 0
198 :     | arity (LoadImage _) = 0
199 : jhr 4628 | arity KillAll = 0
200 : jhr 4480 | arity StabilizeAll = 0
201 : jhr 3474 | arity (Print _) = ~1
202 : jhr 3511 | arity (MathFn _) = ~1
203 : jhr 3474
204 :     fun isPure (MkDynamic _) = false
205 :     | isPure (Append _) = false
206 :     | isPure (Prepend _) = false
207 :     | isPure (Concat _) = false
208 : jhr 4628 | isPure KillAll = false
209 : jhr 4480 | isPure StabilizeAll = false
210 : jhr 3474 | isPure (Print _) = false
211 :     | isPure _ = true
212 :    
213 :     fun same (IAdd, IAdd) = true
214 :     | same (ISub, ISub) = true
215 :     | same (IMul, IMul) = true
216 :     | same (IDiv, IDiv) = true
217 :     | same (IMod, IMod) = true
218 :     | same (INeg, INeg) = true
219 : jhr 5307 | same (IAbs, IAbs) = true
220 : jhr 3474 | 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 :     | same (Power, Power) = true
227 : jhr 4434 | same (BAnd, BAnd) = true
228 :     | same (BOr, BOr) = true
229 :     | same (BNot, BNot) = true
230 : jhr 3483 | same (Max(a0), Max(b0)) = samety(a0, b0)
231 :     | same (Min(a0), Min(b0)) = samety(a0, b0)
232 : jhr 3474 | same (Eigen2x2, Eigen2x2) = true
233 :     | same (Eigen3x3, Eigen3x3) = true
234 : jhr 3493 | same (Zero(a0), Zero(b0)) = samety(a0, b0)
235 : jhr 3797 | same (TensorIndex(a0,a1), TensorIndex(b0,b1)) = samety(a0, b0) andalso sameshape(a1, b1)
236 : jhr 3474 | same (Select(a0,a1), Select(b0,b1)) = samety(a0, b0) andalso sameint(a1, b1)
237 : jhr 3508 | same (Subscript(a0), Subscript(b0)) = samety(a0, b0)
238 : jhr 3474 | same (MkDynamic(a0,a1), MkDynamic(b0,b1)) = samety(a0, b0) andalso sameint(a1, b1)
239 :     | same (Append(a0), Append(b0)) = samety(a0, b0)
240 :     | same (Prepend(a0), Prepend(b0)) = samety(a0, b0)
241 :     | same (Concat(a0), Concat(b0)) = samety(a0, b0)
242 : jhr 3508 | same (Range, Range) = true
243 :     | same (Length(a0), Length(b0)) = samety(a0, b0)
244 : jhr 4349 | same (SphereQuery(a0,a1), SphereQuery(b0,b1)) = sameint(a0, b0) andalso samety(a1, b1)
245 : jhr 3474 | same (IntToReal, IntToReal) = true
246 :     | same (TruncToInt, TruncToInt) = true
247 :     | same (RoundToInt, RoundToInt) = true
248 :     | same (CeilToInt, CeilToInt) = true
249 :     | same (FloorToInt, FloorToInt) = true
250 : jhr 4394 | same (NumStrands(a0), NumStrands(b0)) = StrandSets.same(a0, b0)
251 : jhr 4362 | same (Strands(a0,a1), Strands(b0,b1)) = samety(a0, b0) andalso StrandSets.same(a1, b1)
252 : jhr 3474 | same (Kernel(a0,a1), Kernel(b0,b1)) = Kernel.same(a0, b0) andalso sameint(a1, b1)
253 : jhr 4043 | same (Inside(a0,a1), Inside(b0,b1)) = ImageInfo.same(a0, b0) andalso sameint(a1, b1)
254 : jhr 3474 | same (ImageDim(a0,a1), ImageDim(b0,b1)) = ImageInfo.same(a0, b0) andalso sameint(a1, b1)
255 :     | same (BorderCtlDefault(a0), BorderCtlDefault(b0)) = ImageInfo.same(a0, b0)
256 :     | same (BorderCtlClamp(a0), BorderCtlClamp(b0)) = ImageInfo.same(a0, b0)
257 :     | same (BorderCtlMirror(a0), BorderCtlMirror(b0)) = ImageInfo.same(a0, b0)
258 :     | same (BorderCtlWrap(a0), BorderCtlWrap(b0)) = ImageInfo.same(a0, b0)
259 :     | same (LoadSeq(a0,a1), LoadSeq(b0,b1)) = samety(a0, b0) andalso samestring(a1, b1)
260 :     | same (LoadImage(a0,a1), LoadImage(b0,b1)) = samety(a0, b0) andalso samestring(a1, b1)
261 : jhr 4628 | same (KillAll, KillAll) = true
262 : jhr 4480 | same (StabilizeAll, StabilizeAll) = true
263 : jhr 3474 | same (Print(a0), Print(b0)) = sametys(a0, b0)
264 : jhr 3511 | same (MathFn(a0), MathFn(b0)) = MathFns.same(a0, b0)
265 : jhr 3474 | same _ = false
266 :    
267 :     fun hash IAdd = 0w3
268 :     | hash ISub = 0w5
269 :     | hash IMul = 0w7
270 :     | hash IDiv = 0w11
271 :     | hash IMod = 0w13
272 :     | hash INeg = 0w17
273 : jhr 5307 | hash IAbs = 0w19
274 :     | hash (LT(a0)) = 0w23 + hashty a0
275 :     | hash (LTE(a0)) = 0w29 + hashty a0
276 :     | hash (EQ(a0)) = 0w31 + hashty a0
277 :     | hash (NEQ(a0)) = 0w37 + hashty a0
278 :     | hash (GT(a0)) = 0w41 + hashty a0
279 :     | hash (GTE(a0)) = 0w43 + hashty a0
280 :     | hash Power = 0w47
281 :     | hash BAnd = 0w53
282 :     | hash BOr = 0w59
283 :     | hash BNot = 0w61
284 : jhr 4434 | hash (Max(a0)) = 0w67 + hashty a0
285 :     | hash (Min(a0)) = 0w71 + hashty a0
286 : cchiw 5241 | hash Eigen2x2 = 0w73
287 :     | hash Eigen3x3 = 0w79
288 :     | hash (Zero(a0)) = 0w83 + hashty a0
289 :     | hash (TensorIndex(a0,a1)) = 0w89 + hashty a0 + hashshape a1
290 :     | hash (Select(a0,a1)) = 0w97 + hashty a0 + hashint a1
291 :     | hash (Subscript(a0)) = 0w101 + hashty a0
292 :     | hash (MkDynamic(a0,a1)) = 0w103 + hashty a0 + hashint a1
293 :     | hash (Append(a0)) = 0w107 + hashty a0
294 :     | hash (Prepend(a0)) = 0w109 + hashty a0
295 :     | hash (Concat(a0)) = 0w113 + hashty a0
296 :     | hash Range = 0w127
297 :     | hash (Length(a0)) = 0w131 + hashty a0
298 :     | hash (SphereQuery(a0,a1)) = 0w137 + hashint a0 + hashty a1
299 :     | hash IntToReal = 0w139
300 :     | hash TruncToInt = 0w149
301 :     | hash RoundToInt = 0w151
302 :     | hash CeilToInt = 0w157
303 :     | hash FloorToInt = 0w163
304 :     | hash (NumStrands(a0)) = 0w167 + StrandSets.hash a0
305 :     | hash (Strands(a0,a1)) = 0w173 + hashty a0 + StrandSets.hash a1
306 :     | hash (Kernel(a0,a1)) = 0w179 + Kernel.hash a0 + hashint a1
307 :     | hash (Inside(a0,a1)) = 0w181 + ImageInfo.hash a0 + hashint a1
308 :     | hash (ImageDim(a0,a1)) = 0w191 + ImageInfo.hash a0 + hashint a1
309 :     | hash (BorderCtlDefault(a0)) = 0w193 + ImageInfo.hash a0
310 :     | hash (BorderCtlClamp(a0)) = 0w197 + ImageInfo.hash a0
311 :     | hash (BorderCtlMirror(a0)) = 0w199 + ImageInfo.hash a0
312 :     | hash (BorderCtlWrap(a0)) = 0w211 + ImageInfo.hash a0
313 :     | hash (LoadSeq(a0,a1)) = 0w223 + hashty a0 + hashstring a1
314 :     | hash (LoadImage(a0,a1)) = 0w227 + hashty a0 + hashstring a1
315 :     | hash KillAll = 0w229
316 :     | hash StabilizeAll = 0w233
317 :     | hash (Print(a0)) = 0w239 + hashtys a0
318 :     | hash (MathFn(a0)) = 0w241 + MathFns.hash a0
319 : jhr 3474
320 :     fun toString IAdd = "IAdd"
321 :     | toString ISub = "ISub"
322 :     | toString IMul = "IMul"
323 :     | toString IDiv = "IDiv"
324 :     | toString IMod = "IMod"
325 :     | toString INeg = "INeg"
326 : jhr 5307 | toString IAbs = "IAbs"
327 : jhr 3474 | toString (LT(a0)) = concat["LT<", tyToString a0, ">"]
328 :     | toString (LTE(a0)) = concat["LTE<", tyToString a0, ">"]
329 :     | toString (EQ(a0)) = concat["EQ<", tyToString a0, ">"]
330 :     | toString (NEQ(a0)) = concat["NEQ<", tyToString a0, ">"]
331 :     | toString (GT(a0)) = concat["GT<", tyToString a0, ">"]
332 :     | toString (GTE(a0)) = concat["GTE<", tyToString a0, ">"]
333 :     | toString Power = "Power"
334 : jhr 4434 | toString BAnd = "BAnd"
335 :     | toString BOr = "BOr"
336 :     | toString BNot = "BNot"
337 : jhr 3483 | toString (Max(a0)) = concat["Max<", tyToString a0, ">"]
338 :     | toString (Min(a0)) = concat["Min<", tyToString a0, ">"]
339 : jhr 3474 | toString Eigen2x2 = "Eigen2x2"
340 :     | toString Eigen3x3 = "Eigen3x3"
341 : jhr 3493 | toString (Zero(a0)) = concat["Zero<", tyToString a0, ">"]
342 : jhr 3797 | toString (TensorIndex(a0,a1)) = concat["TensorIndex<", tyToString a0, ",", shapeToString a1, ">"]
343 : jhr 3474 | toString (Select(a0,a1)) = concat["Select<", tyToString a0, ",", intToString a1, ">"]
344 : jhr 3508 | toString (Subscript(a0)) = concat["Subscript<", tyToString a0, ">"]
345 : jhr 3474 | toString (MkDynamic(a0,a1)) = concat["MkDynamic<", tyToString a0, ",", intToString a1, ">"]
346 :     | toString (Append(a0)) = concat["Append<", tyToString a0, ">"]
347 :     | toString (Prepend(a0)) = concat["Prepend<", tyToString a0, ">"]
348 :     | toString (Concat(a0)) = concat["Concat<", tyToString a0, ">"]
349 : jhr 3508 | toString Range = "Range"
350 :     | toString (Length(a0)) = concat["Length<", tyToString a0, ">"]
351 : jhr 4349 | toString (SphereQuery(a0,a1)) = concat["SphereQuery<", intToString a0, ",", tyToString a1, ">"]
352 : jhr 3474 | toString IntToReal = "IntToReal"
353 :     | toString TruncToInt = "TruncToInt"
354 :     | toString RoundToInt = "RoundToInt"
355 :     | toString CeilToInt = "CeilToInt"
356 :     | toString FloorToInt = "FloorToInt"
357 : jhr 4394 | toString (NumStrands(a0)) = concat["NumStrands<", StrandSets.toString a0, ">"]
358 : jhr 4362 | toString (Strands(a0,a1)) = concat["Strands<", tyToString a0, ",", StrandSets.toString a1, ">"]
359 : jhr 3474 | toString (Kernel(a0,a1)) = concat["Kernel<", Kernel.toString a0, ",", intToString a1, ">"]
360 : jhr 4043 | toString (Inside(a0,a1)) = concat["Inside<", ImageInfo.toString a0, ",", intToString a1, ">"]
361 : jhr 3474 | toString (ImageDim(a0,a1)) = concat["ImageDim<", ImageInfo.toString a0, ",", intToString a1, ">"]
362 :     | toString (BorderCtlDefault(a0)) = concat["BorderCtlDefault<", ImageInfo.toString a0, ">"]
363 :     | toString (BorderCtlClamp(a0)) = concat["BorderCtlClamp<", ImageInfo.toString a0, ">"]
364 :     | toString (BorderCtlMirror(a0)) = concat["BorderCtlMirror<", ImageInfo.toString a0, ">"]
365 :     | toString (BorderCtlWrap(a0)) = concat["BorderCtlWrap<", ImageInfo.toString a0, ">"]
366 :     | toString (LoadSeq(a0,a1)) = concat["LoadSeq<", tyToString a0, ",", stringToString a1, ">"]
367 :     | toString (LoadImage(a0,a1)) = concat["LoadImage<", tyToString a0, ",", stringToString a1, ">"]
368 : jhr 4628 | toString KillAll = "KillAll"
369 : jhr 4480 | toString StabilizeAll = "StabilizeAll"
370 : jhr 3474 | toString (Print(a0)) = concat["Print<", tysToString a0, ">"]
371 : jhr 3511 | toString (MathFn(a0)) = concat["MathFn<", MathFns.toString a0, ">"]
372 : jhr 3474
373 :     end
374 :    
375 : jhr 3475 structure HighIR = SSAFn(
376 : jhr 3508 val irName = "high-ir"
377 : jhr 3475 structure Ty = HighTypes
378 : jhr 3474 structure Op = HighOps)
379 :    
380 : jhr 3475 structure HighCensus = CensusFn(HighIR)

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