blob: 154edfdad331d6c7633327bbcf9b2926c769238b [file] [log] [blame]
Misha Brukmand97cb462004-12-09 20:26:20 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
Brian Gaeke74f470b2004-07-01 20:10:40 +00003<html>
Reid Spencerd206bc92004-11-01 21:55:46 +00004<head>
Misha Brukmand97cb462004-12-09 20:26:20 +00005 <title>LLVM bugpoint tool: design and usage</title>
Reid Spencerd206bc92004-11-01 21:55:46 +00006 <link rel="stylesheet" href="llvm.css" type="text/css">
Reid Spencerd206bc92004-11-01 21:55:46 +00007</head>
Brian Gaeke74f470b2004-07-01 20:10:40 +00008
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00009<h1>
Misha Brukmand97cb462004-12-09 20:26:20 +000010 LLVM bugpoint tool: design and usage
NAKAMURA Takumi05d02652011-04-18 23:59:50 +000011</h1>
Brian Gaeke74f470b2004-07-01 20:10:40 +000012
Misha Brukmand97cb462004-12-09 20:26:20 +000013<ul>
14 <li><a href="#desc">Description</a></li>
15 <li><a href="#design">Design Philosophy</a>
16 <ul>
17 <li><a href="#autoselect">Automatic Debugger Selection</a></li>
18 <li><a href="#crashdebug">Crash debugger</a></li>
19 <li><a href="#codegendebug">Code generator debugger</a></li>
20 <li><a href="#miscompilationdebug">Miscompilation debugger</a></li>
21 </ul></li>
22 <li><a href="#advice">Advice for using <tt>bugpoint</tt></a></li>
23</ul>
Brian Gaeke74f470b2004-07-01 20:10:40 +000024
Misha Brukmand97cb462004-12-09 20:26:20 +000025<div class="doc_author">
26<p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a></p>
27</div>
Brian Gaeke74f470b2004-07-01 20:10:40 +000028
Misha Brukmand97cb462004-12-09 20:26:20 +000029<!-- *********************************************************************** -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +000030<h2>
Misha Brukmand97cb462004-12-09 20:26:20 +000031<a name="desc">Description</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +000032</h2>
Misha Brukmand97cb462004-12-09 20:26:20 +000033<!-- *********************************************************************** -->
Brian Gaeke74f470b2004-07-01 20:10:40 +000034
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +000035<div>
Brian Gaeke74f470b2004-07-01 20:10:40 +000036
Misha Brukmand97cb462004-12-09 20:26:20 +000037<p><tt>bugpoint</tt> narrows down the source of problems in LLVM tools and
38passes. It can be used to debug three types of failures: optimizer crashes,
39miscompilations by optimizers, or bad native code generation (including problems
40in the static and JIT compilers). It aims to reduce large test cases to small,
Reid Spencer434262a2007-02-09 15:59:08 +000041useful ones. For example, if <tt>opt</tt> crashes while optimizing a
Misha Brukmand97cb462004-12-09 20:26:20 +000042file, it will identify the optimization (or combination of optimizations) that
43causes the crash, and reduce the file down to a small example which triggers the
44crash.</p>
Brian Gaeke74f470b2004-07-01 20:10:40 +000045
Reid Spencer434262a2007-02-09 15:59:08 +000046<p>For detailed case scenarios, such as debugging <tt>opt</tt>,
47<tt>llvm-ld</tt>, or one of the LLVM code generators, see <a
Misha Brukmand97cb462004-12-09 20:26:20 +000048href="HowToSubmitABug.html">How To Submit a Bug Report document</a>.</p>
49
50</div>
51
52<!-- *********************************************************************** -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +000053<h2>
Misha Brukmand97cb462004-12-09 20:26:20 +000054<a name="design">Design Philosophy</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +000055</h2>
Misha Brukmand97cb462004-12-09 20:26:20 +000056<!-- *********************************************************************** -->
57
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +000058<div>
Misha Brukmand97cb462004-12-09 20:26:20 +000059
60<p><tt>bugpoint</tt> is designed to be a useful tool without requiring any
Brian Gaeke74f470b2004-07-01 20:10:40 +000061hooks into the LLVM infrastructure at all. It works with any and all LLVM
62passes and code generators, and does not need to "know" how they work. Because
63of this, it may appear to do stupid things or miss obvious
64simplifications. <tt>bugpoint</tt> is also designed to trade off programmer
65time for computer time in the compiler-debugging process; consequently, it may
66take a long period of (unattended) time to reduce a test case, but we feel it
67is still worth it. Note that <tt>bugpoint</tt> is generally very quick unless
68debugging a miscompilation where each test of the program (which requires
Misha Brukmand97cb462004-12-09 20:26:20 +000069executing it) takes a long time.</p>
Brian Gaeke74f470b2004-07-01 20:10:40 +000070
Misha Brukmand97cb462004-12-09 20:26:20 +000071<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +000072<h3>
Misha Brukmand97cb462004-12-09 20:26:20 +000073 <a name="autoselect">Automatic Debugger Selection</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +000074</h3>
Brian Gaeke74f470b2004-07-01 20:10:40 +000075
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +000076<div>
Brian Gaeke74f470b2004-07-01 20:10:40 +000077
Misha Brukmand97cb462004-12-09 20:26:20 +000078<p><tt>bugpoint</tt> reads each <tt>.bc</tt> or <tt>.ll</tt> file specified on
79the command line and links them together into a single module, called the test
80program. If any LLVM passes are specified on the command line, it runs these
81passes on the test program. If any of the passes crash, or if they produce
82malformed output (which causes the verifier to abort), <tt>bugpoint</tt> starts
83the <a href="#crashdebug">crash debugger</a>.</p>
84
85<p>Otherwise, if the <tt>-output</tt> option was not specified,
86<tt>bugpoint</tt> runs the test program with the C backend (which is assumed to
87generate good code) to generate a reference output. Once <tt>bugpoint</tt> has
88a reference output for the test program, it tries executing it with the
89selected code generator. If the selected code generator crashes,
90<tt>bugpoint</tt> starts the <a href="#crashdebug">crash debugger</a> on the
91code generator. Otherwise, if the resulting output differs from the reference
92output, it assumes the difference resulted from a code generator failure, and
93starts the <a href="#codegendebug">code generator debugger</a>.</p>
94
95<p>Finally, if the output of the selected code generator matches the reference
Brian Gaeke74f470b2004-07-01 20:10:40 +000096output, <tt>bugpoint</tt> runs the test program after all of the LLVM passes
97have been applied to it. If its output differs from the reference output, it
98assumes the difference resulted from a failure in one of the LLVM passes, and
Misha Brukmand97cb462004-12-09 20:26:20 +000099enters the <a href="#miscompilationdebug">miscompilation debugger</a>.
100Otherwise, there is no problem <tt>bugpoint</tt> can debug.</p>
Brian Gaeke74f470b2004-07-01 20:10:40 +0000101
Misha Brukmand97cb462004-12-09 20:26:20 +0000102</div>
Brian Gaeke74f470b2004-07-01 20:10:40 +0000103
Misha Brukmand97cb462004-12-09 20:26:20 +0000104<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000105<h3>
Misha Brukmand97cb462004-12-09 20:26:20 +0000106 <a name="crashdebug">Crash debugger</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000107</h3>
Misha Brukmand97cb462004-12-09 20:26:20 +0000108
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000109<div>
Misha Brukmand97cb462004-12-09 20:26:20 +0000110
111<p>If an optimizer or code generator crashes, <tt>bugpoint</tt> will try as hard
112as it can to reduce the list of passes (for optimizer crashes) and the size of
113the test program. First, <tt>bugpoint</tt> figures out which combination of
Brian Gaeke74f470b2004-07-01 20:10:40 +0000114optimizer passes triggers the bug. This is useful when debugging a problem
Reid Spencer434262a2007-02-09 15:59:08 +0000115exposed by <tt>opt</tt>, for example, because it runs over 38 passes.</p>
Brian Gaeke74f470b2004-07-01 20:10:40 +0000116
Misha Brukmand97cb462004-12-09 20:26:20 +0000117<p>Next, <tt>bugpoint</tt> tries removing functions from the test program, to
Brian Gaeke74f470b2004-07-01 20:10:40 +0000118reduce its size. Usually it is able to reduce a test program to a single
119function, when debugging intraprocedural optimizations. Once the number of
120functions has been reduced, it attempts to delete various edges in the control
121flow graph, to reduce the size of the function as much as possible. Finally,
122<tt>bugpoint</tt> deletes any individual LLVM instructions whose absence does
123not eliminate the failure. At the end, <tt>bugpoint</tt> should tell you what
Gabor Greif04367bf2007-07-06 22:07:22 +0000124passes crash, give you a bitcode file, and give you instructions on how to
Reid Spencer84f82f72006-08-28 00:34:19 +0000125reproduce the failure with <tt>opt</tt> or <tt>llc</tt>.</p>
Brian Gaeke74f470b2004-07-01 20:10:40 +0000126
Misha Brukmand97cb462004-12-09 20:26:20 +0000127</div>
128
129<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000130<h3>
Misha Brukmand97cb462004-12-09 20:26:20 +0000131 <a name="codegendebug">Code generator debugger</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000132</h3>
Misha Brukmand97cb462004-12-09 20:26:20 +0000133
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000134<div>
Brian Gaeke74f470b2004-07-01 20:10:40 +0000135
136<p>The code generator debugger attempts to narrow down the amount of code that
Misha Brukmand97cb462004-12-09 20:26:20 +0000137is being miscompiled by the selected code generator. To do this, it takes the
138test program and partitions it into two pieces: one piece which it compiles
139with the C backend (into a shared object), and one piece which it runs with
140either the JIT or the static LLC compiler. It uses several techniques to
141reduce the amount of code pushed through the LLVM code generator, to reduce the
Gabor Greif04367bf2007-07-06 22:07:22 +0000142potential scope of the problem. After it is finished, it emits two bitcode
Misha Brukmand97cb462004-12-09 20:26:20 +0000143files (called "test" [to be compiled with the code generator] and "safe" [to be
144compiled with the C backend], respectively), and instructions for reproducing
145the problem. The code generator debugger assumes that the C backend produces
146good code.</p>
Brian Gaeke74f470b2004-07-01 20:10:40 +0000147
Misha Brukmand97cb462004-12-09 20:26:20 +0000148</div>
Brian Gaeke74f470b2004-07-01 20:10:40 +0000149
Misha Brukmand97cb462004-12-09 20:26:20 +0000150<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000151<h3>
Misha Brukmand97cb462004-12-09 20:26:20 +0000152 <a name="miscompilationdebug">Miscompilation debugger</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000153</h3>
Brian Gaeke74f470b2004-07-01 20:10:40 +0000154
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000155<div>
Misha Brukmand97cb462004-12-09 20:26:20 +0000156
157<p>The miscompilation debugger works similarly to the code generator debugger.
158It works by splitting the test program into two pieces, running the
159optimizations specified on one piece, linking the two pieces back together, and
160then executing the result. It attempts to narrow down the list of passes to
161the one (or few) which are causing the miscompilation, then reduce the portion
162of the test program which is being miscompiled. The miscompilation debugger
163assumes that the selected code generator is working properly.</p>
164
165</div>
166
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000167</div>
168
Misha Brukmand97cb462004-12-09 20:26:20 +0000169<!-- *********************************************************************** -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000170<h2>
Misha Brukmand97cb462004-12-09 20:26:20 +0000171 <a name="advice">Advice for using bugpoint</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000172</h2>
Misha Brukmand97cb462004-12-09 20:26:20 +0000173<!-- *********************************************************************** -->
174
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000175<div>
Brian Gaeke74f470b2004-07-01 20:10:40 +0000176
177<tt>bugpoint</tt> can be a remarkably useful tool, but it sometimes works in
178non-obvious ways. Here are some hints and tips:<p>
179
180<ol>
181<li>In the code generator and miscompilation debuggers, <tt>bugpoint</tt> only
182 works with programs that have deterministic output. Thus, if the program
Misha Brukmand97cb462004-12-09 20:26:20 +0000183 outputs <tt>argv[0]</tt>, the date, time, or any other "random" data,
184 <tt>bugpoint</tt> may misinterpret differences in these data, when output,
185 as the result of a miscompilation. Programs should be temporarily modified
186 to disable outputs that are likely to vary from run to run.
Brian Gaeke74f470b2004-07-01 20:10:40 +0000187
188<li>In the code generator and miscompilation debuggers, debugging will go
189 faster if you manually modify the program or its inputs to reduce the
190 runtime, but still exhibit the problem.
191
192<li><tt>bugpoint</tt> is extremely useful when working on a new optimization:
193 it helps track down regressions quickly. To avoid having to relink
194 <tt>bugpoint</tt> every time you change your optimization however, have
Misha Brukmand97cb462004-12-09 20:26:20 +0000195 <tt>bugpoint</tt> dynamically load your optimization with the
196 <tt>-load</tt> option.
Brian Gaeke74f470b2004-07-01 20:10:40 +0000197
Misha Brukmand97cb462004-12-09 20:26:20 +0000198<li><p><tt>bugpoint</tt> can generate a lot of output and run for a long period
199 of time. It is often useful to capture the output of the program to file.
200 For example, in the C shell, you can run:</p>
201
202<div class="doc_code">
203<p><tt>bugpoint ... |&amp; tee bugpoint.log</tt></p>
204</div>
205
206 <p>to get a copy of <tt>bugpoint</tt>'s output in the file
207 <tt>bugpoint.log</tt>, as well as on your terminal.</p>
Brian Gaeke74f470b2004-07-01 20:10:40 +0000208
209<li><tt>bugpoint</tt> cannot debug problems with the LLVM linker. If
210 <tt>bugpoint</tt> crashes before you see its "All input ok" message,
211 you might try <tt>llvm-link -v</tt> on the same set of input files. If
212 that also crashes, you may be experiencing a linker bug.
213
Patrick Jenkins82681662006-08-15 17:03:17 +0000214<li><tt>bugpoint</tt> is useful for proactively finding bugs in LLVM.
215 Invoking <tt>bugpoint</tt> with the <tt>-find-bugs</tt> option will cause
216 the list of specified optimizations to be randomized and applied to the
Patrick Jenkins94f78502006-08-15 17:38:36 +0000217 program. This process will repeat until a bug is found or the user
Patrick Jenkins82681662006-08-15 17:03:17 +0000218 kills <tt>bugpoint</tt>.
Chris Lattner1e079052009-10-12 18:12:47 +0000219
220<li><p><tt>bugpoint</tt> does not understand the <tt>-O</tt> option
221 that is used to specify optimization level to <tt>opt</tt>. You
222 can use e.g.</p>
223
224<div class="doc_code">
225<p><tt>opt -O2 -debug-pass=Arguments foo.bc -disable-output</tt></p>
226</div>
227
228 <p>to get a list of passes that are used with <tt>-O2</tt> and
229 then pass this list to <tt>bugpoint</tt>.</p>
Brian Gaeke74f470b2004-07-01 20:10:40 +0000230
231</ol>
232
Misha Brukmand97cb462004-12-09 20:26:20 +0000233</div>
Brian Gaeke74f470b2004-07-01 20:10:40 +0000234
Misha Brukmand97cb462004-12-09 20:26:20 +0000235<!-- *********************************************************************** -->
Brian Gaeke74f470b2004-07-01 20:10:40 +0000236
Misha Brukmand97cb462004-12-09 20:26:20 +0000237<hr>
238<address>
239 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
Misha Brukman44408702008-12-11 17:34:48 +0000240 src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a>
Misha Brukmand97cb462004-12-09 20:26:20 +0000241 <a href="http://validator.w3.org/check/referer"><img
Misha Brukman44408702008-12-11 17:34:48 +0000242 src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a>
Brian Gaeke74f470b2004-07-01 20:10:40 +0000243
Misha Brukmand97cb462004-12-09 20:26:20 +0000244 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
NAKAMURA Takumib9a33632011-04-09 02:13:37 +0000245 <a href="http://llvm.org/">LLVM Compiler Infrastructure</a><br>
Misha Brukmand97cb462004-12-09 20:26:20 +0000246 Last modified: $Date$
247</address>
Brian Gaeke74f470b2004-07-01 20:10:40 +0000248
Brian Gaeke74f470b2004-07-01 20:10:40 +0000249</body>
250</html>