Add support for naming the destination of a "set" in a pattern


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7748 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/support/tools/TableGen/InstrSelectorEmitter.cpp b/support/tools/TableGen/InstrSelectorEmitter.cpp
index 153f27e..d9f333b 100644
--- a/support/tools/TableGen/InstrSelectorEmitter.cpp
+++ b/support/tools/TableGen/InstrSelectorEmitter.cpp
@@ -138,6 +138,7 @@
       if (!Tree->getChild(0)->isLeaf())
         error("Arg #0 of set should be a register or register class!");
       Result = Tree->getChild(0)->getValueRecord();
+      ResultName = Tree->getChildName(0);
       Tree = Tree->getChild(1);
     }
   }
@@ -895,6 +896,9 @@
   for (unsigned i = 0, e = P->getNumArgs(); i != e; ++i)
     if (P->getArgName(i) == ArgName)
       return Operands[i].second + "->Val";
+
+  if (ArgName == P->getResultName())
+    return "NewReg";
   P->error("Pattern does not define a value named $" + ArgName + "!");
   return "";
 }
diff --git a/support/tools/TableGen/InstrSelectorEmitter.h b/support/tools/TableGen/InstrSelectorEmitter.h
index a1b1b6e..9588130 100644
--- a/support/tools/TableGen/InstrSelectorEmitter.h
+++ b/support/tools/TableGen/InstrSelectorEmitter.h
@@ -142,6 +142,7 @@
   /// register result, specified with a (set) in the pattern.
   ///
   Record *Result;
+  std::string ResultName;     // The name of the result value...
 
   /// TheRecord - The actual TableGen record corresponding to this pattern.
   ///
@@ -185,6 +186,7 @@
   TreePatternNode *getTree() const { return Tree; }
   
   Record *getResult() const { return Result; }
+  const std::string &getResultName() const { return ResultName; }
 
   /// getRecord - Return the actual TableGen record corresponding to this
   /// pattern.
diff --git a/utils/TableGen/InstrSelectorEmitter.cpp b/utils/TableGen/InstrSelectorEmitter.cpp
index 153f27e..d9f333b 100644
--- a/utils/TableGen/InstrSelectorEmitter.cpp
+++ b/utils/TableGen/InstrSelectorEmitter.cpp
@@ -138,6 +138,7 @@
       if (!Tree->getChild(0)->isLeaf())
         error("Arg #0 of set should be a register or register class!");
       Result = Tree->getChild(0)->getValueRecord();
+      ResultName = Tree->getChildName(0);
       Tree = Tree->getChild(1);
     }
   }
@@ -895,6 +896,9 @@
   for (unsigned i = 0, e = P->getNumArgs(); i != e; ++i)
     if (P->getArgName(i) == ArgName)
       return Operands[i].second + "->Val";
+
+  if (ArgName == P->getResultName())
+    return "NewReg";
   P->error("Pattern does not define a value named $" + ArgName + "!");
   return "";
 }
diff --git a/utils/TableGen/InstrSelectorEmitter.h b/utils/TableGen/InstrSelectorEmitter.h
index a1b1b6e..9588130 100644
--- a/utils/TableGen/InstrSelectorEmitter.h
+++ b/utils/TableGen/InstrSelectorEmitter.h
@@ -142,6 +142,7 @@
   /// register result, specified with a (set) in the pattern.
   ///
   Record *Result;
+  std::string ResultName;     // The name of the result value...
 
   /// TheRecord - The actual TableGen record corresponding to this pattern.
   ///
@@ -185,6 +186,7 @@
   TreePatternNode *getTree() const { return Tree; }
   
   Record *getResult() const { return Result; }
+  const std::string &getResultName() const { return ResultName; }
 
   /// getRecord - Return the actual TableGen record corresponding to this
   /// pattern.