}
/// \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 <typename CGSCCPassT> void addPass(CGSCCPassT Pass) {
private:
// Pull in the concept type and model template specialized for SCCs.
- typedef detail::PassConcept<LazyCallGraph::SCC *, CGSCCAnalysisManager>
+ typedef detail::PassConcept<LazyCallGraph::SCC &, CGSCCAnalysisManager>
CGSCCPassConcept;
template <typename PassT>
struct CGSCCPassModel
- : detail::PassModel<LazyCallGraph::SCC *, CGSCCAnalysisManager, PassT> {
+ : detail::PassModel<LazyCallGraph::SCC &, CGSCCAnalysisManager, PassT> {
CGSCCPassModel(PassT Pass)
- : detail::PassModel<LazyCallGraph::SCC *, CGSCCAnalysisManager, PassT>(
+ : detail::PassModel<LazyCallGraph::SCC &, CGSCCAnalysisManager, PassT>(
std::move(Pass)) {}
};
/// \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<CGSCCAnalysisManager,
- LazyCallGraph::SCC *>;
+ LazyCallGraph::SCC &>;
typedef detail::AnalysisManagerBase<CGSCCAnalysisManager,
- LazyCallGraph::SCC *> BaseT;
+ LazyCallGraph::SCC &> BaseT;
typedef BaseT::ResultConceptT ResultConceptT;
typedef BaseT::PassConceptT PassConceptT;
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.
///
/// half of a bijection and provides storage for the actual result concept.
typedef std::list<
std::pair<void *, std::unique_ptr<detail::AnalysisResultConcept<
- LazyCallGraph::SCC *>>>> CGSCCAnalysisResultListT;
+ LazyCallGraph::SCC &>>>> CGSCCAnalysisResultListT;
/// \brief Map type from function pointer to our custom list type.
typedef DenseMap<LazyCallGraph::SCC *, CGSCCAnalysisResultListT>
/// 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;
/// 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;
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;
/// \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;
}
/// \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.
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
// 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.
/// 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;
/// 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;
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;
/// \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;
}
/// \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<FunctionAnalysisManagerCGSCCProxy>(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.
///
/// 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;
public:
explicit LazyCallGraphPrinterPass(raw_ostream &OS);
- PreservedAnalyses run(Module *M, ModuleAnalysisManager *AM);
+ PreservedAnalyses run(Module &M, ModuleAnalysisManager *AM);
static StringRef name() { return "LazyCallGraphPrinterPass"; }
};
/// \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"; }
};
PrintModulePass();
PrintModulePass(raw_ostream &OS, const std::string &Banner = "");
- PreservedAnalyses run(Module *M);
+ PreservedAnalyses run(Module &M);
static StringRef name() { return "PrintModulePass"; }
};
PrintFunctionPass();
PrintFunctionPass(raw_ostream &OS, const std::string &Banner = "");
- PreservedAnalyses run(Function *F);
+ PreservedAnalyses run(Function &F);
static StringRef name() { return "PrintFunctionPass"; }
};
///
/// 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 <typename ModulePassT> void addPass(ModulePassT Pass) {
Passes.emplace_back(new ModulePassModel<ModulePassT>(std::move(Pass)));
private:
// Pull in the concept type and model template specialized for modules.
- typedef detail::PassConcept<Module *, ModuleAnalysisManager>
+ typedef detail::PassConcept<Module &, ModuleAnalysisManager>
ModulePassConcept;
template <typename PassT>
struct ModulePassModel
- : detail::PassModel<Module *, ModuleAnalysisManager, PassT> {
+ : detail::PassModel<Module &, ModuleAnalysisManager, PassT> {
ModulePassModel(PassT Pass)
- : detail::PassModel<Module *, ModuleAnalysisManager, PassT>(
+ : detail::PassModel<Module &, ModuleAnalysisManager, PassT>(
std::move(Pass)) {}
};
Passes.emplace_back(new FunctionPassModel<FunctionPassT>(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<Function *, FunctionAnalysisManager>
+ typedef detail::PassConcept<Function &, FunctionAnalysisManager>
FunctionPassConcept;
template <typename PassT>
struct FunctionPassModel
- : detail::PassModel<Function *, FunctionAnalysisManager, PassT> {
+ : detail::PassModel<Function &, FunctionAnalysisManager, PassT> {
FunctionPassModel(PassT Pass)
- : detail::PassModel<Function *, FunctionAnalysisManager, PassT>(
+ : detail::PassModel<Function &, FunctionAnalysisManager, PassT>(
std::move(Pass)) {}
};
/// \brief Invalidate a specific analysis pass for an IR module.
///
/// Note that the analysis result can disregard invalidation.
- template <typename PassT> void invalidate(Module *M) {
+ template <typename PassT> 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);
/// \brief A module analysis pass manager with lazy running and caching of
/// results.
class ModuleAnalysisManager
- : public detail::AnalysisManagerBase<ModuleAnalysisManager, Module *> {
- friend class detail::AnalysisManagerBase<ModuleAnalysisManager, Module *>;
- typedef detail::AnalysisManagerBase<ModuleAnalysisManager, Module *> BaseT;
+ : public detail::AnalysisManagerBase<ModuleAnalysisManager, Module &> {
+ friend class detail::AnalysisManagerBase<ModuleAnalysisManager, Module &>;
+ typedef detail::AnalysisManagerBase<ModuleAnalysisManager, Module &> BaseT;
typedef BaseT::ResultConceptT ResultConceptT;
typedef BaseT::PassConceptT PassConceptT;
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<void *,
- std::unique_ptr<detail::AnalysisResultConcept<Module *>>>
+ std::unique_ptr<detail::AnalysisResultConcept<Module &>>>
ModuleAnalysisResultMapT;
/// \brief Cache of computed module analysis results for this module.
/// \brief A function analysis manager to coordinate and cache analyses run over
/// a module.
class FunctionAnalysisManager
- : public detail::AnalysisManagerBase<FunctionAnalysisManager, Function *> {
- friend class detail::AnalysisManagerBase<FunctionAnalysisManager, Function *>;
- typedef detail::AnalysisManagerBase<FunctionAnalysisManager, Function *>
+ : public detail::AnalysisManagerBase<FunctionAnalysisManager, Function &> {
+ friend class detail::AnalysisManagerBase<FunctionAnalysisManager, Function &>;
+ typedef detail::AnalysisManagerBase<FunctionAnalysisManager, Function &>
BaseT;
typedef BaseT::ResultConceptT ResultConceptT;
typedef BaseT::PassConceptT PassConceptT;
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.
///
/// 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<std::pair<
- void *, std::unique_ptr<detail::AnalysisResultConcept<Function *>>>>
+ void *, std::unique_ptr<detail::AnalysisResultConcept<Function &>>>>
FunctionAnalysisResultListT;
/// \brief Map type from function pointer to our custom list type.
/// 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;
/// 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;
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;
/// \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;
}
/// \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<FunctionAnalysisManagerModuleProxy>(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.
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"; }
};
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();
}
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());
}
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<void *, 8> InvalidatedPassIDs;
- CGSCCAnalysisResultListT &ResultsList = CGSCCAnalysisResultLists[C];
+ CGSCCAnalysisResultListT &ResultsList = CGSCCAnalysisResultLists[&C];
for (CGSCCAnalysisResultListT::iterator I = ResultsList.begin(),
E = ResultsList.end();
I != E;)
}
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);
}
}
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.
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);
}
}
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.
OS << "\n";
}
-PreservedAnalyses LazyCallGraphPrinterPass::run(Module *M,
+PreservedAnalyses LazyCallGraphPrinterPass::run(Module &M,
ModuleAnalysisManager *AM) {
LazyCallGraph &G = AM->getResult<LazyCallGraphAnalysis>(M);
- OS << "Printing the call graph for module: " << M->getModuleIdentifier()
+ OS << "Printing the call graph for module: " << M.getModuleIdentifier()
<< "\n\n";
SmallPtrSet<LazyCallGraph::Node *, 16> Printed;
printSCC(OS, SCC);
return PreservedAnalyses::all();
-
}
#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();
}
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();
}
PrintFunctionPass::PrintFunctionPass(raw_ostream &OS, const std::string &Banner)
: OS(OS), Banner(Banner) {}
-PreservedAnalyses PrintFunctionPass::run(Function *F) {
- OS << Banner << static_cast<Value &>(*F);
+PreservedAnalyses PrintFunctionPass::run(Function &F) {
+ OS << Banner << static_cast<Value &>(F);
return PreservedAnalyses::all();
}
: ModulePass(ID), P(OS, Banner) {}
bool runOnModule(Module &M) override {
- P.run(&M);
+ P.run(M);
return false;
}
// 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;
}
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)
AM->invalidate(M, PassPA);
PA.intersect(std::move(PassPA));
- M->getContext().yield();
+ M.getContext().yield();
}
if (DebugPM)
}
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<detail::AnalysisResultConcept<Module *>>()));
+ PassID, std::unique_ptr<detail::AnalysisResultConcept<Module &>>()));
// 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.
}
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.
ModuleAnalysisResults.erase(I);
}
-PreservedAnalyses FunctionPassManager::run(Function *F,
+PreservedAnalyses FunctionPassManager::run(Function &F,
FunctionAnalysisManager *AM) {
PreservedAnalyses PA = PreservedAnalyses::all();
AM->invalidate(F, PassPA);
PA.intersect(std::move(PassPA));
- F->getContext().yield();
+ F.getContext().yield();
}
if (DebugPM)
}
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());
}
}
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<void *, 8> InvalidatedPassIDs;
- FunctionAnalysisResultListT &ResultsList = FunctionAnalysisResultLists[F];
+ FunctionAnalysisResultListT &ResultsList = FunctionAnalysisResultLists[&F];
for (FunctionAnalysisResultListT::iterator I = ResultsList.begin(),
E = ResultsList.end();
I != E;)
}
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);
}
}
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.
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();
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)
/// \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"; }
/// \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"; }
};
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;
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);
}
struct TestModulePass {
TestModulePass(int &RunCount) : RunCount(RunCount) {}
- PreservedAnalyses run(Module *M) {
+ PreservedAnalyses run(Module &M) {
++RunCount;
return PreservedAnalyses::none();
}
};
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.
AnalyzedFunctionCount(AnalyzedFunctionCount),
OnlyUseCachedResults(OnlyUseCachedResults) {}
- PreservedAnalyses run(Function *F, FunctionAnalysisManager *AM) {
+ PreservedAnalyses run(Function &F, FunctionAnalysisManager *AM) {
++RunCount;
const ModuleAnalysisManager &MAM =
AM->getResult<ModuleAnalysisManagerFunctionProxy>(F).getManager();
if (TestModuleAnalysis::Result *TMA =
- MAM.getCachedResult<TestModuleAnalysis>(F->getParent()))
+ MAM.getCachedResult<TestModuleAnalysis>(*F.getParent()))
AnalyzedFunctionCount += TMA->FunctionCount;
if (OnlyUseCachedResults) {
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"; }
StringRef Name;
};
-Module *parseIR(const char *IR) {
+std::unique_ptr<Module> 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 {
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
}
- MPM.run(M.get(), &MAM);
+ MPM.run(*M, &MAM);
// Validate module pass counters.
EXPECT_EQ(1, ModulePassRunCount);