diff --git a/include/llvm/InitializePasses.h b/include/llvm/InitializePasses.h index 7c262f8d647..ba4915ac438 100644 --- a/include/llvm/InitializePasses.h +++ b/include/llvm/InitializePasses.h @@ -1,4 +1,4 @@ -//===- llvm/InitializePasses.h -------- Initialize All Passes ---*- C++ -*-===// +//===- llvm/InitializePasses.h - Initialize All Passes ----------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -377,6 +377,7 @@ void initializeWinEHPreparePass(PassRegistry&); void initializeWriteBitcodePassPass(PassRegistry&); void initializeWriteThinLTOBitcodePass(PassRegistry&); void initializeXRayInstrumentationPass(PassRegistry&); -} -#endif +} // end namespace llvm + +#endif // LLVM_INITIALIZEPASSES_H diff --git a/include/llvm/Pass.h b/include/llvm/Pass.h index 2dd6935cf01..ff641170350 100644 --- a/include/llvm/Pass.h +++ b/include/llvm/Pass.h @@ -29,24 +29,24 @@ #ifndef LLVM_PASS_H #define LLVM_PASS_H +#include "llvm/ADT/StringRef.h" #include namespace llvm { +class AnalysisResolver; +class AnalysisUsage; class BasicBlock; class Function; -class Module; -class AnalysisUsage; -class PassInfo; class ImmutablePass; -class PMStack; -class AnalysisResolver; +class Module; +class PassInfo; class PMDataManager; +class PMStack; class raw_ostream; -class StringRef; // AnalysisID - Use the PassInfo to identify a pass... -typedef const void* AnalysisID; +using AnalysisID = const void *; /// Different types of internal pass managers. External pass managers /// (PassManager and FunctionPassManager) are not represented here. @@ -79,24 +79,21 @@ enum PassKind { /// constrained passes described below. /// class Pass { - AnalysisResolver *Resolver; // Used to resolve analysis + AnalysisResolver *Resolver = nullptr; // Used to resolve analysis const void *PassID; PassKind Kind; - void operator=(const Pass&) = delete; - Pass(const Pass &) = delete; public: - explicit Pass(PassKind K, char &pid) - : Resolver(nullptr), PassID(&pid), Kind(K) { } + explicit Pass(PassKind K, char &pid) : PassID(&pid), Kind(K) {} + Pass(const Pass &) = delete; + Pass &operator=(const Pass &) = delete; virtual ~Pass(); - PassKind getPassKind() const { return Kind; } /// getPassName - Return a nice clean name for a pass. This usually /// implemented in terms of the name that is registered by one of the /// Registration templates, but can be overloaded directly. - /// virtual StringRef getPassName() const; /// getPassID - Return the PassID number that corresponds to this pass. @@ -106,12 +103,10 @@ public: /// doInitialization - Virtual method overridden by subclasses to do /// any necessary initialization before any pass is run. - /// virtual bool doInitialization(Module &) { return false; } /// doFinalization - Virtual method overriden by subclasses to do any /// necessary clean up after all passes have run. - /// virtual bool doFinalization(Module &) { return false; } /// print - Print out the internal state of the pass. This is called by @@ -120,19 +115,20 @@ public: /// null. This automatically forwards to a virtual function that does not /// provide the Module* in case the analysis doesn't need it it can just be /// ignored. - /// - virtual void print(raw_ostream &O, const Module *M) const; + virtual void print(raw_ostream &OS, const Module *M) const; + void dump() const; // dump - Print to stderr. /// createPrinterPass - Get a Pass appropriate to print the IR this /// pass operates on (Module, Function or MachineFunction). - virtual Pass *createPrinterPass(raw_ostream &O, + virtual Pass *createPrinterPass(raw_ostream &OS, const std::string &Banner) const = 0; /// Each pass is responsible for assigning a pass manager to itself. /// PMS is the stack of available pass manager. virtual void assignPassManager(PMStack &, PassManagerType) {} + /// Check if available pass managers are suitable for this pass or not. virtual void preparePassManager(PMStack &); @@ -147,7 +143,6 @@ public: /// analysis information to do their job. If a pass specifies that it uses a /// particular analysis result to this function, it can then use the /// getAnalysis() function, below. - /// virtual void getAnalysisUsage(AnalysisUsage &) const; /// releaseMemory() - This member can be implemented by a pass if it wants to @@ -160,7 +155,6 @@ public: /// /// Optionally implement this function to release pass memory when it is no /// longer used. - /// virtual void releaseMemory(); /// getAdjustedAnalysisPointer - This method is used when a pass implements @@ -197,7 +191,6 @@ public: /// the case when the analysis is not available. This method is often used by /// transformation APIs to update analysis results for a pass automatically as /// the transform is performed. - /// template AnalysisType * getAnalysisIfAvailable() const; // Defined in PassAnalysisSupport.h @@ -206,13 +199,11 @@ public: /// obviously cannot give you a properly typed instance of the class if you /// don't have the class name available (use getAnalysisIfAvailable if you /// do), but it can tell you if you need to preserve the pass at least. - /// bool mustPreserveAnalysisID(char &AID) const; /// getAnalysis() - This function is used by subclasses to get /// to the analysis information that they claim to use by overriding the /// getAnalysisUsage function. - /// template AnalysisType &getAnalysis() const; // Defined in PassAnalysisSupport.h @@ -226,7 +217,6 @@ public: AnalysisType &getAnalysisID(AnalysisID PI, Function &F); }; - //===----------------------------------------------------------------------===// /// ModulePass class - This class is used to implement unstructured /// interprocedural optimizations and analyses. ModulePasses may do anything @@ -234,8 +224,13 @@ public: /// class ModulePass : public Pass { public: + explicit ModulePass(char &pid) : Pass(PT_Module, pid) {} + + // Force out-of-line virtual method. + ~ModulePass() override; + /// createPrinterPass - Get a module printer pass. - Pass *createPrinterPass(raw_ostream &O, + Pass *createPrinterPass(raw_ostream &OS, const std::string &Banner) const override; /// runOnModule - Virtual method overriden by subclasses to process the module @@ -247,17 +242,12 @@ public: /// Return what kind of Pass Manager can manage this pass. PassManagerType getPotentialPassManagerType() const override; - explicit ModulePass(char &pid) : Pass(PT_Module, pid) {} - // Force out-of-line virtual method. - ~ModulePass() override; - protected: /// Optional passes call this function to check whether the pass should be /// skipped. This is the case when optimization bisect is over the limit. bool skipModule(Module &M) const; }; - //===----------------------------------------------------------------------===// /// ImmutablePass class - This class is used to provide information that does /// not need to be run. This is useful for things like target information and @@ -265,25 +255,22 @@ protected: /// class ImmutablePass : public ModulePass { public: + explicit ImmutablePass(char &pid) : ModulePass(pid) {} + + // Force out-of-line virtual method. + ~ImmutablePass() override; + /// initializePass - This method may be overriden by immutable passes to allow /// them to perform various initialization actions they require. This is /// primarily because an ImmutablePass can "require" another ImmutablePass, /// and if it does, the overloaded version of initializePass may get access to /// these passes with getAnalysis<>. - /// virtual void initializePass(); ImmutablePass *getAsImmutablePass() override { return this; } /// ImmutablePasses are never run. - /// bool runOnModule(Module &) override { return false; } - - explicit ImmutablePass(char &pid) - : ModulePass(pid) {} - - // Force out-of-line virtual method. - ~ImmutablePass() override; }; //===----------------------------------------------------------------------===// @@ -300,12 +287,11 @@ public: explicit FunctionPass(char &pid) : Pass(PT_Function, pid) {} /// createPrinterPass - Get a function printer pass. - Pass *createPrinterPass(raw_ostream &O, + Pass *createPrinterPass(raw_ostream &OS, const std::string &Banner) const override; /// runOnFunction - Virtual method overriden by subclasses to do the /// per-function processing of the pass. - /// virtual bool runOnFunction(Function &F) = 0; void assignPassManager(PMStack &PMS, PassManagerType T) override; @@ -320,8 +306,6 @@ protected: bool skipFunction(const Function &F) const; }; - - //===----------------------------------------------------------------------===// /// BasicBlockPass class - This class is used to implement most local /// optimizations. Optimizations should subclass this class if they @@ -337,7 +321,7 @@ public: explicit BasicBlockPass(char &pid) : Pass(PT_BasicBlock, pid) {} /// createPrinterPass - Get a basic block printer pass. - Pass *createPrinterPass(raw_ostream &O, + Pass *createPrinterPass(raw_ostream &OS, const std::string &Banner) const override; using llvm::Pass::doInitialization; @@ -345,17 +329,14 @@ public: /// 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 assignPassManager(PMStack &PMS, PassManagerType T) override; @@ -379,12 +360,13 @@ extern bool TimePassesIsEnabled; // debugging options like -print-after-all/-print-before-all. // @brief Tells if the function IR should be printed by PrinterPass. extern bool isFunctionInPrintList(StringRef FunctionName); -} // End llvm namespace + +} // end namespace llvm // Include support files that contain important APIs commonly used by Passes, // but that we want to separate out to make it easier to read the header files. -// +#include "llvm/InitializePasses.h" #include "llvm/PassAnalysisSupport.h" #include "llvm/PassSupport.h" -#endif +#endif // LLVM_PASS_H diff --git a/include/llvm/PassAnalysisSupport.h b/include/llvm/PassAnalysisSupport.h index abd99293805..ba988485c40 100644 --- a/include/llvm/PassAnalysisSupport.h +++ b/include/llvm/PassAnalysisSupport.h @@ -20,11 +20,16 @@ #define LLVM_PASSANALYSISSUPPORT_H #include "llvm/ADT/SmallVector.h" -#include "llvm/Pass.h" +#include "llvm/ADT/StringRef.h" +#include +#include #include namespace llvm { -class StringRef; + +class Function; +class Pass; +class PMDataManager; //===----------------------------------------------------------------------===// /// Represent the analysis usage information of a pass. This tracks analyses @@ -36,7 +41,7 @@ class StringRef; /// class AnalysisUsage { public: - typedef SmallVectorImpl VectorType; + using VectorType = SmallVectorImpl; private: /// Sets of analyses required and preserved by a pass @@ -47,10 +52,10 @@ private: SmallVector RequiredTransitive; SmallVector Preserved; SmallVector Used; - bool PreservesAll; + bool PreservesAll = false; public: - AnalysisUsage() : PreservesAll(false) {} + AnalysisUsage() = default; ///@{ /// Add the specified ID to the required set of the usage info for a pass. @@ -124,7 +129,6 @@ public: /// /// This function annotates the AnalysisUsage info object to say that analyses /// that only depend on the CFG are preserved by this pass. - /// void setPreservesCFG(); const VectorType &getRequiredSet() const { return Required; } @@ -140,15 +144,12 @@ public: /// analysis information out of pass manager that is responsible to manage /// the pass. /// -class PMDataManager; class AnalysisResolver { -private: - AnalysisResolver() = delete; - public: - explicit AnalysisResolver(PMDataManager &P) : PM(P) { } + AnalysisResolver() = delete; + explicit AnalysisResolver(PMDataManager &P) : PM(P) {} - inline PMDataManager &getPMDataManager() { return PM; } + PMDataManager &getPMDataManager() { return PM; } /// Find pass that is implementing PI. Pass *findImplPass(AnalysisID PI) { @@ -183,7 +184,7 @@ public: private: /// This keeps track of which passes implements the interfaces that are /// required by the current pass (to implement getAnalysis()). - std::vector > AnalysisImpls; + std::vector> AnalysisImpls; /// PassManager that is used to resolve analysis info PMDataManager &PM; @@ -196,7 +197,6 @@ private: /// the case when the analysis is not available. This method is often used by /// transformation APIs to update analysis results for a pass automatically as /// the transform is performed. -/// template AnalysisType *Pass::getAnalysisIfAvailable() const { assert(Resolver && "Pass not resident in a PassManager object!"); @@ -216,7 +216,6 @@ AnalysisType *Pass::getAnalysisIfAvailable() const { /// getAnalysis() - This function is used by subclasses to get /// to the analysis information that they claim to use by overriding the /// getAnalysisUsage function. -/// template AnalysisType &Pass::getAnalysis() const { assert(Resolver && "Pass has not been inserted into a PassManager object!"); @@ -231,9 +230,9 @@ AnalysisType &Pass::getAnalysisID(AnalysisID PI) const { // should be a small number, we just do a linear search over a (dense) // vector. Pass *ResultPass = Resolver->findImplPass(PI); - assert (ResultPass && - "getAnalysis*() called on an analysis that was not " - "'required' by pass!"); + assert(ResultPass && + "getAnalysis*() called on an analysis that was not " + "'required' by pass!"); // Because the AnalysisType may not be a subclass of pass (for // AnalysisGroups), we use getAdjustedAnalysisPointer here to potentially @@ -245,7 +244,6 @@ AnalysisType &Pass::getAnalysisID(AnalysisID PI) const { /// getAnalysis() - This function is used by subclasses to get /// to the analysis information that they claim to use by overriding the /// getAnalysisUsage function. -/// template AnalysisType &Pass::getAnalysis(Function &F) { assert(Resolver &&"Pass has not been inserted into a PassManager object!"); @@ -270,6 +268,6 @@ AnalysisType &Pass::getAnalysisID(AnalysisID PI, Function &F) { return *(AnalysisType*)ResultPass->getAdjustedAnalysisPointer(PI); } -} // End llvm namespace +} // end namespace llvm -#endif +#endif // LLVM_PASSANALYSISSUPPORT_H diff --git a/include/llvm/PassInfo.h b/include/llvm/PassInfo.h index 81dface3c9a..2f1ab4d4337 100644 --- a/include/llvm/PassInfo.h +++ b/include/llvm/PassInfo.h @@ -10,18 +10,17 @@ // This file defines and implements the PassInfo class. // //===----------------------------------------------------------------------===// + #ifndef LLVM_PASSINFO_H #define LLVM_PASSINFO_H #include "llvm/ADT/StringRef.h" - #include #include namespace llvm { class Pass; -class TargetMachine; //===--------------------------------------------------------------------------- /// PassInfo class - An instance of this class exists for every pass known by @@ -31,18 +30,17 @@ class TargetMachine; /// class PassInfo { public: - typedef Pass* (*NormalCtor_t)(); + using NormalCtor_t = Pass* (*)(); private: StringRef PassName; // Nice name for Pass StringRef PassArgument; // Command Line argument to run this pass const void *PassID; - const bool IsCFGOnlyPass; // Pass only looks at the CFG. + const bool IsCFGOnlyPass = false; // Pass only looks at the CFG. const bool IsAnalysis; // True if an analysis pass. const bool IsAnalysisGroup; // True if an analysis group. std::vector ItfImpl; // Interfaces implemented by this pass - - NormalCtor_t NormalCtor; + NormalCtor_t NormalCtor = nullptr; public: /// PassInfo ctor - Do not call this directly, this should only be invoked @@ -51,21 +49,22 @@ public: bool isCFGOnly, bool is_analysis) : PassName(name), PassArgument(arg), PassID(pi), IsCFGOnlyPass(isCFGOnly), IsAnalysis(is_analysis), IsAnalysisGroup(false), NormalCtor(normal) {} + /// PassInfo ctor - Do not call this directly, this should only be invoked /// through RegisterPass. This version is for use by analysis groups; it /// does not auto-register the pass. PassInfo(StringRef name, const void *pi) - : PassName(name), PassArgument(""), PassID(pi), IsCFGOnlyPass(false), - IsAnalysis(false), IsAnalysisGroup(true), NormalCtor(nullptr) {} + : PassName(name), PassID(pi), IsAnalysis(false), IsAnalysisGroup(true) {} + + PassInfo(const PassInfo &) = delete; + PassInfo &operator=(const PassInfo &) = delete; /// getPassName - Return the friendly name for the pass, never returns null - /// StringRef getPassName() const { return PassName; } /// getPassArgument - Return the command line option that may be passed to /// 'opt' that will cause this pass to be run. This will return null if there /// is no argument. - /// StringRef getPassArgument() const { return PassArgument; } /// getTypeInfo - Return the id object for the pass... @@ -77,7 +76,6 @@ public: /// isAnalysisGroup - Return true if this is an analysis group, not a normal /// pass. - /// bool isAnalysisGroup() const { return IsAnalysisGroup; } bool isAnalysis() const { return IsAnalysis; } @@ -88,7 +86,6 @@ public: /// getNormalCtor - Return a pointer to a function, that when called, creates /// an instance of the pass and returns it. This pointer may be null if there /// is no default constructor for the pass. - /// NormalCtor_t getNormalCtor() const { return NormalCtor; } @@ -108,23 +105,17 @@ public: /// addInterfaceImplemented - This method is called when this pass is /// registered as a member of an analysis group with the RegisterAnalysisGroup /// template. - /// void addInterfaceImplemented(const PassInfo *ItfPI) { ItfImpl.push_back(ItfPI); } /// getInterfacesImplemented - Return a list of all of the analysis group /// interfaces implemented by this pass. - /// const std::vector &getInterfacesImplemented() const { return ItfImpl; } - -private: - void operator=(const PassInfo &) = delete; - PassInfo(const PassInfo &) = delete; }; -} +} // end namespace llvm -#endif +#endif // LLVM_PASSINFO_H diff --git a/include/llvm/PassRegistry.h b/include/llvm/PassRegistry.h index 4bb19675585..93edc12bdc7 100644 --- a/include/llvm/PassRegistry.h +++ b/include/llvm/PassRegistry.h @@ -18,16 +18,15 @@ #define LLVM_PASSREGISTRY_H #include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/StringMap.h" -#include "llvm/PassInfo.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Support/CBindingWrapping.h" #include "llvm/Support/RWMutex.h" +#include #include namespace llvm { -class StringRef; class PassInfo; struct PassRegistrationListener; @@ -41,17 +40,17 @@ class PassRegistry { mutable sys::SmartRWMutex Lock; /// PassInfoMap - Keep track of the PassInfo object for each registered pass. - typedef DenseMap MapType; + using MapType = DenseMap; MapType PassInfoMap; - typedef StringMap StringMapType; + using StringMapType = StringMap; StringMapType PassInfoStringMap; std::vector> ToFree; std::vector Listeners; public: - PassRegistry() {} + PassRegistry() = default; ~PassRegistry(); /// getPassRegistry - Access the global registry object, which is @@ -94,6 +93,6 @@ public: // Create wrappers for C Binding types (see CBindingWrapping.h). DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry, LLVMPassRegistryRef) -} +} // end namespace llvm -#endif +#endif // LLVM_PASSREGISTRY_H diff --git a/include/llvm/PassSupport.h b/include/llvm/PassSupport.h index 602f45ac517..1bf23dcba50 100644 --- a/include/llvm/PassSupport.h +++ b/include/llvm/PassSupport.h @@ -21,16 +21,16 @@ #ifndef LLVM_PASSSUPPORT_H #define LLVM_PASSSUPPORT_H -#include "Pass.h" -#include "llvm/InitializePasses.h" +#include "llvm/ADT/StringRef.h" #include "llvm/PassInfo.h" #include "llvm/PassRegistry.h" -#include "llvm/Support/Atomic.h" #include "llvm/Support/Threading.h" #include namespace llvm { +class Pass; + #define INITIALIZE_PASS(passName, arg, name, cfg, analysis) \ static void *initialize##passName##PassOnce(PassRegistry &Registry) { \ PassInfo *PI = new PassInfo( \ @@ -88,7 +88,6 @@ template Pass *callDefaultCtor() { return new PassName(); } /// /// This statement will cause your pass to be created by calling the default /// constructor exposed by the pass. -/// template struct RegisterPass : public PassInfo { // Register Pass using default constructor... RegisterPass(StringRef PassArg, StringRef Name, bool CFGOnly = false, @@ -118,7 +117,6 @@ template struct RegisterPass : public PassInfo { /// The actual interface may also be registered as well (by not specifying the /// second template argument). The interface should be registered to associate /// a nice name with the interface. -/// class RegisterAGBase : public PassInfo { public: RegisterAGBase(StringRef Name, const void *InterfaceID, @@ -196,27 +194,23 @@ struct RegisterAnalysisGroup : public RegisterAGBase { /// at runtime (which can be because of the RegisterPass constructors being run /// as the program starts up, or may be because a shared object just got /// loaded). -/// struct PassRegistrationListener { - PassRegistrationListener() {} - virtual ~PassRegistrationListener() {} + PassRegistrationListener() = default; + virtual ~PassRegistrationListener() = default; /// Callback functions - These functions are invoked whenever a pass is loaded /// or removed from the current executable. - /// virtual void passRegistered(const PassInfo *) {} /// enumeratePasses - Iterate over the registered passes, calling the /// passEnumerate callback on each PassInfo object. - /// void enumeratePasses(); /// passEnumerate - Callback function invoked when someone calls /// enumeratePasses on this PassRegistrationListener object. - /// virtual void passEnumerate(const PassInfo *) {} }; -} // End llvm namespace +} // end namespace llvm -#endif +#endif // LLVM_PASSSUPPORT_H diff --git a/lib/IR/Pass.cpp b/lib/IR/Pass.cpp index f1b5f2f108d..5e0b59476c4 100644 --- a/lib/IR/Pass.cpp +++ b/lib/IR/Pass.cpp @@ -14,14 +14,22 @@ //===----------------------------------------------------------------------===// #include "llvm/Pass.h" +#include "llvm/IR/Attributes.h" +#include "llvm/IR/BasicBlock.h" #include "llvm/IR/Function.h" #include "llvm/IR/IRPrintingPasses.h" +#include "llvm/IR/LLVMContext.h" #include "llvm/IR/LegacyPassNameParser.h" #include "llvm/IR/Module.h" #include "llvm/IR/OptBisect.h" +#include "llvm/PassInfo.h" #include "llvm/PassRegistry.h" +#include "llvm/PassSupport.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" +#include + using namespace llvm; #define DEBUG_TYPE "ir" @@ -36,11 +44,11 @@ Pass::~Pass() { } // Force out-of-line virtual method. -ModulePass::~ModulePass() { } +ModulePass::~ModulePass() = default; -Pass *ModulePass::createPrinterPass(raw_ostream &O, +Pass *ModulePass::createPrinterPass(raw_ostream &OS, const std::string &Banner) const { - return createPrintModulePass(O, Banner); + return createPrintModulePass(OS, Banner); } PassManagerType ModulePass::getPotentialPassManagerType() const { @@ -63,7 +71,6 @@ void Pass::dumpPassStructure(unsigned Offset) { /// getPassName - Return a nice clean name for a pass. This usually /// implemented in terms of the name that is registered by one of the /// Registration templates, but can be overloaded directly. -/// StringRef Pass::getPassName() const { AnalysisID AID = getPassID(); const PassInfo *PI = PassRegistry::getPassRegistry()->getPassInfo(AID); @@ -113,9 +120,8 @@ void Pass::setResolver(AnalysisResolver *AR) { // print - Print out the internal state of the pass. This is called by Analyze // to print out the contents of an analysis. Otherwise it is not necessary to // implement this method. -// -void Pass::print(raw_ostream &O,const Module*) const { - O << "Pass::print not implemented for pass: '" << getPassName() << "'!\n"; +void Pass::print(raw_ostream &OS, const Module *) const { + OS << "Pass::print not implemented for pass: '" << getPassName() << "'!\n"; } #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) @@ -129,7 +135,7 @@ LLVM_DUMP_METHOD void Pass::dump() const { // ImmutablePass Implementation // // Force out-of-line virtual method. -ImmutablePass::~ImmutablePass() { } +ImmutablePass::~ImmutablePass() = default; void ImmutablePass::initializePass() { // By default, don't do anything. @@ -139,9 +145,9 @@ void ImmutablePass::initializePass() { // FunctionPass Implementation // -Pass *FunctionPass::createPrinterPass(raw_ostream &O, +Pass *FunctionPass::createPrinterPass(raw_ostream &OS, const std::string &Banner) const { - return createPrintFunctionPass(O, Banner); + return createPrintFunctionPass(OS, Banner); } PassManagerType FunctionPass::getPotentialPassManagerType() const { @@ -164,9 +170,9 @@ bool FunctionPass::skipFunction(const Function &F) const { // BasicBlockPass Implementation // -Pass *BasicBlockPass::createPrinterPass(raw_ostream &O, +Pass *BasicBlockPass::createPrinterPass(raw_ostream &OS, const std::string &Banner) const { - return createPrintBasicBlockPass(O, Banner); + return createPrintBasicBlockPass(OS, Banner); } bool BasicBlockPass::doInitialization(Function &) { @@ -219,7 +225,7 @@ Pass *Pass::createPass(AnalysisID ID) { //===----------------------------------------------------------------------===// // RegisterAGBase implementation -// + RegisterAGBase::RegisterAGBase(StringRef Name, const void *InterfaceID, const void *PassID, bool isDefault) : PassInfo(Name, InterfaceID) { @@ -233,7 +239,6 @@ RegisterAGBase::RegisterAGBase(StringRef Name, const void *InterfaceID, // enumeratePasses - Iterate over the registered passes, calling the // passEnumerate callback on each PassInfo object. -// void PassRegistrationListener::enumeratePasses() { PassRegistry::getPassRegistry()->enumerateWith(this); } @@ -243,28 +248,31 @@ PassNameParser::PassNameParser(cl::Option &O) PassRegistry::getPassRegistry()->addRegistrationListener(this); } -PassNameParser::~PassNameParser() { - // This only gets called during static destruction, in which case the - // PassRegistry will have already been destroyed by llvm_shutdown(). So - // attempting to remove the registration listener is an error. -} +// This only gets called during static destruction, in which case the +// PassRegistry will have already been destroyed by llvm_shutdown(). So +// attempting to remove the registration listener is an error. +PassNameParser::~PassNameParser() = default; //===----------------------------------------------------------------------===// // AnalysisUsage Class Implementation // namespace { - struct GetCFGOnlyPasses : public PassRegistrationListener { - typedef AnalysisUsage::VectorType VectorType; - VectorType &CFGOnlyList; - GetCFGOnlyPasses(VectorType &L) : CFGOnlyList(L) {} - void passEnumerate(const PassInfo *P) override { - if (P->isCFGOnlyPass()) - CFGOnlyList.push_back(P->getTypeInfo()); - } - }; -} +struct GetCFGOnlyPasses : public PassRegistrationListener { + using VectorType = AnalysisUsage::VectorType; + + VectorType &CFGOnlyList; + + GetCFGOnlyPasses(VectorType &L) : CFGOnlyList(L) {} + + void passEnumerate(const PassInfo *P) override { + if (P->isCFGOnlyPass()) + CFGOnlyList.push_back(P->getTypeInfo()); + } +}; + +} // end anonymous namespace // setPreservesCFG - This function should be called to by the pass, iff they do // not: @@ -274,7 +282,6 @@ namespace { // // This function annotates the AnalysisUsage info object to say that analyses // that only depend on the CFG are preserved by this pass. -// void AnalysisUsage::setPreservesCFG() { // Since this transformation doesn't modify the CFG, it preserves all analyses // that only depend on the CFG (like dominators, loop info, etc...) diff --git a/lib/IR/PassRegistry.cpp b/lib/IR/PassRegistry.cpp index c0f6f07169f..b0f1a992872 100644 --- a/lib/IR/PassRegistry.cpp +++ b/lib/IR/PassRegistry.cpp @@ -14,8 +14,12 @@ #include "llvm/PassRegistry.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/PassInfo.h" #include "llvm/PassSupport.h" #include "llvm/Support/ManagedStatic.h" +#include +#include +#include using namespace llvm; @@ -33,7 +37,7 @@ PassRegistry *PassRegistry::getPassRegistry() { // Accessors // -PassRegistry::~PassRegistry() {} +PassRegistry::~PassRegistry() = default; const PassInfo *PassRegistry::getPassInfo(const void *TI) const { sys::SmartScopedReader Guard(Lock); @@ -120,6 +124,6 @@ void PassRegistry::addRegistrationListener(PassRegistrationListener *L) { void PassRegistry::removeRegistrationListener(PassRegistrationListener *L) { sys::SmartScopedWriter Guard(Lock); - auto I = find(Listeners, L); + auto I = llvm::find(Listeners, L); Listeners.erase(I); }