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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3506 - (view) (download)

1 : jhr 3480 (* mid-ir.sml
2 :     *
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 :     * Middle-level version of the Diderot CFG IR
9 :     *
10 :     * Note: this file is generated from gen/ir/mid-ir.spec and gen/ir/mid-ir.in.
11 :     *)
12 :    
13 :     structure MidOps =
14 :     struct
15 :    
16 :     (* required helper functions for types *)
17 :     type ty = MidTypes.ty
18 :     val samety = MidTypes.same
19 :     val hashty = MidTypes.hash
20 :     val tyToString = MidTypes.toString
21 :    
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 index control type type *)
48 :     type idxctl = IndexCtl.ctl
49 :     val sameidxctl = IndexCtl.same
50 :     val hashidxctl = IndexCtl.hash
51 :     val idxctlToString = IndexCtl.toString
52 :    
53 :     datatype rator
54 :     = IAdd
55 :     | ISub
56 :     | IMul
57 :     | IDiv
58 :     | IMod
59 :     | INeg
60 :     | LT of ty
61 :     | LTE of ty
62 :     | EQ of ty
63 :     | NEQ of ty
64 :     | GT of ty
65 :     | GTE of ty
66 :     | Not
67 : jhr 3483 | Abs of ty
68 :     | Max of ty
69 :     | Min of ty
70 : jhr 3480 | Clamp of ty
71 :     | Lerp of ty
72 :     | Normalize of int
73 :     | PrincipleEvec of ty
74 :     | EigenVecs2x2
75 :     | EigenVecs3x3
76 :     | EigenVals2x2
77 :     | EigenVals3x3
78 :     | Zero of ty
79 :     | Select of ty * int
80 :     | Index of ty * int
81 :     | Subscript of ty
82 :     | MkDynamic of ty * int
83 :     | Append of ty
84 :     | Prepend of ty
85 :     | Concat of ty
86 :     | Length of ty
87 :     | Ceiling of int
88 :     | Floor of int
89 :     | Round of int
90 :     | Trunc of int
91 :     | IntToReal
92 :     | RealToInt of int
93 :     | Kernel of Kernel.kernel * int
94 :     | Transform of ImageInfo.info
95 :     | Translate of ImageInfo.info
96 :     | EvalKernel of int * Kernel.kernel * int
97 :     | VoxelAddress of ImageInfo.info * int
98 :     | VoxelAddressWithCtl of ImageInfo.info * int * idxctl
99 :     | LoadVoxels of ImageInfo.info * int
100 :     | Inside of ImageInfo.info * int
101 :     | ImageDim of ImageInfo.info * int
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 Not = 1
119 : jhr 3483 | resultArity (Abs _) = 1
120 :     | resultArity (Max _) = 1
121 :     | resultArity (Min _) = 1
122 : jhr 3480 | resultArity (Clamp _) = 1
123 :     | resultArity (Lerp _) = 1
124 :     | resultArity (Normalize _) = 1
125 :     | resultArity (PrincipleEvec _) = 1
126 :     | resultArity EigenVecs2x2 = 1
127 :     | resultArity EigenVecs3x3 = 1
128 :     | resultArity EigenVals2x2 = 1
129 :     | resultArity EigenVals3x3 = 1
130 :     | resultArity (Zero _) = 1
131 :     | resultArity (Select _) = 1
132 :     | resultArity (Index _) = 1
133 :     | resultArity (Subscript _) = 1
134 :     | resultArity (MkDynamic _) = 1
135 :     | resultArity (Append _) = 2
136 :     | resultArity (Prepend _) = 2
137 :     | resultArity (Concat _) = 2
138 :     | resultArity (Length _) = 1
139 :     | resultArity (Ceiling _) = 1
140 :     | resultArity (Floor _) = 1
141 :     | resultArity (Round _) = 1
142 :     | resultArity (Trunc _) = 1
143 :     | resultArity IntToReal = 1
144 :     | resultArity (RealToInt _) = 1
145 :     | resultArity (Kernel _) = 1
146 :     | resultArity (Transform _) = 1
147 :     | resultArity (Translate _) = 1
148 :     | resultArity (EvalKernel _) = 1
149 :     | resultArity (VoxelAddress _) = 1
150 :     | resultArity (VoxelAddressWithCtl _) = 1
151 :     | resultArity (LoadVoxels _) = 1
152 :     | resultArity (Inside _) = 1
153 :     | resultArity (ImageDim _) = 1
154 :     | resultArity (LoadSeq _) = 1
155 :     | resultArity (LoadImage _) = 1
156 :     | resultArity (Print _) = 0
157 :    
158 :     fun arity IAdd = 2
159 :     | arity ISub = 2
160 :     | arity IMul = 2
161 :     | arity IDiv = 2
162 :     | arity IMod = 2
163 :     | arity INeg = 1
164 :     | arity (LT _) = 2
165 :     | arity (LTE _) = 2
166 :     | arity (EQ _) = 2
167 :     | arity (NEQ _) = 2
168 :     | arity (GT _) = 2
169 :     | arity (GTE _) = 2
170 :     | arity Not = 1
171 : jhr 3483 | arity (Abs _) = 1
172 :     | arity (Max _) = 2
173 :     | arity (Min _) = 2
174 : jhr 3480 | arity (Clamp _) = 3
175 :     | arity (Lerp _) = 3
176 :     | arity (Normalize _) = 1
177 :     | arity (PrincipleEvec _) = 2
178 :     | arity EigenVecs2x2 = 1
179 :     | arity EigenVecs3x3 = 1
180 :     | arity EigenVals2x2 = 1
181 :     | arity EigenVals3x3 = 1
182 :     | arity (Zero _) = 0
183 :     | arity (Select _) = 1
184 :     | arity (Index _) = 1
185 :     | arity (Subscript _) = 2
186 :     | arity (MkDynamic _) = 1
187 :     | arity (Append _) = 1
188 :     | arity (Prepend _) = 1
189 :     | arity (Concat _) = 1
190 :     | arity (Length _) = 1
191 :     | arity (Ceiling _) = 1
192 :     | arity (Floor _) = 1
193 :     | arity (Round _) = 1
194 :     | arity (Trunc _) = 1
195 :     | arity IntToReal = 1
196 :     | arity (RealToInt _) = 1
197 :     | arity (Kernel _) = 0
198 :     | arity (Transform _) = 1
199 :     | arity (Translate _) = 1
200 :     | arity (EvalKernel _) = 1
201 :     | arity (VoxelAddress _) = ~1
202 :     | arity (VoxelAddressWithCtl _) = ~1
203 :     | arity (LoadVoxels _) = 1
204 :     | arity (Inside _) = 2
205 :     | arity (ImageDim _) = 1
206 :     | arity (LoadSeq _) = 0
207 :     | arity (LoadImage _) = 0
208 :     | arity (Print _) = ~1
209 :    
210 :     fun isPure (MkDynamic _) = false
211 :     | isPure (Append _) = false
212 :     | isPure (Prepend _) = false
213 :     | isPure (Concat _) = false
214 :     | isPure (Print _) = false
215 :     | isPure _ = true
216 :    
217 :     fun same (IAdd, IAdd) = true
218 :     | same (ISub, ISub) = true
219 :     | same (IMul, IMul) = true
220 :     | same (IDiv, IDiv) = true
221 :     | same (IMod, IMod) = true
222 :     | same (INeg, INeg) = true
223 :     | 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 :     | same (Not, Not) = true
230 : jhr 3483 | same (Abs(a0), Abs(b0)) = samety(a0, b0)
231 :     | same (Max(a0), Max(b0)) = samety(a0, b0)
232 :     | same (Min(a0), Min(b0)) = samety(a0, b0)
233 : jhr 3480 | same (Clamp(a0), Clamp(b0)) = samety(a0, b0)
234 :     | same (Lerp(a0), Lerp(b0)) = samety(a0, b0)
235 :     | same (Normalize(a0), Normalize(b0)) = sameint(a0, b0)
236 :     | same (PrincipleEvec(a0), PrincipleEvec(b0)) = samety(a0, b0)
237 :     | same (EigenVecs2x2, EigenVecs2x2) = true
238 :     | same (EigenVecs3x3, EigenVecs3x3) = true
239 :     | same (EigenVals2x2, EigenVals2x2) = true
240 :     | same (EigenVals3x3, EigenVals3x3) = true
241 :     | same (Zero(a0), Zero(b0)) = samety(a0, b0)
242 :     | same (Select(a0,a1), Select(b0,b1)) = samety(a0, b0) andalso sameint(a1, b1)
243 :     | same (Index(a0,a1), Index(b0,b1)) = samety(a0, b0) andalso sameint(a1, b1)
244 :     | same (Subscript(a0), Subscript(b0)) = samety(a0, b0)
245 :     | same (MkDynamic(a0,a1), MkDynamic(b0,b1)) = samety(a0, b0) andalso sameint(a1, b1)
246 :     | same (Append(a0), Append(b0)) = samety(a0, b0)
247 :     | same (Prepend(a0), Prepend(b0)) = samety(a0, b0)
248 :     | same (Concat(a0), Concat(b0)) = samety(a0, b0)
249 :     | same (Length(a0), Length(b0)) = samety(a0, b0)
250 :     | same (Ceiling(a0), Ceiling(b0)) = sameint(a0, b0)
251 :     | same (Floor(a0), Floor(b0)) = sameint(a0, b0)
252 :     | same (Round(a0), Round(b0)) = sameint(a0, b0)
253 :     | same (Trunc(a0), Trunc(b0)) = sameint(a0, b0)
254 :     | same (IntToReal, IntToReal) = true
255 :     | same (RealToInt(a0), RealToInt(b0)) = sameint(a0, b0)
256 :     | same (Kernel(a0,a1), Kernel(b0,b1)) = Kernel.same(a0, b0) andalso sameint(a1, b1)
257 :     | same (Transform(a0), Transform(b0)) = ImageInfo.same(a0, b0)
258 :     | same (Translate(a0), Translate(b0)) = ImageInfo.same(a0, b0)
259 :     | same (EvalKernel(a0,a1,a2), EvalKernel(b0,b1,b2)) = sameint(a0, b0) andalso Kernel.same(a1, b1) andalso sameint(a2, b2)
260 :     | same (VoxelAddress(a0,a1), VoxelAddress(b0,b1)) = ImageInfo.same(a0, b0) andalso sameint(a1, b1)
261 :     | same (VoxelAddressWithCtl(a0,a1,a2), VoxelAddressWithCtl(b0,b1,b2)) = ImageInfo.same(a0, b0) andalso sameint(a1, b1) andalso sameidxctl(a2, b2)
262 :     | same (LoadVoxels(a0,a1), LoadVoxels(b0,b1)) = ImageInfo.same(a0, b0) andalso sameint(a1, b1)
263 :     | same (Inside(a0,a1), Inside(b0,b1)) = ImageInfo.same(a0, b0) andalso sameint(a1, b1)
264 :     | same (ImageDim(a0,a1), ImageDim(b0,b1)) = ImageInfo.same(a0, b0) andalso sameint(a1, b1)
265 :     | same (LoadSeq(a0,a1), LoadSeq(b0,b1)) = samety(a0, b0) andalso samestring(a1, b1)
266 :     | same (LoadImage(a0,a1), LoadImage(b0,b1)) = samety(a0, b0) andalso samestring(a1, b1)
267 :     | same (Print(a0), Print(b0)) = sametys(a0, b0)
268 :     | same _ = false
269 :    
270 :     fun hash IAdd = 0w3
271 :     | hash ISub = 0w5
272 :     | hash IMul = 0w7
273 :     | hash IDiv = 0w11
274 :     | hash IMod = 0w13
275 :     | hash INeg = 0w17
276 : jhr 3483 | hash (LT(a0)) = 0w19 + hashty a0
277 :     | hash (LTE(a0)) = 0w23 + hashty a0
278 :     | hash (EQ(a0)) = 0w29 + hashty a0
279 :     | hash (NEQ(a0)) = 0w31 + hashty a0
280 :     | hash (GT(a0)) = 0w37 + hashty a0
281 :     | hash (GTE(a0)) = 0w41 + hashty a0
282 :     | hash Not = 0w43
283 :     | hash (Abs(a0)) = 0w47 + hashty a0
284 :     | hash (Max(a0)) = 0w53 + hashty a0
285 :     | hash (Min(a0)) = 0w59 + hashty a0
286 : jhr 3480 | hash (Clamp(a0)) = 0w61 + hashty a0
287 :     | hash (Lerp(a0)) = 0w67 + hashty a0
288 :     | hash (Normalize(a0)) = 0w71 + hashint a0
289 :     | hash (PrincipleEvec(a0)) = 0w73 + hashty a0
290 :     | hash EigenVecs2x2 = 0w79
291 :     | hash EigenVecs3x3 = 0w83
292 :     | hash EigenVals2x2 = 0w89
293 :     | hash EigenVals3x3 = 0w97
294 :     | hash (Zero(a0)) = 0w101 + hashty a0
295 :     | hash (Select(a0,a1)) = 0w103 + hashty a0 + hashint a1
296 :     | hash (Index(a0,a1)) = 0w107 + hashty a0 + hashint a1
297 :     | hash (Subscript(a0)) = 0w109 + hashty a0
298 :     | hash (MkDynamic(a0,a1)) = 0w113 + hashty a0 + hashint a1
299 :     | hash (Append(a0)) = 0w127 + hashty a0
300 :     | hash (Prepend(a0)) = 0w131 + hashty a0
301 :     | hash (Concat(a0)) = 0w137 + hashty a0
302 :     | hash (Length(a0)) = 0w139 + hashty a0
303 :     | hash (Ceiling(a0)) = 0w149 + hashint a0
304 :     | hash (Floor(a0)) = 0w151 + hashint a0
305 :     | hash (Round(a0)) = 0w157 + hashint a0
306 :     | hash (Trunc(a0)) = 0w163 + hashint a0
307 :     | hash IntToReal = 0w167
308 :     | hash (RealToInt(a0)) = 0w173 + hashint a0
309 :     | hash (Kernel(a0,a1)) = 0w179 + Kernel.hash a0 + hashint a1
310 :     | hash (Transform(a0)) = 0w181 + ImageInfo.hash a0
311 :     | hash (Translate(a0)) = 0w191 + ImageInfo.hash a0
312 :     | hash (EvalKernel(a0,a1,a2)) = 0w193 + hashint a0 + Kernel.hash a1 + hashint a2
313 :     | hash (VoxelAddress(a0,a1)) = 0w197 + ImageInfo.hash a0 + hashint a1
314 :     | hash (VoxelAddressWithCtl(a0,a1,a2)) = 0w199 + ImageInfo.hash a0 + hashint a1 + hashidxctl a2
315 :     | hash (LoadVoxels(a0,a1)) = 0w211 + ImageInfo.hash a0 + hashint a1
316 :     | hash (Inside(a0,a1)) = 0w223 + ImageInfo.hash a0 + hashint a1
317 :     | hash (ImageDim(a0,a1)) = 0w227 + ImageInfo.hash a0 + hashint a1
318 :     | hash (LoadSeq(a0,a1)) = 0w229 + hashty a0 + hashstring a1
319 :     | hash (LoadImage(a0,a1)) = 0w233 + hashty a0 + hashstring a1
320 : jhr 3506 | hash (Print(a0)) = 0w239 + hashtys a0
321 : jhr 3480
322 :     fun toString IAdd = "IAdd"
323 :     | toString ISub = "ISub"
324 :     | toString IMul = "IMul"
325 :     | toString IDiv = "IDiv"
326 :     | toString IMod = "IMod"
327 :     | toString INeg = "INeg"
328 :     | toString (LT(a0)) = concat["LT<", tyToString a0, ">"]
329 :     | toString (LTE(a0)) = concat["LTE<", tyToString a0, ">"]
330 :     | toString (EQ(a0)) = concat["EQ<", tyToString a0, ">"]
331 :     | toString (NEQ(a0)) = concat["NEQ<", tyToString a0, ">"]
332 :     | toString (GT(a0)) = concat["GT<", tyToString a0, ">"]
333 :     | toString (GTE(a0)) = concat["GTE<", tyToString a0, ">"]
334 :     | toString Not = "Not"
335 : jhr 3483 | toString (Abs(a0)) = concat["Abs<", tyToString a0, ">"]
336 :     | toString (Max(a0)) = concat["Max<", tyToString a0, ">"]
337 :     | toString (Min(a0)) = concat["Min<", tyToString a0, ">"]
338 : jhr 3480 | toString (Clamp(a0)) = concat["Clamp<", tyToString a0, ">"]
339 :     | toString (Lerp(a0)) = concat["Lerp<", tyToString a0, ">"]
340 :     | toString (Normalize(a0)) = concat["Normalize<", intToString a0, ">"]
341 :     | toString (PrincipleEvec(a0)) = concat["PrincipleEvec<", tyToString a0, ">"]
342 :     | toString EigenVecs2x2 = "EigenVecs2x2"
343 :     | toString EigenVecs3x3 = "EigenVecs3x3"
344 :     | toString EigenVals2x2 = "EigenVals2x2"
345 :     | toString EigenVals3x3 = "EigenVals3x3"
346 :     | toString (Zero(a0)) = concat["Zero<", tyToString a0, ">"]
347 :     | toString (Select(a0,a1)) = concat["Select<", tyToString a0, ",", intToString a1, ">"]
348 :     | toString (Index(a0,a1)) = concat["Index<", tyToString a0, ",", intToString a1, ">"]
349 :     | toString (Subscript(a0)) = concat["Subscript<", tyToString a0, ">"]
350 :     | toString (MkDynamic(a0,a1)) = concat["MkDynamic<", tyToString a0, ",", intToString a1, ">"]
351 :     | toString (Append(a0)) = concat["Append<", tyToString a0, ">"]
352 :     | toString (Prepend(a0)) = concat["Prepend<", tyToString a0, ">"]
353 :     | toString (Concat(a0)) = concat["Concat<", tyToString a0, ">"]
354 :     | toString (Length(a0)) = concat["Length<", tyToString a0, ">"]
355 :     | toString (Ceiling(a0)) = concat["Ceiling<", intToString a0, ">"]
356 :     | toString (Floor(a0)) = concat["Floor<", intToString a0, ">"]
357 :     | toString (Round(a0)) = concat["Round<", intToString a0, ">"]
358 :     | toString (Trunc(a0)) = concat["Trunc<", intToString a0, ">"]
359 :     | toString IntToReal = "IntToReal"
360 :     | toString (RealToInt(a0)) = concat["RealToInt<", intToString a0, ">"]
361 :     | toString (Kernel(a0,a1)) = concat["Kernel<", Kernel.toString a0, ",", intToString a1, ">"]
362 :     | toString (Transform(a0)) = concat["Transform<", ImageInfo.toString a0, ">"]
363 :     | toString (Translate(a0)) = concat["Translate<", ImageInfo.toString a0, ">"]
364 :     | toString (EvalKernel(a0,a1,a2)) = concat["EvalKernel<", intToString a0, ",", Kernel.toString a1, ",", intToString a2, ">"]
365 :     | toString (VoxelAddress(a0,a1)) = concat["VoxelAddress<", ImageInfo.toString a0, ",", intToString a1, ">"]
366 :     | toString (VoxelAddressWithCtl(a0,a1,a2)) = concat["VoxelAddressWithCtl<", ImageInfo.toString a0, ",", intToString a1, ",", idxctlToString a2, ">"]
367 :     | toString (LoadVoxels(a0,a1)) = concat["LoadVoxels<", ImageInfo.toString a0, ",", intToString a1, ">"]
368 :     | toString (Inside(a0,a1)) = concat["Inside<", ImageInfo.toString a0, ",", intToString a1, ">"]
369 :     | toString (ImageDim(a0,a1)) = concat["ImageDim<", ImageInfo.toString a0, ",", intToString a1, ">"]
370 :     | toString (LoadSeq(a0,a1)) = concat["LoadSeq<", tyToString a0, ",", stringToString a1, ">"]
371 :     | toString (LoadImage(a0,a1)) = concat["LoadImage<", tyToString a0, ",", stringToString a1, ">"]
372 :     | toString (Print(a0)) = concat["Print<", tysToString a0, ">"]
373 :    
374 :     end
375 :    
376 :     structure MidIR = SSAFn(
377 :     val ilName = "mid-ir"
378 :     structure Ty = MidTypes
379 :     structure Op = MidOps)
380 :    
381 :     structure MidCensus = CensusFn(MidIR)

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