Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
| 2 | "http://www.w3.org/TR/html4/strict.dtd"> |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 3 | <html> |
Reid Spencer | d206bc9 | 2004-11-01 21:55:46 +0000 | [diff] [blame] | 4 | <head> |
NAKAMURA Takumi | 5c6e4df | 2011-10-31 11:21:59 +0000 | [diff] [blame] | 5 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 6 | <title>LLVM bugpoint tool: design and usage</title> |
Daniel Dunbar | adea497 | 2012-04-19 20:20:34 +0000 | [diff] [blame] | 7 | <link rel="stylesheet" href="_static/llvm.css" type="text/css"> |
Reid Spencer | d206bc9 | 2004-11-01 21:55:46 +0000 | [diff] [blame] | 8 | </head> |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 9 | |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 10 | <h1> |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 11 | LLVM bugpoint tool: design and usage |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 12 | </h1> |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 13 | |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 14 | <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> |
Joel Jones | a9498a2 | 2012-04-20 18:20:24 +0000 | [diff] [blame^] | 24 | <li><a href="#notEnough">What to do when <tt>bugpoint</tt> isn't enough</a></li> |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 25 | </ul> |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 26 | |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 27 | <div class="doc_author"> |
| 28 | <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a></p> |
| 29 | </div> |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 30 | |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 31 | <!-- *********************************************************************** --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 32 | <h2> |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 33 | <a name="desc">Description</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 34 | </h2> |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 35 | <!-- *********************************************************************** --> |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 36 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 37 | <div> |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 38 | |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 39 | <p><tt>bugpoint</tt> narrows down the source of problems in LLVM tools and |
| 40 | passes. It can be used to debug three types of failures: optimizer crashes, |
| 41 | miscompilations by optimizers, or bad native code generation (including problems |
| 42 | in the static and JIT compilers). It aims to reduce large test cases to small, |
Reid Spencer | 434262a | 2007-02-09 15:59:08 +0000 | [diff] [blame] | 43 | useful ones. For example, if <tt>opt</tt> crashes while optimizing a |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 44 | file, it will identify the optimization (or combination of optimizations) that |
| 45 | causes the crash, and reduce the file down to a small example which triggers the |
| 46 | crash.</p> |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 47 | |
Michael J. Spencer | 7533809 | 2012-04-19 19:27:54 +0000 | [diff] [blame] | 48 | <p>For detailed case scenarios, such as debugging <tt>opt</tt>, or one of the |
| 49 | LLVM code generators, see <a href="HowToSubmitABug.html">How To Submit a Bug |
| 50 | Report document</a>.</p> |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 51 | |
| 52 | </div> |
| 53 | |
| 54 | <!-- *********************************************************************** --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 55 | <h2> |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 56 | <a name="design">Design Philosophy</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 57 | </h2> |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 58 | <!-- *********************************************************************** --> |
| 59 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 60 | <div> |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 61 | |
| 62 | <p><tt>bugpoint</tt> is designed to be a useful tool without requiring any |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 63 | hooks into the LLVM infrastructure at all. It works with any and all LLVM |
| 64 | passes and code generators, and does not need to "know" how they work. Because |
| 65 | of this, it may appear to do stupid things or miss obvious |
| 66 | simplifications. <tt>bugpoint</tt> is also designed to trade off programmer |
| 67 | time for computer time in the compiler-debugging process; consequently, it may |
| 68 | take a long period of (unattended) time to reduce a test case, but we feel it |
| 69 | is still worth it. Note that <tt>bugpoint</tt> is generally very quick unless |
| 70 | debugging a miscompilation where each test of the program (which requires |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 71 | executing it) takes a long time.</p> |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 72 | |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 73 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 74 | <h3> |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 75 | <a name="autoselect">Automatic Debugger Selection</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 76 | </h3> |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 77 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 78 | <div> |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 79 | |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 80 | <p><tt>bugpoint</tt> reads each <tt>.bc</tt> or <tt>.ll</tt> file specified on |
| 81 | the command line and links them together into a single module, called the test |
| 82 | program. If any LLVM passes are specified on the command line, it runs these |
| 83 | passes on the test program. If any of the passes crash, or if they produce |
| 84 | malformed output (which causes the verifier to abort), <tt>bugpoint</tt> starts |
| 85 | the <a href="#crashdebug">crash debugger</a>.</p> |
| 86 | |
| 87 | <p>Otherwise, if the <tt>-output</tt> option was not specified, |
| 88 | <tt>bugpoint</tt> runs the test program with the C backend (which is assumed to |
| 89 | generate good code) to generate a reference output. Once <tt>bugpoint</tt> has |
| 90 | a reference output for the test program, it tries executing it with the |
| 91 | selected code generator. If the selected code generator crashes, |
| 92 | <tt>bugpoint</tt> starts the <a href="#crashdebug">crash debugger</a> on the |
| 93 | code generator. Otherwise, if the resulting output differs from the reference |
| 94 | output, it assumes the difference resulted from a code generator failure, and |
| 95 | starts the <a href="#codegendebug">code generator debugger</a>.</p> |
| 96 | |
| 97 | <p>Finally, if the output of the selected code generator matches the reference |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 98 | output, <tt>bugpoint</tt> runs the test program after all of the LLVM passes |
| 99 | have been applied to it. If its output differs from the reference output, it |
| 100 | assumes the difference resulted from a failure in one of the LLVM passes, and |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 101 | enters the <a href="#miscompilationdebug">miscompilation debugger</a>. |
| 102 | Otherwise, there is no problem <tt>bugpoint</tt> can debug.</p> |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 103 | |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 104 | </div> |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 105 | |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 106 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 107 | <h3> |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 108 | <a name="crashdebug">Crash debugger</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 109 | </h3> |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 110 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 111 | <div> |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 112 | |
| 113 | <p>If an optimizer or code generator crashes, <tt>bugpoint</tt> will try as hard |
| 114 | as it can to reduce the list of passes (for optimizer crashes) and the size of |
| 115 | the test program. First, <tt>bugpoint</tt> figures out which combination of |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 116 | optimizer passes triggers the bug. This is useful when debugging a problem |
Reid Spencer | 434262a | 2007-02-09 15:59:08 +0000 | [diff] [blame] | 117 | exposed by <tt>opt</tt>, for example, because it runs over 38 passes.</p> |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 118 | |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 119 | <p>Next, <tt>bugpoint</tt> tries removing functions from the test program, to |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 120 | reduce its size. Usually it is able to reduce a test program to a single |
| 121 | function, when debugging intraprocedural optimizations. Once the number of |
| 122 | functions has been reduced, it attempts to delete various edges in the control |
| 123 | flow graph, to reduce the size of the function as much as possible. Finally, |
| 124 | <tt>bugpoint</tt> deletes any individual LLVM instructions whose absence does |
| 125 | not eliminate the failure. At the end, <tt>bugpoint</tt> should tell you what |
Gabor Greif | 04367bf | 2007-07-06 22:07:22 +0000 | [diff] [blame] | 126 | passes crash, give you a bitcode file, and give you instructions on how to |
Reid Spencer | 84f82f7 | 2006-08-28 00:34:19 +0000 | [diff] [blame] | 127 | reproduce the failure with <tt>opt</tt> or <tt>llc</tt>.</p> |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 128 | |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 129 | </div> |
| 130 | |
| 131 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 132 | <h3> |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 133 | <a name="codegendebug">Code generator debugger</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 134 | </h3> |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 135 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 136 | <div> |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 137 | |
| 138 | <p>The code generator debugger attempts to narrow down the amount of code that |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 139 | is being miscompiled by the selected code generator. To do this, it takes the |
| 140 | test program and partitions it into two pieces: one piece which it compiles |
| 141 | with the C backend (into a shared object), and one piece which it runs with |
| 142 | either the JIT or the static LLC compiler. It uses several techniques to |
| 143 | reduce the amount of code pushed through the LLVM code generator, to reduce the |
Gabor Greif | 04367bf | 2007-07-06 22:07:22 +0000 | [diff] [blame] | 144 | potential scope of the problem. After it is finished, it emits two bitcode |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 145 | files (called "test" [to be compiled with the code generator] and "safe" [to be |
| 146 | compiled with the C backend], respectively), and instructions for reproducing |
| 147 | the problem. The code generator debugger assumes that the C backend produces |
| 148 | good code.</p> |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 149 | |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 150 | </div> |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 151 | |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 152 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 153 | <h3> |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 154 | <a name="miscompilationdebug">Miscompilation debugger</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 155 | </h3> |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 156 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 157 | <div> |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 158 | |
| 159 | <p>The miscompilation debugger works similarly to the code generator debugger. |
| 160 | It works by splitting the test program into two pieces, running the |
| 161 | optimizations specified on one piece, linking the two pieces back together, and |
| 162 | then executing the result. It attempts to narrow down the list of passes to |
| 163 | the one (or few) which are causing the miscompilation, then reduce the portion |
| 164 | of the test program which is being miscompiled. The miscompilation debugger |
| 165 | assumes that the selected code generator is working properly.</p> |
| 166 | |
| 167 | </div> |
| 168 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 169 | </div> |
| 170 | |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 171 | <!-- *********************************************************************** --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 172 | <h2> |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 173 | <a name="advice">Advice for using bugpoint</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 174 | </h2> |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 175 | <!-- *********************************************************************** --> |
| 176 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 177 | <div> |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 178 | |
| 179 | <tt>bugpoint</tt> can be a remarkably useful tool, but it sometimes works in |
| 180 | non-obvious ways. Here are some hints and tips:<p> |
| 181 | |
| 182 | <ol> |
| 183 | <li>In the code generator and miscompilation debuggers, <tt>bugpoint</tt> only |
| 184 | works with programs that have deterministic output. Thus, if the program |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 185 | outputs <tt>argv[0]</tt>, the date, time, or any other "random" data, |
| 186 | <tt>bugpoint</tt> may misinterpret differences in these data, when output, |
| 187 | as the result of a miscompilation. Programs should be temporarily modified |
| 188 | to disable outputs that are likely to vary from run to run. |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 189 | |
| 190 | <li>In the code generator and miscompilation debuggers, debugging will go |
| 191 | faster if you manually modify the program or its inputs to reduce the |
| 192 | runtime, but still exhibit the problem. |
| 193 | |
| 194 | <li><tt>bugpoint</tt> is extremely useful when working on a new optimization: |
| 195 | it helps track down regressions quickly. To avoid having to relink |
| 196 | <tt>bugpoint</tt> every time you change your optimization however, have |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 197 | <tt>bugpoint</tt> dynamically load your optimization with the |
| 198 | <tt>-load</tt> option. |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 199 | |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 200 | <li><p><tt>bugpoint</tt> can generate a lot of output and run for a long period |
| 201 | of time. It is often useful to capture the output of the program to file. |
| 202 | For example, in the C shell, you can run:</p> |
| 203 | |
| 204 | <div class="doc_code"> |
| 205 | <p><tt>bugpoint ... |& tee bugpoint.log</tt></p> |
| 206 | </div> |
| 207 | |
| 208 | <p>to get a copy of <tt>bugpoint</tt>'s output in the file |
| 209 | <tt>bugpoint.log</tt>, as well as on your terminal.</p> |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 210 | |
| 211 | <li><tt>bugpoint</tt> cannot debug problems with the LLVM linker. If |
| 212 | <tt>bugpoint</tt> crashes before you see its "All input ok" message, |
| 213 | you might try <tt>llvm-link -v</tt> on the same set of input files. If |
| 214 | that also crashes, you may be experiencing a linker bug. |
| 215 | |
Patrick Jenkins | 8268166 | 2006-08-15 17:03:17 +0000 | [diff] [blame] | 216 | <li><tt>bugpoint</tt> is useful for proactively finding bugs in LLVM. |
| 217 | Invoking <tt>bugpoint</tt> with the <tt>-find-bugs</tt> option will cause |
| 218 | the list of specified optimizations to be randomized and applied to the |
Patrick Jenkins | 94f7850 | 2006-08-15 17:38:36 +0000 | [diff] [blame] | 219 | program. This process will repeat until a bug is found or the user |
Patrick Jenkins | 8268166 | 2006-08-15 17:03:17 +0000 | [diff] [blame] | 220 | kills <tt>bugpoint</tt>. |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 221 | </ol> |
| 222 | |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 223 | </div> |
Joel Jones | 7605b29 | 2012-04-20 18:11:07 +0000 | [diff] [blame] | 224 | <!-- *********************************************************************** --> |
| 225 | <h2> |
| 226 | <a name="notEnough">What to do when bugpoint isn't enough</a> |
| 227 | </h2> |
| 228 | <!-- *********************************************************************** --> |
| 229 | |
| 230 | <div> |
| 231 | |
| 232 | <p>Sometimes, <tt>bugpoint</tt> is not enough. In particular, InstCombine and |
| 233 | TargetLowering both have visitor structured code with lots of potential |
| 234 | transformations. If the process of using bugpoint has left you with |
| 235 | still too much code to figure out and the problem seems |
| 236 | to be in instcombine, the following steps may help. These same techniques |
| 237 | are useful with TargetLowering as well.</p> |
| 238 | |
| 239 | <p>Turn on <tt>-debug-only=instcombine</tt> and see which transformations |
| 240 | within instcombine are firing by selecting out lines with "<tt>IC</tt>" |
| 241 | in them.</p> |
| 242 | |
| 243 | <p>At this point, you have a decision to make. Is the number |
| 244 | of transformations small enough to step through them using a debugger? |
| 245 | If so, then try that.</p> |
| 246 | |
| 247 | <p>If there are too many transformations, then a source modification |
| 248 | approach may be helpful. |
| 249 | In this approach, you can modify the source code of instcombine |
| 250 | to disable just those transformations that are being performed on your |
| 251 | test input and perform a binary search over the set of transformations. |
| 252 | One set of places to modify are the "<tt>visit*</tt>" methods of |
| 253 | <tt>InstCombiner</tt> (<I>e.g.</I> <tt>visitICmpInst</tt>) by adding a |
| 254 | "<tt>return false</tt>" as the first line of the method.</p> |
| 255 | |
| 256 | <p>If that still doesn't remove enough, then change the caller of |
| 257 | <tt>InstCombiner::DoOneIteration</tt>, <tt>InstCombiner::runOnFunction</tt> |
| 258 | to limit the number of iterations.</p> |
| 259 | |
| 260 | <p>You may also find it useful to use "<tt>-stats</tt>" now to see what parts |
| 261 | of instcombine are firing. This can guide where to put additional reporting |
| 262 | code.</p> |
| 263 | |
| 264 | <p>At this point, if the amount of transformations is still too large, then |
| 265 | inserting code to limit whether or not to execute the body of the code |
| 266 | in the visit function can be helpful. Add a static counter which is |
| 267 | incremented on every invocation of the function. Then add code which |
| 268 | simply returns false on desired ranges. For example:</p> |
| 269 | |
| 270 | <div class="doc_code"> |
| 271 | <p><tt>static int calledCount = 0;</tt></p> |
| 272 | <p><tt>calledCount++;</tt></p> |
| 273 | <p><tt>DEBUG(if (calledCount < 212) return false);</tt></p> |
| 274 | <p><tt>DEBUG(if (calledCount > 217) return false);</tt></p> |
| 275 | <p><tt>DEBUG(if (calledCount == 213) return false);</tt></p> |
| 276 | <p><tt>DEBUG(if (calledCount == 214) return false);</tt></p> |
| 277 | <p><tt>DEBUG(if (calledCount == 215) return false);</tt></p> |
| 278 | <p><tt>DEBUG(if (calledCount == 216) return false);</tt></p> |
| 279 | <p><tt>DEBUG(dbgs() << "visitXOR calledCount: " << calledCount |
| 280 | << "\n");</tt></p> |
| 281 | <p><tt>DEBUG(dbgs() << "I: "; I->dump());</tt></p> |
| 282 | </div> |
| 283 | |
| 284 | <p>could be added to <tt>visitXOR</tt> to limit <tt>visitXor</tt> to being |
| 285 | applied only to calls 212 and 217. This is from an actual test case and raises |
| 286 | an important point---a simple binary search may not be sufficient, as |
| 287 | transformations that interact may require isolating more than one call. |
| 288 | In TargetLowering, use <tt>return SDNode();</tt> instead of |
| 289 | <tt>return false;</tt>.</p> |
| 290 | |
| 291 | <p>Now that that the number of transformations is down to a manageable |
| 292 | number, try examining the output to see if you can figure out which |
| 293 | transformations are being done. If that can be figured out, then |
| 294 | do the usual debugging. If which code corresponds to the transformation |
| 295 | being performed isn't obvious, set a breakpoint after the call count |
| 296 | based disabling and step through the code. Alternatively, you can use |
| 297 | "printf" style debugging to report waypoints.</p> |
| 298 | |
| 299 | </div> |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 300 | |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 301 | <!-- *********************************************************************** --> |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 302 | |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 303 | <hr> |
| 304 | <address> |
| 305 | <a href="http://jigsaw.w3.org/css-validator/check/referer"><img |
Misha Brukman | 4440870 | 2008-12-11 17:34:48 +0000 | [diff] [blame] | 306 | src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a> |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 307 | <a href="http://validator.w3.org/check/referer"><img |
Misha Brukman | 4440870 | 2008-12-11 17:34:48 +0000 | [diff] [blame] | 308 | src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a> |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 309 | |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 310 | <a href="mailto:sabre@nondot.org">Chris Lattner</a><br> |
NAKAMURA Takumi | b9a3363 | 2011-04-09 02:13:37 +0000 | [diff] [blame] | 311 | <a href="http://llvm.org/">LLVM Compiler Infrastructure</a><br> |
Misha Brukman | d97cb46 | 2004-12-09 20:26:20 +0000 | [diff] [blame] | 312 | Last modified: $Date$ |
| 313 | </address> |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 314 | |
Brian Gaeke | 74f470b | 2004-07-01 20:10:40 +0000 | [diff] [blame] | 315 | </body> |
| 316 | </html> |