Skip to content

Commit b13ff9b

Browse files
committed
Compiler: small cleanup
1 parent b3c1a8c commit b13ff9b

File tree

2 files changed

+33
-32
lines changed

2 files changed

+33
-32
lines changed

compiler/lib/deadcode.ml

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,8 @@ let rec add_arg_dep defs params args =
219219
| _ -> assert false
220220

221221
let add_cont_dep blocks defs (pc, args) =
222-
match try Some (Addr.Map.find pc blocks) with Not_found -> None with
223-
| Some block -> add_arg_dep defs block.params args
224-
| None -> () (* Dead continuation *)
222+
let block = Addr.Map.find pc blocks in
223+
add_arg_dep defs block.params args
225224

226225
let empty_body b =
227226
match b with
@@ -329,35 +328,37 @@ let f ({ blocks; _ } as p : Code.program) =
329328
in
330329
mark_reachable st p.start;
331330
if debug () then Print.program Format.err_formatter (fun pc xi -> annot st pc xi) p;
332-
let all_blocks = blocks in
333-
let blocks =
334-
Addr.Map.filter_map
335-
(fun pc block ->
336-
if not (BitSet.mem st.reachable_blocks pc)
337-
then (
338-
st.deleted_blocks <- st.deleted_blocks + 1;
339-
None)
340-
else
341-
Some
342-
{ params = List.filter block.params ~f:(fun x -> st.live.(Var.idx x) > 0)
343-
; body =
344-
List.fold_left block.body ~init:[] ~f:(fun acc i ->
345-
match i, acc with
346-
| Event _, Event _ :: prev ->
347-
(* Avoid consecutive events (keep just the last one) *)
348-
i :: prev
349-
| _ ->
350-
if live_instr st i
351-
then filter_closure all_blocks st i :: acc
352-
else (
353-
st.deleted_instrs <- st.deleted_instrs + 1;
354-
acc))
355-
|> List.rev
356-
; branch = filter_live_last all_blocks st block.branch
357-
})
358-
blocks
331+
let p =
332+
let all_blocks = blocks in
333+
let blocks =
334+
Addr.Map.filter_map
335+
(fun pc block ->
336+
if not (BitSet.mem st.reachable_blocks pc)
337+
then (
338+
st.deleted_blocks <- st.deleted_blocks + 1;
339+
None)
340+
else
341+
Some
342+
{ params = List.filter block.params ~f:(fun x -> st.live.(Var.idx x) > 0)
343+
; body =
344+
List.fold_left block.body ~init:[] ~f:(fun acc i ->
345+
match i, acc with
346+
| Event _, Event _ :: prev ->
347+
(* Avoid consecutive events (keep just the last one) *)
348+
i :: prev
349+
| _ ->
350+
if live_instr st i
351+
then filter_closure all_blocks st i :: acc
352+
else (
353+
st.deleted_instrs <- st.deleted_instrs + 1;
354+
acc))
355+
|> List.rev
356+
; branch = filter_live_last all_blocks st block.branch
357+
})
358+
blocks
359+
in
360+
{ p with blocks }
359361
in
360-
let p = { p with blocks } in
361362
let p = remove_empty_blocks st p in
362363
if times () then Format.eprintf " dead code elim.: %a@." Timer.print t;
363364
if stats ()

dune-workspace

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
(runtest_alias runtest-wasm))
88
(js_of_ocaml
99
;; enable for debugging
10-
;; (flags (:standard --debug stats-debug))
10+
;; (flags (:standard --debug stats-debug --debug invariant))
1111
(runtest_alias runtest-js))))

0 commit comments

Comments
 (0)