@@ -128,22 +128,25 @@ let update_deps st { blocks; _ } =
128
128
| _ -> () ))
129
129
blocks
130
130
131
- let mark_function_parameters { blocks; _ } =
132
- let function_parameters = Var.Tbl. make () false in
133
- let set x = Var.Tbl. set function_parameters x true in
131
+ let mark_function_parameters ~ fun_info { blocks; _ } =
132
+ let boxed_function_parameters = Var.Tbl. make () false in
133
+ let set x = Var.Tbl. set boxed_function_parameters x true in
134
134
Addr.Map. iter
135
135
(fun _ block ->
136
136
List. iter block.body ~f: (fun i ->
137
137
match i with
138
- | Let (_ , Closure (params , _ , _ )) -> List. iter ~f: set params
138
+ | Let (x, Closure (params, _, _))
139
+ when not (Call_graph_analysis. direct_calls_only fun_info x) ->
140
+ List. iter ~f: set params
139
141
| _ -> () ))
140
142
blocks;
141
- function_parameters
143
+ boxed_function_parameters
142
144
143
145
type st =
144
- { state : state
145
- ; info : info
146
- ; function_parameters : bool Var.Tbl .t
146
+ { global_flow_state : state
147
+ ; global_flow_info : info
148
+ ; boxed_function_parameters : bool Var.Tbl .t
149
+ ; fun_info : Call_graph_analysis .t
147
150
}
148
151
149
152
let rec constant_type (c : constant ) =
@@ -319,11 +322,11 @@ let prim_type ~approx prim args =
319
322
| _ -> Top
320
323
321
324
let propagate st approx x : Domain.t =
322
- match st.state .defs.(Var. idx x) with
325
+ match st.global_flow_state .defs.(Var. idx x) with
323
326
| Phi { known; others; unit } ->
324
327
let res = Domain. join_set ~others (fun y -> Var.Tbl. get approx y) known in
325
328
let res = if unit then Domain. join (Int Unnormalized ) res else res in
326
- if Var.Tbl. get st.function_parameters x then Domain. box res else res
329
+ if Var.Tbl. get st.boxed_function_parameters x then Domain. box res else res
327
330
| Expr e -> (
328
331
match e with
329
332
| Constant c -> constant_type c
@@ -332,7 +335,7 @@ let propagate st approx x : Domain.t =
332
335
Tuple
333
336
(Array. mapi
334
337
~f: (fun i y ->
335
- match st.state .mutable_fields.(Var. idx x) with
338
+ match st.global_flow_state .mutable_fields.(Var. idx x) with
336
339
| All_fields -> Top
337
340
| Some_fields s when IntSet. mem i s -> Top
338
341
| Some_fields _ | No_field ->
@@ -348,15 +351,15 @@ let propagate st approx x : Domain.t =
348
351
( Extern (" caml_check_bound" | " caml_check_bound_float" | " caml_check_bound_gen" )
349
352
, [ Pv y; _ ] ) -> Var.Tbl. get approx y
350
353
| Prim ((Array_get | Extern "caml_array_unsafe_get" ), [ Pv y; _ ]) -> (
351
- match Var.Tbl. get st.info .info_approximation y with
354
+ match Var.Tbl. get st.global_flow_info .info_approximation y with
352
355
| Values { known; others } ->
353
356
Domain. join_set
354
357
~others
355
358
(fun z ->
356
- match st.state .defs.(Var. idx z) with
359
+ match st.global_flow_state .defs.(Var. idx z) with
357
360
| Expr (Block (_ , lst , _ , _ )) ->
358
361
let m =
359
- match st.state .mutable_fields.(Var. idx z) with
362
+ match st.global_flow_state .mutable_fields.(Var. idx z) with
360
363
| No_field -> false
361
364
| Some_fields _ | All_fields -> true
362
365
in
@@ -377,18 +380,22 @@ let propagate st approx x : Domain.t =
377
380
| Prim (Extern prim , args ) -> prim_type ~approx prim args
378
381
| Special _ -> Top
379
382
| Apply { f; args; _ } -> (
380
- match Var.Tbl. get st.info .info_approximation f with
383
+ match Var.Tbl. get st.global_flow_info .info_approximation f with
381
384
| Values { known; others } ->
382
385
Domain. join_set
383
386
~others
384
387
(fun g ->
385
- match st.state .defs.(Var. idx g) with
388
+ match st.global_flow_state .defs.(Var. idx g) with
386
389
| Expr (Closure (params, _, _))
387
390
when List. length args = List. length params ->
388
- Domain. box
389
- (Domain. join_set
390
- (fun y -> Var.Tbl. get approx y)
391
- (Var.Map. find g st.state.return_values))
391
+ let res =
392
+ Domain. join_set
393
+ (fun y -> Var.Tbl. get approx y)
394
+ (Var.Map. find g st.global_flow_state.return_values)
395
+ in
396
+ if false && Call_graph_analysis. direct_calls_only st.fun_info g
397
+ then res
398
+ else Domain. box res
392
399
| Expr (Closure (_ , _ , _ )) ->
393
400
(* The function is partially applied or over applied *)
394
401
Top
@@ -403,33 +410,36 @@ module Solver = G.Solver (Domain)
403
410
let solver st =
404
411
let associated_list h x = try Var.Hashtbl. find h x with Not_found -> [] in
405
412
let g =
406
- { G. domain = st.state .vars
413
+ { G. domain = st.global_flow_state .vars
407
414
; G. iter_children =
408
415
(fun f x ->
409
- List. iter ~f (Var.Tbl. get st.state .deps x);
416
+ List. iter ~f (Var.Tbl. get st.global_flow_state .deps x);
410
417
List. iter
411
- ~f: (fun g -> List. iter ~f (associated_list st.state.function_call_sites g))
412
- (associated_list st.state.functions_from_returned_value x))
418
+ ~f: (fun g ->
419
+ List. iter ~f (associated_list st.global_flow_state.function_call_sites g))
420
+ (associated_list st.global_flow_state.functions_from_returned_value x))
413
421
}
414
422
in
415
423
Solver. f () g (propagate st)
416
424
417
- let f ~state ~info ~deadcode_sentinal p =
418
- update_deps state p;
419
- let function_parameters = mark_function_parameters p in
420
- let typ = solver { state; info; function_parameters } in
425
+ let f ~global_flow_state ~global_flow_info ~fun_info ~deadcode_sentinal p =
426
+ update_deps global_flow_state p;
427
+ let boxed_function_parameters = mark_function_parameters ~fun_info p in
428
+ let typ =
429
+ solver { global_flow_state; global_flow_info; fun_info; boxed_function_parameters }
430
+ in
421
431
Var.Tbl. set typ deadcode_sentinal (Int Normalized );
422
432
if debug ()
423
433
then (
424
434
Var.ISet. iter
425
435
(fun x ->
426
- match state .defs.(Var. idx x) with
436
+ match global_flow_state .defs.(Var. idx x) with
427
437
| Expr _ -> ()
428
438
| Phi _ ->
429
439
let t = Var.Tbl. get typ x in
430
440
if not (Domain. equal t Top )
431
441
then Format. eprintf " %a: %a@." Var. print x Domain. print t)
432
- state .vars;
442
+ global_flow_state .vars;
433
443
Print. program
434
444
Format. err_formatter
435
445
(fun _ i ->
0 commit comments