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

SCM Repository

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

Annotation of /branches/vis15/src/compiler/tree-ir/tree-types.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3941 - (view) (download)

1 : jhr 3750 (* tree-types.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 :     * Types for the TreeIR. For now, these are identical to the LowIR types.
9 :     *)
10 :    
11 : jhr 3754 structure TreeTypes =
12 :     struct
13 :    
14 : jhr 3832 (* the layout of a vector onto target-supported vectors. *)
15 :     type vec_layout = {
16 :     wid : int, (* total width of the vector *)
17 :     padded : bool, (* true if sum of pieces > wid; pad will be in last piece *)
18 :     pieces : int list (* list of pieces; these will all be supported vector widths *)
19 :     }
20 :    
21 : jhr 3810 datatype t
22 : jhr 3835 = BoolTy | StringTy | IntTy
23 :     | VecTy of int * int (* a vector value that fits into a target-supported
24 :     * vector. The first int is the width of the vector
25 :     * and the second is the target width, which will be
26 :     * >= the vector width.
27 : jhr 3766 *)
28 : jhr 3941 (* QUESTION: should we have a TensorRefTy that is represented as "float *" (instead
29 :     * of as "float[n]"), or should we just drop the length when converting TensorTy to
30 :     * a C++ type?
31 :     *)
32 : jhr 3828 | TensorTy of int list (* in-memory tensor type. For 0th order and 1st
33 :     * order tensors, the local-variable types will
34 :     * be RealTy and VecTy (resp.).
35 :     *)
36 : jhr 3810 | TupleTy of t list (* tuples; used for multiple return values *)
37 :     | SeqTy of t * int option
38 : jhr 3754 | ImageTy of ImageInfo.info
39 : jhr 3846 | StrandTy of Atom.atom
40 : jhr 3754
41 :     val intTy = IntTy
42 : jhr 3835
43 :     val realTy = VecTy(1, 1)
44 :    
45 : jhr 3754 fun iVecTy 1 = IntTy
46 :     | iVecTy n = SeqTy(IntTy, SOME n)
47 :    
48 : jhr 3861 fun layoutToString {wid, padded, pieces} = "<layout>"
49 :    
50 : jhr 3835 (* return the vector types that comprise the pieces of a vec_layout *)
51 : jhr 3861 fun piecesOf (layout : vec_layout) = let
52 :     fun toVecs (_, []) = raise Fail(concat["piecesOf(", layoutToString layout, ")"])
53 : jhr 3835 | toVecs (wid, [w]) = [VecTy(wid, w)]
54 :     | toVecs (wid, w::ws) = VecTy(w, w) :: toVecs(wid-w, ws)
55 :     in
56 : jhr 3861 toVecs (#wid layout, #pieces layout)
57 : jhr 3835 end
58 : jhr 3754
59 : jhr 3919 (* return the unpadded width of the n'th component of a vector layout *)
60 :     fun nthWidth (layout : vec_layout, n) = let
61 :     fun get (_, _, []) =
62 :     raise Fail(concat["nthWidth(", layoutToString layout, ", ", Int.toString n, ")"])
63 :     | get (0, wid, _) = wid
64 :     | get (n, wid, w::ws) = get (n-1, wid-w, ws)
65 :     in
66 :     get (n, #wid layout, #pieces layout)
67 :     end
68 :    
69 : jhr 3861 (* return the n'th component of a vector layout as a vector type. *)
70 :     fun nthVec (layout : vec_layout, n) = let
71 :     fun get (_, _, []) =
72 :     raise Fail(concat["nthVec(", layoutToString layout, ", ", Int.toString n, ")"])
73 :     | get (0, wid, w::_) = VecTy(wid, w)
74 :     | get (n, wid, w::ws) = get (n-1, wid-w, ws)
75 :     in
76 :     get (n, #wid layout, #pieces layout)
77 :     end
78 :    
79 : jhr 3894 (* return the offset of the first component in the i'th piece of a vec_layout *)
80 :     fun offsetOf (layout : vec_layout, i) = let
81 :     fun add (0, _, off) = off
82 :     | add (i, pw::pws, off) = add (i-1, pws, off+pw)
83 :     in
84 :     add (i, #pieces layout, 0)
85 :     end
86 :    
87 : jhr 3835 (* is a vector padded? *)
88 :     fun isPaddedVec (VecTy(wid, hwWid)) = (wid <> hwWid)
89 :     | isPaddedVec _ = false
90 :    
91 : jhr 3754 fun same (BoolTy, BoolTy) = true
92 :     | same (StringTy, StringTy) = true
93 :     | same (IntTy, IntTy) = true
94 : jhr 3835 | same (VecTy(wid1, hwWid1), VecTy(wid2, hwWid2)) = (wid1 = wid2) andalso (hwWid1 = hwWid2)
95 : jhr 3832 | same (TensorTy dd1, TensorTy dd2) = ListPair.allEq (op =) (dd1, dd2)
96 : jhr 3754 | same (TupleTy tys1, TupleTy tys2) = ListPair.allEq same (tys1, tys2)
97 :     | same (SeqTy(ty1, NONE), SeqTy(ty2, NONE)) = same(ty1, ty2)
98 :     | same (SeqTy(ty1, SOME n1), SeqTy(ty2, SOME n2)) = (n1 = n2) andalso same(ty1, ty2)
99 :     | same (ImageTy info1, ImageTy info2) = ImageInfo.sameShape(info1, info2)
100 : jhr 3846 | same (StrandTy n1, StrandTy n2) = Atom.same(n1, n2)
101 : jhr 3754 | same _ = false
102 :    
103 :     fun hash BoolTy = 0w1
104 :     | hash StringTy = 0w2
105 :     | hash IntTy = 0w3
106 : jhr 3835 | hash (VecTy(wid, hwWid)) = 0w5 * Word.fromInt wid + 0w7 * Word.fromInt hwWid
107 : jhr 3832 | hash (TensorTy dd) = List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) 0w13 dd
108 : jhr 3754 | hash (TupleTy tys) = List.foldl (fn (ty, s) => hash ty + s) 0w17 tys
109 :     | hash (SeqTy(ty, NONE)) = hash ty + 0w19
110 :     | hash (SeqTy(ty, SOME n)) = Word.fromInt n * hash ty + 0w23
111 : jhr 3835 | hash (ImageTy info) = 0w37 * ImageInfo.hash info + 0w6
112 : jhr 3846 | hash (StrandTy n) = Atom.hash n
113 : jhr 3754
114 :     fun toString BoolTy = "bool"
115 :     | toString StringTy = "string"
116 :     | toString IntTy = "int"
117 : jhr 3835 | toString (VecTy(1,1)) = "real"
118 :     | toString (VecTy(wid, hwWid)) = if (wid = hwWid)
119 :     then "vec" ^ Int.toString wid
120 :     else concat["vec", Int.toString wid, "{", Int.toString hwWid, "}"]
121 : jhr 3832 | toString (TensorTy dd) = String.concat [
122 :     "tensor[", String.concatWithMap "," Int.toString dd, "]"
123 : jhr 3754 ]
124 :     | toString (TupleTy tys) = String.concat [
125 :     "(", String.concatWithMap " * " toString tys, ")"
126 :     ]
127 :     | toString (SeqTy(ty, NONE)) = toString ty ^ "[]"
128 :     | toString (SeqTy(ty, SOME n)) = concat[toString ty, "[", Int.toString n, "]"]
129 :     | toString (ImageTy info) = concat["image(", ImageInfo.toString info, ")"]
130 : jhr 3846 | toString (StrandTy n) = Atom.toString n
131 : jhr 3754
132 : jhr 3812 structure Tbl = HashTableFn (
133 :     struct
134 :     type hash_key = t
135 :     val hashVal = hash
136 :     val sameKey = same
137 :     end)
138 :    
139 : jhr 3754 end

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