Live data from Hacker News

How to learn compilers: LLVM Edition

lowlevelbits.org

21–28 of 28 posts

Re: How to learn compilers: LLVM Edition

#21

Earlier quoted context omitted.

In the Julia world, we make redistributable binaries for all sorts of things; you can find lots of packages here [0], and for LLVM in particular (which Julia uses to do its codegen) you can find _just_ libLLVM.so (plus a few supporting files) here [1]. If you want a more fully-featured, batteries-included build of LLVM, check out this package [2]. When using these JLL packages from Julia, it will automatically downlo…

I’ll take advantage of this comment to ask the tangential question: Where can i learn how llvm “compilation” works in Julia? I know code is only supposed to be JIT’ed and then executed by the runtime (that’s why PackageCompiler exists), but still I’d like to know more about how it works.. Like, if i write a simple pure function in Julia and call code_llvm on it… How “standalone” is the llvm code (if that is even a th…

> Like, if i write a simple pure function in Julia and call code_llvm on it… How “standalone” is the llvm code (if that is even a thing)? When does GC get called? How exactly does the generated code depend on the runtime?

It's standalone unless there's explicit calls to the runtime in it. The most common runtime support is probably heap allocation, so if you see a `jl_alloc_obj` in there, that gets lowered to runtime calls eventually. GC gets called during allocation if the runtime thinks there's been enough garbage generated to have a collection be worth it.

Re: How to learn compilers: LLVM Edition

#22

You could've mentioned Crafting Interpreters. It's an excellent book!!! (At least for the rest of us, mere mortals!)

I'd second this. Been a good read. Learnt a lot. Now I have a DSL for some really strange usecases and its been a blast. Never thought having an interpreter of my own would be so much fun.

Re: How to learn compilers: LLVM Edition

#23
post #22

You could've mentioned Crafting Interpreters. It's an excellent book!!! (At least for the rest of us, mere mortals!)

I'd second this. Been a good read. Learnt a lot. Now I have a DSL for some really strange usecases and its been a blast. Never thought having an interpreter of my own would be so much fun.

Cool! I just started reading it about a week ago, and almost having that feeling I had when I first learned how to program.

Re: How to learn compilers: LLVM Edition

#24

I have to say personally I find general program analysis (e.g. for security) a much more interesting topic than most vanilla compiler courses. For example I recently came across this course by the maintainers of soot: https://youtube.com/playlist?list=PLamk8lFsMyPXrUIQm5naAQ08a... Any pointers to similar courses much appreciated!

Thank you for YouTube link. I would of never found this and it looks like gold.

Re: How to learn compilers: LLVM Edition

#25

Earlier quoted context omitted.

In the Julia world, we make redistributable binaries for all sorts of things; you can find lots of packages here [0], and for LLVM in particular (which Julia uses to do its codegen) you can find _just_ libLLVM.so (plus a few supporting files) here [1]. If you want a more fully-featured, batteries-included build of LLVM, check out this package [2]. When using these JLL packages from Julia, it will automatically downlo…

I’ll take advantage of this comment to ask the tangential question: Where can i learn how llvm “compilation” works in Julia? I know code is only supposed to be JIT’ed and then executed by the runtime (that’s why PackageCompiler exists), but still I’d like to know more about how it works.. Like, if i write a simple pure function in Julia and call code_llvm on it… How “standalone” is the llvm code (if that is even a th…

To add to Keno's sibling comment, Julia, as a JIT compiler, essentially creates large chunks of standalone, "static" code, and runs those as much as it can, breaking out into the "dynamic" runtime when it has reached the limits of type inference or for some other reason needs to return to the runtime to perform dynamic dispatch etc... in these instances, we break out of the standalone code and start using the runtime to do things like determine where to jump next (or whether to compile another chunk of static code and jump to that). Note that these chunks of static code can be both smaller or larger than a function, it all depends on what Julia can compile in one go without needing to break out into the dynamic environment.

Re: How to learn compilers: LLVM Edition

#26

I have to say personally I find general program analysis (e.g. for security) a much more interesting topic than most vanilla compiler courses. For example I recently came across this course by the maintainers of soot: https://youtube.com/playlist?list=PLamk8lFsMyPXrUIQm5naAQ08a... Any pointers to similar courses much appreciated!

Anders Moeller and Michael Schwartzbach's book [1] on static program analysis is a fantastic resource, with (I think) a great balance of theory and practice. If you want to get really deep into the theory of program analysis, Patrick Cousot just published an incredibly thorough book on abstract interpretation (just got my copy this week, so haven't fully explored enough to have much of an opinion on it as a pedagogic…

Thanks, yes I've read the Moeller book and I agree with your evaluation. I wasn't aware of the Cousot book though, I'll be sure to check it out.

Re: How to learn compilers: LLVM Edition

#27

I have to say personally I find general program analysis (e.g. for security) a much more interesting topic than most vanilla compiler courses. For example I recently came across this course by the maintainers of soot: https://youtube.com/playlist?list=PLamk8lFsMyPXrUIQm5naAQ08a... Any pointers to similar courses much appreciated!

More program analysis & LLVM resources (books, courses, and talks): https://gist.github.com/MattPD/00573ee14bf85ccac6bed3c0678dd...

Re: How to learn compilers: LLVM Edition

#28

More great things: - https://c9x.me/compile/ - https://github.com/vnmakarov/mir

Thank you for posting these. I had seen and read about both of these before, and had been blown away by both of them -- but since had forgotten they existed!

  (For MIR overview, I recommend reading the Redhat blogposts mentioned in README rather than the README itself)
If I implement a language for learning purposes, I will implement it first in QBE and then MIR and then LLVM, and publish a retrospective analysis + comparison + thoughts.

I think that would make really interesting reading!

Post reply on HN