Index: docs/OptBisect.rst =================================================================== --- docs/OptBisect.rst +++ docs/OptBisect.rst @@ -157,7 +157,6 @@ bool ModulePass::skipModule(Module &M); bool CallGraphSCCPass::skipSCC(CallGraphSCC &SCC); bool FunctionPass::skipFunction(const Function &F); - bool BasicBlockPass::skipBasicBlock(const BasicBlock &BB); bool LoopPass::skipLoop(const Loop *L); A MachineFunctionPass should use FunctionPass::skipFunction() as such: Index: docs/WritingAnLLVMPass.rst =================================================================== --- docs/WritingAnLLVMPass.rst +++ docs/WritingAnLLVMPass.rst @@ -24,8 +24,7 @@ `, :ref:`FunctionPass ` , or :ref:`LoopPass `, or :ref:`RegionPass -`, or :ref:`BasicBlockPass -` classes, which gives the system more +` classes, which gives the system more information about what your pass does, and how it can be combined with other passes. One of the main features of the LLVM Pass Framework is that it schedules passes to run in an efficient way based on the constraints that your @@ -395,8 +394,7 @@ for building and traversing the ``CallGraph``, but also allows the system to optimize execution of ``CallGraphSCCPass``\ es. If your pass meets the requirements outlined below, and doesn't meet the requirements of a -:ref:`FunctionPass ` or :ref:`BasicBlockPass -`, you should derive from +:ref:`FunctionPass `, you should derive from ``CallGraphSCCPass``. ``TODO``: explain briefly what SCC, Tarjan's algo, and B-U mean. @@ -648,69 +646,6 @@ ` for every region in the program being compiled. -.. _writing-an-llvm-pass-BasicBlockPass: - -The ``BasicBlockPass`` class ----------------------------- - -``BasicBlockPass``\ es are just like :ref:`FunctionPass's -` , except that they must limit their scope -of inspection and modification to a single basic block at a time. As such, -they are **not** allowed to do any of the following: - -#. Modify or inspect any basic blocks outside of the current one. -#. Maintain state across invocations of :ref:`runOnBasicBlock - `. -#. Modify the control flow graph (by altering terminator instructions) -#. Any of the things forbidden for :ref:`FunctionPasses - `. - -``BasicBlockPass``\ es are useful for traditional local and "peephole" -optimizations. They may override the same :ref:`doInitialization(Module &) -` and :ref:`doFinalization(Module &) -` methods that :ref:`FunctionPass's -` have, but also have the following virtual -methods that may also be implemented: - -The ``doInitialization(Function &)`` method -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. code-block:: c++ - - virtual bool doInitialization(Function &F); - -The ``doInitialization`` method is allowed to do most of the things that -``BasicBlockPass``\ es are not allowed to do, but that ``FunctionPass``\ es -can. The ``doInitialization`` method is designed to do simple initialization -that does not depend on the ``BasicBlock``\ s being processed. The -``doInitialization`` method call is not scheduled to overlap with any other -pass executions (thus it should be very fast). - -.. _writing-an-llvm-pass-runOnBasicBlock: - -The ``runOnBasicBlock`` method -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. code-block:: c++ - - virtual bool runOnBasicBlock(BasicBlock &BB) = 0; - -Override this function to do the work of the ``BasicBlockPass``. This function -is not allowed to inspect or modify basic blocks other than the parameter, and -are not allowed to modify the CFG. A ``true`` value must be returned if the -basic block is modified. - -The ``doFinalization(Function &)`` method -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. code-block:: c++ - - virtual bool doFinalization(Function &F); - -The ``doFinalization`` method is an infrequently used method that is called -when the pass framework has finished calling :ref:`runOnBasicBlock -` for every ``BasicBlock`` in the program -being compiled. This can be used to perform per-function finalization. The ``MachineFunctionPass`` class --------------------------------- @@ -864,8 +799,7 @@ modify the LLVM program at all (which is true for analyses), and the ``setPreservesCFG`` method can be used by transformations that change instructions in the program but do not modify the CFG or terminator -instructions (note that this property is implicitly set for -:ref:`BasicBlockPass `\ es). +instructions. ``addPreserved`` is particularly useful for transformations like ``BreakCriticalEdges``. This pass knows how to update a small set of loop and Index: include/llvm/IR/IRPrintingPasses.h =================================================================== --- include/llvm/IR/IRPrintingPasses.h +++ include/llvm/IR/IRPrintingPasses.h @@ -23,7 +23,6 @@ namespace llvm { class Pass; -class BasicBlockPass; class Function; class FunctionPass; class Module; @@ -43,11 +42,6 @@ FunctionPass *createPrintFunctionPass(raw_ostream &OS, const std::string &Banner = ""); -/// Create and return a pass that writes the BB to the specified -/// \c raw_ostream. -BasicBlockPass *createPrintBasicBlockPass(raw_ostream &OS, - const std::string &Banner = ""); - /// Print out a name of an LLVM value without any prefixes. /// /// The name is surrounded with ""'s and escaped if it has any special or Index: include/llvm/IR/LegacyPassManager.h =================================================================== --- include/llvm/IR/LegacyPassManager.h +++ include/llvm/IR/LegacyPassManager.h @@ -63,7 +63,7 @@ PassManagerImpl *PM; }; -/// FunctionPassManager manages FunctionPasses and BasicBlockPassManagers. +/// FunctionPassManager manages FunctionPasses. class FunctionPassManager : public PassManagerBase { public: /// FunctionPassManager ctor - This initializes the pass manager. It needs, Index: include/llvm/IR/LegacyPassManagers.h =================================================================== --- include/llvm/IR/LegacyPassManagers.h +++ include/llvm/IR/LegacyPassManagers.h @@ -53,10 +53,6 @@ // a place to implement common pass manager APIs. All pass managers derive from // PMDataManager. // -// [o] class BBPassManager : public FunctionPass, public PMDataManager; -// -// BBPassManager manages BasicBlockPasses. -// // [o] class FunctionPassManager; // // This is a external interface used to manage FunctionPasses. This @@ -103,7 +99,6 @@ EXECUTION_MSG, // "Executing Pass '" + PassName MODIFICATION_MSG, // "Made Modification '" + PassName FREEING_MSG, // " Freeing Pass '" + PassName - ON_BASICBLOCK_MSG, // "' on BasicBlock '" + InstructionName + "'...\n" ON_FUNCTION_MSG, // "' on Function '" + FunctionName + "'...\n" ON_MODULE_MSG, // "' on Module '" + ModuleName + "'...\n" ON_REGION_MSG, // "' on Region '" + Msg + "'...\n'" Index: include/llvm/InitializePasses.h =================================================================== --- include/llvm/InitializePasses.h +++ include/llvm/InitializePasses.h @@ -332,7 +332,6 @@ void initializePostRASchedulerPass(PassRegistry&); void initializePreISelIntrinsicLoweringLegacyPassPass(PassRegistry&); void initializePredicateInfoPrinterLegacyPassPass(PassRegistry&); -void initializePrintBasicBlockPassPass(PassRegistry&); void initializePrintFunctionPassWrapperPass(PassRegistry&); void initializePrintModulePassWrapperPass(PassRegistry&); void initializeProcessImplicitDefsPass(PassRegistry&); Index: include/llvm/LinkAllPasses.h =================================================================== --- include/llvm/LinkAllPasses.h +++ include/llvm/LinkAllPasses.h @@ -200,7 +200,6 @@ llvm::raw_string_ostream os(buf); (void) llvm::createPrintModulePass(os); (void) llvm::createPrintFunctionPass(os); - (void) llvm::createPrintBasicBlockPass(os); (void) llvm::createModuleDebugInfoPrinterPass(); (void) llvm::createPartialInliningPass(); (void) llvm::createLintPass(); Index: include/llvm/Pass.h =================================================================== --- include/llvm/Pass.h +++ include/llvm/Pass.h @@ -57,13 +57,11 @@ PMT_FunctionPassManager, ///< FPPassManager PMT_LoopPassManager, ///< LPPassManager PMT_RegionPassManager, ///< RGPassManager - PMT_BasicBlockPassManager, ///< BBPassManager PMT_Last }; // Different types of passes. enum PassKind { - PT_BasicBlock, PT_Region, PT_Loop, PT_Function, @@ -305,56 +303,6 @@ bool skipFunction(const Function &F) const; }; -//===----------------------------------------------------------------------===// -/// Deprecated - do not create new passes as BasicBlockPasses. Use FunctionPass -/// with a loop over the BasicBlocks instead. -// -/// BasicBlockPass class - This class is used to implement most local -/// optimizations. Optimizations should subclass this class if they -/// meet the following constraints: -/// 1. Optimizations are local, operating on either a basic block or -/// instruction at a time. -/// 2. Optimizations do not modify the CFG of the contained function, or any -/// other basic block in the function. -/// 3. Optimizations conform to all of the constraints of FunctionPasses. -/// -class BasicBlockPass : public Pass { -public: - explicit BasicBlockPass(char &pid) : Pass(PT_BasicBlock, pid) {} - - /// createPrinterPass - Get a basic block printer pass. - Pass *createPrinterPass(raw_ostream &OS, - const std::string &Banner) const override; - - using llvm::Pass::doInitialization; - using llvm::Pass::doFinalization; - - /// doInitialization - Virtual method overridden by BasicBlockPass subclasses - /// to do any necessary per-function initialization. - virtual bool doInitialization(Function &); - - /// runOnBasicBlock - Virtual method overriden by subclasses to do the - /// per-basicblock processing of the pass. - virtual bool runOnBasicBlock(BasicBlock &BB) = 0; - - /// doFinalization - Virtual method overriden by BasicBlockPass subclasses to - /// do any post processing needed after all passes have run. - virtual bool doFinalization(Function &); - - void preparePassManager(PMStack &PMS) override; - - void assignPassManager(PMStack &PMS, PassManagerType T) override; - - /// Return what kind of Pass Manager can manage this pass. - PassManagerType getPotentialPassManagerType() const override; - -protected: - /// Optional passes call this function to check whether the pass should be - /// skipped. This is the case when Attribute::OptimizeNone is set or when - /// optimization bisect is over the limit. - bool skipBasicBlock(const BasicBlock &BB) const; -}; - /// If the user specifies the -time-passes argument on an LLVM tool command line /// then the value of this boolean will be true, otherwise false. /// This is the storage for the -time-passes option. Index: include/llvm/Transforms/Scalar.h =================================================================== --- include/llvm/Transforms/Scalar.h +++ include/llvm/Transforms/Scalar.h @@ -18,7 +18,6 @@ namespace llvm { -class BasicBlockPass; class Function; class FunctionPass; class ModulePass; @@ -50,8 +49,7 @@ //===----------------------------------------------------------------------===// // // DeadInstElimination - This pass quickly removes trivially dead instructions -// without modifying the CFG of the function. It is a BasicBlockPass, so it -// runs efficiently when queued next to other BasicBlockPass's. +// without modifying the CFG of the function. It is a FunctionPass. // Pass *createDeadInstEliminationPass(); Index: include/llvm/Transforms/Vectorize.h =================================================================== --- include/llvm/Transforms/Vectorize.h +++ include/llvm/Transforms/Vectorize.h @@ -16,7 +16,6 @@ namespace llvm { class BasicBlock; -class BasicBlockPass; class Pass; //===----------------------------------------------------------------------===// Index: lib/IR/Core.cpp =================================================================== --- lib/IR/Core.cpp +++ lib/IR/Core.cpp @@ -47,7 +47,6 @@ initializeDominatorTreeWrapperPassPass(Registry); initializePrintModulePassWrapperPass(Registry); initializePrintFunctionPassWrapperPass(Registry); - initializePrintBasicBlockPassPass(Registry); initializeSafepointIRVerifierPass(Registry); initializeVerifierLegacyPassPass(Registry); } Index: lib/IR/IRPrintingPasses.cpp =================================================================== --- lib/IR/IRPrintingPasses.cpp +++ lib/IR/IRPrintingPasses.cpp @@ -109,28 +109,6 @@ StringRef getPassName() const override { return "Print Function IR"; } }; -class PrintBasicBlockPass : public BasicBlockPass { - raw_ostream &Out; - std::string Banner; - -public: - static char ID; - PrintBasicBlockPass() : BasicBlockPass(ID), Out(dbgs()) {} - PrintBasicBlockPass(raw_ostream &Out, const std::string &Banner) - : BasicBlockPass(ID), Out(Out), Banner(Banner) {} - - bool runOnBasicBlock(BasicBlock &BB) override { - Out << Banner << BB; - return false; - } - - void getAnalysisUsage(AnalysisUsage &AU) const override { - AU.setPreservesAll(); - } - - StringRef getPassName() const override { return "Print BasicBlock IR"; } -}; - } char PrintModulePassWrapper::ID = 0; @@ -139,9 +117,6 @@ char PrintFunctionPassWrapper::ID = 0; INITIALIZE_PASS(PrintFunctionPassWrapper, "print-function", "Print function to stderr", false, true) -char PrintBasicBlockPass::ID = 0; -INITIALIZE_PASS(PrintBasicBlockPass, "print-bb", "Print BB to stderr", false, - true) ModulePass *llvm::createPrintModulePass(llvm::raw_ostream &OS, const std::string &Banner, @@ -154,15 +129,9 @@ return new PrintFunctionPassWrapper(OS, Banner); } -BasicBlockPass *llvm::createPrintBasicBlockPass(llvm::raw_ostream &OS, - const std::string &Banner) { - return new PrintBasicBlockPass(OS, Banner); -} - bool llvm::isIRPrintingPass(Pass *P) { const char *PID = (const char*)P->getPassID(); - return (PID == &PrintModulePassWrapper::ID) - || (PID == &PrintFunctionPassWrapper::ID) - || (PID == &PrintBasicBlockPass::ID); + return (PID == &PrintModulePassWrapper::ID) || + (PID == &PrintFunctionPassWrapper::ID); } Index: lib/IR/LegacyPassManager.cpp =================================================================== --- lib/IR/LegacyPassManager.cpp +++ lib/IR/LegacyPassManager.cpp @@ -314,64 +314,6 @@ OS << "'\n"; } - -namespace { -//===----------------------------------------------------------------------===// -// BBPassManager -// -/// BBPassManager manages BasicBlockPass. It batches all the -/// pass together and sequence them to process one basic block before -/// processing next basic block. -class BBPassManager : public PMDataManager, public FunctionPass { - -public: - static char ID; - explicit BBPassManager() - : PMDataManager(), FunctionPass(ID) {} - - /// Execute all of the passes scheduled for execution. Keep track of - /// whether any of the passes modifies the function, and if so, return true. - bool runOnFunction(Function &F) override; - - /// Pass Manager itself does not invalidate any analysis info. - void getAnalysisUsage(AnalysisUsage &Info) const override { - Info.setPreservesAll(); - } - - bool doInitialization(Module &M) override; - bool doInitialization(Function &F); - bool doFinalization(Module &M) override; - bool doFinalization(Function &F); - - PMDataManager *getAsPMDataManager() override { return this; } - Pass *getAsPass() override { return this; } - - StringRef getPassName() const override { return "BasicBlock Pass Manager"; } - - // Print passes managed by this manager - void dumpPassStructure(unsigned Offset) override { - dbgs().indent(Offset*2) << "BasicBlockPass Manager\n"; - for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) { - BasicBlockPass *BP = getContainedPass(Index); - BP->dumpPassStructure(Offset + 1); - dumpLastUses(BP, Offset+1); - } - } - - BasicBlockPass *getContainedPass(unsigned N) { - assert(N < PassVector.size() && "Pass number out of range!"); - BasicBlockPass *BP = static_cast(PassVector[N]); - return BP; - } - - PassManagerType getPassManagerType() const override { - return PMT_BasicBlockPassManager; - } -}; - -char BBPassManager::ID = 0; -} // End anonymous namespace - namespace llvm { namespace legacy { //===----------------------------------------------------------------------===// @@ -1249,9 +1191,6 @@ break; } switch (S2) { - case ON_BASICBLOCK_MSG: - dbgs() << "' on BasicBlock '" << Msg << "'...\n"; - break; case ON_FUNCTION_MSG: dbgs() << "' on Function '" << Msg << "'...\n"; break; @@ -1367,117 +1306,6 @@ return PM.getOnTheFlyPass(P, AnalysisPI, F); } -//===----------------------------------------------------------------------===// -// BBPassManager implementation - -/// Execute all of the passes scheduled for execution by invoking -/// runOnBasicBlock method. Keep track of whether any of the passes modifies -/// the function, and if so, return true. -bool BBPassManager::runOnFunction(Function &F) { - if (F.isDeclaration()) - return false; - - bool Changed = doInitialization(F); - Module &M = *F.getParent(); - - unsigned InstrCount, BBSize = 0; - StringMap> FunctionToInstrCount; - bool EmitICRemark = M.shouldEmitInstrCountChangedRemark(); - if (EmitICRemark) - InstrCount = initSizeRemarkInfo(M, FunctionToInstrCount); - - for (BasicBlock &BB : F) { - // Collect the initial size of the basic block. - if (EmitICRemark) - BBSize = BB.size(); - for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) { - BasicBlockPass *BP = getContainedPass(Index); - bool LocalChanged = false; - - dumpPassInfo(BP, EXECUTION_MSG, ON_BASICBLOCK_MSG, BB.getName()); - dumpRequiredSet(BP); - - initializeAnalysisImpl(BP); - - { - // If the pass crashes, remember this. - PassManagerPrettyStackEntry X(BP, BB); - TimeRegion PassTimer(getPassTimer(BP)); - LocalChanged |= BP->runOnBasicBlock(BB); - if (EmitICRemark) { - unsigned NewSize = BB.size(); - // Update the size of the basic block, emit a remark, and update the - // size of the module. - if (NewSize != BBSize) { - int64_t Delta = - static_cast(NewSize) - static_cast(BBSize); - emitInstrCountChangedRemark(BP, M, Delta, InstrCount, - FunctionToInstrCount, &F); - InstrCount = static_cast(InstrCount) + Delta; - BBSize = NewSize; - } - } - } - - Changed |= LocalChanged; - if (LocalChanged) - dumpPassInfo(BP, MODIFICATION_MSG, ON_BASICBLOCK_MSG, - BB.getName()); - dumpPreservedSet(BP); - dumpUsedSet(BP); - - verifyPreservedAnalysis(BP); - removeNotPreservedAnalysis(BP); - recordAvailableAnalysis(BP); - removeDeadPasses(BP, BB.getName(), ON_BASICBLOCK_MSG); - } - } - - return doFinalization(F) || Changed; -} - -// Implement doInitialization and doFinalization -bool BBPassManager::doInitialization(Module &M) { - bool Changed = false; - - for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) - Changed |= getContainedPass(Index)->doInitialization(M); - - return Changed; -} - -bool BBPassManager::doFinalization(Module &M) { - bool Changed = false; - - for (int Index = getNumContainedPasses() - 1; Index >= 0; --Index) - Changed |= getContainedPass(Index)->doFinalization(M); - - return Changed; -} - -bool BBPassManager::doInitialization(Function &F) { - bool Changed = false; - - for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) { - BasicBlockPass *BP = getContainedPass(Index); - Changed |= BP->doInitialization(F); - } - - return Changed; -} - -bool BBPassManager::doFinalization(Function &F) { - bool Changed = false; - - for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) { - BasicBlockPass *BP = getContainedPass(Index); - Changed |= BP->doFinalization(F); - } - - return Changed; -} - - //===----------------------------------------------------------------------===// // FunctionPassManager implementation @@ -1998,60 +1826,4 @@ FPP->add(this); } -void BasicBlockPass::preparePassManager(PMStack &PMS) { - // Find BBPassManager - while (!PMS.empty() && - PMS.top()->getPassManagerType() > PMT_BasicBlockPassManager) - PMS.pop(); - - // If this pass is destroying high level information that is used - // by other passes that are managed by BBPM then do not insert - // this pass in current BBPM. Use new BBPassManager. - if (PMS.top()->getPassManagerType() == PMT_BasicBlockPassManager && - !PMS.top()->preserveHigherLevelAnalysis(this)) - PMS.pop(); -} - -/// Find appropriate Basic Pass Manager or Call Graph Pass Manager -/// in the PM Stack and add self into that manager. -void BasicBlockPass::assignPassManager(PMStack &PMS, - PassManagerType PreferredType) { - while (!PMS.empty() && - PMS.top()->getPassManagerType() > PMT_BasicBlockPassManager) - PMS.pop(); - - BBPassManager *BBP; - - // Basic Pass Manager is a leaf pass manager. It does not handle - // any other pass manager. - if (!PMS.empty() && - PMS.top()->getPassManagerType() == PMT_BasicBlockPassManager) { - BBP = (BBPassManager *)PMS.top(); - } else { - // If leaf manager is not Basic Block Pass manager then create new - // basic Block Pass manager. - assert(!PMS.empty() && "Unable to create BasicBlock Pass Manager"); - PMDataManager *PMD = PMS.top(); - - // [1] Create new Basic Block Manager - BBP = new BBPassManager(); - BBP->populateInheritedAnalysis(PMS); - - // [2] Set up new manager's top level manager - // Basic Block Pass Manager does not live by itself - PMTopLevelManager *TPM = PMD->getTopLevelManager(); - TPM->addIndirectPassManager(BBP); - - // [3] Assign manager to manage this new manager. This may create - // and push new managers into PMS - BBP->assignPassManager(PMS, PreferredType); - - // [4] Push new manager into PMS - PMS.push(BBP); - } - - // Assign BBP as the manager of this pass. - BBP->add(this); -} - PassManagerBase::~PassManagerBase() {} Index: lib/IR/Pass.cpp =================================================================== --- lib/IR/Pass.cpp +++ lib/IR/Pass.cpp @@ -176,51 +176,6 @@ return false; } -//===----------------------------------------------------------------------===// -// BasicBlockPass Implementation -// - -Pass *BasicBlockPass::createPrinterPass(raw_ostream &OS, - const std::string &Banner) const { - return createPrintBasicBlockPass(OS, Banner); -} - -bool BasicBlockPass::doInitialization(Function &) { - // By default, don't do anything. - return false; -} - -bool BasicBlockPass::doFinalization(Function &) { - // By default, don't do anything. - return false; -} - -static std::string getDescription(const BasicBlock &BB) { - return "basic block (" + BB.getName().str() + ") in function (" + - BB.getParent()->getName().str() + ")"; -} - -bool BasicBlockPass::skipBasicBlock(const BasicBlock &BB) const { - const Function *F = BB.getParent(); - if (!F) - return false; - OptPassGate &Gate = F->getContext().getOptPassGate(); - if (Gate.isEnabled() && !Gate.shouldRunPass(this, getDescription(BB))) - return true; - if (F->hasOptNone()) { - // Report this only once per function. - if (&BB == &F->getEntryBlock()) - LLVM_DEBUG(dbgs() << "Skipping pass '" << getPassName() - << "' on function " << F->getName() << "\n"); - return true; - } - return false; -} - -PassManagerType BasicBlockPass::getPotentialPassManagerType() const { - return PMT_BasicBlockPassManager; -} - const PassInfo *Pass::lookupPassInfo(const void *TI) { return PassRegistry::getPassRegistry()->getPassInfo(TI); } Index: tools/bugpoint-passes/TestPasses.cpp =================================================================== --- tools/bugpoint-passes/TestPasses.cpp +++ tools/bugpoint-passes/TestPasses.cpp @@ -21,25 +21,25 @@ using namespace llvm; namespace { - /// CrashOnCalls - This pass is used to test bugpoint. It intentionally - /// crashes on any call instructions. - class CrashOnCalls : public BasicBlockPass { - public: - static char ID; // Pass ID, replacement for typeid - CrashOnCalls() : BasicBlockPass(ID) {} - private: - void getAnalysisUsage(AnalysisUsage &AU) const override { - AU.setPreservesAll(); - } +class CrashOnCalls : public FunctionPass { +public: + static char ID; // Pass ID, replacement for typeid + CrashOnCalls() : FunctionPass(ID) {} - bool runOnBasicBlock(BasicBlock &BB) override { +private: + void getAnalysisUsage(AnalysisUsage &AU) const override { + AU.setPreservesAll(); + } + + bool runOnFunction(Function &F) override { + for (auto &BB : F) for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I) if (isa(*I)) abort(); - return false; - } - }; + return false; + } +}; } char CrashOnCalls::ID = 0; @@ -48,14 +48,16 @@ "BugPoint Test Pass - Intentionally crash on CallInsts"); namespace { - /// DeleteCalls - This pass is used to test bugpoint. It intentionally - /// deletes some call instructions, "misoptimizing" the program. - class DeleteCalls : public BasicBlockPass { - public: - static char ID; // Pass ID, replacement for typeid - DeleteCalls() : BasicBlockPass(ID) {} - private: - bool runOnBasicBlock(BasicBlock &BB) override { +/// DeleteCalls - This pass is used to test bugpoint. It intentionally +/// deletes some call instructions, "misoptimizing" the program. +class DeleteCalls : public FunctionPass { +public: + static char ID; // Pass ID, replacement for typeid + DeleteCalls() : FunctionPass(ID) {} + +private: + bool runOnFunction(Function &F) override { + for (auto &BB : F) for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I) if (CallInst *CI = dyn_cast(I)) { if (!CI->use_empty()) @@ -63,9 +65,9 @@ CI->getParent()->getInstList().erase(CI); break; } - return false; - } - }; + return false; + } +}; } char DeleteCalls::ID = 0; Index: tools/opt/PassPrinters.h =================================================================== --- tools/opt/PassPrinters.h +++ tools/opt/PassPrinters.h @@ -18,7 +18,6 @@ namespace llvm { -class BasicBlockPass; class CallGraphSCCPass; class FunctionPass; class ModulePass; @@ -43,9 +42,6 @@ RegionPass *createRegionPassPrinter(const PassInfo *PI, raw_ostream &out, bool Quiet); -BasicBlockPass *createBasicBlockPassPrinter(const PassInfo *PI, - raw_ostream &out, bool Quiet); - } // end namespace llvm #endif // LLVM_TOOLS_OPT_PASSPRINTERS_H Index: tools/opt/PassPrinters.cpp =================================================================== --- tools/opt/PassPrinters.cpp +++ tools/opt/PassPrinters.cpp @@ -198,40 +198,6 @@ char RegionPassPrinter::ID = 0; -struct BasicBlockPassPrinter : public BasicBlockPass { - const PassInfo *PassToPrint; - raw_ostream &Out; - static char ID; - std::string PassName; - bool QuietPass; - - BasicBlockPassPrinter(const PassInfo *PI, raw_ostream &out, bool Quiet) - : BasicBlockPass(ID), PassToPrint(PI), Out(out), QuietPass(Quiet) { - std::string PassToPrintName = PassToPrint->getPassName(); - PassName = "BasicBlockPass Printer: " + PassToPrintName; - } - - bool runOnBasicBlock(BasicBlock &BB) override { - if (!QuietPass) - Out << "Printing Analysis info for BasicBlock '" << BB.getName() - << "': Pass " << PassToPrint->getPassName() << ":\n"; - - // Get and print pass... - getAnalysisID(PassToPrint->getTypeInfo()) - .print(Out, BB.getParent()->getParent()); - return false; - } - - StringRef getPassName() const override { return PassName; } - - void getAnalysisUsage(AnalysisUsage &AU) const override { - AU.addRequiredID(PassToPrint->getTypeInfo()); - AU.setPreservesAll(); - } -}; - -char BasicBlockPassPrinter::ID = 0; - } // end anonymous namespace FunctionPass *llvm::createFunctionPassPrinter(const PassInfo *PI, @@ -260,7 +226,3 @@ return new RegionPassPrinter(PI, OS, Quiet); } -BasicBlockPass *llvm::createBasicBlockPassPrinter(const PassInfo *PI, - raw_ostream &OS, bool Quiet) { - return new BasicBlockPassPrinter(PI, OS, Quiet); -} Index: tools/opt/opt.cpp =================================================================== --- tools/opt/opt.cpp +++ tools/opt/opt.cpp @@ -328,7 +328,7 @@ PassKind Kind = P->getPassKind(); StringRef Name = P->getPassName(); - // TODO: Implement Debugify for BasicBlockPass, LoopPass. + // TODO: Implement Debugify for LoopPass. switch (Kind) { case PT_Function: super::add(createDebugifyFunctionPass()); @@ -790,9 +790,6 @@ if (AnalyzeOnly) { switch (Kind) { - case PT_BasicBlock: - Passes.add(createBasicBlockPassPrinter(PassInf, Out->os(), Quiet)); - break; case PT_Region: Passes.add(createRegionPassPrinter(PassInf, Out->os(), Quiet)); break; Index: unittests/IR/LegacyPassManagerTest.cpp =================================================================== --- unittests/IR/LegacyPassManagerTest.cpp +++ unittests/IR/LegacyPassManagerTest.cpp @@ -38,7 +38,6 @@ void initializeFPassPass(PassRegistry&); void initializeCGPassPass(PassRegistry&); void initializeLPassPass(PassRegistry&); - void initializeBPassPass(PassRegistry&); namespace { // ND = no deps @@ -219,47 +218,6 @@ int LPass::initcount=0; int LPass::fincount=0; - struct BPass : public PassTestBase { - private: - static int inited; - static int fin; - public: - static void finishedOK(int run, int N) { - PassTestBase::finishedOK(run); - EXPECT_EQ(inited, N); - EXPECT_EQ(fin, N); - } - BPass() { - inited = 0; - fin = 0; - } - bool doInitialization(Module &M) override { - EXPECT_FALSE(initialized); - initialized = true; - return false; - } - bool doInitialization(Function &F) override { - inited++; - return false; - } - bool runOnBasicBlock(BasicBlock &BB) override { - run(); - return false; - } - bool doFinalization(Function &F) override { - fin++; - return false; - } - bool doFinalization(Module &M) override { - EXPECT_FALSE(finalized); - finalized = true; - EXPECT_EQ(0, allocated); - return false; - } - }; - int BPass::inited=0; - int BPass::fin=0; - struct OnTheFlyTest: public ModulePass { public: static char ID; @@ -374,10 +332,6 @@ SCOPED_TRACE("Loop pass"); MemoryTestHelper(2, 1); //2 loops, 1 function } - { - SCOPED_TRACE("Basic block pass"); - MemoryTestHelper(7, 4); //9 basic blocks - } } @@ -616,4 +570,3 @@ INITIALIZE_PASS_BEGIN(LPass, "lp","lp", false, false) INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass) INITIALIZE_PASS_END(LPass, "lp","lp", false, false) -INITIALIZE_PASS(BPass, "bp","bp", false, false)