LLVM  10.0.0svn
Go to the documentation of this file.
1 //===- PassManager.cpp - Infrastructure for managing & running IR passes --===//
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 //===----------------------------------------------------------------------===//
9 #include "llvm/IR/PassManager.h"
10 #include "llvm/ADT/STLExtras.h"
11 #include "llvm/IR/LLVMContext.h"
13 using namespace llvm;
15 // Explicit template instantiations and specialization defininitions for core
16 // template typedefs.
17 namespace llvm {
18 template class AllAnalysesOn<Module>;
19 template class AllAnalysesOn<Function>;
20 template class PassManager<Module>;
21 template class PassManager<Function>;
22 template class AnalysisManager<Module>;
23 template class AnalysisManager<Function>;
27 template <>
29  Module &M, const PreservedAnalyses &PA,
31  // If literally everything is preserved, we're done.
32  if (PA.areAllPreserved())
33  return false; // This is still a valid proxy.
35  // If this proxy isn't marked as preserved, then even if the result remains
36  // valid, the key itself may no longer be valid, so we clear everything.
37  //
38  // Note that in order to preserve this proxy, a module pass must ensure that
39  // the FAM has been completely updated to handle the deletion of functions.
40  // Specifically, any FAM-cached results for those functions need to have been
41  // forcibly cleared. When preserved, this proxy will only invalidate results
42  // cached on functions *still in the module* at the end of the module pass.
44  if (!PAC.preserved() && !PAC.preservedSet<AllAnalysesOn<Module>>()) {
45  InnerAM->clear();
46  return true;
47  }
49  // Directly check if the relevant set is preserved.
50  bool AreFunctionAnalysesPreserved =
53  // Now walk all the functions to see if any inner analysis invalidation is
54  // necessary.
55  for (Function &F : M) {
56  Optional<PreservedAnalyses> FunctionPA;
58  // Check to see whether the preserved set needs to be pruned based on
59  // module-level analysis invalidation that triggers deferred invalidation
60  // registered with the outer analysis manager proxy for this function.
61  if (auto *OuterProxy =
62  InnerAM->getCachedResult<ModuleAnalysisManagerFunctionProxy>(F))
63  for (const auto &OuterInvalidationPair :
64  OuterProxy->getOuterInvalidations()) {
65  AnalysisKey *OuterAnalysisID = OuterInvalidationPair.first;
66  const auto &InnerAnalysisIDs = OuterInvalidationPair.second;
67  if (Inv.invalidate(OuterAnalysisID, M, PA)) {
68  if (!FunctionPA)
69  FunctionPA = PA;
70  for (AnalysisKey *InnerAnalysisID : InnerAnalysisIDs)
71  FunctionPA->abandon(InnerAnalysisID);
72  }
73  }
75  // Check if we needed a custom PA set, and if so we'll need to run the
76  // inner invalidation.
77  if (FunctionPA) {
78  InnerAM->invalidate(F, *FunctionPA);
79  continue;
80  }
82  // Otherwise we only need to do invalidation if the original PA set didn't
83  // preserve all function analyses.
84  if (!AreFunctionAnalysesPreserved)
85  InnerAM->invalidate(F, PA);
86  }
88  // Return false to indicate that this result is still a valid proxy.
89  return false;
90 }
91 }
93 AnalysisSetKey CFGAnalyses::SetKey;
95 AnalysisSetKey PreservedAnalyses::AllAnalysesKey;
void abandon()
Mark an analysis as abandoned.
Definition: PassManager.h:208
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:667
This class represents lattice values for constants.
Definition: AllocatorList.h:23
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:66
bool invalidate(IRUnitT &IR, const PreservedAnalyses &PA, typename AnalysisManager< IRUnitT, ExtraArgTs... >::Invalidator &Inv)
Handler for invalidation of the outer IR unit, IRUnitT.
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
Definition: PassManager.h:312
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:154
bool areAllPreserved() const
Test whether all analyses are preserved (and none are abandoned).
Definition: PassManager.h:329
An analysis over an "inner" IR unit that provides access to an analysis manager over a "outer" IR uni...
Definition: PassManager.h:1161
A special type used to provide an address that identifies a set of related analyses.
Definition: PassManager.h:81
Manages a sequence of passes over a particular unit of IR.
Definition: PassManager.h:465
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:649
This templated class represents "all analyses that operate over <a particular IR unit>" (e...
Definition: PassManager.h:92
A container for analyses that lazily runs them and caches their results.
This header defines various interfaces for pass management in LLVM.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:71
bool allAnalysesInSetPreserved() const
Directly test whether a set of analyses is preserved.
Definition: PassManager.h:337
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:1045