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 3741 - (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 : cchiw 3741 | 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.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 : jhr 3630 | 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 : jhr 3631 | Op.Append ty => (Ty.SeqTy(ty, NONE), [Ty.SeqTy(ty, NONE), ty])
71 : jhr 3630 | Op.Prepend ty => (Ty.SeqTy(ty, NONE), [ty, Ty.SeqTy(ty, NONE)])
72 :     | Op.Concat ty => (Ty.SeqTy(ty, NONE), [Ty.SeqTy(ty, NONE), Ty.SeqTy(ty, NONE)])
73 : cchiw 3741 | Op.Range => (Ty.SeqTy(Ty.intTy, NONE), [Ty.IntTy, Ty.IntTy])
74 : jhr 3630 | Op.Length ty => (Ty.intTy, [Ty.SeqTy(ty, NONE)])
75 : cchiw 3741 | Op.SphereQuery(ptTy, strandTy) => (Ty.SeqTy(strandTy, NONE), [ptTy, Ty.realTy])
76 : jhr 3630 | 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 : cchiw 3741 | Op.Transform info => let
97 :     val dim = ImageInfo.dim info
98 :     in
99 :     if (dim = 1)
100 :     then (Ty.TensorTy[], [Ty.ImageTy info])
101 :     else (Ty.TensorTy[dim, dim], [Ty.ImageTy info])
102 :     end
103 :     | Op.Translate info => let
104 :     val dim = ImageInfo.dim info
105 :     in
106 :     if (dim = 1)
107 :     then (Ty.TensorTy[], [Ty.ImageTy info])
108 :     else (Ty.TensorTy[dim], [Ty.ImageTy info])
109 :     end
110 : jhr 3630 | Op.LoadVoxels(info, n) => (Ty.vecTy n, [Ty.AddrTy info])
111 :     | Op.Inside(info, _) => (Ty.BoolTy, [Ty.vecTy(ImageInfo.dim info), Ty.ImageTy info])
112 :     | Op.ImageDim(info, _) => (Ty.IntTy, [Ty.ImageTy info])
113 : cchiw 3741 | Op.imgLoad (info ,i,j)=>(Ty.TensorTy([j]), [Ty.AddrTy info])
114 :     | Op.baseAddr info =>(Ty.AddrTy info,[Ty.ImageTy info])
115 : jhr 3630 | Op.LoadSeq(ty, _) => (ty, [])
116 :     | Op.LoadImage(ty, _) => (ty, [])
117 :     | Op.Print tys => (Ty.TupleTy[], tys)
118 :     | _ => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
119 :     (* end case *))
120 :    
121 :     fun typeOfCons (Ty.TensorTy dd', (ty1 as Ty.TensorTy dd)::r) =
122 :     if List.all (fn ty => Ty.same(ty1, ty)) r
123 :     then (dd' = (List.length r + 1)::dd)
124 :     else false
125 :     | typeOfCons _ = false
126 :    
127 :     fun typeOfSeq (Ty.SeqTy(ty, NONE), tys) = List.all (fn ty' => Ty.same(ty, ty')) tys
128 :     | typeOfSeq (Ty.SeqTy(ty, SOME n), tys) =
129 :     List.all (fn ty' => Ty.same(ty, ty')) tys andalso (List.length tys = n)
130 :     | typeOfSeq _ = false
131 :    
132 :     end
133 :    
134 :     structure CheckLow = CheckIRFn (
135 :     structure IR = LowIR
136 :     structure OpTy = CheckOps)
137 :    
138 :     structure LowPP = SSAPPFn (LowIR)

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