OSDN Git Service

[PM] Fix a bug where through CGSCC iteration we can get
authorChandler Carruth <chandlerc@gmail.com>
Wed, 2 Aug 2017 02:09:22 +0000 (02:09 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Wed, 2 Aug 2017 02:09:22 +0000 (02:09 +0000)
commit759393be2d535d080304d4ca4e610a33573d06da
tree087b35962c34818768bbd2c6988b87b870971d30
parent6023e68daed92f71bcf9cc6203a9a5560a93b311
[PM] Fix a bug where through CGSCC iteration we can get
infinite-inlining across multiple runs of the inliner by keeping a tiny
history of internal-to-SCC inlining decisions.

This is still a bit gross, but I don't yet have any fundamentally better
ideas and numerous people are blocked on this to use new PM and ThinLTO
together.

The core of the idea is to detect when we are about to do an inline that
has a chance of re-splitting an SCC which we have split before with
a similar inlining step. That is a critical component in the inlining
forming a cycle and so far detects all of the various cyclic patterns
I can come up with as well as the original real-world test case (which
comes from a ThinLTO build of libunwind).

I've added some tests that I think really demonstrate what is going on
here. They are essentially state machines that march the inliner through
various steps of a cycle and check that we stop when the cycle is closed
and that we actually did do inlining to form that cycle.

A lot of thanks go to Eric Christopher and Sanjoy Das for the help
understanding this issue and improving the test cases.

The biggest "yuck" here is the layering issue -- the CGSCC pass manager
is providing somewhat magical state to the inliner for it to use to make
itself converge. This isn't great, but I don't honestly have a lot of
better ideas yet and at least seems nicely isolated.

I have tested this patch, and it doesn't block *any* inlining on the
entire LLVM test suite and SPEC, so it seems sufficiently narrowly
targeted to the issue at hand.

We have come up with hypothetical issues that this patch doesn't cover,
but so far none of them are practical and we don't have a viable
solution yet that covers the hypothetical stuff, so proceeding here in
the interim. Definitely an area that we will be back and revisiting in
the future.

Differential Revision: https://reviews.llvm.org/D36188

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@309784 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Analysis/CGSCCPassManager.h
lib/Transforms/IPO/Inliner.cpp
test/Transforms/Inline/cgscc-cycle.ll [new file with mode: 0644]