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 3894 - (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 3828 | TensorTy of int list (* in-memory tensor type. For 0th order and 1st
29 :     * order tensors, the local-variable types will
30 :     * be RealTy and VecTy (resp.).
31 :     *)
32 : jhr 3810 | TupleTy of t list (* tuples; used for multiple return values *)
33 :     | SeqTy of t * int option
34 : jhr 3754 | ImageTy of ImageInfo.info
35 : jhr 3846 | StrandTy of Atom.atom
36 : jhr 3754
37 :     val intTy = IntTy
38 : jhr 3835
39 :     val realTy = VecTy(1, 1)
40 :    
41 : jhr 3754 fun iVecTy 1 = IntTy
42 :     | iVecTy n = SeqTy(IntTy, SOME n)
43 :    
44 : jhr 3861 fun layoutToString {wid, padded, pieces} = "<layout>"
45 :    
46 : jhr 3835 (* return the vector types that comprise the pieces of a vec_layout *)
47 : jhr 3861 fun piecesOf (layout : vec_layout) = let
48 :     fun toVecs (_, []) = raise Fail(concat["piecesOf(", layoutToString layout, ")"])
49 : jhr 3835 | toVecs (wid, [w]) = [VecTy(wid, w)]
50 :     | toVecs (wid, w::ws) = VecTy(w, w) :: toVecs(wid-w, ws)
51 :     in
52 : jhr 3861 toVecs (#wid layout, #pieces layout)
53 : jhr 3835 end
54 : jhr 3754
55 : jhr 3861 (* return the n'th component of a vector layout as a vector type. *)
56 :     fun nthVec (layout : vec_layout, n) = let
57 :     fun get (_, _, []) =
58 :     raise Fail(concat["nthVec(", layoutToString layout, ", ", Int.toString n, ")"])
59 :     | get (0, wid, w::_) = VecTy(wid, w)
60 :     | get (n, wid, w::ws) = get (n-1, wid-w, ws)
61 :     in
62 :     get (n, #wid layout, #pieces layout)
63 :     end
64 :    
65 : jhr 3894 (* return the offset of the first component in the i'th piece of a vec_layout *)
66 :     fun offsetOf (layout : vec_layout, i) = let
67 :     fun add (0, _, off) = off
68 :     | add (i, pw::pws, off) = add (i-1, pws, off+pw)
69 :     in
70 :     add (i, #pieces layout, 0)
71 :     end
72 :    
73 : jhr 3835 (* is a vector padded? *)
74 :     fun isPaddedVec (VecTy(wid, hwWid)) = (wid <> hwWid)
75 :     | isPaddedVec _ = false
76 :    
77 : jhr 3754 fun same (BoolTy, BoolTy) = true
78 :     | same (StringTy, StringTy) = true
79 :     | same (IntTy, IntTy) = true
80 : jhr 3835 | same (VecTy(wid1, hwWid1), VecTy(wid2, hwWid2)) = (wid1 = wid2) andalso (hwWid1 = hwWid2)
81 : jhr 3832 | same (TensorTy dd1, TensorTy dd2) = ListPair.allEq (op =) (dd1, dd2)
82 : jhr 3754 | same (TupleTy tys1, TupleTy tys2) = ListPair.allEq same (tys1, tys2)
83 :     | same (SeqTy(ty1, NONE), SeqTy(ty2, NONE)) = same(ty1, ty2)
84 :     | same (SeqTy(ty1, SOME n1), SeqTy(ty2, SOME n2)) = (n1 = n2) andalso same(ty1, ty2)
85 :     | same (ImageTy info1, ImageTy info2) = ImageInfo.sameShape(info1, info2)
86 : jhr 3846 | same (StrandTy n1, StrandTy n2) = Atom.same(n1, n2)
87 : jhr 3754 | same _ = false
88 :    
89 :     fun hash BoolTy = 0w1
90 :     | hash StringTy = 0w2
91 :     | hash IntTy = 0w3
92 : jhr 3835 | hash (VecTy(wid, hwWid)) = 0w5 * Word.fromInt wid + 0w7 * Word.fromInt hwWid
93 : jhr 3832 | hash (TensorTy dd) = List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) 0w13 dd
94 : jhr 3754 | hash (TupleTy tys) = List.foldl (fn (ty, s) => hash ty + s) 0w17 tys
95 :     | hash (SeqTy(ty, NONE)) = hash ty + 0w19
96 :     | hash (SeqTy(ty, SOME n)) = Word.fromInt n * hash ty + 0w23
97 : jhr 3835 | hash (ImageTy info) = 0w37 * ImageInfo.hash info + 0w6
98 : jhr 3846 | hash (StrandTy n) = Atom.hash n
99 : jhr 3754
100 :     fun toString BoolTy = "bool"
101 :     | toString StringTy = "string"
102 :     | toString IntTy = "int"
103 : jhr 3835 | toString (VecTy(1,1)) = "real"
104 :     | toString (VecTy(wid, hwWid)) = if (wid = hwWid)
105 :     then "vec" ^ Int.toString wid
106 :     else concat["vec", Int.toString wid, "{", Int.toString hwWid, "}"]
107 : jhr 3832 | toString (TensorTy dd) = String.concat [
108 :     "tensor[", String.concatWithMap "," Int.toString dd, "]"
109 : jhr 3754 ]
110 :     | toString (TupleTy tys) = String.concat [
111 :     "(", String.concatWithMap " * " toString tys, ")"
112 :     ]
113 :     | toString (SeqTy(ty, NONE)) = toString ty ^ "[]"
114 :     | toString (SeqTy(ty, SOME n)) = concat[toString ty, "[", Int.toString n, "]"]
115 :     | toString (ImageTy info) = concat["image(", ImageInfo.toString info, ")"]
116 : jhr 3846 | toString (StrandTy n) = Atom.toString n
117 : jhr 3754
118 : jhr 3812 structure Tbl = HashTableFn (
119 :     struct
120 :     type hash_key = t
121 :     val hashVal = hash
122 :     val sameKey = same
123 :     end)
124 :    
125 : jhr 3754 end

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