Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LLVM: intermediate bytecode vs binary

Tags:

llvm

clang

I'm confused about one aspect of LLVM:

For all the languages it supports, does it support compiling both to the intermediate code AND to straight binary?

For instance, if I write something in C, can LLVM (or Clang?) compile to either binary (like GCC) or intermediate code?

Or can only some languages be converted to intermediate? I guess it goes without saying that this intermediate requires some type of LLVM runtime? I never really hear bout the runtime, though.

like image 895
bob Avatar asked Apr 14 '26 09:04

bob


1 Answers

LLVM is a framework for manipulating LLVM IR (the "bytecode" you're alluding to) and lowering it to target-specific binaries (for example x86 machine code). Clang is a front-end for C/C++ (and Objective C) that translates these source languages into LLVM IR.

With this in mind, answering your questions:

For all the languages it supports, does it support compiling both to the intermediate code AND to straight binary?

LLVM can compile IR (intermediate code) to binary (or to assembly text).

For instance, if I write something in C, can LLVM (or Clang?) compile to either binary (like GCC) or intermediate code?

Yes. Clang can compile your code to a binary directly (using LLVM as a backend), or just emit LLVM IR if you want that.

Or can only some languages be converted to intermediate? I guess it goes without saying that this intermediate requires some type of LLVM runtime?

Theoretically, once you have LLVM IR, the LLVM library can convert it to binary. Some languages require a runtime (say Java, or Python), so any compiler from these languages to LLVM IR will have to provide a runtime in one way or another. LLVM has some support for connecting to such runtimes (for example - GC hooks) but carries no "runtime of its own". The only "runtime" project related to LLVM is compiler-rt, which provides fast implementations of some language/compiler builtins and intrinsics. It's mainly used for C/C++/Objective C. It's not officially part of LLVM, though full toolchains based on Clang often use it.

like image 104
Eli Bendersky Avatar answered Apr 16 '26 22:04

Eli Bendersky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!