Code emission
The code emission phase lowers the code from code generator abstractions (such as MachineFunction class, MachineInstr class, and so on) to machine code layer abstractions (MCInst class, MCStreamer class, and so on). The important classes in this phase are the target-independent AsmPrinter class, target-specific subclasses of AsmPrinter, and the TargetLoweringObjectFile class.
The MC layer is responsible for emitting object files, which consist of labels, directives, and instructions; while the CodeGen layer consists of MachineFunctions, MachineBasicBlock and MachineInstructions. A key class used at this point in time is the MCStreamer class, which consists of assembler APIs. The MCStreamer class has functions such as EmitLabel, EmitSymbolAttribute, SwitchSection, and so on, which directly correspond to the aforementioned assembly-level directives.
There are four important things that need to be implemented for the target in order to emit code:
Define a subclass of the
AsmPrinter...