Add an option to the DAG Combiner to enable it for beta runs, and turn on
authorNate Begeman <natebegeman@mac.com>
Wed, 7 Sep 2005 00:15:36 +0000 (00:15 +0000)
committerNate Begeman <natebegeman@mac.com>
Wed, 7 Sep 2005 00:15:36 +0000 (00:15 +0000)
that option for PowerPC's beta.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23253 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/DAGCombiner.cpp
lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

index 52110a1206cb6f2200a51fcddcda55440eef34ca..d2501d81dd268437ed1e21612d8a208af251ae81 100644 (file)
@@ -37,6 +37,7 @@
 #define DEBUG_TYPE "dagcombine"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/CodeGen/SelectionDAG.h"
+#include "llvm/Support/Debug.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Target/TargetLowering.h"
 #include <cmath>
@@ -76,8 +77,8 @@ namespace {
     // Visitation implementation - Implement dag node combining for different
     // node types.  The semantics are as follows:
     // Return Value:
-    //    null        - No change was made
-    //   otherwise    - Node N should be replaced by the returned node.
+    //   SDOperand.Val == 0   - No change was made
+    //   otherwise            - N should be replaced by the returned Operand.
     //
     SDOperand visitTokenFactor(SDNode *N);
     SDOperand visitADD(SDNode *N);
@@ -266,9 +267,9 @@ void DAGCombiner::Run(bool RunningAfterLegalize) {
       // CombineTo was used.  Since CombineTo takes care of the worklist 
       // mechanics for us, we have no work to do in this case.
       if (RV.Val != N) {
-        std::cerr << "\nReplacing "; N->dump();
-        std::cerr << "\nWith: "; RV.Val->dump();
-        std::cerr << '\n';
+        DEBUG(std::cerr << "\nReplacing "; N->dump();
+              std::cerr << "\nWith: "; RV.Val->dump();
+              std::cerr << '\n');
         DAG.ReplaceAllUsesWith(SDOperand(N, 0), RV);
           
         // Push the new node and any users onto the worklist
index ecf9797b4846389cd50afec27bc6c3078b4d5fc6..26421c148f80ca9b68f6d323eb0d1b6e30c624b3 100644 (file)
 #include <iostream>
 using namespace llvm;
 
+// Temporary command line code to enable use of the dag combiner as a beta
+// option.
+namespace llvm {
+  bool CombinerEnabled;
+}
+namespace {
+  cl::opt<bool, true>
+  CombineDAG("enable-dag-combiner", cl::Hidden,
+             cl::desc("Run the DAG combiner before and after Legalize"),
+             cl::location(CombinerEnabled),
+             cl::init(false));
+}
 #ifndef NDEBUG
 static cl::opt<bool>
 ViewDAGs("view-isel-dags", cl::Hidden,
@@ -44,6 +56,7 @@ ViewDAGs("view-isel-dags", cl::Hidden,
 static const bool ViewDAGs = 0;
 #endif
 
+
 namespace llvm {
   //===--------------------------------------------------------------------===//
   /// FunctionLoweringInfo - This contains information that is global to a
@@ -1234,6 +1247,9 @@ void SelectionDAGISel::SelectBasicBlock(BasicBlock *LLVMBB, MachineFunction &MF,
   // types that are not supported by the target.
   BuildSelectionDAG(DAG, LLVMBB, PHINodesToUpdate, FuncInfo);
 
+  // Run the DAG combiner in pre-legalize mode, if we are told to do so
+  if (CombinerEnabled) DAG.Combine(false);
+  
   DEBUG(std::cerr << "Lowered selection DAG:\n");
   DEBUG(DAG.dump());
 
@@ -1246,6 +1262,9 @@ void SelectionDAGISel::SelectBasicBlock(BasicBlock *LLVMBB, MachineFunction &MF,
 
   if (ViewDAGs) DAG.viewGraph();
 
+  // Run the DAG combiner in post-legalize mode, if we are told to do so
+  if (CombinerEnabled) DAG.Combine(true);
+  
   // Third, instruction select all of the operations to machine code, adding the
   // code to the MachineBasicBlock.
   InstructionSelectBasicBlock(DAG);