SCM Repository
View of /trunk/src/compiler/IL/census-fn.sml
Parent Directory
|
Revision Log
Revision 341 -
(download)
(annotate)
Mon Sep 13 17:14:24 2010 UTC (11 years, 9 months ago) by jhr
File size: 2427 byte(s)
Mon Sep 13 17:14:24 2010 UTC (11 years, 9 months ago) by jhr
File size: 2427 byte(s)
Implementing the census functor
(* census-fn.sml * * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu) * All rights reserved. * * Compute use counts for IL variables. *) functor CensusFn (IL : SSA) : sig structure IL : SSA val init : IL.program -> unit val inc : IL.var -> unit end = struct structure IL = IL fun inc (IL.V{useCnt, ...}) = (useCnt := !useCnt + 1) fun init (IL.Program{globals, globalInit, actors}) = let fun clearVar (IL.V{useCnt, ...}) = useCnt := 0 (* clear the counts of the variables defined in a node *) fun clearNode (IL.ND{kind, ...}) = (case kind of IL.JOIN{phis, ...} => List.app (fn (x, _) => clearVar x) (!phis) | IL.BLOCK{body, ...} => List.app (fn (x, _) => clearVar x) (!body) | _ => () (* end case *)) (* clear the counts of the variables defined in an actor *) fun clearActor (IL.Actor{params, state, stateInit, methods, ...}) = let fun clearMethod (IL.Method{stateIn, body, ...}) = ( List.app clearVar stateIn; IL.applyToNodes clearNode body) in List.app clearVar params; List.app clearVar state; IL.applyToNodes clearNode stateInit; List.app clearMethod methods end (* increment the use counts of a list of variables *) val incList = List.app inc (* increment the counts of the variables used in a node *) fun incNode (IL.ND{kind, ...}) = (case kind of IL.JOIN{phis, ...} => List.app (fn (_, xs) => incList xs) (!phis) | IL.COND{cond, ...} => inc cond | IL.BLOCK{body, ...} => let fun incRHS (IL.VAR x) = inc x | incRHS (IL.LIT _) = () | incRHS (IL.OP(_, args)) = incList args | incRHS (IL.CONS args) = incList args in List.app (fn (_, rhs) => incRHS rhs) (!body) end | IL.NEW{args, ...} => incList args | _ => () (* end case *)) (* increment the counts of the variables used in an actor *) fun incActor (IL.Actor{params, state, stateInit, methods, ...}) = let fun incMethod (IL.Method{stateOut, body, ...}) = ( incList stateOut; IL.applyToNodes incNode body) in IL.applyToNodes incNode stateInit; List.app incMethod methods end in (* first clear the counts of all variables *) List.app clearVar globals; IL.applyToNodes clearNode globalInit; List.app clearActor actors; (* then count uses *) IL.applyToNodes incNode globalInit; List.app incActor actors end end
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |