1 ============================
2 Global Instruction Selection
3 ============================
6 This document is a work in progress. It reflects the current state of the
7 implementation, as well as open design and implementation issues.
16 GlobalISel is a framework that provides a set of reusable passes and utilities
17 for instruction selection --- translation from LLVM IR to target-specific
20 GlobalISel is intended to be a replacement for SelectionDAG and FastISel, to
21 solve three major problems:
23 * **Performance** --- SelectionDAG introduces a dedicated intermediate
24 representation, which has a compile-time cost.
26 GlobalISel directly operates on the post-isel representation used by the
27 rest of the code generator, MIR.
28 It does require extensions to that representation to support arbitrary
29 incoming IR: :ref:`gmir`.
31 * **Granularity** --- SelectionDAG and FastISel operate on individual basic
32 blocks, losing some global optimization opportunities.
34 GlobalISel operates on the whole function.
36 * **Modularity** --- SelectionDAG and FastISel are radically different and share
39 GlobalISel is built in a way that enables code reuse. For instance, both the
40 optimized and fast selectors share the :ref:`pipeline`, and targets can
41 configure that pipeline to better suit their needs.
43 Design and Implementation Reference
44 ===================================
46 More information on the design and implementation of GlobalISel can be found in
47 the following sections.
59 More information on specific passes can be found in the following sections:
72 Progress and Future Work
73 ========================
75 The initial goal is to replace FastISel on AArch64. The next step will be to
76 replace SelectionDAG as the optimized ISel.
79 While we iterate on GlobalISel, we strive to avoid affecting the performance of
80 SelectionDAG, FastISel, or the other MIR passes. For instance, the types of
81 :ref:`gmir-gvregs` are stored in a separate table in ``MachineRegisterInfo``,
82 that is destroyed after :ref:`instructionselect`.
84 .. _progress-fastisel:
89 For the initial FastISel replacement, we intend to fallback to SelectionDAG on
92 Currently, compile-time of the fast pipeline is within 1.5x of FastISel.
93 We're optimistic we can get to within 1.1/1.2x, but beating FastISel will be
94 challenging given the multi-pass approach.
95 Still, supporting all IR (via a complete legalizer) and avoiding the fallback
96 to SelectionDAG in the worst case should enable better amortized performance
97 than SelectionDAG+FastISel.
100 We considered never having a fallback to SelectionDAG, instead deciding early
101 whether a given function is supported by GlobalISel or not. The decision would
102 be based on :ref:`milegalizer` queries.
103 We abandoned that for two reasons:
104 a) on IR inputs, we'd need to basically simulate the :ref:`irtranslator`;
105 b) to be robust against unforeseen failures and to enable iterative