Skip to content

Commit 4bad3ae

Browse files
authored
Merge pull request swiftlang#30727 from gottesmm/debugging-compiler-dumping-sil
[debugging-the-compiler] Add more details to Dumping SIL section and explain how to easily extract cmdline for the stdlib to use with those options when building with Ninja.
2 parents 026b8b3 + 2b8fec5 commit 4bad3ae

File tree

1 file changed

+60
-16
lines changed

1 file changed

+60
-16
lines changed

docs/DebuggingTheCompiler.rst

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -164,22 +164,66 @@ Debugging on SIL Level
164164
Options for Dumping the SIL
165165
~~~~~~~~~~~~~~~~~~~~~~~~~~~
166166

167-
Often it is not sufficient to dump the SIL at the beginning or end of the
168-
optimization pipeline.
169-
The SILPassManager supports useful options to dump the SIL also between
170-
pass runs.
171-
172-
The option ``-Xllvm -sil-print-all`` dumps the whole SIL module after all
173-
passes. Although it prints only functions which were changed by a pass, the
174-
output can get *very* large.
175-
176-
It is useful if you identified a problem in the final SIL and you want to
177-
check which pass did introduce the wrong SIL.
178-
179-
There are several other options available, e.g. to filter the output by
180-
function names (``-Xllvm -sil-print-only-function``/``s``) or by pass names
181-
(``-Xllvm -sil-print-before``/``after``/``around``).
182-
For details see ``PassManager.cpp``.
167+
Often it is not sufficient to dump the SIL at the beginning or end of
168+
the optimization pipeline. The SILPassManager supports useful options
169+
to dump the SIL also between pass runs.
170+
171+
The SILPassManager's SIL dumping options vary along two orthogonal
172+
functional axes:
173+
174+
1. Options that control if functions/modules are printed.
175+
2. Options that filter what is printed at those points.
176+
177+
One generally always specifies an option of type 1 and optionally adds
178+
an option of type 2 to filter the output.
179+
180+
A short (non-exhaustive) list of type 1 options:
181+
182+
* ``-Xllvm -sil-print-all``: Print functions/modules when ever a
183+
function pass modifies a function and Print the entire module
184+
(modulo filtering) if a module pass modifies a SILModule.
185+
186+
A short (non-exhaustive) list of type 2 options:
187+
188+
* ``-Xllvm -sil-print-around=$PASS_NAME``: Print a function/module
189+
before and after a function pass with name ``$PASS_NAME`` runs on a
190+
function/module or dump a module before a module pass with name
191+
``$PASS_NAME`` runs on a module.
192+
193+
* ``-Xllvm -sil-print-before=$PASS_NAME``: Print a function/module
194+
before a function pass with name ``$PASS_NAME`` runs on a
195+
function/module or dump a module before a module pass with name
196+
``$PASS_NAME`` runs on a module. NOTE: This happens even without
197+
sil-print-all set!
198+
199+
* ``-Xllvm -sil-print-after=$PASS_NAME``: Print a function/module
200+
after a function pass with name ``$PASS_NAME`` runs on a
201+
function/module or dump a module before a module pass with name
202+
``$PASS_NAME`` runs on a module.
203+
204+
* ``-Xllvm '-sil-print-only-function=SWIFT_MANGLED_NAME'``: When ever
205+
one would print a function/module, only print the given function.
206+
207+
These options together allow one to visualize how a
208+
SILFunction/SILModule is optimized by the optimizer as each
209+
optimization pass runs easily via formulations like::
210+
211+
swiftc -Xllvm '-sil-print-only-function=$myMainFunction' -Xllvm -sil-print-all
212+
213+
NOTE: This may emit a lot of text to stderr, so be sure to pipe the
214+
output to a file.
215+
216+
Getting CommandLine for swift stdlib from Ninja
217+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
218+
219+
If one builds swift using ninja and wants to dump the SIL of the
220+
stdlib using some of the SIL dumping options from the previous
221+
section, one can use the following one-liner::
222+
223+
ninja -t commands | grep swiftc | grep Swift.o | grep " -c "
224+
225+
This should give one a single command line that one can use for
226+
Swift.o, perfect for applying the previous sections options to.
183227

184228
Dumping the SIL and other Data in LLDB
185229
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)