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 3630 - (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 :     | Op.RAdd => (Ty.realTy, [Ty.realTy, Ty.realTy])
38 :     | 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 :     | 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 d, Ty.vecTy d])
45 :     | Op.VMul d => (Ty.vecTy d, [Ty.vecTy d, Ty.vecTy d])
46 :     | Op.VSum d => (Ty.realTy, [Ty.vecTy d, Ty.vecTy d])
47 :     | Op.VNeg d => (Ty.vecTy d, [Ty.vecTy d])
48 :     | Op.VProj(d, i) => (Ty.realTy, [Ty.vecTy d])
49 :     | Op.LT ty => (Ty.BoolTy, [ty, ty])
50 :     | Op.LTE ty => (Ty.BoolTy, [ty, ty])
51 :     | Op.EQ ty => (Ty.BoolTy, [ty, ty])
52 :     | Op.NEQ ty => (Ty.BoolTy, [ty, ty])
53 :     | Op.GT ty => (Ty.BoolTy, [ty, ty])
54 :     | Op.GTE ty => (Ty.BoolTy, [ty, ty])
55 :     | Op.Not => (Ty.BoolTy, [Ty.BoolTy])
56 :     | Op.Abs ty => (ty, [ty])
57 :     | Op.Max ty => (ty, [ty, ty])
58 :     | Op.Min ty => (ty, [ty, ty])
59 :     | Op.Clamp ty => (ty, [ty, ty, ty])
60 :     | Op.Lerp ty => (ty, [ty, ty, Ty.realTy])
61 :     | Op.EigenVecs2x2 => eigenSig 2
62 :     | Op.EigenVecs3x3 => eigenSig 3
63 :     | Op.EigenVals2x2 => (Ty.SeqTy(Ty.realTy, SOME 2), [Ty.TensorTy[2,2]])
64 :     | Op.EigenVals3x3 => (Ty.SeqTy(Ty.realTy, SOME 3), [Ty.TensorTy[3,3]])
65 :     | Op.Zero ty => (ty, [])
66 :     | Op.Select(ty as Ty.TupleTy tys, i) => (List.nth(tys, i-1), [ty])
67 :     | Op.Index(ty as Ty.TensorTy[d], _) => (Ty.realTy, [ty])
68 :     | Op.Subscript(ty as Ty.SeqTy(elemTy, _)) => (elemTy, [ty, Ty.intTy])
69 :     | Op.MkDynamic(ty, n) => (Ty.SeqTy(ty, NONE), [Ty.SeqTy(ty, SOME n)])
70 :     | Op.Prepend ty => (Ty.SeqTy(ty, NONE), [ty, Ty.SeqTy(ty, NONE)])
71 :     | Op.Append ty => (Ty.SeqTy(ty, NONE), [Ty.SeqTy(ty, NONE), ty])
72 :     | Op.Concat ty => (Ty.SeqTy(ty, NONE), [Ty.SeqTy(ty, NONE), Ty.SeqTy(ty, NONE)])
73 :     | Op.Range => (Ty.SeqTy(Ty.intTy, NONE), [Ty.IntTy, Ty.IntTy])
74 :     | Op.Length ty => (Ty.intTy, [Ty.SeqTy(ty, NONE)])
75 :     | Op.SphereQuery(ptTy, strandTy) => (Ty.SeqTy(strandTy, NONE), [ptTy, Ty.realTy])
76 :     | Op.Ceiling d => (Ty.vecTy d, [Ty.vecTy d])
77 :     | Op.Floor d => (Ty.vecTy d, [Ty.vecTy d])
78 :     | Op.Round d => (Ty.vecTy d, [Ty.vecTy d])
79 :     | Op.Trunc d => (Ty.vecTy d, [Ty.vecTy d])
80 :     | Op.IntToReal => (Ty.realTy, [Ty.intTy])
81 :     | Op.RealToInt 1 => (Ty.IntTy, [Ty.realTy])
82 :     | Op.RealToInt d => (Ty.SeqTy(Ty.IntTy, SOME d), [Ty.TensorTy[d]])
83 :     (* FIXME: the type of RealToInt should be
84 :     | Op.RealToInt d => (Ty.SeqTy(Ty.IntTy, d), [Ty.SeqTy(Ty.realTy, d)])
85 :     *)
86 :     (* not sure if we will need these
87 :     | R_All of ty
88 :     | R_Exists of ty
89 :     | R_Max of ty
90 :     | R_Min of ty
91 :     | R_Sum of ty
92 :     | R_Product of ty
93 :     | R_Mean of ty
94 :     | R_Variance of ty
95 :     *)
96 :     | Op.Kernel _ => (Ty.KernelTy, [])
97 :     | Op.Transform info => let
98 :     val dim = ImageInfo.dim info
99 :     in
100 :     if (dim = 1)
101 :     then (Ty.TensorTy[], [Ty.ImageTy info])
102 :     else (Ty.TensorTy[dim, dim], [Ty.ImageTy info])
103 :     end
104 :     | Op.Translate info => let
105 :     val dim = ImageInfo.dim info
106 :     in
107 :     if (dim = 1)
108 :     then (Ty.TensorTy[], [Ty.ImageTy info])
109 :     else (Ty.TensorTy[dim], [Ty.ImageTy info])
110 :     end
111 :     | Op.EvalKernel(d, _, _) => (Ty.vecTy d, [Ty.vecTy d])
112 :     | Op.VoxelAddress(info, offset) => let
113 :     val dim = ImageInfo.dim info
114 :     in
115 :     (Ty.AddrTy info, Ty.ImageTy info :: List.tabulate(dim, fn _ => Ty.intTy))
116 :     end
117 :     | Op.VoxelAddressWithCtl(info, offset, ctl) => let
118 :     val dim = ImageInfo.dim info
119 :     in
120 :     (Ty.AddrTy info, Ty.ImageTy info :: List.tabulate(dim, fn _ => Ty.intTy))
121 :     end
122 :     | Op.LoadVoxels(info, n) => (Ty.vecTy n, [Ty.AddrTy info])
123 :     | Op.Inside(info, _) => (Ty.BoolTy, [Ty.vecTy(ImageInfo.dim info), Ty.ImageTy info])
124 :     | Op.ImageDim(info, _) => (Ty.IntTy, [Ty.ImageTy info])
125 :     | Op.LoadSeq(ty, _) => (ty, [])
126 :     | Op.LoadImage(ty, _) => (ty, [])
127 :     | Op.Print tys => (Ty.TupleTy[], tys)
128 :     | _ => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
129 :     (* end case *))
130 :    
131 :     fun typeOfCons (Ty.TensorTy dd', (ty1 as Ty.TensorTy dd)::r) =
132 :     if List.all (fn ty => Ty.same(ty1, ty)) r
133 :     then (dd' = (List.length r + 1)::dd)
134 :     else false
135 :     | typeOfCons _ = false
136 :    
137 :     fun typeOfSeq (Ty.SeqTy(ty, NONE), tys) = List.all (fn ty' => Ty.same(ty, ty')) tys
138 :     | typeOfSeq (Ty.SeqTy(ty, SOME n), tys) =
139 :     List.all (fn ty' => Ty.same(ty, ty')) tys andalso (List.length tys = n)
140 :     | typeOfSeq _ = false
141 :    
142 :     end
143 :    
144 :     structure CheckLow = CheckIRFn (
145 :     structure IR = LowIR
146 :     structure OpTy = CheckOps)
147 :    
148 :     structure LowPP = SSAPPFn (LowIR)

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