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 3810 - (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 3810 datatype t
15 : jhr 3754 = BoolTy | StringTy | IntTy | RealTy
16 : jhr 3766 | VecTy of int * bool * int list (* vectors have a width and a representation that
17 :     * is spread across hardware-supported vectors.
18 :     * The boolean is true if the type is padded out.
19 :     *)
20 :     (* QUESTION: perhaps at this point, we should just represent higher-order tensors
21 :     * as SeqTy types?
22 :     *)
23 : jhr 3810 | TensorTy of int * t (* type of 2nd-order (or higher) tensor *)
24 :     | TupleTy of t list (* tuples; used for multiple return values *)
25 :     | SeqTy of t * int option
26 : jhr 3754 | AddrTy of ImageInfo.info (* voxel address *)
27 :     | ImageTy of ImageInfo.info
28 :    
29 :     val intTy = IntTy
30 :     val realTy = RealTy
31 : jhr 3757 fun vecTy 1 = RealTy
32 : jhr 3767 | vecTy n = VecTy(n, false, [n])
33 : jhr 3754 fun iVecTy 1 = IntTy
34 :     | iVecTy n = SeqTy(IntTy, SOME n)
35 :    
36 :     (* smart constructor for tensor type that prunes out dimensions with size 1 *)
37 :     fun tensorTy (1, ty) = ty
38 :     | tensorTy arg = TensorTy arg
39 :    
40 :     (* is a type a composite-vector type? *)
41 : jhr 3767 fun isCompVecTy (VecTy(_, _, _::_::_)) = true
42 : jhr 3754 | isCompVecTy _ = false
43 :    
44 :     fun same (BoolTy, BoolTy) = true
45 :     | same (StringTy, StringTy) = true
46 :     | same (IntTy, IntTy) = true
47 :     | same (RealTy, RealTy) = true
48 : jhr 3767 | same (VecTy(d1, b1, vs1), VecTy(d2, b2, vs2)) =
49 :     (d1 = d2) andalso (b1 = b2) andalso ListPair.allEq (op =) (vs1, vs2)
50 : jhr 3754 | same (TensorTy(d1, ty1), TensorTy(d2, ty2)) = (d1 = d2) andalso same(ty1, ty2)
51 :     | same (TupleTy tys1, TupleTy tys2) = ListPair.allEq same (tys1, tys2)
52 :     | same (SeqTy(ty1, NONE), SeqTy(ty2, NONE)) = same(ty1, ty2)
53 :     | same (SeqTy(ty1, SOME n1), SeqTy(ty2, SOME n2)) = (n1 = n2) andalso same(ty1, ty2)
54 :     | same (AddrTy info1, AddrTy info2) = ImageInfo.same(info1, info2)
55 :     | same (ImageTy info1, ImageTy info2) = ImageInfo.sameShape(info1, info2)
56 :     | same _ = false
57 :    
58 :     fun hash BoolTy = 0w1
59 :     | hash StringTy = 0w2
60 :     | hash IntTy = 0w3
61 :     | hash RealTy = 0w5
62 : jhr 3767 | hash (VecTy(d, _, vs)) =
63 : jhr 3766 List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) (0w7 * Word.fromInt d) vs
64 : jhr 3754 | hash (TensorTy(d, ty)) = 0w13 * (Word.fromInt d + hash ty)
65 :     | hash (TupleTy tys) = List.foldl (fn (ty, s) => hash ty + s) 0w17 tys
66 :     | hash (SeqTy(ty, NONE)) = hash ty + 0w19
67 :     | hash (SeqTy(ty, SOME n)) = Word.fromInt n * hash ty + 0w23
68 :     | hash (AddrTy info) = 0w37 + ImageInfo.hash info
69 :     | hash (ImageTy info) = 0w41 * ImageInfo.hash info + 0w6
70 :    
71 :     fun toString BoolTy = "bool"
72 :     | toString StringTy = "string"
73 :     | toString IntTy = "int"
74 :     | toString RealTy = "real"
75 : jhr 3767 | toString (VecTy(d, _, [_])) = "vec" ^ Int.toString d
76 :     | toString (VecTy(d, _, vs)) = String.concat [
77 :     "vec", Int.toString d, "{", String.concatWithMap ":" Int.toString vs, "}"
78 : jhr 3754 ]
79 :     | toString (TensorTy(d, ty)) = String.concat [
80 :     "tensor(", Int.toString d, ",", toString ty, ")"
81 :     ]
82 :     | toString (TupleTy tys) = String.concat [
83 :     "(", String.concatWithMap " * " toString tys, ")"
84 :     ]
85 :     | toString (SeqTy(ty, NONE)) = toString ty ^ "[]"
86 :     | toString (SeqTy(ty, SOME n)) = concat[toString ty, "[", Int.toString n, "]"]
87 :     | toString (AddrTy info) = concat["addr(", ImageInfo.toString info, ")"]
88 :     | toString (ImageTy info) = concat["image(", ImageInfo.toString info, ")"]
89 :    
90 :     end

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