don't emit the old sdnodexform stuff for the new isel.
[oota-llvm.git] / utils / TableGen / DAGISelEmitter.cpp
index fbf3f86e08065519b599a16f065c9352a21c2ee1..bc57428f7888488758cc2faec356ffc109aae508 100644 (file)
@@ -24,7 +24,7 @@
 #include <iostream>
 using namespace llvm;
 
-//#define ENABLE_NEW_ISEL
+#define ENABLE_NEW_ISEL
 
 
 static cl::opt<bool>
@@ -1933,20 +1933,18 @@ void DAGISelEmitter::run(raw_ostream &OS) {
      << "// by the instruction selector.\n";
   OS << "#include \"llvm/CodeGen/DAGISelHeader.h\"\n\n";
   
-  EmitNodeTransforms(OS);
+  DEBUG(errs() << "\n\nALL PATTERNS TO MATCH:\n\n";
+        for (CodeGenDAGPatterns::ptm_iterator I = CGP.ptm_begin(),
+             E = CGP.ptm_end(); I != E; ++I) {
+          errs() << "PATTERN: ";   I->getSrcPattern()->dump();
+          errs() << "\nRESULT:  "; I->getDstPattern()->dump();
+          errs() << "\n";
+        });
+
+  // FIXME: These are being used by hand written code, gross.
   EmitPredicateFunctions(OS);
-  
-  DEBUG(errs() << "\n\nALL PATTERNS TO MATCH:\n\n");
-  for (CodeGenDAGPatterns::ptm_iterator I = CGP.ptm_begin(), E = CGP.ptm_end();
-       I != E; ++I) {
-    DEBUG(errs() << "PATTERN: ";   I->getSrcPattern()->dump());
-    DEBUG(errs() << "\nRESULT:  "; I->getDstPattern()->dump());
-    DEBUG(errs() << "\n");
-  }
-  
-#ifdef ENABLE_NEW_ISEL
-  Matcher *TheMatcher = 0;
 
+#ifdef ENABLE_NEW_ISEL
   // Add all the patterns to a temporary list so we can sort them.
   std::vector<const PatternToMatch*> Patterns;
   for (CodeGenDAGPatterns::ptm_iterator I = CGP.ptm_begin(), E = CGP.ptm_end();
@@ -1960,27 +1958,29 @@ void DAGISelEmitter::run(raw_ostream &OS) {
                    PatternSortingPredicate2(CGP));
   
   
-  // Walk the patterns backwards (since we append to the front of the generated
-  // code), building a matcher for each and adding it to the matcher for the
-  // whole target.
-  while (!Patterns.empty()) {
-    const PatternToMatch &Pattern = *Patterns.back();
-    Patterns.pop_back();
-    
-    Matcher *N = ConvertPatternToMatcher(Pattern, CGP);
-    
-    if (TheMatcher == 0)
-      TheMatcher = N;
-    else
-      TheMatcher = new ScopeMatcher(N, TheMatcher);
+  // Convert each variant of each pattern into a Matcher.
+  std::vector<Matcher*> PatternMatchers;
+  for (unsigned i = 0, e = Patterns.size(); i != e; ++i) {
+    for (unsigned Variant = 0; ; ++Variant) {
+      if (Matcher *M = ConvertPatternToMatcher(*Patterns[i], Variant, CGP))
+        PatternMatchers.push_back(M);
+      else
+        break;
+    }
   }
+          
+  
+  Matcher *TheMatcher = new ScopeMatcher(&PatternMatchers[0],
+                                         PatternMatchers.size());
 
-  TheMatcher = OptimizeMatcher(TheMatcher);
+  TheMatcher = OptimizeMatcher(TheMatcher, CGP);
   //Matcher->dump();
-  EmitMatcherTable(TheMatcher, OS);
+  EmitMatcherTable(TheMatcher, CGP, OS);
   delete TheMatcher;
   
 #else
+  EmitNodeTransforms(OS);
+
   // At this point, we have full information about the 'Patterns' we need to
   // parse, both implicitly from instructions as well as from explicit pattern
   // definitions.  Emit the resultant instruction selector.