[llvm-commits] [llvm] r97215 - /llvm/trunk/utils/TableGen/DAGISelMatcherOpt.cpp

Chris Lattner sabre at nondot.org
Thu Feb 25 23:36:37 PST 2010


Author: lattner
Date: Fri Feb 26 01:36:37 2010
New Revision: 97215

URL: http://llvm.org/viewvc/llvm-project?rev=97215&view=rev
Log:
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! :)

Modified:
    llvm/trunk/utils/TableGen/DAGISelMatcherOpt.cpp

Modified: llvm/trunk/utils/TableGen/DAGISelMatcherOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/DAGISelMatcherOpt.cpp?rev=97215&r1=97214&r2=97215&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/DAGISelMatcherOpt.cpp (original)
+++ llvm/trunk/utils/TableGen/DAGISelMatcherOpt.cpp Fri Feb 26 01:36:37 2010
@@ -83,16 +83,12 @@
     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 @@
     // 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 @@
     // 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 @@
     }
     
     // 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) {





More information about the llvm-commits mailing list