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

SCM Repository

[diderot] View of /branches/vis15/src/compiler/low-to-tree/unify-vars.sml
ViewVC logotype

View of /branches/vis15/src/compiler/low-to-tree/unify-vars.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3834 - (download) (annotate)
Sat May 7 18:39:53 2016 UTC (3 years, 4 months ago) by jhr
File size: 1398 byte(s)
working on merge
(* unify-vars.sml
 *
 * Determine the equivalence classes of local variables.  Given two local
 * variables x and y, if the CFG has either an assignment node "x = y" or
 * a JOIN node with "x = phi(..., y, ...)", then x and y are in the same
 * equivalence class.
 *
 * 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 UnifyVars : sig

    val analyze : LowIR.cfg -> unit

  (* if a local variable is in an equivalence class with other variables, then return
   * the representative member of the class.
   *)
    val eqClassOf : LowIR.var -> LowIR.var option

  end = struct

    structure IR = LowIR

    val {peekFn, setFn, getFn, ...} = IR.Var.newProp URef.uRef

    fun analyze cfg = let
	  fun doPhi (x, ys) = let
		val xRep = getFn x
		fun doVar NONE = ()
		  | doVar (SOME y) = ignore (URef.union(xRep, getFn y))
		in
		  List.app doVar ys
		end
	  fun doNode nd = (case IR.Node.kind nd
		 of IR.JOIN{phis, ...} => List.app doPhi (!phis)
		  | IR.FOREACH{phis, ...} => List.app doPhi (!phis)
		  | IR.ASSIGN{stm = (x, IR.VAR y), ...} => ignore (URef.union(getFn x, getFn y))
		  | _ => ()
		(* end case *))
	  in
	    IR.CFG.apply doNode cfg
	  end

    fun eqClassOf x = (case peekFn x
	   of NONE => NONE
	    | SOME u => SOME(URef.!! u)
	  (* end case *))

  end

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