Skip to content

Commit

Permalink
WSOO side of "Distinguish float field accesses in the Code IR"
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierNicole committed Sep 12, 2024
1 parent 9a98cb1 commit 55281a8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
17 changes: 15 additions & 2 deletions compiler/lib/wasm/wa_generate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ module Generate (Target : Wa_target_sig.S) = struct
return (W.Call (apply, args @ [ closure ]))
| Block (tag, a, _, _) ->
Memory.allocate stack_ctx x ~tag (List.map ~f:(fun x -> `Var x) (Array.to_list a))
| Field (x, n) -> Memory.field (load x) n
| Field (x, n, Non_float) -> Memory.field (load x) n
| Field (x, n, Float) ->
Memory.float_array_get
(load x)
(Constant.translate (Int (Int31.of_int_warning_on_overflow n)))
| Closure _ ->
Closure.translate
~context:ctx.global_context
Expand Down Expand Up @@ -668,7 +672,16 @@ module Generate (Target : Wa_target_sig.S) = struct
if ctx.live.(Var.idx x) = 0
then drop (translate_expr ctx stack_ctx context x e)
else store x (translate_expr ctx stack_ctx context x e)
| Set_field (x, n, y) -> Memory.set_field (load x) n (load y)
| Set_field (x, n, Non_float, y) ->
Memory.set_field
(load x)
n
(load y)
| Set_field (x, n, Float, y) ->
Memory.float_array_set
(load x)
(Constant.translate (Int (Int31.of_int_warning_on_overflow n)))
(load y)
| Offset_ref (x, n) ->
Memory.set_field
(load x)
Expand Down
4 changes: 2 additions & 2 deletions compiler/lib/wasm/wa_globalize.ml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ let traverse_expression x e st =
| Code.Apply { f; args; _ } ->
st |> use f |> fun st -> List.fold_left ~f:(fun st x -> use x st) ~init:st args
| Block (_, a, _, _) -> Array.fold_right ~f:use a ~init:st
| Field (x, _) -> st |> use x
| Field (x, _, _) -> st |> use x
| Closure _ ->
List.fold_left
~f:(fun st x -> use x st)
Expand All @@ -95,7 +95,7 @@ let traverse_instruction st i =
match fst i with
| Code.Let (x, e) -> st |> declare x |> traverse_expression x e
| Assign (_, x) | Offset_ref (x, _) -> st |> use x
| Set_field (x, _, y) -> st |> use x |> use y
| Set_field (x, _, _, y) -> st |> use x |> use y
| Array_set (x, y, z) -> st |> use x |> use y |> use z

let traverse_block p st pc =
Expand Down
4 changes: 2 additions & 2 deletions compiler/lib/wasm/wa_liveness.ml
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ let expr_used ~context ~closures ~ctx x e s =
| Prim (_, l) -> add_prim_args ~ctx s l
| Closure _ -> add_list ~ctx s (function_free_variables ~context ~closures x)
| Constant _ | Special _ -> s
| Field (x, _) -> add_var ~ctx s x
| Field (x, _, _) -> add_var ~ctx s x

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

Expand Down
4 changes: 2 additions & 2 deletions compiler/lib/wasm/wa_spilling.ml
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,10 @@ let spilled_variables
fv
~init:Var.Set.empty
| Constant _ | Special _ -> Var.Set.empty
| Field (x, _) -> check_spilled ~ctx loaded x Var.Set.empty)
| Field (x, _, _) -> check_spilled ~ctx loaded x Var.Set.empty)
| Assign (_, x) | Offset_ref (x, _) ->
check_spilled ~ctx loaded x Var.Set.empty
| Set_field (x, _, y) ->
| Set_field (x, _, _, y) ->
Var.Set.empty
|> check_spilled ~ctx loaded x
|> check_spilled ~ctx loaded y
Expand Down

0 comments on commit 55281a8

Please sign in to comment.