LLVM  14.0.0git
PassManager.h
Go to the documentation of this file.
1 //===- PassManager.h - Pass management infrastructure -----------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 ///
10 /// This header defines various interfaces for pass management in LLVM. There
11 /// is no "pass" interface in LLVM per se. Instead, an instance of any class
12 /// which supports a method to 'run' it over a unit of IR can be used as
13 /// a pass. A pass manager is generally a tool to collect a sequence of passes
14 /// which run over a particular IR construct, and run each of them in sequence
15 /// over each such construct in the containing IR construct. As there is no
16 /// containing IR construct for a Module, a manager for passes over modules
17 /// forms the base case which runs its managed passes in sequence over the
18 /// single module provided.
19 ///
20 /// The core IR library provides managers for running passes over
21 /// modules and functions.
22 ///
23 /// * FunctionPassManager can run over a Module, runs each pass over
24 /// a Function.
25 /// * ModulePassManager must be directly run, runs each pass over the Module.
26 ///
27 /// Note that the implementations of the pass managers use concept-based
28 /// polymorphism as outlined in the "Value Semantics and Concept-based
29 /// Polymorphism" talk (or its abbreviated sibling "Inheritance Is The Base
30 /// Class of Evil") by Sean Parent:
31 /// * http://github.com/sean-parent/sean-parent.github.com/wiki/Papers-and-Presentations
32 /// * http://www.youtube.com/watch?v=_BpMYeUFXv8
33 /// * http://channel9.msdn.com/Events/GoingNative/2013/Inheritance-Is-The-Base-Class-of-Evil
34 ///
35 //===----------------------------------------------------------------------===//
36 
37 #ifndef LLVM_IR_PASSMANAGER_H
38 #define LLVM_IR_PASSMANAGER_H
39 
40 #include "llvm/ADT/DenseMap.h"
41 #include "llvm/ADT/STLExtras.h"
42 #include "llvm/ADT/SmallPtrSet.h"
43 #include "llvm/ADT/StringRef.h"
44 #include "llvm/ADT/TinyPtrVector.h"
45 #include "llvm/IR/Function.h"
46 #include "llvm/IR/Module.h"
49 #include "llvm/Pass.h"
50 #include "llvm/Support/Debug.h"
52 #include "llvm/Support/TypeName.h"
53 #include <algorithm>
54 #include <cassert>
55 #include <cstring>
56 #include <iterator>
57 #include <list>
58 #include <memory>
59 #include <tuple>
60 #include <type_traits>
61 #include <utility>
62 #include <vector>
63 
64 namespace llvm {
65 
66 /// A special type used by analysis passes to provide an address that
67 /// identifies that particular analysis pass type.
68 ///
69 /// Analysis passes should have a static data member of this type and derive
70 /// from the \c AnalysisInfoMixin to get a static ID method used to identify
71 /// the analysis in the pass management infrastructure.
72 struct alignas(8) AnalysisKey {};
73 
74 /// A special type used to provide an address that identifies a set of related
75 /// analyses. These sets are primarily used below to mark sets of analyses as
76 /// preserved.
77 ///
78 /// For example, a transformation can indicate that it preserves the CFG of a
79 /// function by preserving the appropriate AnalysisSetKey. An analysis that
80 /// depends only on the CFG can then check if that AnalysisSetKey is preserved;
81 /// if it is, the analysis knows that it itself is preserved.
82 struct alignas(8) AnalysisSetKey {};
83 
84 /// This templated class represents "all analyses that operate over <a
85 /// particular IR unit>" (e.g. a Function or a Module) in instances of
86 /// PreservedAnalysis.
87 ///
88 /// This lets a transformation say e.g. "I preserved all function analyses".
89 ///
90 /// Note that you must provide an explicit instantiation declaration and
91 /// definition for this template in order to get the correct behavior on
92 /// Windows. Otherwise, the address of SetKey will not be stable.
93 template <typename IRUnitT> class AllAnalysesOn {
94 public:
95  static AnalysisSetKey *ID() { return &SetKey; }
96 
97 private:
98  static AnalysisSetKey SetKey;
99 };
100 
101 template <typename IRUnitT> AnalysisSetKey AllAnalysesOn<IRUnitT>::SetKey;
102 
103 extern template class AllAnalysesOn<Module>;
104 extern template class AllAnalysesOn<Function>;
105 
106 /// Represents analyses that only rely on functions' control flow.
107 ///
108 /// This can be used with \c PreservedAnalyses to mark the CFG as preserved and
109 /// to query whether it has been preserved.
110 ///
111 /// The CFG of a function is defined as the set of basic blocks and the edges
112 /// between them. Changing the set of basic blocks in a function is enough to
113 /// mutate the CFG. Mutating the condition of a branch or argument of an
114 /// invoked function does not mutate the CFG, but changing the successor labels
115 /// of those instructions does.
116 class CFGAnalyses {
117 public:
118  static AnalysisSetKey *ID() { return &SetKey; }
119 
120 private:
121  static AnalysisSetKey SetKey;
122 };
123 
124 /// A set of analyses that are preserved following a run of a transformation
125 /// pass.
126 ///
127 /// Transformation passes build and return these objects to communicate which
128 /// analyses are still valid after the transformation. For most passes this is
129 /// fairly simple: if they don't change anything all analyses are preserved,
130 /// otherwise only a short list of analyses that have been explicitly updated
131 /// are preserved.
132 ///
133 /// This class also lets transformation passes mark abstract *sets* of analyses
134 /// as preserved. A transformation that (say) does not alter the CFG can
135 /// indicate such by marking a particular AnalysisSetKey as preserved, and
136 /// then analyses can query whether that AnalysisSetKey is preserved.
137 ///
138 /// Finally, this class can represent an "abandoned" analysis, which is
139 /// not preserved even if it would be covered by some abstract set of analyses.
140 ///
141 /// Given a `PreservedAnalyses` object, an analysis will typically want to
142 /// figure out whether it is preserved. In the example below, MyAnalysisType is
143 /// preserved if it's not abandoned, and (a) it's explicitly marked as
144 /// preserved, (b), the set AllAnalysesOn<MyIRUnit> is preserved, or (c) both
145 /// AnalysisSetA and AnalysisSetB are preserved.
146 ///
147 /// ```
148 /// auto PAC = PA.getChecker<MyAnalysisType>();
149 /// if (PAC.preserved() || PAC.preservedSet<AllAnalysesOn<MyIRUnit>>() ||
150 /// (PAC.preservedSet<AnalysisSetA>() &&
151 /// PAC.preservedSet<AnalysisSetB>())) {
152 /// // The analysis has been successfully preserved ...
153 /// }
154 /// ```
156 public:
157  /// Convenience factory function for the empty preserved set.
158  static PreservedAnalyses none() { return PreservedAnalyses(); }
159 
160  /// Construct a special preserved set that preserves all passes.
163  PA.PreservedIDs.insert(&AllAnalysesKey);
164  return PA;
165  }
166 
167  /// Construct a preserved analyses object with a single preserved set.
168  template <typename AnalysisSetT>
171  PA.preserveSet<AnalysisSetT>();
172  return PA;
173  }
174 
175  /// Mark an analysis as preserved.
176  template <typename AnalysisT> void preserve() { preserve(AnalysisT::ID()); }
177 
178  /// Given an analysis's ID, mark the analysis as preserved, adding it
179  /// to the set.
181  // Clear this ID from the explicit not-preserved set if present.
182  NotPreservedAnalysisIDs.erase(ID);
183 
184  // If we're not already preserving all analyses (other than those in
185  // NotPreservedAnalysisIDs).
186  if (!areAllPreserved())
187  PreservedIDs.insert(ID);
188  }
189 
190  /// Mark an analysis set as preserved.
191  template <typename AnalysisSetT> void preserveSet() {
192  preserveSet(AnalysisSetT::ID());
193  }
194 
195  /// Mark an analysis set as preserved using its ID.
197  // If we're not already in the saturated 'all' state, add this set.
198  if (!areAllPreserved())
199  PreservedIDs.insert(ID);
200  }
201 
202  /// Mark an analysis as abandoned.
203  ///
204  /// An abandoned analysis is not preserved, even if it is nominally covered
205  /// by some other set or was previously explicitly marked as preserved.
206  ///
207  /// Note that you can only abandon a specific analysis, not a *set* of
208  /// analyses.
209  template <typename AnalysisT> void abandon() { abandon(AnalysisT::ID()); }
210 
211  /// Mark an analysis as abandoned using its ID.
212  ///
213  /// An abandoned analysis is not preserved, even if it is nominally covered
214  /// by some other set or was previously explicitly marked as preserved.
215  ///
216  /// Note that you can only abandon a specific analysis, not a *set* of
217  /// analyses.
219  PreservedIDs.erase(ID);
220  NotPreservedAnalysisIDs.insert(ID);
221  }
222 
223  /// Intersect this set with another in place.
224  ///
225  /// This is a mutating operation on this preserved set, removing all
226  /// preserved passes which are not also preserved in the argument.
228  if (Arg.areAllPreserved())
229  return;
230  if (areAllPreserved()) {
231  *this = Arg;
232  return;
233  }
234  // The intersection requires the *union* of the explicitly not-preserved
235  // IDs and the *intersection* of the preserved IDs.
236  for (auto ID : Arg.NotPreservedAnalysisIDs) {
237  PreservedIDs.erase(ID);
238  NotPreservedAnalysisIDs.insert(ID);
239  }
240  for (auto ID : PreservedIDs)
241  if (!Arg.PreservedIDs.count(ID))
242  PreservedIDs.erase(ID);
243  }
244 
245  /// Intersect this set with a temporary other set in place.
246  ///
247  /// This is a mutating operation on this preserved set, removing all
248  /// preserved passes which are not also preserved in the argument.
250  if (Arg.areAllPreserved())
251  return;
252  if (areAllPreserved()) {
253  *this = std::move(Arg);
254  return;
255  }
256  // The intersection requires the *union* of the explicitly not-preserved
257  // IDs and the *intersection* of the preserved IDs.
258  for (auto ID : Arg.NotPreservedAnalysisIDs) {
259  PreservedIDs.erase(ID);
260  NotPreservedAnalysisIDs.insert(ID);
261  }
262  for (auto ID : PreservedIDs)
263  if (!Arg.PreservedIDs.count(ID))
264  PreservedIDs.erase(ID);
265  }
266 
267  /// A checker object that makes it easy to query for whether an analysis or
268  /// some set covering it is preserved.
270  friend class PreservedAnalyses;
271 
272  const PreservedAnalyses &PA;
273  AnalysisKey *const ID;
274  const bool IsAbandoned;
275 
276  /// A PreservedAnalysisChecker is tied to a particular Analysis because
277  /// `preserved()` and `preservedSet()` both return false if the Analysis
278  /// was abandoned.
280  : PA(PA), ID(ID), IsAbandoned(PA.NotPreservedAnalysisIDs.count(ID)) {}
281 
282  public:
283  /// Returns true if the checker's analysis was not abandoned and either
284  /// - the analysis is explicitly preserved or
285  /// - all analyses are preserved.
286  bool preserved() {
287  return !IsAbandoned && (PA.PreservedIDs.count(&AllAnalysesKey) ||
288  PA.PreservedIDs.count(ID));
289  }
290 
291  /// Return true if the checker's analysis was not abandoned, i.e. it was not
292  /// explicitly invalidated. Even if the analysis is not explicitly
293  /// preserved, if the analysis is known stateless, then it is preserved.
295  return !IsAbandoned;
296  }
297 
298  /// Returns true if the checker's analysis was not abandoned and either
299  /// - \p AnalysisSetT is explicitly preserved or
300  /// - all analyses are preserved.
301  template <typename AnalysisSetT> bool preservedSet() {
302  AnalysisSetKey *SetID = AnalysisSetT::ID();
303  return !IsAbandoned && (PA.PreservedIDs.count(&AllAnalysesKey) ||
304  PA.PreservedIDs.count(SetID));
305  }
306  };
307 
308  /// Build a checker for this `PreservedAnalyses` and the specified analysis
309  /// type.
310  ///
311  /// You can use the returned object to query whether an analysis was
312  /// preserved. See the example in the comment on `PreservedAnalysis`.
313  template <typename AnalysisT> PreservedAnalysisChecker getChecker() const {
314  return PreservedAnalysisChecker(*this, AnalysisT::ID());
315  }
316 
317  /// Build a checker for this `PreservedAnalyses` and the specified analysis
318  /// ID.
319  ///
320  /// You can use the returned object to query whether an analysis was
321  /// preserved. See the example in the comment on `PreservedAnalysis`.
323  return PreservedAnalysisChecker(*this, ID);
324  }
325 
326  /// Test whether all analyses are preserved (and none are abandoned).
327  ///
328  /// This is used primarily to optimize for the common case of a transformation
329  /// which makes no changes to the IR.
330  bool areAllPreserved() const {
331  return NotPreservedAnalysisIDs.empty() &&
332  PreservedIDs.count(&AllAnalysesKey);
333  }
334 
335  /// Directly test whether a set of analyses is preserved.
336  ///
337  /// This is only true when no analyses have been explicitly abandoned.
338  template <typename AnalysisSetT> bool allAnalysesInSetPreserved() const {
339  return allAnalysesInSetPreserved(AnalysisSetT::ID());
340  }
341 
342  /// Directly test whether a set of analyses is preserved.
343  ///
344  /// This is only true when no analyses have been explicitly abandoned.
346  return NotPreservedAnalysisIDs.empty() &&
347  (PreservedIDs.count(&AllAnalysesKey) || PreservedIDs.count(SetID));
348  }
349 
350 private:
351  /// A special key used to indicate all analyses.
352  static AnalysisSetKey AllAnalysesKey;
353 
354  /// The IDs of analyses and analysis sets that are preserved.
355  SmallPtrSet<void *, 2> PreservedIDs;
356 
357  /// The IDs of explicitly not-preserved analyses.
358  ///
359  /// If an analysis in this set is covered by a set in `PreservedIDs`, we
360  /// consider it not-preserved. That is, `NotPreservedAnalysisIDs` always
361  /// "wins" over analysis sets in `PreservedIDs`.
362  ///
363  /// Also, a given ID should never occur both here and in `PreservedIDs`.
364  SmallPtrSet<AnalysisKey *, 2> NotPreservedAnalysisIDs;
365 };
366 
367 // Forward declare the analysis manager template.
368 template <typename IRUnitT, typename... ExtraArgTs> class AnalysisManager;
369 
370 /// A CRTP mix-in to automatically provide informational APIs needed for
371 /// passes.
372 ///
373 /// This provides some boilerplate for types that are passes.
374 template <typename DerivedT> struct PassInfoMixin {
375  /// Gets the name of the pass we are mixed into.
376  static StringRef name() {
377  static_assert(std::is_base_of<PassInfoMixin, DerivedT>::value,
378  "Must pass the derived type as the template argument!");
379  StringRef Name = getTypeName<DerivedT>();
380  Name.consume_front("llvm::");
381  return Name;
382  }
383 
385  function_ref<StringRef(StringRef)> MapClassName2PassName) {
386  StringRef ClassName = DerivedT::name();
387  auto PassName = MapClassName2PassName(ClassName);
388  OS << PassName;
389  }
390 };
391 
392 /// A CRTP mix-in that provides informational APIs needed for analysis passes.
393 ///
394 /// This provides some boilerplate for types that are analysis passes. It
395 /// automatically mixes in \c PassInfoMixin.
396 template <typename DerivedT>
397 struct AnalysisInfoMixin : PassInfoMixin<DerivedT> {
398  /// Returns an opaque, unique ID for this analysis type.
399  ///
400  /// This ID is a pointer type that is guaranteed to be 8-byte aligned and thus
401  /// suitable for use in sets, maps, and other data structures that use the low
402  /// bits of pointers.
403  ///
404  /// Note that this requires the derived type provide a static \c AnalysisKey
405  /// member called \c Key.
406  ///
407  /// FIXME: The only reason the mixin type itself can't declare the Key value
408  /// is that some compilers cannot correctly unique a templated static variable
409  /// so it has the same addresses in each instantiation. The only currently
410  /// known platform with this limitation is Windows DLL builds, specifically
411  /// building each part of LLVM as a DLL. If we ever remove that build
412  /// configuration, this mixin can provide the static key as well.
413  static AnalysisKey *ID() {
414  static_assert(std::is_base_of<AnalysisInfoMixin, DerivedT>::value,
415  "Must pass the derived type as the template argument!");
416  return &DerivedT::Key;
417  }
418 };
419 
420 namespace detail {
421 
422 /// Actual unpacker of extra arguments in getAnalysisResult,
423 /// passes only those tuple arguments that are mentioned in index_sequence.
424 template <typename PassT, typename IRUnitT, typename AnalysisManagerT,
425  typename... ArgTs, size_t... Ns>
426 typename PassT::Result
427 getAnalysisResultUnpackTuple(AnalysisManagerT &AM, IRUnitT &IR,
428  std::tuple<ArgTs...> Args,
429  std::index_sequence<Ns...>) {
430  (void)Args;
431  return AM.template getResult<PassT>(IR, std::get<Ns>(Args)...);
432 }
433 
434 /// Helper for *partial* unpacking of extra arguments in getAnalysisResult.
435 ///
436 /// Arguments passed in tuple come from PassManager, so they might have extra
437 /// arguments after those AnalysisManager's ExtraArgTs ones that we need to
438 /// pass to getResult.
439 template <typename PassT, typename IRUnitT, typename... AnalysisArgTs,
440  typename... MainArgTs>
441 typename PassT::Result
443  std::tuple<MainArgTs...> Args) {
445  PassT, IRUnitT>)(AM, IR, Args,
446  std::index_sequence_for<AnalysisArgTs...>{});
447 }
448 
449 } // namespace detail
450 
451 // Forward declare the pass instrumentation analysis explicitly queried in
452 // generic PassManager code.
453 // FIXME: figure out a way to move PassInstrumentationAnalysis into its own
454 // header.
455 class PassInstrumentationAnalysis;
456 
457 /// Manages a sequence of passes over a particular unit of IR.
458 ///
459 /// A pass manager contains a sequence of passes to run over a particular unit
460 /// of IR (e.g. Functions, Modules). It is itself a valid pass over that unit of
461 /// IR, and when run over some given IR will run each of its contained passes in
462 /// sequence. Pass managers are the primary and most basic building block of a
463 /// pass pipeline.
464 ///
465 /// When you run a pass manager, you provide an \c AnalysisManager<IRUnitT>
466 /// argument. The pass manager will propagate that analysis manager to each
467 /// pass it runs, and will call the analysis manager's invalidation routine with
468 /// the PreservedAnalyses of each pass it runs.
469 template <typename IRUnitT,
470  typename AnalysisManagerT = AnalysisManager<IRUnitT>,
471  typename... ExtraArgTs>
472 class PassManager : public PassInfoMixin<
473  PassManager<IRUnitT, AnalysisManagerT, ExtraArgTs...>> {
474 public:
475  /// Construct a pass manager.
476  explicit PassManager() {}
477 
478  // FIXME: These are equivalent to the default move constructor/move
479  // assignment. However, using = default triggers linker errors due to the
480  // explicit instantiations below. Find away to use the default and remove the
481  // duplicated code here.
483 
485  Passes = std::move(RHS.Passes);
486  return *this;
487  }
488 
490  function_ref<StringRef(StringRef)> MapClassName2PassName) {
491  for (unsigned Idx = 0, Size = Passes.size(); Idx != Size; ++Idx) {
492  auto *P = Passes[Idx].get();
493  P->printPipeline(OS, MapClassName2PassName);
494  if (Idx + 1 < Size)
495  OS << ",";
496  }
497  }
498 
499  /// Run all of the passes in this manager over the given unit of IR.
500  /// ExtraArgs are passed to each pass.
501  PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT &AM,
502  ExtraArgTs... ExtraArgs) {
504 
505  // Request PassInstrumentation from analysis manager, will use it to run
506  // instrumenting callbacks for the passes later.
507  // Here we use std::tuple wrapper over getResult which helps to extract
508  // AnalysisManager's arguments out of the whole ExtraArgs set.
510  detail::getAnalysisResult<PassInstrumentationAnalysis>(
511  AM, IR, std::tuple<ExtraArgTs...>(ExtraArgs...));
512 
513  for (unsigned Idx = 0, Size = Passes.size(); Idx != Size; ++Idx) {
514  auto *P = Passes[Idx].get();
515 
516  // Check the PassInstrumentation's BeforePass callbacks before running the
517  // pass, skip its execution completely if asked to (callback returns
518  // false).
519  if (!PI.runBeforePass<IRUnitT>(*P, IR))
520  continue;
521 
522  PreservedAnalyses PassPA;
523  {
524  TimeTraceScope TimeScope(P->name(), IR.getName());
525  PassPA = P->run(IR, AM, ExtraArgs...);
526  }
527 
528  // Call onto PassInstrumentation's AfterPass callbacks immediately after
529  // running the pass.
530  PI.runAfterPass<IRUnitT>(*P, IR, PassPA);
531 
532  // Update the analysis manager as each pass runs and potentially
533  // invalidates analyses.
534  AM.invalidate(IR, PassPA);
535 
536  // Finally, intersect the preserved analyses to compute the aggregate
537  // preserved set for this pass manager.
538  PA.intersect(std::move(PassPA));
539  }
540 
541  // Invalidation was handled after each pass in the above loop for the
542  // current unit of IR. Therefore, the remaining analysis results in the
543  // AnalysisManager are preserved. We mark this with a set so that we don't
544  // need to inspect each one individually.
546 
547  return PA;
548  }
549 
550  template <typename PassT>
551  std::enable_if_t<!std::is_same<PassT, PassManager>::value>
552  addPass(PassT &&Pass) {
553  using PassModelT =
554  detail::PassModel<IRUnitT, PassT, PreservedAnalyses, AnalysisManagerT,
555  ExtraArgTs...>;
556 
557  Passes.emplace_back(new PassModelT(std::forward<PassT>(Pass)));
558  }
559 
560  /// When adding a pass manager pass that has the same type as this pass
561  /// manager, simply move the passes over. This is because we don't have use
562  /// cases rely on executing nested pass managers. Doing this could reduce
563  /// implementation complexity and avoid potential invalidation issues that may
564  /// happen with nested pass managers of the same type.
565  template <typename PassT>
566  std::enable_if_t<std::is_same<PassT, PassManager>::value>
567  addPass(PassT &&Pass) {
568  for (auto &P : Pass.Passes)
569  Passes.emplace_back(std::move(P));
570  }
571 
572  /// Returns if the pass manager contains any passes.
573  bool isEmpty() const { return Passes.empty(); }
574 
575  static bool isRequired() { return true; }
576 
577 protected:
578  using PassConceptT =
579  detail::PassConcept<IRUnitT, AnalysisManagerT, ExtraArgTs...>;
580 
581  std::vector<std::unique_ptr<PassConceptT>> Passes;
582 };
583 
584 extern template class PassManager<Module>;
585 
586 /// Convenience typedef for a pass manager over modules.
588 
589 extern template class PassManager<Function>;
590 
591 /// Convenience typedef for a pass manager over functions.
593 
594 /// Pseudo-analysis pass that exposes the \c PassInstrumentation to pass
595 /// managers. Goes before AnalysisManager definition to provide its
596 /// internals (e.g PassInstrumentationAnalysis::ID) for use there if needed.
597 /// FIXME: figure out a way to move PassInstrumentationAnalysis into its own
598 /// header.
602  static AnalysisKey Key;
603 
604  PassInstrumentationCallbacks *Callbacks;
605 
606 public:
607  /// PassInstrumentationCallbacks object is shared, owned by something else,
608  /// not this analysis.
610  : Callbacks(Callbacks) {}
611 
613 
614  template <typename IRUnitT, typename AnalysisManagerT, typename... ExtraArgTs>
615  Result run(IRUnitT &, AnalysisManagerT &, ExtraArgTs &&...) {
616  return PassInstrumentation(Callbacks);
617  }
618 };
619 
620 /// A container for analyses that lazily runs them and caches their
621 /// results.
622 ///
623 /// This class can manage analyses for any IR unit where the address of the IR
624 /// unit sufficies as its identity.
625 template <typename IRUnitT, typename... ExtraArgTs> class AnalysisManager {
626 public:
627  class Invalidator;
628 
629 private:
630  // Now that we've defined our invalidator, we can define the concept types.
631  using ResultConceptT =
632  detail::AnalysisResultConcept<IRUnitT, PreservedAnalyses, Invalidator>;
633  using PassConceptT =
634  detail::AnalysisPassConcept<IRUnitT, PreservedAnalyses, Invalidator,
635  ExtraArgTs...>;
636 
637  /// List of analysis pass IDs and associated concept pointers.
638  ///
639  /// Requires iterators to be valid across appending new entries and arbitrary
640  /// erases. Provides the analysis ID to enable finding iterators to a given
641  /// entry in maps below, and provides the storage for the actual result
642  /// concept.
643  using AnalysisResultListT =
644  std::list<std::pair<AnalysisKey *, std::unique_ptr<ResultConceptT>>>;
645 
646  /// Map type from IRUnitT pointer to our custom list type.
647  using AnalysisResultListMapT = DenseMap<IRUnitT *, AnalysisResultListT>;
648 
649  /// Map type from a pair of analysis ID and IRUnitT pointer to an
650  /// iterator into a particular result list (which is where the actual analysis
651  /// result is stored).
652  using AnalysisResultMapT =
653  DenseMap<std::pair<AnalysisKey *, IRUnitT *>,
654  typename AnalysisResultListT::iterator>;
655 
656 public:
657  /// API to communicate dependencies between analyses during invalidation.
658  ///
659  /// When an analysis result embeds handles to other analysis results, it
660  /// needs to be invalidated both when its own information isn't preserved and
661  /// when any of its embedded analysis results end up invalidated. We pass an
662  /// \c Invalidator object as an argument to \c invalidate() in order to let
663  /// the analysis results themselves define the dependency graph on the fly.
664  /// This lets us avoid building an explicit representation of the
665  /// dependencies between analysis results.
666  class Invalidator {
667  public:
668  /// Trigger the invalidation of some other analysis pass if not already
669  /// handled and return whether it was in fact invalidated.
670  ///
671  /// This is expected to be called from within a given analysis result's \c
672  /// invalidate method to trigger a depth-first walk of all inter-analysis
673  /// dependencies. The same \p IR unit and \p PA passed to that result's \c
674  /// invalidate method should in turn be provided to this routine.
675  ///
676  /// The first time this is called for a given analysis pass, it will call
677  /// the corresponding result's \c invalidate method. Subsequent calls will
678  /// use a cache of the results of that initial call. It is an error to form
679  /// cyclic dependencies between analysis results.
680  ///
681  /// This returns true if the given analysis's result is invalid. Any
682  /// dependecies on it will become invalid as a result.
683  template <typename PassT>
684  bool invalidate(IRUnitT &IR, const PreservedAnalyses &PA) {
685  using ResultModelT =
686  detail::AnalysisResultModel<IRUnitT, PassT, typename PassT::Result,
688 
689  return invalidateImpl<ResultModelT>(PassT::ID(), IR, PA);
690  }
691 
692  /// A type-erased variant of the above invalidate method with the same core
693  /// API other than passing an analysis ID rather than an analysis type
694  /// parameter.
695  ///
696  /// This is sadly less efficient than the above routine, which leverages
697  /// the type parameter to avoid the type erasure overhead.
698  bool invalidate(AnalysisKey *ID, IRUnitT &IR, const PreservedAnalyses &PA) {
699  return invalidateImpl<>(ID, IR, PA);
700  }
701 
702  private:
703  friend class AnalysisManager;
704 
705  template <typename ResultT = ResultConceptT>
706  bool invalidateImpl(AnalysisKey *ID, IRUnitT &IR,
707  const PreservedAnalyses &PA) {
708  // If we've already visited this pass, return true if it was invalidated
709  // and false otherwise.
710  auto IMapI = IsResultInvalidated.find(ID);
711  if (IMapI != IsResultInvalidated.end())
712  return IMapI->second;
713 
714  // Otherwise look up the result object.
715  auto RI = Results.find({ID, &IR});
716  assert(RI != Results.end() &&
717  "Trying to invalidate a dependent result that isn't in the "
718  "manager's cache is always an error, likely due to a stale result "
719  "handle!");
720 
721  auto &Result = static_cast<ResultT &>(*RI->second->second);
722 
723  // Insert into the map whether the result should be invalidated and return
724  // that. Note that we cannot reuse IMapI and must do a fresh insert here,
725  // as calling invalidate could (recursively) insert things into the map,
726  // making any iterator or reference invalid.
727  bool Inserted;
728  std::tie(IMapI, Inserted) =
729  IsResultInvalidated.insert({ID, Result.invalidate(IR, PA, *this)});
730  (void)Inserted;
731  assert(Inserted && "Should not have already inserted this ID, likely "
732  "indicates a dependency cycle!");
733  return IMapI->second;
734  }
735 
736  Invalidator(SmallDenseMap<AnalysisKey *, bool, 8> &IsResultInvalidated,
737  const AnalysisResultMapT &Results)
738  : IsResultInvalidated(IsResultInvalidated), Results(Results) {}
739 
740  SmallDenseMap<AnalysisKey *, bool, 8> &IsResultInvalidated;
741  const AnalysisResultMapT &Results;
742  };
743 
744  /// Construct an empty analysis manager.
745  AnalysisManager();
748 
749  /// Returns true if the analysis manager has an empty results cache.
750  bool empty() const {
751  assert(AnalysisResults.empty() == AnalysisResultLists.empty() &&
752  "The storage and index of analysis results disagree on how many "
753  "there are!");
754  return AnalysisResults.empty();
755  }
756 
757  /// Clear any cached analysis results for a single unit of IR.
758  ///
759  /// This doesn't invalidate, but instead simply deletes, the relevant results.
760  /// It is useful when the IR is being removed and we want to clear out all the
761  /// memory pinned for it.
762  void clear(IRUnitT &IR, llvm::StringRef Name);
763 
764  /// Clear all analysis results cached by this AnalysisManager.
765  ///
766  /// Like \c clear(IRUnitT&), this doesn't invalidate the results; it simply
767  /// deletes them. This lets you clean up the AnalysisManager when the set of
768  /// IR units itself has potentially changed, and thus we can't even look up a
769  /// a result and invalidate/clear it directly.
770  void clear() {
771  AnalysisResults.clear();
772  AnalysisResultLists.clear();
773  }
774 
775  /// Get the result of an analysis pass for a given IR unit.
776  ///
777  /// Runs the analysis if a cached result is not available.
778  template <typename PassT>
779  typename PassT::Result &getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs) {
780  assert(AnalysisPasses.count(PassT::ID()) &&
781  "This analysis pass was not registered prior to being queried");
782  ResultConceptT &ResultConcept =
783  getResultImpl(PassT::ID(), IR, ExtraArgs...);
784 
785  using ResultModelT =
786  detail::AnalysisResultModel<IRUnitT, PassT, typename PassT::Result,
787  PreservedAnalyses, Invalidator>;
788 
789  return static_cast<ResultModelT &>(ResultConcept).Result;
790  }
791 
792  /// Get the cached result of an analysis pass for a given IR unit.
793  ///
794  /// This method never runs the analysis.
795  ///
796  /// \returns null if there is no cached result.
797  template <typename PassT>
798  typename PassT::Result *getCachedResult(IRUnitT &IR) const {
799  assert(AnalysisPasses.count(PassT::ID()) &&
800  "This analysis pass was not registered prior to being queried");
801 
802  ResultConceptT *ResultConcept = getCachedResultImpl(PassT::ID(), IR);
803  if (!ResultConcept)
804  return nullptr;
805 
806  using ResultModelT =
807  detail::AnalysisResultModel<IRUnitT, PassT, typename PassT::Result,
808  PreservedAnalyses, Invalidator>;
809 
810  return &static_cast<ResultModelT *>(ResultConcept)->Result;
811  }
812 
813  /// Verify that the given Result cannot be invalidated, assert otherwise.
814  template <typename PassT>
815  void verifyNotInvalidated(IRUnitT &IR, typename PassT::Result *Result) const {
817  SmallDenseMap<AnalysisKey *, bool, 8> IsResultInvalidated;
818  Invalidator Inv(IsResultInvalidated, AnalysisResults);
819  assert(!Result->invalidate(IR, PA, Inv) &&
820  "Cached result cannot be invalidated");
821  }
822 
823  /// Register an analysis pass with the manager.
824  ///
825  /// The parameter is a callable whose result is an analysis pass. This allows
826  /// passing in a lambda to construct the analysis.
827  ///
828  /// The analysis type to register is the type returned by calling the \c
829  /// PassBuilder argument. If that type has already been registered, then the
830  /// argument will not be called and this function will return false.
831  /// Otherwise, we register the analysis returned by calling \c PassBuilder(),
832  /// and this function returns true.
833  ///
834  /// (Note: Although the return value of this function indicates whether or not
835  /// an analysis was previously registered, there intentionally isn't a way to
836  /// query this directly. Instead, you should just register all the analyses
837  /// you might want and let this class run them lazily. This idiom lets us
838  /// minimize the number of times we have to look up analyses in our
839  /// hashtable.)
840  template <typename PassBuilderT>
841  bool registerPass(PassBuilderT &&PassBuilder) {
842  using PassT = decltype(PassBuilder());
843  using PassModelT =
845  Invalidator, ExtraArgTs...>;
846 
847  auto &PassPtr = AnalysisPasses[PassT::ID()];
848  if (PassPtr)
849  // Already registered this pass type!
850  return false;
851 
852  // Construct a new model around the instance returned by the builder.
853  PassPtr.reset(new PassModelT(PassBuilder()));
854  return true;
855  }
856 
857  /// Invalidate cached analyses for an IR unit.
858  ///
859  /// Walk through all of the analyses pertaining to this unit of IR and
860  /// invalidate them, unless they are preserved by the PreservedAnalyses set.
861  void invalidate(IRUnitT &IR, const PreservedAnalyses &PA);
862 
863 private:
864  /// Look up a registered analysis pass.
865  PassConceptT &lookUpPass(AnalysisKey *ID) {
866  typename AnalysisPassMapT::iterator PI = AnalysisPasses.find(ID);
867  assert(PI != AnalysisPasses.end() &&
868  "Analysis passes must be registered prior to being queried!");
869  return *PI->second;
870  }
871 
872  /// Look up a registered analysis pass.
873  const PassConceptT &lookUpPass(AnalysisKey *ID) const {
874  typename AnalysisPassMapT::const_iterator PI = AnalysisPasses.find(ID);
875  assert(PI != AnalysisPasses.end() &&
876  "Analysis passes must be registered prior to being queried!");
877  return *PI->second;
878  }
879 
880  /// Get an analysis result, running the pass if necessary.
881  ResultConceptT &getResultImpl(AnalysisKey *ID, IRUnitT &IR,
882  ExtraArgTs... ExtraArgs);
883 
884  /// Get a cached analysis result or return null.
885  ResultConceptT *getCachedResultImpl(AnalysisKey *ID, IRUnitT &IR) const {
887  AnalysisResults.find({ID, &IR});
888  return RI == AnalysisResults.end() ? nullptr : &*RI->second->second;
889  }
890 
891  /// Map type from analysis pass ID to pass concept pointer.
892  using AnalysisPassMapT =
893  DenseMap<AnalysisKey *, std::unique_ptr<PassConceptT>>;
894 
895  /// Collection of analysis passes, indexed by ID.
896  AnalysisPassMapT AnalysisPasses;
897 
898  /// Map from IR unit to a list of analysis results.
899  ///
900  /// Provides linear time removal of all analysis results for a IR unit and
901  /// the ultimate storage for a particular cached analysis result.
902  AnalysisResultListMapT AnalysisResultLists;
903 
904  /// Map from an analysis ID and IR unit to a particular cached
905  /// analysis result.
906  AnalysisResultMapT AnalysisResults;
907 };
908 
909 extern template class AnalysisManager<Module>;
910 
911 /// Convenience typedef for the Module analysis manager.
913 
914 extern template class AnalysisManager<Function>;
915 
916 /// Convenience typedef for the Function analysis manager.
918 
919 /// An analysis over an "outer" IR unit that provides access to an
920 /// analysis manager over an "inner" IR unit. The inner unit must be contained
921 /// in the outer unit.
922 ///
923 /// For example, InnerAnalysisManagerProxy<FunctionAnalysisManager, Module> is
924 /// an analysis over Modules (the "outer" unit) that provides access to a
925 /// Function analysis manager. The FunctionAnalysisManager is the "inner"
926 /// manager being proxied, and Functions are the "inner" unit. The inner/outer
927 /// relationship is valid because each Function is contained in one Module.
928 ///
929 /// If you're (transitively) within a pass manager for an IR unit U that
930 /// contains IR unit V, you should never use an analysis manager over V, except
931 /// via one of these proxies.
932 ///
933 /// Note that the proxy's result is a move-only RAII object. The validity of
934 /// the analyses in the inner analysis manager is tied to its lifetime.
935 template <typename AnalysisManagerT, typename IRUnitT, typename... ExtraArgTs>
937  : public AnalysisInfoMixin<
938  InnerAnalysisManagerProxy<AnalysisManagerT, IRUnitT>> {
939 public:
940  class Result {
941  public:
942  explicit Result(AnalysisManagerT &InnerAM) : InnerAM(&InnerAM) {}
943 
944  Result(Result &&Arg) : InnerAM(std::move(Arg.InnerAM)) {
945  // We have to null out the analysis manager in the moved-from state
946  // because we are taking ownership of the responsibilty to clear the
947  // analysis state.
948  Arg.InnerAM = nullptr;
949  }
950 
952  // InnerAM is cleared in a moved from state where there is nothing to do.
953  if (!InnerAM)
954  return;
955 
956  // Clear out the analysis manager if we're being destroyed -- it means we
957  // didn't even see an invalidate call when we got invalidated.
958  InnerAM->clear();
959  }
960 
962  InnerAM = RHS.InnerAM;
963  // We have to null out the analysis manager in the moved-from state
964  // because we are taking ownership of the responsibilty to clear the
965  // analysis state.
966  RHS.InnerAM = nullptr;
967  return *this;
968  }
969 
970  /// Accessor for the analysis manager.
971  AnalysisManagerT &getManager() { return *InnerAM; }
972 
973  /// Handler for invalidation of the outer IR unit, \c IRUnitT.
974  ///
975  /// If the proxy analysis itself is not preserved, we assume that the set of
976  /// inner IR objects contained in IRUnit may have changed. In this case,
977  /// we have to call \c clear() on the inner analysis manager, as it may now
978  /// have stale pointers to its inner IR objects.
979  ///
980  /// Regardless of whether the proxy analysis is marked as preserved, all of
981  /// the analyses in the inner analysis manager are potentially invalidated
982  /// based on the set of preserved analyses.
983  bool invalidate(
984  IRUnitT &IR, const PreservedAnalyses &PA,
986 
987  private:
988  AnalysisManagerT *InnerAM;
989  };
990 
991  explicit InnerAnalysisManagerProxy(AnalysisManagerT &InnerAM)
992  : InnerAM(&InnerAM) {}
993 
994  /// Run the analysis pass and create our proxy result object.
995  ///
996  /// This doesn't do any interesting work; it is primarily used to insert our
997  /// proxy result object into the outer analysis cache so that we can proxy
998  /// invalidation to the inner analysis manager.
1000  ExtraArgTs...) {
1001  return Result(*InnerAM);
1002  }
1003 
1004 private:
1005  friend AnalysisInfoMixin<
1007 
1008  static AnalysisKey Key;
1009 
1010  AnalysisManagerT *InnerAM;
1011 };
1012 
1013 template <typename AnalysisManagerT, typename IRUnitT, typename... ExtraArgTs>
1014 AnalysisKey
1015  InnerAnalysisManagerProxy<AnalysisManagerT, IRUnitT, ExtraArgTs...>::Key;
1016 
1017 /// Provide the \c FunctionAnalysisManager to \c Module proxy.
1020 
1021 /// Specialization of the invalidate method for the \c
1022 /// FunctionAnalysisManagerModuleProxy's result.
1023 template <>
1025  Module &M, const PreservedAnalyses &PA,
1027 
1028 // Ensure the \c FunctionAnalysisManagerModuleProxy is provided as an extern
1029 // template.
1031  Module>;
1032 
1033 /// An analysis over an "inner" IR unit that provides access to an
1034 /// analysis manager over a "outer" IR unit. The inner unit must be contained
1035 /// in the outer unit.
1036 ///
1037 /// For example OuterAnalysisManagerProxy<ModuleAnalysisManager, Function> is an
1038 /// analysis over Functions (the "inner" unit) which provides access to a Module
1039 /// analysis manager. The ModuleAnalysisManager is the "outer" manager being
1040 /// proxied, and Modules are the "outer" IR unit. The inner/outer relationship
1041 /// is valid because each Function is contained in one Module.
1042 ///
1043 /// This proxy only exposes the const interface of the outer analysis manager,
1044 /// to indicate that you cannot cause an outer analysis to run from within an
1045 /// inner pass. Instead, you must rely on the \c getCachedResult API. This is
1046 /// due to keeping potential future concurrency in mind. To give an example,
1047 /// running a module analysis before any function passes may give a different
1048 /// result than running it in a function pass. Both may be valid, but it would
1049 /// produce non-deterministic results. GlobalsAA is a good analysis example,
1050 /// because the cached information has the mod/ref info for all memory for each
1051 /// function at the time the analysis was computed. The information is still
1052 /// valid after a function transformation, but it may be *different* if
1053 /// recomputed after that transform. GlobalsAA is never invalidated.
1054 
1055 ///
1056 /// This proxy doesn't manage invalidation in any way -- that is handled by the
1057 /// recursive return path of each layer of the pass manager. A consequence of
1058 /// this is the outer analyses may be stale. We invalidate the outer analyses
1059 /// only when we're done running passes over the inner IR units.
1060 template <typename AnalysisManagerT, typename IRUnitT, typename... ExtraArgTs>
1062  : public AnalysisInfoMixin<
1063  OuterAnalysisManagerProxy<AnalysisManagerT, IRUnitT, ExtraArgTs...>> {
1064 public:
1065  /// Result proxy object for \c OuterAnalysisManagerProxy.
1066  class Result {
1067  public:
1068  explicit Result(const AnalysisManagerT &OuterAM) : OuterAM(&OuterAM) {}
1069 
1070  /// Get a cached analysis. If the analysis can be invalidated, this will
1071  /// assert.
1072  template <typename PassT, typename IRUnitTParam>
1073  typename PassT::Result *getCachedResult(IRUnitTParam &IR) const {
1074  typename PassT::Result *Res =
1075  OuterAM->template getCachedResult<PassT>(IR);
1076  if (Res)
1077  OuterAM->template verifyNotInvalidated<PassT>(IR, Res);
1078  return Res;
1079  }
1080 
1081  /// Method provided for unit testing, not intended for general use.
1082  template <typename PassT, typename IRUnitTParam>
1083  bool cachedResultExists(IRUnitTParam &IR) const {
1084  typename PassT::Result *Res =
1085  OuterAM->template getCachedResult<PassT>(IR);
1086  return Res != nullptr;
1087  }
1088 
1089  /// When invalidation occurs, remove any registered invalidation events.
1091  IRUnitT &IRUnit, const PreservedAnalyses &PA,
1093  // Loop over the set of registered outer invalidation mappings and if any
1094  // of them map to an analysis that is now invalid, clear it out.
1096  for (auto &KeyValuePair : OuterAnalysisInvalidationMap) {
1097  AnalysisKey *OuterID = KeyValuePair.first;
1098  auto &InnerIDs = KeyValuePair.second;
1099  llvm::erase_if(InnerIDs, [&](AnalysisKey *InnerID) {
1100  return Inv.invalidate(InnerID, IRUnit, PA);
1101  });
1102  if (InnerIDs.empty())
1103  DeadKeys.push_back(OuterID);
1104  }
1105 
1106  for (auto OuterID : DeadKeys)
1107  OuterAnalysisInvalidationMap.erase(OuterID);
1108 
1109  // The proxy itself remains valid regardless of anything else.
1110  return false;
1111  }
1112 
1113  /// Register a deferred invalidation event for when the outer analysis
1114  /// manager processes its invalidations.
1115  template <typename OuterAnalysisT, typename InvalidatedAnalysisT>
1117  AnalysisKey *OuterID = OuterAnalysisT::ID();
1118  AnalysisKey *InvalidatedID = InvalidatedAnalysisT::ID();
1119 
1120  auto &InvalidatedIDList = OuterAnalysisInvalidationMap[OuterID];
1121  // Note, this is a linear scan. If we end up with large numbers of
1122  // analyses that all trigger invalidation on the same outer analysis,
1123  // this entire system should be changed to some other deterministic
1124  // data structure such as a `SetVector` of a pair of pointers.
1125  if (!llvm::is_contained(InvalidatedIDList, InvalidatedID))
1126  InvalidatedIDList.push_back(InvalidatedID);
1127  }
1128 
1129  /// Access the map from outer analyses to deferred invalidation requiring
1130  /// analyses.
1133  return OuterAnalysisInvalidationMap;
1134  }
1135 
1136  private:
1137  const AnalysisManagerT *OuterAM;
1138 
1139  /// A map from an outer analysis ID to the set of this IR-unit's analyses
1140  /// which need to be invalidated.
1142  OuterAnalysisInvalidationMap;
1143  };
1144 
1145  OuterAnalysisManagerProxy(const AnalysisManagerT &OuterAM)
1146  : OuterAM(&OuterAM) {}
1147 
1148  /// Run the analysis pass and create our proxy result object.
1149  /// Nothing to see here, it just forwards the \c OuterAM reference into the
1150  /// result.
1152  ExtraArgTs...) {
1153  return Result(*OuterAM);
1154  }
1155 
1156 private:
1157  friend AnalysisInfoMixin<
1158  OuterAnalysisManagerProxy<AnalysisManagerT, IRUnitT, ExtraArgTs...>>;
1159 
1160  static AnalysisKey Key;
1161 
1162  const AnalysisManagerT *OuterAM;
1163 };
1164 
1165 template <typename AnalysisManagerT, typename IRUnitT, typename... ExtraArgTs>
1166 AnalysisKey
1167  OuterAnalysisManagerProxy<AnalysisManagerT, IRUnitT, ExtraArgTs...>::Key;
1168 
1169 extern template class OuterAnalysisManagerProxy<ModuleAnalysisManager,
1170  Function>;
1171 /// Provide the \c ModuleAnalysisManager to \c Function proxy.
1174 
1175 /// Trivial adaptor that maps from a module to its functions.
1176 ///
1177 /// Designed to allow composition of a FunctionPass(Manager) and
1178 /// a ModulePassManager, by running the FunctionPass(Manager) over every
1179 /// function in the module.
1180 ///
1181 /// Function passes run within this adaptor can rely on having exclusive access
1182 /// to the function they are run over. They should not read or modify any other
1183 /// functions! Other threads or systems may be manipulating other functions in
1184 /// the module, and so their state should never be relied on.
1185 /// FIXME: Make the above true for all of LLVM's actual passes, some still
1186 /// violate this principle.
1187 ///
1188 /// Function passes can also read the module containing the function, but they
1189 /// should not modify that module outside of the use lists of various globals.
1190 /// For example, a function pass is not permitted to add functions to the
1191 /// module.
1192 /// FIXME: Make the above true for all of LLVM's actual passes, some still
1193 /// violate this principle.
1194 ///
1195 /// Note that although function passes can access module analyses, module
1196 /// analyses are not invalidated while the function passes are running, so they
1197 /// may be stale. Function analyses will not be stale.
1199  : public PassInfoMixin<ModuleToFunctionPassAdaptor> {
1200 public:
1202 
1203  explicit ModuleToFunctionPassAdaptor(std::unique_ptr<PassConceptT> Pass)
1204  : Pass(std::move(Pass)) {}
1205 
1206  /// Runs the function pass across every function in the module.
1208  void printPipeline(raw_ostream &OS,
1209  function_ref<StringRef(StringRef)> MapClassName2PassName);
1210 
1211  static bool isRequired() { return true; }
1212 
1213 private:
1214  std::unique_ptr<PassConceptT> Pass;
1215 };
1216 
1217 /// A function to deduce a function pass type and wrap it in the
1218 /// templated adaptor.
1219 template <typename FunctionPassT>
1220 ModuleToFunctionPassAdaptor
1222  using PassModelT =
1225 
1227  std::make_unique<PassModelT>(std::forward<FunctionPassT>(Pass)));
1228 }
1229 
1230 /// A utility pass template to force an analysis result to be available.
1231 ///
1232 /// If there are extra arguments at the pass's run level there may also be
1233 /// extra arguments to the analysis manager's \c getResult routine. We can't
1234 /// guess how to effectively map the arguments from one to the other, and so
1235 /// this specialization just ignores them.
1236 ///
1237 /// Specific patterns of run-method extra arguments and analysis manager extra
1238 /// arguments will have to be defined as appropriate specializations.
1239 template <typename AnalysisT, typename IRUnitT,
1240  typename AnalysisManagerT = AnalysisManager<IRUnitT>,
1241  typename... ExtraArgTs>
1243  : PassInfoMixin<RequireAnalysisPass<AnalysisT, IRUnitT, AnalysisManagerT,
1244  ExtraArgTs...>> {
1245  /// Run this pass over some unit of IR.
1246  ///
1247  /// This pass can be run over any unit of IR and use any analysis manager
1248  /// provided they satisfy the basic API requirements. When this pass is
1249  /// created, these methods can be instantiated to satisfy whatever the
1250  /// context requires.
1251  PreservedAnalyses run(IRUnitT &Arg, AnalysisManagerT &AM,
1252  ExtraArgTs &&... Args) {
1253  (void)AM.template getResult<AnalysisT>(Arg,
1254  std::forward<ExtraArgTs>(Args)...);
1255 
1256  return PreservedAnalyses::all();
1257  }
1259  function_ref<StringRef(StringRef)> MapClassName2PassName) {
1260  auto ClassName = AnalysisT::name();
1261  auto PassName = MapClassName2PassName(ClassName);
1262  OS << "require<" << PassName << ">";
1263  }
1264  static bool isRequired() { return true; }
1265 };
1266 
1267 /// A no-op pass template which simply forces a specific analysis result
1268 /// to be invalidated.
1269 template <typename AnalysisT>
1271  : PassInfoMixin<InvalidateAnalysisPass<AnalysisT>> {
1272  /// Run this pass over some unit of IR.
1273  ///
1274  /// This pass can be run over any unit of IR and use any analysis manager,
1275  /// provided they satisfy the basic API requirements. When this pass is
1276  /// created, these methods can be instantiated to satisfy whatever the
1277  /// context requires.
1278  template <typename IRUnitT, typename AnalysisManagerT, typename... ExtraArgTs>
1279  PreservedAnalyses run(IRUnitT &Arg, AnalysisManagerT &AM, ExtraArgTs &&...) {
1280  auto PA = PreservedAnalyses::all();
1281  PA.abandon<AnalysisT>();
1282  return PA;
1283  }
1285  function_ref<StringRef(StringRef)> MapClassName2PassName) {
1286  auto ClassName = AnalysisT::name();
1287  auto PassName = MapClassName2PassName(ClassName);
1288  OS << "invalidate<" << PassName << ">";
1289  }
1290 };
1291 
1292 /// A utility pass that does nothing, but preserves no analyses.
1293 ///
1294 /// Because this preserves no analyses, any analysis passes queried after this
1295 /// pass runs will recompute fresh results.
1296 struct InvalidateAllAnalysesPass : PassInfoMixin<InvalidateAllAnalysesPass> {
1297  /// Run this pass over some unit of IR.
1298  template <typename IRUnitT, typename AnalysisManagerT, typename... ExtraArgTs>
1299  PreservedAnalyses run(IRUnitT &, AnalysisManagerT &, ExtraArgTs &&...) {
1300  return PreservedAnalyses::none();
1301  }
1302 };
1303 
1304 /// A utility pass template that simply runs another pass multiple times.
1305 ///
1306 /// This can be useful when debugging or testing passes. It also serves as an
1307 /// example of how to extend the pass manager in ways beyond composition.
1308 template <typename PassT>
1309 class RepeatedPass : public PassInfoMixin<RepeatedPass<PassT>> {
1310 public:
1311  RepeatedPass(int Count, PassT &&P)
1312  : Count(Count), P(std::forward<PassT>(P)) {}
1313 
1314  template <typename IRUnitT, typename AnalysisManagerT, typename... Ts>
1315  PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT &AM, Ts &&... Args) {
1316 
1317  // Request PassInstrumentation from analysis manager, will use it to run
1318  // instrumenting callbacks for the passes later.
1319  // Here we use std::tuple wrapper over getResult which helps to extract
1320  // AnalysisManager's arguments out of the whole Args set.
1321  PassInstrumentation PI =
1322  detail::getAnalysisResult<PassInstrumentationAnalysis>(
1323  AM, IR, std::tuple<Ts...>(Args...));
1324 
1325  auto PA = PreservedAnalyses::all();
1326  for (int i = 0; i < Count; ++i) {
1327  // Check the PassInstrumentation's BeforePass callbacks before running the
1328  // pass, skip its execution completely if asked to (callback returns
1329  // false).
1330  if (!PI.runBeforePass<IRUnitT>(P, IR))
1331  continue;
1332  PreservedAnalyses IterPA = P.run(IR, AM, std::forward<Ts>(Args)...);
1333  PA.intersect(IterPA);
1334  PI.runAfterPass(P, IR, IterPA);
1335  }
1336  return PA;
1337  }
1338 
1340  function_ref<StringRef(StringRef)> MapClassName2PassName) {
1341  OS << "repeat<" << Count << ">(";
1342  P.printPipeline(OS, MapClassName2PassName);
1343  OS << ")";
1344  }
1345 
1346 private:
1347  int Count;
1348  PassT P;
1349 };
1350 
1351 template <typename PassT>
1353  return RepeatedPass<PassT>(Count, std::forward<PassT>(P));
1354 }
1355 
1356 } // end namespace llvm
1357 
1358 #endif // LLVM_IR_PASSMANAGER_H
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::ModuleToFunctionPassAdaptor::run
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Runs the function pass across every function in the module.
Definition: PassManager.cpp:101
i
i
Definition: README.txt:29
llvm::ModuleToFunctionPassAdaptor
Trivial adaptor that maps from a module to its functions.
Definition: PassManager.h:1198
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:155
llvm::detail::AnalysisResultConcept
Abstract concept of an analysis result.
Definition: PassManagerInternal.h:123
llvm::OuterAnalysisManagerProxy
An analysis over an "inner" IR unit that provides access to an analysis manager over a "outer" IR uni...
Definition: PassManager.h:1061
llvm::OuterAnalysisManagerProxy::OuterAnalysisManagerProxy
OuterAnalysisManagerProxy(const AnalysisManagerT &OuterAM)
Definition: PassManager.h:1145
PassManagerInternal.h
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::SmallVectorImpl::erase
iterator erase(const_iterator CI)
Definition: SmallVector.h:705
llvm::TimeTraceScope
The TimeTraceScope is a helper class to call the begin and end functions of the time trace profiler.
Definition: TimeProfiler.h:65
llvm::PassManager::isEmpty
bool isEmpty() const
Returns if the pass manager contains any passes.
Definition: PassManager.h:573
llvm::OuterAnalysisManagerProxy::run
Result run(IRUnitT &, AnalysisManager< IRUnitT, ExtraArgTs... > &, ExtraArgTs...)
Run the analysis pass and create our proxy result object.
Definition: PassManager.h:1151
llvm::AnalysisInfoMixin::ID
static AnalysisKey * ID()
Returns an opaque, unique ID for this analysis type.
Definition: PassManager.h:413
llvm::InnerAnalysisManagerProxy::Result::Result
Result(Result &&Arg)
Definition: PassManager.h:944
llvm::AnalysisManager::getResult
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:779
llvm::PassInfoMixin
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:374
llvm::OuterAnalysisManagerProxy::Result::invalidate
bool invalidate(IRUnitT &IRUnit, const PreservedAnalyses &PA, typename AnalysisManager< IRUnitT, ExtraArgTs... >::Invalidator &Inv)
When invalidation occurs, remove any registered invalidation events.
Definition: PassManager.h:1090
llvm::ModuleAnalysisManagerFunctionProxy
OuterAnalysisManagerProxy< ModuleAnalysisManager, Function > ModuleAnalysisManagerFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
Definition: PassManager.h:1173
llvm::Function
Definition: Function.h:61
llvm::AnalysisManager::Invalidator::invalidate
bool invalidate(IRUnitT &IR, const PreservedAnalyses &PA)
Trigger the invalidation of some other analysis pass if not already handled and return whether it was...
Definition: PassManager.h:684
llvm::AnalysisManager::invalidate
void invalidate(IRUnitT &IR, const PreservedAnalyses &PA)
Invalidate cached analyses for an IR unit.
Definition: PassManagerImpl.h:89
StringRef.h
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
Pass.h
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
llvm::InnerAnalysisManagerProxy::InnerAnalysisManagerProxy
InnerAnalysisManagerProxy(AnalysisManagerT &InnerAM)
Definition: PassManager.h:991
llvm::InnerAnalysisManagerProxy::Result
Definition: PassManager.h:940
llvm::AllAnalysesOn
This templated class represents "all analyses that operate over <a particular IR unit>" (e....
Definition: PassManager.h:93
llvm::erase_if
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
Definition: STLExtras.h:1732
llvm::SmallDenseMap
Definition: DenseMap.h:880
llvm::detail::getAnalysisResultUnpackTuple
PassT::Result getAnalysisResultUnpackTuple(AnalysisManagerT &AM, IRUnitT &IR, std::tuple< ArgTs... > Args, std::index_sequence< Ns... >)
Actual unpacker of extra arguments in getAnalysisResult, passes only those tuple arguments that are m...
Definition: PassManager.h:427
llvm::PreservedAnalyses::abandon
void abandon()
Mark an analysis as abandoned.
Definition: PassManager.h:209
llvm::InvalidateAnalysisPass::run
PreservedAnalyses run(IRUnitT &Arg, AnalysisManagerT &AM, ExtraArgTs &&...)
Run this pass over some unit of IR.
Definition: PassManager.h:1279
llvm::OuterAnalysisManagerProxy::Result::cachedResultExists
bool cachedResultExists(IRUnitTParam &IR) const
Method provided for unit testing, not intended for general use.
Definition: PassManager.h:1083
llvm::PreservedAnalyses::PreservedAnalysisChecker
A checker object that makes it easy to query for whether an analysis or some set covering it is prese...
Definition: PassManager.h:269
llvm::PreservedAnalyses::none
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition: PassManager.h:158
DenseMap.h
Module.h
llvm::ModuleAnalysisManager
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition: PassManager.h:912
llvm::PassManager::printPipeline
void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
Definition: PassManager.h:489
llvm::DenseMapBase::count
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition: DenseMap.h:145
llvm::SmallPtrSet< void *, 2 >
Results
Function Alias Analysis Results
Definition: AliasAnalysis.cpp:847
llvm::PreservedAnalyses::getChecker
PreservedAnalysisChecker getChecker(AnalysisKey *ID) const
Build a checker for this PreservedAnalyses and the specified analysis ID.
Definition: PassManager.h:322
STLExtras.h
llvm::PassInstrumentationAnalysis::run
Result run(IRUnitT &, AnalysisManagerT &, ExtraArgTs &&...)
Definition: PassManager.h:615
llvm::RepeatedPass::printPipeline
void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
Definition: PassManager.h:1339
llvm::AllAnalysesOn::ID
static AnalysisSetKey * ID()
Definition: PassManager.h:95
llvm::PassManager::operator=
PassManager & operator=(PassManager &&RHS)
Definition: PassManager.h:484
llvm::PreservedAnalyses::intersect
void intersect(const PreservedAnalyses &Arg)
Intersect this set with another in place.
Definition: PassManager.h:227
llvm::PassManager::PassConceptT
detail::PassConcept< IRUnitT, AnalysisManagerT, ExtraArgTs... > PassConceptT
Definition: PassManager.h:579
llvm::PreservedAnalyses::preserveSet
void preserveSet(AnalysisSetKey *ID)
Mark an analysis set as preserved using its ID.
Definition: PassManager.h:196
llvm::DenseMapBase< DenseMap< AnalysisKey *, std::unique_ptr< PassConceptT >, DenseMapInfo< AnalysisKey * >, llvm::detail::DenseMapPair< AnalysisKey *, std::unique_ptr< PassConceptT > > >, AnalysisKey *, std::unique_ptr< PassConceptT >, DenseMapInfo< AnalysisKey * >, llvm::detail::DenseMapPair< AnalysisKey *, std::unique_ptr< PassConceptT > > >::const_iterator
DenseMapIterator< AnalysisKey *, std::unique_ptr< PassConceptT >, DenseMapInfo< AnalysisKey * >, llvm::detail::DenseMapPair< AnalysisKey *, std::unique_ptr< PassConceptT > >, true > const_iterator
Definition: DenseMap.h:72
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:206
llvm::PassManager::PassManager
PassManager(PassManager &&Arg)
Definition: PassManager.h:482
PassInstrumentation.h
llvm::PassBuilder
This class provides access to building LLVM's passes.
Definition: PassBuilder.h:84
llvm::AnalysisManager::empty
bool empty() const
Returns true if the analysis manager has an empty results cache.
Definition: PassManager.h:750
llvm::AMDGPU::PALMD::Key
Key
PAL metadata keys.
Definition: AMDGPUMetadata.h:481
llvm::createModuleToFunctionPassAdaptor
ModuleToFunctionPassAdaptor createModuleToFunctionPassAdaptor(FunctionPassT &&Pass)
A function to deduce a function pass type and wrap it in the templated adaptor.
Definition: PassManager.h:1221
llvm::createRepeatedPass
RepeatedPass< PassT > createRepeatedPass(int Count, PassT &&P)
Definition: PassManager.h:1352
llvm::OuterAnalysisManagerProxy::Result
Result proxy object for OuterAnalysisManagerProxy.
Definition: PassManager.h:1066
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::InvalidateAllAnalysesPass::run
PreservedAnalyses run(IRUnitT &, AnalysisManagerT &, ExtraArgTs &&...)
Run this pass over some unit of IR.
Definition: PassManager.h:1299
IR
Statically lint checks LLVM IR
Definition: Lint.cpp:744
SmallPtrSet.h
llvm::InvalidateAnalysisPass::printPipeline
void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
Definition: PassManager.h:1284
llvm::AnalysisManager::Invalidator
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:666
llvm::PreservedAnalyses::PreservedAnalysisChecker::preservedSet
bool preservedSet()
Returns true if the checker's analysis was not abandoned and either.
Definition: PassManager.h:301
llvm::PassManager::Passes
std::vector< std::unique_ptr< PassConceptT > > Passes
Definition: PassManager.h:581
llvm::RequireAnalysisPass::printPipeline
void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
Definition: PassManager.h:1258
llvm::PassInstrumentationAnalysis::PassInstrumentationAnalysis
PassInstrumentationAnalysis(PassInstrumentationCallbacks *Callbacks=nullptr)
PassInstrumentationCallbacks object is shared, owned by something else, not this analysis.
Definition: PassManager.h:609
llvm::AnalysisSetKey
A special type used to provide an address that identifies a set of related analyses.
Definition: PassManager.h:82
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:168
llvm::PreservedAnalyses::preserve
void preserve(AnalysisKey *ID)
Given an analysis's ID, mark the analysis as preserved, adding it to the set.
Definition: PassManager.h:180
llvm::DenseMapBase::clear
void clear()
Definition: DenseMap.h:111
llvm::count
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
Definition: STLExtras.h:1634
llvm::PassInstrumentation::runAfterPass
void runAfterPass(const PassT &Pass, const IRUnitT &IR, const PreservedAnalyses &PA) const
AfterPass instrumentation point - takes Pass instance that has just been executed and constant refere...
Definition: PassInstrumentation.h:242
llvm::PreservedAnalyses::preserve
void preserve()
Mark an analysis as preserved.
Definition: PassManager.h:176
llvm::OuterAnalysisManagerProxy::Result::Result
Result(const AnalysisManagerT &OuterAM)
Definition: PassManager.h:1068
llvm::detail::AnalysisResultModel
Wrapper to model the analysis result concept.
Definition: PassManagerInternal.h:191
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::CFGAnalyses::ID
static AnalysisSetKey * ID()
Definition: PassManager.h:118
llvm::PreservedAnalyses::abandon
void abandon(AnalysisKey *ID)
Mark an analysis as abandoned using its ID.
Definition: PassManager.h:218
llvm::AnalysisKey
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:72
llvm::InvalidateAllAnalysesPass
A utility pass that does nothing, but preserves no analyses.
Definition: PassManager.h:1296
llvm::detail::PassConcept
Template for the abstract base class used to dispatch polymorphically over pass objects.
Definition: PassManagerInternal.h:37
llvm::InvalidateAnalysisPass
A no-op pass template which simply forces a specific analysis result to be invalidated.
Definition: PassManager.h:1270
llvm::is_contained
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
Definition: STLExtras.h:1616
llvm::InnerAnalysisManagerProxy::Result::invalidate
bool invalidate(IRUnitT &IR, const PreservedAnalyses &PA, typename AnalysisManager< IRUnitT, ExtraArgTs... >::Invalidator &Inv)
Handler for invalidation of the outer IR unit, IRUnitT.
llvm::DenseMapBase::find
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:150
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1609
llvm::PassInstrumentation
This class provides instrumentation entry points for the Pass Manager, doing calls to callbacks regis...
Definition: PassInstrumentation.h:180
llvm::PreservedAnalyses::allAnalysesInSetPreserved
bool allAnalysesInSetPreserved() const
Directly test whether a set of analyses is preserved.
Definition: PassManager.h:338
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::PreservedAnalyses::PreservedAnalysisChecker::preservedWhenStateless
bool preservedWhenStateless()
Return true if the checker's analysis was not abandoned, i.e.
Definition: PassManager.h:294
TinyPtrVector.h
llvm::AnalysisInfoMixin
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:397
llvm::SmallPtrSetImpl::count
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Definition: SmallPtrSet.h:382
llvm::PreservedAnalyses::intersect
void intersect(PreservedAnalyses &&Arg)
Intersect this set with a temporary other set in place.
Definition: PassManager.h:249
TypeName.h
llvm::RepeatedPass::RepeatedPass
RepeatedPass(int Count, PassT &&P)
Definition: PassManager.h:1311
llvm::ModuleToFunctionPassAdaptor::printPipeline
void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
Definition: PassManager.cpp:94
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::detail::getAnalysisResult
PassT::Result getAnalysisResult(AnalysisManager< IRUnitT, AnalysisArgTs... > &AM, IRUnitT &IR, std::tuple< MainArgTs... > Args)
Helper for partial unpacking of extra arguments in getAnalysisResult.
Definition: PassManager.h:442
llvm::PreservedAnalyses::areAllPreserved
bool areAllPreserved() const
Test whether all analyses are preserved (and none are abandoned).
Definition: PassManager.h:330
llvm::CFGAnalyses
Represents analyses that only rely on functions' control flow.
Definition: PassManager.h:116
llvm::InnerAnalysisManagerProxy::Result::Result
Result(AnalysisManagerT &InnerAM)
Definition: PassManager.h:942
llvm::AnalysisManager::AnalysisManager
AnalysisManager()
Construct an empty analysis manager.
Definition: PassManagerImpl.h:23
llvm::AnalysisManager::verifyNotInvalidated
void verifyNotInvalidated(IRUnitT &IR, typename PassT::Result *Result) const
Verify that the given Result cannot be invalidated, assert otherwise.
Definition: PassManager.h:815
llvm::RepeatedPass::run
PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT &AM, Ts &&... Args)
Definition: PassManager.h:1315
llvm::PassInfoMixin::name
static StringRef name()
Gets the name of the pass we are mixed into.
Definition: PassManager.h:376
llvm::RequireAnalysisPass::run
PreservedAnalyses run(IRUnitT &Arg, AnalysisManagerT &AM, ExtraArgTs &&... Args)
Run this pass over some unit of IR.
Definition: PassManager.h:1251
llvm::PassManager
Manages a sequence of passes over a particular unit of IR.
Definition: PassManager.h:472
llvm::DenseMapBase::empty
LLVM_NODISCARD bool empty() const
Definition: DenseMap.h:97
llvm::RepeatedPass
A utility pass template that simply runs another pass multiple times.
Definition: PassManager.h:1309
name
static const char * name
Definition: SVEIntrinsicOpts.cpp:78
llvm::ModuleToFunctionPassAdaptor::ModuleToFunctionPassAdaptor
ModuleToFunctionPassAdaptor(std::unique_ptr< PassConceptT > Pass)
Definition: PassManager.h:1203
llvm::ModuleToFunctionPassAdaptor::isRequired
static bool isRequired()
Definition: PassManager.h:1211
llvm::AnalysisManager::clear
void clear()
Clear all analysis results cached by this AnalysisManager.
Definition: PassManager.h:770
llvm::PreservedAnalyses::PreservedAnalysisChecker::preserved
bool preserved()
Returns true if the checker's analysis was not abandoned and either.
Definition: PassManager.h:286
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
std
Definition: BitVector.h:838
llvm::InnerAnalysisManagerProxy::Result::operator=
Result & operator=(Result &&RHS)
Definition: PassManager.h:961
llvm::PassInstrumentation::runBeforePass
bool runBeforePass(const PassT &Pass, const IRUnitT &IR) const
BeforePass instrumentation point - takes Pass instance to be executed and constant reference to IR it...
Definition: PassInstrumentation.h:217
llvm::DenseMapBase::end
iterator end()
Definition: DenseMap.h:83
llvm::PreservedAnalyses::all
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:161
llvm::AnalysisManager::getCachedResult
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
Definition: PassManager.h:798
Function.h
llvm::PassManager::PassManager
PassManager()
Construct a pass manager.
Definition: PassManager.h:476
llvm::PreservedAnalyses::allAnalysesInSetPreserved
bool allAnalysesInSetPreserved(AnalysisSetKey *SetID) const
Directly test whether a set of analyses is preserved.
Definition: PassManager.h:345
llvm::PassManager::isRequired
static bool isRequired()
Definition: PassManager.h:575
llvm::AnalysisManager::registerPass
bool registerPass(PassBuilderT &&PassBuilder)
Register an analysis pass with the manager.
Definition: PassManager.h:841
llvm::PassManager::run
PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT &AM, ExtraArgTs... ExtraArgs)
Run all of the passes in this manager over the given unit of IR.
Definition: PassManager.h:501
llvm::AnalysisManager::operator=
AnalysisManager & operator=(AnalysisManager &&)
llvm::detail::AnalysisPassModel
Wrapper to model the analysis pass concept.
Definition: PassManagerInternal.h:293
llvm::AnalysisManager::Invalidator::invalidate
bool invalidate(AnalysisKey *ID, IRUnitT &IR, const PreservedAnalyses &PA)
A type-erased variant of the above invalidate method with the same core API other than passing an ana...
Definition: PassManager.h:698
llvm::Pass
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:91
llvm::PassInfoMixin::printPipeline
void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
Definition: PassManager.h:384
llvm::OuterAnalysisManagerProxy::Result::registerOuterAnalysisInvalidation
void registerOuterAnalysisInvalidation()
Register a deferred invalidation event for when the outer analysis manager processes its invalidation...
Definition: PassManager.h:1116
llvm::PreservedAnalyses::preserveSet
void preserveSet()
Mark an analysis set as preserved.
Definition: PassManager.h:191
llvm::DenseMapBase< DenseMap< AnalysisKey *, std::unique_ptr< PassConceptT >, DenseMapInfo< AnalysisKey * >, llvm::detail::DenseMapPair< AnalysisKey *, std::unique_ptr< PassConceptT > > >, AnalysisKey *, std::unique_ptr< PassConceptT >, DenseMapInfo< AnalysisKey * >, llvm::detail::DenseMapPair< AnalysisKey *, std::unique_ptr< PassConceptT > > >::iterator
DenseMapIterator< AnalysisKey *, std::unique_ptr< PassConceptT >, DenseMapInfo< AnalysisKey * >, llvm::detail::DenseMapPair< AnalysisKey *, std::unique_ptr< PassConceptT > > > iterator
Definition: DenseMap.h:70
llvm::InnerAnalysisManagerProxy::Result::getManager
AnalysisManagerT & getManager()
Accessor for the analysis manager.
Definition: PassManager.h:971
llvm::detail::PassModel
A template wrapper used to implement the polymorphic API.
Definition: PassManagerInternal.h:69
llvm::PassInstrumentationCallbacks
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
Definition: PassInstrumentation.h:66
llvm::FunctionAnalysisManager
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
Definition: PassManager.h:917
llvm::OuterAnalysisManagerProxy::Result::getCachedResult
PassT::Result * getCachedResult(IRUnitTParam &IR) const
Get a cached analysis.
Definition: PassManager.h:1073
llvm::PreservedAnalyses::getChecker
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
Definition: PassManager.h:313
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:44
llvm::PassInstrumentationAnalysis
Pseudo-analysis pass that exposes the PassInstrumentation to pass managers.
Definition: PassManager.h:599
llvm::PassManager::addPass
std::enable_if_t< std::is_same< PassT, PassManager >::value > addPass(PassT &&Pass)
When adding a pass manager pass that has the same type as this pass manager, simply move the passes o...
Definition: PassManager.h:567
llvm::InnerAnalysisManagerProxy
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:936
llvm::InnerAnalysisManagerProxy::Result::~Result
~Result()
Definition: PassManager.h:951
llvm::RequireAnalysisPass
A utility pass template to force an analysis result to be available.
Definition: PassManager.h:1242
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:389
llvm::PreservedAnalyses::allInSet
static PreservedAnalyses allInSet()
Construct a preserved analyses object with a single preserved set.
Definition: PassManager.h:169
llvm::PassManager::addPass
std::enable_if_t<!std::is_same< PassT, PassManager >::value > addPass(PassT &&Pass)
Definition: PassManager.h:552
llvm::InnerAnalysisManagerProxy::run
Result run(IRUnitT &IR, AnalysisManager< IRUnitT, ExtraArgTs... > &AM, ExtraArgTs...)
Run the analysis pass and create our proxy result object.
Definition: PassManager.h:999
llvm::RequireAnalysisPass::isRequired
static bool isRequired()
Definition: PassManager.h:1264
TimeProfiler.h
llvm::FunctionAnalysisManagerModuleProxy
InnerAnalysisManagerProxy< FunctionAnalysisManager, Module > FunctionAnalysisManagerModuleProxy
Provide the FunctionAnalysisManager to Module proxy.
Definition: PassManager.h:1019
Debug.h
PassName
static const char PassName[]
Definition: X86LowerAMXIntrinsics.cpp:669
llvm::SmallPtrSetImpl::insert
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:364
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37
llvm::OuterAnalysisManagerProxy::Result::getOuterInvalidations
const SmallDenseMap< AnalysisKey *, TinyPtrVector< AnalysisKey * >, 2 > & getOuterInvalidations() const
Access the map from outer analyses to deferred invalidation requiring analyses.
Definition: PassManager.h:1132