For writing a compiler, what are the advantages and disadvantages of using LLVM IR vs C for a target language? I know both are used, and I imagine that the final machine code would be similar if I were to use clang to compile the C. So what are other things to consider?
I've used LLVM IR for a few compiler back ends and have worked with compilers that use C as a back end. One thing that I found that gave the LLVM IR an advantage is that it is typed. It is hard to make completely ill-formed output without getting errors from the LLVM libraries.
It is also easier to keep a close correlation between the source code and the IR for debugging, in my opinion.
Plus, you get all the cool LLVM command line tools to analyse and process the IR your front end emits.
Architectures and OSes for which there is no CLANG obviously, or for which it is in an experimental state.
C is more widely accepted, but LLVM IR allows you to spoon feed the LLVM engine. Not all paths to IR are equal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With