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 66e288bec3
commit 75dcf6cbd8
1 changed files with 24 additions and 10 deletions

View File

@ -560,8 +560,21 @@ 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) << ") & "
<< " bits for " << Commands.size() << " unique commands.\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";
@ -573,6 +586,7 @@ void AsmWriterEmitter::run(std::ostream &O) {
}
O << " }\n\n";
}
}
// Okay, go through and strip out the operand information that we just
// emitted.