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

SCM Repository

[diderot] View of /branches/vis15/src/compiler/simplify/simplify-vars.sml
ViewVC logotype

View of /branches/vis15/src/compiler/simplify/simplify-vars.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3457 - (download) (annotate)
Mon Nov 23 16:41:51 2015 UTC (4 years, 2 months ago) by jhr
File size: 1678 byte(s)
working on merge
(* simplify-vars.sml
 *
 * This module analyses the use of variables in the Simple AST and rationalizes
 * their use in the following ways:
 *
 *   -- for any strand parameter that is used in a method, we create a shadow state
 *      variable
 *
 *   -- unused constant and global variables are elminated
 *
 *   -- unused strand state variables are eliminated
 *
 *   -- unused local variables are eliminated
 *
 *   -- strand-invariant state variables (except outputs) and expressions are
 *      lifted to global scope
 *
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 *
 * COPYRIGHT (c) 2015 The University of Chicago
 * All rights reserved.
 *)

structure SimplifyVars : sig

    val transform : Simple.program -> Simple.program

  end = struct

    structure S = Simple

  (* analyze an expression using the `doVar` and `doFld`
   * functions to analyze variable uses.
   *)
    fun analyzeExp doVar doFld = let
	  fun anal (env, e) = (case e
		 of S.E_Var x => doVar(x, env)
		  | S.E_Lit _ => env
		  | S.E_Select(x, fld) => doFld (fld, doVar(x, env))
		  | S.E_Apply(f, xs, _) => List.foldl doVar env (f::xs)
		  | S.E_Prim(_, _, xs, _) => List.foldl doVar env xs
		  | S.E_Tensor(xs, _) => List.foldl doVar env xs
		  | S.E_Seq(xs, _) => List.foldl doVar env xs
		  | S.E_Slice(x, indices, _) => let
		      fun doIndex (NONE, env) = env
			| doIndex (SOME ix, env) => doVar(ix, env)
		      in
			doVar (x, List.foldl doIndex env indices)
		      end
		  | S.E_Coerce{x, ...} => doVar(x, env)
		  | S.E_LoadSeq _ => ()
		  | S.E_LoadImage _ => ()
		(* end case *))
	  in
	    anal
	  end

    fun transform prog = prog

  end

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