Introducing the Machine IR
In Chapter 1, we mentioned that an LLVM backend mainly deals with two levels of IR:
- The LLVM IR for high-level optimizations
- The Machine IR for low-level optimizations and the lowering of the LLVM IR to assembly code
As you saw in Chapter 9, the LLVM IR can represent target-specific constructs. Therefore, you might be wondering whether we need two different IRs.
We aren’t going to reiterate the history of the LLVM project here, so let’s just say that the LLVM IR isn’t flexible enough. One of the obvious issues is that target architectures don’t operate on the static single assignment (SSA) form. The SSA form guided a lot of the design decisions of the LLVM IR and departing from it would have dramatic effects on the application programming interface (API) of the core library of the LLVM infrastructure.
The Machine IR embraces the concept of flexibility. It supports both SSA and non-SSA forms and...