Selectors’ inner workings
As we mentioned, overall, the main selectors work the same way and go through three main phases: IR building, legalization, and selection. In practice, the way this materializes is slightly different for each selector.
Figure 14.2 captures the high-level workings of the two main selectors:

Figure 14.2: Inner workings of SelectionDAG and GlobalISel
The left-hand side of Figure 14.2 depicts the lowering phases of SDISel. All phases are part of one big MachineFunctionPass instance called SelectionDAGISelPass. SDISel runs these lowering phases once per basic block. You can see the three main phases of a selector: IR building, legalization, and selection represented respectively with the SelectionDAGBuilder, Legalize, and Select implementations. SDISel also features non-optional pre- and post-legalization optimizations called DAGCombiners. After the Select phase, SDISel needs to run a mandatory Schedule phase that takes the internal DAG...