[hoisting] Make invalidation stop at already explored (var,node) pairs

Reviewed By: mbouaziz

Differential Revision: D12957025

fbshipit-source-id: b51f81966
master
Ezgi Çiçek 6 years ago committed by Facebook Github Bot
parent ff722f975d
commit d5a2198010

@ -102,18 +102,28 @@ let get_vars_in_loop loop_nodes =
loop_nodes VarsInLoop.empty loop_nodes VarsInLoop.empty
module ProcessedPair = struct
type t = Var.t * Procdesc.Node.t [@@deriving compare]
end
module ProcessedPairSet = Caml.Set.Make (ProcessedPair)
(* get all the ptr variables (and their dependencies) occurring on the (* get all the ptr variables (and their dependencies) occurring on the
RHS of the definition of a given variable. *) RHS of the definition of a given variable. *)
let get_ptr_vars_in_defn_path node loop_head var = let get_ptr_vars_in_defn_path node loop_head var =
let rec aux node var = let rec aux node var processed_pairs =
if ProcessedPairSet.mem (var, node) processed_pairs then InvalidatedVars.empty
else
let invalidate_exp exp_rhs init = let invalidate_exp exp_rhs init =
let node_list =
node :: (if Procdesc.Node.equal node loop_head then [] else Procdesc.Node.get_preds node)
in
let processed_pairs' = ProcessedPairSet.add (var, node) processed_pairs in
Var.get_all_vars_in_exp exp_rhs Var.get_all_vars_in_exp exp_rhs
|> Sequence.fold ~init ~f:(fun acc var -> |> Sequence.fold ~init ~f:(fun acc rhs_var ->
List.fold_left ~init:(InvalidatedVars.add var acc) List.fold_left ~init:(InvalidatedVars.add rhs_var acc)
~f:(fun acc node -> InvalidatedVars.union (aux node var) acc) ~f:(fun acc node -> InvalidatedVars.union (aux node rhs_var processed_pairs') acc)
( node node_list )
:: (if Procdesc.Node.equal node loop_head then [] else Procdesc.Node.get_preds node)
) )
in in
Procdesc.Node.get_instrs node Procdesc.Node.get_instrs node
|> Instrs.fold ~init:InvalidatedVars.empty ~f:(fun acc instr -> |> Instrs.fold ~init:InvalidatedVars.empty ~f:(fun acc instr ->
@ -127,7 +137,7 @@ let get_ptr_vars_in_defn_path node loop_head var =
| _ -> | _ ->
acc ) acc )
in in
aux node var aux node var ProcessedPairSet.empty
let get_vars_to_invalidate node loop_head params invalidated_vars : InvalidatedVars.t = let get_vars_to_invalidate node loop_head params invalidated_vars : InvalidatedVars.t =

@ -13,4 +13,17 @@ class HoistInvalidate<T extends Tree> {
void loop_over_sun_list_dont_hoist(List<T> list) { void loop_over_sun_list_dont_hoist(List<T> list) {
for (List<T> item = list; item.nonEmpty(); item = item.tail) {} for (List<T> item = list; item.nonEmpty(); item = item.tail) {}
} }
class Item {
public Item next;
public void while_dont_hoist(Item in1, Item in2) {
while (in1.next != null) {
in1 = in1.next;
if (in1.equals(in2)) {}
}
}
}
} }

Loading…
Cancel
Save