/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/polly/lib/Analysis/ScopPass.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===- ScopPass.cpp - The base class of Passes that operate on Polly IR ---===// |
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 | | // |
9 | | // This file contains the definitions of the ScopPass members. |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #include "polly/ScopPass.h" |
14 | | #include "polly/ScopInfo.h" |
15 | | #include "llvm/Analysis/BasicAliasAnalysis.h" |
16 | | #include "llvm/Analysis/GlobalsModRef.h" |
17 | | #include "llvm/Analysis/OptimizationRemarkEmitter.h" |
18 | | #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h" |
19 | | #include "llvm/Analysis/TargetTransformInfo.h" |
20 | | |
21 | | using namespace llvm; |
22 | | using namespace polly; |
23 | | |
24 | 6.82k | bool ScopPass::runOnRegion(Region *R, RGPassManager &RGM) { |
25 | 6.82k | S = nullptr; |
26 | 6.82k | |
27 | 6.82k | if (skipRegion(*R)) |
28 | 0 | return false; |
29 | 6.82k | |
30 | 6.82k | if ((S = getAnalysis<ScopInfoRegionPass>().getScop())) |
31 | 1.66k | return runOnScop(*S); |
32 | 5.15k | |
33 | 5.15k | return false; |
34 | 5.15k | } |
35 | | |
36 | 1.96k | void ScopPass::print(raw_ostream &OS, const Module *M) const { |
37 | 1.96k | if (S) |
38 | 459 | printScop(OS, *S); |
39 | 1.96k | } |
40 | | |
41 | 988 | void ScopPass::getAnalysisUsage(AnalysisUsage &AU) const { |
42 | 988 | AU.addRequired<ScopInfoRegionPass>(); |
43 | 988 | |
44 | 988 | AU.addPreserved<AAResultsWrapperPass>(); |
45 | 988 | AU.addPreserved<BasicAAWrapperPass>(); |
46 | 988 | AU.addPreserved<LoopInfoWrapperPass>(); |
47 | 988 | AU.addPreserved<DominatorTreeWrapperPass>(); |
48 | 988 | AU.addPreserved<GlobalsAAWrapperPass>(); |
49 | 988 | AU.addPreserved<ScopDetectionWrapperPass>(); |
50 | 988 | AU.addPreserved<ScalarEvolutionWrapperPass>(); |
51 | 988 | AU.addPreserved<SCEVAAWrapperPass>(); |
52 | 988 | AU.addPreserved<OptimizationRemarkEmitterWrapperPass>(); |
53 | 988 | AU.addPreserved<RegionInfoPass>(); |
54 | 988 | AU.addPreserved<ScopInfoRegionPass>(); |
55 | 988 | AU.addPreserved<TargetTransformInfoWrapperPass>(); |
56 | 988 | } |
57 | | |
58 | | namespace polly { |
59 | | template class OwningInnerAnalysisManagerProxy<ScopAnalysisManager, Function>; |
60 | | } |
61 | | |
62 | | namespace llvm { |
63 | | |
64 | | template class PassManager<Scop, ScopAnalysisManager, |
65 | | ScopStandardAnalysisResults &, SPMUpdater &>; |
66 | | template class InnerAnalysisManagerProxy<ScopAnalysisManager, Function>; |
67 | | template class OuterAnalysisManagerProxy<FunctionAnalysisManager, Scop, |
68 | | ScopStandardAnalysisResults &>; |
69 | | |
70 | | template <> |
71 | | PreservedAnalyses |
72 | | PassManager<Scop, ScopAnalysisManager, ScopStandardAnalysisResults &, |
73 | | SPMUpdater &>::run(Scop &S, ScopAnalysisManager &AM, |
74 | 0 | ScopStandardAnalysisResults &AR, SPMUpdater &U) { |
75 | 0 | auto PA = PreservedAnalyses::all(); |
76 | 0 | for (auto &Pass : Passes) { |
77 | 0 | auto PassPA = Pass->run(S, AM, AR, U); |
78 | 0 |
|
79 | 0 | AM.invalidate(S, PassPA); |
80 | 0 | PA.intersect(std::move(PassPA)); |
81 | 0 | } |
82 | 0 |
|
83 | 0 | // All analyses for 'this' Scop have been invalidated above. |
84 | 0 | // If ScopPasses affect break other scops they have to propagate this |
85 | 0 | // information through the updater |
86 | 0 | PA.preserveSet<AllAnalysesOn<Scop>>(); |
87 | 0 | return PA; |
88 | 0 | } |
89 | | |
90 | | bool ScopAnalysisManagerFunctionProxy::Result::invalidate( |
91 | | Function &F, const PreservedAnalyses &PA, |
92 | 0 | FunctionAnalysisManager::Invalidator &Inv) { |
93 | 0 |
|
94 | 0 | // First, check whether our ScopInfo is about to be invalidated |
95 | 0 | auto PAC = PA.getChecker<ScopAnalysisManagerFunctionProxy>(); |
96 | 0 | if (!(PAC.preserved() || PAC.preservedSet<AllAnalysesOn<Function>>()) || |
97 | 0 | Inv.invalidate<ScopInfoAnalysis>(F, PA) || |
98 | 0 | Inv.invalidate<ScalarEvolutionAnalysis>(F, PA) || |
99 | 0 | Inv.invalidate<LoopAnalysis>(F, PA) || |
100 | 0 | Inv.invalidate<DominatorTreeAnalysis>(F, PA)) { |
101 | 0 |
|
102 | 0 | // As everything depends on ScopInfo, we must drop all existing results |
103 | 0 | for (auto &S : *SI) |
104 | 0 | if (auto *scop = S.second.get()) |
105 | 0 | if (InnerAM) |
106 | 0 | InnerAM->clear(*scop, scop->getName()); |
107 | 0 |
|
108 | 0 | InnerAM = nullptr; |
109 | 0 | return true; // Invalidate the proxy result as well. |
110 | 0 | } |
111 | 0 |
|
112 | 0 | bool allPreserved = PA.allAnalysesInSetPreserved<AllAnalysesOn<Scop>>(); |
113 | 0 |
|
114 | 0 | // Invalidate all non-preserved analyses |
115 | 0 | // Even if all analyses were preserved, we still need to run deferred |
116 | 0 | // invalidation |
117 | 0 | for (auto &S : *SI) { |
118 | 0 | Optional<PreservedAnalyses> InnerPA; |
119 | 0 | auto *scop = S.second.get(); |
120 | 0 | if (!scop) |
121 | 0 | continue; |
122 | 0 | |
123 | 0 | if (auto *OuterProxy = |
124 | 0 | InnerAM->getCachedResult<FunctionAnalysisManagerScopProxy>(*scop)) { |
125 | 0 | for (const auto &InvPair : OuterProxy->getOuterInvalidations()) { |
126 | 0 | auto *OuterAnalysisID = InvPair.first; |
127 | 0 | const auto &InnerAnalysisIDs = InvPair.second; |
128 | 0 |
|
129 | 0 | if (Inv.invalidate(OuterAnalysisID, F, PA)) { |
130 | 0 | if (!InnerPA) |
131 | 0 | InnerPA = PA; |
132 | 0 | for (auto *InnerAnalysisID : InnerAnalysisIDs) |
133 | 0 | InnerPA->abandon(InnerAnalysisID); |
134 | 0 | } |
135 | 0 | } |
136 | 0 |
|
137 | 0 | if (InnerPA) { |
138 | 0 | InnerAM->invalidate(*scop, *InnerPA); |
139 | 0 | continue; |
140 | 0 | } |
141 | 0 | } |
142 | 0 | |
143 | 0 | if (!allPreserved) |
144 | 0 | InnerAM->invalidate(*scop, PA); |
145 | 0 | } |
146 | 0 |
|
147 | 0 | return false; // This proxy is still valid |
148 | 0 | } |
149 | | |
150 | | template <> |
151 | | ScopAnalysisManagerFunctionProxy::Result |
152 | | ScopAnalysisManagerFunctionProxy::run(Function &F, |
153 | 0 | FunctionAnalysisManager &FAM) { |
154 | 0 | return Result(*InnerAM, FAM.getResult<ScopInfoAnalysis>(F)); |
155 | 0 | } |
156 | | } // namespace llvm |
157 | | |
158 | | namespace polly { |
159 | | template <> |
160 | | OwningScopAnalysisManagerFunctionProxy::Result |
161 | | OwningScopAnalysisManagerFunctionProxy::run(Function &F, |
162 | 0 | FunctionAnalysisManager &FAM) { |
163 | 0 | return Result(InnerAM, FAM.getResult<ScopInfoAnalysis>(F)); |
164 | 0 | } |
165 | | } // namespace polly |