[PATCH] D99472: [OCaml] Minor optimizations by avoiding double initialization

Josh Berdine via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 28 15:30:29 PDT 2021


jberdine created this revision.
jberdine added a reviewer: vaivaswatha.
Herald added a reviewer: whitequark.
jberdine requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

In several functions an OCaml block is allocated and no further OCaml
allocation functions (or other functions that might trigger allocation
or collection) are performed before the block is fully initialized. In
these cases, it is safe and slightly more efficient to allocate an
uninitialized block.

Also, the code does not become more complex after the non-initializing
allocation, since in the case that a non-small allocation is made, the
initial values stored are definitely not pointers to OCaml young
blocks, and so initializing via direct assignment is still safe. That
is, in general if `caml_alloc_small` is called, initializing it with
direct assignments is safe, but if `caml_alloc_shr` is
called (e.g. for a block larger than `Max_young_wosize`), then
`caml_initialize` should be called to inform the GC of a potential
major to minor pointer. But if the initial value is definitely not a
young OCaml block, direct assignment is safe.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99472

Files:
  llvm/bindings/ocaml/llvm/llvm_ocaml.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99472.333739.patch
Type: text/x-patch
Size: 5974 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210328/08af9947/attachment.bin>


More information about the llvm-commits mailing list