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

llvm-svn: 294230
  • Loading branch information
JonChesterfield committed Feb 6, 2017
1 parent 3746deb commit 1b4eed4
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions llvm/utils/TableGen/DAGISelMatcherOpt.cpp
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 1b4eed4

Please sign in to comment.