[llvm-commits] [llvm] r97431 - in /llvm/trunk/utils/TableGen: DAGISelEmitter.cpp DAGISelMatcher.h DAGISelMatcherEmitter.cpp DAGISelMatcherGen.cpp

Chris Lattner sabre at nondot.org
Sun Feb 28 17:54:19 PST 2010


Author: lattner
Date: Sun Feb 28 19:54:19 2010
New Revision: 97431

URL: http://llvm.org/viewvc/llvm-project?rev=97431&view=rev
Log:
inline the node transforms and node predicates into the generated
dispatcher method.  This eliminates the dependence of the new isel's
generated code on the old isel's predicates, however some random
hand written isel code still uses them.

Modified:
    llvm/trunk/utils/TableGen/DAGISelEmitter.cpp
    llvm/trunk/utils/TableGen/DAGISelMatcher.h
    llvm/trunk/utils/TableGen/DAGISelMatcherEmitter.cpp
    llvm/trunk/utils/TableGen/DAGISelMatcherGen.cpp

Modified: llvm/trunk/utils/TableGen/DAGISelEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/DAGISelEmitter.cpp?rev=97431&r1=97430&r2=97431&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/DAGISelEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/DAGISelEmitter.cpp Sun Feb 28 19:54:19 2010
@@ -1933,17 +1933,18 @@
      << "// by the instruction selector.\n";
   OS << "#include \"llvm/CodeGen/DAGISelHeader.h\"\n\n";
   
+  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.
   EmitNodeTransforms(OS);
   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
   // Add all the patterns to a temporary list so we can sort them.
   std::vector<const PatternToMatch*> Patterns;
@@ -1968,10 +1969,11 @@
 
   TheMatcher = OptimizeMatcher(TheMatcher, CGP);
   //Matcher->dump();
-  EmitMatcherTable(TheMatcher, OS);
+  EmitMatcherTable(TheMatcher, CGP, OS);
   delete TheMatcher;
   
 #else
+  
   // 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.

Modified: llvm/trunk/utils/TableGen/DAGISelMatcher.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/DAGISelMatcher.h?rev=97431&r1=97430&r2=97431&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/DAGISelMatcher.h (original)
+++ llvm/trunk/utils/TableGen/DAGISelMatcher.h Sun Feb 28 19:54:19 2010
@@ -28,7 +28,8 @@
 Matcher *ConvertPatternToMatcher(const PatternToMatch &Pattern,
                                  const CodeGenDAGPatterns &CGP);
 Matcher *OptimizeMatcher(Matcher *Matcher, const CodeGenDAGPatterns &CGP);
-void EmitMatcherTable(const Matcher *Matcher, raw_ostream &OS);
+void EmitMatcherTable(const Matcher *Matcher, const CodeGenDAGPatterns &CGP,
+                      raw_ostream &OS);
 
   
 /// Matcher - Base class for all the the DAG ISel Matcher representation

Modified: llvm/trunk/utils/TableGen/DAGISelMatcherEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/DAGISelMatcherEmitter.cpp?rev=97431&r1=97430&r2=97431&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/DAGISelMatcherEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/DAGISelMatcherEmitter.cpp Sun Feb 28 19:54:19 2010
@@ -34,7 +34,7 @@
 
 
   DenseMap<Record*, unsigned> NodeXFormMap;
-  std::vector<const Record*> NodeXForms;
+  std::vector<Record*> NodeXForms;
 
   // Per opcode frequence count. 
   std::vector<unsigned> Histogram;
@@ -44,7 +44,8 @@
   unsigned EmitMatcherList(const Matcher *N, unsigned Indent,
                            unsigned StartIdx, formatted_raw_ostream &OS);
   
-  void EmitPredicateFunctions(formatted_raw_ostream &OS);
+  void EmitPredicateFunctions(const CodeGenDAGPatterns &CGP,
+                              formatted_raw_ostream &OS);
   
   void EmitHistogram(formatted_raw_ostream &OS);
 private:
@@ -440,7 +441,8 @@
   return Size;
 }
 
-void MatcherTableEmitter::EmitPredicateFunctions(formatted_raw_ostream &OS) {
+void MatcherTableEmitter::EmitPredicateFunctions(const CodeGenDAGPatterns &CGP,
+                                                 formatted_raw_ostream &OS) {
   // FIXME: Don't build off the DAGISelEmitter's predicates, emit them directly
   // here into the case stmts.
   
@@ -454,15 +456,40 @@
     OS << "  }\n";
     OS << "}\n\n";
   }
-    
-
+   
   // Emit Node predicates.
+  // FIXME: Annoyingly, these are stored by name, which we never even emit. Yay?
+  StringMap<TreePattern*> PFsByName;
+  
+  for (CodeGenDAGPatterns::pf_iterator I = CGP.pf_begin(), E = CGP.pf_end();
+       I != E; ++I)
+    PFsByName[I->first->getName()] = I->second;
+  
   if (!NodePredicates.empty()) {
-    OS << "bool CheckNodePredicate(SDNode *N, unsigned PredNo) const {\n";
+    OS << "bool CheckNodePredicate(SDNode *Node, unsigned PredNo) const {\n";
     OS << "  switch (PredNo) {\n";
     OS << "  default: assert(0 && \"Invalid predicate in table?\");\n";
-    for (unsigned i = 0, e = NodePredicates.size(); i != e; ++i)
-      OS << "  case " << i << ": return "  << NodePredicates[i] << "(N);\n";
+    for (unsigned i = 0, e = NodePredicates.size(); i != e; ++i) {
+      // FIXME: Storing this by name is horrible.
+      TreePattern *P =PFsByName[NodePredicates[i].substr(strlen("Predicate_"))];
+      assert(P && "Unknown name?");
+      
+      // Emit the predicate code corresponding to this pattern.
+      std::string Code = P->getRecord()->getValueAsCode("Predicate");
+      assert(!Code.empty() && "No code in this predicate");
+      OS << "  case " << i << ": { // " << NodePredicates[i] << '\n';
+      std::string ClassName;
+      if (P->getOnlyTree()->isLeaf())
+        ClassName = "SDNode";
+      else
+        ClassName =
+          CGP.getSDNodeInfo(P->getOnlyTree()->getOperator()).getSDClassName();
+      if (ClassName == "SDNode")
+        OS << "    SDNode *N = Node;\n";
+      else
+        OS << "    " << ClassName << "*N = cast<" << ClassName << ">(Node);\n";
+      OS << Code << "\n  }\n";
+    }
     OS << "  }\n";
     OS << "}\n\n";
   }
@@ -498,6 +525,7 @@
     OS << "}\n\n";
   }
   
+  
   // Emit SDNodeXForm handlers.
   // FIXME: This should be const.
   if (!NodeXForms.empty()) {
@@ -506,9 +534,23 @@
     OS << "  default: assert(0 && \"Invalid xform # in table?\");\n";
     
     // FIXME: The node xform could take SDValue's instead of SDNode*'s.
-    for (unsigned i = 0, e = NodeXForms.size(); i != e; ++i)
-      OS << "  case " << i << ": return Transform_" << NodeXForms[i]->getName()
-         << "(V.getNode());\n";
+    for (unsigned i = 0, e = NodeXForms.size(); i != e; ++i) {
+      const CodeGenDAGPatterns::NodeXForm &Entry =
+        CGP.getSDNodeTransform(NodeXForms[i]);
+      
+      Record *SDNode = Entry.first;
+      const std::string &Code = Entry.second;
+      
+      OS << "  case " << i << ": {  // " << NodeXForms[i]->getName() << '\n';
+      
+      std::string ClassName = CGP.getSDNodeInfo(SDNode).getSDClassName();
+      if (ClassName == "SDNode")
+        OS << "    SDNode *N = V.getNode();\n";
+      else
+        OS << "    " << ClassName << " *N = cast<" << ClassName
+           << ">(V.getNode());\n";
+      OS << Code << "\n  }\n";
+    }
     OS << "  }\n";
     OS << "}\n\n";
   }
@@ -562,7 +604,8 @@
 }
 
 
-void llvm::EmitMatcherTable(const Matcher *TheMatcher, raw_ostream &O) {
+void llvm::EmitMatcherTable(const Matcher *TheMatcher,
+                            const CodeGenDAGPatterns &CGP, raw_ostream &O) {
   formatted_raw_ostream OS(O);
   
   OS << "// The main instruction selector code.\n";
@@ -583,5 +626,5 @@
   OS << "\n";
   
   // Next up, emit the function for node and pattern predicates:
-  MatcherEmitter.EmitPredicateFunctions(OS);
+  MatcherEmitter.EmitPredicateFunctions(CGP, OS);
 }

Modified: llvm/trunk/utils/TableGen/DAGISelMatcherGen.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/DAGISelMatcherGen.cpp?rev=97431&r1=97430&r2=97431&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/DAGISelMatcherGen.cpp (original)
+++ llvm/trunk/utils/TableGen/DAGISelMatcherGen.cpp Sun Feb 28 19:54:19 2010
@@ -829,7 +829,7 @@
   // that tells the matcher about them so that it can update their results.
   if (!MatchedFlagResultNodes.empty())
     AddMatcher(new MarkFlagResultsMatcher(MatchedFlagResultNodes.data(),
-                                                MatchedFlagResultNodes.size()));
+                                          MatchedFlagResultNodes.size()));
   
   
   // We know that the resulting pattern has exactly one result/





More information about the llvm-commits mailing list