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

SCM Repository

[diderot] View of /branches/vis15/src/compiler/simple/simple.sml
ViewVC logotype

View of /branches/vis15/src/compiler/simple/simple.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3797 - (download) (annotate)
Mon May 2 21:10:12 2016 UTC (3 years, 2 months ago) by jhr
File size: 4568 byte(s)
  Working on merge: clean up tensor slicing/indexing.
(* simple.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.
 *
 * A simplified AST representation of a Diderot program.  This representation has the property
 * that the arguments to ifs, operators, etc. are variables and that the rhs of assignments
 * consist of a single operation.  It is not, however, a single-assignment representation.
 *)

structure Simple =
  struct

    type var = SimpleVar.t

  (* types with the meta variables resolved *)
    type ty = SimpleTypes.ty

  (* resolved meta-variable arguments to basis functions *)
    datatype meta_arg = datatype SimpleTypes.meta_arg

    datatype input_init = datatype Inputs.input_init

    datatype input = datatype Inputs.input

    datatype program = Program of {
        props : Properties.t list,
	consts : var list,		(* constant variables *)
        inputs : var input list,	(* input globals *)
	constInit : block,		(* code that initializes constants and inputs *)
        globals : var list,             (* non-input globals *)
        funcs : func list,
        init : block,
        strand : strand,
        create : create,
	update : block option
      }

    and func = Func of {
        f : var,
        params : var list,
        body : block
      }

    and strand = Strand of {
        name : Atom.atom,
        params : var list,
        state : var list,
        stateInit : block,
	initM : block option,
	updateM : block,
	stabilizeM : block option
      }

  (* initial-strands creation; the stmt will be a loop nest with a "new" as the body *)
    and create = Create of {
	dim : int option,			(* grid dimension; NONE for collections *)
	code : block				(* the loop nest for creating the strands *)
      }

    and block = Block of {
	code : stmt list,			(* the body of the block *)
        props : PropList.holder			(* property list *)
      }

    and stmt
      = S_Var of var * exp option               (* introduce a local variable.  The uninitialized *)
                                                (* form is needed for the results of conditional *)
                                                (* expressions *)
      | S_Assign of var * exp
      | S_IfThenElse of var * block * block
      | S_Foreach of var * var * block
      | S_New of Atom.atom * var list
      | S_Continue
      | S_Die
      | S_Stabilize
      | S_Return of var
      | S_Print of var list
(* FIXME: to support fusion of reductions, we'll have to add tuples or change S_Return
 * to support multiple return values.
 *)
      | S_MapReduce of {			(* parallel map-reduce *)
	    results : var list,			(* the results of reduction phase *)
	    reductions : AST.var list,		(* the reduction operators (one per result) *)
	    body : func,			(* a function that implements map part *)
	    args : var list,			(* the invariant arguments to the map phase *)
	    source : AST.var			(* the set of strands that we map over *)
	  }

    and exp
      = E_Var of var
      | E_Lit of Literal.t
      | E_Select of var * var					(* strand-field selection *)
      | E_Apply of var * var list * ty                          (* user-defined function *)
      | E_Prim of AST.var * meta_arg list * var list * ty       (* Diderot builtin *)
      | E_Tensor of var list * ty
      | E_Seq of var list * ty                                  (* sequence (ty is result type) *)
      | E_Slice of var * int option list * ty                   (* tensor slicing (ty is result type) *)
      | E_Coerce of {srcTy : ty, dstTy : ty, x : var}
      | E_LoadSeq of ty * string
      | E_LoadImage of ty * string * ImageInfo.info

    fun typeOf (E_Var x) = SimpleVar.typeOf x
      | typeOf (E_Lit lit) = (case lit
           of (Literal.Int _) => SimpleTypes.T_Int
            | (Literal.Real _) => SimpleTypes.T_Tensor[]
            | (Literal.String s) => SimpleTypes.T_String
            | (Literal.Bool _) => SimpleTypes.T_Bool
          (* end case *))
      | typeOf (E_Select(_, fld)) = SimpleVar.typeOf fld
      | typeOf (E_Apply(_, _, ty)) = ty
      | typeOf (E_Prim(_, _, _, ty)) = ty
      | typeOf (E_Tensor(_, ty)) = ty
      | typeOf (E_Seq(_, ty)) = ty
      | typeOf (E_Slice(_, _, ty)) = ty
      | typeOf (E_Coerce{dstTy, ...}) = dstTy
      | typeOf (E_LoadSeq(ty, _)) = ty
      | typeOf (E_LoadImage(ty, _, _)) = ty

    fun newProp initFn = PropList.newProp (fn (Block{props, ...}) => props, initFn)
    fun newFlag () = PropList.newFlag (fn (Block{props, ...}) => props)

  end

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