From d6c84720df0b63e34081e0c7890f3074d8b110b9 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 25 Feb 2010 19:00:39 +0000 Subject: change the scope node to include a list of children to be checked instead of to have a chained series of scope nodes. This makes the generated table smaller, improves the efficiency of the interpreter, and make the factoring optimization much more reasonable to implement. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97160 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/TableGen/DAGISelMatcherOpt.cpp | 39 ++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'utils/TableGen/DAGISelMatcherOpt.cpp') diff --git a/utils/TableGen/DAGISelMatcherOpt.cpp b/utils/TableGen/DAGISelMatcherOpt.cpp index 002637b..9a6edd3 100644 --- a/utils/TableGen/DAGISelMatcherOpt.cpp +++ b/utils/TableGen/DAGISelMatcherOpt.cpp @@ -21,9 +21,15 @@ static void ContractNodes(OwningPtr &MatcherPtr) { Matcher *N = MatcherPtr.get(); if (N == 0) return; - // If we have a scope node, walk down both edges. - if (ScopeMatcher *Push = dyn_cast(N)) - ContractNodes(Push->getCheckPtr()); + // If we have a scope node, walk down all of the children. + if (ScopeMatcher *Scope = dyn_cast(N)) { + for (unsigned i = 0, e = Scope->getNumChildren(); i != e; ++i) { + OwningPtr Child(Scope->takeChild(i)); + ContractNodes(Child); + Scope->resetChild(i, Child.take()); + } + return; + } // If we found a movechild node with a node that comes in a 'foochild' form, // transform it. @@ -61,32 +67,31 @@ static void FactorNodes(OwningPtr &MatcherPtr) { if (N == 0) return; // If this is not a push node, just scan for one. - if (!isa(N)) + ScopeMatcher *Scope = dyn_cast(N); + if (Scope == 0) return FactorNodes(N->getNextPtr()); - // Okay, pull together the series of linear push nodes into a vector so we can + // Okay, pull together the children of the scope node into a vector so we can // inspect it more easily. While we're at it, bucket them up by the hash // code of their first predicate. SmallVector OptionsToMatch; typedef DenseMap > HashTableTy; HashTableTy MatchersByHash; - Matcher *CurNode = N; - for (; ScopeMatcher *PMN = dyn_cast(CurNode); - CurNode = PMN->getNext()) { + for (unsigned i = 0, e = Scope->getNumChildren(); i != e; ++i) { // Factor the subexpression. - FactorNodes(PMN->getCheckPtr()); - if (Matcher *Check = PMN->getCheck()) { - OptionsToMatch.push_back(Check); - MatchersByHash[Check->getHash()].push_back(Check); + OwningPtr Child(Scope->takeChild(i)); + FactorNodes(Child); + + // FIXME: Eventually don't pass ownership back to the scope node. + Scope->resetChild(i, Child.take()); + + if (Matcher *N = Scope->getChild(i)) { + OptionsToMatch.push_back(N); + MatchersByHash[N->getHash()].push_back(N); } } - if (CurNode) { - OptionsToMatch.push_back(CurNode); - MatchersByHash[CurNode->getHash()].push_back(CurNode); - } - SmallVector NewOptionsToMatch; -- cgit v1.1