llvm.org GIT mirror llvm / f1d01fb
Added sections about debugging mis-compilations and incorrect code generation. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8584 91177308-0d34-0410-b5e6-96231b3b80d8 Misha Brukman 16 years ago
1 changed file(s) with 80 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
1919
  • Bugs in LLVM passes
  • 2020
    2121
  • Miscompilations
  • 22
    23 <p>Written by Chris Lattner>
    22 <li>Incorrect code generation (JIT and LLC)>
    23
    24

    Written by Chris Lattner and

    25 Misha Brukman

    2426

    2527
    2628
    137139 the full list of objects linked). Then run:

    138140
    139141
    
                      
                    
    140 as < /dev/null > null.bc
    142 llvm-as < /dev/null > null.bc
    141143 gccld -debug-pass=Arguments null.bc
    142144

    143145
    179181
    180182
    181183
    182 Miscompilations
    183
    184
    185
    186 Fortunately we haven't had too many miscompilations. Because of this, this
    187 section is a TODO. Basically, use bugpoint to track down the problem.

    188
    184 Miscompilations
    185
      186 187 188 A miscompilation occurs when a pass does not correctly transform a program, thus 189 producing errors that are only noticed during execution. This is different from 190 producing invalid LLVM code (i.e., code not in SSA form, using values before 191 defining them, etc.) which the verifier will check for after a pass finishes its 192 run.

      193 194 To debug a miscompilation, you should choose which program you wish to run the 195 output through, e.g. C backend, the JIT, or LLC, and a selection of passes, one 196 of which may be causing the error, and run, for example: 197 198

      
                        
                      
      
                    199
                      
                          bugpoint -run-cbe -mode=compile [... optimization passes ...] file-to-test.bc
      
                        
                      
      
                    200
                      
                        
      201 202 bugpoint will try to narrow down your list of passes to the one pass 203 that causes an error, and simplify the bytecode file as much as it can to assist 204 you. It will print a message letting you know how to reproduce the resulting 205 error. 206 207 208
    209
    210 Incorrect code generation
    211
      212 213 214 Similarly to debugging incorrect compilation by mis-behaving passes, you can 215 debug incorrect code generation by either LLC or the JIT, using 216 bugpoint. The process bugpoint follows in this case is to try 217 to narrow the code down to a function that is miscompiled by one or the other 218 method, but since for correctness, the entire program must be run, 219 bugpoint will compile the code it deems to not be affected with the C 220 Backend, and then link in the shared object it generates.

      221 222 To debug the JIT: 223

      
                        
                      
      
                    224
                      
                          bugpoint -run-jit -mode=codegen -output=[correct output file] [bytecodefile]
      
                        
                      
      
                    225
                      
                        
      226 227 Similarly, to debug the LLC, one would run: 228
      
                        
                      
      
                    229
                      
                          bugpoint -run-llc -mode=codegen -output=[correct output file] [bytecodefile]
      
                        
                      
      
                    230
                      
                        
      231 232 At the end of a successful bugpoint run, you will be presented 233 with two bytecode files: a safe file which can be compiled with the C 234 backend and the test file which either LLC or the JIT 235 mis-codegenerates, and thus causes the error.

      236 237 To reproduce the error that bugpoint found, it is sufficient to do the 238 following: 239 240

        241
      1. Regenerate the shared object from the safe bytecode file:
        242
        
                          
                        
        
                      243
                        
                            llvm-dis -c safe.bc -o safe.c
        244 gcc -shared safe.c -o safe.so 245
      2. 246
      3. If debugging LLC, compile test bytecode native and link with the shared object:
        247
        
                          
                        
        
                      248
                        
                            llc test.bc -o test.s -f
        249 gcc test.s safe.so -o test.llc
        250 ./test.llc [program options] 251
      4. 252

        253 If debugging the JIT, load the shared object and supply the test bytecode:
        254

        
                          
                        
        
                      255
                        
                            lli -load=safe.so test.bc [program options]
        
                          
                        
        
                      256
                        
                          
        257
      189258 190259 191260
    195264
    Chris Lattner
    196265 197266 198 Last modified: Fri May 23 09:48:53 CDT 2003 267 Last modified: Wed Sep 17 13:49:15 CDT 2003 199268 200269