[PATCH] D81021: [TableGen] Avoid generating switch with just default

David Stuttard via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 2 12:05:35 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG9244be7b0514: [TableGen] Avoid generating switch with just default (authored by dstuttard).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81021/new/

https://reviews.llvm.org/D81021

Files:
  llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp


Index: llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp
===================================================================
--- llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp
+++ llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp
@@ -612,18 +612,23 @@
 
 void GIMatchTreeOpcodePartitioner::generatePartitionSelectorCode(
     raw_ostream &OS, StringRef Indent) const {
-  OS << Indent << "Partition = -1;\n"
-     << Indent << "switch (MIs[" << InstrID << "]->getOpcode()) {\n";
-  for (const auto &EnumInstr : enumerate(PartitionToInstr)) {
-    if (EnumInstr.value() == nullptr)
-      OS << Indent << "default:";
-    else
-      OS << Indent << "case " << EnumInstr.value()->Namespace
-         << "::" << EnumInstr.value()->TheDef->getName() << ":";
-    OS << " Partition = " << EnumInstr.index() << "; break;\n";
+  // Make sure not to emit empty switch or switch with just default
+  if (PartitionToInstr.size() == 1 && PartitionToInstr[0] == nullptr) {
+    OS << Indent << "Partition = 0;\n";
+  } else if (PartitionToInstr.size()) {
+    OS << Indent << "Partition = -1;\n"
+       << Indent << "switch (MIs[" << InstrID << "]->getOpcode()) {\n";
+    for (const auto &EnumInstr : enumerate(PartitionToInstr)) {
+      if (EnumInstr.value() == nullptr)
+        OS << Indent << "default:";
+      else
+        OS << Indent << "case " << EnumInstr.value()->Namespace
+           << "::" << EnumInstr.value()->TheDef->getName() << ":";
+      OS << " Partition = " << EnumInstr.index() << "; break;\n";
+    }
+    OS << Indent << "}\n";
   }
-  OS << Indent << "}\n"
-     << Indent
+  OS << Indent
      << "// Default case but without conflicting with potential default case "
         "in selection.\n"
      << Indent << "if (Partition == -1) return false;\n";
@@ -775,4 +780,3 @@
 
   OS << Indent << "if (Partition == -1) return false;\n";
 }
-


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81021.267949.patch
Type: text/x-patch
Size: 1856 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200602/ec02770d/attachment.bin>


More information about the llvm-commits mailing list