How do I understand LLVM class abstraction better?

I haven’t spent any “formal” effort to learn LLVM so far, trying to learn by example. However, the downside is, I struggle with comprehending the semantics of the abstraction provided by several LLVM classes often times. The documentation is miserable. Do you have any suggestion for me to lower the learning threshold? Do seasoned LLVM programmers have faced such problems in early days, or is it the lack of systematic reading that’s troubling me?

I found the Kaleidoscope example a rather good way to learn what I needed (I basically started writing a compiler using the example of Kaleidoscope, and then extended and added more code to eventually have a complete Pascal compiler). Once you get far enough into the project, you can usually formulate a clear & concise enough question for this mailing list or the LLVM chat to get a good answer. And learn “when in doubt, alloca” :wink:

However, LLVM is a VERY large set of code, and to understand all of it, and the subtle differences between variants (“When is a ConstantValue not a compile-time constant?”) that initially appear to be “the same”, in some cases, is really not easy. And I’m not sure there is any good answer to “how to do that”.

I wouldn’t even begin to suggest that I actually know ALL of LLVM, certainly not in great detail for everything - there’s a lot to do with Target and binary files that I’ve completely ignored besides “copy/modify from the relevant clang sources”.

Obviously, if you are not planning to write your own compiler (or work on someone else’s compiler project), then perhaps starting at Kaleidoscope is not necessarily the right way. If you explain what it is you’re trying to achieve (assuming it’s not writing a compiler), perhaps someone has a good suggestion…

Or try to grab books about LLVM (free or non-free) to get started. Doxygen [1] would help you
understand the class hierarchy better, too.

[1] http://llvm.org/doxygen/

HTH,
chenwj

Hi Dipanjan,

I have the same problems, so your are not alone. :wink:
Maybe reading this long and helpful discussion could help you:
http://lists.llvm.org/pipermail/llvm-dev/2017-May/112730.html

Advices I found out by others:
- Try to use the Clang compiler to convert very tiny C/C++ language programms into IR code and then try to figure out, how you can generate this IR code with the IR Builder classes.
- Try to write absolute exact and very, very compact emails to this LLVM mailing list. Use the keyword "[beginner]" in the email subject, so LLVM developers see it is a beginner question. If the question is very short, hopefully its easy to answered with no time of reading the full description of 30 sentences of the problem. :slight_smile:

Best regards,
Thomas