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

Loading…
Cancel
Save