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

SCM Repository

[diderot] View of /trunk/src/compiler/high-il/high-opt.sml
ViewVC logotype

View of /trunk/src/compiler/high-il/high-opt.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 287 - (download) (annotate)
Fri Aug 13 21:40:04 2010 UTC (9 years ago) by jhr
File size: 1785 byte(s)
  new files
(* high-opt.sml
 *
 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
 * All rights reserved.
 *
 * Optimization of the HighIL representation of Diderot terms.  The main
 * task of this phase is to statically resolve field definitions.
 *)

structure HighOptimizer : sig

    val optimize : HighIL.program -> HighIL.program

  end = struct

    structure IL = HighIL
    structure Op = IL.Op
    structure V = IL.Var

    datatype binding
      = Unknown
      | OP of Op.rator * IL.var list

  (* decrement a variable's use count *)
    fun decUse (IL.V{useCnt, ...}) = (useCnt := !useCnt - 1)

    val {getFn=getBinding, setFn=setBinding, clrFn=clrBinding, ...}
	  = V.newProp (fn _ => Unknown)

  (* optimize the rhs of an assignment, returning NONE if there is no change *)
    fun doAssignment rhs = (case rhs
	   of IL.OP(Op.Convolve, [v, h]) => (case (getBinding v, getBinding h)
		 of ((Op.LoadImage v', []), (Op.Kernel h', [])) => (
		      decUse v; decUse h;
		      SOME(IL.Op(Op.Field(F.convolve(v', h')), [])))
		  | _ => raise Fail "non-constant Convolve"
		(* end case *))
	    | IL.OP(Op.AddField, [f, g]) => (case (getBinding f, getBinding g)
		 of ((Op.Field f', []), (Op.Field g', [])) => (
		      decUse f; decUse g;
		      SOME(IL.Op(Op.Field(F.SUM(f, g)), [])))
		  | _ => NONE
		(* end case *))
	    | IL.OP(Op.NegField, [f]) => (case (getBinding f)
		 of (Op.Field f', []) => (
		      decUse f';
		      SOME(IL.Op(Op.Field(F.neg f'), [])))
		  | _ => NONE
		(* end case *))
	    | IL.OP(Op.DiffField, [f]) => (case (getBinding f)
		 of (Op.Field f', []) => (
		      decUse f';
		      SOME(IL.Op(Op.Field(F.diff f'), [])))
		  | _ => raise Fail "non-constant DiffField"
		(* end case *))
	    | _ => NONE
	  (* end case *))

  end

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