Instruction selection via the selection DAG
Creating machine instructions from the IR is a very important task in the backend. One common way to implement it is to utilize a DAG:
- First, we must create a DAG from the IR. A node of the DAG represents an operation and the edges model control and data flow dependencies.
- Next, we must loop over the DAG and legalize the types and operations. Legalization means that we only use types and operations that are supported by the hardware. This requires us to create a configuration that tells the framework how to deal with non-legal types and operations. For instance, a 64-bit value could be split into two 32-bit values, the multiplication of two 64-bit values could be changed to a library call, and a complex operation such as count population could be expanded into a sequence of simpler operations for calculating this value.
- After, pattern matching is utilized to match nodes in the DAG and replace them with machine instructions...