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

SCM Repository

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

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

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

revision 3529, Tue Dec 22 18:25:22 2015 UTC revision 3532, Tue Dec 22 20:56:16 2015 UTC
# Line 1  Line 1 
1  (* mid-types.sml  (* mid-types.sml
2   *   *
3     * Types for the MidIR.
4     *
5   * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)   * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
6   *   *
7   * COPYRIGHT (c) 2015 The University of Chicago   * COPYRIGHT (c) 2015 The University of Chicago
8   * All rights reserved.   * All rights reserved.
  *  
  * Types for the MidIR.  
9   *)   *)
10    
11  structure MidTypes =  structure MidTypes =
# Line 13  Line 13 
13    
14      datatype ty      datatype ty
15        = BoolTy | StringTy | IntTy        = BoolTy | StringTy | IntTy
16        | TensorTy of int list            (* tensor types, which include reals, sequences of reals, etc. *)        | TensorTy of int list            (* tensor types, which include reals, vectors, etc. *)
17        | TupleTy of ty list              (* tuples; used for multiple return values *)        | TupleTy of ty list              (* tuples; used for multiple return values *)
18        | SeqTy of ty * int        | SeqTy of ty * int option
19        | AddrTy of ImageInfo.info        (* voxel address *)        | AddrTy of ImageInfo.info        (* voxel address *)
20        | ImageTy of ImageInfo.info        | ImageTy of ImageInfo.info
21        | KernelTy        | KernelTy
 (* FIXME: ask Charisee about the following *)  
       | IndexTy of int list (* Specific index *)  
       | ImgIndexTy of int list (* Image Index V_0 or V_1, [] for scalars *)  
       | VectorLengthTy of int list  
       | UnionTy of int  (*union5_t *)  
       | R of RationalEin.rat  
22    
23      val intTy = IntTy      val intTy = IntTy
     fun iVecTy 1 = IntTy  
       | iVecTy n = SeqTy(IntTy, n)  
24      val realTy = TensorTy[]      val realTy = TensorTy[]
25      fun vecTy 1 = realTy      fun vecTy 1 = realTy
26        | vecTy n = TensorTy[n]        | vecTy n = TensorTy[n]
27    
28      fun tensorTy dd = (case (List.mapPartial (fn 1 => NONE | d => SOME d) dd)    (* smart constructor for tensor type that prunes out dimensions with size 1 *)
29             of [] => realTy (* 0-order tensors are represented as reals *)      fun tensorTy dd = TensorTy(List.mapPartial (fn 1 => NONE | d => SOME d) dd)
             | dd => TensorTy dd  
           (* end case *))  
30    
31      fun same (BoolTy, BoolTy) = true      fun same (BoolTy, BoolTy) = true
32        | same (StringTy, StringTy) = true        | same (StringTy, StringTy) = true
33        | same (IntTy, IntTy) = true        | same (IntTy, IntTy) = true
34        | same (TensorTy dd1, TensorTy dd2) = (dd1 = dd2)        | same (TensorTy dd1, TensorTy dd2) = (dd1 = dd2)
35        | same (TupleTy tys1, TupleTy tys2) = ListPair.allEq same (tys1, tys2)        | same (TupleTy tys1, TupleTy tys2) = ListPair.allEq same (tys1, tys2)
36        | same (SeqTy(ty1, n1), SeqTy(ty2, n2)) = (n1 = n2) andalso same(ty1, ty2)        | same (SeqTy(ty1, NONE), SeqTy(ty2, NONE)) = same(ty1, ty2)
37          | same (SeqTy(ty1, SOME n1), SeqTy(ty2, SOME n2)) = (n1 = n2) andalso same(ty1, ty2)
38        | same (AddrTy info1, AddrTy info2) = ImageInfo.same(info1, info2)        | same (AddrTy info1, AddrTy info2) = ImageInfo.same(info1, info2)
39        | same (ImageTy info1, ImageTy info2) = ImageInfo.same(info1, info2)        | same (ImageTy info1, ImageTy info2) = ImageInfo.sameShape(info1, info2)
40        | same (KernelTy, KernelTy) = true        | same (KernelTy, KernelTy) = true
41  (* ??? the following don't seem correct ??? *)  (* ??? the following two don't seem correct ??? *)
42        | same (TensorTy[], intTy) = true        | same (TensorTy[], intTy) = true
43        | same (intTy, TensorTy[]) = true        | same (intTy, TensorTy[]) = true
       | same (IndexTy dd1, IndexTy dd2)=(dd1=dd2)  
       | same (ImgIndexTy dd1, ImgIndexTy dd2) = (dd1=dd2)  
       | same (VectorLengthTy dd1, VectorLengthTy  dd2) = (dd1=dd2)  
       | same (UnionTy n1, UnionTy n2)= (n1=n2)  
44        | same _ = false        | same _ = false
45    
46      fun hash BoolTy = 0w1      fun hash BoolTy = 0w1
47        | hash StringTy = 0w2        | hash StringTy = 0w2
48        | hash IntTy = 0w3        | hash IntTy = 0w3
49        | hash (TensorTy dd) = List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) 0w4 dd        | hash (TensorTy dd) = List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) 0w5 dd
50        | hash (TupleTy tys) = List.foldl (fn (ty, s) => hash ty + s) 0w7 tys        | hash (TupleTy tys) = List.foldl (fn (ty, s) => hash ty + s) 0w7 tys
51        | hash (SeqTy(ty, n)) = Word.fromInt n * hash ty + 0w11        | hash (SeqTy(ty, NONE)) = hash ty + 0w11
52          | hash (SeqTy(ty, SOME n)) = Word.fromInt n * hash ty + 0w13
53        | hash (AddrTy info) = 0w5 + ImageInfo.hash info        | hash (AddrTy info) = 0w5 + ImageInfo.hash info
54        | hash (ImageTy info) = 0w13 * ImageInfo.hash info + 0w6        | hash (ImageTy info) = 0w13 * ImageInfo.hash info + 0w6
55        | hash KernelTy = 0w17        | hash KernelTy = 0w17
       | hash (ImgIndexTy _ )=0w19  
       | hash (IndexTy dd)= List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) 0w23 dd  
       | hash (VectorLengthTy _)=0w29  
       | hash (UnionTy n1)= 0w31  
56    
57      fun toString BoolTy = "bool"      fun toString BoolTy = "bool"
58        | toString StringTy = "string"        | toString StringTy = "string"
59        | toString IntTy = "int"        | toString IntTy = "int"
60        | toString (TensorTy[]) = "real"        | toString (TensorTy[]) = "real"
61        | toString (TensorTy[n1])=String.concat["VecTy<", Int.toString n1, ">"]        | toString (TensorTy dd) = String.concat[
62        | toString (TensorTy dd) = String.concat["tensor[", String.concatWith "," (List.map Int.toString dd), "]"  ]              "tensor[", String.concatWithMap "," Int.toString dd, "]"
63        | toString (TupleTy tys) = String.concat[ "(", String.concatWith " * " (List.map toString tys), ")"]            ]
64        | toString (SeqTy(ty, n)) = concat[toString ty, "SeqTy{", Int.toString n, "}"]        | toString (TupleTy tys) = String.concat[
65                "(", String.concatWithMap " * " toString tys, ")"
66              ]
67          | toString (SeqTy(ty, NONE)) = toString ty ^ "[]"
68          | toString (SeqTy(ty, SOME n)) = concat[toString ty, "[", Int.toString n, "]"]
69        | toString (AddrTy info) = concat["addr(", ImageInfo.toString info, ")"]        | toString (AddrTy info) = concat["addr(", ImageInfo.toString info, ")"]
70        | toString (ImageTy info) = concat["image(", ImageInfo.toString info, ")"]        | toString (ImageTy info) = concat["image(", ImageInfo.toString info, ")"]
71        | toString KernelTy = "kernel"        | toString KernelTy = "kernel"
       | toString (IndexTy []) = "-"  
       | toString (IndexTy dd) = String.concat["Specific Index:[", String.concatWithMap "," Int.toString dd, "]"]  
       | toString (ImgIndexTy dd) = String.concat["ImgSpecificIndex:[", String.concatWithMap "," Int.toString dd, "]"]  
       | toString (VectorLengthTy dd) = String.concat["[", String.concatWithMap "," Int.toString dd, "]"]  
       | toString (UnionTy n1) = String.concat["Unionty", Int.toString n1]  
   
     (*Quick fix*)  
     fun cmp (e1, e2) = String.compare(toString(e1), toString(e2))  
72    
73    end    end

Legend:
Removed from v.3529  
changed lines
  Added in v.3532

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