1 //===- PassManager.h - Pass management infrastructure -----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// This header defines various interfaces for pass management in LLVM. There
12 /// is no "pass" interface in LLVM per se. Instead, an instance of any class
13 /// which supports a method to 'run' it over a unit of IR can be used as
14 /// a pass. A pass manager is generally a tool to collect a sequence of passes
15 /// which run over a particular IR construct, and run each of them in sequence
16 /// over each such construct in the containing IR construct. As there is no
17 /// containing IR construct for a Module, a manager for passes over modules
18 /// forms the base case which runs its managed passes in sequence over the
19 /// single module provided.
21 /// The core IR library provides managers for running passes over
22 /// modules and functions.
24 /// * FunctionPassManager can run over a Module, runs each pass over
26 /// * ModulePassManager must be directly run, runs each pass over the Module.
28 /// Note that the implementations of the pass managers use concept-based
29 /// polymorphism as outlined in the "Value Semantics and Concept-based
30 /// Polymorphism" talk (or its abbreviated sibling "Inheritance Is The Base
31 /// Class of Evil") by Sean Parent:
32 /// * http://github.com/sean-parent/sean-parent.github.com/wiki/Papers-and-Presentations
33 /// * http://www.youtube.com/watch?v=_BpMYeUFXv8
34 /// * http://channel9.msdn.com/Events/GoingNative/2013/Inheritance-Is-The-Base-Class-of-Evil
36 //===----------------------------------------------------------------------===//
38 #include "llvm/ADT/DenseMap.h"
39 #include "llvm/ADT/SmallPtrSet.h"
40 #include "llvm/ADT/polymorphic_ptr.h"
41 #include "llvm/Support/type_traits.h"
42 #include "llvm/IR/Function.h"
43 #include "llvm/IR/Module.h"
52 /// \brief An abstract set of preserved analyses following a transformation pass
55 /// When a transformation pass is run, it can return a set of analyses whose
56 /// results were preserved by that transformation. The default set is "none",
57 /// and preserving analyses must be done explicitly.
59 /// There is also an explicit all state which can be used (for example) when
60 /// the IR is not mutated at all.
61 class PreservedAnalyses {
63 /// \brief Convenience factory function for the empty preserved set.
64 static PreservedAnalyses none() { return PreservedAnalyses(); }
66 /// \brief Construct a special preserved set that preserves all passes.
67 static PreservedAnalyses all() {
69 PA.PreservedPassIDs.insert((void *)AllPassesID);
73 PreservedAnalyses &operator=(PreservedAnalyses Arg) {
78 void swap(PreservedAnalyses &Arg) {
79 PreservedPassIDs.swap(Arg.PreservedPassIDs);
82 /// \brief Mark a particular pass as preserved, adding it to the set.
83 template <typename PassT> void preserve() {
84 if (!areAllPreserved())
85 PreservedPassIDs.insert(PassT::ID());
88 /// \brief Intersect this set with another in place.
90 /// This is a mutating operation on this preserved set, removing all
91 /// preserved passes which are not also preserved in the argument.
92 void intersect(const PreservedAnalyses &Arg) {
93 if (Arg.areAllPreserved())
95 if (areAllPreserved()) {
96 PreservedPassIDs = Arg.PreservedPassIDs;
99 for (SmallPtrSet<void *, 2>::const_iterator I = PreservedPassIDs.begin(),
100 E = PreservedPassIDs.end();
102 if (!Arg.PreservedPassIDs.count(*I))
103 PreservedPassIDs.erase(*I);
106 #if LLVM_HAS_RVALUE_REFERENCES
107 /// \brief Intersect this set with a temporary other set in place.
109 /// This is a mutating operation on this preserved set, removing all
110 /// preserved passes which are not also preserved in the argument.
111 void intersect(PreservedAnalyses &&Arg) {
112 if (Arg.areAllPreserved())
114 if (areAllPreserved()) {
115 PreservedPassIDs = std::move(Arg.PreservedPassIDs);
118 for (SmallPtrSet<void *, 2>::const_iterator I = PreservedPassIDs.begin(),
119 E = PreservedPassIDs.end();
121 if (!Arg.PreservedPassIDs.count(*I))
122 PreservedPassIDs.erase(*I);
126 /// \brief Query whether a pass is marked as preserved by this set.
127 template <typename PassT> bool preserved() const {
128 return preserved(PassT::ID());
131 /// \brief Query whether an abstract pass ID is marked as preserved by this
133 bool preserved(void *PassID) const {
134 return PreservedPassIDs.count((void *)AllPassesID) ||
135 PreservedPassIDs.count(PassID);
139 // Note that this must not be -1 or -2 as those are already used by the
141 static const uintptr_t AllPassesID = (intptr_t)-3;
143 bool areAllPreserved() const { return PreservedPassIDs.count((void *)AllPassesID); }
145 SmallPtrSet<void *, 2> PreservedPassIDs;
148 inline void swap(PreservedAnalyses &LHS, PreservedAnalyses &RHS) {
152 /// \brief Implementation details of the pass manager interfaces.
155 /// \brief Template for the abstract base class used to dispatch
156 /// polymorphically over pass objects.
157 template <typename IRUnitT, typename AnalysisManagerT> struct PassConcept {
158 // Boiler plate necessary for the container of derived classes.
159 virtual ~PassConcept() {}
160 virtual PassConcept *clone() = 0;
162 /// \brief The polymorphic API which runs the pass over a given IR entity.
164 /// Note that actual pass object can omit the analysis manager argument if
165 /// desired. Also that the analysis manager may be null if there is no
166 /// analysis manager in the pass pipeline.
167 virtual PreservedAnalyses run(IRUnitT IR, AnalysisManagerT *AM) = 0;
170 /// \brief SFINAE metafunction for computing whether \c PassT has a run method
171 /// accepting an \c AnalysisManagerT.
172 template <typename IRUnitT, typename PassT, typename AnalysisManagerT>
173 class PassRunAcceptsAnalysisManager {
174 typedef char SmallType;
175 struct BigType { char a, b; };
177 template <typename T, PreservedAnalyses (T::*)(IRUnitT, AnalysisManagerT *)>
180 template <typename T> static SmallType f(Checker<T, &T::run> *);
181 template <typename T> static BigType f(...);
184 enum { Value = sizeof(f<PassT>(0)) == sizeof(SmallType) };
187 /// \brief A template wrapper used to implement the polymorphic API.
189 /// Can be instantiated for any object which provides a \c run method accepting
190 /// an \c IRUnitT. It requires the pass to be a copyable object. When the
191 /// \c run method also accepts an \c AnalysisManagerT*, we pass it along.
192 template <typename IRUnitT, typename PassT, typename AnalysisManagerT,
193 bool AcceptsAnalysisManager = PassRunAcceptsAnalysisManager<
194 IRUnitT, PassT, AnalysisManagerT>::Value>
197 /// \brief Specialization of \c PassModel for passes that accept an analyis
199 template <typename IRUnitT, typename PassT, typename AnalysisManagerT>
200 struct PassModel<IRUnitT, PassT, AnalysisManagerT,
201 true> : PassConcept<IRUnitT, AnalysisManagerT> {
202 PassModel(PassT Pass) : Pass(llvm_move(Pass)) {}
203 virtual PassModel *clone() { return new PassModel(Pass); }
204 virtual PreservedAnalyses run(IRUnitT IR, AnalysisManagerT *AM) {
205 return Pass.run(IR, AM);
210 /// \brief Specialization of \c PassModel for passes that accept an analyis
212 template <typename IRUnitT, typename PassT, typename AnalysisManagerT>
213 struct PassModel<IRUnitT, PassT, AnalysisManagerT,
214 false> : PassConcept<IRUnitT, AnalysisManagerT> {
215 PassModel(PassT Pass) : Pass(llvm_move(Pass)) {}
216 virtual PassModel *clone() { return new PassModel(Pass); }
217 virtual PreservedAnalyses run(IRUnitT IR, AnalysisManagerT *AM) {
223 /// \brief Abstract concept of an analysis result.
225 /// This concept is parameterized over the IR unit that this result pertains
227 template <typename IRUnitT> struct AnalysisResultConcept {
228 virtual ~AnalysisResultConcept() {}
229 virtual AnalysisResultConcept *clone() = 0;
231 /// \brief Method to try and mark a result as invalid.
233 /// When the outer analysis manager detects a change in some underlying
234 /// unit of the IR, it will call this method on all of the results cached.
236 /// This method also receives a set of preserved analyses which can be used
237 /// to avoid invalidation because the pass which changed the underlying IR
238 /// took care to update or preserve the analysis result in some way.
240 /// \returns true if the result is indeed invalid (the default).
241 virtual bool invalidate(IRUnitT IR, const PreservedAnalyses &PA) = 0;
244 /// \brief SFINAE metafunction for computing whether \c ResultT provides an
245 /// \c invalidate member function.
246 template <typename IRUnitT, typename ResultT> class ResultHasInvalidateMethod {
247 typedef char SmallType;
248 struct BigType { char a, b; };
250 template <typename T, bool (T::*)(IRUnitT, const PreservedAnalyses &)>
253 template <typename T> static SmallType f(Checker<T, &T::invalidate> *);
254 template <typename T> static BigType f(...);
257 enum { Value = sizeof(f<ResultT>(0)) == sizeof(SmallType) };
260 /// \brief Wrapper to model the analysis result concept.
262 /// By default, this will implement the invalidate method with a trivial
263 /// implementation so that the actual analysis result doesn't need to provide
264 /// an invalidation handler. It is only selected when the invalidation handler
265 /// is not part of the ResultT's interface.
266 template <typename IRUnitT, typename PassT, typename ResultT,
267 bool HasInvalidateHandler =
268 ResultHasInvalidateMethod<IRUnitT, ResultT>::Value>
269 struct AnalysisResultModel;
271 /// \brief Specialization of \c AnalysisResultModel which provides the default
272 /// invalidate functionality.
273 template <typename IRUnitT, typename PassT, typename ResultT>
274 struct AnalysisResultModel<IRUnitT, PassT, ResultT,
275 false> : AnalysisResultConcept<IRUnitT> {
276 AnalysisResultModel(ResultT Result) : Result(llvm_move(Result)) {}
277 virtual AnalysisResultModel *clone() {
278 return new AnalysisResultModel(Result);
281 /// \brief The model bases invalidation solely on being in the preserved set.
283 // FIXME: We should actually use two different concepts for analysis results
284 // rather than two different models, and avoid the indirect function call for
285 // ones that use the trivial behavior.
286 virtual bool invalidate(IRUnitT, const PreservedAnalyses &PA) {
287 return !PA.preserved(PassT::ID());
293 /// \brief Specialization of \c AnalysisResultModel which delegates invalidate
294 /// handling to \c ResultT.
295 template <typename IRUnitT, typename PassT, typename ResultT>
296 struct AnalysisResultModel<IRUnitT, PassT, ResultT,
297 true> : AnalysisResultConcept<IRUnitT> {
298 AnalysisResultModel(ResultT Result) : Result(llvm_move(Result)) {}
299 virtual AnalysisResultModel *clone() {
300 return new AnalysisResultModel(Result);
303 /// \brief The model delegates to the \c ResultT method.
304 virtual bool invalidate(IRUnitT IR, const PreservedAnalyses &PA) {
305 return Result.invalidate(IR, PA);
311 /// \brief Abstract concept of an analysis pass.
313 /// This concept is parameterized over the IR unit that it can run over and
314 /// produce an analysis result.
315 template <typename IRUnitT> struct AnalysisPassConcept {
316 virtual ~AnalysisPassConcept() {}
317 virtual AnalysisPassConcept *clone() = 0;
319 /// \brief Method to run this analysis over a unit of IR.
320 /// \returns The analysis result object to be queried by users, the caller
322 virtual AnalysisResultConcept<IRUnitT> *run(IRUnitT IR) = 0;
325 /// \brief Wrapper to model the analysis pass concept.
327 /// Can wrap any type which implements a suitable \c run method. The method
328 /// must accept the IRUnitT as an argument and produce an object which can be
329 /// wrapped in a \c AnalysisResultModel.
330 template <typename IRUnitT, typename PassT>
331 struct AnalysisPassModel : AnalysisPassConcept<IRUnitT> {
332 AnalysisPassModel(PassT Pass) : Pass(llvm_move(Pass)) {}
333 virtual AnalysisPassModel *clone() { return new AnalysisPassModel(Pass); }
335 // FIXME: Replace PassT::Result with type traits when we use C++11.
336 typedef AnalysisResultModel<IRUnitT, PassT, typename PassT::Result>
339 /// \brief The model delegates to the \c PassT::run method.
341 /// The return is wrapped in an \c AnalysisResultModel.
342 virtual ResultModelT *run(IRUnitT IR) {
343 return new ResultModelT(Pass.run(IR));
351 class ModuleAnalysisManager;
353 class ModulePassManager {
355 explicit ModulePassManager() {}
357 /// \brief Run all of the module passes in this module pass manager over
360 /// This method should only be called for a single module as there is the
361 /// expectation that the lifetime of a pass is bounded to that of a module.
362 PreservedAnalyses run(Module *M, ModuleAnalysisManager *AM = 0);
364 template <typename ModulePassT> void addPass(ModulePassT Pass) {
365 Passes.push_back(new ModulePassModel<ModulePassT>(llvm_move(Pass)));
369 // Pull in the concept type and model template specialized for modules.
370 typedef detail::PassConcept<Module *, ModuleAnalysisManager> ModulePassConcept;
371 template <typename PassT>
372 struct ModulePassModel
373 : detail::PassModel<Module *, PassT, ModuleAnalysisManager> {
374 ModulePassModel(PassT Pass)
375 : detail::PassModel<Module *, PassT, ModuleAnalysisManager>(Pass) {}
378 std::vector<polymorphic_ptr<ModulePassConcept> > Passes;
381 class FunctionAnalysisManager;
383 class FunctionPassManager {
385 explicit FunctionPassManager() {}
387 template <typename FunctionPassT> void addPass(FunctionPassT Pass) {
388 Passes.push_back(new FunctionPassModel<FunctionPassT>(llvm_move(Pass)));
391 PreservedAnalyses run(Function *F, FunctionAnalysisManager *AM = 0);
394 // Pull in the concept type and model template specialized for functions.
395 typedef detail::PassConcept<Function *, FunctionAnalysisManager>
397 template <typename PassT>
398 struct FunctionPassModel
399 : detail::PassModel<Function *, PassT, FunctionAnalysisManager> {
400 FunctionPassModel(PassT Pass)
401 : detail::PassModel<Function *, PassT, FunctionAnalysisManager>(Pass) {}
404 std::vector<polymorphic_ptr<FunctionPassConcept> > Passes;
407 /// \brief A module analysis pass manager with lazy running and caching of
409 class ModuleAnalysisManager {
411 ModuleAnalysisManager() {}
413 /// \brief Get the result of an analysis pass for this module.
415 /// If there is not a valid cached result in the manager already, this will
416 /// re-run the analysis to produce a valid result.
417 template <typename PassT> const typename PassT::Result &getResult(Module *M) {
418 assert(ModuleAnalysisPasses.count(PassT::ID()) &&
419 "This analysis pass was not registered prior to being queried");
421 const detail::AnalysisResultConcept<Module *> &ResultConcept =
422 getResultImpl(PassT::ID(), M);
423 typedef detail::AnalysisResultModel<Module *, PassT, typename PassT::Result>
425 return static_cast<const ResultModelT &>(ResultConcept).Result;
428 /// \brief Register an analysis pass with the manager.
430 /// This provides an initialized and set-up analysis pass to the
432 /// manager. Whomever is setting up analysis passes must use this to
434 /// the manager with all of the analysis passes available.
435 template <typename PassT> void registerPass(PassT Pass) {
436 assert(!ModuleAnalysisPasses.count(PassT::ID()) &&
437 "Registered the same analysis pass twice!");
438 ModuleAnalysisPasses[PassT::ID()] =
439 new detail::AnalysisPassModel<Module *, PassT>(llvm_move(Pass));
442 /// \brief Invalidate a specific analysis pass for an IR module.
444 /// Note that the analysis result can disregard invalidation.
445 template <typename PassT> void invalidate(Module *M) {
446 assert(ModuleAnalysisPasses.count(PassT::ID()) &&
447 "This analysis pass was not registered prior to being invalidated");
448 invalidateImpl(PassT::ID(), M);
451 /// \brief Invalidate analyses cached for an IR Module.
453 /// Walk through all of the analyses pertaining to this module and invalidate
454 /// them unless they are preserved by the PreservedAnalyses set.
455 void invalidate(Module *M, const PreservedAnalyses &PA);
458 /// \brief Get a module pass result, running the pass if necessary.
459 const detail::AnalysisResultConcept<Module *> &getResultImpl(void *PassID,
462 /// \brief Invalidate a module pass result.
463 void invalidateImpl(void *PassID, Module *M);
465 /// \brief Map type from module analysis pass ID to pass concept pointer.
466 typedef DenseMap<void *,
467 polymorphic_ptr<detail::AnalysisPassConcept<Module *> > >
468 ModuleAnalysisPassMapT;
470 /// \brief Collection of module analysis passes, indexed by ID.
471 ModuleAnalysisPassMapT ModuleAnalysisPasses;
473 /// \brief Map type from module analysis pass ID to pass result concept pointer.
474 typedef DenseMap<void *,
475 polymorphic_ptr<detail::AnalysisResultConcept<Module *> > >
476 ModuleAnalysisResultMapT;
478 /// \brief Cache of computed module analysis results for this module.
479 ModuleAnalysisResultMapT ModuleAnalysisResults;
482 /// \brief A function analysis manager to coordinate and cache analyses run over
484 class FunctionAnalysisManager {
486 FunctionAnalysisManager() {}
488 /// \brief Get the result of an analysis pass for a function.
490 /// If there is not a valid cached result in the manager already, this will
491 /// re-run the analysis to produce a valid result.
492 template <typename PassT>
493 const typename PassT::Result &getResult(Function *F) {
494 assert(FunctionAnalysisPasses.count(PassT::ID()) &&
495 "This analysis pass was not registered prior to being queried");
497 const detail::AnalysisResultConcept<Function *> &ResultConcept =
498 getResultImpl(PassT::ID(), F);
499 typedef detail::AnalysisResultModel<Function *, PassT,
500 typename PassT::Result> ResultModelT;
501 return static_cast<const ResultModelT &>(ResultConcept).Result;
504 /// \brief Register an analysis pass with the manager.
506 /// This provides an initialized and set-up analysis pass to the
508 /// manager. Whomever is setting up analysis passes must use this to
510 /// the manager with all of the analysis passes available.
511 template <typename PassT> void registerPass(PassT Pass) {
512 assert(!FunctionAnalysisPasses.count(PassT::ID()) &&
513 "Registered the same analysis pass twice!");
514 FunctionAnalysisPasses[PassT::ID()] =
515 new detail::AnalysisPassModel<Function *, PassT>(llvm_move(Pass));
518 /// \brief Invalidate a specific analysis pass for an IR module.
520 /// Note that the analysis result can disregard invalidation.
521 template <typename PassT> void invalidate(Function *F) {
522 assert(FunctionAnalysisPasses.count(PassT::ID()) &&
523 "This analysis pass was not registered prior to being invalidated");
524 invalidateImpl(PassT::ID(), F);
527 /// \brief Invalidate analyses cached for an IR Function.
529 /// Walk through all of the analyses cache for this IR function and
530 /// invalidate them unless they are preserved by the provided
531 /// PreservedAnalyses set.
532 void invalidate(Function *F, const PreservedAnalyses &PA);
534 /// \brief Returns true if the analysis manager has an empty results cache.
537 /// \brief Clear the function analysis result cache.
539 /// This routine allows cleaning up when the set of functions itself has
540 /// potentially changed, and thus we can't even look up a a result and
541 /// invalidate it directly. Notably, this does *not* call invalidate
542 /// functions as there is nothing to be done for them.
546 /// \brief Get a function pass result, running the pass if necessary.
547 const detail::AnalysisResultConcept<Function *> &getResultImpl(void *PassID,
550 /// \brief Invalidate a function pass result.
551 void invalidateImpl(void *PassID, Function *F);
553 /// \brief Map type from function analysis pass ID to pass concept pointer.
554 typedef DenseMap<void *,
555 polymorphic_ptr<detail::AnalysisPassConcept<Function *> > >
556 FunctionAnalysisPassMapT;
558 /// \brief Collection of function analysis passes, indexed by ID.
559 FunctionAnalysisPassMapT FunctionAnalysisPasses;
561 /// \brief List of function analysis pass IDs and associated concept pointers.
563 /// Requires iterators to be valid across appending new entries and arbitrary
564 /// erases. Provides both the pass ID and concept pointer such that it is
565 /// half of a bijection and provides storage for the actual result concept.
566 typedef std::list<std::pair<
567 void *, polymorphic_ptr<detail::AnalysisResultConcept<Function *> > > >
568 FunctionAnalysisResultListT;
570 /// \brief Map type from function pointer to our custom list type.
571 typedef DenseMap<Function *, FunctionAnalysisResultListT>
572 FunctionAnalysisResultListMapT;
574 /// \brief Map from function to a list of function analysis results.
576 /// Provides linear time removal of all analysis results for a function and
577 /// the ultimate storage for a particular cached analysis result.
578 FunctionAnalysisResultListMapT FunctionAnalysisResultLists;
580 /// \brief Map type from a pair of analysis ID and function pointer to an
581 /// iterator into a particular result list.
582 typedef DenseMap<std::pair<void *, Function *>,
583 FunctionAnalysisResultListT::iterator>
584 FunctionAnalysisResultMapT;
586 /// \brief Map from an analysis ID and function to a particular cached
588 FunctionAnalysisResultMapT FunctionAnalysisResults;
591 /// \brief A module analysis which acts as a proxy for a function analysis
594 /// This primarily proxies invalidation information from the module analysis
595 /// manager and module pass manager to a function analysis manager. You should
596 /// never use a function analysis manager from within (transitively) a module
597 /// pass manager unless your parent module pass has received a proxy result
600 /// FIXME: It might be really nice to "enforce" this (softly) by making this
601 /// proxy the API path to access a function analysis manager within a module
603 class FunctionAnalysisManagerModuleProxy {
607 static void *ID() { return (void *)&PassID; }
609 FunctionAnalysisManagerModuleProxy(FunctionAnalysisManager &FAM) : FAM(FAM) {}
611 /// \brief Run the analysis pass and create our proxy result object.
613 /// This doesn't do any interesting work, it is primarily used to insert our
614 /// proxy result object into the module analysis cache so that we can proxy
615 /// invalidation to the function analysis manager.
617 /// In debug builds, it will also assert that the analysis manager is empty
618 /// as no queries should arrive at the function analysis manager prior to
619 /// this analysis being requested.
620 Result run(Module *M);
625 FunctionAnalysisManager &FAM;
628 /// \brief The result proxy object for the
629 /// \c FunctionAnalysisManagerModuleProxy.
631 /// See its documentation for more information.
632 class FunctionAnalysisManagerModuleProxy::Result {
634 Result(FunctionAnalysisManager &FAM) : FAM(FAM) {}
637 /// \brief Accessor for the \c FunctionAnalysisManager.
638 FunctionAnalysisManager &getManager() const { return FAM; }
640 /// \brief Handler for invalidation of the module.
642 /// If this analysis itself is preserved, then we assume that the set of \c
643 /// Function objects in the \c Module hasn't changed and thus we don't need
644 /// to invalidate *all* cached data associated with a \c Function* in the \c
645 /// FunctionAnalysisManager.
647 /// Regardless of whether this analysis is marked as preserved, all of the
648 /// analyses in the \c FunctionAnalysisManager are potentially invalidated
649 /// based on the set of preserved analyses.
650 bool invalidate(Module *M, const PreservedAnalyses &PA);
653 FunctionAnalysisManager &FAM;
656 /// \brief Trivial adaptor that maps from a module to its functions.
658 /// Designed to allow composition of a FunctionPass(Manager) and
659 /// a ModulePassManager. Note that if this pass is constructed with a pointer
660 /// to a \c ModuleAnalysisManager it will run the
661 /// \c FunctionAnalysisManagerModuleProxy analysis prior to running the function
662 /// pass over the module to enable a \c FunctionAnalysisManager to be used
663 /// within this run safely.
664 template <typename FunctionPassT>
665 class ModuleToFunctionPassAdaptor {
667 explicit ModuleToFunctionPassAdaptor(FunctionPassT Pass)
668 : Pass(llvm_move(Pass)) {}
670 /// \brief Runs the function pass across every function in the module.
671 PreservedAnalyses run(Module *M, ModuleAnalysisManager *AM) {
672 FunctionAnalysisManager *FAM = 0;
674 // Setup the function analysis manager from its proxy.
675 FAM = &AM->getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
677 PreservedAnalyses PA = PreservedAnalyses::all();
678 for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) {
679 PreservedAnalyses PassPA = Pass.run(I, FAM);
680 PA.intersect(llvm_move(PassPA));
683 // By definition we preserve the proxy.
684 PA.preserve<FunctionAnalysisManagerModuleProxy>();
692 /// \brief A function to deduce a function pass type and wrap it in the
693 /// templated adaptor.
694 template <typename FunctionPassT>
695 ModuleToFunctionPassAdaptor<FunctionPassT>
696 createModuleToFunctionPassAdaptor(FunctionPassT Pass) {
697 return ModuleToFunctionPassAdaptor<FunctionPassT>(llvm_move(Pass));