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 3870 - (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 : jhr 3830 | Op.RClamp => (Ty.realTy, [Ty.realTy, Ty.realTy, Ty.realTy])
43 :     | Op.RLerp => (Ty.realTy, [Ty.realTy, Ty.realTy, Ty.realTy])
44 : cchiw 3741 | Op.VAdd d => (Ty.vecTy d, [Ty.vecTy d, Ty.vecTy d])
45 :     | Op.VSub d => (Ty.vecTy d, [Ty.vecTy d, Ty.vecTy d])
46 :     | Op.VScale d => (Ty.vecTy d, [Ty.realTy, Ty.vecTy d])
47 :     | Op.VMul d => (Ty.vecTy d, [Ty.vecTy d, Ty.vecTy d])
48 :     | Op.VNeg d => (Ty.vecTy d, [Ty.vecTy d])
49 : jhr 3754 | Op.VSum d => (Ty.realTy, [Ty.vecTy d])
50 : jhr 3832 | Op.VIndex(d, i) => (Ty.realTy, [Ty.vecTy d])
51 : jhr 3830 | Op.VClamp d => (Ty.vecTy d, [Ty.vecTy d, Ty.realTy, Ty.realTy])
52 :     | Op.VMapClamp d => (Ty.vecTy d, [Ty.vecTy d, Ty.vecTy d, Ty.vecTy d])
53 :     | Op.VLerp d => (Ty.vecTy d, [Ty.vecTy d, Ty.vecTy d, Ty.realTy])
54 : jhr 3754 | Op.TensorIndex(ty, _) => (Ty.realTy, [ty])
55 :     | Op.ProjectLast(ty as Ty.TensorTy dd, _) => (Ty.TensorTy[List.last dd], [ty])
56 : jhr 3630 | 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 :     | Op.EigenVecs2x2 => eigenSig 2
67 :     | Op.EigenVecs3x3 => eigenSig 3
68 :     | Op.EigenVals2x2 => (Ty.SeqTy(Ty.realTy, SOME 2), [Ty.TensorTy[2,2]])
69 :     | Op.EigenVals3x3 => (Ty.SeqTy(Ty.realTy, SOME 3), [Ty.TensorTy[3,3]])
70 :     | Op.Zero ty => (ty, [])
71 :     | 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 : jhr 3631 | Op.Append ty => (Ty.SeqTy(ty, NONE), [Ty.SeqTy(ty, NONE), ty])
75 : jhr 3630 | Op.Prepend ty => (Ty.SeqTy(ty, NONE), [ty, Ty.SeqTy(ty, NONE)])
76 :     | Op.Concat ty => (Ty.SeqTy(ty, NONE), [Ty.SeqTy(ty, NONE), Ty.SeqTy(ty, NONE)])
77 : cchiw 3741 | Op.Range => (Ty.SeqTy(Ty.intTy, NONE), [Ty.IntTy, Ty.IntTy])
78 : jhr 3630 | Op.Length ty => (Ty.intTy, [Ty.SeqTy(ty, NONE)])
79 : cchiw 3741 | Op.SphereQuery(ptTy, strandTy) => (Ty.SeqTy(strandTy, NONE), [ptTy, Ty.realTy])
80 : jhr 3805 | Op.Sqrt => (Ty.realTy, [Ty.realTy])
81 :     | Op.Cos => (Ty.realTy, [Ty.realTy])
82 :     | Op.ArcCos => (Ty.realTy, [Ty.realTy])
83 :     | Op.Sin => (Ty.realTy, [Ty.realTy])
84 :     | Op.ArcSin => (Ty.realTy, [Ty.realTy])
85 :     | Op.Tan => (Ty.realTy, [Ty.realTy])
86 :     | Op.ArcTan => (Ty.realTy, [Ty.realTy])
87 : jhr 3630 | 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 : cchiw 3741 | Op.Transform info => let
105 : jhr 3870 val dim = ImageInfo.dim info
106 :     in
107 :     if (dim = 1)
108 :     then (Ty.TensorTy[], [Ty.ImageTy info])
109 :     else (Ty.TensorTy[dim, dim], [Ty.ImageTy info])
110 :     end
111 : cchiw 3741 | Op.Translate info => let
112 : jhr 3870 val dim = ImageInfo.dim info
113 :     in
114 :     if (dim = 1)
115 :     then (Ty.TensorTy[], [Ty.ImageTy info])
116 :     else (Ty.TensorTy[dim], [Ty.ImageTy info])
117 :     end
118 : jhr 3762 | Op.ControlIndex(info, _, _) => (Ty.intTy, [Ty.ImageTy info, Ty.IntTy])
119 : jhr 3851 | Op.LoadVoxel info => (Ty.realTy, [Ty.ImageTy info, Ty.IntTy])
120 : jhr 3786 | Op.Inside(info, _) => let
121 :     val idxTy = (case ImageInfo.dim info
122 :     of 1 => Ty.IntTy
123 :     | d => Ty.SeqTy(Ty.IntTy, SOME d)
124 :     (* end case *))
125 :     in
126 :     (Ty.BoolTy, [idxTy, Ty.ImageTy info])
127 :     end
128 : jhr 3630 | Op.ImageDim(info, _) => (Ty.IntTy, [Ty.ImageTy info])
129 :     | Op.LoadSeq(ty, _) => (ty, [])
130 :     | Op.LoadImage(ty, _) => (ty, [])
131 :     | Op.Print tys => (Ty.TupleTy[], tys)
132 : jhr 3757 | Op.MathFn f => MathFns.sigOf (Ty.realTy, f)
133 : jhr 3630 | _ => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
134 :     (* end case *))
135 :    
136 :     fun typeOfCons (Ty.TensorTy dd', (ty1 as Ty.TensorTy dd)::r) =
137 :     if List.all (fn ty => Ty.same(ty1, ty)) r
138 :     then (dd' = (List.length r + 1)::dd)
139 :     else false
140 :     | typeOfCons _ = false
141 :    
142 :     fun typeOfSeq (Ty.SeqTy(ty, NONE), tys) = List.all (fn ty' => Ty.same(ty, ty')) tys
143 :     | typeOfSeq (Ty.SeqTy(ty, SOME n), tys) =
144 :     List.all (fn ty' => Ty.same(ty, ty')) tys andalso (List.length tys = n)
145 :     | typeOfSeq _ = false
146 :    
147 :     end
148 :    
149 :     structure CheckLow = CheckIRFn (
150 :     structure IR = LowIR
151 :     structure OpTy = CheckOps)
152 :    
153 :     structure LowPP = SSAPPFn (LowIR)

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