From 3378a5b5913110f9212540ab030baf59e9c39ccc Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 16 Jul 2002 23:49:24 +0000 Subject: [PATCH] * Add a bunch of debugging features to LevelRaise - Verify the function every time it is exprconverted if DEBUG is on - Provide a way to start exprconversion AT a specific instruction. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2934 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/LevelRaise.cpp | 41 +++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/lib/Transforms/LevelRaise.cpp b/lib/Transforms/LevelRaise.cpp index 1defda4d845..94aebcbc658 100644 --- a/lib/Transforms/LevelRaise.cpp +++ b/lib/Transforms/LevelRaise.cpp @@ -14,17 +14,29 @@ #include "llvm/Pass.h" #include "llvm/ConstantHandling.h" #include "llvm/Analysis/Expressions.h" +#include "llvm/Analysis/Verifier.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "Support/STLExtras.h" #include "Support/StatisticReporter.h" +#include "Support/CommandLine.h" #include using std::cerr; -static Statistic<> NumLoadStorePeepholes("raise\t\t- Number of load/store peepholes"); -static Statistic<> NumGEPInstFormed("raise\t\t- Number of other getelementptr's formed"); -static Statistic<> NumExprTreesConv("raise\t\t- Number of expression trees converted"); +// StartInst - This enables the -raise-start-inst=foo option to cause the level +// raising pass to start at instruction "foo", which is immensely useful for +// debugging! +// +static cl::String StartInst("raise-start-inst", "Start raise pass at the " + "instruction with the specified name", cl::Hidden); + +static Statistic<> NumLoadStorePeepholes("raise\t\t- Number of load/store " + "peepholes"); +static Statistic<> NumGEPInstFormed("raise\t\t- Number of other " + "getelementptr's formed"); +static Statistic<> NumExprTreesConv("raise\t\t- Number of expression trees" + " converted"); static Statistic<> NumCastOfCast("raise\t\t- Number of cast-of-self removed"); -static Statistic<> NumDCEorCP("raise\t\t- Number of insts DCE'd or constprop'd"); +static Statistic<> NumDCEorCP("raise\t\t- Number of insts DCEd or constprop'd"); #define PRINT_PEEPHOLE(ID, NUM, I) \ @@ -221,6 +233,9 @@ static bool PeepholeOptimize(BasicBlock *BB, BasicBlock::iterator &BI) { BI = BB->begin(); // Rescan basic block. BI might be invalidated. PRINT_PEEPHOLE1("CAST-SRC-EXPR-CONV:out", E); DEBUG(cerr << "DONE CONVERTING SRC EXPR TYPE: \n" << BB->getParent()); + + DEBUG(assert(verifyFunction(*BB->getParent()) == false && + "Function broken!")); ++NumExprTreesConv; return true; } @@ -240,6 +255,9 @@ static bool PeepholeOptimize(BasicBlock *BB, BasicBlock::iterator &BI) { BI = BB->begin(); // Rescan basic block. BI might be invalidated. PRINT_PEEPHOLE1("CAST-DEST-EXPR-CONV:out", Src); DEBUG(cerr << "DONE CONVERTING EXPR TYPE: \n\n" << BB->getParent()); + + DEBUG(assert(verifyFunction(*BB->getParent()) == false && + "Function broken!")); ++NumExprTreesConv; return true; } @@ -468,6 +486,21 @@ static bool doRPR(Function &F) { // bool Changed = false, LocalChange; + + // If the StartInst option was specified, then Peephole optimize that + // instruction first if it occurs in this function. + // + if (!StartInst.empty()) { + for (Function::iterator BB = F.begin(), BBE = F.end(); BB != BBE; ++BB) + for (BasicBlock::iterator BI = BB->begin(); BI != BB->end(); ++BI) + if (BI->getName() == StartInst) { + bool SavedDebug = DebugFlag; // Save the DEBUG() controlling flag. + DebugFlag = true; // Turn on DEBUG's + Changed |= PeepholeOptimize(BB, BI); + DebugFlag = SavedDebug; // Restore DebugFlag to previous state + } + } + do { DEBUG(cerr << "Looping: \n" << F); -- 2.34.1