[llvm] 9244be7 - [TableGen] Avoid generating switch with just default
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 2 11:51:37 PDT 2020
Author: dstuttar
Date: 2020-06-02T19:48:07+01:00
New Revision: 9244be7b0514c41e0fa8a2880595fa663cc2f85f
URL: https://github.com/llvm/llvm-project/commit/9244be7b0514c41e0fa8a2880595fa663cc2f85f
DIFF: https://github.com/llvm/llvm-project/commit/9244be7b0514c41e0fa8a2880595fa663cc2f85f.diff
LOG: [TableGen] Avoid generating switch with just default
Summary:
Switch with just default causes an MSVC warning (warning C4065: switch statement
contains 'default' but no 'case' labels).
Change-Id: I9ddeccdef93666256b5454b164b567b73b488461
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D81021
Added:
Modified:
llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp
Removed:
################################################################################
diff --git a/llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp b/llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp
index 8eef93393a1e..96dc4fc94893 100644
--- a/llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp
+++ b/llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp
@@ -612,18 +612,23 @@ void GIMatchTreeOpcodePartitioner::emitPartitionResults(
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 @@ void GIMatchTreeVRegDefPartitioner::generatePartitionSelectorCode(
OS << Indent << "if (Partition == -1) return false;\n";
}
-
More information about the llvm-commits
mailing list