[llvm-commits] [llvm] r46050 - in /llvm/trunk: include/llvm/CodeGen/SelectionDAGNodes.h lib/CodeGen/SelectionDAG/DAGCombiner.cpp lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Chris Lattner sabre at nondot.org
Tue Jan 15 21:49:24 PST 2008


Author: lattner
Date: Tue Jan 15 23:49:24 2008
New Revision: 46050

URL: http://llvm.org/viewvc/llvm-project?rev=46050&view=rev
Log:
Factor the ReachesChainWithoutSideEffects out of dag combiner into 
a public SDOperand::reachesChainWithoutSideEffects method.  No 
functionality change.

Modified:
    llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h
    llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Modified: llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h?rev=46050&r1=46049&r2=46050&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h (original)
+++ llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h Tue Jan 15 23:49:24 2008
@@ -780,6 +780,14 @@
   inline bool isTargetOpcode() const;
   inline unsigned getTargetOpcode() const;
 
+  
+  /// reachesChainWithoutSideEffects - Return true if this operand (which must
+  /// be a chain) reaches the specified operand without crossing any 
+  /// side-effecting instructions.  In practice, this looks through token
+  /// factors and non-volatile loads.  In order to remain efficient, this only
+  /// looks a couple of nodes in, it does not do an exhaustive search.
+  bool reachesChainWithoutSideEffects(SDOperand Dest, unsigned Depth = 2) const;
+  
   /// hasOneUse - Return true if there is exactly one operation using this
   /// result value of the defining operator.
   inline bool hasOneUse() const;

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=46050&r1=46049&r2=46050&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Tue Jan 15 23:49:24 2008
@@ -4122,33 +4122,6 @@
   return SDOperand();
 }
 
-/// ReachesChainWithoutSideEffects - Do a little local search to see if Src can
-/// reach Dest without any side effects like a store, or call.  Non-volatile
-/// loads are ok though.
-static bool ReachesChainWithoutSideEffects(SDOperand Src, SDOperand Dest,
-                                           unsigned Depth = 0) {
-  if (Src == Dest) return true;
-  
-  // Don't search too deeply, we just want to be able to see through
-  // TokenFactor's etc.
-  if (Depth == 2) return false;
-  
-  // If this is a token factor, all inputs to the TF happen in parallel.  If any
-  // of the operands of the TF reach dest, then we can do the xform.
-  if (Src.getOpcode() == ISD::TokenFactor) {
-    for (unsigned i = 0, e = Src.getNumOperands(); i != e; ++i)
-      if (ReachesChainWithoutSideEffects(Src.getOperand(i), Dest, Depth+1))
-        return true;
-    return false;
-  }
-  
-  // Loads don't have side effects, look through them.
-  if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Src)) {
-    if (!Ld->isVolatile())
-      return ReachesChainWithoutSideEffects(Ld->getChain(), Dest, Depth+1);
-  }
-  return false;
-}
 
 SDOperand DAGCombiner::visitSTORE(SDNode *N) {
   StoreSDNode *ST  = cast<StoreSDNode>(N);
@@ -4283,7 +4256,7 @@
         !ST->isVolatile() &&
         // There can't be any side effects between the load and store, such as
         // a call or store.
-        ReachesChainWithoutSideEffects(Chain, SDOperand(Ld, 1))) {
+        Chain.reachesChainWithoutSideEffects(SDOperand(Ld, 1))) {
       // The store is dead, remove it.
       return Chain;
     }

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=46050&r1=46049&r2=46050&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Tue Jan 15 23:49:24 2008
@@ -3562,6 +3562,37 @@
   return false;
 }
 
+/// reachesChainWithoutSideEffects - Return true if this operand (which must
+/// be a chain) reaches the specified operand without crossing any 
+/// side-effecting instructions.  In practice, this looks through token
+/// factors and non-volatile loads.  In order to remain efficient, this only
+/// looks a couple of nodes in, it does not do an exhaustive search.
+bool SDOperand::reachesChainWithoutSideEffects(SDOperand Dest, 
+                                               unsigned Depth) const {
+  if (*this == Dest) return true;
+  
+  // Don't search too deeply, we just want to be able to see through
+  // TokenFactor's etc.
+  if (Depth == 0) return false;
+  
+  // If this is a token factor, all inputs to the TF happen in parallel.  If any
+  // of the operands of the TF reach dest, then we can do the xform.
+  if (getOpcode() == ISD::TokenFactor) {
+    for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
+      if (getOperand(i).reachesChainWithoutSideEffects(Dest, Depth-1))
+        return true;
+    return false;
+  }
+  
+  // Loads don't have side effects, look through them.
+  if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(*this)) {
+    if (!Ld->isVolatile())
+      return Ld->getChain().reachesChainWithoutSideEffects(Dest, Depth-1);
+  }
+  return false;
+}
+
+
 static void findPredecessor(SDNode *N, const SDNode *P, bool &found,
                             SmallPtrSet<SDNode *, 32> &Visited) {
   if (found || !Visited.insert(N))





More information about the llvm-commits mailing list