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 3834, Sat May 7 18:39:53 2016 UTC revision 3835, Sun May 8 13:10:17 2016 UTC
# Line 19  Line 19 
19        }        }
20    
21      datatype t      datatype t
22        = BoolTy | StringTy | IntTy | RealTy        = BoolTy | StringTy | IntTy
23        | VecTy of vec_layout             (* vectors have a width and a representation that        | VecTy of int * int              (* a vector value that fits into a target-supported
24                                           * is spread across hardware-supported vectors.                                           * vector. The first int is the width of the vector
25                                           * The boolean is true if the type is padded out.                                           * and the second is the target width, which will be
26                                             * >= the vector width.
27                                           *)                                           *)
28        | TensorTy of int list            (* in-memory tensor type.  For 0th order and 1st        | TensorTy of int list            (* in-memory tensor type.  For 0th order and 1st
29                                           * order tensors, the local-variable types will                                           * order tensors, the local-variable types will
# Line 30  Line 31 
31                                           *)                                           *)
32        | TupleTy of t list               (* tuples; used for multiple return values *)        | TupleTy of t list               (* tuples; used for multiple return values *)
33        | SeqTy of t * int option        | SeqTy of t * int option
       | AddrTy of ImageInfo.info        (* voxel address *)  
34        | ImageTy of ImageInfo.info        | ImageTy of ImageInfo.info
35    
36      val intTy = IntTy      val intTy = IntTy
37      val realTy = RealTy  
38      fun vecTy 1 = RealTy      val realTy = VecTy(1, 1)
39        | 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    
43    (* is a type a composite-vector type? *)    (* return the vector types that comprise the pieces of a vec_layout *)
44      fun isCompVecTy (VecTy{pieces = _::_::_, ...}) = true      fun piecesOf ({wid, pieces, ...} : vec_layout) = let
45        | isCompVecTy _ = false            fun toVecs (_, []) = raise Fail "no pieces"
46                | toVecs (wid, [w]) = [VecTy(wid, w)]
47                | toVecs (wid, w::ws) = VecTy(w, w) :: toVecs(wid-w, ws)
48              in
49                toVecs (wid, pieces)
50              end
51    
52      (* is a vector padded? *)
53        fun isPaddedVec (VecTy(wid, hwWid)) = (wid <> hwWid)
54          | isPaddedVec _ = false
55    
56      fun same (BoolTy, BoolTy) = true      fun same (BoolTy, BoolTy) = true
57        | same (StringTy, StringTy) = true        | same (StringTy, StringTy) = true
58        | same (IntTy, IntTy) = true        | same (IntTy, IntTy) = true
59        | same (RealTy, RealTy) = true        | same (VecTy(wid1, hwWid1), VecTy(wid2, hwWid2)) = (wid1 = wid2) andalso (hwWid1 = hwWid2)
       | same (VecTy{wid=d1, padded=b1, pieces=vs1}, VecTy{wid=d2, padded=b2, pieces=vs2}) =  
           (d1 = d2) andalso (b1 = b2) andalso ListPair.allEq (op =) (vs1, vs2)  
60        | same (TensorTy dd1, TensorTy dd2) = ListPair.allEq (op =) (dd1, dd2)        | same (TensorTy dd1, TensorTy dd2) = ListPair.allEq (op =) (dd1, dd2)
61        | same (TupleTy tys1, TupleTy tys2) = ListPair.allEq same (tys1, tys2)        | same (TupleTy tys1, TupleTy tys2) = ListPair.allEq same (tys1, tys2)
62        | same (SeqTy(ty1, NONE), SeqTy(ty2, NONE)) = same(ty1, ty2)        | same (SeqTy(ty1, NONE), SeqTy(ty2, NONE)) = same(ty1, ty2)
63        | 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)
       | same (AddrTy info1, AddrTy info2) = ImageInfo.same(info1, info2)  
64        | same (ImageTy info1, ImageTy info2) = ImageInfo.sameShape(info1, info2)        | same (ImageTy info1, ImageTy info2) = ImageInfo.sameShape(info1, info2)
65        | same _ = false        | same _ = false
66    
67      fun hash BoolTy = 0w1      fun hash BoolTy = 0w1
68        | hash StringTy = 0w2        | hash StringTy = 0w2
69        | hash IntTy = 0w3        | hash IntTy = 0w3
70        | hash RealTy = 0w5        | hash (VecTy(wid, hwWid)) = 0w5 * Word.fromInt wid + 0w7 * Word.fromInt hwWid
       | hash (VecTy{wid, pieces, ...}) =  
           List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) (0w7 * Word.fromInt wid) pieces  
71        | hash (TensorTy dd) = List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) 0w13 dd        | hash (TensorTy dd) = List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) 0w13 dd
72        | 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
73        | hash (SeqTy(ty, NONE)) = hash ty + 0w19        | hash (SeqTy(ty, NONE)) = hash ty + 0w19
74        | hash (SeqTy(ty, SOME n)) = Word.fromInt n * hash ty + 0w23        | hash (SeqTy(ty, SOME n)) = Word.fromInt n * hash ty + 0w23
75        | hash (AddrTy info) = 0w37 + ImageInfo.hash info        | hash (ImageTy info) = 0w37 * ImageInfo.hash info + 0w6
       | hash (ImageTy info) = 0w41 * ImageInfo.hash info + 0w6  
76    
77      fun toString BoolTy = "bool"      fun toString BoolTy = "bool"
78        | toString StringTy = "string"        | toString StringTy = "string"
79        | toString IntTy = "int"        | toString IntTy = "int"
80        | toString RealTy = "real"        | toString (VecTy(1,1)) = "real"
81        | toString (VecTy{wid, padded=false, pieces=[_]}) = "vec" ^ Int.toString wid        | toString (VecTy(wid, hwWid)) = if (wid = hwWid)
82        | toString (VecTy{wid, pieces, ...}) = String.concat [            then "vec" ^ Int.toString wid
83              "vec", Int.toString wid, "{", String.concatWithMap ":" Int.toString pieces, "}"            else concat["vec", Int.toString wid, "{", Int.toString hwWid, "}"]
           ]  
84        | toString (TensorTy dd) = String.concat [        | toString (TensorTy dd) = String.concat [
85              "tensor[", String.concatWithMap "," Int.toString dd, "]"              "tensor[", String.concatWithMap "," Int.toString dd, "]"
86            ]            ]
# Line 87  Line 89 
89            ]            ]
90        | toString (SeqTy(ty, NONE)) = toString ty ^ "[]"        | toString (SeqTy(ty, NONE)) = toString ty ^ "[]"
91        | toString (SeqTy(ty, SOME n)) = concat[toString ty, "[", Int.toString n, "]"]        | toString (SeqTy(ty, SOME n)) = concat[toString ty, "[", Int.toString n, "]"]
       | toString (AddrTy info) = concat["addr(", ImageInfo.toString info, ")"]  
92        | toString (ImageTy info) = concat["image(", ImageInfo.toString info, ")"]        | toString (ImageTy info) = concat["image(", ImageInfo.toString info, ")"]
93    
94      structure Tbl = HashTableFn (      structure Tbl = HashTableFn (

Legend:
Removed from v.3834  
changed lines
  Added in v.3835

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