aboutsummaryrefslogtreecommitdiffstats
path: root/utils/TableGen/DAGISelMatcherOpt.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-02-26 07:36:37 +0000
committerChris Lattner <sabre@nondot.org>2010-02-26 07:36:37 +0000
commitd4397b9481cd848e580c86b4beb0d22e8c3d1213 (patch)
tree0ee3bd0679cacd7dd29f49b7f3da3de196805887 /utils/TableGen/DAGISelMatcherOpt.cpp
parentca56feaf381db61ad1f07873235185ef33f6426f (diff)
downloadexternal_llvm-d4397b9481cd848e580c86b4beb0d22e8c3d1213.zip
external_llvm-d4397b9481cd848e580c86b4beb0d22e8c3d1213.tar.gz
external_llvm-d4397b9481cd848e580c86b4beb0d22e8c3d1213.tar.bz2
finish off the factoring optimization along the lines of the
current design. This generates a matcher that successfully runs, but it turns out that the factoring we're doing violates the ordering of patterns, so we end up matching (e.g.) movups where we want movaps. This won't due, but I'll address this in a follow on patch. It's nice to not be on by default yet! :) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97215 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/DAGISelMatcherOpt.cpp')
-rw-r--r--utils/TableGen/DAGISelMatcherOpt.cpp43
1 files changed, 32 insertions, 11 deletions
diff --git a/utils/TableGen/DAGISelMatcherOpt.cpp b/utils/TableGen/DAGISelMatcherOpt.cpp
index 9a6edd3..d4796e9 100644
--- a/utils/TableGen/DAGISelMatcherOpt.cpp
+++ b/utils/TableGen/DAGISelMatcherOpt.cpp
@@ -83,16 +83,12 @@ static void FactorNodes(OwningPtr<Matcher> &MatcherPtr) {
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)) {
+ if (Matcher *N = Child.take()) {
OptionsToMatch.push_back(N);
MatchersByHash[N->getHash()].push_back(N);
}
}
-
SmallVector<Matcher*, 32> NewOptionsToMatch;
// Now that we have bucketed up things by hash code, iterate over sets of
@@ -109,7 +105,10 @@ static void FactorNodes(OwningPtr<Matcher> &MatcherPtr) {
// hash table, then we must have previously processed a node equal to this
// one.
HashTableTy::iterator DMI = MatchersByHash.find(Optn->getHash());
- if (DMI == MatchersByHash.end()) continue;
+ if (DMI == MatchersByHash.end()) {
+ delete Optn;
+ continue;
+ }
std::vector<Matcher*> &HashMembers = DMI->second;
assert(!HashMembers.empty() && "Should be removed if empty");
@@ -118,7 +117,10 @@ static void FactorNodes(OwningPtr<Matcher> &MatcherPtr) {
// previous node and removed.
std::vector<Matcher*>::iterator MemberSlot =
std::find(HashMembers.begin(), HashMembers.end(), Optn);
- if (MemberSlot == HashMembers.end()) continue;
+ if (MemberSlot == HashMembers.end()) {
+ delete Optn;
+ continue;
+ }
// If the node *does* exist in HashMembers, then we've confirmed that it
// hasn't been processed as equal to a previous node. Process it now, start
@@ -155,14 +157,33 @@ static void FactorNodes(OwningPtr<Matcher> &MatcherPtr) {
}
// Factor these checks by pulling the first node off each entry and
- // discarding it, replacing it with...
- // something amazing??
+ // discarding it. Take the first one off the first entry to reuse.
+ Matcher *Shared = Optn;
+ Optn = Optn->takeNext();
+ EqualMatchers[0] = Optn;
+
+ // Skip the first node. Leave the first node around though, we'll delete it
+ // on subsequent iterations over OptionsToMatch.
+ for (unsigned i = 1, e = EqualMatchers.size(); i != e; ++i)
+ EqualMatchers[i] = EqualMatchers[i]->takeNext();
+
+ Shared->setNext(new ScopeMatcher(&EqualMatchers[0], EqualMatchers.size()));
+
+ // Recursively factor the newly created node.
+ FactorNodes(Shared->getNextPtr());
- // FIXME: Need to change the Scope model.
+ NewOptionsToMatch.push_back(Shared);
}
// Reassemble a new Scope node.
-
+ assert(!NewOptionsToMatch.empty() && "where'd all our children go?");
+ if (NewOptionsToMatch.size() == 1)
+ MatcherPtr.reset(NewOptionsToMatch[0]);
+ else {
+ Scope->setNumChildren(NewOptionsToMatch.size());
+ for (unsigned i = 0, e = NewOptionsToMatch.size(); i != e; ++i)
+ Scope->resetChild(i, NewOptionsToMatch[i]);
+ }
}
Matcher *llvm::OptimizeMatcher(Matcher *TheMatcher) {