Instruction Selection
The SelectionDAG
at this phase is optimized and legalized. However, the instructions are still not in machine code form. These instructions need to be mapped to architecture-specific instructions in the SelectionDAG
itself. The TableGen
class helps select target-specific instructions.
The CodeGenAndEmitDAG()
function calls the DoInstructionSelection()
function that visits each DAG node and calls the Select() function for each node. The Select()
function is the main hook targets implement to select a node. The Select()
function is a virtual method to be implemented by the targets.
For consideration, assume our target architecture is X86. The X86DAGToDAGISel::Select()
function intercepts some nodes for manual matching, but delegates the bulk of the work to the X86DAGToDAGISel::SelectCode()
function. The X86DAGToDAGISel::SelectCode()
function is auto generated by TableGen
. It contains the matcher table, followed by a call to the generic SelectionDAGISel::SelectCodeCommon...