Coverage Report

Created: 2017-10-03 07:32

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