[llvm-commits] [llvm] r97525 - /llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Chris Lattner sabre at nondot.org
Mon Mar 1 16:00:04 PST 2010


Author: lattner
Date: Mon Mar  1 18:00:03 2010
New Revision: 97525

URL: http://llvm.org/viewvc/llvm-project?rev=97525&view=rev
Log:
refactor some code out of OPC_EmitMergeInputChains into a
new helper function.

Modified:
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp?rev=97525&r1=97524&r2=97525&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp Mon Mar  1 18:00:03 2010
@@ -1574,7 +1574,34 @@
   DEBUG(errs() << "ISEL: Match complete!\n");
 }
 
-
+/// HandleMergeInputChains - This implements the OPC_EmitMergeInputChains
+/// operation for when the pattern matched multiple nodes with chains.
+static SDValue
+HandleMergeInputChains(const SmallVectorImpl<SDNode*> &ChainNodesMatched,
+                       SelectionDAG *CurDAG) {
+  assert(ChainNodesMatched.size() > 1 && 
+         "Should only happen for multi chain node case");
+  
+  // Walk all the chained nodes, adding the input chains if they are not in
+  // ChainedNodes (and this, not in the matched pattern).  This is an N^2
+  // algorithm, but # chains is usually 2 here, at most 3 for MSP430.
+  SmallVector<SDValue, 3> InputChains;
+  for (unsigned i = 0, e = ChainNodesMatched.size(); i != e; ++i) {
+    SDValue InChain = ChainNodesMatched[i]->getOperand(0);
+    assert(InChain.getValueType() == MVT::Other && "Not a chain");
+    bool Invalid = false;
+    for (unsigned j = 0; j != e; ++j)
+      Invalid |= ChainNodesMatched[j] == InChain.getNode();
+    if (!Invalid)
+      InputChains.push_back(InChain);
+  }
+  
+  SDValue Res;
+  if (InputChains.size() == 1)
+    return InputChains[0];
+  return CurDAG->getNode(ISD::TokenFactor, ChainNodesMatched[0]->getDebugLoc(),
+                         MVT::Other, &InputChains[0], InputChains.size());
+}  
 
 struct MatchScope {
   /// FailIndex - If this match fails, this is the index to continue with.
@@ -2026,28 +2053,17 @@
           break;
         }
       }
+      
+      // If the inner loop broke out, the match fails.
+      if (ChainNodesMatched.empty())
+        break;
+
+      // Merge the input chains if they are not intra-pattern references.
+      InputChain = HandleMergeInputChains(ChainNodesMatched, CurDAG);
+      
+      if (InputChain.getNode() == 0)
+        break;  // Failed to merge.
 
-      // Walk all the chained nodes, adding the input chains if they are not in
-      // ChainedNodes (and this, not in the matched pattern).  This is an N^2
-      // algorithm, but # chains is usually 2 here, at most 3 for MSP430.
-      SmallVector<SDValue, 3> InputChains;
-      for (unsigned i = 0, e = ChainNodesMatched.size(); i != e; ++i) {
-        SDValue InChain = ChainNodesMatched[i]->getOperand(0);
-        assert(InChain.getValueType() == MVT::Other && "Not a chain");
-        bool Invalid = false;
-        for (unsigned j = 0; j != e; ++j)
-          Invalid |= ChainNodesMatched[j] == InChain.getNode();
-        if (!Invalid)
-          InputChains.push_back(InChain);
-      }
-
-      SDValue Res;
-      if (InputChains.size() == 1)
-        InputChain = InputChains[0];
-      else
-        InputChain = CurDAG->getNode(ISD::TokenFactor,
-                                     NodeToMatch->getDebugLoc(), MVT::Other,
-                                     &InputChains[0], InputChains.size());
       continue;
     }
         





More information about the llvm-commits mailing list