Where to define a new library routine in LLVM framework?

Hello,

I am working on a transformation pass that converts malloc operations into HBM specific allocations. Specifically, I generate a call to a new function that I called memkind_alloc (please don’t confuse it with memkind_malloc that is Intel specific library routine). The transformation has been successfully added to the compiler. However, I was not sure where to add the definition of this function.

The two options I can think of are:
(1) I create a new library for this and link it with LLVM.
(2) extending an existing LLVM runtime library such as compiler-rt. If this is the right/best option, Is compiler-rt the right place to add a new file that will contain my new function?

Please let me know your thoughts on this.

Thanks,

Hello,

I am working on a transformation pass that converts malloc operations into HBM specific allocations. Specifically, I generate a call to a new function that I called memkind_alloc (please don't confuse it with memkind_malloc that is Intel specific library routine). The transformation has been successfully added to the compiler. However, I was not sure where to add the definition of this function.

The two options I can think of are:
(1) I create a new library for this and link it with LLVM.

If you do that, the function will be present in the LLVM binary, but not in the binary *generated by LLVM*, which seems to be what you’re after.
It is possible to generate the function implementation in every Module where you need it in the transformation itself, but it needs to be done programmatically, which may not be ideal for your `memkind_alloc` (I don’t know what it does).

(2) extending an existing LLVM runtime library such as compiler-rt. If this is the right/best option, Is compiler-rt the right place to add a new file that will contain my new function?

Compiler-rt is usually the appropriate place for this kind of need: it is where where we put runtimes that need to be linked-in to the final binary for code generated by the compiler itself (Sanitizer, OpenMP, and other helpers…).