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/check-mid.sml
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4185 - (view) (download)

1 : jhr 3539 (* check-mid.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 :    
9 :     structure CheckOps : OPERATOR_TY = struct
10 :    
11 :     structure Op = MidOps
12 :     structure Ty = MidTypes
13 :    
14 :     type rator = Op.rator
15 :     type ty = Ty.ty
16 :    
17 :     val vec3Ty = Ty.vecTy 3
18 :    
19 :     (* utility function for synthesizing eigenvector/eigenvalue signature *)
20 :     fun eigenSig dim = let
21 :     val tplTy = Ty.TupleTy[
22 :     Ty.SeqTy(Ty.realTy, SOME dim),
23 :     Ty.SeqTy(Ty.vecTy dim, SOME dim)
24 :     ]
25 :     in
26 :     (tplTy, [Ty.TensorTy[dim, dim]])
27 :     end
28 :    
29 : jhr 4075 (* the type of the indices for an image; note that 1D images are indexed by 1-element
30 :     * sequences.
31 :     *)
32 : jhr 4112 fun indexType info = (case ImageInfo.dim info
33 :     of 1 => Ty.IntTy
34 :     | d => Ty.SeqTy(Ty.IntTy, SOME d)
35 :     (* end case *))
36 : jhr 3786
37 : jhr 3774 (* utility function for determining the type of LoadVoxels and LoadVoxelsWithCtl *)
38 :     fun loadVoxelsSig (info, support) = let
39 :     val shp = ImageInfo.voxelShape info
40 :     val dim = ImageInfo.dim info
41 :     val resTy = Ty.TensorTy(shp @ List.tabulate(dim, fn _ => support))
42 :     in
43 : jhr 3786 (resTy, [Ty.ImageTy info, indexType info])
44 : jhr 3774 end
45 :    
46 : jhr 4051 fun chkIndex (idx, bnd) = ((0 <= idx) andalso (idx < bnd))
47 :    
48 : jhr 3539 (* Return the signature of a MidIR operator. *)
49 :     fun sigOf rator = (case rator
50 :     of Op.IAdd => (Ty.IntTy, [Ty.IntTy, Ty.IntTy])
51 :     | Op.ISub => (Ty.IntTy, [Ty.IntTy, Ty.IntTy])
52 :     | Op.IMul => (Ty.IntTy, [Ty.IntTy, Ty.IntTy])
53 :     | Op.IDiv => (Ty.IntTy, [Ty.IntTy, Ty.IntTy])
54 :     | Op.IMod => (Ty.IntTy, [Ty.IntTy, Ty.IntTy])
55 :     | Op.INeg => (Ty.IntTy, [Ty.IntTy])
56 :     | Op.LT ty => (Ty.BoolTy, [ty, ty])
57 :     | Op.LTE ty => (Ty.BoolTy, [ty, ty])
58 :     | Op.EQ ty => (Ty.BoolTy, [ty, ty])
59 :     | Op.NEQ ty => (Ty.BoolTy, [ty, ty])
60 :     | Op.GT ty => (Ty.BoolTy, [ty, ty])
61 :     | Op.GTE ty => (Ty.BoolTy, [ty, ty])
62 :     | Op.Not => (Ty.BoolTy, [Ty.BoolTy])
63 :     | Op.Abs ty => (ty, [ty])
64 :     | Op.Max ty => (ty, [ty, ty])
65 :     | Op.Min ty => (ty, [ty, ty])
66 : jhr 3830 | Op.Clamp ty => (ty, [ty, Ty.realTy, Ty.realTy])
67 :     | Op.MapClamp ty => (ty, [ty, ty, ty])
68 : jhr 3539 | Op.Lerp ty => (ty, [ty, ty, Ty.realTy])
69 :     | Op.EigenVecs2x2 => eigenSig 2
70 :     | Op.EigenVecs3x3 => eigenSig 3
71 :     | Op.EigenVals2x2 => (Ty.SeqTy(Ty.realTy, SOME 2), [Ty.TensorTy[2,2]])
72 :     | Op.EigenVals3x3 => (Ty.SeqTy(Ty.realTy, SOME 3), [Ty.TensorTy[3,3]])
73 :     | Op.Zero ty => (ty, [])
74 : jhr 4051 | Op.TensorIndex(ty as Ty.TensorTy shp, idxs) =>
75 :     if ListPair.allEq chkIndex (idxs, shp)
76 :     then (Ty.realTy, [ty])
77 :     else raise Fail("sigOf: invalid index in operator " ^ Op.toString rator)
78 : jhr 3539 | Op.Select(ty as Ty.TupleTy tys, i) => (List.nth(tys, i-1), [ty])
79 :     | Op.Subscript(ty as Ty.SeqTy(elemTy, _)) => (elemTy, [ty, Ty.intTy])
80 :     | Op.MkDynamic(ty, n) => (Ty.SeqTy(ty, NONE), [Ty.SeqTy(ty, SOME n)])
81 :     | Op.Prepend ty => (Ty.SeqTy(ty, NONE), [ty, Ty.SeqTy(ty, NONE)])
82 :     | Op.Append ty => (Ty.SeqTy(ty, NONE), [Ty.SeqTy(ty, NONE), ty])
83 :     | Op.Concat ty => (Ty.SeqTy(ty, NONE), [Ty.SeqTy(ty, NONE), Ty.SeqTy(ty, NONE)])
84 :     | Op.Range => (Ty.SeqTy(Ty.intTy, NONE), [Ty.IntTy, Ty.IntTy])
85 :     | Op.Length ty => (Ty.intTy, [Ty.SeqTy(ty, NONE)])
86 :     | Op.SphereQuery(ptTy, strandTy) => (Ty.SeqTy(strandTy, NONE), [ptTy, Ty.realTy])
87 :     | Op.Ceiling d => (Ty.vecTy d, [Ty.vecTy d])
88 :     | Op.Floor d => (Ty.vecTy d, [Ty.vecTy d])
89 :     | Op.Round d => (Ty.vecTy d, [Ty.vecTy d])
90 :     | Op.Trunc d => (Ty.vecTy d, [Ty.vecTy d])
91 :     | Op.IntToReal => (Ty.realTy, [Ty.intTy])
92 :     | Op.RealToInt 1 => (Ty.IntTy, [Ty.realTy])
93 :     | Op.RealToInt d => (Ty.SeqTy(Ty.IntTy, SOME d), [Ty.TensorTy[d]])
94 :     (* not sure if we will need these
95 :     | R_All of ty
96 :     | R_Exists of ty
97 :     | R_Max of ty
98 :     | R_Min of ty
99 :     | R_Sum of ty
100 :     | R_Product of ty
101 :     | R_Mean of ty
102 :     | R_Variance of ty
103 :     *)
104 : jhr 3732 | Op.BuildPos s => (Ty.TensorTy[2*s], [Ty.realTy])
105 :     | Op.EvalKernel(d, _, _) => (Ty.TensorTy[d], [Ty.TensorTy[d]])
106 : jhr 3539 | Op.Kernel _ => (Ty.KernelTy, [])
107 :     | Op.Transform info => let
108 :     val dim = ImageInfo.dim info
109 :     in
110 :     if (dim = 1)
111 :     then (Ty.TensorTy[], [Ty.ImageTy info])
112 :     else (Ty.TensorTy[dim, dim], [Ty.ImageTy info])
113 :     end
114 :     | Op.Translate info => let
115 :     val dim = ImageInfo.dim info
116 :     in
117 :     if (dim = 1)
118 :     then (Ty.TensorTy[], [Ty.ImageTy info])
119 :     else (Ty.TensorTy[dim], [Ty.ImageTy info])
120 :     end
121 : jhr 3774 | Op.LoadVoxels(info, s) => loadVoxelsSig (info, s)
122 :     | Op.LoadVoxelsWithCtl(info, s, _) => loadVoxelsSig (info, s)
123 : jhr 4151 | Op.Inside(info, _) => (Ty.BoolTy, [Ty.vecTy(ImageInfo.dim info), Ty.ImageTy info])
124 : jhr 4185 | Op.IndexInside(info, _) => (Ty.BoolTy, [indexType info, Ty.ImageTy info])
125 : jhr 3539 | Op.ImageDim(info, _) => (Ty.IntTy, [Ty.ImageTy info])
126 : jhr 3725 | Op.BorderCtlDefault info =>
127 :     (Ty.ImageTy info, [Ty.ImageTy info, Ty.TensorTy(ImageInfo.voxelShape info)])
128 :     | Op.BorderCtlClamp info => (Ty.ImageTy info, [Ty.ImageTy info])
129 :     | Op.BorderCtlMirror info => (Ty.ImageTy info, [Ty.ImageTy info])
130 :     | Op.BorderCtlWrap info => (Ty.ImageTy info, [Ty.ImageTy info])
131 : jhr 3539 | Op.LoadSeq(ty, _) => (ty, [])
132 :     | Op.LoadImage(ty, _) => (ty, [])
133 :     | Op.Print tys => (Ty.TupleTy[], tys)
134 : jhr 3757 | Op.MathFn f => MathFns.sigOf (Ty.realTy, f)
135 : jhr 3539 | _ => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
136 :     (* end case *))
137 :    
138 :     fun typeOfCons (Ty.TensorTy dd', (ty1 as Ty.TensorTy dd)::r) =
139 :     if List.all (fn ty => Ty.same(ty1, ty)) r
140 :     then (dd' = (List.length r + 1)::dd)
141 :     else false
142 :     | typeOfCons _ = false
143 :    
144 :     fun typeOfSeq (Ty.SeqTy(ty, NONE), tys) = List.all (fn ty' => Ty.same(ty, ty')) tys
145 :     | typeOfSeq (Ty.SeqTy(ty, SOME n), tys) =
146 :     List.all (fn ty' => Ty.same(ty, ty')) tys andalso (List.length tys = n)
147 :     | typeOfSeq _ = false
148 :    
149 : jhr 3937 fun isStrandTy (Ty.StrandTy _) = true
150 :     | isStrandTy _ = false
151 :    
152 :     fun isBoolTy Ty.BoolTy = true
153 :     | isBoolTy _ = false
154 :    
155 : jhr 3539 end
156 :    
157 :     structure CheckMid = CheckIRFn (
158 :     structure IR = MidIR
159 :     structure OpTy = CheckOps)
160 :    
161 :     structure MidPP = SSAPPFn (MidIR)

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