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

SCM Repository

[diderot] View of /branches/vis15/src/compiler/mid-to-low/field-to-low.sml
ViewVC logotype

View of /branches/vis15/src/compiler/mid-to-low/field-to-low.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3727 - (download) (annotate)
Wed Apr 6 18:35:46 2016 UTC (3 years, 5 months ago) by jhr
File size: 2550 byte(s)
  working on merge
(* field-to-low.sml
 *
 * NOTE: this code will need to be changed if we ever want to support different kernels
 * for different axes
 *
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 *
 * COPYRIGHT (c) 2016 The University of Chicago
 * All rights reserved.
 *)

structure FieldToLow : sig

  (* expand a MidIR probe to LowIR code.  The arguments are:
   *
   *    avail  -- available LowIR assignments
   *    mapp   -- mapping from iteration indices to deBruijn indices
   *    sx     -- summation bounds
   *    prod   -- body of summation, which is a product of Ein expressions
   *    params -- the formal parameters of the enclosing Ein expression
   *    args   -- the actual arguments of the enclosing Ein expression
   *)
    val expand : {
	    avail : AvailRHS.t,
	    mapp : int IntRedBlackMap.map,
	    sx : Ein.sumrange list,
	    prod : ein_exp list,
	    params : Ein.param_kind list,
	    args : LowIR.var list
	  }  -> LowIR.var

  end = struct

    structure IR = LowIR
    structure Ty = LowTypes
    structure Op = LowOps
    structure Var = LowIR.Var
    structure E = Ein
    structure Mk = MkLowIR
    structure IMap = IntRedBlackMap

  (* partition expressions into image and kernel expressions *)
    fun partition (E.Img img :: (kexps as k1::rest)) = let
	  fun stripK (E.Krn k) = k
	    | stripK _ = raise Fail "expected kernel"
	  val k1 = stripK k1
	  val rest = List.map stripK rest
	  in
	    (img, k1, k1::rest)
	  end
      | partition _ = raise Fail "missing image/kernel"

  (* get the image and kernel arguments. *)
    fun getArgs (args, (imgId, _, _), (kernId, _, _)) = let
	  val imgArg = List.nth(args, imgId)
	  val imgInfo = (case IR.Var.getDef ()
		 of IR.OP(Op.LoadImage(Ty.ImageTy img, _), _) => img
		  | IR.GLOBAL gv => raise Fail "FIXME: input variable"
		  | _ => raise Fail "unable to get image argument"
		(* end case *))
	  val h = (case IR.Var.getDef (List.nth(args, kernId))
		 of IR.OP(Op.Kernel h) => h
		  | _ => raise Fail "unable to get kernel argument"
		(* end case *))
	  in
	    (imgArg, imgInfo, h)
	  end

  (* expand a MidIR probe to LowIR code. *)
    fun expand {avail, mapp, sx, prod, params, args} = let
	  val (img, k1, kexps) = partition prod
	  val (imgArg, imgInfo, h) = getArgs (args, img, k1)
	(* get the outermost index; note that the (lb, ub) will be the same for all
         * of the indices, since the same kernel (and support) is used for all axes.
	 *)
	  val (E.V sid, lb, ub) :: _ = sx
	  in
raise Fail "FIXME"
	  end

  end

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