@@ -44,9 +44,7 @@ let is_nontail_call : Cfg.terminator -> bool =
44
44
45
45
(* Returns the stack check info, and the max of seen instruction ids. *)
46
46
let block_preproc_stack_check_result :
47
- Cfg. basic_block ->
48
- frame_size :int ->
49
- Emitaux. preproc_stack_check_result * InstructionId. t =
47
+ Cfg. basic_block -> frame_size :int -> Emitaux.preproc_stack_check_result =
50
48
fun block ~frame_size ->
51
49
let contains_nontail_calls =
52
50
(* XCR mshinwell: move to a method in Cfg somewhere?
@@ -55,20 +53,17 @@ let block_preproc_stack_check_result :
55
53
think the predicate is generic enough to be moved to `Cfg`. *)
56
54
is_nontail_call block.terminator.desc
57
55
in
58
- let max_frame_size, max_instr_id =
59
- DLL. fold_left block.body
60
- ~init: (block.terminator.stack_offset, block.terminator.id)
61
- ~f: (fun (max_stack_frame , max_instr_id ) (instr : _ Cfg.instruction ) ->
62
- ( Int. max max_stack_frame instr.stack_offset,
63
- InstructionId. max max_instr_id instr.id ))
56
+ let max_frame_size =
57
+ DLL. fold_left block.body ~init: block.terminator.stack_offset
58
+ ~f: (fun max_stack_frame (instr : _ Cfg.instruction ) ->
59
+ Int. max max_stack_frame instr.stack_offset)
64
60
in
65
61
let max_frame_size = max_frame_size + frame_size in
66
- { max_frame_size; contains_nontail_calls }, max_instr_id
62
+ { max_frame_size; contains_nontail_calls }
67
63
68
64
type cfg_info =
69
65
{ max_frame_size : int ;
70
- blocks_needing_stack_checks : Label.Set .t ;
71
- max_instr_id : InstructionId .t
66
+ blocks_needing_stack_checks : Label.Set .t
72
67
}
73
68
74
69
let build_cfg_info : Cfg.t -> cfg_info =
@@ -78,18 +73,11 @@ let build_cfg_info : Cfg.t -> cfg_info =
78
73
~contains_calls: cfg.fun_contains_calls
79
74
in
80
75
let init =
81
- { max_frame_size = 0 ;
82
- blocks_needing_stack_checks = Label.Set. empty;
83
- max_instr_id = InstructionId. none
84
- }
76
+ { max_frame_size = 0 ; blocks_needing_stack_checks = Label.Set. empty }
85
77
in
86
78
Cfg. fold_blocks cfg ~init
87
- ~f: (fun
88
- label
89
- block
90
- { max_frame_size; blocks_needing_stack_checks; max_instr_id }
91
- ->
92
- let preproc_stack_check_result, max_instr_id_block =
79
+ ~f: (fun label block { max_frame_size; blocks_needing_stack_checks } ->
80
+ let preproc_stack_check_result =
93
81
block_preproc_stack_check_result block ~frame_size
94
82
in
95
83
let block_needs_stack_checks =
@@ -105,8 +93,7 @@ let build_cfg_info : Cfg.t -> cfg_info =
105
93
then Label.Set. add label blocks_needing_stack_checks
106
94
else blocks_needing_stack_checks
107
95
in
108
- let max_instr_id = InstructionId. max max_instr_id max_instr_id_block in
109
- { max_frame_size; blocks_needing_stack_checks; max_instr_id })
96
+ { max_frame_size; blocks_needing_stack_checks })
110
97
111
98
(* Populates `num_checks` with the number of blocks needing a stack check in the
112
99
subtree whose root is the associated label, and returns that value. *)
@@ -170,8 +157,7 @@ let rec find_stack_check_block :
170
157
num_checks_tree"
171
158
to_cover
172
159
173
- let insert_instruction (cfg : Cfg.t ) (label : Label.t ) ~max_frame_size
174
- ~max_instr_id =
160
+ let insert_instruction (cfg : Cfg.t ) (label : Label.t ) ~max_frame_size =
175
161
let block = Cfg. get_block_exn cfg label in
176
162
let stack_offset = Cfg. first_instruction_stack_offset block in
177
163
let check : Cfg.basic Cfg.instruction =
@@ -183,16 +169,15 @@ let insert_instruction (cfg : Cfg.t) (label : Label.t) ~max_frame_size
183
169
184
170
xclerc: (keeping the comment, and the explicit values below until all of
185
171
that is implemented.) *)
186
- let seq = InstructionId. make_sequence ~last_used: max_instr_id () in
187
- let id = InstructionId. get_and_incr seq in
172
+ let id = InstructionId. get_and_incr cfg.next_instruction_id in
188
173
Cfg. make_instruction ()
189
174
~desc: (Cfg. Stack_check { max_frame_size_bytes = max_frame_size })
190
175
~stack_offset ~id ~available_before: None ~available_across: None
191
176
in
192
177
DLL. add_begin block.body check
193
178
194
179
let insert_stack_checks (cfg : Cfg.t ) ~max_frame_size
195
- ~blocks_needing_stack_checks ~ max_instr_id =
180
+ ~blocks_needing_stack_checks =
196
181
(* CR-soon xclerc for xclerc: use the dominators and loop infos from
197
182
Cfg_with_infos (at least on some paths). *)
198
183
let doms = Cfg_dominators. build cfg in
@@ -207,7 +192,7 @@ let insert_stack_checks (cfg : Cfg.t) ~max_frame_size
207
192
| 0 -> ()
208
193
| to_cover ->
209
194
let label = find_stack_check_block tree ~to_cover ~num_checks ~loop_infos in
210
- insert_instruction cfg label ~max_frame_size ~max_instr_id
195
+ insert_instruction cfg label ~max_frame_size
211
196
212
197
(* CR-someday xclerc for xclerc: we may want to duplicate the check in some
213
198
cases, rather than simply pushing it down. *)
@@ -218,7 +203,7 @@ let cfg (cfg_with_layout : Cfg_with_layout.t) =
218
203
let cfg = Cfg_with_layout. cfg cfg_with_layout in
219
204
(if not Config. no_stack_checks
220
205
then
221
- let { max_frame_size; blocks_needing_stack_checks; max_instr_id } =
206
+ let { max_frame_size; blocks_needing_stack_checks } =
222
207
build_cfg_info cfg
223
208
in
224
209
if not (Label.Set. is_empty blocks_needing_stack_checks)
@@ -227,7 +212,5 @@ let cfg (cfg_with_layout : Cfg_with_layout.t) =
227
212
< ! Flambda_backend_flags. cfg_stack_checks_threshold
228
213
then
229
214
insert_stack_checks cfg ~max_frame_size ~blocks_needing_stack_checks
230
- ~max_instr_id
231
- else
232
- insert_instruction cfg cfg.entry_label ~max_frame_size ~max_instr_id );
215
+ else insert_instruction cfg cfg.entry_label ~max_frame_size );
233
216
cfg_with_layout
0 commit comments