[llvm-dev] Where to define a new library routine in LLVM framework?

Mehdi Amini via llvm-dev llvm-dev at lists.llvm.org
Tue Aug 23 17:59:48 PDT 2016


> On Aug 22, 2016, at 4:50 PM, Dounia Khaldi via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 
> 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…).

— 
Mehdi



More information about the llvm-dev mailing list