Skip to content

Commit 9244be7

Browse files
committed
[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
1 parent 2f7269b commit 9244be7

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -612,18 +612,23 @@ void GIMatchTreeOpcodePartitioner::emitPartitionResults(
612612

613613
void GIMatchTreeOpcodePartitioner::generatePartitionSelectorCode(
614614
raw_ostream &OS, StringRef Indent) const {
615-
OS << Indent << "Partition = -1;\n"
616-
<< Indent << "switch (MIs[" << InstrID << "]->getOpcode()) {\n";
617-
for (const auto &EnumInstr : enumerate(PartitionToInstr)) {
618-
if (EnumInstr.value() == nullptr)
619-
OS << Indent << "default:";
620-
else
621-
OS << Indent << "case " << EnumInstr.value()->Namespace
622-
<< "::" << EnumInstr.value()->TheDef->getName() << ":";
623-
OS << " Partition = " << EnumInstr.index() << "; break;\n";
615+
// Make sure not to emit empty switch or switch with just default
616+
if (PartitionToInstr.size() == 1 && PartitionToInstr[0] == nullptr) {
617+
OS << Indent << "Partition = 0;\n";
618+
} else if (PartitionToInstr.size()) {
619+
OS << Indent << "Partition = -1;\n"
620+
<< Indent << "switch (MIs[" << InstrID << "]->getOpcode()) {\n";
621+
for (const auto &EnumInstr : enumerate(PartitionToInstr)) {
622+
if (EnumInstr.value() == nullptr)
623+
OS << Indent << "default:";
624+
else
625+
OS << Indent << "case " << EnumInstr.value()->Namespace
626+
<< "::" << EnumInstr.value()->TheDef->getName() << ":";
627+
OS << " Partition = " << EnumInstr.index() << "; break;\n";
628+
}
629+
OS << Indent << "}\n";
624630
}
625-
OS << Indent << "}\n"
626-
<< Indent
631+
OS << Indent
627632
<< "// Default case but without conflicting with potential default case "
628633
"in selection.\n"
629634
<< Indent << "if (Partition == -1) return false;\n";
@@ -775,4 +780,3 @@ void GIMatchTreeVRegDefPartitioner::generatePartitionSelectorCode(
775780

776781
OS << Indent << "if (Partition == -1) return false;\n";
777782
}
778-

0 commit comments

Comments
 (0)