open LTL
let compress entry graph =
let points =
Label.Map.mapi (fun label _ ->
UnionFind.fresh label
) graph
in
let lookup label =
try
Label.Map.find label points
with Not_found ->
assert false
in
Label.Map.iter (fun source i ->
let source = lookup source in
match i with
| IGoto target ->
let target = lookup target in
if UnionFind.equivalent source target then
assert false
else
UnionFind.union source target
| _ ->
()
) graph;
let rep label =
UnionFind.find (lookup label)
in
rep entry, Label.Map.map (function
| INewFrame l ->
INewFrame (rep l)
| IDeleteFrame l ->
IDeleteFrame (rep l)
| IGetStack (r, s, l) ->
IGetStack (r, s, rep l)
| ISetStack (s, r, l) ->
ISetStack (s, r, rep l)
| IConst (r, k, l) ->
IConst (r, k, rep l)
| IUnOp (op, r1, r2, l) ->
IUnOp (op, r1, r2, rep l)
| IBinOp (op, r1, r2, r3, l) ->
IBinOp (op, r1, r2, r3, rep l)
| ICall (c, l) ->
ICall (c, rep l)
| ILoad (r1, r2, o, l) ->
ILoad (r1, r2, o, rep l)
| IStore (r1, o, r2, l) ->
IStore (r1, o, r2, rep l)
| IGoto l ->
IGoto (rep l)
| IUnBranch (c, r, l1, l2) ->
IUnBranch (c, r, rep l1, rep l2)
| IBinBranch (c, r1, r2, l1, l2) ->
IBinBranch (c, r1, r2, rep l1, rep l2)
| IReturn ->
IReturn
| ITailCall callee ->
ITailCall callee
) graph