Use the new DEBUG(x) macro to allow debugging code to be enabled on the commandline


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2713 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Scalar/ADCE.cpp b/lib/Transforms/Scalar/ADCE.cpp
index 4c01691..20a34c1 100644
--- a/lib/Transforms/Scalar/ADCE.cpp
+++ b/lib/Transforms/Scalar/ADCE.cpp
@@ -16,12 +16,11 @@
 #include "llvm/Support/CFG.h"
 #include "Support/STLExtras.h"
 #include "Support/DepthFirstIterator.h"
+#include "Support/StatisticReporter.h"
 #include <algorithm>
 #include <iostream>
 using std::cerr;
 
-#define DEBUG_ADCE 1
-
 namespace {
 
 //===----------------------------------------------------------------------===//
@@ -69,17 +68,13 @@
 
   inline void markInstructionLive(Instruction *I) {
     if (LiveSet.count(I)) return;
-#ifdef DEBUG_ADCE
-    cerr << "Insn Live: " << I;
-#endif
+    DEBUG(cerr << "Insn Live: " << I);
     LiveSet.insert(I);
     WorkList.push_back(I);
   }
 
   inline void markTerminatorLive(const BasicBlock *BB) {
-#ifdef DEBUG_ADCE
-    cerr << "Terminat Live: " << BB->getTerminator();
-#endif
+    DEBUG(cerr << "Terminat Live: " << BB->getTerminator());
     markInstructionLive((Instruction*)BB->getTerminator());
   }
 
@@ -101,9 +96,7 @@
 // true if the function was modified.
 //
 void ADCE::doADCE(DominanceFrontier &CDG) {
-#ifdef DEBUG_ADCE
-  cerr << "Function: " << Func;
-#endif
+  DEBUG(cerr << "Function: " << Func);
 
   // Iterate over all of the instructions in the function, eliminating trivially
   // dead instructions, and marking instructions live that are known to be 
@@ -130,9 +123,7 @@
     }
   }
 
-#ifdef DEBUG_ADCE
-  cerr << "Processing work list\n";
-#endif
+  DEBUG(cerr << "Processing work list\n");
 
   // AliveBlocks - Set of basic blocks that we know have instructions that are
   // alive in them...
@@ -173,15 +164,15 @@
 	markInstructionLive(Operand);
   }
 
-#ifdef DEBUG_ADCE
-  cerr << "Current Function: X = Live\n";
-  for (Function::iterator I = Func->begin(), E = Func->end(); I != E; ++I)
-    for (BasicBlock::iterator BI = (*I)->begin(), BE = (*I)->end();
-         BI != BE; ++BI) {
-      if (LiveSet.count(*BI)) cerr << "X ";
-      cerr << *BI;
-    }
-#endif
+  if (DebugFlag) {
+    cerr << "Current Function: X = Live\n";
+    for (Function::iterator I = Func->begin(), E = Func->end(); I != E; ++I)
+      for (BasicBlock::iterator BI = (*I)->begin(), BE = (*I)->end();
+           BI != BE; ++BI) {
+        if (LiveSet.count(*BI)) cerr << "X ";
+        cerr << *BI;
+      }
+  }
 
   // After the worklist is processed, recursively walk the CFG in depth first
   // order, patching up references to dead blocks...
@@ -266,9 +257,7 @@
   if (VisitedBlocks.count(BB)) return 0;   // Revisiting a node? No update.
   VisitedBlocks.insert(BB);                // We have now visited this node!
 
-#ifdef DEBUG_ADCE
-  cerr << "Fixing up BB: " << BB;
-#endif
+  DEBUG(cerr << "Fixing up BB: " << BB);
 
   if (AliveBlocks.count(BB)) {             // Is the block alive?
     // Yes it's alive: loop through and eliminate all dead instructions in block
diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp
index 7b1eb5d..6446526 100644
--- a/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -8,6 +8,7 @@
 #include "llvm/Transforms/Scalar.h"
 #include "llvm/Analysis/InductionVariable.h"
 #include "llvm/Analysis/LoopInfo.h"
+#include "llvm/Analysis/Writer.h"
 #include "llvm/iPHINode.h"
 #include "llvm/iOther.h"
 #include "llvm/Type.h"
@@ -19,10 +20,6 @@
 static Statistic<> NumRemoved ("indvars\t\t- Number of aux indvars removed");
 static Statistic<> NumInserted("indvars\t\t- Number of cannonical indvars added");
 
-#if 0
-#define DEBUG
-#include "llvm/Analysis/Writer.h"
-#endif
 
 // InsertCast - Cast Val to Ty, setting a useful name on the cast if Val has a
 // name...
@@ -116,9 +113,7 @@
     Changed = true;
   }
 
-#ifdef DEBUG
-  cerr << "Induction variables:\n";
-#endif
+  DEBUG(cerr << "Induction variables:\n");
 
   // Get the current loop iteration count, which is always the value of the
   // cannonical phi node...
@@ -131,9 +126,9 @@
   unsigned InsertPos = IndVars.size();
   for (unsigned i = 0; i < IndVars.size(); ++i) {
     InductionVariable *IV = &IndVars[i];
-#ifdef DEBUG
-    cerr << IndVars[i];
-#endif
+
+    DEBUG(cerr << IV);
+
     // Don't modify the cannonical indvar or unrecognized indvars...
     if (IV != Cannonical && IV->InductionType != InductionVariable::Unknown) {
       Instruction *Val = IterCount;
diff --git a/lib/Transforms/Scalar/Reassociate.cpp b/lib/Transforms/Scalar/Reassociate.cpp
index f669262..fcbf8b3 100644
--- a/lib/Transforms/Scalar/Reassociate.cpp
+++ b/lib/Transforms/Scalar/Reassociate.cpp
@@ -27,9 +27,6 @@
 #include "Support/PostOrderIterator.h"
 #include "Support/StatisticReporter.h"
 
-//#define DEBUG_REASSOC(x) std::cerr << x
-#define DEBUG_REASSOC(x)
-
 static Statistic<> NumLinear ("reassociate\t- Number of insts linearized");
 static Statistic<> NumChanged("reassociate\t- Number of insts reassociated");
 static Statistic<> NumSwapped("reassociate\t- Number of insts with operands swapped");
@@ -125,7 +122,7 @@
     std::swap(LHSRank, RHSRank);
     Changed = true;
     ++NumSwapped;
-    DEBUG_REASSOC("Transposed: " << I << " Result BB: " << I->getParent());
+    DEBUG(std::cerr << "Transposed: " << I << " Result BB: " << I->getParent());
   }
   
   // If the LHS is the same operator as the current one is, and if we are the
@@ -147,7 +144,8 @@
         I->setOperand(1, LHSI);
 
         ++NumChanged;
-        DEBUG_REASSOC("Reassociated: " << I << " Result BB: " <<I->getParent());
+        DEBUG(std::cerr << "Reassociated: " << I << " Result BB: "
+                        << I->getParent());
 
         // Since we modified the RHS instruction, make sure that we recheck it.
         ReassociateExpr(LHSI);
@@ -238,7 +236,7 @@
           I = Tmp;
           ++NumLinear;
           Changed = true;
-          DEBUG_REASSOC("Linearized: " << I << " Result BB: " << BB);
+          DEBUG(std::cerr << "Linearized: " << I << " Result BB: " << BB);
         }
 
         // Make sure that this expression is correctly reassociated with respect
@@ -269,7 +267,7 @@
       New->setOperand(1, NegateValue(NegatedValue, BB, BI));
       --BI;
       Changed = true;
-      DEBUG_REASSOC("Negated: " << New << " Result BB: " << BB);
+      DEBUG(std::cerr << "Negated: " << New << " Result BB: " << BB);
     }
   }
 
diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp
index 591c22e..93e85fc 100644
--- a/lib/Transforms/Scalar/SCCP.cpp
+++ b/lib/Transforms/Scalar/SCCP.cpp
@@ -34,12 +34,6 @@
 
 static Statistic<> NumInstRemoved("sccp\t\t- Number of instructions removed");
 
-#if 0    // Enable this to get SCCP debug output
-#define DEBUG_SCCP(X) X
-#else
-#define DEBUG_SCCP(X)
-#endif
-
 // InstVal class - This class represents the different lattice values that an 
 // instruction may occupy.  It is a simple class with value semantics.
 //
@@ -125,7 +119,7 @@
   // the users of the instruction are updated later.
   //
   inline bool markConstant(Instruction *I, Constant *V) {
-    DEBUG_SCCP(cerr << "markConstant: " << V << " = " << I);
+    DEBUG(cerr << "markConstant: " << V << " = " << I);
 
     if (ValueState[I].markConstant(V)) {
       InstWorkList.push_back(I);
@@ -141,7 +135,7 @@
   inline bool markOverdefined(Value *V) {
     if (ValueState[V].markOverdefined()) {
       if (Instruction *I = dyn_cast<Instruction>(V)) {
-	DEBUG_SCCP(cerr << "markOverdefined: " << V);
+	DEBUG(cerr << "markOverdefined: " << V);
 	InstWorkList.push_back(I);  // Only instructions go on the work list
       }
       return true;
@@ -173,7 +167,7 @@
   // 
   void markExecutable(BasicBlock *BB) {
     if (BBExecutable.count(BB)) return;
-    DEBUG_SCCP(cerr << "Marking BB Executable: " << BB);
+    DEBUG(cerr << "Marking BB Executable: " << BB);
     BBExecutable.insert(BB);   // Basic block is executable!
     BBWorkList.push_back(BB);  // Add the block to the work list!
   }
@@ -258,7 +252,7 @@
       Instruction *I = InstWorkList.back();
       InstWorkList.pop_back();
 
-      DEBUG_SCCP(cerr << "\nPopped off I-WL: " << I);
+      DEBUG(cerr << "\nPopped off I-WL: " << I);
 
       
       // "I" got into the work list because it either made the transition from
@@ -275,7 +269,7 @@
       BasicBlock *BB = BBWorkList.back();
       BBWorkList.pop_back();
 
-      DEBUG_SCCP(cerr << "\nPopped off BBWL: " << BB);
+      DEBUG(cerr << "\nPopped off BBWL: " << BB);
 
       // If this block only has a single successor, mark it as executable as
       // well... if not, terminate the do loop.
@@ -289,13 +283,11 @@
     }
   }
 
-#if 0
-  for (Function::iterator BBI = F->begin(), BBEnd = F->end();
-       BBI != BBEnd; ++BBI)
-    if (!BBExecutable.count(*BBI))
-      cerr << "BasicBlock Dead:" << *BBI;
-#endif
-
+  if (DebugFlag) {
+    for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I)
+      if (!BBExecutable.count(*I))
+        cerr << "BasicBlock Dead:" << *I;
+  }
 
   // Iterate over all of the instructions in a function, replacing them with
   // constants if we have found them to be of constant values.
@@ -308,7 +300,7 @@
       InstVal &IV = ValueState[Inst];
       if (IV.isConstant()) {
         Constant *Const = IV.getConstant();
-        DEBUG_SCCP(cerr << "Constant: " << Const << " = " << Inst);
+        DEBUG(cerr << "Constant: " << Const << " = " << Inst);
 
         // Replaces all of the uses of a variable with uses of the constant.
         Inst->replaceAllUsesWith(Const);