[llvm] r310008 - Revert "[TableGen] AsmMatcher: fix OpIdx computation when HasOptionalOperands is true"

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 3 17:25:25 PDT 2017


Author: vitalybuka
Date: Thu Aug  3 17:25:24 2017
New Revision: 310008

URL: http://llvm.org/viewvc/llvm-project?rev=310008&view=rev
Log:
Revert "[TableGen] AsmMatcher: fix OpIdx computation when HasOptionalOperands is true"

Breaks check-llvm under ubsan.

This reverts commit r309949.

Modified:
    llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp

Modified: llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp?rev=310008&r1=310007&r2=310008&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp Thu Aug  3 17:25:24 2017
@@ -1847,30 +1847,13 @@ static void emitConvertFuncs(CodeGenTarg
   CvtOS << "  assert(Kind < CVT_NUM_SIGNATURES && \"Invalid signature!\");\n";
   CvtOS << "  const uint8_t *Converter = ConversionTable[Kind];\n";
   if (HasOptionalOperands) {
-    size_t MaxNumOperands = 0;
-    for (const auto &MI : Infos) {
-      MaxNumOperands = std::max(MaxNumOperands, MI->AsmOperands.size());
-    }
-    CvtOS << "  unsigned DefaultsOffset[" << (MaxNumOperands) << "];\n";
-    CvtOS << "  assert(OptionalOperandsMask.size() == " << (MaxNumOperands)
-          << ");\n";
-    CvtOS << "  for (unsigned i = 0, NumDefaults = 0; i < " << (MaxNumOperands)
-          << "; ++i) {\n";
-    CvtOS << "    DefaultsOffset[i] = NumDefaults;\n";
-    CvtOS << "    NumDefaults += (OptionalOperandsMask[i] ? 1 : 0);\n";
-    CvtOS << "  }\n";
+    CvtOS << "  unsigned NumDefaults = 0;\n";
   }
   CvtOS << "  unsigned OpIdx;\n";
   CvtOS << "  Inst.setOpcode(Opcode);\n";
   CvtOS << "  for (const uint8_t *p = Converter; *p; p+= 2) {\n";
   if (HasOptionalOperands) {
-    // OpIdx has different semantics for Tied operands and the rest of the
-    // operands. For Tied it is the index in the Inst, therefore we use it
-    // directly. For the rest of the operands, we need to account for the
-    // offset.
-    CvtOS << "    OpIdx = *(p + 1);\n";
-    CvtOS << "    OpIdx -= (*p != CVT_Tied) ? DefaultsOffset[*(p + 1) - 1] : "
-             "0;\n";
+    CvtOS << "    OpIdx = *(p + 1) - NumDefaults;\n";
   } else {
     CvtOS << "    OpIdx = *(p + 1);\n";
   }
@@ -2005,6 +1988,7 @@ static void emitConvertFuncs(CodeGenTarg
                 << "        " << Op.Class->DefaultMethod << "()"
                 << "->" << Op.Class->RenderMethod << "(Inst, "
                 << OpInfo.MINumOperands << ");\n"
+                << "        ++NumDefaults;\n"
                 << "      } else {\n"
                 << "        static_cast<" << TargetOperandClass
                 << "&>(*Operands[OpIdx])." << Op.Class->RenderMethod




More information about the llvm-commits mailing list