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

SCM Repository

[diderot] View of /trunk/src/compiler/IL/forward-dfa-fn.sml
ViewVC logotype

View of /trunk/src/compiler/IL/forward-dfa-fn.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 258 - (download) (annotate)
Mon Aug 9 18:36:44 2010 UTC (9 years ago) by jhr
File size: 1480 byte(s)
  Added BackwardDFAFn functor
(* forward-dfa-fn.sml
 *
 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
 * All rights reserved.
 *
 * Forward data-flow analysis for IL code.
 *)

functor ForwardDFAFn (D : DOMAIN) :> sig

    structure D : DOMAIN

  (* abstract representation of analysis results *)
    type result

  (* given the entry value and root statement, do the forward DFA on the CFG *)
    val analyse : D.t * D.IL.stmt -> result

  (* get result for a node *)
    val outValue : result * D.IL.node -> D.t

  (* scrub results to reclaim space *)
    val scrub : result -> unit

  end = struct

    structure D = D
    structure IL = D.IL

    type result = IL.node list

    val {setFn, getFn, clrFn, ...} =
	  PropList.newProp (fn (IL.ND{props, ...}) => props, fn _ => D.bottom)

    fun analyse (entryVal, stm) = let
	  val _ = setFn(IL.Stmt.entry stm, entryVal)
	(* use reverse DFS order to get quicker convergence *)
	  val nodes = List.rev (IL.sortNodes stm)
	  fun iterate () = let
		val anyChange = ref false
		fun doNode nd = let
		      val inValue = D.join (List.map getFn (IL.Node.preds nd))
		      val outValue = D.transfer (inValue, nd)
		      in
			if D.same(getFn nd, outValue)
			  then ()
			  else (setFn(nd, outValue); anyChange := true)
		      end
		in
		  List.app doNode nodes;
		  if !anyChange then iterate() else ()
		end
	  in
	    iterate (); nodes
	  end

    fun outValue (_, nd) = getFn nd

    fun scrub nodes = List.app clrFn nodes

  end

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