@@ -237,17 +237,39 @@ let sum ~context f pc =
237
237
blocks
238
238
0
239
239
240
- let rec block_size ~recurse ~context { branch; body; _ } =
240
+ let rec block_size ~inline_comparisons ~ recurse ~context { branch; body; _ } =
241
241
List. fold_left
242
242
~f: (fun n i ->
243
243
match i with
244
244
| Event _ -> n
245
+ | Let
246
+ ( _
247
+ , Prim
248
+ ( Extern
249
+ ( " caml_lessthan"
250
+ | " caml_lessequal"
251
+ | " caml_greaterthan"
252
+ | " caml_greaterequal"
253
+ | " caml_equal"
254
+ | " caml_notequal" )
255
+ , _ ) )
256
+ when inline_comparisons ->
257
+ (* Bias toward inlining functions containing polymorphic
258
+ comparisons, such as min and max, in the hope that
259
+ polymorphic comparisons can be specialized. *)
260
+ n - 1
245
261
| Let (f , Closure (_ , (pc , _ ), _ )) ->
246
262
if recurse
247
263
then
248
264
match Var.Map. find f context.env with
249
- | exception Not_found -> size ~recurse ~context pc + n + 1
250
- | info -> cache ~info info.full_size (size ~recurse: true ~context ) + n + 1
265
+ | exception Not_found -> size ~inline_comparisons ~recurse ~context pc + n + 1
266
+ | info ->
267
+ cache
268
+ ~info
269
+ info.full_size
270
+ (size ~inline_comparisons ~recurse: true ~context )
271
+ + n
272
+ + 1
251
273
else n + 1
252
274
| _ -> n + 1 )
253
275
~init:
@@ -257,13 +279,21 @@ let rec block_size ~recurse ~context { branch; body; _ } =
257
279
| _ -> 0 )
258
280
body
259
281
260
- and size ~recurse ~context = sum ~context (block_size ~recurse ~context )
282
+ and size ~inline_comparisons ~recurse ~context =
283
+ sum ~context (block_size ~inline_comparisons ~recurse ~context )
261
284
262
285
(* * Size of the function body *)
263
- let body_size ~context info = cache ~info info.body_size (size ~recurse: false ~context )
286
+ let body_size ~context info =
287
+ let inline_comparisons =
288
+ match Config. target () with
289
+ | `JavaScript -> false
290
+ | `Wasm -> true
291
+ in
292
+ cache ~info info.body_size (size ~inline_comparisons ~recurse: false ~context )
264
293
265
294
(* * Size of the function, including the size of the closures it contains *)
266
- let full_size ~context info = cache ~info info.full_size (size ~recurse: true ~context )
295
+ let full_size ~context info =
296
+ cache ~info info.full_size (size ~inline_comparisons: false ~recurse: true ~context )
267
297
268
298
let closure_count_uncached ~context =
269
299
sum ~context (fun { body; _ } ->
0 commit comments