[llvm-dev] Pass and Transformation-level debugging in LLVM

Zhizhou Yang via llvm-dev llvm-dev at lists.llvm.org
Tue Sep 18 15:49:33 PDT 2018


Hi all,

Debugging a mis-compilation is always time consuming. I recently did some
attempt on bisecting bad pass for LLVM and would like to share some ideas
about how do we make it work. And meanwhile, I would also encourage the
community to make each pass more bisectable with help of DebugCounter.

We have already got a very useful helper in LLVM for pass level bisection,
which is OptBisect <https://llvm.org/docs/OptBisect.html>. Though it only
works for legacy pass manager, Fedor proposed an on-going effort
<https://reviews.llvm.org/D50923> to make similar things work for new pass
manager.

To bring it to the next level, DebugCounter
<http://llvm.org/docs/ProgrammersManual.html#adding-debug-counters-to-aid-in-debugging-your-code>
provides features for me to have an in-pass (transformation) level limit to
tell which transform in the pass exactly caused the error. When we set
StopAfter value for a DebugCounter, it will eventually stop there as a
limit.


And in D50031 <https://reviews.llvm.org/D50031> and rL337748
<https://reviews.llvm.org/rL337748>, I added a method to print DebugCounter
info: the `-print-debug-counter` flag. With this, writing a transformation
level bisection script will be more straightforward.

The issue we face is that the transformation level bisection can only work
in passes with DebugCounters, and very few passes have these today.
DebugCounter is also very useful even a pass author debugs manually without
special bisection tooling. So I would encourage the community to add
DebugCounter to your own passes to make life easier for debugging.

Adding DebugCounters isn’t often too difficult. For example, I have several
patches to add DebugCounter into passes: D50092
<https://reviews.llvm.org/D50092>, D50033 <https://reviews.llvm.org/D50033>.

I have already built a bisection tool to help Android toolchain debug on
our side. So I will say that the bisecting idea with OptBisect and
DebugCounter helps us save time while debugging mis-compilations.

Feel free to post if you have other ideas on this and hope that this thread
can help.

Thanks,

Zhizhou
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180918/5b40141f/attachment.html>


More information about the llvm-dev mailing list