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 3832 - (download) (annotate)
Fri May 6 15:08:12 2016 UTC (4 years, 1 month ago) by jhr
File size: 4073 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

  (* the layout of a vector onto target-supported vectors. *)
    type vec_layout = {
	wid : int,		(* total width of the vector *)
	padded : bool,		(* true if sum of pieces > wid; pad will be in last piece *)
	pieces : int list	(* list of pieces; these will all be supported vector widths *)
      }

    datatype t
      = BoolTy | StringTy | IntTy | RealTy
      | VecTy of vec_layout		(* 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{wid = n, padded = false, pieces = [n]}
    fun iVecTy 1 = IntTy
      | iVecTy n = SeqTy(IntTy, SOME n)

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

    fun same (BoolTy, BoolTy) = true
      | same (StringTy, StringTy) = true
      | same (IntTy, IntTy) = true
      | same (RealTy, RealTy) = true
      | 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)
      | same (TensorTy dd1, TensorTy dd2) = ListPair.allEq (op =) (dd1, dd2)
      | 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{wid, pieces, ...}) =
	  List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) (0w7 * Word.fromInt wid) pieces
      | hash (TensorTy dd) = List.foldl (fn (d, s) => 0w11 * Word.fromInt d + s) 0w13 dd
      | 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{wid, padded=false, pieces=[_]}) = "vec" ^ Int.toString wid
      | toString (VecTy{wid, pieces, ...}) = String.concat [
            "vec", Int.toString wid, "{", String.concatWithMap ":" Int.toString pieces, "}"
	  ]
      | toString (TensorTy dd) = String.concat [
            "tensor[", String.concatWithMap "," Int.toString dd, "]"
          ]
      | 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