blob: 5454ff40d2bb225d513bc1c05bb658a8ba82d0ee [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>
NAKAMURA Takumi5c6e4df2011-10-31 11:21:59 +00005 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
Misha Brukmand97cb462004-12-09 20:26:20 +00006 <title>LLVM bugpoint tool: design and usage</title>
Reid Spencerd206bc92004-11-01 21:55:46 +00007 <link rel="stylesheet" href="llvm.css" type="text/css">
Reid Spencerd206bc92004-11-01 21:55:46 +00008</head>
Brian Gaeke74f470b2004-07-01 20:10:40 +00009
NAKAMURA Takumi05d02652011-04-18 23:59:50 +000010<h1>
Misha Brukmand97cb462004-12-09 20:26:20 +000011 LLVM bugpoint tool: design and usage
NAKAMURA Takumi05d02652011-04-18 23:59:50 +000012</h1>
Brian Gaeke74f470b2004-07-01 20:10:40 +000013
Misha Brukmand97cb462004-12-09 20:26:20 +000014<ul>
15 <li><a href="#desc">Description</a></li>
16 <li><a href="#design">Design Philosophy</a>
17 <ul>
18 <li><a href="#autoselect">Automatic Debugger Selection</a></li>
19 <li><a href="#crashdebug">Crash debugger</a></li>
20 <li><a href="#codegendebug">Code generator debugger</a></li>
21 <li><a href="#miscompilationdebug">Miscompilation debugger</a></li>
22 </ul></li>
23 <li><a href="#advice">Advice for using <tt>bugpoint</tt></a></li>
24</ul>
Brian Gaeke74f470b2004-07-01 20:10:40 +000025
Misha Brukmand97cb462004-12-09 20:26:20 +000026<div class="doc_author">
27<p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a></p>
28</div>
Brian Gaeke74f470b2004-07-01 20:10:40 +000029
Misha Brukmand97cb462004-12-09 20:26:20 +000030<!-- *********************************************************************** -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +000031<h2>
Misha Brukmand97cb462004-12-09 20:26:20 +000032<a name="desc">Description</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +000033</h2>
Misha Brukmand97cb462004-12-09 20:26:20 +000034<!-- *********************************************************************** -->
Brian Gaeke74f470b2004-07-01 20:10:40 +000035
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +000036<div>
Brian Gaeke74f470b2004-07-01 20:10:40 +000037
Misha Brukmand97cb462004-12-09 20:26:20 +000038<p><tt>bugpoint</tt> narrows down the source of problems in LLVM tools and
39passes. It can be used to debug three types of failures: optimizer crashes,
40miscompilations by optimizers, or bad native code generation (including problems
41in the static and JIT compilers). It aims to reduce large test cases to small,
Reid Spencer434262a2007-02-09 15:59:08 +000042useful ones. For example, if <tt>opt</tt> crashes while optimizing a
Misha Brukmand97cb462004-12-09 20:26:20 +000043file, it will identify the optimization (or combination of optimizations) that
44causes the crash, and reduce the file down to a small example which triggers the
45crash.</p>
Brian Gaeke74f470b2004-07-01 20:10:40 +000046
Reid Spencer434262a2007-02-09 15:59:08 +000047<p>For detailed case scenarios, such as debugging <tt>opt</tt>,
48<tt>llvm-ld</tt>, or one of the LLVM code generators, see <a
Misha Brukmand97cb462004-12-09 20:26:20 +000049href="HowToSubmitABug.html">How To Submit a Bug Report document</a>.</p>
50
51</div>
52
53<!-- *********************************************************************** -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +000054<h2>
Misha Brukmand97cb462004-12-09 20:26:20 +000055<a name="design">Design Philosophy</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +000056</h2>
Misha Brukmand97cb462004-12-09 20:26:20 +000057<!-- *********************************************************************** -->
58
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +000059<div>
Misha Brukmand97cb462004-12-09 20:26:20 +000060
61<p><tt>bugpoint</tt> is designed to be a useful tool without requiring any
Brian Gaeke74f470b2004-07-01 20:10:40 +000062hooks into the LLVM infrastructure at all. It works with any and all LLVM
63passes and code generators, and does not need to "know" how they work. Because
64of this, it may appear to do stupid things or miss obvious
65simplifications. <tt>bugpoint</tt> is also designed to trade off programmer
66time for computer time in the compiler-debugging process; consequently, it may
67take a long period of (unattended) time to reduce a test case, but we feel it
68is still worth it. Note that <tt>bugpoint</tt> is generally very quick unless
69debugging a miscompilation where each test of the program (which requires
Misha Brukmand97cb462004-12-09 20:26:20 +000070executing it) takes a long time.</p>
Brian Gaeke74f470b2004-07-01 20:10:40 +000071
Misha Brukmand97cb462004-12-09 20:26:20 +000072<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +000073<h3>
Misha Brukmand97cb462004-12-09 20:26:20 +000074 <a name="autoselect">Automatic Debugger Selection</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +000075</h3>
Brian Gaeke74f470b2004-07-01 20:10:40 +000076
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +000077<div>
Brian Gaeke74f470b2004-07-01 20:10:40 +000078
Misha Brukmand97cb462004-12-09 20:26:20 +000079<p><tt>bugpoint</tt> reads each <tt>.bc</tt> or <tt>.ll</tt> file specified on
80the command line and links them together into a single module, called the test
81program. If any LLVM passes are specified on the command line, it runs these
82passes on the test program. If any of the passes crash, or if they produce
83malformed output (which causes the verifier to abort), <tt>bugpoint</tt> starts
84the <a href="#crashdebug">crash debugger</a>.</p>
85
86<p>Otherwise, if the <tt>-output</tt> option was not specified,
87<tt>bugpoint</tt> runs the test program with the C backend (which is assumed to
88generate good code) to generate a reference output. Once <tt>bugpoint</tt> has
89a reference output for the test program, it tries executing it with the
90selected code generator. If the selected code generator crashes,
91<tt>bugpoint</tt> starts the <a href="#crashdebug">crash debugger</a> on the
92code generator. Otherwise, if the resulting output differs from the reference
93output, it assumes the difference resulted from a code generator failure, and
94starts the <a href="#codegendebug">code generator debugger</a>.</p>
95
96<p>Finally, if the output of the selected code generator matches the reference
Brian Gaeke74f470b2004-07-01 20:10:40 +000097output, <tt>bugpoint</tt> runs the test program after all of the LLVM passes
98have been applied to it. If its output differs from the reference output, it
99assumes the difference resulted from a failure in one of the LLVM passes, and
Misha Brukmand97cb462004-12-09 20:26:20 +0000100enters the <a href="#miscompilationdebug">miscompilation debugger</a>.
101Otherwise, there is no problem <tt>bugpoint</tt> can debug.</p>
Brian Gaeke74f470b2004-07-01 20:10:40 +0000102
Misha Brukmand97cb462004-12-09 20:26:20 +0000103</div>
Brian Gaeke74f470b2004-07-01 20:10:40 +0000104
Misha Brukmand97cb462004-12-09 20:26:20 +0000105<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000106<h3>
Misha Brukmand97cb462004-12-09 20:26:20 +0000107 <a name="crashdebug">Crash debugger</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000108</h3>
Misha Brukmand97cb462004-12-09 20:26:20 +0000109
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000110<div>
Misha Brukmand97cb462004-12-09 20:26:20 +0000111
112<p>If an optimizer or code generator crashes, <tt>bugpoint</tt> will try as hard
113as it can to reduce the list of passes (for optimizer crashes) and the size of
114the test program. First, <tt>bugpoint</tt> figures out which combination of
Brian Gaeke74f470b2004-07-01 20:10:40 +0000115optimizer passes triggers the bug. This is useful when debugging a problem
Reid Spencer434262a2007-02-09 15:59:08 +0000116exposed by <tt>opt</tt>, for example, because it runs over 38 passes.</p>
Brian Gaeke74f470b2004-07-01 20:10:40 +0000117
Misha Brukmand97cb462004-12-09 20:26:20 +0000118<p>Next, <tt>bugpoint</tt> tries removing functions from the test program, to
Brian Gaeke74f470b2004-07-01 20:10:40 +0000119reduce its size. Usually it is able to reduce a test program to a single
120function, when debugging intraprocedural optimizations. Once the number of
121functions has been reduced, it attempts to delete various edges in the control
122flow graph, to reduce the size of the function as much as possible. Finally,
123<tt>bugpoint</tt> deletes any individual LLVM instructions whose absence does
124not eliminate the failure. At the end, <tt>bugpoint</tt> should tell you what
Gabor Greif04367bf2007-07-06 22:07:22 +0000125passes crash, give you a bitcode file, and give you instructions on how to
Reid Spencer84f82f72006-08-28 00:34:19 +0000126reproduce the failure with <tt>opt</tt> or <tt>llc</tt>.</p>
Brian Gaeke74f470b2004-07-01 20:10:40 +0000127
Misha Brukmand97cb462004-12-09 20:26:20 +0000128</div>
129
130<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000131<h3>
Misha Brukmand97cb462004-12-09 20:26:20 +0000132 <a name="codegendebug">Code generator debugger</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000133</h3>
Misha Brukmand97cb462004-12-09 20:26:20 +0000134
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000135<div>
Brian Gaeke74f470b2004-07-01 20:10:40 +0000136
137<p>The code generator debugger attempts to narrow down the amount of code that
Misha Brukmand97cb462004-12-09 20:26:20 +0000138is being miscompiled by the selected code generator. To do this, it takes the
139test program and partitions it into two pieces: one piece which it compiles
140with the C backend (into a shared object), and one piece which it runs with
141either the JIT or the static LLC compiler. It uses several techniques to
142reduce the amount of code pushed through the LLVM code generator, to reduce the
Gabor Greif04367bf2007-07-06 22:07:22 +0000143potential scope of the problem. After it is finished, it emits two bitcode
Misha Brukmand97cb462004-12-09 20:26:20 +0000144files (called "test" [to be compiled with the code generator] and "safe" [to be
145compiled with the C backend], respectively), and instructions for reproducing
146the problem. The code generator debugger assumes that the C backend produces
147good code.</p>
Brian Gaeke74f470b2004-07-01 20:10:40 +0000148
Misha Brukmand97cb462004-12-09 20:26:20 +0000149</div>
Brian Gaeke74f470b2004-07-01 20:10:40 +0000150
Misha Brukmand97cb462004-12-09 20:26:20 +0000151<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000152<h3>
Misha Brukmand97cb462004-12-09 20:26:20 +0000153 <a name="miscompilationdebug">Miscompilation debugger</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000154</h3>
Brian Gaeke74f470b2004-07-01 20:10:40 +0000155
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000156<div>
Misha Brukmand97cb462004-12-09 20:26:20 +0000157
158<p>The miscompilation debugger works similarly to the code generator debugger.
159It works by splitting the test program into two pieces, running the
160optimizations specified on one piece, linking the two pieces back together, and
161then executing the result. It attempts to narrow down the list of passes to
162the one (or few) which are causing the miscompilation, then reduce the portion
163of the test program which is being miscompiled. The miscompilation debugger
164assumes that the selected code generator is working properly.</p>
165
166</div>
167
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000168</div>
169
Misha Brukmand97cb462004-12-09 20:26:20 +0000170<!-- *********************************************************************** -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000171<h2>
Misha Brukmand97cb462004-12-09 20:26:20 +0000172 <a name="advice">Advice for using bugpoint</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000173</h2>
Misha Brukmand97cb462004-12-09 20:26:20 +0000174<!-- *********************************************************************** -->
175
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000176<div>
Brian Gaeke74f470b2004-07-01 20:10:40 +0000177
178<tt>bugpoint</tt> can be a remarkably useful tool, but it sometimes works in
179non-obvious ways. Here are some hints and tips:<p>
180
181<ol>
182<li>In the code generator and miscompilation debuggers, <tt>bugpoint</tt> only
183 works with programs that have deterministic output. Thus, if the program
Misha Brukmand97cb462004-12-09 20:26:20 +0000184 outputs <tt>argv[0]</tt>, the date, time, or any other "random" data,
185 <tt>bugpoint</tt> may misinterpret differences in these data, when output,
186 as the result of a miscompilation. Programs should be temporarily modified
187 to disable outputs that are likely to vary from run to run.
Brian Gaeke74f470b2004-07-01 20:10:40 +0000188
189<li>In the code generator and miscompilation debuggers, debugging will go
190 faster if you manually modify the program or its inputs to reduce the
191 runtime, but still exhibit the problem.
192
193<li><tt>bugpoint</tt> is extremely useful when working on a new optimization:
194 it helps track down regressions quickly. To avoid having to relink
195 <tt>bugpoint</tt> every time you change your optimization however, have
Misha Brukmand97cb462004-12-09 20:26:20 +0000196 <tt>bugpoint</tt> dynamically load your optimization with the
197 <tt>-load</tt> option.
Brian Gaeke74f470b2004-07-01 20:10:40 +0000198
Misha Brukmand97cb462004-12-09 20:26:20 +0000199<li><p><tt>bugpoint</tt> can generate a lot of output and run for a long period
200 of time. It is often useful to capture the output of the program to file.
201 For example, in the C shell, you can run:</p>
202
203<div class="doc_code">
204<p><tt>bugpoint ... |&amp; tee bugpoint.log</tt></p>
205</div>
206
207 <p>to get a copy of <tt>bugpoint</tt>'s output in the file
208 <tt>bugpoint.log</tt>, as well as on your terminal.</p>
Brian Gaeke74f470b2004-07-01 20:10:40 +0000209
210<li><tt>bugpoint</tt> cannot debug problems with the LLVM linker. If
211 <tt>bugpoint</tt> crashes before you see its "All input ok" message,
212 you might try <tt>llvm-link -v</tt> on the same set of input files. If
213 that also crashes, you may be experiencing a linker bug.
214
Patrick Jenkins82681662006-08-15 17:03:17 +0000215<li><tt>bugpoint</tt> is useful for proactively finding bugs in LLVM.
216 Invoking <tt>bugpoint</tt> with the <tt>-find-bugs</tt> option will cause
217 the list of specified optimizations to be randomized and applied to the
Patrick Jenkins94f78502006-08-15 17:38:36 +0000218 program. This process will repeat until a bug is found or the user
Patrick Jenkins82681662006-08-15 17:03:17 +0000219 kills <tt>bugpoint</tt>.
Brian Gaeke74f470b2004-07-01 20:10:40 +0000220</ol>
221
Misha Brukmand97cb462004-12-09 20:26:20 +0000222</div>
Brian Gaeke74f470b2004-07-01 20:10:40 +0000223
Misha Brukmand97cb462004-12-09 20:26:20 +0000224<!-- *********************************************************************** -->
Brian Gaeke74f470b2004-07-01 20:10:40 +0000225
Misha Brukmand97cb462004-12-09 20:26:20 +0000226<hr>
227<address>
228 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
Misha Brukman44408702008-12-11 17:34:48 +0000229 src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a>
Misha Brukmand97cb462004-12-09 20:26:20 +0000230 <a href="http://validator.w3.org/check/referer"><img
Misha Brukman44408702008-12-11 17:34:48 +0000231 src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a>
Brian Gaeke74f470b2004-07-01 20:10:40 +0000232
Misha Brukmand97cb462004-12-09 20:26:20 +0000233 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
NAKAMURA Takumib9a33632011-04-09 02:13:37 +0000234 <a href="http://llvm.org/">LLVM Compiler Infrastructure</a><br>
Misha Brukmand97cb462004-12-09 20:26:20 +0000235 Last modified: $Date$
236</address>
Brian Gaeke74f470b2004-07-01 20:10:40 +0000237
Brian Gaeke74f470b2004-07-01 20:10:40 +0000238</body>
239</html>