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 3766 - (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 :     datatype ty
15 :     = 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 3754 | TensorTy of int * ty (* type of 2nd-order (or higher) tensor *)
24 :     | TupleTy of ty list (* tuples; used for multiple return values *)
25 :     | SeqTy of ty * int option
26 :     | 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 3766 | vecTy n = VecTy(n, [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 3766 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 3766 | same (VecTy(d1, vs1), VecTy(d2, vs2)) = (d1 = d2) andalso ListPair.allEq (op =) (vs1, vs2)
49 : jhr 3754 | same (TensorTy(d1, ty1), TensorTy(d2, ty2)) = (d1 = d2) andalso same(ty1, ty2)
50 :     | same (TupleTy tys1, TupleTy tys2) = ListPair.allEq same (tys1, tys2)
51 :     | same (SeqTy(ty1, NONE), SeqTy(ty2, NONE)) = same(ty1, ty2)
52 :     | same (SeqTy(ty1, SOME n1), SeqTy(ty2, SOME n2)) = (n1 = n2) andalso same(ty1, ty2)
53 :     | same (AddrTy info1, AddrTy info2) = ImageInfo.same(info1, info2)
54 :     | same (ImageTy info1, ImageTy info2) = ImageInfo.sameShape(info1, info2)
55 :     | same _ = false
56 :    
57 :     fun hash BoolTy = 0w1
58 :     | hash StringTy = 0w2
59 :     | hash IntTy = 0w3
60 :     | hash RealTy = 0w5
61 : jhr 3766 | hash (VecTy(d, vs)) =
62 :     List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) (0w7 * Word.fromInt d) vs
63 : jhr 3754 | hash (TensorTy(d, ty)) = 0w13 * (Word.fromInt d + hash ty)
64 :     | hash (TupleTy tys) = List.foldl (fn (ty, s) => hash ty + s) 0w17 tys
65 :     | hash (SeqTy(ty, NONE)) = hash ty + 0w19
66 :     | hash (SeqTy(ty, SOME n)) = Word.fromInt n * hash ty + 0w23
67 :     | hash (AddrTy info) = 0w37 + ImageInfo.hash info
68 :     | hash (ImageTy info) = 0w41 * ImageInfo.hash info + 0w6
69 :    
70 :     fun toString BoolTy = "bool"
71 :     | toString StringTy = "string"
72 :     | toString IntTy = "int"
73 :     | toString RealTy = "real"
74 : jhr 3766 | toString (VecTy(d, [_])) = "vec" ^ Int.toString d
75 :     | toString (CompVecTy(d, vs)) = String.concat [
76 :     "vec", Int.toStirng d, "{", String.concatWithMap ":" Int.toString vs, "}"
77 : jhr 3754 ]
78 :     | toString (TensorTy(d, ty)) = String.concat [
79 :     "tensor(", Int.toString d, ",", toString ty, ")"
80 :     ]
81 :     | toString (TupleTy tys) = String.concat [
82 :     "(", String.concatWithMap " * " toString tys, ")"
83 :     ]
84 :     | toString (SeqTy(ty, NONE)) = toString ty ^ "[]"
85 :     | toString (SeqTy(ty, SOME n)) = concat[toString ty, "[", Int.toString n, "]"]
86 :     | toString (AddrTy info) = concat["addr(", ImageInfo.toString info, ")"]
87 :     | toString (ImageTy info) = concat["image(", ImageInfo.toString info, ")"]
88 :    
89 :     end

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