[llvm] 9f0ff0b - [LegacyPassManager] Delete BasicBlockPass/Manager.

Alina Sbirlea via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 30 11:40:35 PDT 2019


Author: Alina Sbirlea
Date: 2019-10-30T11:40:16-07:00
New Revision: 9f0ff0b2634bab6a5be8dace005c9eb24d386dd1

URL: https://github.com/llvm/llvm-project/commit/9f0ff0b2634bab6a5be8dace005c9eb24d386dd1
DIFF: https://github.com/llvm/llvm-project/commit/9f0ff0b2634bab6a5be8dace005c9eb24d386dd1.diff

LOG: [LegacyPassManager] Delete BasicBlockPass/Manager.

Summary:
Delete the BasicBlockPass and BasicBlockManager, all its dependencies and update documentation.
The BasicBlockManager was improperly tested and found to be potentially broken, and was deprecated as of rL373254.

In light of the switch to the new pass manager coming before the next release, this patch is a first cleanup of the LegacyPassManager.

Reviewers: chandlerc, echristo

Subscribers: mehdi_amini, sanjoy.google, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D69121

Added: 
    

Modified: 
    llvm/docs/OptBisect.rst
    llvm/docs/WritingAnLLVMPass.rst
    llvm/include/llvm/IR/IRPrintingPasses.h
    llvm/include/llvm/IR/LegacyPassManager.h
    llvm/include/llvm/IR/LegacyPassManagers.h
    llvm/include/llvm/InitializePasses.h
    llvm/include/llvm/LinkAllPasses.h
    llvm/include/llvm/Pass.h
    llvm/include/llvm/Transforms/Scalar.h
    llvm/include/llvm/Transforms/Vectorize.h
    llvm/lib/IR/Core.cpp
    llvm/lib/IR/IRPrintingPasses.cpp
    llvm/lib/IR/LegacyPassManager.cpp
    llvm/lib/IR/Pass.cpp
    llvm/tools/bugpoint-passes/TestPasses.cpp
    llvm/tools/opt/PassPrinters.cpp
    llvm/tools/opt/PassPrinters.h
    llvm/tools/opt/opt.cpp
    llvm/unittests/IR/LegacyPassManagerTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/docs/OptBisect.rst b/llvm/docs/OptBisect.rst
index 4dcbb76ccebe..a0044eec8df4 100644
--- a/llvm/docs/OptBisect.rst
+++ b/llvm/docs/OptBisect.rst
@@ -157,7 +157,6 @@ to make this check uniform across all passes.  These helper functions are:
   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:

diff  --git a/llvm/docs/WritingAnLLVMPass.rst b/llvm/docs/WritingAnLLVMPass.rst
index ddf045acb74a..fae14d8ca320 100644
--- a/llvm/docs/WritingAnLLVMPass.rst
+++ b/llvm/docs/WritingAnLLVMPass.rst
@@ -24,8 +24,7 @@ on how your pass works, you should inherit from the :ref:`ModulePass
 <writing-an-llvm-pass-CallGraphSCCPass>`, :ref:`FunctionPass
 <writing-an-llvm-pass-FunctionPass>` , or :ref:`LoopPass
 <writing-an-llvm-pass-LoopPass>`, or :ref:`RegionPass
-<writing-an-llvm-pass-RegionPass>`, or :ref:`BasicBlockPass
-<writing-an-llvm-pass-BasicBlockPass>` classes, which gives the system more
+<writing-an-llvm-pass-RegionPass>` 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 @@ before callers).  Deriving from ``CallGraphSCCPass`` provides some mechanics
 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 <writing-an-llvm-pass-FunctionPass>` or :ref:`BasicBlockPass
-<writing-an-llvm-pass-BasicBlockPass>`, you should derive from
+:ref:`FunctionPass <writing-an-llvm-pass-FunctionPass>`, you should derive from
 ``CallGraphSCCPass``.
 
 ``TODO``: explain briefly what SCC, Tarjan's algo, and B-U mean.
@@ -648,69 +646,6 @@ when the pass framework has finished calling :ref:`runOnRegion
 <writing-an-llvm-pass-runOnRegion>` for every region in the program being
 compiled.
 
-.. _writing-an-llvm-pass-BasicBlockPass:
-
-The ``BasicBlockPass`` class
-----------------------------
-
-``BasicBlockPass``\ es are just like :ref:`FunctionPass's
-<writing-an-llvm-pass-FunctionPass>` , 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
-   <writing-an-llvm-pass-runOnBasicBlock>`.
-#. Modify the control flow graph (by altering terminator instructions)
-#. Any of the things forbidden for :ref:`FunctionPasses
-   <writing-an-llvm-pass-FunctionPass>`.
-
-``BasicBlockPass``\ es are useful for traditional local and "peephole"
-optimizations.  They may override the same :ref:`doInitialization(Module &)
-<writing-an-llvm-pass-doInitialization-mod>` and :ref:`doFinalization(Module &)
-<writing-an-llvm-pass-doFinalization-mod>` methods that :ref:`FunctionPass's
-<writing-an-llvm-pass-FunctionPass>` 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
-<writing-an-llvm-pass-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 @@ certain circumstances that are related to ``addPreserved``.  In particular, the
 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 <writing-an-llvm-pass-BasicBlockPass>`\ es).
+instructions.
 
 ``addPreserved`` is particularly useful for transformations like
 ``BreakCriticalEdges``.  This pass knows how to update a small set of loop and

diff  --git a/llvm/include/llvm/IR/IRPrintingPasses.h b/llvm/include/llvm/IR/IRPrintingPasses.h
index 3be9449c1a93..230db988f737 100644
--- a/llvm/include/llvm/IR/IRPrintingPasses.h
+++ b/llvm/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 @@ ModulePass *createPrintModulePass(raw_ostream &OS,
 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

diff  --git a/llvm/include/llvm/IR/LegacyPassManager.h b/llvm/include/llvm/IR/LegacyPassManager.h
index d6bb79ab6019..2b87143276b9 100644
--- a/llvm/include/llvm/IR/LegacyPassManager.h
+++ b/llvm/include/llvm/IR/LegacyPassManager.h
@@ -63,7 +63,7 @@ class PassManager : public PassManagerBase {
   PassManagerImpl *PM;
 };
 
-/// FunctionPassManager manages FunctionPasses and BasicBlockPassManagers.
+/// FunctionPassManager manages FunctionPasses.
 class FunctionPassManager : public PassManagerBase {
 public:
   /// FunctionPassManager ctor - This initializes the pass manager.  It needs,

diff  --git a/llvm/include/llvm/IR/LegacyPassManagers.h b/llvm/include/llvm/IR/LegacyPassManagers.h
index 72bc80fb5381..5044c1f6ed31 100644
--- a/llvm/include/llvm/IR/LegacyPassManagers.h
+++ b/llvm/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 @@ enum PassDebuggingString {
   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'"

diff  --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h
index b8108339abbf..034d851abcc8 100644
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
@@ -334,7 +334,6 @@ void initializePostRAMachineSinkingPass(PassRegistry&);
 void initializePostRASchedulerPass(PassRegistry&);
 void initializePreISelIntrinsicLoweringLegacyPassPass(PassRegistry&);
 void initializePredicateInfoPrinterLegacyPassPass(PassRegistry&);
-void initializePrintBasicBlockPassPass(PassRegistry&);
 void initializePrintFunctionPassWrapperPass(PassRegistry&);
 void initializePrintModulePassWrapperPass(PassRegistry&);
 void initializeProcessImplicitDefsPass(PassRegistry&);

diff  --git a/llvm/include/llvm/LinkAllPasses.h b/llvm/include/llvm/LinkAllPasses.h
index ac88165845d3..46d8f0c8ed81 100644
--- a/llvm/include/llvm/LinkAllPasses.h
+++ b/llvm/include/llvm/LinkAllPasses.h
@@ -200,7 +200,6 @@ namespace {
       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();

diff  --git a/llvm/include/llvm/Pass.h b/llvm/include/llvm/Pass.h
index 1d53ae32cf37..fce7729f90b1 100644
--- a/llvm/include/llvm/Pass.h
+++ b/llvm/include/llvm/Pass.h
@@ -57,13 +57,11 @@ enum PassManagerType {
   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 @@ class FunctionPass : public Pass {
   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.

diff  --git a/llvm/include/llvm/Transforms/Scalar.h b/llvm/include/llvm/Transforms/Scalar.h
index f06230b6f366..9099d3d06bf3 100644
--- a/llvm/include/llvm/Transforms/Scalar.h
+++ b/llvm/include/llvm/Transforms/Scalar.h
@@ -18,7 +18,6 @@
 
 namespace llvm {
 
-class BasicBlockPass;
 class Function;
 class FunctionPass;
 class ModulePass;
@@ -50,8 +49,7 @@ FunctionPass *createSCCPPass();
 //===----------------------------------------------------------------------===//
 //
 // 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();
 

diff  --git a/llvm/include/llvm/Transforms/Vectorize.h b/llvm/include/llvm/Transforms/Vectorize.h
index 88a0e49d0fae..bca78d073003 100644
--- a/llvm/include/llvm/Transforms/Vectorize.h
+++ b/llvm/include/llvm/Transforms/Vectorize.h
@@ -16,7 +16,6 @@
 
 namespace llvm {
 class BasicBlock;
-class BasicBlockPass;
 class Pass;
 
 //===----------------------------------------------------------------------===//

diff  --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index a5f46b16e600..03bff7e5fde0 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -47,7 +47,6 @@ void llvm::initializeCore(PassRegistry &Registry) {
   initializeDominatorTreeWrapperPassPass(Registry);
   initializePrintModulePassWrapperPass(Registry);
   initializePrintFunctionPassWrapperPass(Registry);
-  initializePrintBasicBlockPassPass(Registry);
   initializeSafepointIRVerifierPass(Registry);
   initializeVerifierLegacyPassPass(Registry);
 }

diff  --git a/llvm/lib/IR/IRPrintingPasses.cpp b/llvm/lib/IR/IRPrintingPasses.cpp
index 953cf9410162..75850b403fbd 100644
--- a/llvm/lib/IR/IRPrintingPasses.cpp
+++ b/llvm/lib/IR/IRPrintingPasses.cpp
@@ -109,28 +109,6 @@ class PrintFunctionPassWrapper : public FunctionPass {
   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 @@ INITIALIZE_PASS(PrintModulePassWrapper, "print-module",
 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 @@ FunctionPass *llvm::createPrintFunctionPass(llvm::raw_ostream &OS,
   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);
 }

diff  --git a/llvm/lib/IR/LegacyPassManager.cpp b/llvm/lib/IR/LegacyPassManager.cpp
index 3a03c493100b..b912fd7e6b8e 100644
--- a/llvm/lib/IR/LegacyPassManager.cpp
+++ b/llvm/lib/IR/LegacyPassManager.cpp
@@ -314,64 +314,6 @@ void PassManagerPrettyStackEntry::print(raw_ostream &OS) const {
   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<BasicBlockPass *>(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 @@ void PMDataManager::dumpPassInfo(Pass *P, enum PassDebuggingString S1,
     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 @@ Pass *AnalysisResolver::findImplPass(Pass *P, AnalysisID AnalysisPI,
   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<std::pair<unsigned, unsigned>> 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<int64_t>(NewSize) - static_cast<int64_t>(BBSize);
-            emitInstrCountChangedRemark(BP, M, Delta, InstrCount,
-                                        FunctionToInstrCount, &F);
-            InstrCount = static_cast<int64_t>(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 @@ void FunctionPass::assignPassManager(PMStack &PMS,
   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() {}

diff  --git a/llvm/lib/IR/Pass.cpp b/llvm/lib/IR/Pass.cpp
index 699a7e17c0cb..dbdbbf4cf35e 100644
--- a/llvm/lib/IR/Pass.cpp
+++ b/llvm/lib/IR/Pass.cpp
@@ -176,51 +176,6 @@ bool FunctionPass::skipFunction(const Function &F) const {
   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);
 }

diff  --git a/llvm/tools/bugpoint-passes/TestPasses.cpp b/llvm/tools/bugpoint-passes/TestPasses.cpp
index d11a605fa88e..6667cbe9255e 100644
--- a/llvm/tools/bugpoint-passes/TestPasses.cpp
+++ b/llvm/tools/bugpoint-passes/TestPasses.cpp
@@ -25,25 +25,27 @@ using namespace llvm::PatternMatch;
 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();
-    }
+/// CrashOnCalls - This pass is used to test bugpoint.  It intentionally
+/// crashes on any call instructions.
+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<CallInst>(*I))
           abort();
 
-      return false;
-    }
-  };
+    return false;
+  }
+};
 }
 
 char CrashOnCalls::ID = 0;
@@ -52,14 +54,16 @@ static RegisterPass<CrashOnCalls>
     "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<CallInst>(I)) {
           if (!CI->use_empty())
@@ -67,9 +71,9 @@ namespace {
           CI->getParent()->getInstList().erase(CI);
           break;
         }
-      return false;
-    }
-  };
+    return false;
+  }
+};
 }
 
 char DeleteCalls::ID = 0;

diff  --git a/llvm/tools/opt/PassPrinters.cpp b/llvm/tools/opt/PassPrinters.cpp
index 70da6a43f8d9..a877d9dc90f4 100644
--- a/llvm/tools/opt/PassPrinters.cpp
+++ b/llvm/tools/opt/PassPrinters.cpp
@@ -198,40 +198,6 @@ struct RegionPassPrinter : public RegionPass {
 
 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<Pass>(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 @@ RegionPass *llvm::createRegionPassPrinter(const PassInfo *PI, raw_ostream &OS,
   return new RegionPassPrinter(PI, OS, Quiet);
 }
 
-BasicBlockPass *llvm::createBasicBlockPassPrinter(const PassInfo *PI,
-                                                  raw_ostream &OS, bool Quiet) {
-  return new BasicBlockPassPrinter(PI, OS, Quiet);
-}

diff  --git a/llvm/tools/opt/PassPrinters.h b/llvm/tools/opt/PassPrinters.h
index d4e7a4a97f31..692befbdae75 100644
--- a/llvm/tools/opt/PassPrinters.h
+++ b/llvm/tools/opt/PassPrinters.h
@@ -18,7 +18,6 @@
 
 namespace llvm {
 
-class BasicBlockPass;
 class CallGraphSCCPass;
 class FunctionPass;
 class ModulePass;
@@ -43,9 +42,6 @@ LoopPass *createLoopPassPrinter(const PassInfo *PI, raw_ostream &out,
 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

diff  --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp
index 15495a511d06..433f5f22d8d5 100644
--- a/llvm/tools/opt/opt.cpp
+++ b/llvm/tools/opt/opt.cpp
@@ -328,7 +328,7 @@ class OptCustomPassManager : public legacy::PassManager {
     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 @@ int main(int argc, char **argv) {
 
       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;

diff  --git a/llvm/unittests/IR/LegacyPassManagerTest.cpp b/llvm/unittests/IR/LegacyPassManagerTest.cpp
index 6c0c251aff9f..1ce7fa0bd0e8 100644
--- a/llvm/unittests/IR/LegacyPassManagerTest.cpp
+++ b/llvm/unittests/IR/LegacyPassManagerTest.cpp
@@ -38,7 +38,6 @@ namespace llvm {
   void initializeFPassPass(PassRegistry&);
   void initializeCGPassPass(PassRegistry&);
   void initializeLPassPass(PassRegistry&);
-  void initializeBPassPass(PassRegistry&);
 
   namespace {
     // ND = no deps
@@ -219,47 +218,6 @@ namespace llvm {
     int LPass::initcount=0;
     int LPass::fincount=0;
 
-    struct BPass : public PassTestBase<BasicBlockPass> {
-    private:
-      static int inited;
-      static int fin;
-    public:
-      static void finishedOK(int run, int N) {
-        PassTestBase<BasicBlockPass>::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 @@ namespace llvm {
         SCOPED_TRACE("Loop pass");
         MemoryTestHelper<LPass>(2, 1); //2 loops, 1 function
       }
-      {
-        SCOPED_TRACE("Basic block pass");
-        MemoryTestHelper<BPass>(7, 4); //9 basic blocks
-      }
 
     }
 
@@ -616,4 +570,3 @@ INITIALIZE_PASS(FPass, "fp","fp", false, false)
 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)


        


More information about the llvm-commits mailing list