[llvm] 28fd75c - [TableGen] Don't emit empty switch statement for Combiner Match Tables

via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 11 03:11:34 PDT 2023


Author: pvanhout
Date: 2023-07-11T12:11:27+02:00
New Revision: 28fd75c64f875999638951300a135bf099972dd8

URL: https://github.com/llvm/llvm-project/commit/28fd75c64f875999638951300a135bf099972dd8
DIFF: https://github.com/llvm/llvm-project/commit/28fd75c64f875999638951300a135bf099972dd8.diff

LOG: [TableGen] Don't emit empty switch statement for Combiner Match Tables

The change in `emitCxxPredicateFns` is NFC, just a cleanup

Added: 
    

Modified: 
    llvm/utils/TableGen/GlobalISelCombinerMatchTableEmitter.cpp
    llvm/utils/TableGen/GlobalISelMatchTableExecutorEmitter.h

Removed: 
    


################################################################################
diff  --git a/llvm/utils/TableGen/GlobalISelCombinerMatchTableEmitter.cpp b/llvm/utils/TableGen/GlobalISelCombinerMatchTableEmitter.cpp
index 53d76ff02da969..1a391e96e7b81d 100644
--- a/llvm/utils/TableGen/GlobalISelCombinerMatchTableEmitter.cpp
+++ b/llvm/utils/TableGen/GlobalISelCombinerMatchTableEmitter.cpp
@@ -1389,16 +1389,18 @@ void GICombinerEmitter::emitRunCustomAction(raw_ostream &OS) {
 
   OS << "void " << getClassName()
      << "::runCustomAction(unsigned ApplyID, const MatcherState &State) const "
-        "{\n"
-     << "  switch(ApplyID) {\n";
-  for (const auto &Apply : ApplyCode) {
-    OS << "  case " << Apply->getEnumNameWithPrefix(CXXApplyPrefix) << ":{\n"
-       << "    " << Apply->Code << "\n"
-       << "    return;\n";
-    OS << "  }\n";
+        "{\n";
+  if (!ApplyCode.empty()) {
+    OS << "  switch(ApplyID) {\n";
+    for (const auto &Apply : ApplyCode) {
+      OS << "  case " << Apply->getEnumNameWithPrefix(CXXApplyPrefix) << ":{\n"
+         << "    " << Apply->Code << "\n"
+         << "    return;\n";
+      OS << "  }\n";
+    }
+    OS << "}\n";
   }
-  OS << "}\n"
-     << "  llvm_unreachable(\"Unknown Apply Action\");\n"
+  OS << "  llvm_unreachable(\"Unknown Apply Action\");\n"
      << "}\n";
 }
 

diff  --git a/llvm/utils/TableGen/GlobalISelMatchTableExecutorEmitter.h b/llvm/utils/TableGen/GlobalISelMatchTableExecutorEmitter.h
index 0cb73898af370d..d526e08a96e310 100644
--- a/llvm/utils/TableGen/GlobalISelMatchTableExecutorEmitter.h
+++ b/llvm/utils/TableGen/GlobalISelMatchTableExecutorEmitter.h
@@ -102,21 +102,21 @@ class GlobalISelMatchTableExecutorEmitter {
        << AdditionalDeclarations;
     if (!AdditionalDeclarations.empty())
       OS << "\n";
-    if (!Predicates.empty())
+    if (!Predicates.empty()) {
       OS << "  switch (PredicateID) {\n";
-    for (const auto &Pred : Predicates) {
-      const auto Code = GetPredCode(Pred);
-      OS << "  case GICXXPred_" << TypeIdentifier << "_Predicate_"
-         << GetPredEnumName(Pred) << ": {\n"
-         << "    " << Code << "\n";
-      if (!StringRef(Code).ltrim().startswith("return")) {
-        OS << "    llvm_unreachable(\"" << GetPredEnumName(Pred)
-           << " should have returned\");\n";
+      for (const auto &Pred : Predicates) {
+        const auto Code = GetPredCode(Pred);
+        OS << "  case GICXXPred_" << TypeIdentifier << "_Predicate_"
+           << GetPredEnumName(Pred) << ": {\n"
+           << "    " << Code << "\n";
+        if (!StringRef(Code).ltrim().startswith("return")) {
+          OS << "    llvm_unreachable(\"" << GetPredEnumName(Pred)
+             << " should have returned\");\n";
+        }
+        OS << "  }\n";
       }
       OS << "  }\n";
     }
-    if (!Predicates.empty())
-      OS << "  }\n";
     OS << "  llvm_unreachable(\"Unknown predicate\");\n"
        << "  return false;\n"
        << "}\n";


        


More information about the llvm-commits mailing list