diff --git a/include/llvm/Analysis/CGSCCPassManager.h b/include/llvm/Analysis/CGSCCPassManager.h index 1533b36f24c..7ddaf05604b 100644 --- a/include/llvm/Analysis/CGSCCPassManager.h +++ b/include/llvm/Analysis/CGSCCPassManager.h @@ -40,7 +40,7 @@ public: } /// \brief Run all of the CGSCC passes in this pass manager over a SCC. - PreservedAnalyses run(LazyCallGraph::SCC *C, + PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager *AM = nullptr); template void addPass(CGSCCPassT Pass) { @@ -51,13 +51,13 @@ public: private: // Pull in the concept type and model template specialized for SCCs. - typedef detail::PassConcept + typedef detail::PassConcept CGSCCPassConcept; template struct CGSCCPassModel - : detail::PassModel { + : detail::PassModel { CGSCCPassModel(PassT Pass) - : detail::PassModel( + : detail::PassModel( std::move(Pass)) {} }; @@ -70,11 +70,11 @@ private: /// \brief A function analysis manager to coordinate and cache analyses run over /// a module. class CGSCCAnalysisManager : public detail::AnalysisManagerBase< - CGSCCAnalysisManager, LazyCallGraph::SCC *> { + CGSCCAnalysisManager, LazyCallGraph::SCC &> { friend class detail::AnalysisManagerBase; + LazyCallGraph::SCC &>; typedef detail::AnalysisManagerBase BaseT; + LazyCallGraph::SCC &> BaseT; typedef BaseT::ResultConceptT ResultConceptT; typedef BaseT::PassConceptT PassConceptT; @@ -110,17 +110,17 @@ private: operator=(const CGSCCAnalysisManager &) LLVM_DELETED_FUNCTION; /// \brief Get a function pass result, running the pass if necessary. - ResultConceptT &getResultImpl(void *PassID, LazyCallGraph::SCC *C); + ResultConceptT &getResultImpl(void *PassID, LazyCallGraph::SCC &C); /// \brief Get a cached function pass result or return null. ResultConceptT *getCachedResultImpl(void *PassID, - LazyCallGraph::SCC *C) const; + LazyCallGraph::SCC &C) const; /// \brief Invalidate a function pass result. - void invalidateImpl(void *PassID, LazyCallGraph::SCC *C); + void invalidateImpl(void *PassID, LazyCallGraph::SCC &C); /// \brief Invalidate the results for a function.. - void invalidateImpl(LazyCallGraph::SCC *C, const PreservedAnalyses &PA); + void invalidateImpl(LazyCallGraph::SCC &C, const PreservedAnalyses &PA); /// \brief List of function analysis pass IDs and associated concept pointers. /// @@ -129,7 +129,7 @@ private: /// half of a bijection and provides storage for the actual result concept. typedef std::list< std::pair>>> CGSCCAnalysisResultListT; + LazyCallGraph::SCC &>>>> CGSCCAnalysisResultListT; /// \brief Map type from function pointer to our custom list type. typedef DenseMap @@ -187,7 +187,7 @@ public: /// Regardless of whether this analysis is marked as preserved, all of the /// analyses in the \c CGSCCAnalysisManager are potentially invalidated /// based on the set of preserved analyses. - bool invalidate(Module *M, const PreservedAnalyses &PA); + bool invalidate(Module &M, const PreservedAnalyses &PA); private: CGSCCAnalysisManager *CGAM; @@ -219,7 +219,7 @@ public: /// In debug builds, it will also assert that the analysis manager is empty /// as no queries should arrive at the CGSCC analysis manager prior to /// this analysis being requested. - Result run(Module *M); + Result run(Module &M); private: static char PassID; @@ -257,7 +257,7 @@ public: const ModuleAnalysisManager &getManager() const { return *MAM; } /// \brief Handle invalidation by ignoring it, this pass is immutable. - bool invalidate(LazyCallGraph::SCC *) { return false; } + bool invalidate(LazyCallGraph::SCC &) { return false; } private: const ModuleAnalysisManager *MAM; @@ -283,7 +283,7 @@ public: /// \brief Run the analysis pass and create our proxy result object. /// Nothing to see here, it just forwards the \c MAM reference into the /// result. - Result run(LazyCallGraph::SCC *) { return Result(*MAM); } + Result run(LazyCallGraph::SCC &) { return Result(*MAM); } private: static char PassID; @@ -323,7 +323,7 @@ public: } /// \brief Runs the CGSCC pass across every SCC in the module. - PreservedAnalyses run(Module *M, ModuleAnalysisManager *AM) { + PreservedAnalyses run(Module &M, ModuleAnalysisManager *AM) { assert(AM && "We need analyses to compute the call graph!"); // Setup the CGSCC analysis manager from its proxy. @@ -335,7 +335,7 @@ public: PreservedAnalyses PA = PreservedAnalyses::all(); for (LazyCallGraph::SCC &C : CG.postorder_sccs()) { - PreservedAnalyses PassPA = Pass.run(&C, &CGAM); + PreservedAnalyses PassPA = Pass.run(C, &CGAM); // We know that the CGSCC pass couldn't have invalidated any other // SCC's analyses (that's the contract of a CGSCC pass), so @@ -343,7 +343,7 @@ public: // FIXME: This isn't quite correct. We need to handle the case where the // pass updated the CG, particularly some child of the current SCC, and // invalidate its analyses. - CGAM.invalidate(&C, PassPA); + CGAM.invalidate(C, PassPA); // Then intersect the preserved set so that invalidation of module // analyses will eventually occur when the module pass completes. @@ -409,7 +409,7 @@ public: /// Regardless of whether this analysis is marked as preserved, all of the /// analyses in the \c FunctionAnalysisManager are potentially invalidated /// based on the set of preserved analyses. - bool invalidate(LazyCallGraph::SCC *C, const PreservedAnalyses &PA); + bool invalidate(LazyCallGraph::SCC &C, const PreservedAnalyses &PA); private: FunctionAnalysisManager *FAM; @@ -441,7 +441,7 @@ public: /// In debug builds, it will also assert that the analysis manager is empty /// as no queries should arrive at the function analysis manager prior to /// this analysis being requested. - Result run(LazyCallGraph::SCC *C); + Result run(LazyCallGraph::SCC &C); private: static char PassID; @@ -479,7 +479,7 @@ public: const CGSCCAnalysisManager &getManager() const { return *CGAM; } /// \brief Handle invalidation by ignoring it, this pass is immutable. - bool invalidate(Function *) { return false; } + bool invalidate(Function &) { return false; } private: const CGSCCAnalysisManager *CGAM; @@ -505,7 +505,7 @@ public: /// \brief Run the analysis pass and create our proxy result object. /// Nothing to see here, it just forwards the \c CGAM reference into the /// result. - Result run(Function *) { return Result(*CGAM); } + Result run(Function &) { return Result(*CGAM); } private: static char PassID; @@ -541,21 +541,21 @@ public: } /// \brief Runs the function pass across every function in the module. - PreservedAnalyses run(LazyCallGraph::SCC *C, CGSCCAnalysisManager *AM) { + PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager *AM) { FunctionAnalysisManager *FAM = nullptr; if (AM) // Setup the function analysis manager from its proxy. FAM = &AM->getResult(C).getManager(); PreservedAnalyses PA = PreservedAnalyses::all(); - for (LazyCallGraph::Node *N : *C) { - PreservedAnalyses PassPA = Pass.run(&N->getFunction(), FAM); + for (LazyCallGraph::Node *N : C) { + PreservedAnalyses PassPA = Pass.run(N->getFunction(), FAM); // We know that the function pass couldn't have invalidated any other // function's analyses (that's the contract of a function pass), so // directly handle the function analysis manager's invalidation here. if (FAM) - FAM->invalidate(&N->getFunction(), PassPA); + FAM->invalidate(N->getFunction(), PassPA); // Then intersect the preserved set so that invalidation of module // analyses will eventually occur when the module pass completes. diff --git a/include/llvm/Analysis/LazyCallGraph.h b/include/llvm/Analysis/LazyCallGraph.h index 9a59844d672..4008bb71643 100644 --- a/include/llvm/Analysis/LazyCallGraph.h +++ b/include/llvm/Analysis/LazyCallGraph.h @@ -541,7 +541,7 @@ public: /// /// This just builds the set of entry points to the call graph. The rest is /// built lazily as it is walked. - LazyCallGraph run(Module *M) { return LazyCallGraph(*M); } + LazyCallGraph run(Module &M) { return LazyCallGraph(M); } private: static char PassID; @@ -556,7 +556,7 @@ class LazyCallGraphPrinterPass { public: explicit LazyCallGraphPrinterPass(raw_ostream &OS); - PreservedAnalyses run(Module *M, ModuleAnalysisManager *AM); + PreservedAnalyses run(Module &M, ModuleAnalysisManager *AM); static StringRef name() { return "LazyCallGraphPrinterPass"; } }; diff --git a/include/llvm/Bitcode/BitcodeWriterPass.h b/include/llvm/Bitcode/BitcodeWriterPass.h index eb85548fa6f..8fe9b7e8434 100644 --- a/include/llvm/Bitcode/BitcodeWriterPass.h +++ b/include/llvm/Bitcode/BitcodeWriterPass.h @@ -41,7 +41,7 @@ public: /// \brief Run the bitcode writer pass, and output the module to the selected /// output stream. - PreservedAnalyses run(Module *M); + PreservedAnalyses run(Module &M); static StringRef name() { return "BitcodeWriterPass"; } }; diff --git a/include/llvm/IR/IRPrintingPasses.h b/include/llvm/IR/IRPrintingPasses.h index afea0c349e7..7f2027b6e29 100644 --- a/include/llvm/IR/IRPrintingPasses.h +++ b/include/llvm/IR/IRPrintingPasses.h @@ -58,7 +58,7 @@ public: PrintModulePass(); PrintModulePass(raw_ostream &OS, const std::string &Banner = ""); - PreservedAnalyses run(Module *M); + PreservedAnalyses run(Module &M); static StringRef name() { return "PrintModulePass"; } }; @@ -75,7 +75,7 @@ public: PrintFunctionPass(); PrintFunctionPass(raw_ostream &OS, const std::string &Banner = ""); - PreservedAnalyses run(Function *F); + PreservedAnalyses run(Function &F); static StringRef name() { return "PrintFunctionPass"; } }; diff --git a/include/llvm/IR/PassManager.h b/include/llvm/IR/PassManager.h index 8eed3f84d41..db792efca36 100644 --- a/include/llvm/IR/PassManager.h +++ b/include/llvm/IR/PassManager.h @@ -186,7 +186,7 @@ public: /// /// This method should only be called for a single module as there is the /// expectation that the lifetime of a pass is bounded to that of a module. - PreservedAnalyses run(Module *M, ModuleAnalysisManager *AM = nullptr); + PreservedAnalyses run(Module &M, ModuleAnalysisManager *AM = nullptr); template void addPass(ModulePassT Pass) { Passes.emplace_back(new ModulePassModel(std::move(Pass))); @@ -196,13 +196,13 @@ public: private: // Pull in the concept type and model template specialized for modules. - typedef detail::PassConcept + typedef detail::PassConcept ModulePassConcept; template struct ModulePassModel - : detail::PassModel { + : detail::PassModel { ModulePassModel(PassT Pass) - : detail::PassModel( + : detail::PassModel( std::move(Pass)) {} }; @@ -255,19 +255,19 @@ public: Passes.emplace_back(new FunctionPassModel(std::move(Pass))); } - PreservedAnalyses run(Function *F, FunctionAnalysisManager *AM = nullptr); + PreservedAnalyses run(Function &F, FunctionAnalysisManager *AM = nullptr); static StringRef name() { return "FunctionPassManager"; } private: // Pull in the concept type and model template specialized for functions. - typedef detail::PassConcept + typedef detail::PassConcept FunctionPassConcept; template struct FunctionPassModel - : detail::PassModel { + : detail::PassModel { FunctionPassModel(PassT Pass) - : detail::PassModel( + : detail::PassModel( std::move(Pass)) {} }; @@ -369,7 +369,7 @@ public: /// \brief Invalidate a specific analysis pass for an IR module. /// /// Note that the analysis result can disregard invalidation. - template void invalidate(Module *M) { + template void invalidate(Module &M) { assert(AnalysisPasses.count(PassT::ID()) && "This analysis pass was not registered prior to being invalidated"); derived_this()->invalidateImpl(PassT::ID(), M); @@ -413,9 +413,9 @@ private: /// \brief A module analysis pass manager with lazy running and caching of /// results. class ModuleAnalysisManager - : public detail::AnalysisManagerBase { - friend class detail::AnalysisManagerBase; - typedef detail::AnalysisManagerBase BaseT; + : public detail::AnalysisManagerBase { + friend class detail::AnalysisManagerBase; + typedef detail::AnalysisManagerBase BaseT; typedef BaseT::ResultConceptT ResultConceptT; typedef BaseT::PassConceptT PassConceptT; @@ -438,21 +438,21 @@ private: operator=(const ModuleAnalysisManager &) LLVM_DELETED_FUNCTION; /// \brief Get a module pass result, running the pass if necessary. - ResultConceptT &getResultImpl(void *PassID, Module *M); + ResultConceptT &getResultImpl(void *PassID, Module &M); /// \brief Get a cached module pass result or return null. - ResultConceptT *getCachedResultImpl(void *PassID, Module *M) const; + ResultConceptT *getCachedResultImpl(void *PassID, Module &M) const; /// \brief Invalidate a module pass result. - void invalidateImpl(void *PassID, Module *M); + void invalidateImpl(void *PassID, Module &M); /// \brief Invalidate results across a module. - void invalidateImpl(Module *M, const PreservedAnalyses &PA); + void invalidateImpl(Module &M, const PreservedAnalyses &PA); /// \brief Map type from module analysis pass ID to pass result concept /// pointer. typedef DenseMap>> + std::unique_ptr>> ModuleAnalysisResultMapT; /// \brief Cache of computed module analysis results for this module. @@ -462,9 +462,9 @@ private: /// \brief A function analysis manager to coordinate and cache analyses run over /// a module. class FunctionAnalysisManager - : public detail::AnalysisManagerBase { - friend class detail::AnalysisManagerBase; - typedef detail::AnalysisManagerBase + : public detail::AnalysisManagerBase { + friend class detail::AnalysisManagerBase; + typedef detail::AnalysisManagerBase BaseT; typedef BaseT::ResultConceptT ResultConceptT; typedef BaseT::PassConceptT PassConceptT; @@ -502,16 +502,16 @@ private: operator=(const FunctionAnalysisManager &) LLVM_DELETED_FUNCTION; /// \brief Get a function pass result, running the pass if necessary. - ResultConceptT &getResultImpl(void *PassID, Function *F); + ResultConceptT &getResultImpl(void *PassID, Function &F); /// \brief Get a cached function pass result or return null. - ResultConceptT *getCachedResultImpl(void *PassID, Function *F) const; + ResultConceptT *getCachedResultImpl(void *PassID, Function &F) const; /// \brief Invalidate a function pass result. - void invalidateImpl(void *PassID, Function *F); + void invalidateImpl(void *PassID, Function &F); /// \brief Invalidate the results for a function.. - void invalidateImpl(Function *F, const PreservedAnalyses &PA); + void invalidateImpl(Function &F, const PreservedAnalyses &PA); /// \brief List of function analysis pass IDs and associated concept pointers. /// @@ -519,7 +519,7 @@ private: /// erases. Provides both the pass ID and concept pointer such that it is /// half of a bijection and provides storage for the actual result concept. typedef std::list>>> + void *, std::unique_ptr>>> FunctionAnalysisResultListT; /// \brief Map type from function pointer to our custom list type. @@ -581,7 +581,7 @@ public: /// In debug builds, it will also assert that the analysis manager is empty /// as no queries should arrive at the function analysis manager prior to /// this analysis being requested. - Result run(Module *M); + Result run(Module &M); private: static char PassID; @@ -619,7 +619,7 @@ public: /// Regardless of whether this analysis is marked as preserved, all of the /// analyses in the \c FunctionAnalysisManager are potentially invalidated /// based on the set of preserved analyses. - bool invalidate(Module *M, const PreservedAnalyses &PA); + bool invalidate(Module &M, const PreservedAnalyses &PA); private: FunctionAnalysisManager *FAM; @@ -655,7 +655,7 @@ public: const ModuleAnalysisManager &getManager() const { return *MAM; } /// \brief Handle invalidation by ignoring it, this pass is immutable. - bool invalidate(Function *) { return false; } + bool invalidate(Function &) { return false; } private: const ModuleAnalysisManager *MAM; @@ -681,7 +681,7 @@ public: /// \brief Run the analysis pass and create our proxy result object. /// Nothing to see here, it just forwards the \c MAM reference into the /// result. - Result run(Function *) { return Result(*MAM); } + Result run(Function &) { return Result(*MAM); } private: static char PassID; @@ -718,21 +718,21 @@ public: } /// \brief Runs the function pass across every function in the module. - PreservedAnalyses run(Module *M, ModuleAnalysisManager *AM) { + PreservedAnalyses run(Module &M, ModuleAnalysisManager *AM) { FunctionAnalysisManager *FAM = nullptr; if (AM) // Setup the function analysis manager from its proxy. FAM = &AM->getResult(M).getManager(); PreservedAnalyses PA = PreservedAnalyses::all(); - for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) { - PreservedAnalyses PassPA = Pass.run(I, FAM); + for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) { + PreservedAnalyses PassPA = Pass.run(*I, FAM); // We know that the function pass couldn't have invalidated any other // function's analyses (that's the contract of a function pass), so // directly handle the function analysis manager's invalidation here. if (FAM) - FAM->invalidate(I, PassPA); + FAM->invalidate(*I, PassPA); // Then intersect the preserved set so that invalidation of module // analyses will eventually occur when the module pass completes. diff --git a/include/llvm/IR/Verifier.h b/include/llvm/IR/Verifier.h index 0272e206f37..43bd123e7f4 100644 --- a/include/llvm/IR/Verifier.h +++ b/include/llvm/IR/Verifier.h @@ -77,8 +77,8 @@ class VerifierPass { public: explicit VerifierPass(bool FatalErrors = true) : FatalErrors(FatalErrors) {} - PreservedAnalyses run(Module *M); - PreservedAnalyses run(Function *F); + PreservedAnalyses run(Module &M); + PreservedAnalyses run(Function &F); static StringRef name() { return "VerifierPass"; } }; diff --git a/lib/Analysis/CGSCCPassManager.cpp b/lib/Analysis/CGSCCPassManager.cpp index 5d1d8a9c6e0..7be0afb70b4 100644 --- a/lib/Analysis/CGSCCPassManager.cpp +++ b/lib/Analysis/CGSCCPassManager.cpp @@ -17,7 +17,7 @@ static cl::opt DebugPM("debug-cgscc-pass-manager", cl::Hidden, cl::desc("Print CGSCC pass management debugging information")); -PreservedAnalyses CGSCCPassManager::run(LazyCallGraph::SCC *C, +PreservedAnalyses CGSCCPassManager::run(LazyCallGraph::SCC &C, CGSCCAnalysisManager *AM) { PreservedAnalyses PA = PreservedAnalyses::all(); @@ -53,16 +53,16 @@ void CGSCCAnalysisManager::clear() { } CGSCCAnalysisManager::ResultConceptT & -CGSCCAnalysisManager::getResultImpl(void *PassID, LazyCallGraph::SCC *C) { +CGSCCAnalysisManager::getResultImpl(void *PassID, LazyCallGraph::SCC &C) { CGSCCAnalysisResultMapT::iterator RI; bool Inserted; std::tie(RI, Inserted) = CGSCCAnalysisResults.insert(std::make_pair( - std::make_pair(PassID, C), CGSCCAnalysisResultListT::iterator())); + std::make_pair(PassID, &C), CGSCCAnalysisResultListT::iterator())); // If we don't have a cached result for this function, look up the pass and // run it to produce a result, which we then add to the cache. if (Inserted) { - CGSCCAnalysisResultListT &ResultList = CGSCCAnalysisResultLists[C]; + CGSCCAnalysisResultListT &ResultList = CGSCCAnalysisResultLists[&C]; ResultList.emplace_back(PassID, lookupPass(PassID).run(C, this)); RI->second = std::prev(ResultList.end()); } @@ -72,27 +72,27 @@ CGSCCAnalysisManager::getResultImpl(void *PassID, LazyCallGraph::SCC *C) { CGSCCAnalysisManager::ResultConceptT * CGSCCAnalysisManager::getCachedResultImpl(void *PassID, - LazyCallGraph::SCC *C) const { + LazyCallGraph::SCC &C) const { CGSCCAnalysisResultMapT::const_iterator RI = - CGSCCAnalysisResults.find(std::make_pair(PassID, C)); + CGSCCAnalysisResults.find(std::make_pair(PassID, &C)); return RI == CGSCCAnalysisResults.end() ? nullptr : &*RI->second->second; } -void CGSCCAnalysisManager::invalidateImpl(void *PassID, LazyCallGraph::SCC *C) { +void CGSCCAnalysisManager::invalidateImpl(void *PassID, LazyCallGraph::SCC &C) { CGSCCAnalysisResultMapT::iterator RI = - CGSCCAnalysisResults.find(std::make_pair(PassID, C)); + CGSCCAnalysisResults.find(std::make_pair(PassID, &C)); if (RI == CGSCCAnalysisResults.end()) return; - CGSCCAnalysisResultLists[C].erase(RI->second); + CGSCCAnalysisResultLists[&C].erase(RI->second); } -void CGSCCAnalysisManager::invalidateImpl(LazyCallGraph::SCC *C, +void CGSCCAnalysisManager::invalidateImpl(LazyCallGraph::SCC &C, const PreservedAnalyses &PA) { // Clear all the invalidated results associated specifically with this // function. SmallVector InvalidatedPassIDs; - CGSCCAnalysisResultListT &ResultsList = CGSCCAnalysisResultLists[C]; + CGSCCAnalysisResultListT &ResultsList = CGSCCAnalysisResultLists[&C]; for (CGSCCAnalysisResultListT::iterator I = ResultsList.begin(), E = ResultsList.end(); I != E;) @@ -104,14 +104,14 @@ void CGSCCAnalysisManager::invalidateImpl(LazyCallGraph::SCC *C, } while (!InvalidatedPassIDs.empty()) CGSCCAnalysisResults.erase( - std::make_pair(InvalidatedPassIDs.pop_back_val(), C)); - CGSCCAnalysisResultLists.erase(C); + std::make_pair(InvalidatedPassIDs.pop_back_val(), &C)); + CGSCCAnalysisResultLists.erase(&C); } char CGSCCAnalysisManagerModuleProxy::PassID; CGSCCAnalysisManagerModuleProxy::Result -CGSCCAnalysisManagerModuleProxy::run(Module *M) { +CGSCCAnalysisManagerModuleProxy::run(Module &M) { assert(CGAM->empty() && "CGSCC analyses ran prior to the module proxy!"); return Result(*CGAM); } @@ -123,7 +123,7 @@ CGSCCAnalysisManagerModuleProxy::Result::~Result() { } bool CGSCCAnalysisManagerModuleProxy::Result::invalidate( - Module *M, const PreservedAnalyses &PA) { + Module &M, const PreservedAnalyses &PA) { // If this proxy isn't marked as preserved, then we can't even invalidate // individual CGSCC analyses, there may be an invalid set of SCC objects in // the cache making it impossible to incrementally preserve them. @@ -140,7 +140,7 @@ char ModuleAnalysisManagerCGSCCProxy::PassID; char FunctionAnalysisManagerCGSCCProxy::PassID; FunctionAnalysisManagerCGSCCProxy::Result -FunctionAnalysisManagerCGSCCProxy::run(LazyCallGraph::SCC *C) { +FunctionAnalysisManagerCGSCCProxy::run(LazyCallGraph::SCC &C) { assert(FAM->empty() && "Function analyses ran prior to the CGSCC proxy!"); return Result(*FAM); } @@ -152,7 +152,7 @@ FunctionAnalysisManagerCGSCCProxy::Result::~Result() { } bool FunctionAnalysisManagerCGSCCProxy::Result::invalidate( - LazyCallGraph::SCC *C, const PreservedAnalyses &PA) { + LazyCallGraph::SCC &C, const PreservedAnalyses &PA) { // If this proxy isn't marked as preserved, then we can't even invalidate // individual function analyses, there may be an invalid set of Function // objects in the cache making it impossible to incrementally preserve them. diff --git a/lib/Analysis/LazyCallGraph.cpp b/lib/Analysis/LazyCallGraph.cpp index 767da4e31d1..c8d0410c1e0 100644 --- a/lib/Analysis/LazyCallGraph.cpp +++ b/lib/Analysis/LazyCallGraph.cpp @@ -708,11 +708,11 @@ static void printSCC(raw_ostream &OS, LazyCallGraph::SCC &SCC) { OS << "\n"; } -PreservedAnalyses LazyCallGraphPrinterPass::run(Module *M, +PreservedAnalyses LazyCallGraphPrinterPass::run(Module &M, ModuleAnalysisManager *AM) { LazyCallGraph &G = AM->getResult(M); - OS << "Printing the call graph for module: " << M->getModuleIdentifier() + OS << "Printing the call graph for module: " << M.getModuleIdentifier() << "\n\n"; SmallPtrSet Printed; @@ -724,5 +724,4 @@ PreservedAnalyses LazyCallGraphPrinterPass::run(Module *M, printSCC(OS, SCC); return PreservedAnalyses::all(); - } diff --git a/lib/Bitcode/Writer/BitcodeWriterPass.cpp b/lib/Bitcode/Writer/BitcodeWriterPass.cpp index 4167f6da509..25456a45621 100644 --- a/lib/Bitcode/Writer/BitcodeWriterPass.cpp +++ b/lib/Bitcode/Writer/BitcodeWriterPass.cpp @@ -18,8 +18,8 @@ #include "llvm/Pass.h" using namespace llvm; -PreservedAnalyses BitcodeWriterPass::run(Module *M) { - WriteBitcodeToFile(M, OS); +PreservedAnalyses BitcodeWriterPass::run(Module &M) { + WriteBitcodeToFile(&M, OS); return PreservedAnalyses::all(); } diff --git a/lib/IR/IRPrintingPasses.cpp b/lib/IR/IRPrintingPasses.cpp index c8a17479d8a..91ccfbb2f46 100644 --- a/lib/IR/IRPrintingPasses.cpp +++ b/lib/IR/IRPrintingPasses.cpp @@ -24,8 +24,8 @@ PrintModulePass::PrintModulePass() : OS(dbgs()) {} PrintModulePass::PrintModulePass(raw_ostream &OS, const std::string &Banner) : OS(OS), Banner(Banner) {} -PreservedAnalyses PrintModulePass::run(Module *M) { - OS << Banner << *M; +PreservedAnalyses PrintModulePass::run(Module &M) { + OS << Banner << M; return PreservedAnalyses::all(); } @@ -33,8 +33,8 @@ PrintFunctionPass::PrintFunctionPass() : OS(dbgs()) {} PrintFunctionPass::PrintFunctionPass(raw_ostream &OS, const std::string &Banner) : OS(OS), Banner(Banner) {} -PreservedAnalyses PrintFunctionPass::run(Function *F) { - OS << Banner << static_cast(*F); +PreservedAnalyses PrintFunctionPass::run(Function &F) { + OS << Banner << static_cast(F); return PreservedAnalyses::all(); } @@ -50,7 +50,7 @@ public: : ModulePass(ID), P(OS, Banner) {} bool runOnModule(Module &M) override { - P.run(&M); + P.run(M); return false; } @@ -70,7 +70,7 @@ public: // This pass just prints a banner followed by the function as it's processed. bool runOnFunction(Function &F) override { - P.run(&F); + P.run(F); return false; } diff --git a/lib/IR/PassManager.cpp b/lib/IR/PassManager.cpp index 39270edc387..121ec001fd1 100644 --- a/lib/IR/PassManager.cpp +++ b/lib/IR/PassManager.cpp @@ -19,7 +19,7 @@ static cl::opt DebugPM("debug-pass-manager", cl::Hidden, cl::desc("Print pass management debugging information")); -PreservedAnalyses ModulePassManager::run(Module *M, ModuleAnalysisManager *AM) { +PreservedAnalyses ModulePassManager::run(Module &M, ModuleAnalysisManager *AM) { PreservedAnalyses PA = PreservedAnalyses::all(); if (DebugPM) @@ -34,7 +34,7 @@ PreservedAnalyses ModulePassManager::run(Module *M, ModuleAnalysisManager *AM) { AM->invalidate(M, PassPA); PA.intersect(std::move(PassPA)); - M->getContext().yield(); + M.getContext().yield(); } if (DebugPM) @@ -44,11 +44,11 @@ PreservedAnalyses ModulePassManager::run(Module *M, ModuleAnalysisManager *AM) { } ModuleAnalysisManager::ResultConceptT & -ModuleAnalysisManager::getResultImpl(void *PassID, Module *M) { +ModuleAnalysisManager::getResultImpl(void *PassID, Module &M) { ModuleAnalysisResultMapT::iterator RI; bool Inserted; std::tie(RI, Inserted) = ModuleAnalysisResults.insert(std::make_pair( - PassID, std::unique_ptr>())); + PassID, std::unique_ptr>())); // If we don't have a cached result for this module, look up the pass and run // it to produce a result, which we then add to the cache. @@ -59,17 +59,17 @@ ModuleAnalysisManager::getResultImpl(void *PassID, Module *M) { } ModuleAnalysisManager::ResultConceptT * -ModuleAnalysisManager::getCachedResultImpl(void *PassID, Module *M) const { +ModuleAnalysisManager::getCachedResultImpl(void *PassID, Module &M) const { ModuleAnalysisResultMapT::const_iterator RI = ModuleAnalysisResults.find(PassID); return RI == ModuleAnalysisResults.end() ? nullptr : &*RI->second; } -void ModuleAnalysisManager::invalidateImpl(void *PassID, Module *M) { +void ModuleAnalysisManager::invalidateImpl(void *PassID, Module &M) { ModuleAnalysisResults.erase(PassID); } -void ModuleAnalysisManager::invalidateImpl(Module *M, +void ModuleAnalysisManager::invalidateImpl(Module &M, const PreservedAnalyses &PA) { // FIXME: This is a total hack based on the fact that erasure doesn't // invalidate iteration for DenseMap. @@ -80,7 +80,7 @@ void ModuleAnalysisManager::invalidateImpl(Module *M, ModuleAnalysisResults.erase(I); } -PreservedAnalyses FunctionPassManager::run(Function *F, +PreservedAnalyses FunctionPassManager::run(Function &F, FunctionAnalysisManager *AM) { PreservedAnalyses PA = PreservedAnalyses::all(); @@ -96,7 +96,7 @@ PreservedAnalyses FunctionPassManager::run(Function *F, AM->invalidate(F, PassPA); PA.intersect(std::move(PassPA)); - F->getContext().yield(); + F.getContext().yield(); } if (DebugPM) @@ -119,16 +119,16 @@ void FunctionAnalysisManager::clear() { } FunctionAnalysisManager::ResultConceptT & -FunctionAnalysisManager::getResultImpl(void *PassID, Function *F) { +FunctionAnalysisManager::getResultImpl(void *PassID, Function &F) { FunctionAnalysisResultMapT::iterator RI; bool Inserted; std::tie(RI, Inserted) = FunctionAnalysisResults.insert(std::make_pair( - std::make_pair(PassID, F), FunctionAnalysisResultListT::iterator())); + std::make_pair(PassID, &F), FunctionAnalysisResultListT::iterator())); // If we don't have a cached result for this function, look up the pass and // run it to produce a result, which we then add to the cache. if (Inserted) { - FunctionAnalysisResultListT &ResultList = FunctionAnalysisResultLists[F]; + FunctionAnalysisResultListT &ResultList = FunctionAnalysisResultLists[&F]; ResultList.emplace_back(PassID, lookupPass(PassID).run(F, this)); RI->second = std::prev(ResultList.end()); } @@ -137,27 +137,27 @@ FunctionAnalysisManager::getResultImpl(void *PassID, Function *F) { } FunctionAnalysisManager::ResultConceptT * -FunctionAnalysisManager::getCachedResultImpl(void *PassID, Function *F) const { +FunctionAnalysisManager::getCachedResultImpl(void *PassID, Function &F) const { FunctionAnalysisResultMapT::const_iterator RI = - FunctionAnalysisResults.find(std::make_pair(PassID, F)); + FunctionAnalysisResults.find(std::make_pair(PassID, &F)); return RI == FunctionAnalysisResults.end() ? nullptr : &*RI->second->second; } -void FunctionAnalysisManager::invalidateImpl(void *PassID, Function *F) { +void FunctionAnalysisManager::invalidateImpl(void *PassID, Function &F) { FunctionAnalysisResultMapT::iterator RI = - FunctionAnalysisResults.find(std::make_pair(PassID, F)); + FunctionAnalysisResults.find(std::make_pair(PassID, &F)); if (RI == FunctionAnalysisResults.end()) return; - FunctionAnalysisResultLists[F].erase(RI->second); + FunctionAnalysisResultLists[&F].erase(RI->second); } -void FunctionAnalysisManager::invalidateImpl(Function *F, +void FunctionAnalysisManager::invalidateImpl(Function &F, const PreservedAnalyses &PA) { // Clear all the invalidated results associated specifically with this // function. SmallVector InvalidatedPassIDs; - FunctionAnalysisResultListT &ResultsList = FunctionAnalysisResultLists[F]; + FunctionAnalysisResultListT &ResultsList = FunctionAnalysisResultLists[&F]; for (FunctionAnalysisResultListT::iterator I = ResultsList.begin(), E = ResultsList.end(); I != E;) @@ -169,15 +169,15 @@ void FunctionAnalysisManager::invalidateImpl(Function *F, } while (!InvalidatedPassIDs.empty()) FunctionAnalysisResults.erase( - std::make_pair(InvalidatedPassIDs.pop_back_val(), F)); + std::make_pair(InvalidatedPassIDs.pop_back_val(), &F)); if (ResultsList.empty()) - FunctionAnalysisResultLists.erase(F); + FunctionAnalysisResultLists.erase(&F); } char FunctionAnalysisManagerModuleProxy::PassID; FunctionAnalysisManagerModuleProxy::Result -FunctionAnalysisManagerModuleProxy::run(Module *M) { +FunctionAnalysisManagerModuleProxy::run(Module &M) { assert(FAM->empty() && "Function analyses ran prior to the module proxy!"); return Result(*FAM); } @@ -189,7 +189,7 @@ FunctionAnalysisManagerModuleProxy::Result::~Result() { } bool FunctionAnalysisManagerModuleProxy::Result::invalidate( - Module *M, const PreservedAnalyses &PA) { + Module &M, const PreservedAnalyses &PA) { // If this proxy isn't marked as preserved, then we can't even invalidate // individual function analyses, there may be an invalid set of Function // objects in the cache making it impossible to incrementally preserve them. diff --git a/lib/IR/Verifier.cpp b/lib/IR/Verifier.cpp index 0bc9d5e1bc8..bc721145d2a 100644 --- a/lib/IR/Verifier.cpp +++ b/lib/IR/Verifier.cpp @@ -2902,15 +2902,15 @@ ModulePass *llvm::createDebugInfoVerifierPass(bool FatalErrors) { return new DebugInfoVerifierLegacyPass(FatalErrors); } -PreservedAnalyses VerifierPass::run(Module *M) { - if (verifyModule(*M, &dbgs()) && FatalErrors) +PreservedAnalyses VerifierPass::run(Module &M) { + if (verifyModule(M, &dbgs()) && FatalErrors) report_fatal_error("Broken module found, compilation aborted!"); return PreservedAnalyses::all(); } -PreservedAnalyses VerifierPass::run(Function *F) { - if (verifyFunction(*F, &dbgs()) && FatalErrors) +PreservedAnalyses VerifierPass::run(Function &F) { + if (verifyFunction(F, &dbgs()) && FatalErrors) report_fatal_error("Broken function found, compilation aborted!"); return PreservedAnalyses::all(); diff --git a/tools/opt/NewPMDriver.cpp b/tools/opt/NewPMDriver.cpp index 8076ff44872..cdf4e42ca12 100644 --- a/tools/opt/NewPMDriver.cpp +++ b/tools/opt/NewPMDriver.cpp @@ -86,7 +86,7 @@ bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M, cl::PrintOptionValues(); // Now that we have all of the passes ready, run them. - MPM.run(&M, &MAM); + MPM.run(M, &MAM); // Declare success. if (OK != OK_NoOutput) diff --git a/tools/opt/Passes.cpp b/tools/opt/Passes.cpp index a171f42691a..6ac044a0d05 100644 --- a/tools/opt/Passes.cpp +++ b/tools/opt/Passes.cpp @@ -28,13 +28,13 @@ namespace { /// \brief No-op module pass which does nothing. struct NoOpModulePass { - PreservedAnalyses run(Module *M) { return PreservedAnalyses::all(); } + PreservedAnalyses run(Module &M) { return PreservedAnalyses::all(); } static StringRef name() { return "NoOpModulePass"; } }; /// \brief No-op CGSCC pass which does nothing. struct NoOpCGSCCPass { - PreservedAnalyses run(LazyCallGraph::SCC *C) { + PreservedAnalyses run(LazyCallGraph::SCC &C) { return PreservedAnalyses::all(); } static StringRef name() { return "NoOpCGSCCPass"; } @@ -42,7 +42,7 @@ struct NoOpCGSCCPass { /// \brief No-op function pass which does nothing. struct NoOpFunctionPass { - PreservedAnalyses run(Function *F) { return PreservedAnalyses::all(); } + PreservedAnalyses run(Function &F) { return PreservedAnalyses::all(); } static StringRef name() { return "NoOpFunctionPass"; } }; diff --git a/unittests/IR/PassManagerTest.cpp b/unittests/IR/PassManagerTest.cpp index d493156a343..d641e36ac6a 100644 --- a/unittests/IR/PassManagerTest.cpp +++ b/unittests/IR/PassManagerTest.cpp @@ -32,10 +32,10 @@ public: TestFunctionAnalysis(int &Runs) : Runs(Runs) {} /// \brief Run the analysis pass over the function and return a result. - Result run(Function *F, FunctionAnalysisManager *AM) { + Result run(Function &F, FunctionAnalysisManager *AM) { ++Runs; int Count = 0; - for (Function::iterator BBI = F->begin(), BBE = F->end(); BBI != BBE; ++BBI) + for (Function::iterator BBI = F.begin(), BBE = F.end(); BBI != BBE; ++BBI) for (BasicBlock::iterator II = BBI->begin(), IE = BBI->end(); II != IE; ++II) ++Count; @@ -62,10 +62,10 @@ public: TestModuleAnalysis(int &Runs) : Runs(Runs) {} - Result run(Module *M, ModuleAnalysisManager *AM) { + Result run(Module &M, ModuleAnalysisManager *AM) { ++Runs; int Count = 0; - for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) + for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) ++Count; return Result(Count); } @@ -81,7 +81,7 @@ char TestModuleAnalysis::PassID; struct TestModulePass { TestModulePass(int &RunCount) : RunCount(RunCount) {} - PreservedAnalyses run(Module *M) { + PreservedAnalyses run(Module &M) { ++RunCount; return PreservedAnalyses::none(); } @@ -92,13 +92,13 @@ struct TestModulePass { }; struct TestPreservingModulePass { - PreservedAnalyses run(Module *M) { return PreservedAnalyses::all(); } + PreservedAnalyses run(Module &M) { return PreservedAnalyses::all(); } static StringRef name() { return "TestPreservingModulePass"; } }; struct TestMinPreservingModulePass { - PreservedAnalyses run(Module *M, ModuleAnalysisManager *AM) { + PreservedAnalyses run(Module &M, ModuleAnalysisManager *AM) { PreservedAnalyses PA; // Force running an analysis. @@ -119,13 +119,13 @@ struct TestFunctionPass { AnalyzedFunctionCount(AnalyzedFunctionCount), OnlyUseCachedResults(OnlyUseCachedResults) {} - PreservedAnalyses run(Function *F, FunctionAnalysisManager *AM) { + PreservedAnalyses run(Function &F, FunctionAnalysisManager *AM) { ++RunCount; const ModuleAnalysisManager &MAM = AM->getResult(F).getManager(); if (TestModuleAnalysis::Result *TMA = - MAM.getCachedResult(F->getParent())) + MAM.getCachedResult(*F.getParent())) AnalyzedFunctionCount += TMA->FunctionCount; if (OnlyUseCachedResults) { @@ -155,9 +155,9 @@ struct TestFunctionPass { struct TestInvalidationFunctionPass { TestInvalidationFunctionPass(StringRef FunctionName) : Name(FunctionName) {} - PreservedAnalyses run(Function *F) { - return F->getName() == Name ? PreservedAnalyses::none() - : PreservedAnalyses::all(); + PreservedAnalyses run(Function &F) { + return F.getName() == Name ? PreservedAnalyses::none() + : PreservedAnalyses::all(); } static StringRef name() { return "TestInvalidationFunctionPass"; } @@ -165,10 +165,10 @@ struct TestInvalidationFunctionPass { StringRef Name; }; -Module *parseIR(const char *IR) { +std::unique_ptr parseIR(const char *IR) { LLVMContext &C = getGlobalContext(); SMDiagnostic Err; - return parseAssemblyString(IR, Err, C).release(); + return parseAssemblyString(IR, Err, C); } class PassManagerTest : public ::testing::Test { @@ -310,7 +310,7 @@ TEST_F(PassManagerTest, Basic) { MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); } - MPM.run(M.get(), &MAM); + MPM.run(*M, &MAM); // Validate module pass counters. EXPECT_EQ(1, ModulePassRunCount);