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 4386 - (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 : jhr 4151 type vec_layout = VectorLayout.t
16 : jhr 3832
17 : jhr 3810 datatype t
18 : jhr 3835 = BoolTy | StringTy | IntTy
19 : jhr 4317 | VecTy of int * int (* a vector value that fits into a target-supported
20 :     * vector. The first int is the width of the vector
21 :     * and the second is the target width, which will be
22 :     * >= the vector width.
23 :     *)
24 :     | TensorTy of int list (* in-memory tensor type. For 0th order and 1st
25 :     * order tensors, the local-variable types will
26 :     * be RealTy and VecTy (resp.).
27 :     *)
28 :     | TensorRefTy of int list (* a shared reference to tensor *)
29 : jhr 3810 | TupleTy of t list (* tuples; used for multiple return values *)
30 :     | SeqTy of t * int option
31 : jhr 3754 | ImageTy of ImageInfo.info
32 : jhr 4386 | StrandIdTy of Atom.atom (* index into strand-state array *)
33 :     | StrandPtrTy of Atom.atom (* pointer to strand state object *)
34 : jhr 3754
35 :     val intTy = IntTy
36 : jhr 3835
37 :     val realTy = VecTy(1, 1)
38 :    
39 : jhr 3754 fun iVecTy 1 = IntTy
40 :     | iVecTy n = SeqTy(IntTy, SOME n)
41 :    
42 : jhr 3835 (* return the vector types that comprise the pieces of a vec_layout *)
43 : jhr 3861 fun piecesOf (layout : vec_layout) = let
44 : jhr 4317 fun toVecs (_, []) = raise Fail(concat["piecesOf(", VectorLayout.toString layout, ")"])
45 :     | toVecs (wid, [w]) = [VecTy(wid, w)]
46 :     | toVecs (wid, w::ws) = VecTy(w, w) :: toVecs(wid-w, ws)
47 :     in
48 :     toVecs (#wid layout, #pieces layout)
49 :     end
50 : jhr 3754
51 : jhr 3919 (* return the unpadded width of the n'th component of a vector layout *)
52 :     fun nthWidth (layout : vec_layout, n) = let
53 : jhr 4317 fun get (_, _, []) =
54 :     raise Fail(concat["nthWidth(", VectorLayout.toString layout, ", ", Int.toString n, ")"])
55 :     | get (0, wid, _) = wid
56 :     | get (n, wid, w::ws) = get (n-1, wid-w, ws)
57 :     in
58 :     get (n, #wid layout, #pieces layout)
59 :     end
60 : jhr 3919
61 : jhr 3861 (* return the n'th component of a vector layout as a vector type. *)
62 :     fun nthVec (layout : vec_layout, n) = let
63 : jhr 4317 fun get (_, _, []) = raise Fail(concat[
64 :     "nthVec(", VectorLayout.toString layout, ", ", Int.toString n, ")"
65 :     ])
66 :     | get (0, wid, w::_) = VecTy(wid, w)
67 :     | get (n, wid, w::ws) = get (n-1, wid-w, ws)
68 :     in
69 :     get (n, #wid layout, #pieces layout)
70 :     end
71 : jhr 3861
72 : jhr 3894 (* return the offset of the first component in the i'th piece of a vec_layout *)
73 :     fun offsetOf (layout : vec_layout, i) = let
74 : jhr 4317 fun add (0, _, off) = off
75 :     | add (i, pw::pws, off) = add (i-1, pws, off+pw)
76 :     in
77 :     add (i, #pieces layout, 0)
78 :     end
79 : jhr 3894
80 : jhr 3835 (* is a vector padded? *)
81 :     fun isPaddedVec (VecTy(wid, hwWid)) = (wid <> hwWid)
82 :     | isPaddedVec _ = false
83 :    
84 : jhr 3955 (* are two type structurally equal? *)
85 : jhr 3754 fun same (BoolTy, BoolTy) = true
86 :     | same (StringTy, StringTy) = true
87 :     | same (IntTy, IntTy) = true
88 : jhr 3835 | same (VecTy(wid1, hwWid1), VecTy(wid2, hwWid2)) = (wid1 = wid2) andalso (hwWid1 = hwWid2)
89 : jhr 3832 | same (TensorTy dd1, TensorTy dd2) = ListPair.allEq (op =) (dd1, dd2)
90 : jhr 3955 | same (TensorRefTy dd1, TensorRefTy dd2) = ListPair.allEq (op =) (dd1, dd2)
91 : jhr 3754 | same (TupleTy tys1, TupleTy tys2) = ListPair.allEq same (tys1, tys2)
92 :     | same (SeqTy(ty1, NONE), SeqTy(ty2, NONE)) = same(ty1, ty2)
93 :     | same (SeqTy(ty1, SOME n1), SeqTy(ty2, SOME n2)) = (n1 = n2) andalso same(ty1, ty2)
94 :     | same (ImageTy info1, ImageTy info2) = ImageInfo.sameShape(info1, info2)
95 : jhr 4386 | same (StrandIdTy n1, StrandIdTy n2) = Atom.same(n1, n2)
96 :     | same (StrandPtrTy n1, StrandPtrTy n2) = Atom.same(n1, n2)
97 : jhr 3754 | same _ = false
98 :    
99 : jhr 3955 (* is a source type compatible with the destination type? *)
100 :     fun match {src = TensorTy dd1, dst = TensorRefTy dd2} = ListPair.allEq (op =) (dd1, dd2)
101 :     | match {src, dst} = same(src, dst)
102 :    
103 : jhr 3754 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 3955 | hash (TensorRefTy dd) = List.foldl (fn (d, s) => 0w13 * Word.fromInt d + s) 0w17 dd
109 :     | hash (TupleTy tys) = List.foldl (fn (ty, s) => hash ty + s) 0w19 tys
110 :     | hash (SeqTy(ty, NONE)) = hash ty + 0w23
111 :     | hash (SeqTy(ty, SOME n)) = Word.fromInt n * hash ty + 0w29
112 : jhr 3835 | hash (ImageTy info) = 0w37 * ImageInfo.hash info + 0w6
113 : jhr 4386 | hash (StrandIdTy n) = 0w41 + Atom.hash n
114 :     | hash (StrandPtrTy n) = 0w43 + Atom.hash n
115 : jhr 3754
116 :     fun toString BoolTy = "bool"
117 :     | toString StringTy = "string"
118 :     | toString IntTy = "int"
119 : jhr 3835 | toString (VecTy(1,1)) = "real"
120 :     | toString (VecTy(wid, hwWid)) = if (wid = hwWid)
121 : jhr 4317 then "vec" ^ Int.toString wid
122 :     else concat["vec", Int.toString wid, "{", Int.toString hwWid, "}"]
123 : jhr 3832 | toString (TensorTy dd) = String.concat [
124 :     "tensor[", String.concatWithMap "," Int.toString dd, "]"
125 : jhr 3754 ]
126 : jhr 3955 | toString (TensorRefTy dd) = String.concat [
127 :     "&tensor[", String.concatWithMap "," Int.toString dd, "]"
128 :     ]
129 : jhr 3754 | toString (TupleTy tys) = String.concat [
130 :     "(", String.concatWithMap " * " toString tys, ")"
131 :     ]
132 :     | toString (SeqTy(ty, NONE)) = toString ty ^ "[]"
133 :     | toString (SeqTy(ty, SOME n)) = concat[toString ty, "[", Int.toString n, "]"]
134 :     | toString (ImageTy info) = concat["image(", ImageInfo.toString info, ")"]
135 : jhr 4386 | toString (StrandIdTy n) = concat["id(", Atom.toString n, ")"]
136 :     | toString (StrandPtrTy n) = "&" ^ Atom.toString n
137 : jhr 3754
138 : jhr 3812 structure Tbl = HashTableFn (
139 :     struct
140 :     type hash_key = t
141 : jhr 4317 val hashVal = hash
142 :     val sameKey = same
143 : jhr 3812 end)
144 :    
145 : jhr 3754 end

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