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>
552  std::enable_if_t<!std::is_same<PassT, PassManager>::value>
553  addPass(PassT &&Pass) {
554  using PassModelT =
555  detail::PassModel<IRUnitT, PassT, PreservedAnalyses, AnalysisManagerT,
556  ExtraArgTs...>;
557  // Do not use make_unique or emplace_back, they cause too many template
558  // instantiations, causing terrible compile times.
559  Passes.push_back(std::unique_ptr<PassConceptT>(
560  new PassModelT(std::forward<PassT>(Pass))));
561  }
562 
563  /// When adding a pass manager pass that has the same type as this pass
564  /// manager, simply move the passes over. This is because we don't have use
565  /// cases rely on executing nested pass managers. Doing this could reduce
566  /// implementation complexity and avoid potential invalidation issues that may
567  /// happen with nested pass managers of the same type.
568  template <typename PassT>
570  std::enable_if_t<std::is_same<PassT, PassManager>::value>
571  addPass(PassT &&Pass) {
572  for (auto &P : Pass.Passes)
573  Passes.push_back(std::move(P));
574  }
575 
576  /// Returns if the pass manager contains any passes.
577  bool isEmpty() const { return Passes.empty(); }
578 
579  static bool isRequired() { return true; }
580 
581 protected:
582  using PassConceptT =
583  detail::PassConcept<IRUnitT, AnalysisManagerT, ExtraArgTs...>;
584 
585  std::vector<std::unique_ptr<PassConceptT>> Passes;
586 };
587 
588 extern template class PassManager<Module>;
589 
590 /// Convenience typedef for a pass manager over modules.
592 
593 extern template class PassManager<Function>;
594 
595 /// Convenience typedef for a pass manager over functions.
597 
598 /// Pseudo-analysis pass that exposes the \c PassInstrumentation to pass
599 /// managers. Goes before AnalysisManager definition to provide its
600 /// internals (e.g PassInstrumentationAnalysis::ID) for use there if needed.
601 /// FIXME: figure out a way to move PassInstrumentationAnalysis into its own
602 /// header.
606  static AnalysisKey Key;
607 
608  PassInstrumentationCallbacks *Callbacks;
609 
610 public:
611  /// PassInstrumentationCallbacks object is shared, owned by something else,
612  /// not this analysis.
614  : Callbacks(Callbacks) {}
615 
617 
618  template <typename IRUnitT, typename AnalysisManagerT, typename... ExtraArgTs>
619  Result run(IRUnitT &, AnalysisManagerT &, ExtraArgTs &&...) {
620  return PassInstrumentation(Callbacks);
621  }
622 };
623 
624 /// A container for analyses that lazily runs them and caches their
625 /// results.
626 ///
627 /// This class can manage analyses for any IR unit where the address of the IR
628 /// unit sufficies as its identity.
629 template <typename IRUnitT, typename... ExtraArgTs> class AnalysisManager {
630 public:
631  class Invalidator;
632 
633 private:
634  // Now that we've defined our invalidator, we can define the concept types.
635  using ResultConceptT =
636  detail::AnalysisResultConcept<IRUnitT, PreservedAnalyses, Invalidator>;
637  using PassConceptT =
638  detail::AnalysisPassConcept<IRUnitT, PreservedAnalyses, Invalidator,
639  ExtraArgTs...>;
640 
641  /// List of analysis pass IDs and associated concept pointers.
642  ///
643  /// Requires iterators to be valid across appending new entries and arbitrary
644  /// erases. Provides the analysis ID to enable finding iterators to a given
645  /// entry in maps below, and provides the storage for the actual result
646  /// concept.
647  using AnalysisResultListT =
648  std::list<std::pair<AnalysisKey *, std::unique_ptr<ResultConceptT>>>;
649 
650  /// Map type from IRUnitT pointer to our custom list type.
651  using AnalysisResultListMapT = DenseMap<IRUnitT *, AnalysisResultListT>;
652 
653  /// Map type from a pair of analysis ID and IRUnitT pointer to an
654  /// iterator into a particular result list (which is where the actual analysis
655  /// result is stored).
656  using AnalysisResultMapT =
657  DenseMap<std::pair<AnalysisKey *, IRUnitT *>,
658  typename AnalysisResultListT::iterator>;
659 
660 public:
661  /// API to communicate dependencies between analyses during invalidation.
662  ///
663  /// When an analysis result embeds handles to other analysis results, it
664  /// needs to be invalidated both when its own information isn't preserved and
665  /// when any of its embedded analysis results end up invalidated. We pass an
666  /// \c Invalidator object as an argument to \c invalidate() in order to let
667  /// the analysis results themselves define the dependency graph on the fly.
668  /// This lets us avoid building an explicit representation of the
669  /// dependencies between analysis results.
670  class Invalidator {
671  public:
672  /// Trigger the invalidation of some other analysis pass if not already
673  /// handled and return whether it was in fact invalidated.
674  ///
675  /// This is expected to be called from within a given analysis result's \c
676  /// invalidate method to trigger a depth-first walk of all inter-analysis
677  /// dependencies. The same \p IR unit and \p PA passed to that result's \c
678  /// invalidate method should in turn be provided to this routine.
679  ///
680  /// The first time this is called for a given analysis pass, it will call
681  /// the corresponding result's \c invalidate method. Subsequent calls will
682  /// use a cache of the results of that initial call. It is an error to form
683  /// cyclic dependencies between analysis results.
684  ///
685  /// This returns true if the given analysis's result is invalid. Any
686  /// dependecies on it will become invalid as a result.
687  template <typename PassT>
688  bool invalidate(IRUnitT &IR, const PreservedAnalyses &PA) {
689  using ResultModelT =
690  detail::AnalysisResultModel<IRUnitT, PassT, typename PassT::Result,
692 
693  return invalidateImpl<ResultModelT>(PassT::ID(), IR, PA);
694  }
695 
696  /// A type-erased variant of the above invalidate method with the same core
697  /// API other than passing an analysis ID rather than an analysis type
698  /// parameter.
699  ///
700  /// This is sadly less efficient than the above routine, which leverages
701  /// the type parameter to avoid the type erasure overhead.
702  bool invalidate(AnalysisKey *ID, IRUnitT &IR, const PreservedAnalyses &PA) {
703  return invalidateImpl<>(ID, IR, PA);
704  }
705 
706  private:
707  friend class AnalysisManager;
708 
709  template <typename ResultT = ResultConceptT>
710  bool invalidateImpl(AnalysisKey *ID, IRUnitT &IR,
711  const PreservedAnalyses &PA) {
712  // If we've already visited this pass, return true if it was invalidated
713  // and false otherwise.
714  auto IMapI = IsResultInvalidated.find(ID);
715  if (IMapI != IsResultInvalidated.end())
716  return IMapI->second;
717 
718  // Otherwise look up the result object.
719  auto RI = Results.find({ID, &IR});
720  assert(RI != Results.end() &&
721  "Trying to invalidate a dependent result that isn't in the "
722  "manager's cache is always an error, likely due to a stale result "
723  "handle!");
724 
725  auto &Result = static_cast<ResultT &>(*RI->second->second);
726 
727  // Insert into the map whether the result should be invalidated and return
728  // that. Note that we cannot reuse IMapI and must do a fresh insert here,
729  // as calling invalidate could (recursively) insert things into the map,
730  // making any iterator or reference invalid.
731  bool Inserted;
732  std::tie(IMapI, Inserted) =
733  IsResultInvalidated.insert({ID, Result.invalidate(IR, PA, *this)});
734  (void)Inserted;
735  assert(Inserted && "Should not have already inserted this ID, likely "
736  "indicates a dependency cycle!");
737  return IMapI->second;
738  }
739 
740  Invalidator(SmallDenseMap<AnalysisKey *, bool, 8> &IsResultInvalidated,
741  const AnalysisResultMapT &Results)
742  : IsResultInvalidated(IsResultInvalidated), Results(Results) {}
743 
744  SmallDenseMap<AnalysisKey *, bool, 8> &IsResultInvalidated;
745  const AnalysisResultMapT &Results;
746  };
747 
748  /// Construct an empty analysis manager.
749  AnalysisManager();
752 
753  /// Returns true if the analysis manager has an empty results cache.
754  bool empty() const {
755  assert(AnalysisResults.empty() == AnalysisResultLists.empty() &&
756  "The storage and index of analysis results disagree on how many "
757  "there are!");
758  return AnalysisResults.empty();
759  }
760 
761  /// Clear any cached analysis results for a single unit of IR.
762  ///
763  /// This doesn't invalidate, but instead simply deletes, the relevant results.
764  /// It is useful when the IR is being removed and we want to clear out all the
765  /// memory pinned for it.
766  void clear(IRUnitT &IR, llvm::StringRef Name);
767 
768  /// Clear all analysis results cached by this AnalysisManager.
769  ///
770  /// Like \c clear(IRUnitT&), this doesn't invalidate the results; it simply
771  /// deletes them. This lets you clean up the AnalysisManager when the set of
772  /// IR units itself has potentially changed, and thus we can't even look up a
773  /// a result and invalidate/clear it directly.
774  void clear() {
775  AnalysisResults.clear();
776  AnalysisResultLists.clear();
777  }
778 
779  /// Get the result of an analysis pass for a given IR unit.
780  ///
781  /// Runs the analysis if a cached result is not available.
782  template <typename PassT>
783  typename PassT::Result &getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs) {
784  assert(AnalysisPasses.count(PassT::ID()) &&
785  "This analysis pass was not registered prior to being queried");
786  ResultConceptT &ResultConcept =
787  getResultImpl(PassT::ID(), IR, ExtraArgs...);
788 
789  using ResultModelT =
790  detail::AnalysisResultModel<IRUnitT, PassT, typename PassT::Result,
791  PreservedAnalyses, Invalidator>;
792 
793  return static_cast<ResultModelT &>(ResultConcept).Result;
794  }
795 
796  /// Get the cached result of an analysis pass for a given IR unit.
797  ///
798  /// This method never runs the analysis.
799  ///
800  /// \returns null if there is no cached result.
801  template <typename PassT>
802  typename PassT::Result *getCachedResult(IRUnitT &IR) const {
803  assert(AnalysisPasses.count(PassT::ID()) &&
804  "This analysis pass was not registered prior to being queried");
805 
806  ResultConceptT *ResultConcept = getCachedResultImpl(PassT::ID(), IR);
807  if (!ResultConcept)
808  return nullptr;
809 
810  using ResultModelT =
811  detail::AnalysisResultModel<IRUnitT, PassT, typename PassT::Result,
812  PreservedAnalyses, Invalidator>;
813 
814  return &static_cast<ResultModelT *>(ResultConcept)->Result;
815  }
816 
817  /// Verify that the given Result cannot be invalidated, assert otherwise.
818  template <typename PassT>
819  void verifyNotInvalidated(IRUnitT &IR, typename PassT::Result *Result) const {
821  SmallDenseMap<AnalysisKey *, bool, 8> IsResultInvalidated;
822  Invalidator Inv(IsResultInvalidated, AnalysisResults);
823  assert(!Result->invalidate(IR, PA, Inv) &&
824  "Cached result cannot be invalidated");
825  }
826 
827  /// Register an analysis pass with the manager.
828  ///
829  /// The parameter is a callable whose result is an analysis pass. This allows
830  /// passing in a lambda to construct the analysis.
831  ///
832  /// The analysis type to register is the type returned by calling the \c
833  /// PassBuilder argument. If that type has already been registered, then the
834  /// argument will not be called and this function will return false.
835  /// Otherwise, we register the analysis returned by calling \c PassBuilder(),
836  /// and this function returns true.
837  ///
838  /// (Note: Although the return value of this function indicates whether or not
839  /// an analysis was previously registered, there intentionally isn't a way to
840  /// query this directly. Instead, you should just register all the analyses
841  /// you might want and let this class run them lazily. This idiom lets us
842  /// minimize the number of times we have to look up analyses in our
843  /// hashtable.)
844  template <typename PassBuilderT>
845  bool registerPass(PassBuilderT &&PassBuilder) {
846  using PassT = decltype(PassBuilder());
847  using PassModelT =
849  Invalidator, ExtraArgTs...>;
850 
851  auto &PassPtr = AnalysisPasses[PassT::ID()];
852  if (PassPtr)
853  // Already registered this pass type!
854  return false;
855 
856  // Construct a new model around the instance returned by the builder.
857  PassPtr.reset(new PassModelT(PassBuilder()));
858  return true;
859  }
860 
861  /// Invalidate cached analyses for an IR unit.
862  ///
863  /// Walk through all of the analyses pertaining to this unit of IR and
864  /// invalidate them, unless they are preserved by the PreservedAnalyses set.
865  void invalidate(IRUnitT &IR, const PreservedAnalyses &PA);
866 
867 private:
868  /// Look up a registered analysis pass.
869  PassConceptT &lookUpPass(AnalysisKey *ID) {
870  typename AnalysisPassMapT::iterator PI = AnalysisPasses.find(ID);
871  assert(PI != AnalysisPasses.end() &&
872  "Analysis passes must be registered prior to being queried!");
873  return *PI->second;
874  }
875 
876  /// Look up a registered analysis pass.
877  const PassConceptT &lookUpPass(AnalysisKey *ID) const {
878  typename AnalysisPassMapT::const_iterator PI = AnalysisPasses.find(ID);
879  assert(PI != AnalysisPasses.end() &&
880  "Analysis passes must be registered prior to being queried!");
881  return *PI->second;
882  }
883 
884  /// Get an analysis result, running the pass if necessary.
885  ResultConceptT &getResultImpl(AnalysisKey *ID, IRUnitT &IR,
886  ExtraArgTs... ExtraArgs);
887 
888  /// Get a cached analysis result or return null.
889  ResultConceptT *getCachedResultImpl(AnalysisKey *ID, IRUnitT &IR) const {
891  AnalysisResults.find({ID, &IR});
892  return RI == AnalysisResults.end() ? nullptr : &*RI->second->second;
893  }
894 
895  /// Map type from analysis pass ID to pass concept pointer.
896  using AnalysisPassMapT =
897  DenseMap<AnalysisKey *, std::unique_ptr<PassConceptT>>;
898 
899  /// Collection of analysis passes, indexed by ID.
900  AnalysisPassMapT AnalysisPasses;
901 
902  /// Map from IR unit to a list of analysis results.
903  ///
904  /// Provides linear time removal of all analysis results for a IR unit and
905  /// the ultimate storage for a particular cached analysis result.
906  AnalysisResultListMapT AnalysisResultLists;
907 
908  /// Map from an analysis ID and IR unit to a particular cached
909  /// analysis result.
910  AnalysisResultMapT AnalysisResults;
911 };
912 
913 extern template class AnalysisManager<Module>;
914 
915 /// Convenience typedef for the Module analysis manager.
917 
918 extern template class AnalysisManager<Function>;
919 
920 /// Convenience typedef for the Function analysis manager.
922 
923 /// An analysis over an "outer" IR unit that provides access to an
924 /// analysis manager over an "inner" IR unit. The inner unit must be contained
925 /// in the outer unit.
926 ///
927 /// For example, InnerAnalysisManagerProxy<FunctionAnalysisManager, Module> is
928 /// an analysis over Modules (the "outer" unit) that provides access to a
929 /// Function analysis manager. The FunctionAnalysisManager is the "inner"
930 /// manager being proxied, and Functions are the "inner" unit. The inner/outer
931 /// relationship is valid because each Function is contained in one Module.
932 ///
933 /// If you're (transitively) within a pass manager for an IR unit U that
934 /// contains IR unit V, you should never use an analysis manager over V, except
935 /// via one of these proxies.
936 ///
937 /// Note that the proxy's result is a move-only RAII object. The validity of
938 /// the analyses in the inner analysis manager is tied to its lifetime.
939 template <typename AnalysisManagerT, typename IRUnitT, typename... ExtraArgTs>
941  : public AnalysisInfoMixin<
942  InnerAnalysisManagerProxy<AnalysisManagerT, IRUnitT>> {
943 public:
944  class Result {
945  public:
946  explicit Result(AnalysisManagerT &InnerAM) : InnerAM(&InnerAM) {}
947 
948  Result(Result &&Arg) : InnerAM(std::move(Arg.InnerAM)) {
949  // We have to null out the analysis manager in the moved-from state
950  // because we are taking ownership of the responsibilty to clear the
951  // analysis state.
952  Arg.InnerAM = nullptr;
953  }
954 
956  // InnerAM is cleared in a moved from state where there is nothing to do.
957  if (!InnerAM)
958  return;
959 
960  // Clear out the analysis manager if we're being destroyed -- it means we
961  // didn't even see an invalidate call when we got invalidated.
962  InnerAM->clear();
963  }
964 
966  InnerAM = RHS.InnerAM;
967  // We have to null out the analysis manager in the moved-from state
968  // because we are taking ownership of the responsibilty to clear the
969  // analysis state.
970  RHS.InnerAM = nullptr;
971  return *this;
972  }
973 
974  /// Accessor for the analysis manager.
975  AnalysisManagerT &getManager() { return *InnerAM; }
976 
977  /// Handler for invalidation of the outer IR unit, \c IRUnitT.
978  ///
979  /// If the proxy analysis itself is not preserved, we assume that the set of
980  /// inner IR objects contained in IRUnit may have changed. In this case,
981  /// we have to call \c clear() on the inner analysis manager, as it may now
982  /// have stale pointers to its inner IR objects.
983  ///
984  /// Regardless of whether the proxy analysis is marked as preserved, all of
985  /// the analyses in the inner analysis manager are potentially invalidated
986  /// based on the set of preserved analyses.
987  bool invalidate(
988  IRUnitT &IR, const PreservedAnalyses &PA,
990 
991  private:
992  AnalysisManagerT *InnerAM;
993  };
994 
995  explicit InnerAnalysisManagerProxy(AnalysisManagerT &InnerAM)
996  : InnerAM(&InnerAM) {}
997 
998  /// Run the analysis pass and create our proxy result object.
999  ///
1000  /// This doesn't do any interesting work; it is primarily used to insert our
1001  /// proxy result object into the outer analysis cache so that we can proxy
1002  /// invalidation to the inner analysis manager.
1004  ExtraArgTs...) {
1005  return Result(*InnerAM);
1006  }
1007 
1008 private:
1009  friend AnalysisInfoMixin<
1011 
1012  static AnalysisKey Key;
1013 
1014  AnalysisManagerT *InnerAM;
1015 };
1016 
1017 template <typename AnalysisManagerT, typename IRUnitT, typename... ExtraArgTs>
1018 AnalysisKey
1019  InnerAnalysisManagerProxy<AnalysisManagerT, IRUnitT, ExtraArgTs...>::Key;
1020 
1021 /// Provide the \c FunctionAnalysisManager to \c Module proxy.
1024 
1025 /// Specialization of the invalidate method for the \c
1026 /// FunctionAnalysisManagerModuleProxy's result.
1027 template <>
1029  Module &M, const PreservedAnalyses &PA,
1031 
1032 // Ensure the \c FunctionAnalysisManagerModuleProxy is provided as an extern
1033 // template.
1035  Module>;
1036 
1037 /// An analysis over an "inner" IR unit that provides access to an
1038 /// analysis manager over a "outer" IR unit. The inner unit must be contained
1039 /// in the outer unit.
1040 ///
1041 /// For example OuterAnalysisManagerProxy<ModuleAnalysisManager, Function> is an
1042 /// analysis over Functions (the "inner" unit) which provides access to a Module
1043 /// analysis manager. The ModuleAnalysisManager is the "outer" manager being
1044 /// proxied, and Modules are the "outer" IR unit. The inner/outer relationship
1045 /// is valid because each Function is contained in one Module.
1046 ///
1047 /// This proxy only exposes the const interface of the outer analysis manager,
1048 /// to indicate that you cannot cause an outer analysis to run from within an
1049 /// inner pass. Instead, you must rely on the \c getCachedResult API. This is
1050 /// due to keeping potential future concurrency in mind. To give an example,
1051 /// running a module analysis before any function passes may give a different
1052 /// result than running it in a function pass. Both may be valid, but it would
1053 /// produce non-deterministic results. GlobalsAA is a good analysis example,
1054 /// because the cached information has the mod/ref info for all memory for each
1055 /// function at the time the analysis was computed. The information is still
1056 /// valid after a function transformation, but it may be *different* if
1057 /// recomputed after that transform. GlobalsAA is never invalidated.
1058 
1059 ///
1060 /// This proxy doesn't manage invalidation in any way -- that is handled by the
1061 /// recursive return path of each layer of the pass manager. A consequence of
1062 /// this is the outer analyses may be stale. We invalidate the outer analyses
1063 /// only when we're done running passes over the inner IR units.
1064 template <typename AnalysisManagerT, typename IRUnitT, typename... ExtraArgTs>
1066  : public AnalysisInfoMixin<
1067  OuterAnalysisManagerProxy<AnalysisManagerT, IRUnitT, ExtraArgTs...>> {
1068 public:
1069  /// Result proxy object for \c OuterAnalysisManagerProxy.
1070  class Result {
1071  public:
1072  explicit Result(const AnalysisManagerT &OuterAM) : OuterAM(&OuterAM) {}
1073 
1074  /// Get a cached analysis. If the analysis can be invalidated, this will
1075  /// assert.
1076  template <typename PassT, typename IRUnitTParam>
1077  typename PassT::Result *getCachedResult(IRUnitTParam &IR) const {
1078  typename PassT::Result *Res =
1079  OuterAM->template getCachedResult<PassT>(IR);
1080  if (Res)
1081  OuterAM->template verifyNotInvalidated<PassT>(IR, Res);
1082  return Res;
1083  }
1084 
1085  /// Method provided for unit testing, not intended for general use.
1086  template <typename PassT, typename IRUnitTParam>
1087  bool cachedResultExists(IRUnitTParam &IR) const {
1088  typename PassT::Result *Res =
1089  OuterAM->template getCachedResult<PassT>(IR);
1090  return Res != nullptr;
1091  }
1092 
1093  /// When invalidation occurs, remove any registered invalidation events.
1095  IRUnitT &IRUnit, const PreservedAnalyses &PA,
1097  // Loop over the set of registered outer invalidation mappings and if any
1098  // of them map to an analysis that is now invalid, clear it out.
1100  for (auto &KeyValuePair : OuterAnalysisInvalidationMap) {
1101  AnalysisKey *OuterID = KeyValuePair.first;
1102  auto &InnerIDs = KeyValuePair.second;
1103  llvm::erase_if(InnerIDs, [&](AnalysisKey *InnerID) {
1104  return Inv.invalidate(InnerID, IRUnit, PA);
1105  });
1106  if (InnerIDs.empty())
1107  DeadKeys.push_back(OuterID);
1108  }
1109 
1110  for (auto OuterID : DeadKeys)
1111  OuterAnalysisInvalidationMap.erase(OuterID);
1112 
1113  // The proxy itself remains valid regardless of anything else.
1114  return false;
1115  }
1116 
1117  /// Register a deferred invalidation event for when the outer analysis
1118  /// manager processes its invalidations.
1119  template <typename OuterAnalysisT, typename InvalidatedAnalysisT>
1121  AnalysisKey *OuterID = OuterAnalysisT::ID();
1122  AnalysisKey *InvalidatedID = InvalidatedAnalysisT::ID();
1123 
1124  auto &InvalidatedIDList = OuterAnalysisInvalidationMap[OuterID];
1125  // Note, this is a linear scan. If we end up with large numbers of
1126  // analyses that all trigger invalidation on the same outer analysis,
1127  // this entire system should be changed to some other deterministic
1128  // data structure such as a `SetVector` of a pair of pointers.
1129  if (!llvm::is_contained(InvalidatedIDList, InvalidatedID))
1130  InvalidatedIDList.push_back(InvalidatedID);
1131  }
1132 
1133  /// Access the map from outer analyses to deferred invalidation requiring
1134  /// analyses.
1137  return OuterAnalysisInvalidationMap;
1138  }
1139 
1140  private:
1141  const AnalysisManagerT *OuterAM;
1142 
1143  /// A map from an outer analysis ID to the set of this IR-unit's analyses
1144  /// which need to be invalidated.
1146  OuterAnalysisInvalidationMap;
1147  };
1148 
1149  OuterAnalysisManagerProxy(const AnalysisManagerT &OuterAM)
1150  : OuterAM(&OuterAM) {}
1151 
1152  /// Run the analysis pass and create our proxy result object.
1153  /// Nothing to see here, it just forwards the \c OuterAM reference into the
1154  /// result.
1156  ExtraArgTs...) {
1157  return Result(*OuterAM);
1158  }
1159 
1160 private:
1161  friend AnalysisInfoMixin<
1162  OuterAnalysisManagerProxy<AnalysisManagerT, IRUnitT, ExtraArgTs...>>;
1163 
1164  static AnalysisKey Key;
1165 
1166  const AnalysisManagerT *OuterAM;
1167 };
1168 
1169 template <typename AnalysisManagerT, typename IRUnitT, typename... ExtraArgTs>
1170 AnalysisKey
1171  OuterAnalysisManagerProxy<AnalysisManagerT, IRUnitT, ExtraArgTs...>::Key;
1172 
1173 extern template class OuterAnalysisManagerProxy<ModuleAnalysisManager,
1174  Function>;
1175 /// Provide the \c ModuleAnalysisManager to \c Function proxy.
1178 
1179 /// Trivial adaptor that maps from a module to its functions.
1180 ///
1181 /// Designed to allow composition of a FunctionPass(Manager) and
1182 /// a ModulePassManager, by running the FunctionPass(Manager) over every
1183 /// function in the module.
1184 ///
1185 /// Function passes run within this adaptor can rely on having exclusive access
1186 /// to the function they are run over. They should not read or modify any other
1187 /// functions! Other threads or systems may be manipulating other functions in
1188 /// the module, and so their state should never be relied on.
1189 /// FIXME: Make the above true for all of LLVM's actual passes, some still
1190 /// violate this principle.
1191 ///
1192 /// Function passes can also read the module containing the function, but they
1193 /// should not modify that module outside of the use lists of various globals.
1194 /// For example, a function pass is not permitted to add functions to the
1195 /// module.
1196 /// FIXME: Make the above true for all of LLVM's actual passes, some still
1197 /// violate this principle.
1198 ///
1199 /// Note that although function passes can access module analyses, module
1200 /// analyses are not invalidated while the function passes are running, so they
1201 /// may be stale. Function analyses will not be stale.
1203  : public PassInfoMixin<ModuleToFunctionPassAdaptor> {
1204 public:
1206 
1207  explicit ModuleToFunctionPassAdaptor(std::unique_ptr<PassConceptT> Pass)
1208  : Pass(std::move(Pass)) {}
1209 
1210  /// Runs the function pass across every function in the module.
1212  void printPipeline(raw_ostream &OS,
1213  function_ref<StringRef(StringRef)> MapClassName2PassName);
1214 
1215  static bool isRequired() { return true; }
1216 
1217 private:
1218  std::unique_ptr<PassConceptT> Pass;
1219 };
1220 
1221 /// A function to deduce a function pass type and wrap it in the
1222 /// templated adaptor.
1223 template <typename FunctionPassT>
1224 ModuleToFunctionPassAdaptor
1226  using PassModelT =
1229  // Do not use make_unique, it causes too many template instantiations,
1230  // causing terrible compile times.
1232  std::unique_ptr<ModuleToFunctionPassAdaptor::PassConceptT>(
1233  new PassModelT(std::forward<FunctionPassT>(Pass))));
1234 }
1235 
1236 /// A utility pass template to force an analysis result to be available.
1237 ///
1238 /// If there are extra arguments at the pass's run level there may also be
1239 /// extra arguments to the analysis manager's \c getResult routine. We can't
1240 /// guess how to effectively map the arguments from one to the other, and so
1241 /// this specialization just ignores them.
1242 ///
1243 /// Specific patterns of run-method extra arguments and analysis manager extra
1244 /// arguments will have to be defined as appropriate specializations.
1245 template <typename AnalysisT, typename IRUnitT,
1246  typename AnalysisManagerT = AnalysisManager<IRUnitT>,
1247  typename... ExtraArgTs>
1249  : PassInfoMixin<RequireAnalysisPass<AnalysisT, IRUnitT, AnalysisManagerT,
1250  ExtraArgTs...>> {
1251  /// Run this pass over some unit of IR.
1252  ///
1253  /// This pass can be run over any unit of IR and use any analysis manager
1254  /// provided they satisfy the basic API requirements. When this pass is
1255  /// created, these methods can be instantiated to satisfy whatever the
1256  /// context requires.
1257  PreservedAnalyses run(IRUnitT &Arg, AnalysisManagerT &AM,
1258  ExtraArgTs &&... Args) {
1259  (void)AM.template getResult<AnalysisT>(Arg,
1260  std::forward<ExtraArgTs>(Args)...);
1261 
1262  return PreservedAnalyses::all();
1263  }
1265  function_ref<StringRef(StringRef)> MapClassName2PassName) {
1266  auto ClassName = AnalysisT::name();
1267  auto PassName = MapClassName2PassName(ClassName);
1268  OS << "require<" << PassName << ">";
1269  }
1270  static bool isRequired() { return true; }
1271 };
1272 
1273 /// A no-op pass template which simply forces a specific analysis result
1274 /// to be invalidated.
1275 template <typename AnalysisT>
1277  : PassInfoMixin<InvalidateAnalysisPass<AnalysisT>> {
1278  /// Run this pass over some unit of IR.
1279  ///
1280  /// This pass can be run over any unit of IR and use any analysis manager,
1281  /// provided they satisfy the basic API requirements. When this pass is
1282  /// created, these methods can be instantiated to satisfy whatever the
1283  /// context requires.
1284  template <typename IRUnitT, typename AnalysisManagerT, typename... ExtraArgTs>
1285  PreservedAnalyses run(IRUnitT &Arg, AnalysisManagerT &AM, ExtraArgTs &&...) {
1286  auto PA = PreservedAnalyses::all();
1287  PA.abandon<AnalysisT>();
1288  return PA;
1289  }
1291  function_ref<StringRef(StringRef)> MapClassName2PassName) {
1292  auto ClassName = AnalysisT::name();
1293  auto PassName = MapClassName2PassName(ClassName);
1294  OS << "invalidate<" << PassName << ">";
1295  }
1296 };
1297 
1298 /// A utility pass that does nothing, but preserves no analyses.
1299 ///
1300 /// Because this preserves no analyses, any analysis passes queried after this
1301 /// pass runs will recompute fresh results.
1302 struct InvalidateAllAnalysesPass : PassInfoMixin<InvalidateAllAnalysesPass> {
1303  /// Run this pass over some unit of IR.
1304  template <typename IRUnitT, typename AnalysisManagerT, typename... ExtraArgTs>
1305  PreservedAnalyses run(IRUnitT &, AnalysisManagerT &, ExtraArgTs &&...) {
1306  return PreservedAnalyses::none();
1307  }
1308 };
1309 
1310 /// A utility pass template that simply runs another pass multiple times.
1311 ///
1312 /// This can be useful when debugging or testing passes. It also serves as an
1313 /// example of how to extend the pass manager in ways beyond composition.
1314 template <typename PassT>
1315 class RepeatedPass : public PassInfoMixin<RepeatedPass<PassT>> {
1316 public:
1317  RepeatedPass(int Count, PassT &&P)
1318  : Count(Count), P(std::forward<PassT>(P)) {}
1319 
1320  template <typename IRUnitT, typename AnalysisManagerT, typename... Ts>
1321  PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT &AM, Ts &&... Args) {
1322 
1323  // Request PassInstrumentation from analysis manager, will use it to run
1324  // instrumenting callbacks for the passes later.
1325  // Here we use std::tuple wrapper over getResult which helps to extract
1326  // AnalysisManager's arguments out of the whole Args set.
1327  PassInstrumentation PI =
1328  detail::getAnalysisResult<PassInstrumentationAnalysis>(
1329  AM, IR, std::tuple<Ts...>(Args...));
1330 
1331  auto PA = PreservedAnalyses::all();
1332  for (int i = 0; i < Count; ++i) {
1333  // Check the PassInstrumentation's BeforePass callbacks before running the
1334  // pass, skip its execution completely if asked to (callback returns
1335  // false).
1336  if (!PI.runBeforePass<IRUnitT>(P, IR))
1337  continue;
1338  PreservedAnalyses IterPA = P.run(IR, AM, std::forward<Ts>(Args)...);
1339  PA.intersect(IterPA);
1340  PI.runAfterPass(P, IR, IterPA);
1341  }
1342  return PA;
1343  }
1344 
1346  function_ref<StringRef(StringRef)> MapClassName2PassName) {
1347  OS << "repeat<" << Count << ">(";
1348  P.printPipeline(OS, MapClassName2PassName);
1349  OS << ")";
1350  }
1351 
1352 private:
1353  int Count;
1354  PassT P;
1355 };
1356 
1357 template <typename PassT>
1359  return RepeatedPass<PassT>(Count, std::forward<PassT>(P));
1360 }
1361 
1362 } // end namespace llvm
1363 
1364 #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:113
i
i
Definition: README.txt:29
llvm::ModuleToFunctionPassAdaptor
Trivial adaptor that maps from a module to its functions.
Definition: PassManager.h:1202
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:1065
llvm::OuterAnalysisManagerProxy::OuterAnalysisManagerProxy
OuterAnalysisManagerProxy(const AnalysisManagerT &OuterAM)
Definition: PassManager.h:1149
PassManagerInternal.h
llvm
This file implements support for optimizing divisions by a constant.
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:577
llvm::OuterAnalysisManagerProxy::run
Result run(IRUnitT &, AnalysisManager< IRUnitT, ExtraArgTs... > &, ExtraArgTs...)
Run the analysis pass and create our proxy result object.
Definition: PassManager.h:1155
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:948
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:783
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:1094
llvm::ModuleAnalysisManagerFunctionProxy
OuterAnalysisManagerProxy< ModuleAnalysisManager, Function > ModuleAnalysisManagerFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
Definition: PassManager.h:1177
llvm::Function
Definition: Function.h:62
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:688
llvm::AnalysisManager::invalidate
void invalidate(IRUnitT &IR, const PreservedAnalyses &PA)
Invalidate cached analyses for an IR unit.
Definition: PassManagerImpl.h:89
StringRef.h
llvm::PassManager::addPass
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!std::is_same< PassT, PassManager >::value > addPass(PassT &&Pass)
Definition: PassManager.h:553
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:995
llvm::InnerAnalysisManagerProxy::Result
Definition: PassManager.h:944
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:1285
llvm::OuterAnalysisManagerProxy::Result::cachedResultExists
bool cachedResultExists(IRUnitTParam &IR) const
Method provided for unit testing, not intended for general use.
Definition: PassManager.h:1087
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
LLVM_ATTRIBUTE_MINSIZE
#define LLVM_ATTRIBUTE_MINSIZE
Definition: Compiler.h:218
Module.h
llvm::ModuleAnalysisManager
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition: PassManager.h:916
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:619
llvm::RepeatedPass::printPipeline
void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
Definition: PassManager.h:1345
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:583
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:754
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:1225
llvm::createRepeatedPass
RepeatedPass< PassT > createRepeatedPass(int Count, PassT &&P)
Definition: PassManager.h:1358
llvm::OuterAnalysisManagerProxy::Result
Result proxy object for OuterAnalysisManagerProxy.
Definition: PassManager.h:1070
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:1305
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:1290
llvm::AnalysisManager::Invalidator
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:670
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:585
llvm::RequireAnalysisPass::printPipeline
void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
Definition: PassManager.h:1264
llvm::PassManager::addPass
LLVM_ATTRIBUTE_MINSIZE 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:571
llvm::PassInstrumentationAnalysis::PassInstrumentationAnalysis
PassInstrumentationAnalysis(PassInstrumentationCallbacks *Callbacks=nullptr)
PassInstrumentationCallbacks object is shared, owned by something else, not this analysis.
Definition: PassManager.h:613
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:1072
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:1302
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:1276
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:1317
llvm::ModuleToFunctionPassAdaptor::printPipeline
void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
Definition: PassManager.cpp:106
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:946
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:819
llvm::RepeatedPass::run
PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT &AM, Ts &&... Args)
Definition: PassManager.h:1321
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:1257
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:1315
name
static const char * name
Definition: SVEIntrinsicOpts.cpp:78
llvm::ModuleToFunctionPassAdaptor::ModuleToFunctionPassAdaptor
ModuleToFunctionPassAdaptor(std::unique_ptr< PassConceptT > Pass)
Definition: PassManager.h:1207
llvm::ModuleToFunctionPassAdaptor::isRequired
static bool isRequired()
Definition: PassManager.h:1215
llvm::AnalysisManager::clear
void clear()
Clear all analysis results cached by this AnalysisManager.
Definition: PassManager.h:774
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:965
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:802
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:579
llvm::AnalysisManager::registerPass
bool registerPass(PassBuilderT &&PassBuilder)
Register an analysis pass with the manager.
Definition: PassManager.h:845
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:702
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:1120
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:975
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:921
llvm::OuterAnalysisManagerProxy::Result::getCachedResult
PassT::Result * getCachedResult(IRUnitTParam &IR) const
Get a cached analysis.
Definition: PassManager.h:1077
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:603
llvm::InnerAnalysisManagerProxy
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:940
llvm::InnerAnalysisManagerProxy::Result::~Result
~Result()
Definition: PassManager.h:955
llvm::RequireAnalysisPass
A utility pass template to force an analysis result to be available.
Definition: PassManager.h:1248
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::InnerAnalysisManagerProxy::run
Result run(IRUnitT &IR, AnalysisManager< IRUnitT, ExtraArgTs... > &AM, ExtraArgTs...)
Run the analysis pass and create our proxy result object.
Definition: PassManager.h:1003
llvm::RequireAnalysisPass::isRequired
static bool isRequired()
Definition: PassManager.h:1270
TimeProfiler.h
llvm::FunctionAnalysisManagerModuleProxy
InnerAnalysisManagerProxy< FunctionAnalysisManager, Module > FunctionAnalysisManagerModuleProxy
Provide the FunctionAnalysisManager to Module proxy.
Definition: PassManager.h:1023
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:1136