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

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