[llvm-commits] [llvm] r116211 - in /llvm/trunk/utils/TableGen: CodeEmitterGen.cpp CodeGenInstruction.cpp CodeGenInstruction.h

Jim Grosbach grosbach at apple.com
Mon Oct 11 11:25:51 PDT 2010


Author: grosbach
Date: Mon Oct 11 13:25:51 2010
New Revision: 116211

URL: http://llvm.org/viewvc/llvm-project?rev=116211&view=rev
Log:
When figuring out which operands match which encoding fields in an instruction,
try to match them by name first. If there is no by-name match, fall back to
assuming they are in order (this was the previous behavior).


Modified:
    llvm/trunk/utils/TableGen/CodeEmitterGen.cpp
    llvm/trunk/utils/TableGen/CodeGenInstruction.cpp
    llvm/trunk/utils/TableGen/CodeGenInstruction.h

Modified: llvm/trunk/utils/TableGen/CodeEmitterGen.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeEmitterGen.cpp?rev=116211&r1=116210&r2=116211&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeEmitterGen.cpp (original)
+++ llvm/trunk/utils/TableGen/CodeEmitterGen.cpp Mon Oct 11 13:25:51 2010
@@ -128,7 +128,7 @@
 
     // Loop over all of the fields in the instruction, determining which are the
     // operands to the instruction.
-    unsigned op = 0;
+    unsigned NumberedOp = 0;
     for (unsigned i = 0, e = Vals.size(); i != e; ++i) {
       if (!Vals[i].getPrefix() && !Vals[i].getValue()->isComplete()) {
         // Is the operand continuous? If so, we can just mask and OR it in
@@ -154,14 +154,25 @@
             }
 
             if (!gotOp) {
-              /// If this operand is not supposed to be emitted by the generated
-              /// emitter, skip it.
-              while (CGI.isFlatOperandNotEmitted(op))
-                ++op;
+
+              // If the operand matches by name, reference according to that
+              // operand number. Non-matching operands are assumed to be in
+              // order.
+              unsigned OpIdx;
+              if (CGI.hasOperandNamed(VarName, OpIdx)) {
+                assert (!CGI.isFlatOperandNotEmitted(OpIdx) &&
+                        "Explicitly used operand also marked as not emitted!");
+              } else {
+                /// If this operand is not supposed to be emitted by the
+                /// generated emitter, skip it.
+                while (CGI.isFlatOperandNotEmitted(NumberedOp))
+                  ++NumberedOp;
+                OpIdx = NumberedOp++;
+              }
 
               Case += "      // op: " + VarName + "\n"
                    +  "      op = getMachineOpValue(MI, MI.getOperand("
-                   +  utostr(op++) + "));\n";
+                   +  utostr(OpIdx) + "));\n";
               gotOp = true;
             }
 

Modified: llvm/trunk/utils/TableGen/CodeGenInstruction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenInstruction.cpp?rev=116211&r1=116210&r2=116211&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenInstruction.cpp (original)
+++ llvm/trunk/utils/TableGen/CodeGenInstruction.cpp Mon Oct 11 13:25:51 2010
@@ -234,13 +234,26 @@
 /// specified name, throw an exception.
 ///
 unsigned CodeGenInstruction::getOperandNamed(const std::string &Name) const {
-  assert(!Name.empty() && "Cannot search for operand with no name!");
-  for (unsigned i = 0, e = OperandList.size(); i != e; ++i)
-    if (OperandList[i].Name == Name) return i;
+  unsigned OpIdx;
+  if (hasOperandNamed(Name, OpIdx)) return OpIdx;
   throw "Instruction '" + TheDef->getName() +
         "' does not have an operand named '$" + Name + "'!";
 }
 
+/// hasOperandNamed - Query whether the instruction has an operand of the
+/// given name. If so, return true and set OpIdx to the index of the
+/// operand. Otherwise, return false.
+bool CodeGenInstruction::hasOperandNamed(const std::string &Name,
+                                         unsigned &OpIdx) const {
+  assert(!Name.empty() && "Cannot search for operand with no name!");
+  for (unsigned i = 0, e = OperandList.size(); i != e; ++i)
+    if (OperandList[i].Name == Name) {
+      OpIdx = i;
+      return true;
+    }
+  return false;
+}
+
 std::pair<unsigned,unsigned>
 CodeGenInstruction::ParseOperandName(const std::string &Op,
                                      bool AllowWholeOp) {

Modified: llvm/trunk/utils/TableGen/CodeGenInstruction.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenInstruction.h?rev=116211&r1=116210&r2=116211&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenInstruction.h (original)
+++ llvm/trunk/utils/TableGen/CodeGenInstruction.h Mon Oct 11 13:25:51 2010
@@ -186,6 +186,11 @@
     /// specified name, throw an exception.
     unsigned getOperandNamed(const std::string &Name) const;
 
+    /// hasOperandNamed - Query whether the instruction has an operand of the
+    /// given name. If so, return true and set OpIdx to the index of the
+    /// operand. Otherwise, return false.
+    bool hasOperandNamed(const std::string &Name, unsigned &OpIdx) const;
+
     /// HasOneImplicitDefWithKnownVT - If the instruction has at least one
     /// implicit def and it has a known VT, return the VT, otherwise return
     /// MVT::Other.





More information about the llvm-commits mailing list