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 3861 - (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 3835 (* is a vector padded? *)
66 :     fun isPaddedVec (VecTy(wid, hwWid)) = (wid <> hwWid)
67 :     | isPaddedVec _ = false
68 :    
69 : jhr 3754 fun same (BoolTy, BoolTy) = true
70 :     | same (StringTy, StringTy) = true
71 :     | same (IntTy, IntTy) = true
72 : jhr 3835 | same (VecTy(wid1, hwWid1), VecTy(wid2, hwWid2)) = (wid1 = wid2) andalso (hwWid1 = hwWid2)
73 : jhr 3832 | same (TensorTy dd1, TensorTy dd2) = ListPair.allEq (op =) (dd1, dd2)
74 : jhr 3754 | same (TupleTy tys1, TupleTy tys2) = ListPair.allEq same (tys1, tys2)
75 :     | same (SeqTy(ty1, NONE), SeqTy(ty2, NONE)) = same(ty1, ty2)
76 :     | same (SeqTy(ty1, SOME n1), SeqTy(ty2, SOME n2)) = (n1 = n2) andalso same(ty1, ty2)
77 :     | same (ImageTy info1, ImageTy info2) = ImageInfo.sameShape(info1, info2)
78 : jhr 3846 | same (StrandTy n1, StrandTy n2) = Atom.same(n1, n2)
79 : jhr 3754 | same _ = false
80 :    
81 :     fun hash BoolTy = 0w1
82 :     | hash StringTy = 0w2
83 :     | hash IntTy = 0w3
84 : jhr 3835 | hash (VecTy(wid, hwWid)) = 0w5 * Word.fromInt wid + 0w7 * Word.fromInt hwWid
85 : jhr 3832 | hash (TensorTy dd) = List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) 0w13 dd
86 : jhr 3754 | hash (TupleTy tys) = List.foldl (fn (ty, s) => hash ty + s) 0w17 tys
87 :     | hash (SeqTy(ty, NONE)) = hash ty + 0w19
88 :     | hash (SeqTy(ty, SOME n)) = Word.fromInt n * hash ty + 0w23
89 : jhr 3835 | hash (ImageTy info) = 0w37 * ImageInfo.hash info + 0w6
90 : jhr 3846 | hash (StrandTy n) = Atom.hash n
91 : jhr 3754
92 :     fun toString BoolTy = "bool"
93 :     | toString StringTy = "string"
94 :     | toString IntTy = "int"
95 : jhr 3835 | toString (VecTy(1,1)) = "real"
96 :     | toString (VecTy(wid, hwWid)) = if (wid = hwWid)
97 :     then "vec" ^ Int.toString wid
98 :     else concat["vec", Int.toString wid, "{", Int.toString hwWid, "}"]
99 : jhr 3832 | toString (TensorTy dd) = String.concat [
100 :     "tensor[", String.concatWithMap "," Int.toString dd, "]"
101 : jhr 3754 ]
102 :     | toString (TupleTy tys) = String.concat [
103 :     "(", String.concatWithMap " * " toString tys, ")"
104 :     ]
105 :     | toString (SeqTy(ty, NONE)) = toString ty ^ "[]"
106 :     | toString (SeqTy(ty, SOME n)) = concat[toString ty, "[", Int.toString n, "]"]
107 :     | toString (ImageTy info) = concat["image(", ImageInfo.toString info, ")"]
108 : jhr 3846 | toString (StrandTy n) = Atom.toString n
109 : jhr 3754
110 : jhr 3812 structure Tbl = HashTableFn (
111 :     struct
112 :     type hash_key = t
113 :     val hashVal = hash
114 :     val sameKey = same
115 :     end)
116 :    
117 : jhr 3754 end

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