Code Emission
We started from LLVM IR in the first section and converted it to SelectioDAG
and then to MachineInstr
. Now, we need to emit this code. Currently, we have LLVM JIT and MC to do so. LLVM JIT is the traditional way of generating the object code for a target on the go directly in the memory. What we are more interested in is the LLVM MC layer.
The MC layer is responsible for generation of assembly file/object file from the MachineInstr
passed on to it from the previous step. In the MC Layer, the instructions are represented as MCInst
, which are lightweight, as in they don't carry much information about the program as MachineInstr
.
The code emission starts with the AsmPrinter
class, which is overloaded by the target specific AsmPrinter
class. This class deals with general lowering process by converting the MachineFunction
functions into MC label constructs by making use of the target specific MCInstLowering
interface(for x86 it is X86MCInstLower
class in the lib/Target/x86/X86MCInstLower...