1 //===- ScopPass.cpp - The base class of Passes that operate on Polly IR ---===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the definitions of the ScopPass members.
12 //===----------------------------------------------------------------------===//
14 #include "polly/ScopPass.h"
15 #include "polly/ScopInfo.h"
17 #include "llvm/Analysis/AssumptionCache.h"
20 using namespace polly
;
22 bool ScopPass::runOnRegion(Region
*R
, RGPassManager
&RGM
) {
28 if ((S
= getAnalysis
<ScopInfoRegionPass
>().getScop()))
34 void ScopPass::print(raw_ostream
&OS
, const Module
*M
) const {
39 void ScopPass::getAnalysisUsage(AnalysisUsage
&AU
) const {
40 AU
.addRequired
<ScopInfoRegionPass
>();
44 template class OwningInnerAnalysisManagerProxy
<ScopAnalysisManager
, Function
>;
48 template class PassManager
<Scop
, ScopAnalysisManager
,
49 ScopStandardAnalysisResults
&, SPMUpdater
&>;
50 template class InnerAnalysisManagerProxy
<ScopAnalysisManager
, Function
>;
51 template class OuterAnalysisManagerProxy
<FunctionAnalysisManager
, Scop
,
52 ScopStandardAnalysisResults
&>;
56 PassManager
<Scop
, ScopAnalysisManager
, ScopStandardAnalysisResults
&,
57 SPMUpdater
&>::run(Scop
&S
, ScopAnalysisManager
&AM
,
58 ScopStandardAnalysisResults
&AR
, SPMUpdater
&U
) {
59 auto PA
= PreservedAnalyses::all();
60 for (auto &Pass
: Passes
) {
61 auto PassPA
= Pass
->run(S
, AM
, AR
, U
);
63 AM
.invalidate(S
, PassPA
);
64 PA
.intersect(std::move(PassPA
));
67 // All analyses for 'this' Scop have been invalidated above.
68 // If ScopPasses affect break other scops they have to propagate this
69 // information through the updater
70 PA
.preserveSet
<AllAnalysesOn
<Scop
>>();
74 bool ScopAnalysisManagerFunctionProxy::Result::invalidate(
75 Function
&F
, const PreservedAnalyses
&PA
,
76 FunctionAnalysisManager::Invalidator
&Inv
) {
78 // First, check whether our ScopInfo is about to be invalidated
79 auto PAC
= PA
.getChecker
<ScopAnalysisManagerFunctionProxy
>();
80 if (!(PAC
.preserved() || PAC
.preservedSet
<AllAnalysesOn
<Function
>>() ||
81 Inv
.invalidate
<ScopInfoAnalysis
>(F
, PA
) ||
82 Inv
.invalidate
<ScalarEvolutionAnalysis
>(F
, PA
) ||
83 Inv
.invalidate
<LoopAnalysis
>(F
, PA
) ||
84 Inv
.invalidate
<DominatorTreeAnalysis
>(F
, PA
))) {
86 // As everything depends on ScopInfo, we must drop all existing results
88 if (auto *scop
= S
.second
.get())
90 InnerAM
->clear(*scop
);
93 return true; // Invalidate the proxy result as well.
96 bool allPreserved
= PA
.allAnalysesInSetPreserved
<AllAnalysesOn
<Scop
>>();
98 // Invalidate all non-preserved analyses
99 // Even if all analyses were preserved, we still need to run deferred
101 for (auto &S
: *SI
) {
102 Optional
<PreservedAnalyses
> InnerPA
;
103 auto *scop
= S
.second
.get();
107 if (auto *OuterProxy
=
108 InnerAM
->getCachedResult
<FunctionAnalysisManagerScopProxy
>(*scop
)) {
109 for (const auto &InvPair
: OuterProxy
->getOuterInvalidations()) {
110 auto *OuterAnalysisID
= InvPair
.first
;
111 const auto &InnerAnalysisIDs
= InvPair
.second
;
113 if (Inv
.invalidate(OuterAnalysisID
, F
, PA
)) {
116 for (auto *InnerAnalysisID
: InnerAnalysisIDs
)
117 InnerPA
->abandon(InnerAnalysisID
);
122 InnerAM
->invalidate(*scop
, *InnerPA
);
128 InnerAM
->invalidate(*scop
, PA
);
131 return false; // This proxy is still valid
135 OwningScopAnalysisManagerFunctionProxy::Result
136 OwningScopAnalysisManagerFunctionProxy::run(Function
&F
,
137 FunctionAnalysisManager
&FAM
) {
138 return Result(InnerAM
, FAM
.getResult
<ScopInfoAnalysis
>(F
));
141 ScopAnalysisManagerFunctionProxy::Result
142 ScopAnalysisManagerFunctionProxy::run(Function
&F
,
143 FunctionAnalysisManager
&FAM
) {
144 return Result(*InnerAM
, FAM
.getResult
<ScopInfoAnalysis
>(F
));