[sledge] Preserve sharing of Func.parent

Summary:
Previously the locals of a function were computed after backpatching
the blocks in its cfg. This resulted in loss of sharing, and incorrect
locals if queried through the parent of a block.

Reviewed By: kren1

Differential Revision: D15738027

fbshipit-source-id: d7e70530a
master
Josh Berdine 6 years ago committed by Facebook Github Bot
parent 2d69e17d51
commit 2440ee69ae

@ -397,6 +397,7 @@ module Func = struct
let invariant func =
Invariant.invariant [%here] func [%sexp_of: t]
@@ fun () ->
assert (func == func.entry.parent) ;
let {name= {typ}; cfg} = func in
match typ with
| Pointer _ ->
@ -416,6 +417,11 @@ module Func = struct
let find functions name = Map.find functions name
let mk ~name ~entry ~cfg =
let locals =
Vector.fold ~init:entry.locals cfg ~f:(fun locals block ->
Set.union locals block.locals )
in
let entry = {entry with locals} in
let func = {name; entry; cfg} in
let resolve_parent_and_jumps block =
block.parent <- func ;
@ -434,12 +440,8 @@ module Func = struct
| Return _ | Throw _ | Unreachable -> ()
in
resolve_parent_and_jumps entry ;
let locals =
Vector.fold ~init:entry.locals cfg ~f:(fun locals block ->
resolve_parent_and_jumps block ;
Set.union locals block.locals )
in
{func with entry= {entry with locals}} |> check invariant
Vector.iter cfg ~f:resolve_parent_and_jumps ;
func |> check invariant
let mk_undefined ~name ~params =
let entry =

Loading…
Cancel
Save