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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3781 - (view) (download)

1 : jhr 3630 (* check-low.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 = LowOps
12 :     structure Ty = LowTypes
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 :     (* Return the signature of a LowIR operator. *)
30 :     fun sigOf rator = (case rator
31 :     of Op.IAdd => (Ty.IntTy, [Ty.IntTy, Ty.IntTy])
32 :     | Op.ISub => (Ty.IntTy, [Ty.IntTy, Ty.IntTy])
33 :     | Op.IMul => (Ty.IntTy, [Ty.IntTy, Ty.IntTy])
34 :     | Op.IDiv => (Ty.IntTy, [Ty.IntTy, Ty.IntTy])
35 :     | Op.IMod => (Ty.IntTy, [Ty.IntTy, Ty.IntTy])
36 :     | Op.INeg => (Ty.IntTy, [Ty.IntTy])
37 : jhr 3754 | Op.RAdd => (Ty.realTy, [Ty.realTy, Ty.realTy])
38 : jhr 3630 | Op.RSub => (Ty.realTy, [Ty.realTy, Ty.realTy])
39 :     | Op.RMul => (Ty.realTy, [Ty.realTy, Ty.realTy])
40 :     | Op.RDiv => (Ty.realTy, [Ty.realTy, Ty.realTy])
41 :     | Op.RNeg => (Ty.realTy, [Ty.realTy])
42 : cchiw 3741 | Op.VAdd d => (Ty.vecTy d, [Ty.vecTy d, Ty.vecTy d])
43 :     | Op.VSub d => (Ty.vecTy d, [Ty.vecTy d, Ty.vecTy d])
44 :     | Op.VScale d => (Ty.vecTy d, [Ty.realTy, Ty.vecTy d])
45 :     | Op.VMul d => (Ty.vecTy d, [Ty.vecTy d, Ty.vecTy d])
46 :     | Op.VNeg d => (Ty.vecTy d, [Ty.vecTy d])
47 : jhr 3754 | Op.VSum d => (Ty.realTy, [Ty.vecTy d])
48 : cchiw 3741 | Op.VProj(d, i) => (Ty.realTy, [Ty.vecTy d])
49 : jhr 3754 | Op.TensorIndex(ty, _) => (Ty.realTy, [ty])
50 :     | Op.ProjectLast(ty as Ty.TensorTy dd, _) => (Ty.TensorTy[List.last dd], [ty])
51 : jhr 3630 | Op.LT ty => (Ty.BoolTy, [ty, ty])
52 :     | Op.LTE ty => (Ty.BoolTy, [ty, ty])
53 :     | Op.EQ ty => (Ty.BoolTy, [ty, ty])
54 :     | Op.NEQ ty => (Ty.BoolTy, [ty, ty])
55 :     | Op.GT ty => (Ty.BoolTy, [ty, ty])
56 :     | Op.GTE ty => (Ty.BoolTy, [ty, ty])
57 :     | Op.Not => (Ty.BoolTy, [Ty.BoolTy])
58 :     | Op.Abs ty => (ty, [ty])
59 :     | Op.Max ty => (ty, [ty, ty])
60 :     | Op.Min ty => (ty, [ty, ty])
61 :     | Op.Clamp ty => (ty, [ty, ty, ty])
62 :     | Op.Lerp ty => (ty, [ty, ty, Ty.realTy])
63 :     | Op.EigenVecs2x2 => eigenSig 2
64 :     | Op.EigenVecs3x3 => eigenSig 3
65 :     | Op.EigenVals2x2 => (Ty.SeqTy(Ty.realTy, SOME 2), [Ty.TensorTy[2,2]])
66 :     | Op.EigenVals3x3 => (Ty.SeqTy(Ty.realTy, SOME 3), [Ty.TensorTy[3,3]])
67 :     | Op.Zero ty => (ty, [])
68 :     | Op.Select(ty as Ty.TupleTy tys, i) => (List.nth(tys, i-1), [ty])
69 : jhr 3754 (* FIXME: It appears that Index(ty,i) == TensorIndex(ty, [i])!!! *)
70 : jhr 3630 | Op.Index(ty as Ty.TensorTy[d], _) => (Ty.realTy, [ty])
71 :     | Op.Subscript(ty as Ty.SeqTy(elemTy, _)) => (elemTy, [ty, Ty.intTy])
72 :     | Op.MkDynamic(ty, n) => (Ty.SeqTy(ty, NONE), [Ty.SeqTy(ty, SOME n)])
73 : jhr 3631 | Op.Append ty => (Ty.SeqTy(ty, NONE), [Ty.SeqTy(ty, NONE), ty])
74 : jhr 3630 | Op.Prepend ty => (Ty.SeqTy(ty, NONE), [ty, Ty.SeqTy(ty, NONE)])
75 :     | Op.Concat ty => (Ty.SeqTy(ty, NONE), [Ty.SeqTy(ty, NONE), Ty.SeqTy(ty, NONE)])
76 : cchiw 3741 | Op.Range => (Ty.SeqTy(Ty.intTy, NONE), [Ty.IntTy, Ty.IntTy])
77 : jhr 3630 | Op.Length ty => (Ty.intTy, [Ty.SeqTy(ty, NONE)])
78 : cchiw 3741 | Op.SphereQuery(ptTy, strandTy) => (Ty.SeqTy(strandTy, NONE), [ptTy, Ty.realTy])
79 : jhr 3630 | Op.Ceiling d => (Ty.vecTy d, [Ty.vecTy d])
80 :     | Op.Floor d => (Ty.vecTy d, [Ty.vecTy d])
81 :     | Op.Round d => (Ty.vecTy d, [Ty.vecTy d])
82 :     | Op.Trunc d => (Ty.vecTy d, [Ty.vecTy d])
83 :     | Op.IntToReal => (Ty.realTy, [Ty.intTy])
84 :     | Op.RealToInt 1 => (Ty.IntTy, [Ty.realTy])
85 :     | Op.RealToInt d => (Ty.SeqTy(Ty.IntTy, SOME d), [Ty.TensorTy[d]])
86 :     (* FIXME: the type of RealToInt should be
87 :     | Op.RealToInt d => (Ty.SeqTy(Ty.IntTy, d), [Ty.SeqTy(Ty.realTy, d)])
88 :     *)
89 :     (* not sure if we will need these
90 :     | R_All of ty
91 :     | R_Exists of ty
92 :     | R_Max of ty
93 :     | R_Min of ty
94 :     | R_Sum of ty
95 :     | R_Product of ty
96 :     | R_Mean of ty
97 :     | R_Variance of ty
98 :     *)
99 : cchiw 3741 | Op.Transform info => let
100 :     val dim = ImageInfo.dim info
101 :     in
102 :     if (dim = 1)
103 :     then (Ty.TensorTy[], [Ty.ImageTy info])
104 :     else (Ty.TensorTy[dim, dim], [Ty.ImageTy info])
105 :     end
106 :     | Op.Translate info => let
107 :     val dim = ImageInfo.dim info
108 :     in
109 :     if (dim = 1)
110 :     then (Ty.TensorTy[], [Ty.ImageTy info])
111 :     else (Ty.TensorTy[dim], [Ty.ImageTy info])
112 :     end
113 : jhr 3762 | Op.ControlIndex(info, _, _) => (Ty.intTy, [Ty.ImageTy info, Ty.IntTy])
114 : jhr 3781 | Op.VoxelAddress info => (Ty.AddrTy info, [Ty.ImageTy info, Ty.IntTy])
115 :     | Op.LoadVoxels(info, d) => (Ty.vecTy d, [Ty.AddrTy info])
116 : jhr 3630 | Op.Inside(info, _) => (Ty.BoolTy, [Ty.vecTy(ImageInfo.dim info), Ty.ImageTy info])
117 :     | Op.ImageDim(info, _) => (Ty.IntTy, [Ty.ImageTy info])
118 :     | Op.LoadSeq(ty, _) => (ty, [])
119 :     | Op.LoadImage(ty, _) => (ty, [])
120 :     | Op.Print tys => (Ty.TupleTy[], tys)
121 : jhr 3757 | Op.MathFn f => MathFns.sigOf (Ty.realTy, f)
122 : jhr 3630 | _ => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
123 :     (* end case *))
124 :    
125 :     fun typeOfCons (Ty.TensorTy dd', (ty1 as Ty.TensorTy dd)::r) =
126 :     if List.all (fn ty => Ty.same(ty1, ty)) r
127 :     then (dd' = (List.length r + 1)::dd)
128 :     else false
129 :     | typeOfCons _ = false
130 :    
131 :     fun typeOfSeq (Ty.SeqTy(ty, NONE), tys) = List.all (fn ty' => Ty.same(ty, ty')) tys
132 :     | typeOfSeq (Ty.SeqTy(ty, SOME n), tys) =
133 :     List.all (fn ty' => Ty.same(ty, ty')) tys andalso (List.length tys = n)
134 :     | typeOfSeq _ = false
135 :    
136 :     end
137 :    
138 :     structure CheckLow = CheckIRFn (
139 :     structure IR = LowIR
140 :     structure OpTy = CheckOps)
141 :    
142 :     structure LowPP = SSAPPFn (LowIR)

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