Skip to content

Small cleanup #2024

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

Merged
merged 3 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
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
5 changes: 0 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@ jobs:
with:
ocaml-compiler: ${{ matrix.ocaml-compiler }}

# Pin Dune to a version which supports the new --effects flag
# (https://github.com/ocaml/dune/pull/11222).
- name: Pin Dune
run: opam pin add --no-action dune https://github.com/hhugo/dune.git#jsoo-effects

# Work-around a race between reinstalling mingw-w64-shims
# (because of conf-pkg-config optional dep) and installing other
# packages that implicitly depend on mingw-w64-shims.
Expand Down
3 changes: 1 addition & 2 deletions compiler/lib/deadcode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -391,14 +391,13 @@ let remove_empty_blocks st (p : Code.program) : Code.program =
in
{ p with blocks }

let f ({ blocks; _ } as p : Code.program) =
let f pure_funs ({ blocks; _ } as p : Code.program) =
let previous_p = p in
Code.invariant p;
let t = Timer.make () in
let nv = Var.count () in
let defs = Array.make nv [] in
let live = Array.make nv 0 in
let pure_funs = Pure_fun.f p in
Addr.Map.iter
(fun _ block ->
List.iter block.body ~f:(fun i ->
Expand Down
2 changes: 1 addition & 1 deletion compiler/lib/deadcode.mli
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
type variable_uses =
int array (* For each variable, indicates how many times it is used. *)

val f : Code.program -> Code.program * variable_uses
val f : Pure_fun.t -> Code.program -> Code.program * variable_uses

val remove_unused_blocks : Code.program -> Code.program

Expand Down
10 changes: 6 additions & 4 deletions compiler/lib/driver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ let tailcall p =

let deadcode' p =
if debug () then Format.eprintf "Dead-code...@.";
Deadcode.f p
let pure_fun = Pure_fun.f p in
Deadcode.f pure_fun p

let deadcode p =
let p, _ = deadcode' p in
Expand Down Expand Up @@ -100,12 +101,13 @@ let effects_and_exact_calls ~deadcode_sentinal (profile : Profile.t) p =
| _, O1 -> true
in
let info = Global_flow.f ~fast p in
let pure_fun = Pure_fun.f p in
let p, live_vars =
if Config.Flag.globaldeadcode () && Config.Flag.deadcode ()
then
let p = Global_deadcode.f p ~deadcode_sentinal info in
Deadcode.f p
else Deadcode.f p
let p = Global_deadcode.f pure_fun p ~deadcode_sentinal info in
Deadcode.f pure_fun p
else Deadcode.f pure_fun p
in
match Config.effects () with
| `Cps | `Double_translation ->
Expand Down
3 changes: 1 addition & 2 deletions compiler/lib/global_deadcode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ let add_sentinal p sentinal =
Code.prepend p [ instr ]

(** Run the liveness analysis and replace dead variables with the given sentinal. *)
let f p ~deadcode_sentinal global_info =
let f pure_funs p ~deadcode_sentinal global_info =
Code.invariant p;
let t = Timer.make () in
(* Add sentinal variable *)
Expand All @@ -570,7 +570,6 @@ let f p ~deadcode_sentinal global_info =
(* Compute definitions *)
let defs = definitions p in
(* Compute initial liveness *)
let pure_funs = Pure_fun.f p in
let live_table, scoped_live_vars = liveness p pure_funs global_info in
(* Compute usages *)
let uses = usages p global_info scoped_live_vars in
Expand Down
7 changes: 6 additions & 1 deletion compiler/lib/global_deadcode.mli
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ variables that are then removed by [deadcode.ml]. In particular it
allows for the elimination of unused functions defined in functors,
which the original deadcode elimination cannot. *)

val f : Code.program -> deadcode_sentinal:Code.Var.t -> Global_flow.info -> Code.program
val f :
Pure_fun.t
-> Code.program
-> deadcode_sentinal:Code.Var.t
-> Global_flow.info
-> Code.program
7 changes: 1 addition & 6 deletions compiler/lib/partial_cps_analysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,7 @@ let cps_needed ~info ~in_mutual_recursion ~rev_deps st x =
true
| Expr (Prim _ | Block _ | Constant _ | Field _ | Special _) | Phi _ -> false

module SCC = Strongly_connected_components.Make (struct
type t = Var.t

module Set = Var.Set
module Map = Var.Map
end)
module SCC = Strongly_connected_components.Make (Var)

let find_mutually_recursive_calls tail_deps =
let scc = SCC.component_graph !tail_deps in
Expand Down
Loading