Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/vis15/src/compiler/tree-ir/tree-types.sml
ViewVC logotype

Diff of /branches/vis15/src/compiler/tree-ir/tree-types.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3831, Thu May 5 22:17:06 2016 UTC revision 3832, Fri May 6 15:08:12 2016 UTC
# Line 11  Line 11 
11  structure TreeTypes =  structure TreeTypes =
12    struct    struct
13    
14      (* 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      datatype t      datatype t
22        = BoolTy | StringTy | IntTy | RealTy        = BoolTy | StringTy | IntTy | RealTy
23        | VecTy of int * bool * int list  (* vectors have a width and a representation that        | VecTy of vec_layout             (* vectors have a width and a representation that
24                                           * is spread across hardware-supported vectors.                                           * is spread across hardware-supported vectors.
25                                           * The boolean is true if the type is padded out.                                           * The boolean is true if the type is padded out.
26                                           *)                                           *)
# Line 29  Line 36 
36      val intTy = IntTy      val intTy = IntTy
37      val realTy = RealTy      val realTy = RealTy
38      fun vecTy 1 = RealTy      fun vecTy 1 = RealTy
39        | vecTy n = VecTy(n, false, [n])        | vecTy n = VecTy{wid = n, padded = false, pieces = [n]}
40      fun iVecTy 1 = IntTy      fun iVecTy 1 = IntTy
41        | iVecTy n = SeqTy(IntTy, SOME n)        | iVecTy n = SeqTy(IntTy, SOME n)
42    
   (* smart constructor for tensor type that prunes out dimensions with size 1 *)  
     fun tensorTy (1, ty) = ty  
       | tensorTy arg = TensorTy arg  
   
43    (* is a type a composite-vector type? *)    (* is a type a composite-vector type? *)
44      fun isCompVecTy (VecTy(_, _, _::_::_)) = true      fun isCompVecTy (VecTy{pieces = _::_::_, ...}) = true
45        | isCompVecTy _ = false        | isCompVecTy _ = false
46    
47      fun same (BoolTy, BoolTy) = true      fun same (BoolTy, BoolTy) = true
48        | same (StringTy, StringTy) = true        | same (StringTy, StringTy) = true
49        | same (IntTy, IntTy) = true        | same (IntTy, IntTy) = true
50        | same (RealTy, RealTy) = true        | same (RealTy, RealTy) = true
51        | same (VecTy(d1, b1, vs1), VecTy(d2, b2, vs2)) =        | same (VecTy{wid=d1, padded=b1, pieces=vs1}, VecTy{wid=d2, padded=b2, pieces=vs2}) =
52            (d1 = d2) andalso (b1 = b2) andalso ListPair.allEq (op =) (vs1, vs2)            (d1 = d2) andalso (b1 = b2) andalso ListPair.allEq (op =) (vs1, vs2)
53        | same (TensorTy(d1, ty1), TensorTy(d2, ty2)) = (d1 = d2) andalso same(ty1, ty2)        | same (TensorTy dd1, TensorTy dd2) = ListPair.allEq (op =) (dd1, dd2)
54        | same (TupleTy tys1, TupleTy tys2) = ListPair.allEq same (tys1, tys2)        | same (TupleTy tys1, TupleTy tys2) = ListPair.allEq same (tys1, tys2)
55        | same (SeqTy(ty1, NONE), SeqTy(ty2, NONE)) = same(ty1, ty2)        | 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)        | same (SeqTy(ty1, SOME n1), SeqTy(ty2, SOME n2)) = (n1 = n2) andalso same(ty1, ty2)
# Line 59  Line 62 
62        | hash StringTy = 0w2        | hash StringTy = 0w2
63        | hash IntTy = 0w3        | hash IntTy = 0w3
64        | hash RealTy = 0w5        | hash RealTy = 0w5
65        | hash (VecTy(d, _, vs)) =        | hash (VecTy{wid, pieces, ...}) =
66            List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) (0w7 * Word.fromInt d) vs            List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) (0w7 * Word.fromInt wid) pieces
67        | hash (TensorTy(d, ty)) = 0w13 * (Word.fromInt d + hash ty)        | hash (TensorTy dd) = List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) 0w13 dd
68        | hash (TupleTy tys) = List.foldl (fn (ty, s) => hash ty + s) 0w17 tys        | hash (TupleTy tys) = List.foldl (fn (ty, s) => hash ty + s) 0w17 tys
69        | hash (SeqTy(ty, NONE)) = hash ty + 0w19        | hash (SeqTy(ty, NONE)) = hash ty + 0w19
70        | hash (SeqTy(ty, SOME n)) = Word.fromInt n * hash ty + 0w23        | hash (SeqTy(ty, SOME n)) = Word.fromInt n * hash ty + 0w23
# Line 72  Line 75 
75        | toString StringTy = "string"        | toString StringTy = "string"
76        | toString IntTy = "int"        | toString IntTy = "int"
77        | toString RealTy = "real"        | toString RealTy = "real"
78        | toString (VecTy(d, _, [_])) = "vec" ^ Int.toString d        | toString (VecTy{wid, padded=false, pieces=[_]}) = "vec" ^ Int.toString wid
79        | toString (VecTy(d, _, vs)) = String.concat [        | toString (VecTy{wid, pieces, ...}) = String.concat [
80              "vec", Int.toString d, "{", String.concatWithMap ":" Int.toString vs, "}"              "vec", Int.toString wid, "{", String.concatWithMap ":" Int.toString pieces, "}"
81            ]            ]
82        | toString (TensorTy(d, ty)) = String.concat [        | toString (TensorTy dd) = String.concat [
83              "tensor(", Int.toString d, ",", toString ty, ")"              "tensor[", String.concatWithMap "," Int.toString dd, "]"
84            ]            ]
85        | toString (TupleTy tys) = String.concat [        | toString (TupleTy tys) = String.concat [
86              "(", String.concatWithMap " * " toString tys, ")"              "(", String.concatWithMap " * " toString tys, ")"

Legend:
Removed from v.3831  
changed lines
  Added in v.3832

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