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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3506 - (view) (download)

1 : jhr 3487 (* check-high.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 = HighOps
12 :     structure Ty = HighTypes
13 :    
14 :     type rator = Op.rator
15 :     type ty = Ty.ty
16 :    
17 :     (* utility function for synthesizing eigenvector/eigenvalue signature *)
18 :     fun eigenSig dim = let
19 :     val tplTy = Ty.TupleTy[
20 :     Ty.SeqTy(Ty.realTy, SOME dim),
21 :     Ty.SeqTy(Ty.vecTy dim, SOME dim)
22 :     ]
23 :     in
24 :     (tplTy, [Ty.TensorTy[dim, dim]])
25 :     end
26 :    
27 :     (* Return the signature of a HighIL operator. *)
28 :     fun sigOf rator = (case rator
29 :     of Op.IAdd => (Ty.IntTy, [Ty.IntTy, Ty.IntTy])
30 :     | Op.ISub => (Ty.IntTy, [Ty.IntTy, Ty.IntTy])
31 :     | Op.IMul => (Ty.IntTy, [Ty.IntTy, Ty.IntTy])
32 :     | Op.IDiv => (Ty.IntTy, [Ty.IntTy, Ty.IntTy])
33 :     | Op.IMod => (Ty.IntTy, [Ty.IntTy, Ty.IntTy])
34 :     | Op.INeg => (Ty.IntTy, [Ty.IntTy])
35 :     | Op.Abs ty => (ty, [ty])
36 :     | Op.LT ty => (Ty.BoolTy, [ty, ty])
37 :     | Op.LTE ty => (Ty.BoolTy, [ty, ty])
38 :     | Op.EQ ty => (Ty.BoolTy, [ty, ty])
39 :     | Op.NEQ ty => (Ty.BoolTy, [ty, ty])
40 :     | Op.GT ty => (Ty.BoolTy, [ty, ty])
41 :     | Op.GTE ty => (Ty.BoolTy, [ty, ty])
42 :     | Op.Power => (Ty.realTy, [Ty.realTy, Ty.IntTy])
43 :     | Op.Not => (Ty.BoolTy, [Ty.BoolTy])
44 : jhr 3506 | Op.Max ty => (ty, [ty, ty])
45 :     | Op.Min ty => (ty, [ty, ty])
46 : jhr 3487 | Op.Clamp ty => (ty, [ty, ty, ty])
47 :     | Op.Lerp ty => (ty, [ty, ty, Ty.realTy])
48 :     | Op.PrincipleEvec(resTy as Ty.TensorTy[d]) => (resTy, [Ty.TensorTy[d,d]])
49 :     | Op.Eigen2x2 => eigenSig 2
50 :     | Op.Eigen3x3 => eigenSig 3
51 :     | Op.Slice(ty as Ty.TensorTy dd, m) => let
52 :     val (resDims, idxDims) = let
53 :     fun f (d, false, (rds, ids)) = (d::rds, ids)
54 :     | f (_, true, (rds, ids)) = (rds, Ty.IntTy::ids)
55 :     in
56 :     ListPair.foldr f ([], []) (dd, m)
57 :     end
58 :     in
59 :     (Ty.TensorTy resDims, ty::idxDims)
60 :     end
61 :     | Op.TensorSub(ty as Ty.TensorTy dd) =>
62 :     (Ty.realTy, ty :: List.map (fn _ => Ty.IntTy) dd)
63 :     | Op.Select(ty as Ty.TupleTy tys, i) =>
64 :     if (1 <= i) andalso (i <= length tys)
65 :     then (List.nth(tys, i-1), [ty])
66 :     else raise Fail("sigOf: invalid operator " ^ Op.toString rator)
67 :     | Op.SeqSub(ty as Ty.SeqTy(elemTy, _)) => (elemTy, [ty, Ty.IntTy])
68 :     | Op.MkDynamic(ty, n) => (Ty.SeqTy(ty, NONE), [Ty.SeqTy(ty, SOME n)])
69 :     | Op.Prepend ty => (Ty.SeqTy(ty, NONE), [ty, Ty.SeqTy(ty, NONE)])
70 :     | Op.Append ty => (Ty.SeqTy(ty, NONE), [Ty.SeqTy(ty, NONE), ty])
71 :     | Op.Concat ty => (Ty.SeqTy(ty, NONE), [Ty.SeqTy(ty, NONE), Ty.SeqTy(ty, NONE)])
72 :     | Op.Length ty => (Ty.intTy, [Ty.SeqTy(ty, NONE)])
73 :     | Op.IntToReal => (Ty.realTy, [Ty.IntTy])
74 :     | Op.TruncToInt => (Ty.IntTy, [Ty.realTy])
75 :     | Op.RoundToInt => (Ty.IntTy, [Ty.realTy])
76 :     | Op.CeilToInt => (Ty.IntTy, [Ty.realTy])
77 :     | Op.FloorToInt => (Ty.IntTy, [Ty.realTy])
78 :     | Op.Kernel _ => (Ty.KernelTy, [])
79 :     | Op.Inside dim => (Ty.BoolTy, [Ty.vecTy dim, Ty.FieldTy])
80 :     (* ??
81 :     | Op.ProbeWithCtl(domTy, rngTy) => (rngTy, [Ty.FieldTy, domTy])
82 :     *)
83 :     | Op.ImageDim(info, _) => (Ty.IntTy, [Ty.ImageTy info])
84 :     | Op.BorderCtlDefault info =>
85 :     (Ty.ImageTy info, [Ty.ImageTy info, Ty.TensorTy(ImageInfo.voxelShape info)])
86 :     | Op.BorderCtlClamp info => (Ty.ImageTy info, [Ty.ImageTy info])
87 :     | Op.BorderCtlMirror info => (Ty.ImageTy info, [Ty.ImageTy info])
88 :     | Op.BorderCtlWrap info => (Ty.ImageTy info, [Ty.ImageTy info])
89 :     | Op.LoadSeq(ty, _) => (ty, [])
90 :     | Op.LoadImage(ty, _) => (ty, [])
91 :     | Op.Print tys => (Ty.TupleTy[], tys)
92 :     | _ => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
93 :     (* end case *))
94 :    
95 :     fun typeOfCons (Ty.TensorTy dd', (ty1 as Ty.TensorTy dd)::r) =
96 :     if List.all (fn ty => Ty.same(ty1, ty)) r
97 :     then (dd' = (List.length r + 1)::dd)
98 :     else false
99 :     | typeOfCons _ = false
100 :    
101 :     fun typeOfSeq (Ty.SeqTy(ty, NONE), tys) = List.all (fn ty' => Ty.same(ty, ty')) tys
102 :     | typeOfSeq (Ty.SeqTy(ty, SOME n), tys) =
103 :     List.all (fn ty' => Ty.same(ty, ty')) tys andalso (List.length tys = n)
104 :     | typeOfSeq _ = false
105 :    
106 :     end
107 :    
108 :     structure CheckHigh = CheckIRFn (
109 :     structure IR = HighIR
110 :     structure OpTy = CheckOps)
111 :    
112 :     structure HighPP = SSAPPFn (HighIR)

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