Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Nobody actually programs in the IR of a compiler, except for (say) tests and debugging. The IR is not usually designed to be read to by humans, although LLVM is actually very readable (But still rather tedious).

If you looked at, just for an example, the IR used in the dmd d compiler, using (Walter Bright's) Digital Mars backend then you'd notice that the IR is not trivial to access at all. Last time I checked, you had to actually dive into the backend code (I'm pretty sure there's an undocumented flag/switch that I'm missing somewhere) to get the IR out of the compiler. In fairly sharp contrast to this, getting the IR (in a textual format!) is normally as simple as using -emit-llvm when compiling. This is part of the revolution (~Slight~ exaggeration) that LLVM brought about in compiler design: Compared to most other compilers, LLVM is designed to be very portable. The only compiler, of similar stature, like it is GCC. GCC is much better than it was, I'd imagine because of the competition from LLVM/Clang.

Tangent Aside: The LLVM IR textual format is not guaranteed to be stable at all. It's also not particularly nice to program in, and also it uses SSA form so it's not suitable for humane consumption. It looks like a high level programming language, but it really isn't. IR is designed to be generated, bullied and discard by the compiler.

If you want to punish yourself, the LLVM project does contain interpreters and compilers just for IR in a file. If I remember correctly, Clang will compile anything with a ?.ll? file as IR.

You can see all the optimisation passes in action here: https://godbolt.org/g/uZH3UD



"Nobody actually programs in the IR of a compiler"

It's called LISP. It is a niche style, I'll give you. ;)


:-). I think GCC has/had IR's that are LISP like.


Parts of the libraries for the Clover OpenCL implementation seem to be programmed in LLVM IR directly.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: