mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 18:54:02 +01:00
[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
This commit is contained in:
parent
8b0a9dd9e7
commit
b7704a045e
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user