Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

makes dead code elimination less conservative #906

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions plugins/optimization/optimization_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,17 @@ let compute_dead can_touch protected sub =
let defs,uses = computed_def_use sub in
let dead = Set.diff defs uses in
let live v = not (Set.mem dead v) in
(object inherit [Tid.Set.t] Term.visitor
method! enter_def t dead =
let v = Def.lhs t in
if not (can_touch v) || Set.mem protected (Var.base v) || live v
then dead
else Set.add dead (Term.tid t)
end)#visit_sub sub Tid.Set.empty
Term.enum blk_t sub |>
Seq.fold ~init:Tid.Set.empty ~f:(fun dead blk ->
Term.enum ~rev:true def_t blk |>
Seq.fold ~init:(protected,dead) ~f:(fun (protected,dead) def ->
let v = Def.lhs def in
if not (can_touch v) || live v
then (protected,dead)
else if Set.mem protected (Var.base v)
then Set.remove protected (Var.base v), dead
else protected, Set.add dead (Term.tid def)) |>
snd)

let is_alive dead t = not (Set.mem dead (Term.tid t))
let live_phi dead blk = Term.filter phi_t ~f:(is_alive dead) blk
Expand Down