3 ms·
As an addition to what others said: 'emitting' and the textual representation of LLVM IR may have put you on the wrong footing. The LLVM intermediate represent
by Someone 14y ago
As an addition to what others said: 'emitting' and the textual representation of LLVM IR may have put you on the wrong footing.
The LLVM intermediate representation is an in-memory data structure. Compilers can build that structure directly.
LLVM has code for serializing and deserializing that data structure. That makes it easier to debug optimization steps (for example, one can check a dead code elimination pass without having to look at CPU-specific things), makes it easier to wrote a compiler (a compiler can pipe the LLVM textual representation into LLVM tools), and also makes it easier for LLVM writers to discuss LLVM behavior.
For an example compiler, see http://llvm.org/docs/tutorial/LangImpl1.html http://llvm.org/docs/tutorial/LangImpl1.html? Section 3 shows how to directly emit the binary representation.
- StavrosK 14y agoThat's more or less what I got... The IR is similar to bytecode, isn't it?
- Someone 14y agoLLVM assembly and bytecode are both serializations of the intermediate representation. Using a somewhat loose definition, one could call all three of them IR, even though few tools would use assembly or bytecode as their internal representation of the code. Reading http://llvm.org/docs/CommandGuide/index.html#basic-commands http://llvm.org/docs/CommandGuide/index.html#basic-commands, llvm-as takes LLVM assembly to bytecode; llvm-dis does the reverse.
- wladimir 14y agoExactly. Internally, the data structure serialized as "LLVM bitcode" (or the textual equivalent) is a list of functions, each function represented by a Control Flow Graph of basic blocks. Each basic block contains runs of SSA (static single assignment) instructions without jumps and flow control (effectively a DAG of operations). There is also some basic data structure layout information. This representation is very handy for code generation, code analysis, and implementing optimization passes.