diff options
| -rw-r--r-- | utils/TableGen/DAGISelMatcherEmitter.cpp | 103 | 
1 files changed, 56 insertions, 47 deletions
| diff --git a/utils/TableGen/DAGISelMatcherEmitter.cpp b/utils/TableGen/DAGISelMatcherEmitter.cpp index c25243d..76241c5 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<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) { | 
