Skip to content

Commit 5f1db04

Browse files
committed
Further simplify Utils module.
1 parent c2fed36 commit 5f1db04

File tree

5 files changed

+8
-43
lines changed

5 files changed

+8
-43
lines changed

backend/regalloc/regalloc_gi.ml

+1-8
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,7 @@ open! Int_replace_polymorphic_compare
44
open! Regalloc_utils
55
open! Regalloc_gi_utils
66
module State = Regalloc_gi_state
7-
8-
module Utils = struct
9-
include Regalloc_gi_utils
10-
11-
type state = State.t
12-
13-
let is_spilled _state reg = reg.Reg.spill
14-
end
7+
module Utils = Regalloc_gi_utils
158

169
let rewrite : State.t -> Cfg_with_infos.t -> spilled_nodes:Reg.t list -> bool =
1710
fun state cfg_with_infos ~spilled_nodes ->

backend/regalloc/regalloc_irc.ml

+1-14
Original file line numberDiff line numberDiff line change
@@ -384,20 +384,7 @@ let assign_colors : State.t -> Cfg_with_layout.t -> unit =
384384
State.set_color state n (State.color state alias));
385385
if debug then dedent ()
386386

387-
module Utils = struct
388-
include Regalloc_irc_utils
389-
390-
type state = State.t
391-
392-
let is_spilled state reg =
393-
match State.work_list_opt state reg with
394-
| None ->
395-
(* Freshly-created may not have been added to the map yet; such registers
396-
would morally be in the "unknown" work list, hence returning
397-
`false`. *)
398-
false
399-
| Some work_list -> WorkList.equal work_list WorkList.Spilled
400-
end
387+
module Utils = Regalloc_irc_utils
401388

402389
(* Returns `true` if new temporaries have been introduced. *)
403390
let rewrite :

backend/regalloc/regalloc_ls.ml

+1-7
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@ module State = Regalloc_ls_state
77

88
let snapshot_for_fatal = ref None
99

10-
module Utils = struct
11-
include Regalloc_ls_utils
12-
13-
type state = State.t
14-
15-
let is_spilled _state reg = reg.Reg.spill
16-
end
10+
module Utils = Regalloc_ls_utils
1711

1812
let rewrite :
1913
State.t ->

backend/regalloc/regalloc_rewrite.ml

+4-8
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ module type State = sig
1414
end
1515

1616
module type Utils = sig
17-
type state
18-
1917
val log : ?no_eol:unit -> ('a, Format.formatter, unit) format -> 'a
2018

2119
val indent : unit -> unit
@@ -27,8 +25,6 @@ module type Utils = sig
2725
Cfg.terminator Cfg.instruction ->
2826
liveness ->
2927
unit
30-
31-
val is_spilled : state -> Reg.t -> bool
3228
end
3329

3430
type direction =
@@ -121,7 +117,7 @@ let equal_move_kind left right =
121117
let rewrite_gen :
122118
type s.
123119
(module State with type t = s) ->
124-
(module Utils with type state = s) ->
120+
(module Utils) ->
125121
s ->
126122
Cfg_with_infos.t ->
127123
spilled_nodes:Reg.t list ->
@@ -140,7 +136,6 @@ let rewrite_gen :
140136
let spilled_map : Reg.t Reg.Tbl.t =
141137
List.fold_left spilled_nodes ~init:(Reg.Tbl.create 17)
142138
~f:(fun spilled_map reg ->
143-
if debug then assert (Utils.is_spilled state reg);
144139
let spilled = Reg.create reg.Reg.typ in
145140
(* for printing *)
146141
spilled.Reg.raw_name <- reg.Reg.raw_name;
@@ -153,6 +148,7 @@ let rewrite_gen :
153148
Reg.Tbl.replace spilled_map reg spilled;
154149
spilled_map)
155150
in
151+
let is_spilled reg = Reg.Tbl.mem spilled_map reg in
156152
let new_inst_temporaries : Reg.t list ref = ref [] in
157153
let new_block_temporaries = ref [] in
158154
let make_new_temporary ~(move : Move.t) (reg : Reg.t) : Reg.t =
@@ -169,7 +165,7 @@ let rewrite_gen :
169165
let[@inline] array_contains_spilled (arr : Reg.t array) : bool =
170166
let len = Array.length arr in
171167
let i = ref 0 in
172-
while !i < len && not (Utils.is_spilled state (Array.unsafe_get arr !i)) do
168+
while !i < len && not (is_spilled (Array.unsafe_get arr !i)) do
173169
incr i
174170
done;
175171
!i < len
@@ -181,7 +177,7 @@ let rewrite_gen :
181177
~(sharing : (Reg.t * move_kind) Reg.Tbl.t) (instr : _ Cfg.instruction) :
182178
unit =
183179
let[@inline] rewrite_reg (reg : Reg.t) : Reg.t =
184-
if Utils.is_spilled state reg
180+
if is_spilled reg
185181
then (
186182
let spilled =
187183
match Reg.Tbl.find_opt spilled_map reg with

backend/regalloc/regalloc_rewrite.mli

+1-6
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ module type State = sig
1111
end
1212

1313
module type Utils = sig
14-
type state
15-
1614
val log : ?no_eol:unit -> ('a, Format.formatter, unit) format -> 'a
1715

1816
val indent : unit -> unit
@@ -24,9 +22,6 @@ module type Utils = sig
2422
Cfg.terminator Cfg.instruction ->
2523
liveness ->
2624
unit
27-
28-
(* Tests whether the passed register is marked as "spilled". *)
29-
val is_spilled : state -> Reg.t -> bool
3025
end
3126

3227
(* This is the `rewrite` function from IRC, parametrized by state, functions for
@@ -41,7 +36,7 @@ end
4136
will be empty. *)
4237
val rewrite_gen :
4338
(module State with type t = 's) ->
44-
(module Utils with type state = 's) ->
39+
(module Utils) ->
4540
's ->
4641
Cfg_with_infos.t ->
4742
spilled_nodes:Reg.t list ->

0 commit comments

Comments
 (0)