Skip to content

Commit

Permalink
[TableGen] Use less stack in DAGISelMatcherOpt
Browse files Browse the repository at this point in the history
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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294230 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
JonChesterfield committed Feb 6, 2017
1 parent 8ebf30a commit 919fdbb
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions utils/TableGen/DAGISelMatcherOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 919fdbb

Please sign in to comment.