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

SCM Repository

[diderot] View of /branches/vis12-cl/src/compiler/codegen/classify-state.sml
ViewVC logotype

View of /branches/vis12-cl/src/compiler/codegen/classify-state.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2402 - (download) (annotate)
Sat Jul 27 13:55:03 2013 UTC (5 years, 10 months ago) by jhr
File size: 1959 byte(s)
  Create branch for adding OpenCL to vis12 branch.  Based on r2401 of the vis12 branch.
(* classify-state.sml
 *
 * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *
 * Classify strand state variables into three categories:
 *
 *	UNIFORM		-- these have the same value for all strands
 *	INVARIANT	-- does not change over the life of the strand
 *	VARYING		-- varies from step to step
 *
 * UNIFORM variables can be lifted into the global name space, while INVARIANT variables
 * can be lifted into the non-varying state.
 *)

structure ClassifyState : sig

    datatype state_var_class = UNIFORM | INVARIANT | VARYING

  (* get the classification of a state variable *)
    val varClass : LowIL.var -> state_var_class

  end = struct

    structure IL = LowIL
    structure V = IL.Var

    datatype state_var_class = UNIFORM | INVARIANT | VARYING

  (* property for state variable classification *)
    val {getFn = varClass : V.var -> state_var_class, setFn = setClass, ...} =
	  V.newProp (fn x => raise Fail(V.toString x ^ " not a state variable"))

    fun join (UNIFORM, cls) = cls
      | join (cls, UNIFORM) = cls
      | join (INVARIANT, cls) = cls
      | join (cls, INVARIANT) = cls
      | join (VARYING, VARYING) = VARYING

    fun analyseCFG () = let
	  val anyChange = ref false
	  fun mark (x, cls) = (case (varClass x, cls)
		 of (UNIFORM, cls) => (setClass(x, cls); anyChange := true)
		  | (INVARIANT, VARYING) => (setClass(x, cls); anyChange := true)
		  | _ => () (* no change *)
		(* end case *))
	  fun loopToFixPt () = (
		anyChange := false;
		analyse();
		if (! anyChange)
		  then loopToFixPt ()
		  else ())
	  in
	    loopToFixPt ()
	  end

  (* analyse a strand *)
    fun analyseStrand (IL.Strand{name, params, state, stateInit, methods}) = let
	  in
	  (* initially, we mark all state variables as UNIFORM and parameters as INVARIANT *)
	    List.app (fn x => setClass(x, UNIFORM)) state;
	    List.app (fn x => setClass(x, INVARIANT)) params;
	  end

  end

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