Skip to content

Commit

Permalink
Tweak variable declaration reconstruction -- big code-gen quality imp…
Browse files Browse the repository at this point in the history
…rovement
  • Loading branch information
msprotz committed Feb 13, 2024
1 parent 5820d55 commit 818bcab
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions lib/Cleanup1.ml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ let remove_assignments = object(self)
with_type e.typ @@ close_now_over not_yet_closed (
(* We must now bind: *)
(count e) ++ (* whichever variables were in the condition *)
(AtomSet.inter (count e') (count e''))) (* variables that appear in both branches *)
AtomSet.empty) (* unlike below, we are in terminal position, so we do not need to
close immediately variables that appear in both branches -- we can simply declare them
twice in each branch! is this a better code-gen choice? yes, absolutely -- owing to
the structure of MIR, NOT doing this generates awful code *)
(fun not_yet_closed ->
EIfThenElse (self#visit_expr_w not_yet_closed e,
recurse_or_close not_yet_closed e',
Expand All @@ -98,12 +101,8 @@ let remove_assignments = object(self)
| ESwitch (e, branches) ->
with_type e.typ @@ close_now_over not_yet_closed (
(* We must now bind: *)
(count e) ++
(* i.e., whichever variables were in the condition *)
(Krml.KList.reduce AtomSet.inter (List.map (fun (_p, e) -> count e) branches)))
(* i.e., variables that appear in all branches -- note that
switches don't bind variables in their branches so it's simpler
than the match below*)
(count e) ++ (* i.e., whichever variables were in the condition *)
AtomSet.empty) (* see above *)
(fun not_yet_closed ->
ESwitch (
self#visit_expr_w not_yet_closed e,
Expand All @@ -113,11 +112,8 @@ let remove_assignments = object(self)
| EMatch (c, e, branches) ->
with_type e.typ @@ close_now_over not_yet_closed (
(* We must now bind: *)
(count e) ++
(* i.e., whichever variables were in the condition *)
(Krml.KList.reduce AtomSet.inter (List.map (fun (_bs, _p, e) -> count e) branches)))
(* i.e., variables that appear in all branches -- note that we
don't open _bs meaning that we don't collect bound variables in this branch *)
(count e) ++ (* i.e., whichever variables were in the condition *)
AtomSet.empty) (* see above *)
(fun not_yet_closed ->
EMatch (
c,
Expand Down

0 comments on commit 818bcab

Please sign in to comment.