Emit switches with 1/2 cases as unconditional code or an if/then/else for

tidyness.

llvm-svn: 29181
This commit is contained in:
Chris Lattner 2006-07-18 17:43:54 +00:00
parent b84950e599
commit 2c14435831

View File

@ -560,18 +560,32 @@ void AsmWriterEmitter::run(std::ostream &O) {
BitsLeft -= NumBits;
O << "\n // Fragment " << i << " encoded into " << NumBits
<< " bits for " << Commands.size() << " unique commands.\n"
<< " switch ((Bits >> " << (BitsLeft+AsmStrBits) << ") & "
<< ((1 << NumBits)-1) << ") {\n"
<< " default: // unreachable.\n";
<< " bits for " << Commands.size() << " unique commands.\n";
// Print out all the cases.
for (unsigned i = 0, e = Commands.size(); i != e; ++i) {
O << " case " << i << ":\n";
O << Commands[i];
O << " break;\n";
if (Commands.size() == 1) {
// Only one possibility, just emit it.
O << Commands[0];
} else if (Commands.size() == 2) {
// Emit two possibilitys with if/else.
O << " if ((Bits >> " << (BitsLeft+AsmStrBits) << ") & "
<< ((1 << NumBits)-1) << ") {\n"
<< Commands[1]
<< " } else {\n"
<< Commands[0]
<< " }\n\n";
} else {
O << " switch ((Bits >> " << (BitsLeft+AsmStrBits) << ") & "
<< ((1 << NumBits)-1) << ") {\n"
<< " default: // unreachable.\n";
// Print out all the cases.
for (unsigned i = 0, e = Commands.size(); i != e; ++i) {
O << " case " << i << ":\n";
O << Commands[i];
O << " break;\n";
}
O << " }\n\n";
}
O << " }\n\n";
}
// Okay, go through and strip out the operand information that we just