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 3832 - (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 3754 = BoolTy | StringTy | IntTy | RealTy
23 : jhr 3832 | VecTy of vec_layout (* vectors have a width and a representation that
24 : jhr 3766 * is spread across hardware-supported vectors.
25 :     * The boolean is true if the type is padded out.
26 :     *)
27 : jhr 3828 | TensorTy of int list (* in-memory tensor type. For 0th order and 1st
28 :     * order tensors, the local-variable types will
29 :     * be RealTy and VecTy (resp.).
30 :     *)
31 : jhr 3810 | TupleTy of t list (* tuples; used for multiple return values *)
32 :     | SeqTy of t * int option
33 : jhr 3754 | AddrTy of ImageInfo.info (* voxel address *)
34 :     | ImageTy of ImageInfo.info
35 :    
36 :     val intTy = IntTy
37 :     val realTy = RealTy
38 : jhr 3757 fun vecTy 1 = RealTy
39 : jhr 3832 | vecTy n = VecTy{wid = n, padded = false, pieces = [n]}
40 : jhr 3754 fun iVecTy 1 = IntTy
41 :     | iVecTy n = SeqTy(IntTy, SOME n)
42 :    
43 :     (* is a type a composite-vector type? *)
44 : jhr 3832 fun isCompVecTy (VecTy{pieces = _::_::_, ...}) = true
45 : jhr 3754 | isCompVecTy _ = false
46 :    
47 :     fun same (BoolTy, BoolTy) = true
48 :     | same (StringTy, StringTy) = true
49 :     | same (IntTy, IntTy) = true
50 :     | same (RealTy, RealTy) = true
51 : jhr 3832 | same (VecTy{wid=d1, padded=b1, pieces=vs1}, VecTy{wid=d2, padded=b2, pieces=vs2}) =
52 : jhr 3767 (d1 = d2) andalso (b1 = b2) andalso ListPair.allEq (op =) (vs1, vs2)
53 : jhr 3832 | same (TensorTy dd1, TensorTy dd2) = ListPair.allEq (op =) (dd1, dd2)
54 : jhr 3754 | same (TupleTy tys1, TupleTy tys2) = ListPair.allEq same (tys1, tys2)
55 :     | same (SeqTy(ty1, NONE), SeqTy(ty2, NONE)) = same(ty1, ty2)
56 :     | same (SeqTy(ty1, SOME n1), SeqTy(ty2, SOME n2)) = (n1 = n2) andalso same(ty1, ty2)
57 :     | same (AddrTy info1, AddrTy info2) = ImageInfo.same(info1, info2)
58 :     | same (ImageTy info1, ImageTy info2) = ImageInfo.sameShape(info1, info2)
59 :     | same _ = false
60 :    
61 :     fun hash BoolTy = 0w1
62 :     | hash StringTy = 0w2
63 :     | hash IntTy = 0w3
64 :     | hash RealTy = 0w5
65 : jhr 3832 | hash (VecTy{wid, pieces, ...}) =
66 :     List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) (0w7 * Word.fromInt wid) pieces
67 :     | hash (TensorTy dd) = List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) 0w13 dd
68 : jhr 3754 | hash (TupleTy tys) = List.foldl (fn (ty, s) => hash ty + s) 0w17 tys
69 :     | hash (SeqTy(ty, NONE)) = hash ty + 0w19
70 :     | hash (SeqTy(ty, SOME n)) = Word.fromInt n * hash ty + 0w23
71 :     | hash (AddrTy info) = 0w37 + ImageInfo.hash info
72 :     | hash (ImageTy info) = 0w41 * ImageInfo.hash info + 0w6
73 :    
74 :     fun toString BoolTy = "bool"
75 :     | toString StringTy = "string"
76 :     | toString IntTy = "int"
77 :     | toString RealTy = "real"
78 : jhr 3832 | toString (VecTy{wid, padded=false, pieces=[_]}) = "vec" ^ Int.toString wid
79 :     | toString (VecTy{wid, pieces, ...}) = String.concat [
80 :     "vec", Int.toString wid, "{", String.concatWithMap ":" Int.toString pieces, "}"
81 : jhr 3754 ]
82 : jhr 3832 | toString (TensorTy dd) = String.concat [
83 :     "tensor[", String.concatWithMap "," Int.toString dd, "]"
84 : jhr 3754 ]
85 :     | toString (TupleTy tys) = String.concat [
86 :     "(", String.concatWithMap " * " toString tys, ")"
87 :     ]
88 :     | toString (SeqTy(ty, NONE)) = toString ty ^ "[]"
89 :     | toString (SeqTy(ty, SOME n)) = concat[toString ty, "[", Int.toString n, "]"]
90 :     | toString (AddrTy info) = concat["addr(", ImageInfo.toString info, ")"]
91 :     | toString (ImageTy info) = concat["image(", ImageInfo.toString info, ")"]
92 :    
93 : jhr 3812 structure Tbl = HashTableFn (
94 :     struct
95 :     type hash_key = t
96 :     val hashVal = hash
97 :     val sameKey = same
98 :     end)
99 :    
100 : jhr 3754 end

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