[PATCH] D155805: [TableGen][CodeEmitterGen] Emit a default label for getOperandBitOffset()'s OpNum switch

Ilya Leoshkevich via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 20 03:42:44 PDT 2023


iii updated this revision to Diff 542414.
iii added a comment.

- Avoid emitting empty cases entirely.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155805

Files:
  llvm/utils/TableGen/CodeEmitterGen.cpp


Index: llvm/utils/TableGen/CodeEmitterGen.cpp
===================================================================
--- llvm/utils/TableGen/CodeEmitterGen.cpp
+++ llvm/utils/TableGen/CodeEmitterGen.cpp
@@ -310,7 +310,9 @@
   // 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 @@
     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...


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155805.542414.patch
Type: text/x-patch
Size: 1164 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230720/e578b71f/attachment.bin>


More information about the llvm-commits mailing list