> For optimized code, there are many optimizations that can break
> coverage info. Code motion is one of them. This patch actually tries
> to fix the broken coverage info, as illustrated by the unittest.

No, you seems to be misunderstanding what coverage means.  For coverage to be 
correct, it is necessary that every insn generated for a particular source 
construct be associated with this source construct in the debug info.  If you 
associate an insn with another source construct and it is executed, then 
you'll have the other source construct marked as covered, although it might 
not be actually covered during the execution.

Code motion (as any other optimization passes) doesn't break coverage per se.
For example, there is nothing wrong with hoisting a instruction out of a loop 
and keeping its source location if it is always executed; coverage info will 
be correct after the hoisting.  In more complex cases, it might be necessary 
to clear the source location of the hoisted instruction.

> If we clear the debug info for instructions moved to other BB, is it
> acceptable?

Yes, clearing is acceptable in principle, but should be done with extreme care 
since you drop information, so reorder_insns isn't the appropriate place as 
it's too big a hammer.

FWIW, we have related patchlets in our internal tree, like:

        * loop-invariant.c (move_invariant_reg): Clear the locator of the
        invariant's insn after it has been moved.

        * tree-ssa-loop-im.c (move_computations_stmt): Clear the location and
        block of the invariant's statement after it has been moved.


As for the more general problem of jumpiness in GDB for highly optimized code, 
this should be changed in GDB if your users cannot deal with it.  The debug 
info describes the relationship between the generated code and the source code 
and, at high optimization levels, this relationship is not isomorphic at all.
It's up to the source level debugger to filter out the non-isomorphic part of 
the mapping if it deems desirable to do so.

-- 
Eric Botcazou

Reply via email to