[PATCH] D117448: [NFC][SDNode] Use `StringSwitch` instead of `if`
Shao-Ce SUN via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 16 20:21:53 PST 2022
achieveartificialintelligence updated this revision to Diff 400426.
achieveartificialintelligence added a comment.
Address @craig.topper's comments. Thanks!
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.400426.patch
Type: text/x-patch
Size: 2788 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220117/2ef67a2e/attachment.bin>
More information about the llvm-commits
mailing list