LLVM  8.0.1
PassManager.cpp
Go to the documentation of this file.
1 //===- PassManager.cpp - Infrastructure for managing & running IR passes --===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "llvm/IR/PassManager.h"
11 #include "llvm/ADT/STLExtras.h"
12 #include "llvm/IR/LLVMContext.h"
13 
14 using namespace llvm;
15 
16 // Explicit template instantiations and specialization defininitions for core
17 // template typedefs.
18 namespace llvm {
19 template class AllAnalysesOn<Module>;
20 template class AllAnalysesOn<Function>;
21 template class PassManager<Module>;
22 template class PassManager<Function>;
23 template class AnalysisManager<Module>;
24 template class AnalysisManager<Function>;
27 
28 template <>
30  Module &M, const PreservedAnalyses &PA,
32  // If literally everything is preserved, we're done.
33  if (PA.areAllPreserved())
34  return false; // This is still a valid proxy.
35 
36  // If this proxy isn't marked as preserved, then even if the result remains
37  // valid, the key itself may no longer be valid, so we clear everything.
38  //
39  // Note that in order to preserve this proxy, a module pass must ensure that
40  // the FAM has been completely updated to handle the deletion of functions.
41  // Specifically, any FAM-cached results for those functions need to have been
42  // forcibly cleared. When preserved, this proxy will only invalidate results
43  // cached on functions *still in the module* at the end of the module pass.
45  if (!PAC.preserved() && !PAC.preservedSet<AllAnalysesOn<Module>>()) {
46  InnerAM->clear();
47  return true;
48  }
49 
50  // Directly check if the relevant set is preserved.
51  bool AreFunctionAnalysesPreserved =
53 
54  // Now walk all the functions to see if any inner analysis invalidation is
55  // necessary.
56  for (Function &F : M) {
57  Optional<PreservedAnalyses> FunctionPA;
58 
59  // Check to see whether the preserved set needs to be pruned based on
60  // module-level analysis invalidation that triggers deferred invalidation
61  // registered with the outer analysis manager proxy for this function.
62  if (auto *OuterProxy =
63  InnerAM->getCachedResult<ModuleAnalysisManagerFunctionProxy>(F))
64  for (const auto &OuterInvalidationPair :
65  OuterProxy->getOuterInvalidations()) {
66  AnalysisKey *OuterAnalysisID = OuterInvalidationPair.first;
67  const auto &InnerAnalysisIDs = OuterInvalidationPair.second;
68  if (Inv.invalidate(OuterAnalysisID, M, PA)) {
69  if (!FunctionPA)
70  FunctionPA = PA;
71  for (AnalysisKey *InnerAnalysisID : InnerAnalysisIDs)
72  FunctionPA->abandon(InnerAnalysisID);
73  }
74  }
75 
76  // Check if we needed a custom PA set, and if so we'll need to run the
77  // inner invalidation.
78  if (FunctionPA) {
79  InnerAM->invalidate(F, *FunctionPA);
80  continue;
81  }
82 
83  // Otherwise we only need to do invalidation if the original PA set didn't
84  // preserve all function analyses.
85  if (!AreFunctionAnalysesPreserved)
86  InnerAM->invalidate(F, PA);
87  }
88 
89  // Return false to indicate that this result is still a valid proxy.
90  return false;
91 }
92 }
93 
94 AnalysisSetKey CFGAnalyses::SetKey;
95 
96 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:660
This class represents lattice values for constants.
Definition: AllocatorList.h:24
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
bool invalidate(IRUnitT &IR, const PreservedAnalyses &PA, typename AnalysisManager< IRUnitT, ExtraArgTs... >::Invalidator &Inv)
Handler for invalidation of the outer IR unit, IRUnitT.
F(f)
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
Definition: PassManager.h:305
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:322
An analysis over an "inner" IR unit that provides access to an analysis manager over a "outer" IR uni...
Definition: PassManager.h:1154
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:458
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:642
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:330
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:1038