[llvm] c05eff2 - [TableGen][CodeEmitterGen] Avoid empty OpNum switches in getOperandBitOffset()
Ilya Leoshkevich via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 20 04:28:53 PDT 2023
Author: Ilya Leoshkevich
Date: 2023-07-20T13:28:35+02:00
New Revision: c05eff2f92425af8b8a9f279eb73d867d62e0d08
URL: https://github.com/llvm/llvm-project/commit/c05eff2f92425af8b8a9f279eb73d867d62e0d08
DIFF: https://github.com/llvm/llvm-project/commit/c05eff2f92425af8b8a9f279eb73d867d62e0d08.diff
LOG: [TableGen][CodeEmitterGen] Avoid empty OpNum switches in getOperandBitOffset()
getOperandBitOffset() causes the following warning on MSVC:
E:\llvm\ninja\lib\Target\SystemZ\SystemZGenMCCodeEmitter.inc(15414): warning C4060: switch statement contains no 'case' or 'default' labels
Do not emit empty OpNum switches.
Reviewed By: RKSimon, uweigand
Differential Revision: https://reviews.llvm.org/D155805
Added:
Modified:
llvm/utils/TableGen/CodeEmitterGen.cpp
Removed:
################################################################################
diff --git a/llvm/utils/TableGen/CodeEmitterGen.cpp b/llvm/utils/TableGen/CodeEmitterGen.cpp
index ba077c3c616065..48ed319bf06f47 100644
--- a/llvm/utils/TableGen/CodeEmitterGen.cpp
+++ b/llvm/utils/TableGen/CodeEmitterGen.cpp
@@ -310,7 +310,9 @@ void CodeEmitterGen::addInstructionCasesForEncoding(
// Loop over all of the fields in the instruction, determining which are the
// operands to the instruction.
bool Success = true;
+ size_t OrigBitOffsetCaseSize = BitOffsetCase.size();
BitOffsetCase += " switch (OpNum) {\n";
+ size_t BitOffsetCaseSizeBeforeLoop = BitOffsetCase.size();
for (const RecordVal &RV : EncodingDef->getValues()) {
// Ignore fixed fields in the record, we're looking for values like:
// bits<5> RST = { ?, ?, ?, ?, ? };
@@ -320,7 +322,11 @@ void CodeEmitterGen::addInstructionCasesForEncoding(
Success &= addCodeToMergeInOperand(R, BI, std::string(RV.getName()), Case,
BitOffsetCase, Target);
}
- BitOffsetCase += " }\n";
+ // Avoid empty switches.
+ if (BitOffsetCase.size() == BitOffsetCaseSizeBeforeLoop)
+ BitOffsetCase.resize(OrigBitOffsetCaseSize);
+ else
+ BitOffsetCase += " }\n";
if (!Success) {
// Dump the record, so we can see what's going on...
More information about the llvm-commits
mailing list