[PATCH] D117448: [NFC][SDNode] Use `StringSwitch` instead of `if`

Shao-Ce SUN via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 17 16:12:40 PST 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGefd72ee23b99: [NFC][SDNode] Use `StringSwitch` instead of `if` (authored by achieveartificialintelligence).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117448

Files:
  llvm/utils/TableGen/SDNodeProperties.cpp


Index: llvm/utils/TableGen/SDNodeProperties.cpp
===================================================================
--- llvm/utils/TableGen/SDNodeProperties.cpp
+++ llvm/utils/TableGen/SDNodeProperties.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "SDNodeProperties.h"
+#include "llvm/ADT/StringSwitch.h"
 #include "llvm/TableGen/Error.h"
 #include "llvm/TableGen/Record.h"
 
@@ -15,34 +16,25 @@
 unsigned llvm::parseSDPatternOperatorProperties(Record *R) {
   unsigned Properties = 0;
   for (Record *Property : R->getValueAsListOfDefs("Properties")) {
-    if (Property->getName() == "SDNPCommutative") {
-      Properties |= 1 << SDNPCommutative;
-    } else if (Property->getName() == "SDNPAssociative") {
-      Properties |= 1 << SDNPAssociative;
-    } else if (Property->getName() == "SDNPHasChain") {
-      Properties |= 1 << SDNPHasChain;
-    } else if (Property->getName() == "SDNPOutGlue") {
-      Properties |= 1 << SDNPOutGlue;
-    } else if (Property->getName() == "SDNPInGlue") {
-      Properties |= 1 << SDNPInGlue;
-    } else if (Property->getName() == "SDNPOptInGlue") {
-      Properties |= 1 << SDNPOptInGlue;
-    } else if (Property->getName() == "SDNPMayStore") {
-      Properties |= 1 << SDNPMayStore;
-    } else if (Property->getName() == "SDNPMayLoad") {
-      Properties |= 1 << SDNPMayLoad;
-    } else if (Property->getName() == "SDNPSideEffect") {
-      Properties |= 1 << SDNPSideEffect;
-    } else if (Property->getName() == "SDNPMemOperand") {
-      Properties |= 1 << SDNPMemOperand;
-    } else if (Property->getName() == "SDNPVariadic") {
-      Properties |= 1 << SDNPVariadic;
-    } else {
+    auto Offset = StringSwitch<unsigned>(Property->getName())
+                      .Case("SDNPCommutative", SDNPCommutative)
+                      .Case("SDNPAssociative", SDNPAssociative)
+                      .Case("SDNPHasChain", SDNPHasChain)
+                      .Case("SDNPOutGlue", SDNPOutGlue)
+                      .Case("SDNPInGlue", SDNPInGlue)
+                      .Case("SDNPOptInGlue", SDNPOptInGlue)
+                      .Case("SDNPMayStore", SDNPMayStore)
+                      .Case("SDNPMayLoad", SDNPMayLoad)
+                      .Case("SDNPSideEffect", SDNPSideEffect)
+                      .Case("SDNPMemOperand", SDNPMemOperand)
+                      .Case("SDNPVariadic", SDNPVariadic)
+                      .Default(-1u);
+    if (Offset != -1u)
+      Properties |= 1 << Offset;
+    else
       PrintFatalError(R->getLoc(), "Unknown SD Node property '" +
                                        Property->getName() + "' on node '" +
                                        R->getName() + "'!");
-    }
   }
-
   return Properties;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117448.400665.patch
Type: text/x-patch
Size: 2788 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220118/ce1a9ff6/attachment.bin>


More information about the llvm-commits mailing list