Introduction
The ultimate goal of a compiler is to produce a target code, or an assembly code that can be converted into object code and executed on the actual hardware. To generate the assembly code, the compiler needs to know the various aspects of the architecture of the target machine—the registers, instruction set, calling convention, pipeline, and so on. There are lots of optimizations that can be done in this phase as well.
LLVM has its own way of defining the target machine. It uses tablegen
to specify the target registers, instructions, calling convention, and so on. The tablegen
function eases the way we describe a large set of architecture properties in a programmatic way.
LLVM has a pipeline structure for the backend, where instructions travel through phases like this; from the LLVM IR to SelectionDAG
, then to MachineDAG
, then to MachineInstr
, and finally to MCInst
.
The IR is converted into SelectionDAG (DAG stands for Directed Acyclic Graph). Then SelectionDAG legalization occurs...