From d20c0bc5698688f69e52dc4d19cedfcd973a7088 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 28 Feb 2010 22:57:03 +0000 Subject: [PATCH] don't emit useless functions. These were producing 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 | 103 ++++++++++++----------- 1 file changed, 56 insertions(+), 47 deletions(-) diff --git a/utils/TableGen/DAGISelMatcherEmitter.cpp b/utils/TableGen/DAGISelMatcherEmitter.cpp index c25243d9eb4..76241c5193e 100644 --- a/utils/TableGen/DAGISelMatcherEmitter.cpp +++ b/utils/TableGen/DAGISelMatcherEmitter.cpp @@ -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 &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 &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) { -- 2.34.1