[llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Chris Lattner lattner at cs.uiuc.edu
Tue Feb 28 20:53:50 PST 2006



Changes in directory llvm/lib/CodeGen/SelectionDAG:

DAGCombiner.cpp updated: 1.116 -> 1.117
---
Log message:

Add support for target-specific dag combines


---
Diffs of the changes:  (+58 -13)

 DAGCombiner.cpp |   71 +++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 58 insertions(+), 13 deletions(-)


Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1.116 llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1.117
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1.116	Tue Feb 28 22:03:14 2006
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp	Tue Feb 28 22:53:38 2006
@@ -68,6 +68,7 @@
                      WorkList.end());
     }
     
+  public:
     void AddToWorkList(SDNode *N) {
       WorkList.push_back(N);
     }
@@ -97,6 +98,20 @@
       return SDOperand(N, 0);
     }
     
+    SDOperand CombineTo(SDNode *N, SDOperand Res) {
+      std::vector<SDOperand> To;
+      To.push_back(Res);
+      return CombineTo(N, To);
+    }
+    
+    SDOperand CombineTo(SDNode *N, SDOperand Res0, SDOperand Res1) {
+      std::vector<SDOperand> To;
+      To.push_back(Res0);
+      To.push_back(Res1);
+      return CombineTo(N, To);
+    }
+  private:    
+    
     /// SimplifyDemandedBits - Check the specified integer node value to see if
     /// it can be simplified or if things is uses can be simplified by bit
     /// propagation.  If so, return true.
@@ -137,19 +152,6 @@
       return true;
     }
 
-    SDOperand CombineTo(SDNode *N, SDOperand Res) {
-      std::vector<SDOperand> To;
-      To.push_back(Res);
-      return CombineTo(N, To);
-    }
-    
-    SDOperand CombineTo(SDNode *N, SDOperand Res0, SDOperand Res1) {
-      std::vector<SDOperand> To;
-      To.push_back(Res0);
-      To.push_back(Res1);
-      return CombineTo(N, To);
-    }
-    
     /// visit - call the node-specific routine that knows how to fold each
     /// particular type of node.
     SDOperand visit(SDNode *N);
@@ -229,6 +231,36 @@
   };
 }
 
+//===----------------------------------------------------------------------===//
+//  TargetLowering::DAGCombinerInfo implementation
+//===----------------------------------------------------------------------===//
+
+void TargetLowering::DAGCombinerInfo::AddToWorklist(SDNode *N) {
+  ((DAGCombiner*)DC)->AddToWorkList(N);
+}
+
+SDOperand TargetLowering::DAGCombinerInfo::
+CombineTo(SDNode *N, const std::vector<SDOperand> &To) {
+  return ((DAGCombiner*)DC)->CombineTo(N, To);
+}
+
+SDOperand TargetLowering::DAGCombinerInfo::
+CombineTo(SDNode *N, SDOperand Res) {
+  return ((DAGCombiner*)DC)->CombineTo(N, Res);
+}
+
+
+SDOperand TargetLowering::DAGCombinerInfo::
+CombineTo(SDNode *N, SDOperand Res0, SDOperand Res1) {
+  return ((DAGCombiner*)DC)->CombineTo(N, Res0, Res1);
+}
+
+
+
+
+//===----------------------------------------------------------------------===//
+
+
 struct ms {
   int64_t m;  // magic number
   int64_t s;  // shift amount
@@ -495,6 +527,11 @@
   // changes of the root.
   HandleSDNode Dummy(DAG.getRoot());
   
+  
+  /// DagCombineInfo - Expose the DAG combiner to the target combiner impls.
+  TargetLowering::DAGCombinerInfo 
+    DagCombineInfo(DAG, !RunningAfterLegalize, this);
+  
   // while the worklist isn't empty, inspect the node on the end of it and
   // try and combine it.
   while (!WorkList.empty()) {
@@ -514,6 +551,14 @@
     }
     
     SDOperand RV = visit(N);
+    
+    // If nothing happened, try a target-specific DAG combine.
+    if (RV.Val == 0) {
+      if (N->getOpcode() >= ISD::BUILTIN_OP_END ||
+          TLI.hasTargetDAGCombine((ISD::NodeType)N->getOpcode()))
+        RV = TLI.PerformDAGCombine(N, DagCombineInfo);
+    }
+    
     if (RV.Val) {
       ++NodesCombined;
       // If we get back the same node we passed in, rather than a new node or






More information about the llvm-commits mailing list