Teaching llvm-tblgen to not emit a switch statement when there are no case statements.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186330 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Aaron Ballman
2013-07-15 16:53:32 +00:00
parent f73f809756
commit 54911a5303
3 changed files with 89 additions and 54 deletions
+13 -8
View File
@@ -879,15 +879,20 @@ emitPredicateFunction(formatted_raw_ostream &OS, PredicateSet &Predicates,
OS.indent(Indentation) << "static bool checkDecoderPredicate(unsigned Idx, "
<< "uint64_t Bits) {\n";
Indentation += 2;
OS.indent(Indentation) << "switch (Idx) {\n";
OS.indent(Indentation) << "default: llvm_unreachable(\"Invalid index!\");\n";
unsigned Index = 0;
for (PredicateSet::const_iterator I = Predicates.begin(), E = Predicates.end();
I != E; ++I, ++Index) {
OS.indent(Indentation) << "case " << Index << ":\n";
OS.indent(Indentation+2) << "return (" << *I << ");\n";
if (!Predicates.empty()) {
OS.indent(Indentation) << "switch (Idx) {\n";
OS.indent(Indentation) << "default: llvm_unreachable(\"Invalid index!\");\n";
unsigned Index = 0;
for (PredicateSet::const_iterator I = Predicates.begin(), E = Predicates.end();
I != E; ++I, ++Index) {
OS.indent(Indentation) << "case " << Index << ":\n";
OS.indent(Indentation+2) << "return (" << *I << ");\n";
}
OS.indent(Indentation) << "}\n";
} else {
// No case statement to emit
OS.indent(Indentation) << "llvm_unreachable(\"Invalid index!\");\n";
}
OS.indent(Indentation) << "}\n";
Indentation -= 2;
OS.indent(Indentation) << "}\n\n";
}