[MLton-devel] handler and link liveness in backend/live.fun
Stephen Weeks
MLton@mlton.org
Tue, 31 Dec 2002 11:45:33 -0800
I am confused about the following code in live.fun.
(* handler code and link slots are harder; in particular, they don't
* satisfy the SSA invariant -- there are multiple definitions;
* furthermore, a def and use in a block does not mean that the def
* occurs before the use. But, a back propagated use will always
* come after a def in the same block
*)
fun handlerLink (defuse, sel) =
let
val todo: LiveInfo.t list ref = ref []
val defs =
List.foldr
(!defuse, [],
fn (Def b, defs) => b::defs
| (Use (b as LiveInfo.T {liveHS, ...}), defs) =>
if List.exists (defs, fn b' => LiveInfo.equals (b, b'))
then defs
else (sel liveHS := true
; List.push (todo, b)
; defs))
I am guessing that the foldr is important because earlier in live.fun
the statements in each block were visited in order, meaning that the
earlier statements appear later in !defuse. Hence, with the foldr,
the defs and uses are visited in order for each block. This means
that by doing "List.exists (defs, ...", we are considering all of the
earlier definitions in the block, if any. What I don't understand is
that since we are visiting all of the statements in the block
together, in order, aren't we guaranteed that if there is a prior
definition then it will be first on the defs list? So, can I replace
the "List.exists (defs, ..." with
case defs of
[] => false
| b' :: _ => LiveInfo.equals (b, b')
The efficiency gain would be nice, but I am more concerned about my
understanding of the code, since I am modifying it.
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
MLton-devel mailing list
MLton-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlton-devel