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
This commit is contained in:
Chris Lattner
2002-05-22 17:17:27 +00:00
parent 70e60cbd4d
commit f016ea4ff8
4 changed files with 36 additions and 62 deletions

View File

@ -16,12 +16,11 @@
#include "llvm/Support/CFG.h" #include "llvm/Support/CFG.h"
#include "Support/STLExtras.h" #include "Support/STLExtras.h"
#include "Support/DepthFirstIterator.h" #include "Support/DepthFirstIterator.h"
#include "Support/StatisticReporter.h"
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>
using std::cerr; using std::cerr;
#define DEBUG_ADCE 1
namespace { namespace {
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -69,17 +68,13 @@ private:
inline void markInstructionLive(Instruction *I) { inline void markInstructionLive(Instruction *I) {
if (LiveSet.count(I)) return; if (LiveSet.count(I)) return;
#ifdef DEBUG_ADCE DEBUG(cerr << "Insn Live: " << I);
cerr << "Insn Live: " << I;
#endif
LiveSet.insert(I); LiveSet.insert(I);
WorkList.push_back(I); WorkList.push_back(I);
} }
inline void markTerminatorLive(const BasicBlock *BB) { inline void markTerminatorLive(const BasicBlock *BB) {
#ifdef DEBUG_ADCE DEBUG(cerr << "Terminat Live: " << BB->getTerminator());
cerr << "Terminat Live: " << BB->getTerminator();
#endif
markInstructionLive((Instruction*)BB->getTerminator()); markInstructionLive((Instruction*)BB->getTerminator());
} }
@ -101,9 +96,7 @@ Pass *createAggressiveDCEPass() {
// true if the function was modified. // true if the function was modified.
// //
void ADCE::doADCE(DominanceFrontier &CDG) { void ADCE::doADCE(DominanceFrontier &CDG) {
#ifdef DEBUG_ADCE DEBUG(cerr << "Function: " << Func);
cerr << "Function: " << Func;
#endif
// Iterate over all of the instructions in the function, eliminating trivially // Iterate over all of the instructions in the function, eliminating trivially
// dead instructions, and marking instructions live that are known to be // dead instructions, and marking instructions live that are known to be
@ -130,9 +123,7 @@ void ADCE::doADCE(DominanceFrontier &CDG) {
} }
} }
#ifdef DEBUG_ADCE DEBUG(cerr << "Processing work list\n");
cerr << "Processing work list\n";
#endif
// AliveBlocks - Set of basic blocks that we know have instructions that are // AliveBlocks - Set of basic blocks that we know have instructions that are
// alive in them... // alive in them...
@ -173,15 +164,15 @@ void ADCE::doADCE(DominanceFrontier &CDG) {
markInstructionLive(Operand); markInstructionLive(Operand);
} }
#ifdef DEBUG_ADCE if (DebugFlag) {
cerr << "Current Function: X = Live\n"; cerr << "Current Function: X = Live\n";
for (Function::iterator I = Func->begin(), E = Func->end(); I != E; ++I) for (Function::iterator I = Func->begin(), E = Func->end(); I != E; ++I)
for (BasicBlock::iterator BI = (*I)->begin(), BE = (*I)->end(); for (BasicBlock::iterator BI = (*I)->begin(), BE = (*I)->end();
BI != BE; ++BI) { BI != BE; ++BI) {
if (LiveSet.count(*BI)) cerr << "X "; if (LiveSet.count(*BI)) cerr << "X ";
cerr << *BI; cerr << *BI;
} }
#endif }
// After the worklist is processed, recursively walk the CFG in depth first // After the worklist is processed, recursively walk the CFG in depth first
// order, patching up references to dead blocks... // order, patching up references to dead blocks...
@ -266,9 +257,7 @@ BasicBlock *ADCE::fixupCFG(BasicBlock *BB, std::set<BasicBlock*> &VisitedBlocks,
if (VisitedBlocks.count(BB)) return 0; // Revisiting a node? No update. if (VisitedBlocks.count(BB)) return 0; // Revisiting a node? No update.
VisitedBlocks.insert(BB); // We have now visited this node! VisitedBlocks.insert(BB); // We have now visited this node!
#ifdef DEBUG_ADCE DEBUG(cerr << "Fixing up BB: " << BB);
cerr << "Fixing up BB: " << BB;
#endif
if (AliveBlocks.count(BB)) { // Is the block alive? if (AliveBlocks.count(BB)) { // Is the block alive?
// Yes it's alive: loop through and eliminate all dead instructions in block // Yes it's alive: loop through and eliminate all dead instructions in block

View File

@ -8,6 +8,7 @@
#include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Scalar.h"
#include "llvm/Analysis/InductionVariable.h" #include "llvm/Analysis/InductionVariable.h"
#include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/Writer.h"
#include "llvm/iPHINode.h" #include "llvm/iPHINode.h"
#include "llvm/iOther.h" #include "llvm/iOther.h"
#include "llvm/Type.h" #include "llvm/Type.h"
@ -19,10 +20,6 @@
static Statistic<> NumRemoved ("indvars\t\t- Number of aux indvars removed"); static Statistic<> NumRemoved ("indvars\t\t- Number of aux indvars removed");
static Statistic<> NumInserted("indvars\t\t- Number of cannonical indvars added"); 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 // InsertCast - Cast Val to Ty, setting a useful name on the cast if Val has a
// name... // name...
@ -116,9 +113,7 @@ static bool TransformLoop(LoopInfo *Loops, Loop *Loop) {
Changed = true; Changed = true;
} }
#ifdef DEBUG DEBUG(cerr << "Induction variables:\n");
cerr << "Induction variables:\n";
#endif
// Get the current loop iteration count, which is always the value of the // Get the current loop iteration count, which is always the value of the
// cannonical phi node... // cannonical phi node...
@ -131,9 +126,9 @@ static bool TransformLoop(LoopInfo *Loops, Loop *Loop) {
unsigned InsertPos = IndVars.size(); unsigned InsertPos = IndVars.size();
for (unsigned i = 0; i < IndVars.size(); ++i) { for (unsigned i = 0; i < IndVars.size(); ++i) {
InductionVariable *IV = &IndVars[i]; InductionVariable *IV = &IndVars[i];
#ifdef DEBUG
cerr << IndVars[i]; DEBUG(cerr << IV);
#endif
// Don't modify the cannonical indvar or unrecognized indvars... // Don't modify the cannonical indvar or unrecognized indvars...
if (IV != Cannonical && IV->InductionType != InductionVariable::Unknown) { if (IV != Cannonical && IV->InductionType != InductionVariable::Unknown) {
Instruction *Val = IterCount; Instruction *Val = IterCount;

View File

@ -27,9 +27,6 @@
#include "Support/PostOrderIterator.h" #include "Support/PostOrderIterator.h"
#include "Support/StatisticReporter.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<> NumLinear ("reassociate\t- Number of insts linearized");
static Statistic<> NumChanged("reassociate\t- Number of insts reassociated"); static Statistic<> NumChanged("reassociate\t- Number of insts reassociated");
static Statistic<> NumSwapped("reassociate\t- Number of insts with operands swapped"); static Statistic<> NumSwapped("reassociate\t- Number of insts with operands swapped");
@ -125,7 +122,7 @@ bool Reassociate::ReassociateExpr(BinaryOperator *I) {
std::swap(LHSRank, RHSRank); std::swap(LHSRank, RHSRank);
Changed = true; Changed = true;
++NumSwapped; ++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 // If the LHS is the same operator as the current one is, and if we are the
@ -147,7 +144,8 @@ bool Reassociate::ReassociateExpr(BinaryOperator *I) {
I->setOperand(1, LHSI); I->setOperand(1, LHSI);
++NumChanged; ++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. // Since we modified the RHS instruction, make sure that we recheck it.
ReassociateExpr(LHSI); ReassociateExpr(LHSI);
@ -238,7 +236,7 @@ bool Reassociate::ReassociateBB(BasicBlock *BB) {
I = Tmp; I = Tmp;
++NumLinear; ++NumLinear;
Changed = true; 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 // Make sure that this expression is correctly reassociated with respect
@ -269,7 +267,7 @@ bool Reassociate::ReassociateBB(BasicBlock *BB) {
New->setOperand(1, NegateValue(NegatedValue, BB, BI)); New->setOperand(1, NegateValue(NegatedValue, BB, BI));
--BI; --BI;
Changed = true; Changed = true;
DEBUG_REASSOC("Negated: " << New << " Result BB: " << BB); DEBUG(std::cerr << "Negated: " << New << " Result BB: " << BB);
} }
} }

View File

@ -34,12 +34,6 @@ using std::cerr;
static Statistic<> NumInstRemoved("sccp\t\t- Number of instructions removed"); 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 // InstVal class - This class represents the different lattice values that an
// instruction may occupy. It is a simple class with value semantics. // instruction may occupy. It is a simple class with value semantics.
// //
@ -125,7 +119,7 @@ private:
// the users of the instruction are updated later. // the users of the instruction are updated later.
// //
inline bool markConstant(Instruction *I, Constant *V) { inline bool markConstant(Instruction *I, Constant *V) {
DEBUG_SCCP(cerr << "markConstant: " << V << " = " << I); DEBUG(cerr << "markConstant: " << V << " = " << I);
if (ValueState[I].markConstant(V)) { if (ValueState[I].markConstant(V)) {
InstWorkList.push_back(I); InstWorkList.push_back(I);
@ -141,7 +135,7 @@ private:
inline bool markOverdefined(Value *V) { inline bool markOverdefined(Value *V) {
if (ValueState[V].markOverdefined()) { if (ValueState[V].markOverdefined()) {
if (Instruction *I = dyn_cast<Instruction>(V)) { 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 InstWorkList.push_back(I); // Only instructions go on the work list
} }
return true; return true;
@ -173,7 +167,7 @@ private:
// //
void markExecutable(BasicBlock *BB) { void markExecutable(BasicBlock *BB) {
if (BBExecutable.count(BB)) return; 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! BBExecutable.insert(BB); // Basic block is executable!
BBWorkList.push_back(BB); // Add the block to the work list! BBWorkList.push_back(BB); // Add the block to the work list!
} }
@ -258,7 +252,7 @@ bool SCCP::runOnFunction(Function *F) {
Instruction *I = InstWorkList.back(); Instruction *I = InstWorkList.back();
InstWorkList.pop_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 // "I" got into the work list because it either made the transition from
@ -275,7 +269,7 @@ bool SCCP::runOnFunction(Function *F) {
BasicBlock *BB = BBWorkList.back(); BasicBlock *BB = BBWorkList.back();
BBWorkList.pop_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 // If this block only has a single successor, mark it as executable as
// well... if not, terminate the do loop. // well... if not, terminate the do loop.
@ -289,13 +283,11 @@ bool SCCP::runOnFunction(Function *F) {
} }
} }
#if 0 if (DebugFlag) {
for (Function::iterator BBI = F->begin(), BBEnd = F->end(); for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I)
BBI != BBEnd; ++BBI) if (!BBExecutable.count(*I))
if (!BBExecutable.count(*BBI)) cerr << "BasicBlock Dead:" << *I;
cerr << "BasicBlock Dead:" << *BBI; }
#endif
// Iterate over all of the instructions in a function, replacing them with // Iterate over all of the instructions in a function, replacing them with
// constants if we have found them to be of constant values. // constants if we have found them to be of constant values.
@ -308,7 +300,7 @@ bool SCCP::runOnFunction(Function *F) {
InstVal &IV = ValueState[Inst]; InstVal &IV = ValueState[Inst];
if (IV.isConstant()) { if (IV.isConstant()) {
Constant *Const = IV.getConstant(); 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. // Replaces all of the uses of a variable with uses of the constant.
Inst->replaceAllUsesWith(Const); Inst->replaceAllUsesWith(Const);