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
>();
46 template class PassManager
<Scop
, ScopAnalysisManager
,
47 ScopStandardAnalysisResults
&, SPMUpdater
&>;
48 template class InnerAnalysisManagerProxy
<ScopAnalysisManager
, Function
>;
49 template class OuterAnalysisManagerProxy
<FunctionAnalysisManager
, Scop
,
50 ScopStandardAnalysisResults
&>;
54 PassManager
<Scop
, ScopAnalysisManager
, ScopStandardAnalysisResults
&,
55 SPMUpdater
&>::run(Scop
&S
, ScopAnalysisManager
&AM
,
56 ScopStandardAnalysisResults
&AR
, SPMUpdater
&U
) {
57 auto PA
= PreservedAnalyses::all();
58 for (auto &Pass
: Passes
) {
59 auto PassPA
= Pass
->run(S
, AM
, AR
, U
);
61 AM
.invalidate(S
, PassPA
);
62 PA
.intersect(std::move(PassPA
));
65 // All analyses for 'this' Scop have been invalidated above.
66 // If ScopPasses affect break other scops they have to propagate this
67 // information through the updater
68 PA
.preserveSet
<AllAnalysesOn
<Scop
>>();
72 bool ScopAnalysisManagerFunctionProxy::Result::invalidate(
73 Function
&F
, const PreservedAnalyses
&PA
,
74 FunctionAnalysisManager::Invalidator
&Inv
) {
76 // First, check whether our ScopInfo is about to be invalidated
77 auto PAC
= PA
.getChecker
<ScopAnalysisManagerFunctionProxy
>();
78 if (!(PAC
.preserved() || PAC
.preservedSet
<AllAnalysesOn
<Function
>>() ||
79 Inv
.invalidate
<ScopAnalysis
>(F
, PA
) ||
80 Inv
.invalidate
<ScalarEvolutionAnalysis
>(F
, PA
) ||
81 Inv
.invalidate
<LoopAnalysis
>(F
, PA
) ||
82 Inv
.invalidate
<AAManager
>(F
, PA
) ||
83 Inv
.invalidate
<DominatorTreeAnalysis
>(F
, PA
) ||
84 Inv
.invalidate
<AssumptionAnalysis
>(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 ScopAnalysisManagerFunctionProxy::Result
136 ScopAnalysisManagerFunctionProxy::run(Function
&F
,
137 FunctionAnalysisManager
&FAM
) {
138 return Result(*InnerAM
, FAM
.getResult
<ScopInfoAnalysis
>(F
));