blob: 31cfaad4bfcf718c78c1b3a0af96b7e5a98a554d [file] [log] [blame]
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +00001opt - LLVM optimizer
2====================
3
James Hendersona0566842019-06-27 13:24:46 +00004.. program:: opt
5
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +00006SYNOPSIS
7--------
8
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +00009:program:`opt` [*options*] [*filename*]
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000010
11DESCRIPTION
12-----------
13
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +000014The :program:`opt` command is the modular LLVM optimizer and analyzer. It
15takes LLVM source files as input, runs the specified optimizations or analyses
16on it, and then outputs the optimized file or the analysis results. The
Renato Golin124f2592016-07-20 12:16:38 +000017function of :program:`opt` depends on whether the `-analyze` option is
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +000018given.
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000019
Renato Golin124f2592016-07-20 12:16:38 +000020When `-analyze` is specified, :program:`opt` performs various analyses
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +000021of the input source. It will usually print the results on standard output, but
22in a few cases, it will print output to standard error or generate a file with
23the analysis output, which is usually done when the output is meant for another
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000024program.
25
Renato Golin124f2592016-07-20 12:16:38 +000026While `-analyze` is *not* given, :program:`opt` attempts to produce an
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +000027optimized output file. The optimizations available via :program:`opt` depend
28upon what libraries were linked into it as well as any additional libraries
29that have been loaded with the :option:`-load` option. Use the :option:`-help`
30option to determine what optimizations you can use.
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000031
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +000032If ``filename`` is omitted from the command line or is "``-``", :program:`opt`
33reads its input from standard input. Inputs can be in either the LLVM assembly
34language format (``.ll``) or the LLVM bitcode format (``.bc``).
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000035
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +000036If an output filename is not specified with the :option:`-o` option,
37:program:`opt` writes its output to the standard output.
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000038
39OPTIONS
40-------
41
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +000042.. option:: -f
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000043
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +000044 Enable binary output on terminals. Normally, :program:`opt` will refuse to
45 write raw bitcode output if the output stream is a terminal. With this option,
46 :program:`opt` will write raw bitcode regardless of the output device.
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000047
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +000048.. option:: -help
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000049
50 Print a summary of command line options.
51
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +000052.. option:: -o <filename>
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000053
54 Specify the output filename.
55
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +000056.. option:: -S
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000057
58 Write output in LLVM intermediate language (instead of bitcode).
59
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +000060.. option:: -{passname}
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000061
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +000062 :program:`opt` provides the ability to run any of LLVM's optimization or
63 analysis passes in any order. The :option:`-help` option lists all the passes
64 available. The order in which the options occur on the command line are the
65 order in which they are executed (within pass constraints).
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000066
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +000067.. option:: -disable-inlining
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000068
Rafael Espindola11aaaee2014-10-16 20:00:02 +000069 This option simply removes the inlining pass from the standard list.
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000070
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +000071.. option:: -disable-opt
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000072
Renato Golin124f2592016-07-20 12:16:38 +000073 This option is only meaningful when `-std-link-opts` is given. It
Rafael Espindola11aaaee2014-10-16 20:00:02 +000074 disables most passes.
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000075
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +000076.. option:: -strip-debug
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000077
78 This option causes opt to strip debug information from the module before
Renato Golin124f2592016-07-20 12:16:38 +000079 applying other optimizations. It is essentially the same as `-strip`
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +000080 but it ensures that stripping of debug information is done first.
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000081
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +000082.. option:: -verify-each
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000083
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +000084 This option causes opt to add a verify pass after every pass otherwise
Renato Golin124f2592016-07-20 12:16:38 +000085 specified on the command line (including `-verify`). This is useful
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +000086 for cases where it is suspected that a pass is creating an invalid module but
Rafael Espindola11aaaee2014-10-16 20:00:02 +000087 it is not clear which pass is doing it.
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000088
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +000089.. option:: -stats
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000090
91 Print statistics.
92
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +000093.. option:: -time-passes
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000094
95 Record the amount of time needed for each pass and print it to standard
96 error.
97
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +000098.. option:: -debug
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000099
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +0000100 If this is a debug build, this option will enable debug printouts from passes
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000101 which use the ``LLVM_DEBUG()`` macro. See the `LLVM Programmer's Manual
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +0000102 <../ProgrammersManual.html>`_, section ``#DEBUG`` for more information.
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000103
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +0000104.. option:: -load=<plugin>
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000105
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +0000106 Load the dynamic object ``plugin``. This object should register new
107 optimization or analysis passes. Once loaded, the object will add new command
108 line options to enable various optimizations or analyses. To see the new
109 complete list of optimizations, use the :option:`-help` and :option:`-load`
110 options together. For example:
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000111
Dmitri Gribenkoa99fa5b2012-06-12 15:45:07 +0000112 .. code-block:: sh
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000113
114 opt -load=plugin.so -help
115
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +0000116.. option:: -p
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000117
118 Print module after each transformation.
119
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000120EXIT STATUS
121-----------
122
Dmitri Gribenko6c80bcb2012-11-29 19:02:50 +0000123If :program:`opt` succeeds, it will exit with 0. Otherwise, if an error
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000124occurs, it will exit with a non-zero value.