diff options
| author | Jon Chesterfield <jonathanchesterfield@gmail.com> | 2017-02-06 19:41:44 +0000 |
|---|---|---|
| committer | Jon Chesterfield <jonathanchesterfield@gmail.com> | 2017-02-06 19:41:44 +0000 |
| commit | 1b4eed4c1e11ea5f51b00ad18cbc45c4169ba8a4 (patch) | |
| tree | 775640cfdb02819b7e9d71a354954619a670aebb /llvm/utils/TableGen | |
| parent | 3746deb9d8b31c766fe06295ef2c4c33849bdb48 (diff) | |
| download | bcm5719-llvm-1b4eed4c1e11ea5f51b00ad18cbc45c4169ba8a4.tar.gz bcm5719-llvm-1b4eed4c1e11ea5f51b00ad18cbc45c4169ba8a4.zip | |
[TableGen] Use less stack in DAGISelMatcherOpt
Refactor a helper function, FactorNodes, to search for a push node in constant space. This resolves a problem in a not-yet-upstreamed backend where a recursive pattern blew the call stack (at a depth of 255) under a debug build of tablegen. No functional change so no new test coverage. The change is minimal to avoid disturbing existing behaviour.
Differential Revision: https://reviews.llvm.org/D29080
llvm-svn: 294230
Diffstat (limited to 'llvm/utils/TableGen')
| -rw-r--r-- | llvm/utils/TableGen/DAGISelMatcherOpt.cpp | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/llvm/utils/TableGen/DAGISelMatcherOpt.cpp b/llvm/utils/TableGen/DAGISelMatcherOpt.cpp index 783b35e745f..0bb656826fb 100644 --- a/llvm/utils/TableGen/DAGISelMatcherOpt.cpp +++ b/llvm/utils/TableGen/DAGISelMatcherOpt.cpp @@ -181,15 +181,21 @@ static Matcher *FindNodeWithKind(Matcher *M, Matcher::KindTy Kind) { /// ABC /// XYZ /// -static void FactorNodes(std::unique_ptr<Matcher> &MatcherPtr) { - // If we reached the end of the chain, we're done. - Matcher *N = MatcherPtr.get(); - if (!N) return; - - // If this is not a push node, just scan for one. - ScopeMatcher *Scope = dyn_cast<ScopeMatcher>(N); - if (!Scope) - return FactorNodes(N->getNextPtr()); +static void FactorNodes(std::unique_ptr<Matcher> &InputMatcherPtr) { + // Look for a push node. Iterates instead of recurses to reduce stack usage. + ScopeMatcher *Scope = nullptr; + std::unique_ptr<Matcher> *RebindableMatcherPtr = &InputMatcherPtr; + while (!Scope) { + // If we reached the end of the chain, we're done. + Matcher *N = RebindableMatcherPtr->get(); + if (!N) return; + + // If this is not a push node, just scan for one. + Scope = dyn_cast<ScopeMatcher>(N); + if (!Scope) + RebindableMatcherPtr = &(N->getNextPtr()); + } + std::unique_ptr<Matcher> &MatcherPtr = *RebindableMatcherPtr; // Okay, pull together the children of the scope node into a vector so we can // inspect it more easily. |

