Swift: Analyze SIL Optimizations

Yeskendir Salgara
Kerege
Published in
13 min readNov 24, 2023

--

This analysis is useful if you need to get a detailed insight into the optimizer passes, their effect on the SIL code, compile times, compiler’s memory consumption, etc.

This article describes how you can collect and analyze the counters produced by the optimizer of the Swift compiler. You can find out which optimization passes or phases of optimization produce most new SIL instructions or delete most SIL functions.

Content:

  • Practice, practice, practice.
  • Theory, theory, theory.

It is possible by means of providing some special command-line options to ask the Swift compiler to produce different statistics about the optimizer counters. Optimizer counters are most typically counters representing different aspects of a SIL representation for a Swift module being compiled, e.g. the number of SIL basic blocks or instructions. These counters may also reveal some details about transformations and optimizations performed on SIL, e.g. the duration of an optimization or how much memory was consumed by the compiler. Therefore having the information about the changes of optimizer counters over time allows for analysis of changes to the SIL representation during the compilation.

The following statistics can be recorded:

  • For SILFunctions: the…

--

--