Skip to content

For testing #3833

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

Open
wants to merge 56 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
f7586bc
Propagate effects info to Cfg.external_call_operation (#3765)
mshinwell Mar 31, 2025
cb8c355
Mark Obj_dup as not having effects and handle in Cfg (#3766)
mshinwell Mar 31, 2025
9cecf95
github ci jobs with debug runtime for macos (#3744)
gretay-js Mar 31, 2025
4d1240f
github ci actions on arm64 linux (#3745)
gretay-js Mar 31, 2025
65c8bc8
Merge `_utils` module (backend) (#3767)
xclerc Mar 31, 2025
ddd6e08
Avoid uncaught `Not_found` arising from free vars in probes (#3776)
lukemaurer Apr 1, 2025
f7364cf
Remove .mlp File from the Arm Backend (#3771)
spiessimon Apr 1, 2025
8e1748e
Add cfg invariants pass (#657)
gretay-js Apr 1, 2025
da0a241
Remove Select_utils.common_selector (#3783)
mshinwell Apr 2, 2025
dcd0d26
Revert "Merge atomic counter inc/dec functions and use them consisten…
mshinwell Apr 2, 2025
51104de
Rename sub_cfg instance variable -> current_sub_cfg (#3788)
mshinwell Apr 2, 2025
22d7822
Remove backend/dune (#3786)
gretay-js Apr 2, 2025
f025167
Revert "Avoid checking pending actions in Condition.wait (#3741)" (#3…
stedolan Apr 2, 2025
5f3b444
Pass around "sub_cfg" in Cfg_selectgen (#3792)
mshinwell Apr 2, 2025
d914311
Refactor stack classes (#3784)
xclerc Apr 2, 2025
9e0a8fe
Delete uses of `Reg.anonymous` (#3793)
TheNumbat Apr 3, 2025
3fd4b3b
Remove the current_sub_cfg instance variable (#3795)
mshinwell Apr 3, 2025
1a9ec8f
Clean up regalloc jobs (CI) (#3787)
xclerc Apr 3, 2025
f3b0cfb
Use caml_array_blit for %arrayblit on Pgenarray and Paddrarray (#3760)
mshinwell Apr 3, 2025
488f30e
Introduce Or_never_returns in Cfg_selectgen (#3798)
mshinwell Apr 3, 2025
82d9705
Compiler Compare Script (#3779)
spiessimon Apr 3, 2025
6f69bbe
Add new interface for target-specific selection code (#3800)
mshinwell Apr 3, 2025
3f67408
Cfg_selectgen emit_expr tidyups etc (#3799)
mshinwell Apr 3, 2025
bb6b65a
Move code from Cfg_selectgen to Select_utils etc (#3801)
mshinwell Apr 3, 2025
cf91b80
Cfg_selectgen: move code around (#3802)
mshinwell Apr 3, 2025
ce76ff7
New version of Cfg_selectgen.emit_stores (#3803)
mshinwell Apr 4, 2025
c7d2ec1
Remove objects from CSE code (#3806)
mshinwell Apr 4, 2025
ca1b65f
Remove objects from instruction selection code (#3782)
mshinwell Apr 4, 2025
ce96f37
Extend ARM DSL and use it for the emission of more instructions (Part…
spiessimon Apr 4, 2025
986dc5f
Specific instructions cannot raise (#3811)
gretay-js Apr 4, 2025
ee49613
Use the same verbose parameter for all register allocators (#3769)
xclerc Apr 7, 2025
8c435c3
Tidying up in Cfg_selectgen (#3815)
mshinwell Apr 7, 2025
c233e29
Improve compiler comparison script (#3818)
spiessimon Apr 7, 2025
d6f1350
Remove all objects from ocamltest (#3821)
lukemaurer Apr 8, 2025
dde9349
Remove Cmm.kind_for_unboxing (#3817)
mshinwell Apr 8, 2025
cd16a28
Remove cvt_emit (#3816)
spiessimon Apr 8, 2025
ba8ed94
Tweak logging code of register allocators (#3822)
xclerc Apr 8, 2025
d67ee12
Simplify the logging logic (register allocators) (#3777)
xclerc Apr 8, 2025
e7ad7a7
Merge `Simple_operation` into `Operation` (#3805)
xclerc Apr 8, 2025
f2aaa29
Remove reference to `simple_operation.ml*` in `.ocamlformat-enable` (…
xclerc Apr 8, 2025
d877934
Fix Weak.set on arm64 (and other relaxed architectures) (#3819)
stedolan Apr 8, 2025
5d6a0f6
Move `Substitution` to a dedicated top-level module (#3700)
xclerc Apr 9, 2025
1772d2b
Small cleanup changes in emit.ml (#3827)
spiessimon Apr 9, 2025
ea238dc
Linscan: use doubly-linked lists for intervals (#3737)
xclerc Apr 9, 2025
252c53e
Linscan: keep only the doubly-linked lists (#3751)
xclerc Apr 9, 2025
d106170
Extend ARM DSL and use it for the emission of more instructions (Part…
spiessimon Apr 9, 2025
2c028b3
Refactor peephole pass (#3797)
gretay-js Apr 9, 2025
be12560
Avoid polymorphic comparison in `backend` (#3649)
xclerc Apr 9, 2025
4fc47a8
Format emit.ml (#3831)
gretay-js Apr 9, 2025
1f6e829
Fix a soundness bug in Simplif (#3832)
stedolan Apr 10, 2025
12ea397
runtime events: disable flaky test (#3830)
gretay-js Apr 10, 2025
5ef70c1
Cfg_simplify pass (#3768)
gretay-js Apr 10, 2025
09d0685
no need for sigwait check as posix signals suffice (#3256)
avsm Apr 10, 2025
b731c0c
Enable cfg invariants and dead trap handler elimination by default
gretay-js Apr 2, 2025
85d4e30
Fix bug in flag
gretay-js Apr 21, 2025
d756cef
Remove fatal_error
gretay-js Apr 21, 2025
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
Prev Previous commit
Next Next commit
Simplify the logging logic (register allocators) (#3777)
  • Loading branch information
xclerc authored and gretay-js committed Apr 21, 2025
commit d67ee12c83bed87b3fcfc070f7060232bcb25130
51 changes: 24 additions & 27 deletions backend/regalloc/regalloc_gi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ module State = Regalloc_gi_state
module Utils = struct
include Regalloc_gi_utils

let debug = gi_debug
let debug = debug

let invariants = gi_invariants

let log = log

let log_body_and_terminator = log_body_and_terminator
let invariants = invariants

let is_spilled reg = reg.Reg.spill

Expand Down Expand Up @@ -43,7 +39,7 @@ let rewrite : State.t -> Cfg_with_infos.t -> spilled_nodes:Reg.t list -> bool =

let update_register_locations : State.t -> unit =
fun state ->
if gi_debug
if debug
then (
log "update_register_locations";
indent ());
Expand All @@ -57,14 +53,14 @@ let update_register_locations : State.t -> unit =
(* a register may "disappear" because of split/rename *)
()
| Some location ->
if gi_debug
if debug
then
log "updating %a to %a" Printreg.reg reg
Hardware_register.print_location location;
reg.Reg.loc <- Hardware_register.reg_location_of_location location)
in
List.iter (Reg.all_registers ()) ~f:update_register;
if gi_debug then dedent ()
if debug then dedent ()

module Prio_queue = Make_max_priority_queue (Int)

Expand All @@ -78,7 +74,7 @@ let priority_heuristics : Reg.t -> Interval.t -> int =

let make_hardware_registers_and_prio_queue (cfg_with_infos : Cfg_with_infos.t) :
Hardware_registers.t * prio_queue =
if gi_debug
if debug
then (
log "creating registers and queue";
indent ());
Expand All @@ -92,7 +88,7 @@ let make_hardware_registers_and_prio_queue (cfg_with_infos : Cfg_with_infos.t) :
(fun reg interval ->
match reg.loc with
| Reg _ -> (
if gi_debug
if debug
then (
log "pre-assigned register %a" Printreg.reg reg;
indent ();
Expand All @@ -104,7 +100,7 @@ let make_hardware_registers_and_prio_queue (cfg_with_infos : Cfg_with_infos.t) :
Hardware_register.add_non_evictable hardware_reg reg interval)
| Unknown ->
let priority = priority_heuristics reg interval in
if gi_debug
if debug
then (
log "register %a" Printreg.reg reg;
indent ();
Expand All @@ -113,15 +109,15 @@ let make_hardware_registers_and_prio_queue (cfg_with_infos : Cfg_with_infos.t) :
dedent ());
Prio_queue.add prio_queue ~priority ~data:(reg, interval)
| Stack _ ->
if gi_debug
if debug
then (
log "stack register %a" Printreg.reg reg;
indent ();
log "%a" Interval.print interval;
dedent ());
())
intervals;
if gi_debug then dedent ();
if debug then dedent ();
hardware_registers, prio_queue

(* CR xclerc for xclerc: try to find a reasonable threshold. *)
Expand All @@ -144,15 +140,15 @@ let rec main : round:int -> flat:bool -> State.t -> Cfg_with_infos.t -> unit =
fatal "register allocation introduced %d temporaries after starting with %d"
(State.introduced_temporary_count state)
(State.initial_temporary_count state);
if gi_debug
if debug
then (
log "main, round #%d" round;
log_cfg_with_infos cfg_with_infos);
if gi_debug then log "updating spilling costs";
if debug then log "updating spilling costs";
update_spill_cost cfg_with_infos ~flat ();
State.iter_introduced_temporaries state ~f:(fun (reg : Reg.t) ->
reg.Reg.spill_cost <- reg.Reg.spill_cost + 10_000);
if gi_debug
if debug
then (
log "spilling costs";
indent ();
Expand All @@ -168,19 +164,19 @@ let rec main : round:int -> flat:bool -> State.t -> Cfg_with_infos.t -> unit =
indent ();
while not (Prio_queue.is_empty prio_queue) do
incr step;
if gi_debug then log "step #%d (size=%d)" !step (Prio_queue.size prio_queue);
if debug then log "step #%d (size=%d)" !step (Prio_queue.size prio_queue);
let { Prio_queue.priority; data = reg, interval } =
Prio_queue.get_and_remove prio_queue
in
if gi_debug
if debug
then (
indent ();
log "got register %a (prio=%d)" Printreg.reg reg priority);
(match
Hardware_registers.find_available hardware_registers reg interval
with
| For_assignment { hardware_reg } ->
if gi_debug
if debug
then
log "assigning %a to %a" Printreg.reg reg
Hardware_register.print_location hardware_reg.location;
Expand All @@ -189,7 +185,7 @@ let rec main : round:int -> flat:bool -> State.t -> Cfg_with_infos.t -> unit =
<- { Hardware_register.pseudo_reg = reg; interval; evictable = true }
:: hardware_reg.assigned
| For_eviction { hardware_reg; evicted_regs } ->
if gi_debug
if debug
then
log "evicting %a from %a" Printreg.regs
(Array.of_list
Expand Down Expand Up @@ -225,16 +221,16 @@ let rec main : round:int -> flat:bool -> State.t -> Cfg_with_infos.t -> unit =
Reg.same r r')))
| Split_or_spill ->
(* CR xclerc for xclerc: we should actually try to split. *)
if gi_debug then log "spilling %a" Printreg.reg reg;
if debug then log "spilling %a" Printreg.reg reg;
reg.Reg.spill <- true;
spilling := (reg, interval) :: !spilling);
if gi_debug then dedent ()
if debug then dedent ()
done;
dedent ();
match !spilling with
| [] -> ()
| _ :: _ as spilled_nodes -> (
if gi_debug
if debug
then (
log_cfg_with_infos cfg_with_infos;
indent ();
Expand Down Expand Up @@ -269,11 +265,12 @@ let rec main : round:int -> flat:bool -> State.t -> Cfg_with_infos.t -> unit =
rewrite state cfg_with_infos
~spilled_nodes:(List.map spilled_nodes ~f:fst)
with
| false -> if gi_debug then log "(end of main)"
| false -> if debug then log "(end of main)"
| true -> main ~round:(succ round) ~flat state cfg_with_infos)

let run : Cfg_with_infos.t -> Cfg_with_infos.t =
fun cfg_with_infos ->
if debug then reset_indentation ();
let cfg_with_layout = Cfg_with_infos.cfg_with_layout cfg_with_infos in
let cfg_infos, stack_slots =
Regalloc_rewrite.prelude
Expand All @@ -285,7 +282,7 @@ let run : Cfg_with_infos.t -> Cfg_with_infos.t =
the creation of the state to `prelude`. *)
let all_temporaries = Reg.Set.union cfg_infos.arg cfg_infos.res in
let initial_temporaries = Reg.Set.cardinal all_temporaries in
if gi_debug then log "#temporaries=%d" initial_temporaries;
if debug then log "#temporaries=%d" initial_temporaries;
let state =
State.make ~stack_slots ~initial_temporaries
~last_used:cfg_infos.max_instruction_id
Expand All @@ -306,7 +303,7 @@ let run : Cfg_with_infos.t -> Cfg_with_infos.t =
| Random_for_testing -> Spilling_heuristics.random ()
in
main ~round:1 ~flat state cfg_with_infos;
if gi_debug
if debug
then (
indent ();
log_cfg_with_infos cfg_with_infos;
Expand Down
38 changes: 16 additions & 22 deletions backend/regalloc/regalloc_gi_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,16 @@ open! Int_replace_polymorphic_compare
open! Regalloc_utils
module DLL = Flambda_backend_utils.Doubly_linked_list

let gi_debug = true

let gi_rng = Random.State.make [| 4; 6; 2 |]

let bool_of_param param_name =
bool_of_param ~guard:(gi_debug, "gi_debug") param_name

let gi_invariants : bool Lazy.t = bool_of_param "GI_INVARIANTS"

let log_function = lazy (make_log_function ~label:"gi")

let indent () = (Lazy.force log_function).indent ()

let dedent () = (Lazy.force log_function).dedent ()

let reset_indentation () = (Lazy.force log_function).reset_indentation ()

let log : type a. ?no_eol:unit -> (a, Format.formatter, unit) format -> a =
fun ?no_eol fmt -> (Lazy.force log_function).log ?no_eol fmt

Expand Down Expand Up @@ -454,7 +449,7 @@ end

let build_intervals : Cfg_with_infos.t -> Interval.t Reg.Tbl.t =
fun cfg_with_infos ->
if gi_debug
if debug
then (
log "build_intervals";
indent ());
Expand Down Expand Up @@ -521,12 +516,12 @@ let build_intervals : Cfg_with_infos.t -> Interval.t Reg.Tbl.t =
(fun _reg (interval : Interval.t) ->
interval.ranges <- List.rev interval.ranges)
past_ranges;
if gi_debug && Lazy.force verbose
if debug && Lazy.force verbose
then
iter_cfg_layout cfg_with_layout ~f:(fun block ->
log "(block %a)" Label.format block.start;
log_body_and_terminator block.body block.terminator liveness);
if gi_debug then dedent ();
if debug then dedent ();
past_ranges

module Hardware_register = struct
Expand Down Expand Up @@ -633,7 +628,7 @@ module Hardware_registers = struct

let overlap (hardware_reg : Hardware_register.t) (interval : Interval.t) :
bool =
if gi_debug
if debug
then (
log "considering %a" Hardware_register.print_location
hardware_reg.location;
Expand All @@ -646,7 +641,7 @@ module Hardware_registers = struct
-> Interval.overlap itv interval)
in
let overlap = overlap_hard || overlap_assigned in
if gi_debug
if debug
then (
log "overlap=%B (hard=%B, assigned=%B)" overlap overlap_hard
overlap_assigned;
Expand Down Expand Up @@ -676,7 +671,7 @@ module Hardware_registers = struct
let find_evictable (t : t) (reg : Reg.t) (interval : Interval.t) : available =
let eviction =
fold_class t ~of_reg:reg ~init:None ~f:(fun acc hardware_reg ->
if gi_debug
if debug
then
log "considering %a (length=%d)" Hardware_register.print_location
hardware_reg.location
Expand All @@ -685,7 +680,7 @@ module Hardware_registers = struct
if overlap_hard
then acc
else (
if gi_debug then indent ();
if debug then indent ();
let overlaping : Hardware_register.assigned list =
List.filter hardware_reg.assigned
~f:(fun
Expand All @@ -695,7 +690,7 @@ module Hardware_registers = struct
}
->
let overlap = Interval.overlap interval itv in
if gi_debug
if debug
then
log "%a is assigned / overlap=%B" Printreg.reg pseudo_reg
overlap;
Expand All @@ -712,7 +707,7 @@ module Hardware_registers = struct
->
acc_cost + actual_cost pseudo_reg, acc_evictable && evictable)
in
if gi_debug then dedent ();
if debug then dedent ();
if not evictable
then acc
else
Expand All @@ -721,7 +716,7 @@ module Hardware_registers = struct
in
if cost < evict_cost && cost < actual_cost reg
then (
if gi_debug
if debug
then
List.iter overlaping ~f:(fun assigned ->
log "evicting %a" Hardware_register.print_assigned
Expand All @@ -746,21 +741,20 @@ module Hardware_registers = struct
match heuristic with
| Selection_heuristics.Random_for_testing -> assert false
| Selection_heuristics.First_available ->
if gi_debug
if debug
then log "trying to find an available register with 'first-available'";
find_first t reg interval
| Selection_heuristics.Best_fit ->
if gi_debug
then log "trying to find an available register with 'best-fit'";
if debug then log "trying to find an available register with 'best-fit'";
find_using_length t reg interval ~better:( > )
| Selection_heuristics.Worst_fit ->
if gi_debug
if debug
then log "trying to find an available register with 'worst-fit'";
find_using_length t reg interval ~better:( < )
in
match with_no_overlap with
| Some hardware_reg -> For_assignment { hardware_reg }
| None ->
if gi_debug then log "trying to find an evictable register";
if debug then log "trying to find an evictable register";
find_evictable t reg interval
end
6 changes: 2 additions & 4 deletions backend/regalloc/regalloc_gi_utils.mli
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

open Regalloc_utils

val gi_debug : bool

val gi_invariants : bool Lazy.t

val log : ?no_eol:unit -> ('a, Format.formatter, unit) format -> 'a

val indent : unit -> unit

val dedent : unit -> unit

val reset_indentation : unit -> unit

val log_body_and_terminator :
Cfg.basic_instruction_list ->
Cfg.terminator Cfg.instruction ->
Expand Down
Loading