[llvm-commits] CVS: llvm/utils/TableGen/AsmWriterEmitter.cpp

Chris Lattner lattner at cs.uiuc.edu
Tue Jul 18 10:44:07 PDT 2006



Changes in directory llvm/utils/TableGen:

AsmWriterEmitter.cpp updated: 1.33 -> 1.34
---
Log message:

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


---
Diffs of the changes:  (+24 -10)

 AsmWriterEmitter.cpp |   34 ++++++++++++++++++++++++----------
 1 files changed, 24 insertions(+), 10 deletions(-)


Index: llvm/utils/TableGen/AsmWriterEmitter.cpp
diff -u llvm/utils/TableGen/AsmWriterEmitter.cpp:1.33 llvm/utils/TableGen/AsmWriterEmitter.cpp:1.34
--- llvm/utils/TableGen/AsmWriterEmitter.cpp:1.33	Tue Jul 18 12:38:46 2006
+++ llvm/utils/TableGen/AsmWriterEmitter.cpp	Tue Jul 18 12:43:54 2006
@@ -560,18 +560,32 @@
     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






More information about the llvm-commits mailing list