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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3828 - (download) (annotate)
Thu May 5 19:55:46 2016 UTC (3 years ago) by jhr
File size: 3796 byte(s)
  Working on merge
(* tree-types.sml
 *
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 *
 * COPYRIGHT (c) 2015 The University of Chicago
 * All rights reserved.
 *
 * Types for the TreeIR.  For now, these are identical to the LowIR types.
 *)

structure TreeTypes =
  struct

    datatype t
      = BoolTy | StringTy | IntTy | RealTy
      | VecTy of int * bool * int list	(* vectors have a width and a representation that
					 * is spread across hardware-supported vectors.
					 * The boolean is true if the type is padded out.
					 *)
      | TensorTy of int list		(* in-memory tensor type.  For 0th order and 1st
					 * order tensors, the local-variable types will
					 * be RealTy and VecTy (resp.).
					 *)
      | TupleTy of t list               (* tuples; used for multiple return values *)
      | SeqTy of t * int option
      | AddrTy of ImageInfo.info        (* voxel address *)
      | ImageTy of ImageInfo.info

    val intTy = IntTy
    val realTy = RealTy
    fun vecTy 1 = RealTy
      | vecTy n = VecTy(n, false, [n])
    fun iVecTy 1 = IntTy
      | iVecTy n = SeqTy(IntTy, SOME n)

  (* smart constructor for tensor type that prunes out dimensions with size 1 *)
    fun tensorTy (1, ty) = ty
      | tensorTy arg = TensorTy arg

  (* is a type a composite-vector type? *)
    fun isCompVecTy (VecTy(_, _, _::_::_)) = true
      | isCompVecTy _ = false

    fun same (BoolTy, BoolTy) = true
      | same (StringTy, StringTy) = true
      | same (IntTy, IntTy) = true
      | same (RealTy, RealTy) = true
      | same (VecTy(d1, b1, vs1), VecTy(d2, b2, vs2)) =
	  (d1 = d2) andalso (b1 = b2) andalso ListPair.allEq (op =) (vs1, vs2)
      | same (TensorTy(d1, ty1), TensorTy(d2, ty2)) = (d1 = d2) andalso same(ty1, ty2)
      | same (TupleTy tys1, TupleTy tys2) = ListPair.allEq same (tys1, tys2)
      | same (SeqTy(ty1, NONE), SeqTy(ty2, NONE)) = 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)
      | same (ImageTy info1, ImageTy info2) = ImageInfo.sameShape(info1, info2)
      | same _ = false

    fun hash BoolTy = 0w1
      | hash StringTy = 0w2
      | hash IntTy = 0w3
      | hash RealTy = 0w5
      | hash (VecTy(d, _, vs)) =
	  List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) (0w7 * Word.fromInt d) vs
      | hash (TensorTy(d, ty)) = 0w13 * (Word.fromInt d + hash ty)
      | hash (TupleTy tys) = List.foldl (fn (ty, s) => hash ty + s) 0w17 tys
      | hash (SeqTy(ty, NONE)) = hash ty + 0w19
      | hash (SeqTy(ty, SOME n)) = Word.fromInt n * hash ty + 0w23
      | hash (AddrTy info) = 0w37 + ImageInfo.hash info
      | hash (ImageTy info) = 0w41 * ImageInfo.hash info + 0w6

    fun toString BoolTy = "bool"
      | toString StringTy = "string"
      | toString IntTy = "int"
      | toString RealTy = "real"
      | toString (VecTy(d, _, [_])) = "vec" ^ Int.toString d
      | toString (VecTy(d, _, vs)) = String.concat [
            "vec", Int.toString d, "{", String.concatWithMap ":" Int.toString vs, "}"
	  ]
      | toString (TensorTy(d, ty)) = String.concat [
            "tensor(", Int.toString d, ",", toString ty, ")"
          ]
      | toString (TupleTy tys) = String.concat [
            "(", String.concatWithMap " * " toString tys, ")"
          ]
      | toString (SeqTy(ty, NONE)) = toString ty ^ "[]"
      | toString (SeqTy(ty, SOME n)) = concat[toString ty, "[", Int.toString n, "]"]
      | toString (AddrTy info) = concat["addr(", ImageInfo.toString info, ")"]
      | toString (ImageTy info) = concat["image(", ImageInfo.toString info, ")"]

    structure Tbl = HashTableFn (
      struct
        type hash_key = t
	val hashVal = hash
	val sameKey = same
      end)

  end

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