Skip to content

Commit fb7484a

Browse files
committed
WSOO side of "Distinguish float field accesses in the Code IR"
See ocsigen/js_of_ocaml#1649
1 parent 3cf1b97 commit fb7484a

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

compiler/lib/wasm/wa_generate.ml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,11 @@ module Generate (Target : Wa_target_sig.S) = struct
156156
return (W.Call (apply, args @ [ closure ]))
157157
| Block (tag, a, _, _) ->
158158
Memory.allocate stack_ctx x ~tag (List.map ~f:(fun x -> `Var x) (Array.to_list a))
159-
| Field (x, n) -> Memory.field (load x) n
159+
| Field (x, n, Non_float) -> Memory.field (load x) n
160+
| Field (x, n, Float) ->
161+
Memory.float_array_get
162+
(load x)
163+
(Constant.translate (Int (Int31.of_int_warning_on_overflow n)))
160164
| Closure _ ->
161165
Closure.translate
162166
~context:ctx.global_context
@@ -667,7 +671,16 @@ module Generate (Target : Wa_target_sig.S) = struct
667671
if ctx.live.(Var.idx x) = 0
668672
then drop (translate_expr ctx stack_ctx context x e)
669673
else store x (translate_expr ctx stack_ctx context x e)
670-
| Set_field (x, n, y) -> Memory.set_field (load x) n (load y)
674+
| Set_field (x, n, Non_float, y) ->
675+
Memory.set_field
676+
(load x)
677+
n
678+
(load y)
679+
| Set_field (x, n, Float, y) ->
680+
Memory.float_array_set
681+
(load x)
682+
(Constant.translate (Int (Int31.of_int_warning_on_overflow n)))
683+
(load y)
671684
| Offset_ref (x, n) ->
672685
Memory.set_field
673686
(load x)

compiler/lib/wasm/wa_globalize.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ let traverse_expression x e st =
7474
| Code.Apply { f; args; _ } ->
7575
st |> use f |> fun st -> List.fold_left ~f:(fun st x -> use x st) ~init:st args
7676
| Block (_, a, _, _) -> Array.fold_right ~f:use a ~init:st
77-
| Field (x, _) -> st |> use x
77+
| Field (x, _, _) -> st |> use x
7878
| Closure _ ->
7979
List.fold_left
8080
~f:(fun st x -> use x st)
@@ -95,7 +95,7 @@ let traverse_instruction st i =
9595
match fst i with
9696
| Code.Let (x, e) -> st |> declare x |> traverse_expression x e
9797
| Assign (_, x) | Offset_ref (x, _) -> st |> use x
98-
| Set_field (x, _, y) -> st |> use x |> use y
98+
| Set_field (x, _, _, y) -> st |> use x |> use y
9999
| Array_set (x, y, z) -> st |> use x |> use y |> use z
100100

101101
let traverse_block p st pc =

compiler/lib/wasm/wa_liveness.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ let expr_used ~context ~closures ~ctx x e s =
109109
| Prim (_, l) -> add_prim_args ~ctx s l
110110
| Closure _ -> add_list ~ctx s (function_free_variables ~context ~closures x)
111111
| Constant _ | Special _ -> s
112-
| Field (x, _) -> add_var ~ctx s x
112+
| Field (x, _, _) -> add_var ~ctx s x
113113

114114
let propagate_through_instr ~context ~closures ~ctx (i, _) s =
115115
match i with
116116
| Let (x, e) -> expr_used ~context ~closures ~ctx x e (Var.Set.remove x s)
117-
| Set_field (x, _, y) -> add_var ~ctx (add_var ~ctx s x) y
117+
| Set_field (x, _, _, y) -> add_var ~ctx (add_var ~ctx s x) y
118118
| Assign (_, x) | Offset_ref (x, _) -> add_var ~ctx s x
119119
| Array_set (x, y, z) -> add_var ~ctx (add_var ~ctx (add_var ~ctx s x) y) z
120120

compiler/lib/wasm/wa_spilling.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,10 @@ let spilled_variables
309309
fv
310310
~init:Var.Set.empty
311311
| Constant _ | Special _ -> Var.Set.empty
312-
| Field (x, _) -> check_spilled ~ctx loaded x Var.Set.empty)
312+
| Field (x, _, _) -> check_spilled ~ctx loaded x Var.Set.empty)
313313
| Assign (_, x) | Offset_ref (x, _) ->
314314
check_spilled ~ctx loaded x Var.Set.empty
315-
| Set_field (x, _, y) ->
315+
| Set_field (x, _, _, y) ->
316316
Var.Set.empty
317317
|> check_spilled ~ctx loaded x
318318
|> check_spilled ~ctx loaded y

0 commit comments

Comments
 (0)