[sledge] Change Llair representation of functions to a String map

Summary:
Using a type of keys richer than strings, which are the unique symbol
names at the C/LLVM level, is unnecessary.

Reviewed By: ngorogiannis

Differential Revision: D17665262

fbshipit-source-id: 6b8c31146
master
Josh Berdine 5 years ago committed by Facebook Github Bot
parent 6aaeaba104
commit 0c04ecc9aa

@ -479,8 +479,7 @@ module Make (Dom : Domain_sig.Dom) = struct
let harness : exec_opts -> Llair.t -> (int -> Work.t) option = let harness : exec_opts -> Llair.t -> (int -> Work.t) option =
fun opts pgm -> fun opts pgm ->
let entry_points = Config.find_list "entry-points" in let entry_points = Config.find_list "entry-points" in
List.find_map entry_points ~f:(fun name -> List.find_map ~f:(Llair.Func.find pgm.functions) entry_points
Llair.Func.find pgm.functions (Var.program ~global:() name) )
|> function |> function
| Some {name= {var}; locals; params= []; entry} -> | Some {name= {var}; locals; params= []; entry} ->
Some Some

@ -45,7 +45,7 @@ module type Dom = sig
val dnf : t -> t list val dnf : t -> t list
val resolve_callee : val resolve_callee :
(Var.t -> Llair.func list) -> Exp.t -> t -> Llair.func list * t (string -> Llair.func list) -> Exp.t -> t -> Llair.func list * t
type summary type summary

@ -28,9 +28,9 @@ let post _ _ () = ()
let retn _ _ _ _ = () let retn _ _ _ _ = ()
let dnf () = [()] let dnf () = [()]
let resolve_callee lookup ptr () = let resolve_callee lookup ptr _ =
match Var.of_exp ptr with match Var.of_exp ptr with
| Some callee_name -> (lookup callee_name, ()) | Some callee -> (lookup (Var.name callee), ())
| None -> ([], ()) | None -> ([], ())
type summary = unit type summary = unit

@ -67,7 +67,7 @@ let call ~summaries:_ ~globals:_ actuals _ _ ~locals:_ st =
let resolve_callee lookup ptr st = let resolve_callee lookup ptr st =
let st = used_globals ~init:st ptr in let st = used_globals ~init:st ptr in
match Var.of_exp ptr with match Var.of_exp ptr with
| Some callee_name -> (lookup callee_name, st) | Some callee -> (lookup (Var.name callee), st)
| None -> ([], st) | None -> ([], st)
(* A function summary is the set of global variables accessed by that (* A function summary is the set of global variables accessed by that

@ -121,7 +121,7 @@ let sexp_of_func {name; params; freturn; fthrow; locals; entry; cfg} =
let compare_block x y = Int.compare x.sort_index y.sort_index let compare_block x y = Int.compare x.sort_index y.sort_index
let equal_block x y = Int.equal x.sort_index y.sort_index let equal_block x y = Int.equal x.sort_index y.sort_index
type functions = func Var.Map.t [@@deriving sexp_of] type functions = func Map.M(String).t [@@deriving sexp_of]
type t = {globals: Global.t vector; functions: functions} type t = {globals: Global.t vector; functions: functions}
[@@deriving sexp_of] [@@deriving sexp_of]
@ -551,7 +551,9 @@ let set_derived_metadata functions =
jump els jump els
| Iswitch {tbl; _} -> Vector.iter tbl ~f:jump | Iswitch {tbl; _} -> Vector.iter tbl ~f:jump
| Call ({callee; return; throw; _} as call) -> | Call ({callee; return; throw; _} as call) ->
( match Var.of_exp callee >>= Func.find functions with ( match
Var.of_exp callee >>| Var.name >>= Func.find functions
with
| Some func -> | Some func ->
if Set.mem ancestors func.entry then call.recursive <- true if Set.mem ancestors func.entry then call.recursive <- true
else visit ancestors func func.entry else visit ancestors func func.entry
@ -579,8 +581,10 @@ let set_derived_metadata functions =
(Vector.to_array cfg) ) (Vector.to_array cfg) )
in in
let functions = let functions =
List.fold functions ~init:Var.Map.empty ~f:(fun m func -> List.fold functions
Map.add_exn m ~key:func.name.var ~data:func ) ~init:(Map.empty (module String))
~f:(fun m func ->
Map.add_exn m ~key:(Var.name func.name.var) ~data:func )
in in
let roots = compute_roots functions in let roots = compute_roots functions in
let tips_to_roots = topsort functions roots in let tips_to_roots = topsort functions roots in

@ -191,7 +191,7 @@ module Func : sig
val mk_undefined : name:Global.t -> params:Var.t list -> t val mk_undefined : name:Global.t -> params:Var.t list -> t
val find : functions -> Var.t -> func option val find : functions -> string -> func option
(** Look up a function of the given name in the given functions. *) (** Look up a function of the given name in the given functions. *)
val is_undefined : func -> bool val is_undefined : func -> bool

@ -151,10 +151,10 @@ let retn formals freturn {areturn; subst; frame} q =
|> |>
[%Trace.retn fun {pf} -> pf "%a" pp] [%Trace.retn fun {pf} -> pf "%a" pp]
let resolve_callee lookup ptr st = let resolve_callee lookup ptr q =
match Var.of_exp ptr with match Var.of_exp ptr with
| Some callee_name -> (lookup callee_name, st) | Some callee -> (lookup (Var.name callee), q)
| None -> ([], st) | None -> ([], q)
type summary = {xs: Var.Set.t; foot: t; post: t} type summary = {xs: Var.Set.t; foot: t; post: t}

Loading…
Cancel
Save