From 866aa0d742b7bc9811fd1b45507af999c605205a Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 10 Aug 2010 15:46:11 +0000 Subject: Use RunPassesOn as in the rest of bugpoint. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@110682 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/bugpoint/BugDriver.h | 3 +-- tools/bugpoint/CrashDebugger.cpp | 23 ++++++++++++++++------- tools/bugpoint/ExtractFunction.cpp | 34 +++++++++++++++++----------------- 3 files changed, 34 insertions(+), 26 deletions(-) (limited to 'tools') diff --git a/tools/bugpoint/BugDriver.h b/tools/bugpoint/BugDriver.h index dbb7a3dd8f..e48806aee6 100644 --- a/tools/bugpoint/BugDriver.h +++ b/tools/bugpoint/BugDriver.h @@ -214,8 +214,7 @@ public: /// series of cleanup passes (ADCE and SimplifyCFG) to eliminate any code /// which depends on the value. The modified module is then returned. /// - Module *deleteInstructionFromProgram(const Instruction *I, unsigned Simp) - const; + Module *deleteInstructionFromProgram(const Instruction *I, unsigned Simp); /// performFinalCleanups - This method clones the current Program and performs /// a series of cleanups intended to get rid of extra cruft on the module. If diff --git a/tools/bugpoint/CrashDebugger.cpp b/tools/bugpoint/CrashDebugger.cpp index 2f73d9a58c..57dc1c830c 100644 --- a/tools/bugpoint/CrashDebugger.cpp +++ b/tools/bugpoint/CrashDebugger.cpp @@ -312,17 +312,24 @@ bool ReduceCrashingBlocks::TestBlocks(std::vector &BBs) { // a "persistent mapping" by turning basic blocks into pairs. // This won't work well if blocks are unnamed, but that is just the risk we // have to take. - std::vector > BlockInfo; + std::vector > BlockInfo; for (SmallPtrSet::iterator I = Blocks.begin(), E = Blocks.end(); I != E; ++I) - BlockInfo.push_back(std::make_pair((*I)->getParent(), (*I)->getName())); + BlockInfo.push_back(std::make_pair((*I)->getParent()->getName(), + (*I)->getName())); // Now run the CFG simplify pass on the function... - PassManager Passes; - Passes.add(createCFGSimplificationPass()); - Passes.add(createVerifierPass()); - Passes.run(*M); + std::vector Passes; + Passes.push_back("simplifycfg"); + Passes.push_back("verify"); + Module *New = BD.runPassesOn(M, Passes); + delete M; + if (!New) { + errs() << "simplifycfg failed!\n"; + exit(1); + } + M = New; // Try running on the hacked up program... if (TestFn(BD, M)) { @@ -331,8 +338,10 @@ bool ReduceCrashingBlocks::TestBlocks(std::vector &BBs) { // Make sure to use basic block pointers that point into the now-current // module, and that they don't include any deleted blocks. BBs.clear(); + const ValueSymbolTable &GST = M->getValueSymbolTable(); for (unsigned i = 0, e = BlockInfo.size(); i != e; ++i) { - ValueSymbolTable &ST = BlockInfo[i].first->getValueSymbolTable(); + Function *F = cast(GST.lookup(BlockInfo[i].first)); + ValueSymbolTable &ST = F->getValueSymbolTable(); Value* V = ST.lookup(BlockInfo[i].second); if (V && V->getType() == Type::getLabelTy(V->getContext())) BBs.push_back(cast(V)); diff --git a/tools/bugpoint/ExtractFunction.cpp b/tools/bugpoint/ExtractFunction.cpp index 4e63e1698e..7d3040255a 100644 --- a/tools/bugpoint/ExtractFunction.cpp +++ b/tools/bugpoint/ExtractFunction.cpp @@ -55,13 +55,14 @@ namespace { /// depends on the value. The modified module is then returned. /// Module *BugDriver::deleteInstructionFromProgram(const Instruction *I, - unsigned Simplification) const { - Module *Result = CloneModule(Program); + unsigned Simplification) { + // FIXME, use vmap? + Module *Clone = CloneModule(Program); const BasicBlock *PBB = I->getParent(); const Function *PF = PBB->getParent(); - Module::iterator RFI = Result->begin(); // Get iterator to corresponding fn + Module::iterator RFI = Clone->begin(); // Get iterator to corresponding fn std::advance(RFI, std::distance(PF->getParent()->begin(), Module::const_iterator(PF))); @@ -79,24 +80,23 @@ Module *BugDriver::deleteInstructionFromProgram(const Instruction *I, // Remove the instruction from the program. TheInst->getParent()->getInstList().erase(TheInst); - - //writeProgramToFile("current.bc", Result); - // Spiff up the output a little bit. - PassManager Passes; - // Make sure that the appropriate target data is always used... - Passes.add(new TargetData(Result)); + std::vector Passes; - /// FIXME: If this used runPasses() like the methods below, we could get rid - /// of the -disable-* options! + /// Can we get rid of the -disable-* options? if (Simplification > 1 && !NoDCE) - Passes.add(createDeadCodeEliminationPass()); + Passes.push_back("dce"); if (Simplification && !DisableSimplifyCFG) - Passes.add(createCFGSimplificationPass()); // Delete dead control flow - - Passes.add(createVerifierPass()); - Passes.run(*Result); - return Result; + Passes.push_back("simplifycfg"); // Delete dead control flow + + Passes.push_back("verify"); + Module *New = runPassesOn(Clone, Passes); + delete Clone; + if (!New) { + errs() << "Instruction removal failed. Sorry. :( Please report a bug!\n"; + exit(1); + } + return New; } /// performFinalCleanups - This method clones the current Program and performs -- cgit v1.2.3