implement the last known missing feature: updating uses of results 
of the matched pattern to use the newly created node results.  Onto
the "making it actually work" phase!



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96724 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/utils/TableGen/DAGISelEmitter.cpp b/utils/TableGen/DAGISelEmitter.cpp
index 55a9d36..d0da114 100644
--- a/utils/TableGen/DAGISelEmitter.cpp
+++ b/utils/TableGen/DAGISelEmitter.cpp
@@ -1917,7 +1917,7 @@
   // definitions.  Emit the resultant instruction selector.
   EmitInstructionSelector(OS);  
   
-#if 0
+#if 1
   MatcherNode *Matcher = 0;
   // Walk the patterns backwards, building a matcher for each and adding it to
   // the matcher for the whole target.
diff --git a/utils/TableGen/DAGISelMatcher.cpp b/utils/TableGen/DAGISelMatcher.cpp
index eaaaefb..b3c846c 100644
--- a/utils/TableGen/DAGISelMatcher.cpp
+++ b/utils/TableGen/DAGISelMatcher.cpp
@@ -180,7 +180,8 @@
   printNext(OS, indent);
 }
 
-void PatternMarkerMatcherNode::print(raw_ostream &OS, unsigned indent) const {
+void CompleteMatchMatcherNode::print(raw_ostream &OS, unsigned indent) const {
+  OS.indent(indent) << "CompleteMatch <todo args>\n";
   OS.indent(indent) << "Src = " << *Pattern.getSrcPattern() << "\n";
   OS.indent(indent) << "Dst = " << *Pattern.getDstPattern() << "\n";
   printNext(OS, indent);
diff --git a/utils/TableGen/DAGISelMatcher.h b/utils/TableGen/DAGISelMatcher.h
index 4dcb4d6..c162a0c 100644
--- a/utils/TableGen/DAGISelMatcher.h
+++ b/utils/TableGen/DAGISelMatcher.h
@@ -70,7 +70,7 @@
     EmitCopyToReg,        // Emit a copytoreg into a physreg.
     EmitNode,             // Create a DAG node
     EmitNodeXForm,        // Run a SDNodeXForm
-    PatternMarker         // Comment for printing.
+    CompleteMatch         // Finish a match and update the results.
   };
   const KindTy Kind;
 
@@ -601,19 +601,25 @@
   
   virtual void print(raw_ostream &OS, unsigned indent = 0) const;
 };
-
-/// PatternMarkerMatcherNode - This prints as a comment indicating the source
-/// and dest patterns.
-class PatternMarkerMatcherNode : public MatcherNode {
+  
+/// CompleteMatchMatcherNode - Complete a match by replacing the results of the
+/// pattern with the newly generated nodes.  This also prints a comment
+/// indicating the source and dest patterns.
+class CompleteMatchMatcherNode : public MatcherNode {
+  SmallVector<unsigned, 2> Results;
   const PatternToMatch &Pattern;
 public:
-  PatternMarkerMatcherNode(const PatternToMatch &pattern)
-  : MatcherNode(PatternMarker), Pattern(pattern) {}
-  
+  CompleteMatchMatcherNode(const unsigned *results, unsigned numresults,
+                           const PatternToMatch &pattern)
+  : MatcherNode(CompleteMatch), Results(results, results+numresults),
+    Pattern(pattern) {}
+
+  unsigned getNumResults() const { return Results.size(); }
+  unsigned getResult(unsigned R) const { return Results[R]; }
   const PatternToMatch &getPattern() const { return Pattern; }
   
   static inline bool classof(const MatcherNode *N) {
-    return N->getKind() == PatternMarker;
+    return N->getKind() == CompleteMatch;
   }
   
   virtual void print(raw_ostream &OS, unsigned indent = 0) const;
diff --git a/utils/TableGen/DAGISelMatcherEmitter.cpp b/utils/TableGen/DAGISelMatcherEmitter.cpp
index 077dd5d..de17005 100644
--- a/utils/TableGen/DAGISelMatcherEmitter.cpp
+++ b/utils/TableGen/DAGISelMatcherEmitter.cpp
@@ -305,13 +305,19 @@
     OS << '\n';
     return 5+EN->getNumVTs()+EN->getNumOperands();
   }
-  case MatcherNode::PatternMarker:
-    OS << "// Src: "
-    << *cast<PatternMarkerMatcherNode>(N)->getPattern().getSrcPattern() << '\n';
-    OS.PadToColumn(Indent*2) << "// Dst: "
-    << *cast<PatternMarkerMatcherNode>(N)->getPattern().getDstPattern() << '\n';
+  case MatcherNode::CompleteMatch: {
+    const CompleteMatchMatcherNode *CM = cast<CompleteMatchMatcherNode>(N);
+    OS << "OPC_CompleteMatch, " << CM->getNumResults() << ", ";
+    for (unsigned i = 0, e = CM->getNumResults(); i != e; ++i)
+      OS << CM->getResult(i) << ", ";
+    OS << '\n';
+    OS.PadToColumn(Indent*2) << "// Src: "
+      << *CM->getPattern().getSrcPattern() << '\n';
+    OS.PadToColumn(Indent*2) << "// Dst: " 
+      << *CM->getPattern().getDstPattern() << '\n';
     return 0;
   }
+  }
   assert(0 && "Unreachable");
   return 0;
 }
diff --git a/utils/TableGen/DAGISelMatcherGen.cpp b/utils/TableGen/DAGISelMatcherGen.cpp
index 693c4cc..b22fa87 100644
--- a/utils/TableGen/DAGISelMatcherGen.cpp
+++ b/utils/TableGen/DAGISelMatcherGen.cpp
@@ -723,8 +723,8 @@
   
   // The newly emitted node gets recorded.
   // FIXME2: This should record all of the results except the (implicit) one.
-  OutputOps.push_back(NextRecordedOperandNo++);
-  
+  if (ResultVTs[0] != MVT::Other)
+    OutputOps.push_back(NextRecordedOperandNo++);
   
   // FIXME2: Kill off all the SelectionDAG::SelectNodeTo and getMachineNode
   // variants.  Call MorphNodeTo instead of SelectNodeTo.
@@ -776,11 +776,11 @@
   // We know that the resulting pattern has exactly one result/
   // FIXME2: why?  what about something like (set a,b,c, (complexpat))
   // FIXME2: Implicit results should be pushed here I guess?
-  assert(Ops.size() == 1);
+  assert(Ops.size() <= 1);
   // FIXME: Handle Ops.
   // FIXME: Handle (set EAX, (foo)) but not (implicit EFLAGS)
   
-  AddMatcherNode(new PatternMarkerMatcherNode(Pattern));
+  AddMatcherNode(new CompleteMatchMatcherNode(Ops.data(), Ops.size(), Pattern));
 }