Improve unboxing during cmm for Flambda#295
Conversation
7079df6 to
b543137
Compare
|
Do we need all that machinery ? Your example gets unboxed as expected with Closure, so I would expect that the solution would be to add value_kind annotations on Flambda lets. Do you have other examples that benefit from the extra annotations, in particular with Closure ? |
|
(Disclaimer: I'm familiar with the idea of this PR, but haven't read the code yet)
Trying to ensure that all I think it should be possible to produce some examples that don't unbox on closure without this PR. They aren't going to be common pieces of code though. Something like: module Foo : sig
type t
val create : unit -> t
val add : t -> t -> t
end = struct
type t = float
let create () = 0.0
let add = (+.)
end
type _ foo_or_float =
| Foo : Foo.t foo_or_float
| Float : float foo_or_float
let bar (type a) p (witness : a foo_or_float) (x : float) (y : float) : a =
let z : a =
match witness with
| Foo -> Foo.create ()
| Float ->
if p then x +. y
else y
in
match witness with
| Foo -> Foo.add z z
| Float -> z +. zI would expect |
|
I'm not completely convinced that it makes sense to spend time reviewing such a big patch when Flambda 2 already does the job correctly, but at least I understand why this patch is useful, thanks. |
lpw25
left a comment
There was a problem hiding this comment.
Most of this looks good, but I think the changes in cmmgen.ml are much more invasive than they need to be.
9cb7d4c to
819b3d6
Compare
lpw25
left a comment
There was a problem hiding this comment.
This is looking pretty good, just a few small things to address.
33fbb42 to
03f5b03
Compare
1269762 to
0c8d2eb
Compare
lthls
left a comment
There was a problem hiding this comment.
Approving for the Flambda 2 parts.
The kinds in To_cmm_helpers are dubious, but they're never used and as noted in To_cmm, the Cmm terms generated here never return anything unless it's a function return anyway.
5a29f0e to
ababce8
Compare
first version Remove unneeded changes from ocaml/ make fmt Fix tests Fix wrong kinds in lambda/ Move valuekind in the type switch for flambda Changed handling of [kind] inside backend More precise value_kind in translmod Add a value_kind on catch Fill a dummy value_kind in parsecmm Fix tests Code review ocamlformat Fix tests VVal -> Vval Fix tests Makes comprehension lists works Code review [Pseqor] and [Pseqand] are returning a Pintval
ababce8 to
7766f1f
Compare
64235a3 flambda-backend: Change Float.nan from sNaN to qNaN (oxcaml#466) 14a8e27 flambda-backend: Track GC work for all managed bigarray allocations (upstream 11022) (oxcaml#569) c3cda96 flambda-backend: Add two new methods to targetint for dwarf (oxcaml#560) e6f1fed flambda-backend: Handle arithmetic overflow in select_addr (oxcaml#570) dab7209 flambda-backend: Add Target_system to ocaml/utils (oxcaml#542) 82d5044 flambda-backend: Enhance numbers.ml with more primitive types (oxcaml#544) 216be99 flambda-backend: Fix flambda_o3 and flambda_oclassic attributes (oxcaml#536) 4b56e07 flambda-backend: Test naked pointer root handling (oxcaml#550) 40d69ce flambda-backend: Stop local function optimisation from moving code into function bodies; opaque_identity fixes for class compilation (oxcaml#537) f08ae58 flambda-backend: Implemented inlining history and use it inside inlining reports (oxcaml#365) ac496bf flambda-backend: Disable the local keyword in typing (oxcaml#540) 7d46712 flambda-backend: Bugfix for Typedtree generation of arrow types (oxcaml#539) 61a7b47 flambda-backend: Insert missing page table check in roots_nat.c (oxcaml#541) 323bd36 flambda-backend: Compiler error when -disable-all-extensions and -extension are used (oxcaml#534) d8956b0 flambda-backend: Persistent environment and reproducibility (oxcaml#533) 4a0c89f flambda-backend: Revert "Revert bswap PRs (480 and 482)" (oxcaml#506) 7803705 flambda-backend: Cause a C warning when CAMLreturn is missing in C stubs. (oxcaml#376) 6199db5 flambda-backend: Improve unboxing during cmm for Flambda (oxcaml#295) 96b9e1b flambda-backend: Print diagnostics at runtime for Invalid (oxcaml#530) 42ab88e flambda-backend: Disable bytecode compilers in ocamltest (oxcaml#504) 58c72d5 flambda-backend: Backport ocaml/ocaml#10595 from upstream/trunk (oxcaml#471) 1010539 flambda-backend: Use C++ name mangling convention (oxcaml#483) 81881bb flambda-backend: Local allocation test no longer relies on lifting (oxcaml#525) f5c4719 flambda-backend: Fix an assertion in Closure that breaks probes (oxcaml#505) c2cf2b2 flambda-backend: Add some missing command line arguments to ocamlnat (oxcaml#499) git-subtree-dir: ocaml git-subtree-split: 64235a3
64235a3 flambda-backend: Change Float.nan from sNaN to qNaN (#466) 14a8e27 flambda-backend: Track GC work for all managed bigarray allocations (upstream 11022) (#569) c3cda96 flambda-backend: Add two new methods to targetint for dwarf (#560) e6f1fed flambda-backend: Handle arithmetic overflow in select_addr (#570) dab7209 flambda-backend: Add Target_system to ocaml/utils (#542) 82d5044 flambda-backend: Enhance numbers.ml with more primitive types (#544) 216be99 flambda-backend: Fix flambda_o3 and flambda_oclassic attributes (#536) 4b56e07 flambda-backend: Test naked pointer root handling (#550) 40d69ce flambda-backend: Stop local function optimisation from moving code into function bodies; opaque_identity fixes for class compilation (#537) f08ae58 flambda-backend: Implemented inlining history and use it inside inlining reports (#365) ac496bf flambda-backend: Disable the local keyword in typing (#540) 7d46712 flambda-backend: Bugfix for Typedtree generation of arrow types (#539) 61a7b47 flambda-backend: Insert missing page table check in roots_nat.c (#541) 323bd36 flambda-backend: Compiler error when -disable-all-extensions and -extension are used (#534) d8956b0 flambda-backend: Persistent environment and reproducibility (#533) 4a0c89f flambda-backend: Revert "Revert bswap PRs (480 and 482)" (#506) 7803705 flambda-backend: Cause a C warning when CAMLreturn is missing in C stubs. (#376) 6199db5 flambda-backend: Improve unboxing during cmm for Flambda (#295) 96b9e1b flambda-backend: Print diagnostics at runtime for Invalid (#530) 42ab88e flambda-backend: Disable bytecode compilers in ocamltest (#504) 58c72d5 flambda-backend: Backport ocaml/ocaml#10595 from upstream/trunk (#471) 1010539 flambda-backend: Use C++ name mangling convention (#483) 81881bb flambda-backend: Local allocation test no longer relies on lifting (#525) f5c4719 flambda-backend: Fix an assertion in Closure that breaks probes (#505) c2cf2b2 flambda-backend: Add some missing command line arguments to ocamlnat (#499) git-subtree-dir: ocaml git-subtree-split: 64235a3
5b98caf flambda-backend: Revert "Restructure LIBDIR" (oxcaml#1093) 46f1b16 flambda-backend: Remove a stray character from dynlink Makefile (oxcaml#1090) e515442 flambda-backend: Restructure LIBDIR: Move Dynlink, Str and Unix to sub-directories (port PR#11198) (oxcaml#895) 9307e7c flambda-backend: inline fast path of caml_applyN (oxcaml#934) 3244386 flambda-backend: Bump magic numbers (oxcaml#1077) 7c9e15d flambda-backend: Fix bug in arguments to `get_unit_info` (oxcaml#1069) a2f4c9e flambda-backend: Closure rename static catch (oxcaml#1070) 2ee705a flambda-backend: Backport oxcaml#946 to ocaml/ subfolder (oxcaml#1061) 569703f flambda-backend: Merge ocaml-jst#97 (oxcaml#1063) 7b1779a flambda-backend: Port value_kind changes to testsuite/tools to fix parsecmm.mly (oxcaml#1060) 49505d1 flambda-backend: Bugfix for Ctype.nondep_type (oxcaml#1059) 654c63c flambda-backend: Backport oxcaml#295 kind changes to ocaml/ subfolder (oxcaml#1018) 50a9ce0 flambda-backend: Fix extern_closure_up_to_env (oxcaml#1053) bc2c78d flambda-backend: Remove obsolete pack-related code (oxcaml#1051) 872ff38 flambda-backend: Fix error-prone syntax resulting from reformatting (oxcaml#1050) d03b346 flambda-backend: Fix different .cmi files being produced by ocamlopt and ocamlc when using -pack (oxcaml#1049) 90ee37b flambda-backend: Revert "Revert "Use Import_info.t in Cmt_format"" (oxcaml#1045) ac12d90 flambda-backend: Fix version number (oxcaml#1043) 75e0154 flambda-backend: Revert "Use Import_info.t in Cmt_format" (oxcaml#1042) ecab74c flambda-backend: Use Import_info.t in Cmt_format (oxcaml#1037) 7661d4d flambda-backend: Bootstrap 1098a56 flambda-backend: Update .depend files a7292da flambda-backend: Revert ocaml/toplevel/native/dune 7584479 flambda-backend: Remove alloc-check from ocaml/ git-subtree-dir: ocaml git-subtree-split: 5b98caf
77434f0 flambda-backend: Bump magic numbers for 4.14.1-5 (oxcaml#1190) 3a78e83 flambda-backend: Revert "Instance compilation units" (oxcaml#1175) 9a683c9 flambda-backend: Move compute_layout to Lambda (oxcaml#1167) 0ea58e9 flambda-backend: Revert "Add a proper top and bottom layout" (oxcaml#1169) 1e5e23a flambda-backend: Add hint for common misplaced [@unboxed] attribute (oxcaml#1164) 10f870a flambda-backend: Add a proper top and bottom layout (oxcaml#1158) d1be563 flambda-backend: Don't warn about misplaced attributes in -i mode (oxcaml#1163) feefcaa flambda-backend: Remove immutable arrays from stdlib.ml and stdlib.mli (oxcaml#1154) ba101be flambda-backend: Shrink the ref_table if it grows large (oxcaml#1156) 777fda7 flambda-backend: Preserve backtraces from failing `Lazy_backtrack` computations (oxcaml#805) 56d014e flambda-backend: Remove remaining `layout_top` after oxcaml#1084 (oxcaml#1138) dc1c1ce flambda-backend: Layouts for parameters in lambda & remove most layout_top (oxcaml#1084) 49fea78 flambda-backend: Instance compilation units (oxcaml#1113) 1127fd2 flambda-backend: Merge pull request oxcaml#1143 from riaqn/merge-ocaml-jst f458733 flambda-backend: fix things after merge b43d385 flambda-backend: File magic updates (oxcaml#306) 9f604aa flambda-backend: Merge ocaml-jst 1f54613 flambda-backend: More assertions for local alloc and letrec (oxcaml#1081) 0c95280 flambda-backend: Remove most layout_top in closure (oxcaml#1127) 8ad48b5 flambda-backend: Use only `.ocamlformat*` to enable or disable ocamlformat (oxcaml#1135) 1aa2885 flambda-backend: Build all boot targets in `make hacking` (oxcaml#1133) 6b6c25a flambda-backend: Hide `Compilation_unit.t`'s definition in a submodule (oxcaml#1134) 529d66b flambda-backend: Compile refactor (oxcaml#1096) df798c1 flambda-backend: Propagates layouts through Flambda1 (oxcaml#1115) 9bce50b flambda-backend: Add `gc-timings` to collect timing information from the GC (oxcaml#1089) d431d3b flambda-backend: Use the type of primitive declarations to make their layout (oxcaml#1118) 8da887e flambda-backend: Changes to arity in clambda (oxcaml#1106) db20e97 flambda-backend: Fix simplify-exits (oxcaml#1108) 6a63906 flambda-backend: Add layout on Lregion (oxcaml#1107) c562fb3 flambda-backend: caml_{curry,apply,send}* for unboxed types (oxcaml#1104) 50ee311 flambda-backend: Temporary fix for incorrect layout for result of custom and operators (oxcaml#1119) c89512d flambda-backend: More error checking for natdynlink symbols (oxcaml#1005) 27d68bf flambda-backend: Flambda1 region deletion and locals fixes (oxcaml#1000) 0e3e057 flambda-backend: Add identifiers for instantiated functor units (oxcaml#1092) 4b75b46 flambda-backend: Fix build system under ocaml/runtime (oxcaml#1085) 7c9fc32 flambda-backend: Fix valid character range computation for compilation units (oxcaml#1110) 40c754a flambda-backend: Add result layout in Lapply and Lsend (oxcaml#1102) cedaea1 flambda-backend: Add layout type in Lambda (oxcaml#1032) 47c0e23 flambda-backend: Configure: Add flag to use legacy library layout (oxcaml#1098) eed5888 flambda-backend: Restructure LIBDIR: Move Dynlink, Str and Unix to sub-directories (port part of ocaml/PR11198) (oxcaml#1094) 5b98caf flambda-backend: Revert "Restructure LIBDIR" (oxcaml#1093) 46f1b16 flambda-backend: Remove a stray character from dynlink Makefile (oxcaml#1090) e515442 flambda-backend: Restructure LIBDIR: Move Dynlink, Str and Unix to sub-directories (port PR#11198) (oxcaml#895) 9307e7c flambda-backend: inline fast path of caml_applyN (oxcaml#934) 3244386 flambda-backend: Bump magic numbers (oxcaml#1077) 7c9e15d flambda-backend: Fix bug in arguments to `get_unit_info` (oxcaml#1069) a2f4c9e flambda-backend: Closure rename static catch (oxcaml#1070) 2ee705a flambda-backend: Backport oxcaml#946 to ocaml/ subfolder (oxcaml#1061) 569703f flambda-backend: Merge ocaml-jst#97 (oxcaml#1063) 7b1779a flambda-backend: Port value_kind changes to testsuite/tools to fix parsecmm.mly (oxcaml#1060) 49505d1 flambda-backend: Bugfix for Ctype.nondep_type (oxcaml#1059) 654c63c flambda-backend: Backport oxcaml#295 kind changes to ocaml/ subfolder (oxcaml#1018) 50a9ce0 flambda-backend: Fix extern_closure_up_to_env (oxcaml#1053) bc2c78d flambda-backend: Remove obsolete pack-related code (oxcaml#1051) 872ff38 flambda-backend: Fix error-prone syntax resulting from reformatting (oxcaml#1050) d03b346 flambda-backend: Fix different .cmi files being produced by ocamlopt and ocamlc when using -pack (oxcaml#1049) 90ee37b flambda-backend: Revert "Revert "Use Import_info.t in Cmt_format"" (oxcaml#1045) ac12d90 flambda-backend: Fix version number (oxcaml#1043) 75e0154 flambda-backend: Revert "Use Import_info.t in Cmt_format" (oxcaml#1042) ecab74c flambda-backend: Use Import_info.t in Cmt_format (oxcaml#1037) 7661d4d flambda-backend: Bootstrap 1098a56 flambda-backend: Update .depend files a7292da flambda-backend: Revert ocaml/toplevel/native/dune 7584479 flambda-backend: Remove alloc-check from ocaml/ git-subtree-dir: ocaml git-subtree-split: 77434f0
bcae5ff flambda-backend: Bump buffer size to avoid gcc warning (#1247) d6c170b flambda-backend: Remove `-absname` to improve dune build errors (#1233) 1b2bcb4 flambda-backend: Put frametables in .text with relative offsets for return addresses. (#1227) 999d523 flambda-backend: Small optimisation for caml_modify (#1226) b16493b flambda-backend: Add timestamps to GC logs (#1229) 95f7e80 flambda-backend: Provide a no-naked-pointers runtime and use it for the compiler (#1224) ba77581 flambda-backend: Replace assertion with a match statement (#1225) cfb3cd2 flambda-backend: Memoise last substitution composition (#1209) 1c4db44 flambda-backend: Port PR1202 and PR1205 to the ocaml/ subtree (#1211) 577410e flambda-backend: Correctly stack debuginfo for inlined body in classic mode (#1152) 6733de6 flambda-backend: Fix dune install in otherlibs: missing cmt and typo. (#1194) 4c97d26 flambda-backend: Unboxed numbers (#1165) 1ad7252 flambda-backend: Revert "Revert "Add a proper top and bottom layout" (#1169)" (#1191) dea4b3e flambda-backend: Don't get the layout of arguments from patterns (#1179) 6d3e85b flambda-backend: Don't copy when resolving aliases in try_modtypes (#1184) 73e52b7 flambda-backend: Clarify the types used for static jump/catch (#1180) 273a40d flambda-backend: Reenable backtrace testsuite folder for flambda2 (#1161) 77434f0 flambda-backend: Bump magic numbers for 4.14.1-5 (#1190) 3a78e83 flambda-backend: Revert "Instance compilation units" (#1175) 9a683c9 flambda-backend: Move compute_layout to Lambda (#1167) 0ea58e9 flambda-backend: Revert "Add a proper top and bottom layout" (#1169) 1e5e23a flambda-backend: Add hint for common misplaced [@unboxed] attribute (#1164) 10f870a flambda-backend: Add a proper top and bottom layout (#1158) d1be563 flambda-backend: Don't warn about misplaced attributes in -i mode (#1163) feefcaa flambda-backend: Remove immutable arrays from stdlib.ml and stdlib.mli (#1154) ba101be flambda-backend: Shrink the ref_table if it grows large (#1156) 777fda7 flambda-backend: Preserve backtraces from failing `Lazy_backtrack` computations (#805) 56d014e flambda-backend: Remove remaining `layout_top` after #1084 (#1138) dc1c1ce flambda-backend: Layouts for parameters in lambda & remove most layout_top (#1084) 49fea78 flambda-backend: Instance compilation units (#1113) 1127fd2 flambda-backend: Merge pull request #1143 from riaqn/merge-ocaml-jst f458733 flambda-backend: fix things after merge b43d385 flambda-backend: File magic updates (#306) 9f604aa flambda-backend: Merge ocaml-jst 1f54613 flambda-backend: More assertions for local alloc and letrec (#1081) 0c95280 flambda-backend: Remove most layout_top in closure (#1127) 8ad48b5 flambda-backend: Use only `.ocamlformat*` to enable or disable ocamlformat (#1135) 1aa2885 flambda-backend: Build all boot targets in `make hacking` (#1133) 6b6c25a flambda-backend: Hide `Compilation_unit.t`'s definition in a submodule (#1134) 529d66b flambda-backend: Compile refactor (#1096) df798c1 flambda-backend: Propagates layouts through Flambda1 (#1115) 9bce50b flambda-backend: Add `gc-timings` to collect timing information from the GC (#1089) d431d3b flambda-backend: Use the type of primitive declarations to make their layout (#1118) 8da887e flambda-backend: Changes to arity in clambda (#1106) db20e97 flambda-backend: Fix simplify-exits (#1108) 6a63906 flambda-backend: Add layout on Lregion (#1107) c562fb3 flambda-backend: caml_{curry,apply,send}* for unboxed types (#1104) 50ee311 flambda-backend: Temporary fix for incorrect layout for result of custom and operators (#1119) c89512d flambda-backend: More error checking for natdynlink symbols (#1005) 27d68bf flambda-backend: Flambda1 region deletion and locals fixes (#1000) 0e3e057 flambda-backend: Add identifiers for instantiated functor units (#1092) 4b75b46 flambda-backend: Fix build system under ocaml/runtime (#1085) 7c9fc32 flambda-backend: Fix valid character range computation for compilation units (#1110) 40c754a flambda-backend: Add result layout in Lapply and Lsend (#1102) cedaea1 flambda-backend: Add layout type in Lambda (#1032) 47c0e23 flambda-backend: Configure: Add flag to use legacy library layout (#1098) eed5888 flambda-backend: Restructure LIBDIR: Move Dynlink, Str and Unix to sub-directories (port part of ocaml/PR11198) (#1094) 5b98caf flambda-backend: Revert "Restructure LIBDIR" (#1093) 46f1b16 flambda-backend: Remove a stray character from dynlink Makefile (#1090) e515442 flambda-backend: Restructure LIBDIR: Move Dynlink, Str and Unix to sub-directories (port PR#11198) (#895) 9307e7c flambda-backend: inline fast path of caml_applyN (#934) 3244386 flambda-backend: Bump magic numbers (#1077) 7c9e15d flambda-backend: Fix bug in arguments to `get_unit_info` (#1069) a2f4c9e flambda-backend: Closure rename static catch (#1070) 2ee705a flambda-backend: Backport #946 to ocaml/ subfolder (#1061) 569703f flambda-backend: Merge ocaml-jst#97 (#1063) 7b1779a flambda-backend: Port value_kind changes to testsuite/tools to fix parsecmm.mly (#1060) 49505d1 flambda-backend: Bugfix for Ctype.nondep_type (#1059) 654c63c flambda-backend: Backport #295 kind changes to ocaml/ subfolder (#1018) 50a9ce0 flambda-backend: Fix extern_closure_up_to_env (#1053) bc2c78d flambda-backend: Remove obsolete pack-related code (#1051) 872ff38 flambda-backend: Fix error-prone syntax resulting from reformatting (#1050) d03b346 flambda-backend: Fix different .cmi files being produced by ocamlopt and ocamlc when using -pack (#1049) 90ee37b flambda-backend: Revert "Revert "Use Import_info.t in Cmt_format"" (#1045) ac12d90 flambda-backend: Fix version number (#1043) 75e0154 flambda-backend: Revert "Use Import_info.t in Cmt_format" (#1042) ecab74c flambda-backend: Use Import_info.t in Cmt_format (#1037) 7661d4d flambda-backend: Bootstrap 1098a56 flambda-backend: Update .depend files a7292da flambda-backend: Revert ocaml/toplevel/native/dune 7584479 flambda-backend: Remove alloc-check from ocaml/ git-subtree-dir: ocaml git-subtree-split: bcae5ff
Cmm was able to unbox some values thanks to the
value_kindput onlet. However, only putting thevalue_kindonletis not enough and on some simple example the heuristic would fail.For example, the following example:
Was compiling into:
Instead of
This PR adds a
value_kindon all join points that is then used to decide if a value should be unboxed on some let statements.