don't emit useless functions. These were producing
authorChris Lattner <sabre@nondot.org>
Sun, 28 Feb 2010 22:57:03 +0000 (22:57 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 28 Feb 2010 22:57:03 +0000 (22:57 +0000)
warnings in release-assert builds if there were no cases.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97428 91177308-0d34-0410-b5e6-96231b3b80d8

utils/TableGen/DAGISelMatcherEmitter.cpp

index c25243d9eb4391e12664968d8b08c55c37cf13b1..76241c5193ebc78f58ff5f9036f26fb61f1badb9 100644 (file)
@@ -445,64 +445,73 @@ void MatcherTableEmitter::EmitPredicateFunctions(formatted_raw_ostream &OS) {
   // here into the case stmts.
   
   // Emit pattern predicates.
-  OS << "bool CheckPatternPredicate(unsigned PredNo) const {\n";
-  OS << "  switch (PredNo) {\n";
-  OS << "  default: assert(0 && \"Invalid predicate in table?\");\n";
-  for (unsigned i = 0, e = PatternPredicates.size(); i != e; ++i)
-    OS << "  case " << i << ": return "  << PatternPredicates[i] << ";\n";
-  OS << "  }\n";
-  OS << "}\n\n";
+  if (!PatternPredicates.empty()) {
+    OS << "bool CheckPatternPredicate(unsigned PredNo) const {\n";
+    OS << "  switch (PredNo) {\n";
+    OS << "  default: assert(0 && \"Invalid predicate in table?\");\n";
+    for (unsigned i = 0, e = PatternPredicates.size(); i != e; ++i)
+      OS << "  case " << i << ": return "  << PatternPredicates[i] << ";\n";
+    OS << "  }\n";
+    OS << "}\n\n";
+  }
+    
 
   // Emit Node predicates.
-  OS << "bool CheckNodePredicate(SDNode *N, 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";
-  OS << "  }\n";
-  OS << "}\n\n";
+  if (!NodePredicates.empty()) {
+    OS << "bool CheckNodePredicate(SDNode *N, 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";
+    OS << "  }\n";
+    OS << "}\n\n";
+  }
   
   // Emit CompletePattern matchers.
   // FIXME: This should be const.
-  OS << "bool CheckComplexPattern(SDNode *Root, SDValue N,\n";
-  OS << "      unsigned PatternNo, SmallVectorImpl<SDValue> &Result) {\n";
-  OS << "  switch (PatternNo) {\n";
-  OS << "  default: assert(0 && \"Invalid pattern # in table?\");\n";
-  for (unsigned i = 0, e = ComplexPatterns.size(); i != e; ++i) {
-    const ComplexPattern &P = *ComplexPatterns[i];
-    unsigned NumOps = P.getNumOperands();
+  if (!ComplexPatterns.empty()) {
+    OS << "bool CheckComplexPattern(SDNode *Root, SDValue N,\n";
+    OS << "      unsigned PatternNo, SmallVectorImpl<SDValue> &Result) {\n";
+    OS << "  switch (PatternNo) {\n";
+    OS << "  default: assert(0 && \"Invalid pattern # in table?\");\n";
+    for (unsigned i = 0, e = ComplexPatterns.size(); i != e; ++i) {
+      const ComplexPattern &P = *ComplexPatterns[i];
+      unsigned NumOps = P.getNumOperands();
 
-    if (P.hasProperty(SDNPHasChain))
-      ++NumOps;  // Get the chained node too.
-    
-    OS << "  case " << i << ":\n";
-    OS << "    Result.resize(Result.size()+" << NumOps << ");\n";
-    OS << "    return "  << P.getSelectFunc();
+      if (P.hasProperty(SDNPHasChain))
+        ++NumOps;  // Get the chained node too.
+      
+      OS << "  case " << i << ":\n";
+      OS << "    Result.resize(Result.size()+" << NumOps << ");\n";
+      OS << "    return "  << P.getSelectFunc();
 
-    // FIXME: Temporary hack until old isel dies.
-    if (P.hasProperty(SDNPHasChain))
-      OS << "XXX";
-    
-    OS << "(Root, N";
-    for (unsigned i = 0; i != NumOps; ++i)
-      OS << ", Result[Result.size()-" << (NumOps-i) << ']';
-    OS << ");\n";
+      // FIXME: Temporary hack until old isel dies.
+      if (P.hasProperty(SDNPHasChain))
+        OS << "XXX";
+      
+      OS << "(Root, N";
+      for (unsigned i = 0; i != NumOps; ++i)
+        OS << ", Result[Result.size()-" << (NumOps-i) << ']';
+      OS << ");\n";
+    }
+    OS << "  }\n";
+    OS << "}\n\n";
   }
-  OS << "  }\n";
-  OS << "}\n\n";
   
   // Emit SDNodeXForm handlers.
   // FIXME: This should be const.
-  OS << "SDValue RunSDNodeXForm(SDValue V, unsigned XFormNo) {\n";
-  OS << "  switch (XFormNo) {\n";
-  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";
-  OS << "  }\n";
-  OS << "}\n\n";
+  if (!NodeXForms.empty()) {
+    OS << "SDValue RunSDNodeXForm(SDValue V, unsigned XFormNo) {\n";
+    OS << "  switch (XFormNo) {\n";
+    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";
+    OS << "  }\n";
+    OS << "}\n\n";
+  }
 }
 
 void MatcherTableEmitter::EmitHistogram(formatted_raw_ostream &OS) {