[PATCH] D136400: [llvm-ocaml] Migrate from naked pointers to prepare for OCaml 5

Alan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 23 00:46:06 PDT 2022


alan added a comment.

The original binding code on the main branch often skipped using `CAMLparamX` and `CAMLreturn` because many of the functions did not manipulate OCaml heap objects. When converting the bindings to eliminate naked pointers, I followed all the rules at https://v2.ocaml.org/manual/intfc.html because I assumed that `to_val` might allocate on the OCaml heap. Now, I have a stacked diff at https://reviews.llvm.org/D136537 that assumes that all pointers that LLVM provides OCaml are at least 2-bit aligned, and therefore don't require an allocation on the OCaml heap. This diff also:

- Skips `CAMLparamX` and `CAMLreturn` entirely if the function does not allocate on the OCaml heap
- Only registers OCaml boxed values with `CAMLparamX` (i.e. it does not pass an int or a bool to `CAMLparamX`)

The code passes all tests on OCaml 5.0~beta1. This stacked diff is therefore closer to the original code on the main branch. However, it relies on more assumptions that could possibly change, or I may have gotten wrong, so it is more brittle. I will leave it up to the reviewers to decide if the performance benefit is worth these changes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136400/new/

https://reviews.llvm.org/D136400



More information about the llvm-commits mailing list