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
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 @@
Matcher *N = MatcherPtr.get();
if (N == 0) return;
- // If we have a scope node, walk down both edges.
- if (ScopeMatcher *Push = dyn_cast<ScopeMatcher>(N))
- ContractNodes(Push->getCheckPtr());
+ // If we have a scope node, walk down all of the children.
+ if (ScopeMatcher *Scope = dyn_cast<ScopeMatcher>(N)) {
+ for (unsigned i = 0, e = Scope->getNumChildren(); i != e; ++i) {
+ OwningPtr<Matcher> 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 @@
if (N == 0) return;
// If this is not a push node, just scan for one.
- if (!isa<ScopeMatcher>(N))
+ ScopeMatcher *Scope = dyn_cast<ScopeMatcher>(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<Matcher*, 32> OptionsToMatch;
typedef DenseMap<unsigned, std::vector<Matcher*> > HashTableTy;
HashTableTy MatchersByHash;
- Matcher *CurNode = N;
- for (; ScopeMatcher *PMN = dyn_cast<ScopeMatcher>(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<Matcher> 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<Matcher*, 32> NewOptionsToMatch;