2
votes

I've recently started using LLVM IR generation APIs for my project. The documentation and LLC tool are pretty helpful, but I haven't been able to find answer to the following -

Question-1 - Pointer ownership semantics

All code that creates LLVM IR instructions using their APIs seems to "new" instructions instead of creating them as stack variables.

auto x = new Alloca(...) vs. Alloca(...) x;

I am wondering what the ownership semantics are for the pointers that are created? Do I have to call delete on these instruction objects. All code that I've seen calls "delete engine;".

I am guessing that all this memory is owned by this Module object and when the module is destroyed, all the memory occupied by these instructions are also destroyed. By looking at some of the code, it seems that all these instruction objects are created by using "placement new" ... Is this understanding correct?

Question-2 - Why doe LLVM IR APIs take "unsigned" data-type args. (e.g. unsigned addresspace is one common argument. Why not a sized type like uint32_t ?)

Question-3 - How to attach debug information to an IR instruction? Pointers to LLVM APIs to attach debug info would be really useful.

1

1 Answers

2
votes

It's probably best to split this up into 3 questions, but to answer the 3rd question I did a talk at this year's US LLVM Developer Conference on exactly this:

http://llvm.org/devmtg/2014-10/#tutorial3

and you can also use the documentation I wrote after as a guideline:

http://llvm.org/docs/tutorial/LangImpl8.html