<html><head></head><body bgcolor="#FFFFFF"><div><br><br><br></div><div><br>On Sep 4, 2012, at 3:57 PM, Jim Grosbach <<a href="mailto:grosbach@apple.com">grosbach@apple.com</a>> wrote:<br><br></div><div></div><blockquote type="cite"><div><span>Nomenclature: s/GetMCInstOperandNum/getMCInstOperandNum/.</span><br><span></span><br><span>Function names should be camel-case but start w/ a lower case letter.</span><br></div></blockquote><div><br></div><div>Done in r163187.  I'll cleanup others as I come across them.  Thanks, Jim<span class="Apple-style-span" style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.296875); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); ">.<b> </b></span></div><br><blockquote type="cite"><div><span>Other than that trivial note, this is awesome. Glad to see this moving forward.</span><br><span></span><br><span>-Jim</span><br><span>On Aug 30, 2012, at 10:59 AM, Chad Rosier <<a href="mailto:mcrosier@apple.com">mcrosier@apple.com</a>> wrote:</span><br><span></span><br><blockquote type="cite"><span>Author: mcrosier</span><br></blockquote><blockquote type="cite"><span>Date: Thu Aug 30 12:59:25 2012</span><br></blockquote><blockquote type="cite"><span>New Revision: 162920</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>URL: <a href="http://llvm.org/viewvc/llvm-project?rev=162920&view=rev">http://llvm.org/viewvc/llvm-project?rev=162920&view=rev</a></span><br></blockquote><blockquote type="cite"><span>Log:</span><br></blockquote><blockquote type="cite"><span>[ms-inline asm] Add a new function, GetMCInstOperandNum, to the</span><br></blockquote><blockquote type="cite"><span>AsmMatcherEmitter.  This function maps inline assembly operands to MCInst</span><br></blockquote><blockquote type="cite"><span>operands.</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>For example, '__asm mov j, eax' is represented by the follow MCInst:</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span><MCInst 1460 <MCOperand Reg:0> <MCOperand Imm:1> <MCOperand Reg:0> </span><br></blockquote><blockquote type="cite"><span>            <MCOperand Expr:(j)> <MCOperand Reg:0> <MCOperand Reg:43>></span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>The first 5 MCInst operands are a result of j matching as a memory operand</span><br></blockquote><blockquote type="cite"><span>consisting of a BaseReg (Reg:0), MemScale (Imm:1), MemIndexReg(Reg:0), </span><br></blockquote><blockquote type="cite"><span>Expr (Expr:(j), and a MemSegReg (Reg:0).  The 6th MCInst operand represents</span><br></blockquote><blockquote type="cite"><span>the eax register (Reg:43).</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>This translation is necessary to determine the Input and Output Exprs.  If a</span><br></blockquote><blockquote type="cite"><span>single asm operand maps to multiple MCInst operands, the index of the first</span><br></blockquote><blockquote type="cite"><span>MCInst operand is returned.  Ideally, it would return the operand we really</span><br></blockquote><blockquote type="cite"><span>care out (i.e., the Expr:(j) in this case), but I haven't found an easy way</span><br></blockquote><blockquote type="cite"><span>of doing this yet.</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>Modified:</span><br></blockquote><blockquote type="cite"><span>   llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>Modified: llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp</span><br></blockquote><blockquote type="cite"><span>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp?rev=162920&r1=162919&r2=162920&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp?rev=162920&r1=162919&r2=162920&view=diff</a></span><br></blockquote><blockquote type="cite"><span>==============================================================================</span><br></blockquote><blockquote type="cite"><span>--- llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp (original)</span><br></blockquote><blockquote type="cite"><span>+++ llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp Thu Aug 30 12:59:25 2012</span><br></blockquote><blockquote type="cite"><span>@@ -1697,6 +1697,26 @@</span><br></blockquote><blockquote type="cite"><span>        << "      Inst.addOperand(Inst.getOperand(*(p + 1)));\n"</span><br></blockquote><blockquote type="cite"><span>        << "      break;\n";</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>+  std::string OperandFnBody;</span><br></blockquote><blockquote type="cite"><span>+  raw_string_ostream OpOS(OperandFnBody);</span><br></blockquote><blockquote type="cite"><span>+  // Start the operand number lookup function.</span><br></blockquote><blockquote type="cite"><span>+  OpOS << "bool " << Target.getName() << ClassName << "::\n"</span><br></blockquote><blockquote type="cite"><span>+       << "GetMCInstOperandNum(unsigned Kind, MCInst &Inst,\n"</span><br></blockquote><blockquote type="cite"><span>+       << "                 const SmallVectorImpl<MCParsedAsmOperand*> &Operands,"</span><br></blockquote><blockquote type="cite"><span>+       << "\n                 unsigned OperandNum, unsigned &MCOperandNum) {\n"</span><br></blockquote><blockquote type="cite"><span>+       << "  if (Kind >= CVT_NUM_SIGNATURES) return false;\n"</span><br></blockquote><blockquote type="cite"><span>+       << "  MCOperandNum = 0;\n"</span><br></blockquote><blockquote type="cite"><span>+       << "  uint8_t *Converter = ConversionTable[Kind];\n"</span><br></blockquote><blockquote type="cite"><span>+       << "  for (uint8_t *p = Converter; *p; p+= 2) {\n"</span><br></blockquote><blockquote type="cite"><span>+       << "    if (*(p + 1) > OperandNum) continue;\n"</span><br></blockquote><blockquote type="cite"><span>+       << "    switch (*p) {\n"</span><br></blockquote><blockquote type="cite"><span>+       << "    default: llvm_unreachable(\"invalid conversion entry!\");\n"</span><br></blockquote><blockquote type="cite"><span>+       << "    case CVT_Reg:\n"</span><br></blockquote><blockquote type="cite"><span>+       << "      ++MCOperandNum;\n"</span><br></blockquote><blockquote type="cite"><span>+       << "      break;\n"</span><br></blockquote><blockquote type="cite"><span>+       << "    case CVT_Tied:\n"</span><br></blockquote><blockquote type="cite"><span>+       << "      //Inst.getOperand(*(p + 1)));\n"</span><br></blockquote><blockquote type="cite"><span>+       << "      break;\n";</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>  // Pre-populate the operand conversion kinds with the standard always</span><br></blockquote><blockquote type="cite"><span>  // available entries.</span><br></blockquote><blockquote type="cite"><span>@@ -1734,6 +1754,7 @@</span><br></blockquote><blockquote type="cite"><span>            << "      return " << AsmMatchConverter</span><br></blockquote><blockquote type="cite"><span>            << "(Inst, Opcode, Operands);\n";</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>+      // FIXME: Handle the operand number lookup for custom match functions.</span><br></blockquote><blockquote type="cite"><span>      continue;</span><br></blockquote><blockquote type="cite"><span>    }</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>@@ -1787,9 +1808,13 @@</span><br></blockquote><blockquote type="cite"><span>              << Op.Class->RenderMethod << "(Inst, " << OpInfo.MINumOperands</span><br></blockquote><blockquote type="cite"><span>              << ");\n"</span><br></blockquote><blockquote type="cite"><span>              << "      break;\n";</span><br></blockquote><blockquote type="cite"><span>+</span><br></blockquote><blockquote type="cite"><span>+        // Add a handler for the operand number lookup.</span><br></blockquote><blockquote type="cite"><span>+        OpOS << "    case " << Name << ":\n"</span><br></blockquote><blockquote type="cite"><span>+             << "      MCOperandNum += " << OpInfo.MINumOperands << ";\n"</span><br></blockquote><blockquote type="cite"><span>+             << "      break;\n";</span><br></blockquote><blockquote type="cite"><span>        break;</span><br></blockquote><blockquote type="cite"><span>      }</span><br></blockquote><blockquote type="cite"><span>-</span><br></blockquote><blockquote type="cite"><span>      case MatchableInfo::ResOperand::TiedOperand: {</span><br></blockquote><blockquote type="cite"><span>        // If this operand is tied to a previous one, just copy the MCInst</span><br></blockquote><blockquote type="cite"><span>        // operand from the earlier one.We can only tie single MCOperand values.</span><br></blockquote><blockquote type="cite"><span>@@ -1799,6 +1824,7 @@</span><br></blockquote><blockquote type="cite"><span>        Signature += "__Tie" + utostr(TiedOp);</span><br></blockquote><blockquote type="cite"><span>        ConversionRow.push_back(CVT_Tied);</span><br></blockquote><blockquote type="cite"><span>        ConversionRow.push_back(TiedOp);</span><br></blockquote><blockquote type="cite"><span>+        // FIXME: Handle the operand number lookup for tied operands.</span><br></blockquote><blockquote type="cite"><span>        break;</span><br></blockquote><blockquote type="cite"><span>      }</span><br></blockquote><blockquote type="cite"><span>      case MatchableInfo::ResOperand::ImmOperand: {</span><br></blockquote><blockquote type="cite"><span>@@ -1821,6 +1847,9 @@</span><br></blockquote><blockquote type="cite"><span>              << "      Inst.addOperand(MCOperand::CreateImm(" << Val << "));\n"</span><br></blockquote><blockquote type="cite"><span>              << "      break;\n";</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>+        OpOS << "    case " << Name << ":\n"</span><br></blockquote><blockquote type="cite"><span>+             << "      ++MCOperandNum;\n"</span><br></blockquote><blockquote type="cite"><span>+             << "      break;\n";</span><br></blockquote><blockquote type="cite"><span>        break;</span><br></blockquote><blockquote type="cite"><span>      }</span><br></blockquote><blockquote type="cite"><span>      case MatchableInfo::ResOperand::RegOperand: {</span><br></blockquote><blockquote type="cite"><span>@@ -1846,6 +1875,10 @@</span><br></blockquote><blockquote type="cite"><span>        CvtOS << "    case " << Name << ":\n"</span><br></blockquote><blockquote type="cite"><span>              << "      Inst.addOperand(MCOperand::CreateReg(" << Reg << "));\n"</span><br></blockquote><blockquote type="cite"><span>              << "      break;\n";</span><br></blockquote><blockquote type="cite"><span>+</span><br></blockquote><blockquote type="cite"><span>+        OpOS << "    case " << Name << ":\n"</span><br></blockquote><blockquote type="cite"><span>+             << "      ++MCOperandNum;\n"</span><br></blockquote><blockquote type="cite"><span>+             << "      break;\n";</span><br></blockquote><blockquote type="cite"><span>      }</span><br></blockquote><blockquote type="cite"><span>      }</span><br></blockquote><blockquote type="cite"><span>    }</span><br></blockquote><blockquote type="cite"><span>@@ -1868,6 +1901,9 @@</span><br></blockquote><blockquote type="cite"><span>  // Finish up the converter driver function.</span><br></blockquote><blockquote type="cite"><span>  CvtOS << "    }\n  }\n  return true;\n}\n\n";</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>+  // Finish up the operand number lookup function.</span><br></blockquote><blockquote type="cite"><span>+  OpOS << "    }\n  }\n  return true;\n}\n\n";</span><br></blockquote><blockquote type="cite"><span>+</span><br></blockquote><blockquote type="cite"><span>  OS << "namespace {\n";</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>  // Output the operand conversion kind enum.</span><br></blockquote><blockquote type="cite"><span>@@ -1908,6 +1944,8 @@</span><br></blockquote><blockquote type="cite"><span>  // Spit out the conversion driver function.</span><br></blockquote><blockquote type="cite"><span>  OS << CvtOS.str();</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>+  // Spit out the operand number lookup function.</span><br></blockquote><blockquote type="cite"><span>+  OS << OpOS.str();</span><br></blockquote><blockquote type="cite"><span>}</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>/// emitMatchClassEnumeration - Emit the enumeration for match class kinds.</span><br></blockquote><blockquote type="cite"><span>@@ -2542,6 +2580,10 @@</span><br></blockquote><blockquote type="cite"><span>     << "unsigned Opcode,\n"</span><br></blockquote><blockquote type="cite"><span>     << "                       const SmallVectorImpl<MCParsedAsmOperand*> "</span><br></blockquote><blockquote type="cite"><span>     << "&Operands);\n";</span><br></blockquote><blockquote type="cite"><span>+  OS << "  bool GetMCInstOperandNum(unsigned Kind, MCInst &Inst,\n"</span><br></blockquote><blockquote type="cite"><span>+     << "                           const SmallVectorImpl<MCParsedAsmOperand*> "</span><br></blockquote><blockquote type="cite"><span>+     << "&Operands,\n                           unsigned OperandNum, unsigned "</span><br></blockquote><blockquote type="cite"><span>+     << "&MCOperandNum);\n";</span><br></blockquote><blockquote type="cite"><span>  OS << "  bool MnemonicIsValid(StringRef Mnemonic);\n";</span><br></blockquote><blockquote type="cite"><span>  OS << "  unsigned MatchInstructionImpl(\n";</span><br></blockquote><blockquote type="cite"><span>  OS << "    const SmallVectorImpl<MCParsedAsmOperand*> &Operands,\n";</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>_______________________________________________</span><br></blockquote><blockquote type="cite"><span>llvm-commits mailing list</span><br></blockquote><blockquote type="cite"><span><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a></span><br></blockquote><blockquote type="cite"><span><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a></span><br></blockquote><span></span><br></div></blockquote></body></html>