llvm.org GIT mirror llvm / 33d5681
[PM] Change the static object whose address is used to uniquely identify analyses to have a common type which is enforced rather than using a char object and a `void *` type when used as an identifier. This has a number of advantages. First, it at least helps some of the confusion raised in Justin Lebar's code review of why `void *` was being used everywhere by having a stronger type that connects to documentation about this. However, perhaps more importantly, it addresses a serious issue where the alignment of these pointer-like identifiers was unknown. This made it hard to use them in pointer-like data structures. We were already dodging this in dangerous ways to create the "all analyses" entry. In a subsequent patch I attempted to use these with TinyPtrVector and things fell apart in a very bad way. And it isn't just a compile time or type system issue. Worse than that, the actual alignment of these pointer-like opaque identifiers wasn't guaranteed to be a useful alignment as they were just characters. This change introduces a type to use as the "key" object whose address forms the opaque identifier. This both forces the objects to have proper alignment, and provides type checking that we get it right everywhere. It also makes the types somewhat less mysterious than `void *`. We could go one step further and introduce a truly opaque pointer-like type to return from the `ID()` static function rather than returning `AnalysisKey *`, but that didn't seem to be a clear win so this is just the initial change to get to a reliably typed and aligned object serving is a key for all the analyses. Thanks to Richard Smith and Justin Lebar for helping pick plausible names and avoid making this refactoring many times. =] And thanks to Sean for the super fast review! While here, I've tried to move away from the "PassID" nomenclature entirely as it wasn't really helping and is overloaded with old pass manager constructs. Now we have IDs for analyses, and key objects whose address can be used as IDs. Where possible and clear I've shortened this to just "ID". In a few places I kept "AnalysisID" to make it clear what was being identified. Differential Revision: https://reviews.llvm.org/D27031 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287783 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 2 years ago
71 changed file(s) with 186 addition(s) and 188 deletion(s). Raw diff Collapse all Expand all
910910
911911 private:
912912 friend AnalysisInfoMixin;
913 static char PassID;
913 static AnalysisKey Key;
914914
915915 SmallVector
916916 AAResults &AAResults),
9494 /// assumption caches for a given function.
9595 class AssumptionAnalysis : public AnalysisInfoMixin {
9696 friend AnalysisInfoMixin;
97 static char PassID;
97 static AnalysisKey Key;
9898
9999 public:
100100 typedef AssumptionCache Result;
195195 /// Analysis pass providing a never-invalidated alias analysis result.
196196 class BasicAA : public AnalysisInfoMixin {
197197 friend AnalysisInfoMixin;
198 static char PassID;
198 static AnalysisKey Key;
199199
200200 public:
201201 typedef BasicAAResult Result;
8989 class BlockFrequencyAnalysis
9090 : public AnalysisInfoMixin {
9191 friend AnalysisInfoMixin;
92 static char PassID;
92 static AnalysisKey Key;
9393
9494 public:
9595 /// \brief Provide the result typedef for this analysis pass.
177177 class BranchProbabilityAnalysis
178178 : public AnalysisInfoMixin {
179179 friend AnalysisInfoMixin;
180 static char PassID;
180 static AnalysisKey Key;
181181
182182 public:
183183 /// \brief Provide the result typedef for this analysis pass.
102102 /// in particular to leverage invalidation to trigger re-computation.
103103 class CFLAndersAA : public AnalysisInfoMixin {
104104 friend AnalysisInfoMixin;
105 static char PassID;
105 static AnalysisKey Key;
106106
107107 public:
108108 typedef CFLAndersAAResult Result;
121121 /// in particular to leverage invalidation to trigger re-computation of sets.
122122 class CFLSteensAA : public AnalysisInfoMixin {
123123 friend AnalysisInfoMixin;
124 static char PassID;
124 static AnalysisKey Key;
125125
126126 public:
127127 typedef CFLSteensAAResult Result;
296296 /// resulting data.
297297 class CallGraphAnalysis : public AnalysisInfoMixin {
298298 friend AnalysisInfoMixin;
299 static char PassID;
299 static AnalysisKey Key;
300300
301301 public:
302302 /// \brief A formulaic typedef to inform clients of the result type.
8888 /// An analysis that produces \c DemandedBits for a function.
8989 class DemandedBitsAnalysis : public AnalysisInfoMixin {
9090 friend AnalysisInfoMixin;
91 static char PassID;
91 static AnalysisKey Key;
9292
9393 public:
9494 /// \brief Provide the result typedef for this analysis pass.
920920 Result run(Function &F, FunctionAnalysisManager &FAM);
921921
922922 private:
923 static char PassID;
923 static AnalysisKey Key;
924924 friend struct AnalysisInfoMixin;
925925 }; // class DependenceAnalysis
926926
170170 class DominanceFrontierAnalysis
171171 : public AnalysisInfoMixin {
172172 friend AnalysisInfoMixin;
173 static char PassID;
173 static AnalysisKey Key;
174174
175175 public:
176176 /// \brief Provide the result typedef for this analysis pass.
119119 /// Analysis pass providing a never-invalidated alias analysis result.
120120 class GlobalsAA : public AnalysisInfoMixin {
121121 friend AnalysisInfoMixin;
122 static char PassID;
122 static AnalysisKey Key;
123123
124124 public:
125125 typedef GlobalsAAResult Result;
187187 /// Analysis pass that exposes the \c IVUsers for a loop.
188188 class IVUsersAnalysis : public AnalysisInfoMixin {
189189 friend AnalysisInfoMixin;
190 static char PassID;
190 static AnalysisKey Key;
191191
192192 public:
193193 typedef IVUsers Result;
11441144 /// An analysis pass which computes the call graph for a module.
11451145 class LazyCallGraphAnalysis : public AnalysisInfoMixin {
11461146 friend AnalysisInfoMixin;
1147 static char PassID;
1147 static AnalysisKey Key;
11481148
11491149 public:
11501150 /// Inform generic clients of the result type.
108108 Result run(Function &F, FunctionAnalysisManager &FAM);
109109
110110 private:
111 static char PassID;
111 static AnalysisKey Key;
112112 friend struct AnalysisInfoMixin;
113113 };
114114
748748 class LoopAccessAnalysis
749749 : public AnalysisInfoMixin {
750750 friend AnalysisInfoMixin;
751 static char PassID;
751 static AnalysisKey Key;
752752
753753 public:
754754 typedef LoopAccessInfo Result;
804804 /// \brief Analysis pass that exposes the \c LoopInfo for a function.
805805 class LoopAnalysis : public AnalysisInfoMixin {
806806 friend AnalysisInfoMixin;
807 static char PassID;
807 static AnalysisKey Key;
808808
809809 public:
810810 typedef LoopInfo Result;
484484 class MemoryDependenceAnalysis
485485 : public AnalysisInfoMixin {
486486 friend AnalysisInfoMixin;
487 static char PassID;
487 static AnalysisKey Key;
488488
489489 public:
490490 typedef MemoryDependenceResults Result;
3737 class ModuleSummaryIndexAnalysis
3838 : public AnalysisInfoMixin {
3939 friend AnalysisInfoMixin;
40 static char PassID;
40 static AnalysisKey Key;
4141
4242 public:
4343 typedef ModuleSummaryIndex Result;
6262 /// Analysis pass providing a never-invalidated alias analysis result.
6363 class ObjCARCAA : public AnalysisInfoMixin {
6464 friend AnalysisInfoMixin;
65 static char PassID;
65 static AnalysisKey Key;
6666
6767 public:
6868 typedef ObjCARCAAResult Result;
250250 class OptimizationRemarkEmitterAnalysis
251251 : public AnalysisInfoMixin {
252252 friend AnalysisInfoMixin;
253 static char PassID;
253 static AnalysisKey Key;
254254
255255 public:
256256 /// \brief Provide the result typedef for this analysis pass.
3131 class PostDominatorTreeAnalysis
3232 : public AnalysisInfoMixin {
3333 friend AnalysisInfoMixin;
34 static char PassID;
34 static AnalysisKey Key;
3535
3636 public:
3737 /// \brief Provide the result typedef for this analysis pass.
9393
9494 private:
9595 friend AnalysisInfoMixin;
96 static char PassID;
96 static AnalysisKey Key;
9797 };
9898
9999 /// \brief Printer pass that uses \c ProfileSummaryAnalysis.
932932 /// \brief Analysis pass that exposes the \c RegionInfo for a function.
933933 class RegionInfoAnalysis : public AnalysisInfoMixin {
934934 friend AnalysisInfoMixin;
935 static char PassID;
935 static AnalysisKey Key;
936936
937937 public:
938938 typedef RegionInfo Result;
16251625 class ScalarEvolutionAnalysis
16261626 : public AnalysisInfoMixin {
16271627 friend AnalysisInfoMixin;
1628 static char PassID;
1628 static AnalysisKey Key;
16291629
16301630 public:
16311631 typedef ScalarEvolution Result;
3939 /// Analysis pass providing a never-invalidated alias analysis result.
4040 class SCEVAA : public AnalysisInfoMixin {
4141 friend AnalysisInfoMixin;
42 static char PassID;
42 static AnalysisKey Key;
4343
4444 public:
4545 typedef SCEVAAResult Result;
4242 /// Analysis pass providing a never-invalidated alias analysis result.
4343 class ScopedNoAliasAA : public AnalysisInfoMixin {
4444 friend AnalysisInfoMixin;
45 static char PassID;
45 static AnalysisKey Key;
4646
4747 public:
4848 typedef ScopedNoAliasAAResult Result;
342342
343343 private:
344344 friend AnalysisInfoMixin;
345 static char PassID;
345 static AnalysisKey Key;
346346
347347 Optional PresetInfoImpl;
348348
11271127
11281128 private:
11291129 friend AnalysisInfoMixin;
1130 static char PassID;
1130 static AnalysisKey Key;
11311131
11321132 /// \brief The callback used to produce a result.
11331133 ///
4646 /// Analysis pass providing a never-invalidated alias analysis result.
4747 class TypeBasedAA : public AnalysisInfoMixin {
4848 friend AnalysisInfoMixin;
49 static char PassID;
49 static AnalysisKey Key;
5050
5151 public:
5252 typedef TypeBasedAAResult Result;
187187 /// \brief Analysis pass which computes a \c DominatorTree.
188188 class DominatorTreeAnalysis : public AnalysisInfoMixin {
189189 friend AnalysisInfoMixin;
190 static char PassID;
190 static AnalysisKey Key;
191191
192192 public:
193193 /// \brief Provide the result typedef for this analysis pass.
5353
5454 namespace llvm {
5555
56 /// A special type used by analysis passes to provide an address that
57 /// identifies that particular analysis pass type.
58 ///
59 /// Analysis passes should have a static data member of this type and derive
60 /// from the \c AnalysisInfoMixin to get a static ID method used to identify
61 /// the analysis in the pass management infrastructure.
62 struct alignas(8) AnalysisKey {};
63
5664 /// \brief An abstract set of preserved analyses following a transformation pass
5765 /// run.
5866 ///
7078 /// \brief Construct a special preserved set that preserves all passes.
7179 static PreservedAnalyses all() {
7280 PreservedAnalyses PA;
73 PA.PreservedPassIDs.insert((void *)AllPassesID);
81 PA.PreservedAnalysisIDs.insert(&AllAnalysesKey);
7482 return PA;
7583 }
7684
7785 /// \brief Mark a particular pass as preserved, adding it to the set.
7886 template void preserve() { preserve(PassT::ID()); }
7987
80 /// \brief Mark an abstract PassID as preserved, adding it to the set.
81 void preserve(void *PassID) {
88 /// \brief Mark an abstract ID as preserved, adding it to the set.
89 void preserve(AnalysisKey *ID) {
8290 if (!areAllPreserved())
83 PreservedPassIDs.insert(PassID);
91 PreservedAnalysisIDs.insert(ID);
8492 }
8593
8694 /// \brief Intersect this set with another in place.
9199 if (Arg.areAllPreserved())
92100 return;
93101 if (areAllPreserved()) {
94 PreservedPassIDs = Arg.PreservedPassIDs;
102 PreservedAnalysisIDs = Arg.PreservedAnalysisIDs;
95103 return;
96104 }
97 for (void *P : PreservedPassIDs)
98 if (!Arg.PreservedPassIDs.count(P))
99 PreservedPassIDs.erase(P);
105 for (auto ID : PreservedAnalysisIDs)
106 if (!Arg.PreservedAnalysisIDs.count(ID))
107 PreservedAnalysisIDs.erase(ID);
100108 }
101109
102110 /// \brief Intersect this set with a temporary other set in place.
107115 if (Arg.areAllPreserved())
108116 return;
109117 if (areAllPreserved()) {
110 PreservedPassIDs = std::move(Arg.PreservedPassIDs);
118 PreservedAnalysisIDs = std::move(Arg.PreservedAnalysisIDs);
111119 return;
112120 }
113 for (void *P : PreservedPassIDs)
114 if (!Arg.PreservedPassIDs.count(P))
115 PreservedPassIDs.erase(P);
121 for (auto ID : PreservedAnalysisIDs)
122 if (!Arg.PreservedAnalysisIDs.count(ID))
123 PreservedAnalysisIDs.erase(ID);
116124 }
117125
118126 /// \brief Query whether a pass is marked as preserved by this set.
122130
123131 /// \brief Query whether an abstract pass ID is marked as preserved by this
124132 /// set.
125 bool preserved(void *PassID) const {
126 return PreservedPassIDs.count((void *)AllPassesID) ||
127 PreservedPassIDs.count(PassID);
133 bool preserved(AnalysisKey *ID) const {
134 return PreservedAnalysisIDs.count(&AllAnalysesKey) ||
135 PreservedAnalysisIDs.count(ID);
128136 }
129137
130138 /// \brief Query whether all of the analyses in the set are preserved.
131139 bool preserved(PreservedAnalyses Arg) {
132140 if (Arg.areAllPreserved())
133141 return areAllPreserved();
134 for (void *P : Arg.PreservedPassIDs)
135 if (!preserved(P))
142 for (auto ID : Arg.PreservedAnalysisIDs)
143 if (!preserved(ID))
136144 return false;
137145 return true;
138146 }
142150 /// This is used primarily to optimize for the case of no changes which will
143151 /// common in many scenarios.
144152 bool areAllPreserved() const {
145 return PreservedPassIDs.count((void *)AllPassesID);
153 return PreservedAnalysisIDs.count(&AllAnalysesKey);
146154 }
147155
148156 private:
149 // Note that this must not be -1 or -2 as those are already used by the
150 // SmallPtrSet.
151 static const uintptr_t AllPassesID = (intptr_t)(-3);
152
153 SmallPtrSet PreservedPassIDs;
157 // A special key used to indicate all analyses.
158 static AnalysisKey AllAnalysesKey;
159
160 SmallPtrSet PreservedAnalysisIDs;
154161 };
155162
156163 // Forward declare the analysis manager template.
178185 /// specifically used for analyses.
179186 template
180187 struct AnalysisInfoMixin : PassInfoMixin {
181 /// Returns an opaque, unique ID for this pass type.
182 ///
183 /// Note that this requires the derived type provide a static member whose
184 /// address can be converted to a void pointer.
188 /// Returns an opaque, unique ID for this analysis type.
189 ///
190 /// This ID is a pointer type that is guaranteed to be 8-byte aligned and
191 /// thus suitable for use in sets, maps, and other data structures optimized
192 /// for pointer-like types using the alignment-provided low bits.
193 ///
194 /// Note that this requires the derived type provide a static \c AnalysisKey
195 /// member called \c Key.
185196 ///
186197 /// FIXME: The only reason the derived type needs to provide this rather than
187198 /// this mixin providing it is due to broken implementations which cannot
190201 /// instantiation. The only currently known platform with this limitation are
191202 /// Windows DLL builds, specifically building each part of LLVM as a DLL. If
192203 /// we ever remove that build configuration, this mixin can provide the
193 /// static PassID as well.
194 static void *ID() { return (void *)&DerivedT::PassID; }
204 /// static key as well.
205 static AnalysisKey *ID() { return &DerivedT::Key; }
195206 };
196207
197208 /// A class template to provide analysis sets for IR units.
204215 ///
205216 /// Note that you must provide an explicit instantiation declaration and
206217 /// definition for this template in order to get the correct behavior on
207 /// Windows. Otherwise, the address of SetID will not be stable.
218 /// Windows. Otherwise, the address of SetKey will not be stable.
208219 template
209220 class AllAnalysesOn {
210221 public:
211 static void *ID() { return (void *)&SetID; }
222 static AnalysisKey *ID() { return &SetKey; }
212223
213224 private:
214 static char SetID;
215 };
216
217 template char AllAnalysesOn::SetID;
225 static AnalysisKey SetKey;
226 };
227
228 template AnalysisKey AllAnalysesOn::SetKey;
218229
219230 extern template class AllAnalysesOn;
220231 extern template class AllAnalysesOn;
362373
363374 // Clear all the invalidated results associated specifically with this
364375 // function.
365 SmallVector<void *, 8> InvalidatedPassIDs;
376 SmallVector<AnalysisKey *, 8> InvalidatedIDs;
366377 auto ResultsListI = AnalysisResultLists.find(&IR);
367378 if (ResultsListI == AnalysisResultLists.end())
368379 return;
369380 // Clear the map pointing into the results list.
370 for (auto &PassIDAndResult : ResultsListI->second)
371 AnalysisResults.erase(std::make_pair(PassIDAndResult.first, &IR));
381 for (auto &IDAndResult : ResultsListI->second)
382 AnalysisResults.erase(std::make_pair(IDAndResult.first, &IR));
372383
373384 // And actually destroy and erase the results associated with this IR.
374385 AnalysisResultLists.erase(ResultsListI);
478489
479490 // Clear all the invalidated results associated specifically with this
480491 // function.
481 SmallVector<void *, 8> InvalidatedPassIDs;
492 SmallVector<AnalysisKey *, 8> InvalidatedIDs;
482493 AnalysisResultListT &ResultsList = AnalysisResultLists[&IR];
483494 for (typename AnalysisResultListT::iterator I = ResultsList.begin(),
484495 E = ResultsList.end();
485496 I != E;) {
486 void *PassID = I->first;
497 AnalysisKey *ID = I->first;
487498
488499 // Pass the invalidation down to the pass itself to see if it thinks it is
489500 // necessary. The analysis pass can return false if no action on the part
490501 // of the analysis manager is required for this invalidation event.
491502 if (I->second->invalidate(IR, PA)) {
492503 if (DebugLogging)
493 dbgs() << "Invalidating analysis: " << this->lookupPass(PassID).name()
504 dbgs() << "Invalidating analysis: " << this->lookupPass(ID).name()
494505 << "\n";
495506
496 InvalidatedPassIDs.push_back(I->first);
507 InvalidatedIDs.push_back(I->first);
497508 I = ResultsList.erase(I);
498509 } else {
499510 ++I;
502513 // After handling each pass, we mark it as preserved. Once we've
503514 // invalidated any stale results, the rest of the system is allowed to
504515 // start preserving this analysis again.
505 PA.preserve(PassID);
516 PA.preserve(ID);
506517 }
507 while (!InvalidatedPassIDs.empty())
508 AnalysisResults.erase(
509 std::make_pair(InvalidatedPassIDs.pop_back_val(), &IR));
518 while (!InvalidatedIDs.empty())
519 AnalysisResults.erase(std::make_pair(InvalidatedIDs.pop_back_val(), &IR));
510520 if (ResultsList.empty())
511521 AnalysisResultLists.erase(&IR);
512522
515525
516526 private:
517527 /// \brief Lookup a registered analysis pass.
518 PassConceptT &lookupPass(void *PassID) {
519 typename AnalysisPassMapT::iterator PI = AnalysisPasses.find(PassID);
528 PassConceptT &lookupPass(AnalysisKey *ID) {
529 typename AnalysisPassMapT::iterator PI = AnalysisPasses.find(ID);
520530 assert(PI != AnalysisPasses.end() &&
521531 "Analysis passes must be registered prior to being queried!");
522532 return *PI->second;
523533 }
524534
525535 /// \brief Lookup a registered analysis pass.
526 const PassConceptT &lookupPass(void *PassID) const {
527 typename AnalysisPassMapT::const_iterator PI = AnalysisPasses.find(PassID);
536 const PassConceptT &lookupPass(AnalysisKey *ID) const {
537 typename AnalysisPassMapT::const_iterator PI = AnalysisPasses.find(ID);
528538 assert(PI != AnalysisPasses.end() &&
529539 "Analysis passes must be registered prior to being queried!");
530540 return *PI->second;
531541 }
532542
533543 /// \brief Get an analysis result, running the pass if necessary.
534 ResultConceptT &getResultImpl(void *PassID, IRUnitT &IR,
544 ResultConceptT &getResultImpl(AnalysisKey *ID, IRUnitT &IR,
535545 ExtraArgTs... ExtraArgs) {
536546 typename AnalysisResultMapT::iterator RI;
537547 bool Inserted;
538548 std::tie(RI, Inserted) = AnalysisResults.insert(std::make_pair(
539 std::make_pair(PassID, &IR), typename AnalysisResultListT::iterator()));
549 std::make_pair(ID, &IR), typename AnalysisResultListT::iterator()));
540550
541551 // If we don't have a cached result for this function, look up the pass and
542552 // run it to produce a result, which we then add to the cache.
543553 if (Inserted) {
544 auto &P = this->lookupPass(PassID);
554 auto &P = this->lookupPass(ID);
545555 if (DebugLogging)
546556 dbgs() << "Running analysis: " << P.name() << "\n";
547557 AnalysisResultListT &ResultList = AnalysisResultLists[&IR];
548 ResultList.emplace_back(PassID, P.run(IR, *this, ExtraArgs...));
558 ResultList.emplace_back(ID, P.run(IR, *this, ExtraArgs...));
549559
550560 // P.run may have inserted elements into AnalysisResults and invalidated
551561 // RI.
552 RI = AnalysisResults.find(std::make_pair(PassID, &IR));
562 RI = AnalysisResults.find(std::make_pair(ID, &IR));
553563 assert(RI != AnalysisResults.end() && "we just inserted it!");
554564
555565 RI->second = std::prev(ResultList.end());
559569 }
560570
561571 /// \brief Get a cached analysis result or return null.
562 ResultConceptT *getCachedResultImpl(void *PassID, IRUnitT &IR) const {
572 ResultConceptT *getCachedResultImpl(AnalysisKey *ID, IRUnitT &IR) const {
563573 typename AnalysisResultMapT::const_iterator RI =
564 AnalysisResults.find(std::make_pair(PassID, &IR));
574 AnalysisResults.find(std::make_pair(ID, &IR));
565575 return RI == AnalysisResults.end() ? nullptr : &*RI->second->second;
566576 }
567577
568578 /// \brief Invalidate a function pass result.
569 void invalidateImpl(void *PassID, IRUnitT &IR) {
579 void invalidateImpl(AnalysisKey *ID, IRUnitT &IR) {
570580 typename AnalysisResultMapT::iterator RI =
571 AnalysisResults.find(std::make_pair(PassID, &IR));
581 AnalysisResults.find(std::make_pair(ID, &IR));
572582 if (RI == AnalysisResults.end())
573583 return;
574584
575585 if (DebugLogging)
576 dbgs() << "Invalidating analysis: " << this->lookupPass(PassID).name()
586 dbgs() << "Invalidating analysis: " << this->lookupPass(ID).name()
577587 << "\n";
578588 AnalysisResultLists[&IR].erase(RI->second);
579589 AnalysisResults.erase(RI);
580590 }
581591
582592 /// \brief Map type from module analysis pass ID to pass concept pointer.
583 typedef DenseMap<void *, std::unique_ptr> AnalysisPassMapT;
593 typedef DenseMap<AnalysisKey *, std::unique_ptr> AnalysisPassMapT;
584594
585595 /// \brief Collection of module analysis passes, indexed by ID.
586596 AnalysisPassMapT AnalysisPasses;
591601 /// erases. Provides both the pass ID and concept pointer such that it is
592602 /// half of a bijection and provides storage for the actual result concept.
593603 typedef std::list
594 void *, std::unique_ptr>>>
604 AnalysisKey *, std::unique_ptr>>>
595605 AnalysisResultListT;
596606
597607 /// \brief Map type from function pointer to our custom list type.
605615
606616 /// \brief Map type from a pair of analysis ID and function pointer to an
607617 /// iterator into a particular result list.
608 typedef DenseMapvoid *, IRUnitT *>,
618 typedef DenseMapAnalysisKey *, IRUnitT *>,
609619 typename AnalysisResultListT::iterator>
610620 AnalysisResultMapT;
611621
717727 private:
718728 friend AnalysisInfoMixin<
719729 InnerAnalysisManagerProxy>;
720 static char PassID;
730 static AnalysisKey Key;
721731
722732 AnalysisManagerT *AM;
723733 };
724734
725735 template
726 char
727 InnerAnalysisManagerProxy::PassID;
736 AnalysisKey
737 InnerAnalysisManagerProxy::Key;
728738
729739 extern template class InnerAnalysisManagerProxy
730740 Module>;
776786 private:
777787 friend AnalysisInfoMixin<
778788 OuterAnalysisManagerProxy>;
779 static char PassID;
789 static AnalysisKey Key;
780790
781791 const AnalysisManagerT *AM;
782792 };
783793
784794 template
785 char
786 OuterAnalysisManagerProxy::PassID;
795 AnalysisKey
796 OuterAnalysisManagerProxy::Key;
787797
788798 extern template class OuterAnalysisManagerProxy
789799 Function>;
5757 /// and debug info errors.
5858 class VerifierAnalysis : public AnalysisInfoMixin {
5959 friend AnalysisInfoMixin;
60 static char PassID;
60 static AnalysisKey Key;
6161
6262 public:
6363 struct Result {
6464 bool IRBroken, DebugInfoBroken;
6565 };
66 static void *ID() { return (void *)&PassID; }
6766 Result run(Module &M, ModuleAnalysisManager &);
6867 Result run(Function &F, FunctionAnalysisManager &);
6968 };
671671 ///
672672 class MemorySSAAnalysis : public AnalysisInfoMixin {
673673 friend AnalysisInfoMixin;
674 static char PassID;
674 static AnalysisKey Key;
675675
676676 public:
677677 // Wrap MemorySSA result to ensure address stability of internal MemorySSA
512512 AAResults::Concept::~Concept() {}
513513
514514 // Provide a definition for the static object used to identify passes.
515 char AAManager::PassID;
515 AnalysisKey AAManager::Key;
516516
517517 namespace {
518518 /// A wrapper pass for external alias analyses. This just squirrels away the
7373 #endif
7474 }
7575
76 char AssumptionAnalysis::PassID;
76 AnalysisKey AssumptionAnalysis::Key;
7777
7878 PreservedAnalyses AssumptionPrinterPass::run(Function &F,
7979 FunctionAnalysisManager &AM) {
17141714 // BasicAliasAnalysis Pass
17151715 //===----------------------------------------------------------------------===//
17161716
1717 char BasicAA::PassID;
1717 AnalysisKey BasicAA::Key;
17181718
17191719 BasicAAResult BasicAA::run(Function &F, FunctionAnalysisManager &AM) {
17201720 return BasicAAResult(F.getParent()->getDataLayout(),
251251 return false;
252252 }
253253
254 char BlockFrequencyAnalysis::PassID;
254 AnalysisKey BlockFrequencyAnalysis::Key;
255255 BlockFrequencyInfo BlockFrequencyAnalysis::run(Function &F,
256256 FunctionAnalysisManager &AM) {
257257 BlockFrequencyInfo BFI;
710710 BPI.print(OS);
711711 }
712712
713 char BranchProbabilityAnalysis::PassID;
713 AnalysisKey BranchProbabilityAnalysis::Key;
714714 BranchProbabilityInfo
715715 BranchProbabilityAnalysis::run(Function &F, FunctionAnalysisManager &AM) {
716716 BranchProbabilityInfo BPI;
864864 return QueryResult;
865865 }
866866
867 char CFLAndersAA::PassID;
867 AnalysisKey CFLAndersAA::Key;
868868
869869 CFLAndersAAResult CFLAndersAA::run(Function &F, FunctionAnalysisManager &AM) {
870870 return CFLAndersAAResult(AM.getResult(F));
340340 return NoAlias;
341341 }
342342
343 char CFLSteensAA::PassID;
343 AnalysisKey CFLSteensAA::Key;
344344
345345 CFLSteensAAResult CFLSteensAA::run(Function &F, FunctionAnalysisManager &AM) {
346346 return CFLSteensAAResult(AM.getResult(F));
257257 }
258258
259259 // Provide an explicit template instantiation for the static ID.
260 char CallGraphAnalysis::PassID;
260 AnalysisKey CallGraphAnalysis::Key;
261261
262262 PreservedAnalyses CallGraphPrinterPass::run(Module &M,
263263 ModuleAnalysisManager &AM) {
385385 return new DemandedBitsWrapperPass();
386386 }
387387
388 char DemandedBitsAnalysis::PassID;
388 AnalysisKey DemandedBitsAnalysis::Key;
389389
390390 DemandedBits DemandedBitsAnalysis::run(Function &F,
391391 FunctionAnalysisManager &AM) {
121121 return DependenceInfo(&F, &AA, &SE, &LI);
122122 }
123123
124 char DependenceAnalysis::PassID;
124 AnalysisKey DependenceAnalysis::Key;
125125
126126 INITIALIZE_PASS_BEGIN(DependenceAnalysisWrapperPass, "da",
127127 "Dependence Analysis", true, true)
5555 }
5656 #endif
5757
58 char DominanceFrontierAnalysis::PassID;
58 AnalysisKey DominanceFrontierAnalysis::Key;
5959
6060 DominanceFrontier DominanceFrontierAnalysis::run(Function &F,
6161 FunctionAnalysisManager &AM) {
940940 return Result;
941941 }
942942
943 char GlobalsAA::PassID;
943 AnalysisKey GlobalsAA::Key;
944944
945945 GlobalsAAResult GlobalsAA::run(Module &M, ModuleAnalysisManager &AM) {
946946 return GlobalsAAResult::analyzeModule(M,
3333
3434 #define DEBUG_TYPE "iv-users"
3535
36 char IVUsersAnalysis::PassID;
36 AnalysisKey IVUsersAnalysis::Key;
3737
3838 IVUsers IVUsersAnalysis::run(Loop &L, LoopAnalysisManager &AM) {
3939 const auto &FAM =
18321832 }
18331833 }
18341834
1835 char LazyCallGraphAnalysis::PassID;
1835 AnalysisKey LazyCallGraphAnalysis::Key;
18361836
18371837 LazyCallGraphPrinterPass::LazyCallGraphPrinterPass(raw_ostream &OS) : OS(OS) {}
18381838
5050 FunctionPass *createLazyValueInfoPass() { return new LazyValueInfoWrapperPass(); }
5151 }
5252
53 char LazyValueAnalysis::PassID;
53 AnalysisKey LazyValueAnalysis::Key;
5454
5555 //===----------------------------------------------------------------------===//
5656 // LVILatticeVal
20662066 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
20672067 INITIALIZE_PASS_END(LoopAccessLegacyAnalysis, LAA_NAME, laa_name, false, true)
20682068
2069 char LoopAccessAnalysis::PassID;
2069 AnalysisKey LoopAccessAnalysis::Key;
20702070
20712071 LoopAccessInfo LoopAccessAnalysis::run(Loop &L, LoopAnalysisManager &AM) {
20722072 const FunctionAnalysisManager &FAM =
668668 }
669669 }
670670
671 char LoopAnalysis::PassID;
671 AnalysisKey LoopAnalysis::Key;
672672
673673 LoopInfo LoopAnalysis::run(Function &F, FunctionAnalysisManager &AM) {
674674 // FIXME: Currently we create a LoopInfo from scratch for every function.
16421642 #endif
16431643 }
16441644
1645 char MemoryDependenceAnalysis::PassID;
1645 AnalysisKey MemoryDependenceAnalysis::Key;
16461646
16471647 MemoryDependenceResults
16481648 MemoryDependenceAnalysis::run(Function &F, FunctionAnalysisManager &AM) {
304304 return Index;
305305 }
306306
307 char ModuleSummaryIndexAnalysis::PassID;
307 AnalysisKey ModuleSummaryIndexAnalysis::Key;
308308
309309 ModuleSummaryIndex
310310 ModuleSummaryIndexAnalysis::run(Module &M, ModuleAnalysisManager &AM) {
236236 AU.setPreservesAll();
237237 }
238238
239 char OptimizationRemarkEmitterAnalysis::PassID;
239 AnalysisKey OptimizationRemarkEmitterAnalysis::Key;
240240
241241 OptimizationRemarkEmitter
242242 OptimizationRemarkEmitterAnalysis::run(Function &F,
4343 return new PostDominatorTreeWrapperPass();
4444 }
4545
46 char PostDominatorTreeAnalysis::PassID;
46 AnalysisKey PostDominatorTreeAnalysis::Key;
4747
4848 PostDominatorTree PostDominatorTreeAnalysis::run(Function &F,
4949 FunctionAnalysisManager &) {
158158 return false;
159159 }
160160
161 char ProfileSummaryAnalysis::PassID;
161 AnalysisKey ProfileSummaryAnalysis::Key;
162162 ProfileSummaryInfo ProfileSummaryAnalysis::run(Module &M,
163163 ModuleAnalysisManager &) {
164164 return ProfileSummaryInfo(M);
180180 // RegionInfoAnalysis implementation
181181 //
182182
183 char RegionInfoAnalysis::PassID;
183 AnalysisKey RegionInfoAnalysis::Key;
184184
185185 RegionInfo RegionInfoAnalysis::run(Function &F, FunctionAnalysisManager &AM) {
186186 RegionInfo RI;
1001210012 // TODO: Verify more things.
1001310013 }
1001410014
10015 char ScalarEvolutionAnalysis::PassID;
10015 AnalysisKey ScalarEvolutionAnalysis::Key;
1001610016
1001710017 ScalarEvolution ScalarEvolutionAnalysis::run(Function &F,
1001810018 FunctionAnalysisManager &AM) {
109109 return nullptr;
110110 }
111111
112 char SCEVAA::PassID;
112 AnalysisKey SCEVAA::Key;
113113
114114 SCEVAAResult SCEVAA::run(Function &F, FunctionAnalysisManager &AM) {
115115 return SCEVAAResult(AM.getResult(F));
172172 return true;
173173 }
174174
175 char ScopedNoAliasAA::PassID;
175 AnalysisKey ScopedNoAliasAA::Key;
176176
177177 ScopedNoAliasAAResult ScopedNoAliasAA::run(Function &F,
178178 FunctionAnalysisManager &AM) {
12641264 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
12651265 }
12661266
1267 char TargetLibraryAnalysis::PassID;
1267 AnalysisKey TargetLibraryAnalysis::Key;
12681268
12691269 // Register the basic pass.
12701270 INITIALIZE_PASS(TargetLibraryInfoWrapperPass, "targetlibinfo",
472472 return TTICallback(F);
473473 }
474474
475 char TargetIRAnalysis::PassID;
475 AnalysisKey TargetIRAnalysis::Key;
476476
477477 TargetIRAnalysis::Result TargetIRAnalysis::getDefaultTTI(const Function &F) {
478478 return Result(F.getParent()->getDataLayout());
549549 return false;
550550 }
551551
552 char TypeBasedAA::PassID;
552 AnalysisKey TypeBasedAA::Key;
553553
554554 TypeBasedAAResult TypeBasedAA::run(Function &F, FunctionAnalysisManager &AM) {
555555 return TypeBasedAAResult();
310310 return DT;
311311 }
312312
313 char DominatorTreeAnalysis::PassID;
313 AnalysisKey DominatorTreeAnalysis::Key;
314314
315315 DominatorTreePrinterPass::DominatorTreePrinterPass(raw_ostream &OS) : OS(OS) {}
316316
2323 template class InnerAnalysisManagerProxy;
2424 template class OuterAnalysisManagerProxy;
2525 }
26
27 AnalysisKey PreservedAnalyses::AllAnalysesKey;
44724472 return new VerifierLegacyPass(FatalErrors);
44734473 }
44744474
4475 char VerifierAnalysis::PassID;
4475 AnalysisKey VerifierAnalysis::Key;
44764476 VerifierAnalysis::Result VerifierAnalysis::run(Module &M,
44774477 ModuleAnalysisManager &) {
44784478 Result Res;
151151 /// \brief No-op module analysis.
152152 class NoOpModuleAnalysis : public AnalysisInfoMixin {
153153 friend AnalysisInfoMixin;
154 static char PassID;
154 static AnalysisKey Key;
155155
156156 public:
157157 struct Result {};
171171 /// \brief No-op CGSCC analysis.
172172 class NoOpCGSCCAnalysis : public AnalysisInfoMixin {
173173 friend AnalysisInfoMixin;
174 static char PassID;
174 static AnalysisKey Key;
175175
176176 public:
177177 struct Result {};
192192 /// \brief No-op function analysis.
193193 class NoOpFunctionAnalysis : public AnalysisInfoMixin {
194194 friend AnalysisInfoMixin;
195 static char PassID;
195 static AnalysisKey Key;
196196
197197 public:
198198 struct Result {};
211211 /// \brief No-op loop analysis.
212212 class NoOpLoopAnalysis : public AnalysisInfoMixin {
213213 friend AnalysisInfoMixin;
214 static char PassID;
214 static AnalysisKey Key;
215215
216216 public:
217217 struct Result {};
219219 static StringRef name() { return "NoOpLoopAnalysis"; }
220220 };
221221
222 char NoOpModuleAnalysis::PassID;
223 char NoOpCGSCCAnalysis::PassID;
224 char NoOpFunctionAnalysis::PassID;
225 char NoOpLoopAnalysis::PassID;
222 AnalysisKey NoOpModuleAnalysis::Key;
223 AnalysisKey NoOpCGSCCAnalysis::Key;
224 AnalysisKey NoOpFunctionAnalysis::Key;
225 AnalysisKey NoOpLoopAnalysis::Key;
226226
227227 } // End anonymous namespace.
228228
20662066 return false;
20672067 }
20682068
2069 char MemorySSAAnalysis::PassID;
2069 AnalysisKey MemorySSAAnalysis::Key;
20702070
20712071 MemorySSAAnalysis::Result MemorySSAAnalysis::run(Function &F,
20722072 FunctionAnalysisManager &AM) {
2121
2222 namespace {
2323
24 class TestModuleAnalysis {
24 class TestModuleAnalysis : public AnalysisInfoMixin {
2525 public:
2626 struct Result {
2727 Result(int Count) : FunctionCount(Count) {}
2828 int FunctionCount;
2929 };
3030
31 static void *ID() { return (void *)&PassID; }
32 static StringRef name() { return "TestModuleAnalysis"; }
33
3431 TestModuleAnalysis(int &Runs) : Runs(Runs) {}
3532
3633 Result run(Module &M, ModuleAnalysisManager &AM) {
3936 }
4037
4138 private:
42 static char PassID;
39 friend AnalysisInfoMixin;
40 static AnalysisKey Key;
4341
4442 int &Runs;
4543 };
4644
47 char TestModuleAnalysis::PassID;
48
49 class TestSCCAnalysis {
45 AnalysisKey TestModuleAnalysis::Key;
46
47 class TestSCCAnalysis : public AnalysisInfoMixin {
5048 public:
5149 struct Result {
5250 Result(int Count) : FunctionCount(Count) {}
5351 int FunctionCount;
5452 };
5553
56 static void *ID() { return (void *)&PassID; }
57 static StringRef name() { return "TestSCCAnalysis"; }
58
5954 TestSCCAnalysis(int &Runs) : Runs(Runs) {}
6055
6156 Result run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, LazyCallGraph &) {
6459 }
6560
6661 private:
67 static char PassID;
62 friend AnalysisInfoMixin;
63 static AnalysisKey Key;
6864
6965 int &Runs;
7066 };
7167
72 char TestSCCAnalysis::PassID;
73
74 class TestFunctionAnalysis {
68 AnalysisKey TestSCCAnalysis::Key;
69
70 class TestFunctionAnalysis : public AnalysisInfoMixin {
7571 public:
7672 struct Result {
7773 Result(int Count) : InstructionCount(Count) {}
7874 int InstructionCount;
7975 };
80
81 static void *ID() { return (void *)&PassID; }
82 static StringRef name() { return "TestFunctionAnalysis"; }
8376
8477 TestFunctionAnalysis(int &Runs) : Runs(Runs) {}
8578
9487 }
9588
9689 private:
97 static char PassID;
90 friend AnalysisInfoMixin;
91 static AnalysisKey Key;
9892
9993 int &Runs;
10094 };
10195
102 char TestFunctionAnalysis::PassID;
103
104 class TestImmutableFunctionAnalysis {
96 AnalysisKey TestFunctionAnalysis::Key;
97
98 class TestImmutableFunctionAnalysis
99 : public AnalysisInfoMixin {
105100 public:
106101 struct Result {
107102 bool invalidate(Function &, const PreservedAnalyses &) { return false; }
108103 };
109104
110 static void *ID() { return (void *)&PassID; }
111 static StringRef name() { return "TestImmutableFunctionAnalysis"; }
112
113105 TestImmutableFunctionAnalysis(int &Runs) : Runs(Runs) {}
114106
115107 Result run(Function &F, FunctionAnalysisManager &AM) {
118110 }
119111
120112 private:
121 static char PassID;
113 friend AnalysisInfoMixin;
114 static AnalysisKey Key;
122115
123116 int &Runs;
124117 };
125118
126 char TestImmutableFunctionAnalysis::PassID;
119 AnalysisKey TestImmutableFunctionAnalysis::Key;
127120
128121 struct LambdaSCCPass : public PassInfoMixin {
129122 template LambdaSCCPass(T &&Arg) : Func(std::forward(Arg)) {}
2020
2121 namespace {
2222
23 class TestLoopAnalysis {
24 /// \brief Private static data to provide unique ID.
25 static char PassID;
23 class TestLoopAnalysis : public AnalysisInfoMixin {
24 friend AnalysisInfoMixin;
25 static AnalysisKey Key;
2626
2727 int &Runs;
2828
3131 Result(int Count) : BlockCount(Count) {}
3232 int BlockCount;
3333 };
34
35 /// \brief Returns an opaque, unique ID for this pass type.
36 static void *ID() { return (void *)&PassID; }
37
38 /// \brief Returns the name of the analysis.
39 static StringRef name() { return "TestLoopAnalysis"; }
4034
4135 TestLoopAnalysis(int &Runs) : Runs(Runs) {}
4236
5145 }
5246 };
5347
54 char TestLoopAnalysis::PassID;
48 AnalysisKey TestLoopAnalysis::Key;
5549
5650 class TestLoopPass {
5751 std::vector &VisitedLoops;
4040
4141 private:
4242 friend AnalysisInfoMixin;
43 static char PassID;
43 static AnalysisKey Key;
4444
4545 int &Runs;
4646 };
4747
48 char TestFunctionAnalysis::PassID;
48 AnalysisKey TestFunctionAnalysis::Key;
4949
5050 class TestModuleAnalysis : public AnalysisInfoMixin {
5151 public:
6666
6767 private:
6868 friend AnalysisInfoMixin;
69 static char PassID;
69 static AnalysisKey Key;
7070
7171 int &Runs;
7272 };
7373
74 char TestModuleAnalysis::PassID;
74 AnalysisKey TestModuleAnalysis::Key;
7575
7676 struct TestModulePass : PassInfoMixin {
7777 TestModulePass(int &RunCount) : RunCount(RunCount) {}
350350
351351 private:
352352 friend AnalysisInfoMixin;
353 static char PassID;
354 };
355
356 char CustomizedAnalysis::PassID;
353 static AnalysisKey Key;
354 };
355
356 AnalysisKey CustomizedAnalysis::Key;
357357
358358 struct CustomizedPass : PassInfoMixin {
359359 std::function Callback;